|
|
1.1 root 1: /*
2: This is version 4. The input language is:
3:
4: Cmd Abbrev Operands / Comments
5: comment # only at start of line
6: blank b s <vnum> start blanking; erase commands follow
7: e <vnum> end blanking current view
8: click c <clicknum>
9: define d v <number> <viewname> xmin ymin xmax ymax
10: c <number> <clickname>
11: p e pragma -- end of defs at front of file
12: Other possible ``pragmas'': ???
13: Number of views, clicks
14: Number of (lines, bytes) in file
15: erase e <line repeated here, except for leading g>
16: Object is deletable
17: geom g <slotn> l <vnum> <opts> <x1> <y1> <x2> <y2> line
18: b <vnum> <opts> <x1> <y1> <x2> <y2> box
19: c <vnum> <opts> <x> <y> <rad> circle
20: t <vnum> <opts> <x> <y> <text string> text
21: one separating blank; string unquoted
22: <opts> format: string of characters, in order
23: <slotn> == 0 => line never erased
24:
25: At beginning of file:
26: d v <number> <view name>
27: d c <number> <click name>
28: d p <various pragmas here>
29: d p e
30:
31: */
32:
33: #include <stdio.h>
34: #include "anim.h"
35:
36: #define sendpoint(p) { sendint(p.x); sendint(p.y); }
37: #define sendpair(x,y) { sendint(x); sendint(y); }
38: #define eq(s, t) (strcmp(s,t) == 0)
39: #define FATAL 1
40:
41: char *cmdname;
42: char *emalloc();
43:
44: #ifdef BLIT
45: long memsize = 65000; /* memory allocation */
46: #endif
47: #ifdef X11
48: long memsize = 200000; /* X11 memory allocation */
49: #endif
50:
51: int dbg = 0;
52: int lineno = 1; /* ? */
53:
54: char *zload = ""; /* will be -z for load and hang on blit */
55: char *termld = TERMLD; /* will be "32ld" or "dmdld" */
56: int nterm = 0; /* number of bytes needed in terminal */
57:
58: main(argc, argv)
59: char *argv[];
60: {
61: FILE *fp;
62: char *term_process = ANIMTERM; /* typically "./animterm" */
63: char buf[100];
64: int i, c, bootstat;
65:
66: cmdname = argv[0];
67: while (argc > 1 && argv[1][0] == '-') {
68: switch (argv[1][1]) {
69: case 'd':
70: dbg = !dbg;
71: break;
72: case 'z':
73: zload = "-z";
74: break;
75: case 't':
76: term_process = argv[2];
77: argc--;
78: argv++;
79: break;
80: case 'm':
81: memsize = atoi(&argv[1][2]);
82: if (memsize <= 0) {
83: memsize = atoi(argv[2]);
84: if (memsize <= 0)
85: error(FATAL, "memory size must be positive. use -mN");
86: argc--;
87: argv++;
88: }
89: break;
90: }
91: argc--;
92: argv++;
93: }
94: if (argc <= 1)
95: error(FATAL, "no input file");
96: if ((fp = fopen(argv[1], "r")) == NULL)
97: error(FATAL, "can't open %s\n", argv[1]);
98: if (!dbg) {
99: bootstat = bootterm(term_process);
100: set_tty();
101: }
102: if (bootstat)
103: send_data(fp);
104: if (dbg) {
105: printf("\nterminal bytes needed: %d\n", nterm);
106: exit(0);
107: }
108: while ((c = readchar()) != P_QUIT) {
109: if (c == P_FILE) { /* rest of line is a filename */
110: readstring(buf);
111: if ((fp = fopen(buf, "r")) == NULL)
112: send1char(P_ERROR);
113: else {
114: send1char(P_FILE); /* ack */
115: send_data(fp);
116: }
117: } else
118: send1char(P_ERROR);
119: }
120: reset_tty();
121: }
122:
123: send_data(fp)
124: FILE *fp;
125: {
126: char text[100], buf[100], opts[100], *p;
127: int c, x1, y1, x2, y2, i, v, slot;
128: int ntext;
129:
130: sendint(memsize);
131: send1char(P_INIT);
132: send1char(P_PRINT);
133: sendstring("here comes the data!");
134: while ((c = getc(fp)) != EOF) {
135: switch (c) {
136: case ' ':
137: case '\t':
138: break;
139: case '\n':
140: lineno++; /* this should be the only increment */
141: break;
142: case '#': /* comments */
143: skipline(fp);
144: break;
145: case 'b': /* blank. ignore for now */
146: skipline(fp);
147: break;
148: case 'c': /* click */
149: fscanf(fp, "%d", &i);
150: send1char(P_OBJECT);
151: send1char(c);
152: sendint(i);
153: skipline(fp);
154: nterm += 3;
155: break;
156: case 'e': /* erase */
157: fscanf(fp, "%d", &i);
158: send1char(P_OBJECT);
159: send1char(c);
160: sendint(i);
161: skipline(fp);
162: nterm += 6;
163: break;
164: case 'g': /* geom: draw line, box, circle, ... */
165: fscanf(fp, "%d", &slot);
166: switch (c = skipbl(fp)) {
167: case 'l':
168: case 'b':
169: fscanf(fp, "%d %s %d %d %d %d", &v, opts, &x1, &y1, &x2, &y2);
170: send1char(P_OBJECT);
171: send1char(c);
172: sendint(slot);
173: sendint(v);
174: sendopt(c=='b' ? boxops : lineops, opts);
175: sendpair(x1, y1);
176: sendpair(x2, y2);
177: nterm += 12;
178: break;
179: case 'c': /* circle */
180: fscanf(fp, "%d %s %d %d %d", &v, opts, &x1, &y1, &x2);
181: send1char(P_OBJECT);
182: send1char('o'); /* 'o' is for circle */
183: sendint(slot);
184: sendint(v);
185: sendopt(circops, opts);
186: sendpair(x1, y1);
187: sendint(x2);
188: nterm += 10;
189: break;
190: case 't': /* text */
191: fscanf(fp, "%d %s %d %d", &v, opts, &x1, &y1);
192: send1char(P_OBJECT);
193: send1char('t');
194: sendint(slot);
195: sendint(v);
196: sendopt(textops, opts);
197: sendpair(x1, y1);
198: getc(fp); /* skip 1 separator; no quotes */
199: for (p = text; (c = getc(fp)) != '\n'; )
200: *p++ = c;
201: *p = 0;
202: ungetc('\n', fp);
203: ntext = 1;
204: /* slow... */
205: if (eq(text, "bullet"))
206: sendstring("*");
207: else if (eq(text, "dot"))
208: sendstring(".");
209: else if (eq(text, "circle"))
210: sendstring("o");
211: else if (eq(text, "times"))
212: sendstring("x");
213: else {
214: sendstring(text);
215: ntext = strlen(text);
216: }
217: nterm += 10 + ntext;
218: break;
219: default:
220: send1char(P_ERROR);
221: flushproto();
222: error(FATAL, "illegal g command: g %c", c);
223: break;
224: }
225: break;
226: case 'd': /* definition of some sort */
227: switch (c = skipbl(fp)) {
228: case 'v': /* view */
229: fscanf(fp, "%d %s", &i, text);
230: send1char(P_DEFINE);
231: send1char('v');
232: sendint(i);
233: sendstring(text);
234: skipline(fp); /* might be a title there */
235: break;
236: case 'c': /* click */
237: fscanf(fp, "%d %s", &i, text);
238: send1char(P_DEFINE);
239: send1char('c');
240: sendint(i);
241: sendstring(text);
242: break;
243: case 'p':
244: skipline(fp);
245: break;
246: default:
247: send1char(P_ERROR);
248: flushproto();
249: error(FATAL, "unknown define command d %c", c);
250: break;
251: }
252: break;
253: default:
254: send1char(P_ERROR);
255: flushproto();
256: error(FATAL, "unknown command %c", c);
257: break;
258: }
259: }
260: send1char(P_ENDFILE);
261: fclose(fp);
262: flushproto();
263: }
264:
265: sendopt(optvals, opts)
266: int optvals[];
267: char *opts;
268: {
269: int i, n;
270:
271: n = 0;
272: for (i = 0; optvals[i] && opts; i += 2)
273: if (*opts == optvals[i]) {
274: n += optvals[i+1];
275: opts++;
276: }
277: sendint(n);
278: }
279:
280: skipbl(fp)
281: FILE *fp;
282: {
283: int c;
284:
285: while ((c = getc(fp)) == ' ' || c == '\t')
286: ;
287: return c;
288: }
289:
290: skipline(fp)
291: FILE *fp;
292: {
293: int c;
294:
295: while ((c = getc(fp)) != '\n')
296: ;
297: ungetc('\n', fp);
298: }
299:
300: error(f, s, a1, a2, a3, a4, a5, a6, a7)
301: {
302: extern char *cmdname;
303: extern int dbg;
304:
305: fprintf(stderr, "%s: ", cmdname);
306: fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7);
307: fprintf(stderr, "\n");
308: if (lineno)
309: fprintf(stderr, " source line number %d\n", lineno);
310: if (f) {
311: if (dbg)
312: abort();
313: exit(2);
314: }
315: }
316:
317: #ifndef X11
318:
319: bootterm(procname)
320: char *procname;
321: {
322: char buf[100];
323:
324: sprintf(buf, "%s %s %s </dev/tty", termld, zload, procname);
325: if (system(buf) != 0) {
326: fprintf(stderr,
327: "anim: can't create pipe to terminal process\n");
328: return 0;
329: }
330: return 1;
331: }
332:
333: #endif
334:
335: #ifdef X11
336:
337: bootterm(procname)
338: char *procname;
339: {
340: int afildes[2], bfildes[2], pid;
341: if((pipe(afildes)==-1)||(pipe(bfildes)==-1)){
342: fprintf(stderr,
343: "anim: can't create pipe to terminal process\n");
344: return 0;
345: }
346: if((pid=fork())==0){
347: close(0);
348: dup(afildes[0]);
349: close(1);
350: dup(bfildes[1]);
351: execl(procname, "animterm", 0);
352: exit(127);
353: }
354: if(pid==-1){
355: fprintf(stderr,"anim: can't fork %s\n", procname);
356: return 0;
357: }
358: close(0);
359: dup(bfildes[0]);
360: close(1);
361: dup(afildes[1]);
362: return 1;
363: }
364:
365: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.