/* Copyright (C) 1991, 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
/* Device property operators */
#include "gsmatrix.h" /* for gxdevice.h */
/* Imported procedures */
extern int array_get(P3(ref
*, long, ref
*));
private int props_to_stack(P3(gs_prop_item
*, os_ptr
, int));
private int props_from_stack(P3(gs_prop_item
*, os_ptr
, int));
zgetdeviceprops(os_ptr op
)
check_type(*op
, t_device
);
count
= (*dev
->procs
->get_props
)(dev
, NULL
);
plist
= (gs_prop_item
*)alloc(count
, sizeof(gs_prop_item
), "getdeviceprops");
if ( plist
== 0 ) return_error(e_VMerror
);
(*dev
->procs
->get_props
)(dev
, plist
);
code
= props_to_stack(plist
, op
+ 1, count
);
alloc_free((char *)plist
, count
, sizeof(gs_prop_item
), "getdeviceprops");
zputdeviceprops(os_ptr op
)
check_type(*op
, t_device
);
for ( mp
= op
- 1; !r_has_type(mp
, t_mark
); mp
-- )
{ if ( mp
<= osbot
) return e_unmatchedmark
;
if ( count
& 1 ) return e_rangecheck
;
plist
= (gs_prop_item
*)alloc(count
+ acount
, sizeof(gs_prop_item
), "putdeviceprops");
if ( plist
== 0 ) return_error(e_VMerror
);
code
= props_from_stack(plist
, mp
+ 1, count
);
code
= (*dev
->procs
->put_props
)(dev
, plist
, count
+ acount
);
alloc_free((char *)plist
, count
+ acount
, sizeof(gs_prop_item
), "putdeviceprops");
/* ------ Initialization procedure ------ */
op_def zprops_op_defs
[] = {
{"1getdeviceprops", zgetdeviceprops
},
{"2putdeviceprops", zputdeviceprops
},
/* ------ Internal routines ------ */
/* Get properties from a property list to the stack. */
props_to_stack(gs_prop_item
*plist
, os_ptr op0
, int count
)
for ( op
= op0
, pi
= plist
, i
= count
; i
!= 0; pi
++, i
-- )
const char *nstr
= pi
->pname
;
int nlen
= pi
->name_size
;
if ( nstr
== 0 ) continue; /* no name, skip */
if ( ostop
- op
< 2 ) return e_stackoverflow
;
if ( nlen
< 0 ) nlen
= strlen(nstr
);
code
= name_ref((const byte
*)nstr
, nlen
, op
, 0);
if ( code
< 0 ) return code
;
make_int(&value
, pi
->value
.i
);
make_real(&value
, pi
->value
.f
);
make_bool(&value
, pi
->value
.b
);
{ ushort size
= pi
->value
.a
.size
;
if ( size
== (ushort
)(-1) )
size
= strlen(pi
->value
.a
.p
.s
);
str
= alloc(size
, 1, "props_to_stack(string)");
if ( str
== 0 ) return e_VMerror
;
memcpy(str
, pi
->value
.a
.p
.s
, size
);
make_tasv(&value
, t_string
, a_all
, size
, bytes
, (byte
*)str
);
case (int)prt_float_array
:
{ uint size
= pi
->value
.a
.size
;
ref
*arefs
= alloc_refs(size
, "props_to_stack(array)");
gs_prop_item
*pv
= pi
->value
.a
.p
.v
;
if ( arefs
== 0 ) return e_VMerror
;
make_tasv_new(&value
, t_array
, a_all
, size
, refs
, arefs
);
for ( j
= 0; j
< size
; j
++, arefs
++, pv
++ )
if ( pi
->type
== prt_int_array
)
make_int_new(arefs
, pv
->value
.i
);
make_real_new(arefs
, pv
->value
.f
);
ref_assign(op
+ 1, &value
);
/* Set properties from the stack. */
/* Returns the number of elements copied. */
/* Entries with non-name keys are not copied; */
/* entries with invalid values are copied with status = pv_typecheck. */
props_from_stack(gs_prop_item
*plist
/* [count + acount] */, os_ptr op0
,
{ gs_prop_item
*pi
= plist
;
gs_prop_item
*pai
= plist
+ count
;
for ( ; count
; op
+= 2, count
-- )
if ( !r_has_type(op
- 1, t_name
) ) return e_typecheck
;
name_string_ref(op
- 1, &sref
);
pi
->pname
= (char *)sref
.value
.bytes
;
pi
->name_size
= r_size(&sref
);
pi
->value
.i
= op
->value
.intval
;
pi
->value
.f
= op
->value
.realval
;
pi
->value
.b
= op
->value
.index
;
name_string_ref(op
, &sref
);
pi
->value
.a
.p
.s
= (char *)op
->value
.bytes
;
nst
: pi
->value
.a
.size
= r_size(&sref
);
{ uint size
= r_size(op
);
gs_prop_type tv
= prt_int
;
pi
->type
= prt_int_array
;
for ( i
= 0; i
< size
; i
++ )
array_get(op
, (long)i
, &rnum
);
pi
->type
= prt_float_array
;
pv
++->value
.f
= rnum
.value
.realval
;
pv
++->value
.i
= rnum
.value
.intval
;
pv
++->value
.f
= rnum
.value
.intval
;
pi
->status
= pv_typecheck
;
pi
->status
= pv_typecheck
;