2 |
- |
1 |
/* Copyright (C) 1990, 2000 Aladdin Enterprises. All rights reserved.
|
|
|
2 |
|
|
|
3 |
This software is provided AS-IS with no warranty, either express or
|
|
|
4 |
implied.
|
|
|
5 |
|
|
|
6 |
This software is distributed under license and may not be copied,
|
|
|
7 |
modified or distributed except as expressly authorized under the terms
|
|
|
8 |
of the license contained in the file LICENSE in this distribution.
|
|
|
9 |
|
|
|
10 |
For more information about licensing, please refer to
|
|
|
11 |
http://www.ghostscript.com/licensing/. For information on
|
|
|
12 |
commercial licensing, go to http://www.artifex.com/licensing/ or
|
|
|
13 |
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
|
|
|
14 |
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
/* $Id: zbseq.c,v 1.6 2002/02/21 22:24:54 giles Exp $ */
|
|
|
18 |
/* Level 2 binary object sequence operators */
|
|
|
19 |
#include "memory_.h"
|
|
|
20 |
#include "ghost.h"
|
|
|
21 |
#include "gxalloc.h" /* for names_array in allocator */
|
|
|
22 |
#include "oper.h"
|
|
|
23 |
#include "ialloc.h"
|
|
|
24 |
#include "istruct.h"
|
|
|
25 |
#include "btoken.h"
|
|
|
26 |
#include "store.h"
|
|
|
27 |
|
|
|
28 |
/*
|
|
|
29 |
* Define the structure that holds the t_*array ref for the system or
|
|
|
30 |
* user name table.
|
|
|
31 |
*/
|
|
|
32 |
typedef struct names_array_ref_s {
|
|
|
33 |
ref names;
|
|
|
34 |
} names_array_ref_t;
|
|
|
35 |
gs_private_st_ref_struct(st_names_array_ref, names_array_ref_t,
|
|
|
36 |
"names_array_ref_t");
|
|
|
37 |
|
|
|
38 |
/* Create a system or user name table (in the stable memory of mem). */
|
|
|
39 |
int
|
|
|
40 |
create_names_array(ref **ppnames, gs_memory_t *mem, client_name_t cname)
|
|
|
41 |
{
|
|
|
42 |
ref *pnames = (ref *)
|
|
|
43 |
gs_alloc_struct(gs_memory_stable(mem), names_array_ref_t,
|
|
|
44 |
&st_names_array_ref, cname);
|
|
|
45 |
|
|
|
46 |
if (pnames == 0)
|
|
|
47 |
return_error(e_VMerror);
|
|
|
48 |
make_empty_array(pnames, a_readonly);
|
|
|
49 |
*ppnames = pnames;
|
|
|
50 |
return 0;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/* Initialize the binary token machinery. */
|
|
|
54 |
private int
|
|
|
55 |
zbseq_init(i_ctx_t *i_ctx_p)
|
|
|
56 |
{
|
|
|
57 |
/* Initialize a fake system name table. */
|
|
|
58 |
/* PostScript code will install the real system name table. */
|
|
|
59 |
ref *psystem_names = 0;
|
|
|
60 |
int code = create_names_array(&psystem_names, imemory_global,
|
|
|
61 |
"zbseq_init(system_names)");
|
|
|
62 |
|
|
|
63 |
if (code < 0)
|
|
|
64 |
return code;
|
|
|
65 |
system_names_p = psystem_names;
|
|
|
66 |
return 0;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/* <names> .installsystemnames - */
|
|
|
70 |
private int
|
|
|
71 |
zinstallsystemnames(i_ctx_t *i_ctx_p)
|
|
|
72 |
{
|
|
|
73 |
os_ptr op = osp;
|
|
|
74 |
|
|
|
75 |
if (r_space(op) != avm_global || imemory_save_level(iimemory_global) != 0)
|
|
|
76 |
return_error(e_invalidaccess);
|
|
|
77 |
check_read_type(*op, t_shortarray);
|
|
|
78 |
ref_assign_old(NULL, system_names_p, op, ".installsystemnames");
|
|
|
79 |
pop(1);
|
|
|
80 |
return 0;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/* - currentobjectformat <int> */
|
|
|
84 |
private int
|
|
|
85 |
zcurrentobjectformat(i_ctx_t *i_ctx_p)
|
|
|
86 |
{
|
|
|
87 |
os_ptr op = osp;
|
|
|
88 |
|
|
|
89 |
push(1);
|
|
|
90 |
*op = ref_binary_object_format;
|
|
|
91 |
return 0;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/* <int> setobjectformat - */
|
|
|
95 |
private int
|
|
|
96 |
zsetobjectformat(i_ctx_t *i_ctx_p)
|
|
|
97 |
{
|
|
|
98 |
os_ptr op = osp;
|
|
|
99 |
ref cont;
|
|
|
100 |
|
|
|
101 |
check_type(*op, t_integer);
|
|
|
102 |
if (op->value.intval < 0 || op->value.intval > 4)
|
|
|
103 |
return_error(e_rangecheck);
|
|
|
104 |
make_struct(&cont, avm_local, ref_binary_object_format_container);
|
|
|
105 |
ref_assign_old(&cont, &ref_binary_object_format, op, "setobjectformat");
|
|
|
106 |
pop(1);
|
|
|
107 |
return 0;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/* <ref_offset> <char_offset> <obj> <string8> .bosobject */
|
|
|
111 |
/* <ref_offset'> <char_offset'> <string8> */
|
|
|
112 |
/*
|
|
|
113 |
* This converts a single object to its binary object sequence
|
|
|
114 |
* representation, doing the dirty work of printobject and writeobject.
|
|
|
115 |
* (The main control is in PostScript code, so that we don't have to worry
|
|
|
116 |
* about interrupts or callouts in the middle of writing the various data
|
|
|
117 |
* items.) Note that this may or may not modify the 'unused' field.
|
|
|
118 |
*/
|
|
|
119 |
|
|
|
120 |
private int
|
|
|
121 |
zbosobject(i_ctx_t *i_ctx_p)
|
|
|
122 |
{
|
|
|
123 |
os_ptr op = osp;
|
|
|
124 |
int code;
|
|
|
125 |
|
|
|
126 |
check_type(op[-3], t_integer);
|
|
|
127 |
check_type(op[-2], t_integer);
|
|
|
128 |
check_write_type(*op, t_string);
|
|
|
129 |
if (r_size(op) < 8)
|
|
|
130 |
return_error(e_rangecheck);
|
|
|
131 |
code = encode_binary_token(i_ctx_p, op - 1, &op[-3].value.intval,
|
|
|
132 |
&op[-2].value.intval, op->value.bytes);
|
|
|
133 |
if (code < 0)
|
|
|
134 |
return code;
|
|
|
135 |
op[-1] = *op;
|
|
|
136 |
r_set_size(op - 1, 8);
|
|
|
137 |
pop(1);
|
|
|
138 |
return 0;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
/* ------ Initialization procedure ------ */
|
|
|
142 |
|
|
|
143 |
const op_def zbseq_l2_op_defs[] =
|
|
|
144 |
{
|
|
|
145 |
op_def_begin_level2(),
|
|
|
146 |
{"1.installsystemnames", zinstallsystemnames},
|
|
|
147 |
{"0currentobjectformat", zcurrentobjectformat},
|
|
|
148 |
{"1setobjectformat", zsetobjectformat},
|
|
|
149 |
{"4.bosobject", zbosobject},
|
|
|
150 |
op_def_end(zbseq_init)
|
|
|
151 |
};
|