1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
14 |
|
|
15 |
|
#include "standard.h" |
16 |
|
|
17 |
+ |
#include "paths.h" |
18 |
+ |
|
19 |
|
#include <ctype.h> |
20 |
|
|
21 |
|
#include "object.h" |
31 |
|
|
32 |
|
int invert = 0; /* boolean true to invert surfaces */ |
33 |
|
|
34 |
< |
int expand = 0; /* boolean true to expand commands */ |
34 |
> |
int expand = 1; /* boolean true to expand commands */ |
35 |
|
|
36 |
|
char *newmod = NULL; /* new modifier for surfaces */ |
37 |
|
|
38 |
|
char *idprefix = NULL; /* prefix for object identifiers */ |
39 |
|
|
40 |
< |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
40 |
> |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
41 |
|
|
42 |
< |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
42 |
> |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
43 |
|
|
44 |
|
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
45 |
|
|
46 |
|
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
47 |
|
|
48 |
< |
extern char *malloc(), *fgetword(); |
48 |
> |
int nrept = 1; /* number of array repetitions */ |
49 |
|
|
50 |
< |
#define progname (xav[0]) |
50 |
> |
int stdinused = 0; /* stdin has been used by -f option? */ |
51 |
|
|
52 |
+ |
extern char *malloc(), *fgets(), *fgetword(); |
53 |
|
|
54 |
+ |
char mainfn[MAXPATH]; /* main file name */ |
55 |
+ |
FILE *mainfp = NULL; /* main file pointer */ |
56 |
+ |
|
57 |
+ |
#define progname (xav[0]) |
58 |
+ |
|
59 |
+ |
|
60 |
|
main(argc, argv) /* get transform options and transform file */ |
61 |
|
int argc; |
62 |
|
char *argv[]; |
63 |
|
{ |
64 |
< |
FILE *fopen(); |
56 |
< |
FILE *fp; |
64 |
> |
char *fname; |
65 |
|
int a; |
66 |
< |
/* check for array */ |
66 |
> |
/* check for argument list file */ |
67 |
|
for (a = 1; a < argc; a++) |
68 |
+ |
if (!strcmp(argv[a], "-f")) |
69 |
+ |
return(doargf(argc, argv, a)); |
70 |
+ |
/* check for regular array */ |
71 |
+ |
for (a = 1; a < argc; a++) |
72 |
|
if (!strcmp(argv[a], "-a")) |
73 |
|
return(doarray(argc, argv, a)); |
74 |
|
|
87 |
|
break; |
88 |
|
idprefix = argv[++a]; |
89 |
|
continue; |
90 |
+ |
case 'c': |
91 |
+ |
if (argv[a][2]) |
92 |
+ |
break; |
93 |
+ |
expand = 0; |
94 |
+ |
continue; |
95 |
|
case 'e': |
96 |
|
if (argv[a][2]) |
97 |
|
break; |
129 |
|
printf(" %s", xav[a]); |
130 |
|
putchar('\n'); |
131 |
|
/* transform input */ |
132 |
< |
if (xac == argc) |
133 |
< |
xform("standard input", stdin); |
134 |
< |
else |
132 |
> |
if (xac == argc) { |
133 |
> |
if (stdinused) { |
134 |
> |
fprintf(stderr, "%s: cannot use stdin more than once\n", |
135 |
> |
argv[0]); |
136 |
> |
exit(1); |
137 |
> |
} |
138 |
> |
openmain(NULL); |
139 |
> |
xform(mainfn, mainfp); |
140 |
> |
} else |
141 |
|
for (a = xac; a < argc; a++) { |
142 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
143 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
121 |
< |
progname, argv[a]); |
122 |
< |
exit(1); |
123 |
< |
} |
124 |
< |
xform(argv[a], fp); |
125 |
< |
fclose(fp); |
142 |
> |
openmain(argv[a]); |
143 |
> |
xform(mainfn, mainfp); |
144 |
|
} |
145 |
|
|
146 |
|
return(0); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
+ |
doargf(ac, av, fi) /* take argument list from file */ |
151 |
+ |
char **av; |
152 |
+ |
int ac, fi; |
153 |
+ |
{ |
154 |
+ |
char *newav[256], **avp; |
155 |
+ |
char argbuf[1024]; |
156 |
+ |
char newid[128]; |
157 |
+ |
char *oldid; |
158 |
+ |
register char *cp; |
159 |
+ |
FILE *argfp; |
160 |
+ |
int n, i, k, newac, err; |
161 |
+ |
|
162 |
+ |
if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) { |
163 |
+ |
fprintf(stderr, "%s: missing file for -f option\n", av[0]); |
164 |
+ |
exit(1); |
165 |
+ |
} |
166 |
+ |
if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') { |
167 |
+ |
if (stdinused++) { |
168 |
+ |
fprintf(stderr, "%s: cannot use stdin more than once\n", |
169 |
+ |
av[0]); |
170 |
+ |
exit(1); |
171 |
+ |
} |
172 |
+ |
argfp = stdin; |
173 |
+ |
n = 100; /* we just don't know! */ |
174 |
+ |
} else { |
175 |
+ |
if ((argfp = fopen(av[fi+1], "r")) == NULL) { |
176 |
+ |
fprintf(stderr, "%s: cannot open argument file \"%s\"\n", |
177 |
+ |
av[0], av[fi+1]); |
178 |
+ |
exit(1); |
179 |
+ |
} |
180 |
+ |
n = 0; /* count number of lines in file */ |
181 |
+ |
while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) |
182 |
+ |
n += argbuf[0] != '\n' & argbuf[0] != '#'; |
183 |
+ |
if (!n) { |
184 |
+ |
fprintf(stderr, "%s: empty argument file \"%s\"\n", |
185 |
+ |
av[0], av[fi+1]); |
186 |
+ |
exit(1); |
187 |
+ |
} |
188 |
+ |
nrept *= n; |
189 |
+ |
rewind(argfp); |
190 |
+ |
} |
191 |
+ |
err = 0; k = 0; /* read each arg list and call main */ |
192 |
+ |
while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) { |
193 |
+ |
if (argbuf[0] == '\n' | argbuf[0] == '#') |
194 |
+ |
continue; |
195 |
+ |
avp = newav+2; |
196 |
+ |
avp[0] = av[0]; |
197 |
+ |
for (i = 1; i < fi; i++) |
198 |
+ |
avp[i] = av[i]; |
199 |
+ |
newac = i; |
200 |
+ |
cp = argbuf; /* parse new words */ |
201 |
+ |
if (*cp == '!') cp++; |
202 |
+ |
if (!strncmp(cp, "xform ", 6)) cp += 6; |
203 |
+ |
for ( ; ; ) { |
204 |
+ |
while (isspace(*cp)) /* nullify spaces */ |
205 |
+ |
*cp++ = '\0'; |
206 |
+ |
if (!*cp) /* all done? */ |
207 |
+ |
break; |
208 |
+ |
avp[newac++] = cp; /* add argument to list */ |
209 |
+ |
while (*++cp && !isspace(*cp)) |
210 |
+ |
; |
211 |
+ |
} |
212 |
+ |
for (i = fi+2; i < ac; i++) |
213 |
+ |
avp[newac++] = av[i]; |
214 |
+ |
avp[newac] = NULL; |
215 |
+ |
oldid = NULL; |
216 |
+ |
for (i = 2; i < newac; i++) |
217 |
+ |
if (!strcmp(avp[i-1], "-n")) { |
218 |
+ |
oldid = avp[i]; |
219 |
+ |
avp[i] = newid; |
220 |
+ |
break; |
221 |
+ |
} |
222 |
+ |
if (oldid == NULL) { |
223 |
+ |
newav[0] = av[0]; |
224 |
+ |
newav[1] = "-n"; |
225 |
+ |
newav[2] = newid; |
226 |
+ |
avp = newav; |
227 |
+ |
newac += 2; |
228 |
+ |
} |
229 |
+ |
if (oldid == NULL) |
230 |
+ |
sprintf(newid, "i%d", k); |
231 |
+ |
else |
232 |
+ |
sprintf(newid, "%s.%d", oldid, k); |
233 |
+ |
err |= main(newac, avp); |
234 |
+ |
k++; |
235 |
+ |
} |
236 |
+ |
fclose(argfp); |
237 |
+ |
return(err); |
238 |
+ |
} |
239 |
+ |
|
240 |
+ |
|
241 |
|
doarray(ac, av, ai) /* make array */ |
242 |
|
char **av; |
243 |
|
int ac, ai; |
245 |
|
char *newav[256], **avp; |
246 |
|
char newid[128], repts[32]; |
247 |
|
char *oldid = NULL; |
248 |
< |
int i, err; |
248 |
> |
int n, i, err; |
249 |
|
|
250 |
+ |
if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) { |
251 |
+ |
fprintf(stderr, "%s: missing count for -a option\n", av[0]); |
252 |
+ |
exit(1); |
253 |
+ |
} |
254 |
+ |
nrept *= n; |
255 |
|
avp = newav+2; |
256 |
|
avp[0] = av[0]; |
257 |
|
for (i = 1; i < ac; i++) |
271 |
|
ac += 2; |
272 |
|
} |
273 |
|
err = 0; |
274 |
< |
for (i = 0; i < atoi(av[ai+1]); i++) { |
274 |
> |
for (i = 0; i < n; i++) { |
275 |
|
if (oldid == NULL) |
276 |
|
sprintf(newid, "a%d", i); |
277 |
|
else |
287 |
|
char *name; |
288 |
|
register FILE *fin; |
289 |
|
{ |
290 |
+ |
int nobjs = 0; |
291 |
|
register int c; |
292 |
|
|
293 |
|
while ((c = getc(fin)) != EOF) { |
303 |
|
} else if (c == '!') { /* command */ |
304 |
|
ungetc(c, fin); |
305 |
|
xfcomm(name, fin); |
306 |
+ |
nobjs++; |
307 |
|
} else { /* object */ |
308 |
|
ungetc(c, fin); |
309 |
|
xfobject(name, fin); |
310 |
+ |
nobjs++; |
311 |
|
} |
312 |
|
} |
313 |
+ |
if (nobjs == 0) |
314 |
+ |
fprintf(stderr, "%s: (%s): warning - empty file\n", |
315 |
+ |
progname, name); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
|
xfcomm(fname, fin) /* transform a command */ |
320 |
+ |
char *fname; |
321 |
|
FILE *fin; |
322 |
|
{ |
323 |
< |
FILE *popen(); |
324 |
< |
char *fgetline(); |
323 |
> |
extern FILE *popen(); |
324 |
> |
extern char *fgetline(); |
325 |
|
FILE *pin; |
326 |
|
char buf[512]; |
327 |
|
int i; |
328 |
|
|
329 |
|
fgetline(buf, sizeof(buf), fin); |
330 |
|
if (expand) { |
331 |
< |
if (xac > 2) { |
332 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
333 |
< |
fprintf(stderr, |
334 |
< |
"%s: (%s): cannot execute \"%s\"\n", |
214 |
< |
progname, fname, buf); |
215 |
< |
exit(1); |
216 |
< |
} |
217 |
< |
xform(buf, pin); |
218 |
< |
pclose(pin); |
219 |
< |
} else { |
220 |
< |
fflush(stdout); |
221 |
< |
system(buf+1); |
331 |
> |
if ((pin = popen(buf+1, "r")) == NULL) { |
332 |
> |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
333 |
> |
progname, fname, buf); |
334 |
> |
exit(1); |
335 |
|
} |
336 |
+ |
xform(buf, pin); |
337 |
+ |
pclose(pin); |
338 |
|
} else { |
339 |
|
printf("\n%s", buf); |
340 |
|
if (xac > 1) { |
341 |
< |
printf(" | %s -e", xav[0]); |
341 |
> |
printf(" | %s", xav[0]); |
342 |
|
for (i = 1; i < xac; i++) |
343 |
|
printf(" %s", xav[i]); |
344 |
|
} |
363 |
|
progname, fname, typ); |
364 |
|
exit(1); |
365 |
|
} |
366 |
< |
if (issurface(fn)) |
366 |
> |
if (ismodifier(fn)) |
367 |
> |
printf("\n%s %s ", nam, typ); |
368 |
> |
else |
369 |
|
printf("\n%s %s ", newmod != NULL ? newmod : nam, |
370 |
|
invert ? ofun[tinvers[fn]].funame : typ); |
254 |
– |
else |
255 |
– |
printf("\n%s %s ", nam, typ); |
371 |
|
/* object name */ |
372 |
|
fgetword(nam, sizeof(nam), fin); |
373 |
< |
if (idprefix != NULL && issurface(fn)) |
259 |
< |
printf("%s.%s\n", idprefix, nam); |
260 |
< |
else |
373 |
> |
if (idprefix == NULL || ismodifier(fn)) |
374 |
|
printf("%s\n", nam); |
375 |
+ |
else |
376 |
+ |
printf("%s.%s\n", idprefix, nam); |
377 |
|
/* transform arguments */ |
378 |
|
if ((*ofun[fn].funp)(fin) < 0) { |
379 |
|
fprintf(stderr, "%s: (%s): bad %s \"%s\"\n", |
387 |
|
FILE *fin; |
388 |
|
{ |
389 |
|
register int i; |
390 |
< |
FUNARGS fa; |
390 |
> |
FUNARGS fa; |
391 |
|
|
392 |
|
if (readfargs(&fa, fin) != 1) |
393 |
|
return(-1); |
396 |
|
for (i = 0; i < fa.nsargs; i++) |
397 |
|
printf(" %s", fa.sarg[i]); |
398 |
|
printf("\n"); |
399 |
< |
#ifdef IARGS |
399 |
> |
#ifdef IARGS |
400 |
|
/* integer arguments */ |
401 |
|
printf("%d", fa.niargs); |
402 |
|
for (i = 0; i < fa.niargs; i++) |
419 |
|
FILE *fin; |
420 |
|
{ |
421 |
|
register int i; |
422 |
< |
FUNARGS fa; |
422 |
> |
int resetarr = 0; |
423 |
> |
FUNARGS fa; |
424 |
|
|
425 |
|
if (readfargs(&fa, fin) != 1) |
426 |
|
return(-1); |
427 |
|
/* string arguments */ |
428 |
< |
printf("%d", fa.nsargs + xac-xfa); |
428 |
> |
if (xac > xfa && strcmp(xav[xfa], "-i")) |
429 |
> |
resetarr = 2; |
430 |
> |
printf("%d", fa.nsargs + resetarr + xac-xfa); |
431 |
|
for (i = 0; i < fa.nsargs; i++) |
432 |
|
printf(" %s", fa.sarg[i]); |
433 |
+ |
if (resetarr) |
434 |
+ |
printf(" -i 1"); |
435 |
|
for (i = xfa; i < xac; i++) /* add xf arguments */ |
436 |
|
printf(" %s", xav[i]); |
437 |
|
printf("\n"); |
438 |
< |
#ifdef IARGS |
438 |
> |
#ifdef IARGS |
439 |
|
/* integer arguments */ |
440 |
|
printf("%d", fa.niargs); |
441 |
|
for (i = 0; i < fa.niargs; i++) |
483 |
|
m_glow(fin) /* transform arguments for proximity light */ |
484 |
|
FILE *fin; |
485 |
|
{ |
486 |
< |
FUNARGS fa; |
486 |
> |
FUNARGS fa; |
487 |
|
|
488 |
|
if (readfargs(&fa, fin) != 1) |
489 |
|
return(-1); |
501 |
|
m_spot(fin) /* transform arguments for spotlight */ |
502 |
|
FILE *fin; |
503 |
|
{ |
504 |
< |
double v[3]; |
505 |
< |
FUNARGS fa; |
504 |
> |
FVECT v; |
505 |
> |
FUNARGS fa; |
506 |
|
|
507 |
|
if (readfargs(&fa, fin) != 1) |
508 |
|
return(-1); |
518 |
|
} |
519 |
|
|
520 |
|
|
521 |
+ |
m_mist(fin) /* transform arguments for mist */ |
522 |
+ |
FILE *fin; |
523 |
+ |
{ |
524 |
+ |
FUNARGS fa; |
525 |
+ |
int i; |
526 |
+ |
|
527 |
+ |
if (readfargs(&fa, fin) != 1) |
528 |
+ |
return(-1); |
529 |
+ |
if (fa.nfargs > 7) |
530 |
+ |
return(-1); |
531 |
+ |
printf("%d", fa.nsargs); |
532 |
+ |
if (idprefix == NULL) |
533 |
+ |
for (i = 0; i < fa.nsargs; i++) |
534 |
+ |
printf(" %s", fa.sarg[i]); |
535 |
+ |
else |
536 |
+ |
for (i = 0; i < fa.nsargs; i++) { |
537 |
+ |
char sname[256], *sp; |
538 |
+ |
register char *cp1, *cp2 = sname; |
539 |
+ |
/* add idprefix */ |
540 |
+ |
for (sp = fa.sarg[i]; *sp; sp = cp1) { |
541 |
+ |
for (cp1 = idprefix; *cp1; ) |
542 |
+ |
*cp2++ = *cp1++; |
543 |
+ |
*cp2++ = '.'; |
544 |
+ |
for (cp1 = sp; *cp1 && |
545 |
+ |
(*cp2++ = *cp1++) != '>'; ) |
546 |
+ |
; |
547 |
+ |
} |
548 |
+ |
*cp2 = '\0'; |
549 |
+ |
printf(" %s", sname); |
550 |
+ |
} |
551 |
+ |
printf("\n0\n%d", fa.nfargs); |
552 |
+ |
if (fa.nfargs > 2) |
553 |
+ |
printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca, |
554 |
+ |
fa.farg[1]/tot.sca, fa.farg[2]/tot.sca); |
555 |
+ |
for (i = 3; i < fa.nfargs; i++) |
556 |
+ |
printf(" %12.6g", fa.farg[i]); |
557 |
+ |
printf("\n"); |
558 |
+ |
freefargs(&fa); |
559 |
+ |
return(0); |
560 |
+ |
} |
561 |
+ |
|
562 |
+ |
|
563 |
|
m_dielectric(fin) /* transform arguments for dielectric */ |
564 |
|
FILE *fin; |
565 |
|
{ |
566 |
< |
double pow(); |
405 |
< |
FUNARGS fa; |
566 |
> |
FUNARGS fa; |
567 |
|
|
568 |
|
if (readfargs(&fa, fin) != 1) |
569 |
|
return(-1); |
570 |
|
if (fa.nsargs != 0 || fa.nfargs != 5) |
571 |
|
return(-1); |
572 |
|
printf("0\n0\n5"); |
573 |
< |
printf(" %18.12g %18.12g %18.12g", |
573 |
> |
printf(" %12.6g %12.6g %12.6g", |
574 |
|
pow(fa.farg[0], 1.0/tot.sca), |
575 |
|
pow(fa.farg[1], 1.0/tot.sca), |
576 |
|
pow(fa.farg[2], 1.0/tot.sca)); |
577 |
< |
printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]); |
577 |
> |
printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]); |
578 |
|
freefargs(&fa); |
579 |
|
return(0); |
580 |
|
} |
583 |
|
m_interface(fin) /* transform arguments for interface */ |
584 |
|
FILE *fin; |
585 |
|
{ |
586 |
< |
double pow(); |
426 |
< |
FUNARGS fa; |
586 |
> |
FUNARGS fa; |
587 |
|
|
588 |
|
if (readfargs(&fa, fin) != 1) |
589 |
|
return(-1); |
590 |
|
if (fa.nsargs != 0 || fa.nfargs != 8) |
591 |
|
return(-1); |
592 |
|
printf("0\n0\n8\n"); |
593 |
< |
printf("%18.12g %18.12g %18.12g", |
593 |
> |
printf("%12.6g %12.6g %12.6g", |
594 |
|
pow(fa.farg[0], 1.0/tot.sca), |
595 |
|
pow(fa.farg[1], 1.0/tot.sca), |
596 |
|
pow(fa.farg[2], 1.0/tot.sca)); |
597 |
< |
printf(" %18.12g\n", fa.farg[3]); |
598 |
< |
printf("%18.12g %18.12g %18.12g", |
597 |
> |
printf(" %12.6g\n", fa.farg[3]); |
598 |
> |
printf("%12.6g %12.6g %12.6g", |
599 |
|
pow(fa.farg[4], 1.0/tot.sca), |
600 |
|
pow(fa.farg[5], 1.0/tot.sca), |
601 |
|
pow(fa.farg[6], 1.0/tot.sca)); |
602 |
< |
printf(" %18.12g\n", fa.farg[7]); |
602 |
> |
printf(" %12.6g\n", fa.farg[7]); |
603 |
|
freefargs(&fa); |
604 |
|
return(0); |
605 |
|
} |
609 |
|
FILE *fin; |
610 |
|
{ |
611 |
|
int i; |
612 |
< |
double v[3]; |
613 |
< |
FUNARGS fa; |
612 |
> |
FVECT v; |
613 |
> |
FUNARGS fa; |
614 |
|
|
615 |
|
if (readfargs(&fa, fin) != 1) |
616 |
|
return(-1); |
617 |
< |
if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15) |
617 |
> |
if (fa.nfargs < 9) |
618 |
|
return(-1); |
619 |
|
/* string arguments */ |
620 |
|
printf("%d", fa.nsargs); |
629 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
630 |
|
/* down vector */ |
631 |
|
multv3(v, fa.farg+6, tot.xfm); |
632 |
< |
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
633 |
< |
/* forground and background */ |
634 |
< |
if (fa.nfargs == 11) |
635 |
< |
printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]); |
636 |
< |
else if (fa.nfargs == 15) { |
637 |
< |
printf(" %18.12g %18.12g %18.12g\n", |
478 |
< |
fa.farg[9], fa.farg[10], fa.farg[11]); |
479 |
< |
printf(" %18.12g %18.12g %18.12g\n", |
480 |
< |
fa.farg[12], fa.farg[13], fa.farg[14]); |
632 |
> |
printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]); |
633 |
> |
/* remaining arguments */ |
634 |
> |
for (i = 9; i < fa.nfargs; i++) { |
635 |
> |
if (i%3 == 0) |
636 |
> |
putchar('\n'); |
637 |
> |
printf(" %18.12g", fa.farg[i]); |
638 |
|
} |
639 |
+ |
putchar('\n'); |
640 |
|
freefargs(&fa); |
641 |
|
return(0); |
642 |
|
} |
645 |
|
o_source(fin) /* transform source arguments */ |
646 |
|
FILE *fin; |
647 |
|
{ |
648 |
< |
double dv[3]; |
649 |
< |
FUNARGS fa; |
648 |
> |
FVECT dv; |
649 |
> |
FUNARGS fa; |
650 |
|
|
651 |
|
if (readfargs(&fa, fin) != 1) |
652 |
|
return(-1); |
666 |
|
o_sphere(fin) /* transform sphere arguments */ |
667 |
|
FILE *fin; |
668 |
|
{ |
669 |
< |
double cent[3], rad; |
670 |
< |
FUNARGS fa; |
669 |
> |
FVECT cent; |
670 |
> |
double rad; |
671 |
> |
FUNARGS fa; |
672 |
|
|
673 |
|
if (readfargs(&fa, fin) != 1) |
674 |
|
return(-1); |
675 |
|
if (fa.nsargs != 0 || fa.nfargs != 4) |
676 |
|
return(-1); |
677 |
|
|
678 |
< |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
678 |
> |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
679 |
|
|
680 |
|
rad = fa.farg[3] * tot.sca; /* scale radius */ |
681 |
|
|
690 |
|
o_face(fin) /* transform face arguments */ |
691 |
|
FILE *fin; |
692 |
|
{ |
693 |
< |
double p[3]; |
693 |
> |
FVECT p; |
694 |
|
register int i; |
695 |
< |
FUNARGS fa; |
695 |
> |
FUNARGS fa; |
696 |
|
|
697 |
|
if (readfargs(&fa, fin) != 1) |
698 |
|
return(-1); |
716 |
|
o_cone(fin) /* transform cone and cup arguments */ |
717 |
|
FILE *fin; |
718 |
|
{ |
719 |
< |
double p0[3], p1[3], r0, r1; |
720 |
< |
FUNARGS fa; |
719 |
> |
FVECT p0, p1; |
720 |
> |
double r0, r1; |
721 |
> |
FUNARGS fa; |
722 |
|
|
723 |
|
if (readfargs(&fa, fin) != 1) |
724 |
|
return(-1); |
743 |
|
o_cylinder(fin) /* transform cylinder and tube arguments */ |
744 |
|
FILE *fin; |
745 |
|
{ |
746 |
< |
double p0[3], p1[3], rad; |
747 |
< |
FUNARGS fa; |
746 |
> |
FVECT p0, p1; |
747 |
> |
double rad; |
748 |
> |
FUNARGS fa; |
749 |
|
|
750 |
|
if (readfargs(&fa, fin) != 1) |
751 |
|
return(-1); |
768 |
|
o_ring(fin) /* transform ring arguments */ |
769 |
|
FILE *fin; |
770 |
|
{ |
771 |
< |
double p0[3], pd[3], r0, r1; |
772 |
< |
FUNARGS fa; |
771 |
> |
FVECT p0, pd; |
772 |
> |
double r0, r1; |
773 |
> |
FUNARGS fa; |
774 |
|
|
775 |
|
if (readfargs(&fa, fin) != 1) |
776 |
|
return(-1); |
798 |
|
|
799 |
|
initotypes() /* initialize ofun[] array */ |
800 |
|
{ |
639 |
– |
extern int o_source(); |
640 |
– |
extern int o_sphere(); |
641 |
– |
extern int o_face(); |
642 |
– |
extern int o_cone(); |
643 |
– |
extern int o_cylinder(); |
644 |
– |
extern int o_ring(); |
645 |
– |
extern int m_glow(); |
646 |
– |
extern int m_spot(); |
647 |
– |
extern int m_dielectric(); |
648 |
– |
extern int m_interface(); |
649 |
– |
extern int text(); |
650 |
– |
extern int alias(); |
651 |
– |
extern int passargs(); |
652 |
– |
extern int addxform(); |
801 |
|
register int i; |
802 |
|
|
803 |
|
if (ofun[OBJ_SOURCE].funp == o_source) |
824 |
|
ofun[MAT_SPOT].funp = m_spot; |
825 |
|
ofun[MAT_DIELECTRIC].funp = m_dielectric; |
826 |
|
ofun[MAT_INTERFACE].funp = m_interface; |
827 |
+ |
ofun[MAT_MIST].funp = m_mist; |
828 |
|
ofun[PAT_CTEXT].funp = |
829 |
|
ofun[PAT_BTEXT].funp = |
830 |
|
ofun[MIX_TEXT].funp = text; |
831 |
|
ofun[ALIAS].funp = alias; |
832 |
|
/* surface inverses */ |
833 |
+ |
tinvers[OBJ_FACE] = OBJ_FACE; |
834 |
|
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
835 |
|
tinvers[OBJ_CONE] = OBJ_CUP; |
836 |
|
tinvers[OBJ_CUP] = OBJ_CONE; |
841 |
|
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
842 |
|
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
843 |
|
} |
844 |
+ |
|
845 |
+ |
|
846 |
+ |
#ifdef OLDXFORM |
847 |
+ |
openmain(fname) |
848 |
+ |
char *fname; |
849 |
+ |
{ |
850 |
+ |
if (fname == NULL) { |
851 |
+ |
strcpy(mainfn, "standard input"); |
852 |
+ |
mainfp = stdin; |
853 |
+ |
return; |
854 |
+ |
} |
855 |
+ |
if (mainfp != NULL) { |
856 |
+ |
if (!strcmp(fname, mainfn)) { |
857 |
+ |
rewind(mainfp); |
858 |
+ |
return; |
859 |
+ |
} |
860 |
+ |
fclose(mainfp); |
861 |
+ |
} |
862 |
+ |
if ((mainfp = fopen(fname, "r")) == NULL) { |
863 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
864 |
+ |
progname, fname); |
865 |
+ |
exit(1); |
866 |
+ |
} |
867 |
+ |
strcpy(mainfn, fname); |
868 |
+ |
} |
869 |
+ |
#else |
870 |
+ |
openmain(fname) /* open fname for input, changing to its directory */ |
871 |
+ |
char *fname; |
872 |
+ |
{ |
873 |
+ |
extern FILE *tmpfile(); |
874 |
+ |
extern char *getlibpath(), *getpath(); |
875 |
+ |
static char origdir[MAXPATH]; |
876 |
+ |
static char curfn[MAXPATH]; |
877 |
+ |
static int diffdir; |
878 |
+ |
register char *fpath; |
879 |
+ |
|
880 |
+ |
if (fname == NULL) { /* standard input */ |
881 |
+ |
if (mainfp == NULL) { |
882 |
+ |
register int c; |
883 |
+ |
strcpy(mainfn, "standard input"); |
884 |
+ |
if (nrept <= 1) { |
885 |
+ |
mainfp = stdin; |
886 |
+ |
return; /* just read once */ |
887 |
+ |
} |
888 |
+ |
/* else copy */ |
889 |
+ |
if ((mainfp = tmpfile()) == NULL) { |
890 |
+ |
fprintf(stderr, |
891 |
+ |
"%s: cannot create temporary file\n", |
892 |
+ |
progname); |
893 |
+ |
exit(1); |
894 |
+ |
} |
895 |
+ |
while ((c = getc(stdin)) != EOF) |
896 |
+ |
putc(c, mainfp); |
897 |
+ |
fclose(stdin); |
898 |
+ |
} |
899 |
+ |
rewind(mainfp); /* rewind copy */ |
900 |
+ |
return; |
901 |
+ |
} |
902 |
+ |
if (mainfp == NULL) { /* first call, initialize */ |
903 |
+ |
getwd(origdir); |
904 |
+ |
} else if (!strcmp(fname, curfn)) { /* just need to rewind? */ |
905 |
+ |
rewind(mainfp); |
906 |
+ |
return; |
907 |
+ |
} else { /* else close old stream */ |
908 |
+ |
fclose(mainfp); |
909 |
+ |
if (diffdir) { |
910 |
+ |
chdir(origdir); |
911 |
+ |
diffdir = 0; |
912 |
+ |
} |
913 |
+ |
} |
914 |
+ |
strcpy(curfn, fname); /* remember file name */ |
915 |
+ |
/* get full path */ |
916 |
+ |
if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) { |
917 |
+ |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
918 |
+ |
progname, fname); |
919 |
+ |
exit(1); |
920 |
+ |
} |
921 |
+ |
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
922 |
+ |
fpath += 2; |
923 |
+ |
/* record path name */ |
924 |
+ |
strcpy(mainfn, fpath); |
925 |
+ |
if (expand) { /* change to local directory */ |
926 |
+ |
register char *cp = fpath + strlen(fpath); /* get dir. */ |
927 |
+ |
while (cp > fpath) { |
928 |
+ |
cp--; |
929 |
+ |
if (ISDIRSEP(*cp)) { |
930 |
+ |
if (cp == fpath) |
931 |
+ |
cp++; /* root special case */ |
932 |
+ |
break; |
933 |
+ |
} |
934 |
+ |
} |
935 |
+ |
*cp = '\0'; |
936 |
+ |
if (fpath[0]) { /* change to new directory? */ |
937 |
+ |
if (chdir(fpath) < 0) { |
938 |
+ |
fprintf(stderr, |
939 |
+ |
"%s: cannot change directory to \"%s\"\n", |
940 |
+ |
progname, fpath); |
941 |
+ |
exit(1); |
942 |
+ |
} |
943 |
+ |
diffdir++; |
944 |
+ |
} |
945 |
+ |
/* get final path component */ |
946 |
+ |
for (fpath = fname+strlen(fname); |
947 |
+ |
fpath > fname && !ISDIRSEP(fpath[-1]); fpath--) |
948 |
+ |
; |
949 |
+ |
} |
950 |
+ |
/* open the file */ |
951 |
+ |
if ((mainfp = fopen(fpath, "r")) == NULL) { |
952 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
953 |
+ |
progname, mainfn); |
954 |
+ |
exit(1); |
955 |
+ |
} |
956 |
+ |
} |
957 |
+ |
#endif |