ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/expand.c
Revision: 1.2
Committed: Sun Jun 8 12:03:10 2003 UTC (21 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.1: +43 -43 lines
Log Message:
Reduced compile warnings/errors on Windows.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: expand.c,v 1.1 2003/02/22 02:07:26 greg Exp $";
3 #endif
4 /*
5 * Expansion routine for command implementation
6 * on simple drivers
7 */
8
9
10 #include "meta.h"
11
12
13 /* vector characters file */
14 #define VINPUT "vchars.mta"
15
16 #define FIRSTCHAR ' ' /* first vector character */
17
18 #define LASTCHAR '~' /* last vector character */
19
20 #define PEPS 5 /* minimum size for fill area */
21
22 #define fillok(p) ((p)->xy[XMX] - (p)->xy[XMN] > PEPS && \
23 (p)->xy[YMX] - (p)->xy[YMN] > PEPS)
24
25
26
27 static short *xlist; /* pointer to expansion list */
28
29 static void exfile(FILE *fp);
30 static void exprim(PRIMITIVE *p);
31 static void sendmstr(register PRIMITIVE *p);
32 static void sendvstr(register PRIMITIVE *p);
33 static void include(int code, char *fname);
34 static void polyfill(PRIMITIVE *p);
35 static void polyedge(PRIMITIVE *p, int x1, int y1, int x2, int y2);
36
37
38 void
39 expand( /* expand requested commands */
40 FILE *infp,
41 short *exlist
42 )
43 {
44 static PRIMITIVE pincl = {PINCL, 02, -1, -1, -1, -1, VINPUT};
45 static short vcloaded = FALSE;
46
47 xlist = exlist;
48
49 if (exlist[comndx(PVSTR)] == 1 && !vcloaded) {
50 vcloaded = TRUE;
51 exprim(&pincl);
52 }
53
54 exfile(infp);
55
56 if (inseg())
57 error(USER, "unclosed segment in expand");
58
59 }
60
61
62
63
64 static void
65 exfile( /* expand the given file */
66 register FILE *fp
67 )
68 {
69 PRIMITIVE curp;
70
71 while (readp(&curp, fp)) {
72 exprim(&curp);
73 fargs(&curp);
74 }
75
76 }
77
78
79
80
81 static void
82 exprim( /* expand primitive */
83 register PRIMITIVE *p
84 )
85 {
86 int xflag = xlist[comndx(p->com)];
87 /* 1==expand, 0==pass, -1==discard */
88 if (xflag != -1)
89 if (xflag == 1)
90 switch (p->com) {
91
92 case POPEN:
93 openseg(p->args);
94 break;
95
96 case PSEG:
97 segment(p, exprim);
98 break;
99
100 case PCLOSE:
101 closeseg();
102 break;
103
104 case PINCL:
105 include(p->arg0, p->args);
106 break;
107
108 case PMSTR:
109 sendmstr(p);
110 break;
111
112 case PVSTR:
113 sendvstr(p);
114 break;
115
116 case PPFILL:
117 polyfill(p);
118 break;
119
120 default:
121 sprintf(errmsg, "unsupported command '%c' in exprim", p->com);
122 error(WARNING, errmsg);
123 break;
124 }
125 else if (inseg())
126 segprim(p);
127 else
128 writep(p, stdout);
129
130 }
131
132
133
134
135 static void
136 sendmstr( /* expand a matrix string */
137 register PRIMITIVE *p
138 )
139 {
140 PRIMITIVE pout;
141 int cheight, cwidth, cthick, ccol;
142
143 cheight = 350;
144 if (p->arg0 & 010)
145 cheight *= 2;
146 cwidth = (6 - ((p->arg0 >> 4) & 03)) * 35;
147 if (p->arg0 & 04)
148 cwidth *= 2;
149 cthick = (p->arg0 & 0100) ? 1 : 0;
150 ccol = p->arg0 & 03;
151
152 pout.com = PVSTR;
153 pout.arg0 = (cthick << 2) | ccol;
154 pout.xy[XMN] = p->xy[XMN];
155 pout.xy[YMN] = p->xy[YMX] - cheight/2;
156 pout.xy[XMX] = p->xy[XMN] + strlen(p->args)*cwidth;
157 if (pout.xy[XMX] >= XYSIZE)
158 pout.xy[XMX] = XYSIZE-1;
159 pout.xy[YMX] = p->xy[YMX] + cheight/2;
160 pout.args = p->args;
161
162 exprim(&pout);
163
164 }
165
166
167
168 static void
169 sendvstr( /* expand a vector string */
170 register PRIMITIVE *p
171 )
172 {
173 PRIMITIVE pout;
174 int xadv, yadv;
175 char s[3];
176 register char *cp;
177
178 if (p->args == NULL)
179 error(USER, "illegal empty string in sendvstr");
180
181 pout.com = PSEG;
182 pout.arg0 = p->arg0;
183 switch (p->arg0 & 060) {
184 case 0: /* right */
185 xadv = (p->xy[XMX] - p->xy[XMN])/strlen(p->args);
186 pout.xy[XMN] = p->xy[XMN];
187 pout.xy[XMX] = p->xy[XMN] + xadv;
188 yadv = 0;
189 pout.xy[YMN] = p->xy[YMN];
190 pout.xy[YMX] = p->xy[YMX];
191 break;
192 case 020: /* up */
193 xadv = 0;
194 pout.xy[XMN] = p->xy[XMN];
195 pout.xy[XMX] = p->xy[XMX];
196 yadv = (p->xy[YMX] - p->xy[YMN])/strlen(p->args);
197 pout.xy[YMN] = p->xy[YMN];
198 pout.xy[YMX] = p->xy[YMN] + yadv;
199 break;
200 case 040: /* left */
201 xadv = -(p->xy[XMX] - p->xy[XMN])/strlen(p->args);
202 pout.xy[XMN] = p->xy[XMX] + xadv;
203 pout.xy[XMX] = p->xy[XMX];
204 yadv = 0;
205 pout.xy[YMN] = p->xy[YMN];
206 pout.xy[YMX] = p->xy[YMX];
207 break;
208 case 060: /* down */
209 xadv = 0;
210 pout.xy[XMN] = p->xy[XMN];
211 pout.xy[XMX] = p->xy[XMX];
212 yadv = -(p->xy[YMX] - p->xy[YMN])/strlen(p->args);
213 pout.xy[YMN] = p->xy[YMX] + yadv;
214 pout.xy[YMX] = p->xy[YMX];
215 break;
216 }
217
218 pout.args = s;
219 s[1] = '\'';
220 s[2] = '\0';
221 for (cp = p->args; *cp; cp++)
222 if (*cp < FIRSTCHAR || *cp > LASTCHAR) {
223 sprintf(errmsg, "unknown character (%d) in sendvstr", *cp);
224 error(WARNING, errmsg);
225 }
226 else {
227 s[0] = *cp;
228 exprim(&pout);
229 pout.xy[XMN] += xadv;
230 pout.xy[XMX] += xadv;
231 pout.xy[YMN] += yadv;
232 pout.xy[YMX] += yadv;
233 }
234
235 }
236
237
238
239 static void
240 include( /* load an include file */
241 int code,
242 char *fname
243 )
244 {
245 register FILE *fp;
246
247 if (fname == NULL)
248 error(USER, "missing include file name in include");
249
250 if (code == 2 || (fp = fopen(fname, "r")) == NULL)
251 if (code != 0)
252 fp = mfopen(fname, "r");
253 else {
254 sprintf(errmsg, "cannot open user include file \"%s\"", fname);
255 error(USER, errmsg);
256 }
257
258 exfile(fp);
259 fclose(fp);
260
261 }
262
263
264
265 static void
266 polyfill( /* expand polygon fill command */
267 PRIMITIVE *p
268 )
269 {
270 char *nextscan();
271 int firstx, firsty, lastx, lasty, x, y;
272 register char *cp;
273
274 if ((cp=nextscan(nextscan(p->args,"%d",&firstx),"%d",&firsty)) == NULL) {
275 sprintf(errmsg, "illegal polygon spec \"%s\" in polyfill", p->args);
276 error(WARNING, errmsg);
277 return;
278 }
279
280 lastx = firstx;
281 lasty = firsty;
282
283 while ((cp=nextscan(nextscan(cp,"%d",&x),"%d",&y)) != NULL) {
284
285 polyedge(p, lastx, lasty, x, y);
286 lastx = x;
287 lasty = y;
288 }
289
290 polyedge(p, lastx, lasty, firstx, firsty);
291 }
292
293
294
295 static void
296 polyedge( /* expand edge of polygon */
297 PRIMITIVE *p,
298 int x1, int y1, int x2, int y2
299 )
300 {
301 int reverse;
302 PRIMITIVE pin, pout;
303
304 if (x1 < x2) {
305 pin.xy[XMN] = x1;
306 pin.xy[XMX] = x2;
307 reverse = FALSE;
308 } else {
309 pin.xy[XMN] = x2;
310 pin.xy[XMX] = x1;
311 reverse = TRUE;
312 }
313
314 if (y1 < y2) {
315 pin.xy[YMN] = y1;
316 pin.xy[YMX] = y2;
317 } else {
318 pin.xy[YMN] = y2;
319 pin.xy[YMX] = y1;
320 reverse = y1 > y2 && !reverse;
321 }
322
323 pout.xy[XMN] = xlate(XMN, &pin, p);
324 pout.xy[XMX] = xlate(XMX, &pin, p);
325 pout.xy[YMN] = xlate(YMN, &pin, p);
326 pout.xy[YMX] = xlate(YMX, &pin, p);
327 pout.com = PTFILL;
328 pout.arg0 = 0100 | (reverse << 4) | (p->arg0 & 017);
329 pout.args = NULL;
330 if (fillok(&pout))
331 exprim(&pout);
332
333 if (p->arg0 & 0100) { /* draw border */
334 pout.com = PLSEG;
335 pout.arg0 = reverse << 6;
336 exprim(&pout);
337 }
338
339 pout.com = PRFILL;
340 pout.arg0 = 0100 | (p->arg0 & 017);
341 pout.xy[XMN] = pout.xy[XMX];
342 pout.xy[XMX] = p->xy[XMX];
343 if (fillok(&pout))
344 exprim(&pout);
345
346 }