ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/aed5.c
Revision: 1.2
Committed: Tue Jul 1 21:21:40 2003 UTC (20 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
Compile fixes for gcc 3.3

File Contents

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