]> git.ipfire.org Git - thirdparty/cups.git/blob - pstoraster/zmisc3.c
Import cups.org releases
[thirdparty/cups.git] / pstoraster / zmisc3.c
1 /* Copyright (C) 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 /* Miscellaneous LanguageLevel 3 operators */
27 #include "ghost.h"
28 #include "gsclipsr.h"
29 #include "oper.h"
30 #include "igstate.h"
31 #include "store.h"
32
33 /* - clipsave - */
34 private int
35 zclipsave(os_ptr op)
36 {
37 return gs_clipsave(igs);
38 }
39
40 /* - cliprestore - */
41 private int
42 zcliprestore(os_ptr op)
43 {
44 return gs_cliprestore(igs);
45 }
46
47 /* <proc1> <proc2> .eqproc <bool> */
48 /*
49 * Test whether two procedures are equal to depth 10.
50 * This is the equality test used by idiom recognition in 'bind'.
51 */
52 #define MAX_DEPTH 10 /* depth is per Adobe specification */
53 typedef struct ref2_s {
54 ref proc1, proc2;
55 } ref2_t;
56 private int
57 zeqproc(register os_ptr op)
58 {
59 ref2_t stack[MAX_DEPTH + 1];
60 ref2_t *top = stack;
61
62 make_array(&stack[0].proc1, 0, 1, op - 1);
63 make_array(&stack[0].proc2, 0, 1, op);
64 for (;;) {
65 long i;
66
67 if (r_size(&top->proc1) == 0) {
68 /* Finished these arrays, go up to next level. */
69 if (top == stack) {
70 /* We're done matching: it succeeded. */
71 make_true(op - 1);
72 pop(1);
73 return 0;
74 }
75 --top;
76 continue;
77 }
78 /* Look at the next elements of the arrays. */
79 i = r_size(&top->proc1) - 1;
80 array_get(&top->proc1, i, &top[1].proc1);
81 array_get(&top->proc2, i, &top[1].proc2);
82 r_dec_size(&top->proc1, 1);
83 ++top;
84 /*
85 * Amazingly enough, the objects' executable attributes are not
86 * required to match. This means { x load } will match { /x load },
87 * even though this is clearly wrong.
88 */
89 #if 0
90 if (r_has_attr(&top->proc1, a_executable) !=
91 r_has_attr(&top->proc2, a_executable)
92 )
93 break;
94 #endif
95 if (obj_eq(&top->proc1, &top->proc2)) {
96 /* Names don't match strings. */
97 if (r_type(&top->proc1) != r_type(&top->proc2) &&
98 (r_type(&top->proc1) == t_name ||
99 r_type(&top->proc2) == t_name)
100 )
101 break;
102 --top; /* no recursion */
103 continue;
104 }
105 if (r_is_array(&top->proc1) && r_is_array(&top->proc2) &&
106 r_size(&top->proc1) == r_size(&top->proc2) &&
107 top < stack + (MAX_DEPTH - 1)
108 ) {
109 /* Descend into the arrays. */
110 continue;
111 }
112 break;
113 }
114 /* An exit from the loop indicates that matching failed. */
115 make_false(op - 1);
116 pop(1);
117 return 0;
118 }
119
120 /* ------ Initialization procedure ------ */
121
122 const op_def zmisc3_op_defs[] =
123 {
124 op_def_begin_ll3(),
125 {"0cliprestore", zcliprestore},
126 {"0clipsave", zclipsave},
127 {"2.eqproc", zeqproc},
128 op_def_end(0)
129 };