ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/plotout.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

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