1: /* parse.c
2: *
3: * Copyright (c) 1984, 1985 Xerox Corp.
4: *
5: * Eight items are left on the stack when execution finishes.
6: * See the RES manual.
7: *
8: *
9: * pop() can be used to remove items from the stack.
10: * Please remember to free() any item you pop off the stack.
11: *
12: *
13: *
14: */
15:
16: #include <stdio.h>
17: #include <iptokens.h>
18:
19: FILE *fp;
20: long filepos = 0;
21:
22:
23: #define "Interpress/Xerox/2.1/RasterEncoding/1.0 "
24: #define 40
25:
26: #define token_id 0340
27: #define token_mask 0037
28: #define token_short_op 0200
29: #define token_long_op 0240
30: #define token_short_seq 0300
31: #define token_long_seq 0340
32:
33: parse(fpin)
34: FILE *fpin;
35: {
36: /* variables */
37: int c, len;
38: char string[len_RES_header+1];
39: int last = 0;
40: int seq;
41:
42: /* Get the header. */
43: fp = fpin;
44: fgets(string, len_RES_header+1, fp);
45: header(string, RES_header);
46:
47: /* Analyze every token in the file. */
48: while ((c = getc(fp)) != EOF)
49: {
50: filepos = ftell(fp)-1;
51: switch (c & token_id)
52: {
53: case token_short_op: /* Only allowed short op is "nop". */
54: len = c & token_mask;
55: operator(len);
56: last = 0;
57: break;
58: case token_long_op:
59: len = getc(fp)+((c & token_mask) << 8);
60: if (operator(len)) return; /* Quit when you hit endBlock. */
61: last = 0;
62: break;
63: case token_short_seq:
64: len = getc(fp);
65: seq = c & token_mask;
66: sequence(seq, len, last);
67: if (seq != sequenceContinued) last = seq;
68: break;
69: case token_long_seq:
70: len = getc(fp) << 16;
71: len = len+(getc(fp) << 8);
72: len = len+getc(fp);
73: seq = c & token_mask;
74: sequence(seq, len, last);
75: if (seq != sequenceContinued) last = seq;
76: break;
77: default:
78: shortnum((c << 8)+getc(fp)-INTEGER_ZERO);
79: last = 0;
80: break;
81: }
82: }
83: /* Shouldn't get here if file ends properly! */
84: fprintf(stderr, "(%d) Unexpected EOF\n", filepos);
85: exit(2);
86: }
87:
88:
89: #ifndef debug
90: operator(op)
91: int op;
92: {
93: switch (op)
94: {
95: case OP_makevec: op_makevec(); break;
96: case OP_do: op_do(); break;
97: case OP_pop: op_pop(); break;
98: case OP_copy: op_copy(); break;
99: case OP_dup: op_dup(); break;
100: case OP_roll: op_roll(); break;
101: case OP_exch: op_exch(); break;
102: case OP_nop: op_nop(); break;
103: case OP_translate: op_translate(); break;
104: case OP_rotate: op_rotate(); break;
105: case OP_scale: op_scale(); break;
106: case OP_scale2: op_scale2(); break;
107: case OP_concat: op_concat(); break;
108: case OP_makepixelarray: op_makepixelarray(); break;
109: case : op_extractpixelarray(); break;
110: case OP_finddecompressor: op_finddecompressor(); break;
111: case OP_makegray: op_makegray(); break;
112: case OP_findcolor: op_findcolor(); break;
113: case OP_findcoloroperator: op_findcoloroperator(); break;
114: case OP_findcolormodeloperator: op_findcolormodeloperator(); break;
115: case OP_beginBlock: op_beginblock(); break;
116: case OP_endBlock: op_endblock(); return(1);
117: default: op_unknown(op); break;
118: }
119: return (0);
120: }
121:
122: sequence(type, len, last)
123: int type, len, last;
124: {
125: switch (type)
126: {
127: case sequenceAdaptivePixelVector: seq_adaptivepixel(len); break;
128: case : seq_comment(len); break;
129: case sequenceCompressedPixelVector: seq_compressedpixel(len); break;
130: case sequenceContinued: seq_continued(len, last); break;
131: case sequenceIdentifier: seq_identifier(len); break;
132: case sequenceInsertFile: seq_insertfile(len); break;
133: case sequenceInteger: seq_integer(len); break;
134: case sequenceLargeVector: seq_largevector(len); break;
135: case sequencePackedPixelVector: seq_packedpixel(len); break;
136: case sequenceRational: seq_rational(len); break;
137: case sequenceString: seq_string(len); break;
138: default: seq_unknown(type, len); break;
139: }
140: }
141:
142: #else
143: operator(op)
144: int op;
145: {
146: switch (op)
147: {
148: case OP_makevec:
149: fprintf(stderr, "op_makevec\n");
150: op_makevec();
151: break;
152: case OP_do:
153: fprintf(stderr, "op_do\n");
154: op_do();
155: break;
156: case OP_pop:
157: fprintf(stderr, "op_pop\n");
158: op_pop();
159: break;
160: case OP_copy:
161: fprintf(stderr, "op_copy\n");
162: op_copy();
163: break;
164: case OP_dup:
165: fprintf(stderr, "op_dup\n");
166: op_dup();
167: break;
168: case OP_roll:
169: fprintf(stderr, "op_roll\n");
170: op_roll();
171: break;
172: case OP_exch:
173: fprintf(stderr, "op_exch\n");
174: op_exch();
175: break;
176: case OP_nop:
177: fprintf(stderr, "op_nop\n");
178: op_nop();
179: break;
180: case OP_translate:
181: fprintf(stderr, "op_translate\n");
182: op_translate();
183: break;
184: case OP_rotate:
185: fprintf(stderr, "op_rotate\n");
186: op_rotate();
187: break;
188: case OP_scale:
189: fprintf(stderr, "op_scale\n");
190: op_scale();
191: break;
192: case OP_scale2:
193: fprintf(stderr, "op_scale2\n");
194: op_scale2();
195: break;
196: case OP_concat:
197: fprintf(stderr, "op_concat\n");
198: op_concat();
199: break;
200: case OP_makepixelarray:
201: fprintf(stderr, "op_makepixelarray\n");
202: op_makepixelarray();
203: break;
204: case OP_extractpixelarray:
205: fprintf(stderr, "op_extractpixelarray\n");
206: op_extractpixelarray();
207: break;
208: case OP_finddecompressor:
209: fprintf(stderr, "op_finddecompressor\n");
210: op_finddecompressor();
211: break;
212: case OP_makegray:
213: fprintf(stderr, "op_makegray\n");
214: op_makegray();
215: break;
216: case OP_findcolor:
217: fprintf(stderr, "op_findcolor\n");
218: op_findcolor();
219: break;
220: case OP_findcoloroperator:
221: fprintf(stderr, "op_findcoloroperator\n");
222: op_findcoloroperator();
223: break;
224: case OP_findcolormodeloperator:
225: fprintf(stderr, "op_findcolormodeloperator\n");
226: op_findcolormodeloperator();
227: break;
228: case OP_beginBlock:
229: fprintf(stderr, "op_beginblock\n");
230: op_beginblock();
231: break;
232: case OP_endBlock:
233: fprintf(stderr, "op_endblock\n");
234: op_endblock();
235: return(1);
236: default:
237: fprintf(stderr, "op_unknown\n");
238: op_unknown(op);
239: break;
240: }
241: return (0);
242: }
243:
244: sequence(type, len, last)
245: int type, len, last;
246: {
247: switch (type)
248: {
249: case sequenceAdaptivePixelVector:
250: fprintf(stderr, "seq_adaptivepixel\n");
251: seq_adaptivepixel(len);
252: break;
253: case sequenceComment:
254: fprintf(stderr, "seq_comment\n");
255: seq_comment(len);
256: break;
257: case sequenceCompressedPixelVector:
258: fprintf(stderr, "seq_compressedpixel\n");
259: seq_compressedpixel(len);
260: break;
261: case sequenceContinued:
262: fprintf(stderr, "seq_continued\n");
263: seq_continued(len, last);
264: break;
265: case sequenceIdentifier:
266: fprintf(stderr, "seq_identifier\n");
267: seq_identifier(len);
268: break;
269: case sequenceInsertFile:
270: fprintf(stderr, "seq_insertfile\n");
271: seq_insertfile(len);
272: break;
273: case sequenceInteger:
274: fprintf(stderr, "seq_integer\n");
275: seq_integer(len);
276: break;
277: case sequenceLargeVector:
278: fprintf(stderr, "seq_largevector\n");
279: seq_largevector(len);
280: break;
281: case sequencePackedPixelVector:
282: fprintf(stderr, "seq_packedpixel\n");
283: seq_packedpixel(len);
284: break;
285: case sequenceRational:
286: fprintf(stderr, "seq_rational\n");
287: seq_rational(len);
288: break;
289: case sequenceString:
290: fprintf(stderr, "seq_string\n");
291: seq_string(len);
292: break;
293: default:
294: fprintf(stderr, "seq_unknown\n");
295: seq_unknown(type, len);
296: break;
297: }
298: }
299:
300: #endif
301:
302: /* Change Log
303: *
304: * K. Knox, 28-Mar-85 18:26:50, Created first version.
305: *
306: *
307: *
308: */