]> git.ipfire.org Git - thirdparty/cups.git/blob - pstoraster/zbseq.c
Import cups.org releases
[thirdparty/cups.git] / pstoraster / zbseq.c
1 /* Copyright (C) 1990, 1995, 1997, 1998 Aladdin Enterprises. All rights reserved.
2
3 This file is part of GNU Ghostscript.
4
5 GNU Ghostscript is distributed in the hope that it will be useful, but
6 WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
7 to anyone for the consequences of using it or for whether it serves any
8 particular purpose or works at all, unless he says so in writing. Refer
9 to the GNU General Public License for full details.
10
11 Everyone is granted permission to copy, modify and redistribute GNU
12 Ghostscript, but only under the conditions described in the GNU General
13 Public License. A copy of this license is supposed to have been given
14 to you along with GNU Ghostscript so you can know your rights and
15 responsibilities. It should be in a file named COPYING. Among other
16 things, the copyright notice and this notice must be preserved on all
17 copies.
18
19 Aladdin Enterprises supports the work of the GNU Project, but is not
20 affiliated with the Free Software Foundation or the GNU Project. GNU
21 Ghostscript, as distributed by Aladdin Enterprises, does not require any
22 GNU software to build or run it.
23 */
24
25 /*$Id$ */
26 /* Level 2 binary object sequence operators */
27 #include "memory_.h"
28 #include "ghost.h"
29 #include "oper.h"
30 #include "ialloc.h"
31 #include "btoken.h"
32 #include "store.h"
33
34 /* Current binary format (in iscan.c) */
35 extern ref ref_binary_object_format;
36
37 /* System and user name arrays. */
38 ref binary_token_names; /* array of size 2 */
39 private ref *const binary_token_names_p = &binary_token_names;
40
41 /* Import the Level 2 scanner extensions. */
42 typedef struct scanner_state_s scanner_state;
43 extern int scan_binary_token(P3(stream *, ref *, scanner_state *));
44 extern int (*scan_btoken_proc) (P3(stream *, ref *, scanner_state *));
45
46 /* Initialize the binary token machinery. */
47 private void
48 zbseq_init(void)
49 {
50 /* Initialize fake system and user name tables. */
51 /* PostScript code will install the real system name table. */
52 ialloc_ref_array(&binary_token_names, 0 /*a_noaccess */ , 2,
53 "binary token names");
54 make_empty_array(system_names_p, a_readonly);
55 make_empty_array(user_names_p, a_all);
56 gs_register_ref_root(imemory, NULL, (void **)&binary_token_names_p,
57 "binary token names");
58
59 /* Set up Level 2 scanning constants. */
60 scan_btoken_proc = scan_binary_token;
61 }
62
63 /* <names> .installsystemnames - */
64 private int
65 zinstallsystemnames(register os_ptr op)
66 {
67 if (r_space(op) != avm_global)
68 return_error(e_invalidaccess);
69 check_read_type(*op, t_shortarray);
70 ref_assign_old(NULL, system_names_p, op, ".installsystemnames");
71 pop(1);
72 return 0;
73 }
74
75 /* - currentobjectformat <int> */
76 private int
77 zcurrentobjectformat(register os_ptr op)
78 {
79 push(1);
80 *op = ref_binary_object_format;
81 return 0;
82 }
83
84 /* <int> setobjectformat - */
85 private int
86 zsetobjectformat(register os_ptr op)
87 {
88 check_type(*op, t_integer);
89 if (op->value.intval < 0 || op->value.intval > 4)
90 return_error(e_rangecheck);
91 ref_assign_old(NULL, &ref_binary_object_format, op, "setobjectformat");
92 pop(1);
93 return 0;
94 }
95
96 /* <ref_offset> <char_offset> <obj> <string8> .bosobject */
97 /* <ref_offset'> <char_offset'> <string8> */
98 /*
99 * This converts a single object to its binary object sequence
100 * representation, doing the dirty work of printobject and writeobject.
101 * (The main control is in PostScript code, so that we don't have to worry
102 * about interrupts or callouts in the middle of writing the various data
103 * items.) Note that this may or may not modify the 'unused' field.
104 */
105
106 private int
107 zbosobject(os_ptr op)
108 {
109 int code;
110
111 check_type(op[-3], t_integer);
112 check_type(op[-2], t_integer);
113 check_write_type(*op, t_string);
114 if (r_size(op) < 8)
115 return_error(e_rangecheck);
116 code = encode_binary_token(op - 1, &op[-3].value.intval,
117 &op[-2].value.intval, op->value.bytes);
118 if (code < 0)
119 return code;
120 op[-1] = *op;
121 r_set_size(op - 1, 8);
122 pop(1);
123 return 0;
124 }
125
126 /* ------ Initialization procedure ------ */
127
128 const op_def zbseq_l2_op_defs[] =
129 {
130 op_def_begin_level2(),
131 {"1.installsystemnames", zinstallsystemnames},
132 {"0currentobjectformat", zcurrentobjectformat},
133 {"1setobjectformat", zsetobjectformat},
134 {"4.bosobject", zbosobject},
135 op_def_end(zbseq_init)
136 };