ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/plotout.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: +3 -2 lines
Log Message:
Various compatibility fixes.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.3 static const char RCSid[] = "$Id: plotout.c,v 1.2 2003/07/01 21:21:40 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * Program to send meta-files to plot(3X) drivers
6     *
7     * cc -o plotout plotout.c mfio.o syscalls.o misc.o -lplot
8     *
9     * Plot drivers
10     */
11    
12    
13     #ifdef FORTEK
14     #define XCOM "pexpand +vOCIsm -rtpSUR %s"
15     #else
16     #define XCOM "pexpand +vOCIs -rtpSUR %s"
17     #endif
18    
19    
20    
21    
22     #include <fcntl.h>
23    
24 schorsch 1.3 #include "rtprocess.h"
25 greg 1.1 #include "meta.h"
26    
27    
28    
29    
30     char *progname;
31    
32     static short newpage = TRUE;
33    
34     static int curx = -1, /* current position */
35     cury = -1;
36    
37     static short curmod = -1; /* current line drawing mode */
38    
39     static char lmode[4][16] = {"solid", "shortdashed",
40     "dotted", "dotdashed"};
41    
42     static PRIMITIVE nextp;
43    
44    
45    
46     main(argc, argv)
47    
48     int argc;
49     char **argv;
50    
51     {
52 schorsch 1.3 FILE *fp;
53 greg 1.1 char comargs[200], command[300];
54     short condonly = FALSE, conditioned = FALSE;
55    
56     progname = *argv++;
57     argc--;
58    
59     while (argc && **argv == '-') {
60     switch (*(*argv+1)) {
61     case 'c':
62     condonly = TRUE;
63     break;
64     case 'r':
65     conditioned = TRUE;
66     break;
67     default:
68     error(WARNING, "unknown option");
69     break;
70     }
71     argv++;
72     argc--;
73     }
74    
75     if (conditioned)
76     if (argc)
77     while (argc) {
78     fp = efopen(*argv, "r");
79     plot(fp);
80     fclose(fp);
81     argv++;
82     argc--;
83     }
84     else
85     plot(stdin);
86     else {
87     comargs[0] = '\0';
88     while (argc) {
89     strcat(comargs, " ");
90     strcat(comargs, *argv);
91     argv++;
92     argc--;
93     }
94     sprintf(command, XCOM, comargs);
95     if (condonly)
96     return(system(command));
97     else {
98     if ((fp = popen(command, "r")) == NULL)
99     error(SYSTEM, "cannot execute input filter");
100     plot(fp);
101     pclose(fp);
102     }
103     }
104    
105     return(0);
106     }
107    
108    
109    
110    
111    
112     plot(infp) /* plot meta-file */
113    
114     FILE *infp;
115    
116     {
117    
118     openpl();
119     space(0, 0, XYSIZE, XYSIZE);
120    
121     do {
122     readp(&nextp, infp);
123     while (isprim(nextp.com)) {
124     doprim(&nextp);
125     fargs(&nextp);
126     readp(&nextp, infp);
127     }
128     doglobal(&nextp);
129     fargs(&nextp);
130     } while (nextp.com != PEOF);
131    
132     closepl();
133    
134     }
135    
136    
137    
138    
139    
140     doglobal(g) /* execute a global command */
141    
142     PRIMITIVE *g;
143    
144     {
145     int tty;
146     char c;
147    
148     switch (g->com) {
149    
150     case PEOF:
151     break;
152    
153     case PDRAW:
154     fflush(stdout);
155     break;
156    
157     case PEOP:
158     newpage = TRUE;
159     if (!isatty(fileno(stdout)))
160     break;
161     /* fall through */
162    
163 greg 1.2 case PPAUS:
164 greg 1.1 fflush(stdout);
165     tty = open(TTY, O_RDWR);
166     if (g->args != NULL) {
167     write(tty, g->args, strlen(g->args));
168     write(tty, " - (hit return to continue)", 27);
169     } else
170     write(tty, "\007", 1);
171     do {
172     c = '\n';
173     read(tty, &c, 1);
174     } while (c != '\n' && c != '\r');
175     close(tty);
176     break;
177    
178     default:
179     sprintf(errmsg, "unknown command '%c' in doglobal", g->com);
180     error(WARNING, errmsg);
181     break;
182     }
183    
184     }
185    
186    
187    
188    
189     doprim(p) /* plot primitive */
190    
191     register PRIMITIVE *p;
192    
193     {
194    
195     if (newpage) {
196     erase();
197     newpage = FALSE;
198     }
199    
200     switch (p->com) {
201    
202     case PLSEG:
203     plotlseg(p);
204     break;
205    
206     case PMSTR:
207     printstr(p);
208     break;
209    
210     default:
211     sprintf(errmsg, "unknown command '%c' in doprim", p->com);
212     error(WARNING, errmsg);
213     return;
214     }
215    
216     }
217    
218    
219    
220    
221    
222    
223     printstr(p) /* output a string */
224    
225     register PRIMITIVE *p;
226    
227     {
228    
229     move(p->xy[XMN], p->xy[YMX]);
230     label(p->args);
231     curx = -1;
232     cury = -1;
233    
234     }
235    
236    
237    
238    
239    
240     plotlseg(p) /* plot a line segment */
241    
242     register PRIMITIVE *p;
243    
244     {
245     static short right = FALSE;
246     int y1, y2;
247     short lm = (p->arg0 >> 4) & 03;
248    
249     if (p->arg0 & 0100) {
250     y1 = p->xy[YMX];
251     y2 = p->xy[YMN];
252     } else {
253     y1 = p->xy[YMN];
254     y2 = p->xy[YMX];
255     }
256    
257     if (lm != curmod) {
258     linemod(lmode[lm]);
259     curmod = lm;
260     }
261    
262     if (p->xy[XMN] == curx && y1 == cury) {
263     cont(p->xy[XMX], y2);
264     curx = p->xy[XMX];
265     cury = y2;
266     } else if (p->xy[XMX] == curx && y2 == cury) {
267     cont(p->xy[XMN], y1);
268     curx = p->xy[XMN];
269     cury = y1;
270     } else if (right = !right) {
271     line(p->xy[XMN], y1, p->xy[XMX], y2);
272     curx = p->xy[XMX];
273     cury = y2;
274     } else {
275     line(p->xy[XMX], y2, p->xy[XMN], y1);
276     curx = p->xy[XMN];
277     cury = y1;
278     }
279     }