ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/aed5.c
Revision: 1.3
Committed: Mon Oct 27 10:28:59 2003 UTC (20 years, 6 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.2: +4 -2 lines
Log Message:
Various compatibility fixes.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: aed5.c,v 1.2 2003/07/01 21:21:40 greg Exp $";
3 #endif
4 /*
5 * aed.c - driver for AED 512 terminal.
6 *
7 * 7/8/86
8 */
9
10 #include <fcntl.h>
11
12 #include "platform.h"
13 #include "rtprocess.h"
14 #include "meta.h"
15
16
17 /* AED command characters */
18
19 #define AEDFMT "1888N" /* Format string to send to AED */
20 #define SCT 75 /* Set color lookup table */
21 #define SEC 67 /* Set color for vector drawing */
22 #define SBC 91 /* Set background color */
23 #define MOV 81 /* Set CAP (current access pointer) to x, y */
24 #define MVR 105 /* Set CAP relative */
25 #define DVA 65 /* Draw vector to new CAP x, y */
26 #define DVR 108 /* Draw vector relative */
27 #define WHR 92 /* Write horizontal runs */
28 #define OPT 40 /* Miscellaneous terminal control */
29 #define SEN 71 /* Set encoding types */
30 #define RST 48 /* Reset terminal */
31 #define FFD 12 /* Clear screen */
32 #define SCS 96 /* Set status */
33 #define DAI 114 /* Define area of interest */
34 #define EJC 85 /* Enable Joystick cursor positioning */
35 #define DJC 100 /* Disable Joystick cursor positioning */
36 #define SCC 99 /* Set Cursor Colors */
37 #define SCP 93 /* Set Cursor Parameters */
38 #define RCP 106 /* Read Cursor Position */
39 #define SAP 94 /* Set alphanumeric parameters */
40 #define SLS 49 /* Set Line Style */
41 #define DFR 111 /* Draw Filled Rectangle */
42 #define MAXRLEN 255 /* Maximum runlength for a span */
43 #define NUL 0 /* Null terminates run sequences */
44 #define ESC 27 /* Escape starts a command sequence */
45 #define END 1 /* Ctrl-A used to terminate command mode */
46
47 #define command(c) (putc(ESC, stdout), putc(c, stdout))
48 #define byte(b) putc(b, stdout)
49 #define ascii(c) putc(c, stdout)
50
51 #define BKGCOL 7 /* Background color (white) */
52
53 #define NROWS 512 /* # rows for output */
54 #define NCOLS 512 /* # columns for output */
55
56 #define xconv(x) CONV(x, NCOLS)
57 #define yconv(y) CONV(y, NROWS)
58
59 #define XCOM "pexpand +vOCIs -tpSUR %s"
60
61 char *progname;
62
63 static short newpage = TRUE;
64
65 static int curx = -1, /* current position */
66 cury = -1;
67
68 static int curcol = -1; /* current color */
69
70 static short curmod = -1; /* current line drawing mode */
71
72 static short cmode[4] = {0, 1, 2, 4}; /* color map */
73
74 static short lmode[4] = {255, 15, 85, 39}; /* line map */
75
76 static PRIMITIVE nextp;
77
78
79
80 main(argc, argv)
81 int argc;
82 char **argv;
83 {
84 FILE *fp;
85 char comargs[200], shcom[300];
86 short condonly = FALSE, conditioned = FALSE;
87
88 progname = *argv++;
89 argc--;
90
91 while (argc && **argv == '-') {
92 switch (*(*argv+1)) {
93 case 'c':
94 condonly = TRUE;
95 break;
96 case 'r':
97 conditioned = TRUE;
98 break;
99 default:
100 error(WARNING, "unknown option");
101 break;
102 }
103 argv++;
104 argc--;
105 }
106
107 if (conditioned) {
108 init();
109 if (argc)
110 while (argc) {
111 fp = efopen(*argv, "r");
112 plot(fp);
113 fclose(fp);
114 argv++;
115 argc--;
116 }
117 else
118 plot(stdin);
119 } else {
120 comargs[0] = '\0';
121 while (argc) {
122 strcat(comargs, " ");
123 strcat(comargs, *argv);
124 argv++;
125 argc--;
126 }
127 sprintf(shcom, XCOM, comargs);
128 if (condonly)
129 return(system(shcom));
130 else {
131 init();
132 if ((fp = popen(shcom, "r")) == NULL)
133 error(SYSTEM, "cannot execute input filter");
134 plot(fp);
135 return(pclose(fp));
136 }
137 }
138 return(0);
139 }
140
141
142
143
144
145 plot(infp) /* plot meta-file */
146
147 FILE *infp;
148
149 {
150
151 do {
152 readp(&nextp, infp);
153 while (isprim(nextp.com)) {
154 doprim(&nextp);
155 fargs(&nextp);
156 readp(&nextp, infp);
157 }
158 doglobal(&nextp);
159 fargs(&nextp);
160 }
161 while (nextp.com != PEOF);
162
163 }
164
165
166
167
168
169 doglobal(g) /* execute a global command */
170
171 PRIMITIVE *g;
172
173 {
174 int tty;
175 char c;
176
177 switch (g->com) {
178
179 case PEOF:
180 break;
181
182 case PDRAW:
183 fflush(stdout);
184 break;
185
186 case PEOP:
187 newpage = TRUE;
188 if (!isatty(fileno(stdout)))
189 break;
190 /* fall through */
191
192 case PPAUS:
193 fflush(stdout);
194 tty = open(TTY, O_RDWR);
195 if (g->args != NULL) {
196 write(tty, g->args, strlen(g->args));
197 write(tty, " - (hit return to continue)", 27);
198 }
199 else
200 write(tty, "\007", 1);
201 do {
202 c = '\n';
203 read(tty, &c, 1);
204 }
205 while (c != '\n' && c != '\r');
206 close(tty);
207 break;
208
209 default:
210 sprintf(errmsg, "unknown command '%c' in doglobal", g->com);
211 error(WARNING, errmsg);
212 break;
213 }
214
215 }
216
217
218
219
220 doprim(p) /* plot primitive */
221
222 register PRIMITIVE *p;
223
224 {
225
226 if (newpage) { /* clear screen */
227 command(FFD);
228 shortwait(50);
229 newpage = FALSE;
230 }
231
232 switch (p->com) {
233
234 case PLSEG:
235 plotlseg(p);
236 break;
237
238 case PMSTR:
239 printstr(p);
240 break;
241
242 case PRFILL:
243 fillrect(p);
244 break;
245
246 default:
247 sprintf(errmsg, "unknown command '%c' in doprim", p->com);
248 error(WARNING, errmsg);
249 return;
250 }
251
252 }
253
254
255
256
257
258
259 printstr(p) /* output a string */
260
261 register PRIMITIVE *p;
262
263 {
264 static int hsp[4] = {6, 5, 4, 3};
265 char font, size;
266 int hspace, vspace = 18;
267
268 hspace = hsp[(p->arg0 >> 4) & 03];
269
270 if (p->arg0 & 04)
271 hspace *= 2;
272
273 if (hspace > 16) {
274 font = '7'; size = '2';
275 } else if (hspace > 12) {
276 font = '5'; size = '2';
277 } else if (hspace > 8) {
278 font = '7'; size = '1';
279 } else {
280 font = '5'; size = '1';
281 }
282
283 command(SAP);
284 ascii(size); ascii(font);
285 byte(hspace); byte(vspace);
286 ascii('L');
287
288 setcolor(p->arg0 & 03);
289
290 move(p->xy[XMN], p->xy[YMX]);
291
292 putc(END, stdout);
293 fputs(p->args, stdout);
294
295 curx = -1;
296 cury = -1;
297 }
298
299
300
301
302
303 plotlseg(p) /* plot a line segment */
304
305 register PRIMITIVE *p;
306
307 {
308 static short right = FALSE;
309 int y1, y2;
310 short lm = (p->arg0 >> 4) & 03;
311
312 if (p->arg0 & 0100) {
313 y1 = p->xy[YMX];
314 y2 = p->xy[YMN];
315 }
316 else {
317 y1 = p->xy[YMN];
318 y2 = p->xy[YMX];
319 }
320
321 setcolor(p->arg0 & 03);
322
323 if (lm != curmod) {
324 command(SLS);
325 byte(lmode[lm]); byte(85);
326 curmod = lm;
327 }
328
329 if (p->xy[XMN] == curx && y1 == cury)
330 draw(p->xy[XMX], y2);
331 else if (p->xy[XMX] == curx && y2 == cury)
332 draw(p->xy[XMN], y1);
333 else if (right = !right) {
334 move(p->xy[XMN], y1);
335 draw(p->xy[XMX], y2);
336 } else {
337 move(p->xy[XMX], y2);
338 draw(p->xy[XMN], y1);
339 }
340 }
341
342
343 fillrect(p)
344
345 register PRIMITIVE *p;
346
347 {
348
349 setcolor(p->arg0 & 03);
350 move(p->xy[XMN], p->xy[YMN]);
351 curx = xconv(p->xy[XMX]);
352 cury = yconv(p->xy[YMX]);
353 command(DFR);
354 aedcoord(curx, cury);
355
356 }
357
358 init() /* initialize terminal */
359 {
360 /* Reset AED and tell it the data format */
361 command(RST);
362 longwait(2);
363 command(OPT);
364 byte(6); byte(1); /* AED command set */
365 command(SEN); fputs(AEDFMT, stdout);
366 command(SBC); byte(BKGCOL);
367 }
368
369
370 setcolor(cn) /* set color */
371 int cn;
372 {
373 if (cn != curcol) {
374 command(SEC);
375 byte(cmode[cn]);
376 curcol = cn;
377 }
378 }
379
380
381 move(x, y) /* move to coordinate (x,y) */
382 int x, y;
383 {
384 command(MOV);
385 aedcoord(xconv(x), yconv(y));
386 curx = x;
387 cury = y;
388 }
389
390
391 draw(x, y) /* draw vector from CAP to (x,y) */
392 int x, y;
393 {
394 command(DVA);
395 aedcoord(xconv(x), yconv(y));
396 curx = x;
397 cury = y;
398 }
399
400
401 /*
402 * aedcoord - puts out an (x, y) coordinate in AED 8 bit format.
403 */
404
405 aedcoord(x, y)
406 register int x, y;
407 {
408 putc(((x >> 4) & 0x30) | ((y >> 8) & 0x3), stdout);
409 putc(x & 0xff, stdout);
410 putc(y & 0xff, stdout);
411 }
412
413
414 longwait(t) /* longer wait */
415 int t;
416 {
417 fflush(stdout);
418 sleep(t);
419 }
420
421
422 shortwait(t) /* shorter wait */
423 int t;
424 {
425 register long l = t*1000;
426
427 fflush(stdout);
428 while (l--)
429 ;
430 }