ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/expand.c
Revision: 1.4
Committed: Sat Nov 15 02:13:36 2003 UTC (20 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 1.3: +7 -7 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: expand.c,v 1.3 2003/07/21 22:30:18 schorsch Exp $";
3 #endif
4 /*
5 * Expansion routine for command implementation
6 * on simple drivers
7 */
8
9 #include <string.h>
10
11 #include "meta.h"
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, NULL};
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 = 0, yadv = 0;
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 = NULL;
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
259 exfile(fp);
260 fclose(fp);
261
262 }
263
264
265
266 static void
267 polyfill( /* expand polygon fill command */
268 PRIMITIVE *p
269 )
270 {
271 char firstx, firsty, x, y;
272 int lastx, lasty;
273 register char *cp;
274
275 if ((cp=nextscan(nextscan(p->args,"%d",&firstx),"%d",&firsty)) == NULL) {
276 sprintf(errmsg, "illegal polygon spec \"%s\" in polyfill", p->args);
277 error(WARNING, errmsg);
278 return;
279 }
280
281 lastx = firstx;
282 lasty = firsty;
283
284 while ((cp=nextscan(nextscan(cp,"%d",&x),"%d",&y)) != NULL) {
285
286 polyedge(p, lastx, lasty, x, y);
287 lastx = x;
288 lasty = y;
289 }
290
291 polyedge(p, lastx, lasty, firstx, firsty);
292 }
293
294
295
296 static void
297 polyedge( /* expand edge of polygon */
298 PRIMITIVE *p,
299 int x1, int y1, int x2, int y2
300 )
301 {
302 int reverse;
303 PRIMITIVE pin, pout;
304
305 if (x1 < x2) {
306 pin.xy[XMN] = x1;
307 pin.xy[XMX] = x2;
308 reverse = FALSE;
309 } else {
310 pin.xy[XMN] = x2;
311 pin.xy[XMX] = x1;
312 reverse = TRUE;
313 }
314
315 if (y1 < y2) {
316 pin.xy[YMN] = y1;
317 pin.xy[YMX] = y2;
318 } else {
319 pin.xy[YMN] = y2;
320 pin.xy[YMX] = y1;
321 reverse = y1 > y2 && !reverse;
322 }
323
324 pout.xy[XMN] = xlate(XMN, &pin, p);
325 pout.xy[XMX] = xlate(XMX, &pin, p);
326 pout.xy[YMN] = xlate(YMN, &pin, p);
327 pout.xy[YMX] = xlate(YMX, &pin, p);
328 pout.com = PTFILL;
329 pout.arg0 = 0100 | (reverse << 4) | (p->arg0 & 017);
330 pout.args = NULL;
331 if (fillok(&pout))
332 exprim(&pout);
333
334 if (p->arg0 & 0100) { /* draw border */
335 pout.com = PLSEG;
336 pout.arg0 = reverse << 6;
337 exprim(&pout);
338 }
339
340 pout.com = PRFILL;
341 pout.arg0 = 0100 | (p->arg0 & 017);
342 pout.xy[XMN] = pout.xy[XMX];
343 pout.xy[XMX] = p->xy[XMX];
344 if (fillok(&pout))
345 exprim(&pout);
346
347 }