/* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
/* Relational, boolean, and bit operators for Ghostscript */
int obj_le(P2(os_ptr
, os_ptr
));
{ register os_ptr op1
= op
- 1;
#define eq_check_read(opp)\
{ case t_string: case t_array: case t_mixedarray: case t_shortarray:\
check_read(*opp); break;\
case t_dictionary: check_dict_read(*opp);\
make_bool(op1
, (obj_eq(op1
, op
) ? 1 : 0));
{ /* We'll just be lazy and use eq. */
if ( !code
) op
[-1].value
.index
^= 1;
{ int code
= obj_le(op
, op
- 1);
if ( code
< 0 ) return code
;
{ int code
= obj_le(op
- 1, op
);
if ( code
< 0 ) return code
;
make_bool(op
- 1, code
^ 1);
{ int code
= obj_le(op
- 1, op
);
if ( code
< 0 ) return code
;
{ int code
= obj_le(op
, op
- 1);
if ( code
< 0 ) return code
;
make_bool(op
- 1, code
^ 1);
{ int code
= obj_le(op
- 1, op
);
if ( code
< 0 ) return code
;
{ ref_assign(op
- 1, op
);
{ int code
= obj_le(op
- 1, op
);
if ( code
< 0 ) return code
;
{ ref_assign(op
- 1, op
);
{ check_type(op
[-1], r_type(op
));
case t_boolean
: op
[-1].value
.index
&= op
->value
.index
; break;
case t_integer
: op
[-1].value
.intval
&= op
->value
.intval
; break;
default: return e_typecheck
;
case t_boolean
: op
->value
.index
= !op
->value
.index
; break;
case t_integer
: op
->value
.intval
= ~op
->value
.intval
; break;
default: return e_typecheck
;
{ check_type(op
[-1], r_type(op
));
case t_boolean
: op
[-1].value
.index
|= op
->value
.index
; break;
case t_integer
: op
[-1].value
.intval
|= op
->value
.intval
; break;
default: return e_typecheck
;
{ check_type(op
[-1], r_type(op
));
case t_boolean
: op
[-1].value
.index
^= op
->value
.index
; break;
case t_integer
: op
[-1].value
.intval
^= op
->value
.intval
; break;
default: return e_typecheck
;
zbitshift(register os_ptr op
)
check_type(op
[-1], t_integer
);
check_type(*op
, t_integer
);
if ( op
->value
.intval
< -31 || op
->value
.intval
> 31 )
else if ( (shift
= op
->value
.intval
) < 0 )
op
[-1].value
.intval
= ((ulong
)(op
[-1].value
.intval
)) >> -shift
;
op
[-1].value
.intval
<<= shift
;
/* ------ Initialization procedure ------ */
op_def zrelbit_op_defs
[] = {
{"2bitshift", zbitshift
},
/* ------ Internal routines ------ */
/* Compare two operands (both numeric, or both strings). */
/* Return 1 if op[-1] <= op[0], 0 if op[-1] > op[0], */
/* or a (negative) error code. */
#define bcval(v1, rel, v2) (op1->value.v1 rel op->value.v2 ? 1 : 0)
(bytes_compare(op1->value.bytes, r_size(op1),\
op->value.bytes, r_size(op)) rel 0 ? 1 : 0)
obj_le(register os_ptr op1
, register os_ptr op
)
case t_integer
: return bcval(intval
, <=, intval
);
case t_real
: return bcval(intval
, <=, realval
);
default: return e_typecheck
;
case t_real
: return bcval(realval
, <=, realval
);
case t_integer
: return bcval(realval
, <=, intval
);
default: return e_typecheck
;
check_read_type(*op
, t_string
);
default: return e_typecheck
;