/* Copyright (C) 1989, 1992 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
/* Dictionary operators for GhostScript */
zdict(register os_ptr op
)
{ check_type(*op
, t_integer
);
if ( op
->value
.intval
< 0 || op
->value
.intval
> dict_max_size
)
return dict_create((uint
)op
->value
.intval
, op
);
zmaxlength(register os_ptr op
)
{ check_type(*op
, t_dictionary
);
make_int(op
, dict_maxlength(op
));
zsetmaxlength(register os_ptr op
)
check_type(*op1
, t_dictionary
);
check_type(*op
, t_integer
);
if ( op
->value
.intval
< 0 || op
->value
.intval
> dict_max_size
)
new_size
= (uint
)op
->value
.intval
;
if ( dict_length(op
- 1) > new_size
)
code
= dict_resize(op
- 1, new_size
);
zbegin(register os_ptr op
)
{ check_type(*op
, t_dictionary
);
if ( dsp
== dstop
) return e_dictstackoverflow
;
{ if ( dsp
== dstack
+ 1 ) return e_dictstackunderflow
;
/* We make this into a separate procedure because */
/* the interpreter will almost always call it directly. */
zop_def(register os_ptr op
)
if ( r_has_type(op
- 1, t_null
) ) return e_typecheck
;
return dict_put(dsp
, op
- 1, op
);
{ int code
= zop_def(op
);
zload(register os_ptr op
)
if ( r_has_type(op
, t_null
) ) return e_typecheck
;
if ( r_has_type(op
, t_name
) )
{ /* Use the fast lookup */
if ( (pvalue
= dict_find_name(op
)) == 0 )
{ if ( dict_lookup(dstack
, dsp
, op
, &pvalue
) <= 0 )
zstore(register os_ptr op
)
if ( r_has_type(op
- 1, t_null
) ) return e_typecheck
;
if ( dict_lookup(dstack
, dsp
, op
- 1, &pvalue
) <= 0 )
{ code
= dict_put(dsp
, op
- 1, op
);
ref_assign_old(pvalue
, op
, "store");
/* get - implemented in zgeneric.c */
/* put - implemented in zgeneric.c */
zundef(register os_ptr op
)
{ check_type(op
[-1], t_dictionary
);
check_dict_write(op
[-1]);
if ( !r_has_type(op
, t_null
) )
dict_undef(op
- 1, op
); /* ignore undefined error */
zknown(register os_ptr op
)
check_type(*op1
, t_dictionary
);
(r_has_type(op
, t_null
) ? 0 :
dict_find(op1
, op
, &pvalue
) > 0 ? 1 : 0));
zwhere(register os_ptr op
)
if ( r_has_type(op
, t_null
) )
{ check_dict_read(*pdref
);
if ( dict_find(pdref
, op
, &pvalue
) > 0 ) break;
/* copy for dictionaries -- called from zcopy in zgeneric.c. */
/* Only the type of *op has been checked. */
zcopy_dict(register os_ptr op
)
check_type(*op1
, t_dictionary
);
if ( !dict_auto_expand
&& (dict_length(op
) != 0 || dict_maxlength(op
) < dict_length(op1
)) )
zcurrentdict(register os_ptr op
)
zcountdictstack(register os_ptr op
)
make_int(op
, dsp
- dstack
+ 1);
zdictstack(register os_ptr op
)
{ int depth
= dsp
- dstack
+ 1;
check_write_type(*op
, t_array
);
if ( depth
> r_size(op
) ) return e_rangecheck
;
refcpy_to_old(op
->value
.refs
, dstack
, depth
, "dictstack");
zcleardictstack(os_ptr op
)
/* ------ Initialization procedure ------ */
op_def zdict_op_defs
[] = {
{"0cleardictstack", zcleardictstack
},
{"0countdictstack", zcountdictstack
},
{"0currentdict", zcurrentdict
},
{"0dictstack", zdictstack
},
{"1maxlength", zmaxlength
},
{"2setmaxlength", zsetmaxlength
},