1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* xform.c - program to transform object files. |
6 |
|
* Transformations must preserve aspect ratio. |
11 |
|
|
12 |
|
#include "standard.h" |
13 |
|
|
14 |
+ |
#include "paths.h" |
15 |
+ |
|
16 |
|
#include <ctype.h> |
17 |
|
|
18 |
|
#include "object.h" |
26 |
|
XF tot; /* total transformation */ |
27 |
|
int reverse; /* boolean true if scene mirrored */ |
28 |
|
|
29 |
< |
int invert = 0; /* boolean true to invert surfaces */ |
29 |
> |
int invert; /* boolean true to invert surfaces */ |
30 |
|
|
31 |
< |
int expand = 0; /* boolean true to expand commands */ |
31 |
> |
int expand; /* boolean true to expand commands */ |
32 |
|
|
33 |
< |
char *newmod = NULL; /* new modifier for surfaces */ |
33 |
> |
char *newmod; /* new modifier for surfaces */ |
34 |
|
|
35 |
< |
char *idprefix = NULL; /* prefix for object identifiers */ |
35 |
> |
char *idprefix; /* prefix for object identifiers */ |
36 |
|
|
37 |
< |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
37 |
> |
FUN ofun[NUMOTYPE] = INIT_OTYPE; /* default types and actions */ |
38 |
|
|
39 |
< |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
39 |
> |
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
40 |
|
|
41 |
< |
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
41 |
> |
int nrept = 1; /* number of array repetitions */ |
42 |
|
|
43 |
< |
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
43 |
> |
int stdinused = 0; /* stdin has been used by -f option? */ |
44 |
|
|
45 |
< |
extern char *malloc(), *fgetword(); |
45 |
> |
char mainfn[MAXPATH]; /* main file name */ |
46 |
> |
FILE *mainfp = NULL; /* main file pointer */ |
47 |
|
|
48 |
< |
#define progname (xav[0]) |
48 |
> |
#define progname (xav[0]) |
49 |
|
|
50 |
|
|
51 |
|
main(argc, argv) /* get transform options and transform file */ |
52 |
|
int argc; |
53 |
|
char *argv[]; |
54 |
|
{ |
55 |
< |
FILE *fopen(); |
56 |
< |
FILE *fp; |
55 |
> |
int mal_prefix = 0; |
56 |
> |
char *fname; |
57 |
|
int a; |
58 |
< |
/* check for array */ |
58 |
> |
/* check for argument list file */ |
59 |
|
for (a = 1; a < argc; a++) |
60 |
+ |
if (!strcmp(argv[a], "-f")) |
61 |
+ |
return(doargf(argc, argv, a)); |
62 |
+ |
/* check for regular array */ |
63 |
+ |
for (a = 1; a < argc; a++) |
64 |
|
if (!strcmp(argv[a], "-a")) |
65 |
|
return(doarray(argc, argv, a)); |
66 |
|
|
67 |
< |
initotypes(); |
67 |
> |
initotypes(); /* initialize */ |
68 |
> |
invert = 0; |
69 |
> |
expand = 1; |
70 |
> |
newmod = NULL; |
71 |
> |
idprefix = NULL; |
72 |
|
|
73 |
|
for (a = 1; a < argc; a++) { |
74 |
|
if (argv[a][0] == '-') |
75 |
|
switch (argv[a][1]) { |
76 |
|
case 'm': |
77 |
< |
if (argv[a][2] || a+1 >= argc) |
77 |
> |
if (argv[a][2] | a+1 >= argc) |
78 |
|
break; |
79 |
< |
newmod = argv[++a]; |
79 |
> |
a++; |
80 |
> |
if (newmod == NULL) |
81 |
> |
newmod = argv[a]; |
82 |
|
continue; |
83 |
|
case 'n': |
84 |
< |
if (argv[a][2] || a+1 >= argc) |
84 |
> |
if (argv[a][2] | a+1 >= argc) |
85 |
|
break; |
86 |
< |
idprefix = argv[++a]; |
86 |
> |
a++; |
87 |
> |
if (idprefix == NULL) |
88 |
> |
idprefix = argv[a]; |
89 |
> |
else { |
90 |
> |
register char *newp; |
91 |
> |
newp = (char *)malloc(strlen(idprefix)+ |
92 |
> |
strlen(argv[a])+2); |
93 |
> |
if (newp == NULL) |
94 |
> |
exit(2); |
95 |
> |
sprintf(newp, "%s.%s", |
96 |
> |
idprefix, argv[a]); |
97 |
> |
if (mal_prefix++) |
98 |
> |
free((void *)idprefix); |
99 |
> |
idprefix = newp; |
100 |
> |
} |
101 |
|
continue; |
102 |
+ |
case 'c': |
103 |
+ |
if (argv[a][2]) |
104 |
+ |
break; |
105 |
+ |
expand = 0; |
106 |
+ |
continue; |
107 |
|
case 'e': |
108 |
|
if (argv[a][2]) |
109 |
|
break; |
112 |
|
case 'I': |
113 |
|
if (argv[a][2]) |
114 |
|
break; |
115 |
< |
invert = 1; |
115 |
> |
invert = !invert; |
116 |
|
continue; |
117 |
|
} |
118 |
|
break; |
141 |
|
printf(" %s", xav[a]); |
142 |
|
putchar('\n'); |
143 |
|
/* transform input */ |
144 |
< |
if (xac == argc) |
145 |
< |
xform("standard input", stdin); |
146 |
< |
else |
144 |
> |
if (xac == argc) { |
145 |
> |
if (stdinused) { |
146 |
> |
fprintf(stderr, "%s: cannot use stdin more than once\n", |
147 |
> |
argv[0]); |
148 |
> |
exit(1); |
149 |
> |
} |
150 |
> |
openmain(NULL); |
151 |
> |
xform(mainfn, mainfp); |
152 |
> |
} else |
153 |
|
for (a = xac; a < argc; a++) { |
154 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
155 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
121 |
< |
progname, argv[a]); |
122 |
< |
exit(1); |
123 |
< |
} |
124 |
< |
xform(argv[a], fp); |
125 |
< |
fclose(fp); |
154 |
> |
openmain(argv[a]); |
155 |
> |
xform(mainfn, mainfp); |
156 |
|
} |
157 |
|
|
158 |
+ |
if (mal_prefix) |
159 |
+ |
free((void *)idprefix); |
160 |
|
return(0); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
+ |
doargf(ac, av, fi) /* take argument list from file */ |
165 |
+ |
char **av; |
166 |
+ |
int ac, fi; |
167 |
+ |
{ |
168 |
+ |
int inquote; |
169 |
+ |
char *newav[256], **avp; |
170 |
+ |
char argbuf[1024]; |
171 |
+ |
char newid[128]; |
172 |
+ |
char *oldid; |
173 |
+ |
register char *cp; |
174 |
+ |
FILE *argfp; |
175 |
+ |
int n, i, k, newac, err; |
176 |
+ |
|
177 |
+ |
if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) { |
178 |
+ |
fprintf(stderr, "%s: missing file for -f option\n", av[0]); |
179 |
+ |
exit(1); |
180 |
+ |
} |
181 |
+ |
if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') { |
182 |
+ |
if (stdinused++) { |
183 |
+ |
fprintf(stderr, |
184 |
+ |
"%s: cannot use stdin more than once\n", |
185 |
+ |
av[0]); |
186 |
+ |
exit(1); |
187 |
+ |
} |
188 |
+ |
argfp = stdin; |
189 |
+ |
n = 100; /* we just don't know! */ |
190 |
+ |
} else { |
191 |
+ |
if ((argfp = fopen(av[fi+1], "r")) == NULL) { |
192 |
+ |
fprintf(stderr, |
193 |
+ |
"%s: cannot open argument file \"%s\"\n", |
194 |
+ |
av[0], av[fi+1]); |
195 |
+ |
exit(1); |
196 |
+ |
} |
197 |
+ |
n = 0; /* count number of lines in file */ |
198 |
+ |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) |
199 |
+ |
n += argbuf[0] && argbuf[0] != '#'; |
200 |
+ |
if (!n) { |
201 |
+ |
fprintf(stderr, "%s: empty argument file \"%s\"\n", |
202 |
+ |
av[0], av[fi+1]); |
203 |
+ |
exit(1); |
204 |
+ |
} |
205 |
+ |
nrept *= n; |
206 |
+ |
rewind(argfp); |
207 |
+ |
} |
208 |
+ |
err = 0; k = 0; /* read each arg list and call main */ |
209 |
+ |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) { |
210 |
+ |
if (!argbuf[0] || argbuf[0] == '#') |
211 |
+ |
continue; |
212 |
+ |
avp = newav+2; |
213 |
+ |
avp[0] = av[0]; |
214 |
+ |
for (i = 1; i < fi; i++) |
215 |
+ |
avp[i] = av[i]; |
216 |
+ |
newac = i; |
217 |
+ |
cp = argbuf; /* parse new words */ |
218 |
+ |
if (*cp == '!') cp++; |
219 |
+ |
if (!strncmp(cp, "xform ", 6)) cp += 6; |
220 |
+ |
inquote = 0; |
221 |
+ |
for ( ; ; ) { |
222 |
+ |
skipspaces: |
223 |
+ |
while (isspace(*cp)) /* nullify spaces */ |
224 |
+ |
*cp++ = '\0'; |
225 |
+ |
if ((*cp == '"' | *cp == '\'')) |
226 |
+ |
inquote = *cp++; |
227 |
+ |
if (!*cp) /* all done? */ |
228 |
+ |
break; |
229 |
+ |
if (cp[0] == '\\' && cp[1]) |
230 |
+ |
if (*++cp == '\n') |
231 |
+ |
goto skipspaces; |
232 |
+ |
avp[newac++] = cp; /* add argument to list */ |
233 |
+ |
if (inquote) { |
234 |
+ |
while (*++cp) |
235 |
+ |
if (*cp == inquote) { |
236 |
+ |
*cp++ = '\0'; |
237 |
+ |
break; |
238 |
+ |
} |
239 |
+ |
} else { |
240 |
+ |
while (*++cp && !isspace(*cp)) |
241 |
+ |
; |
242 |
+ |
} |
243 |
+ |
} |
244 |
+ |
for (i = fi+2; i < ac; i++) |
245 |
+ |
avp[newac++] = av[i]; |
246 |
+ |
avp[newac] = NULL; |
247 |
+ |
oldid = NULL; |
248 |
+ |
for (i = 2; i < newac; i++) |
249 |
+ |
if (!strcmp(avp[i-1], "-n")) { |
250 |
+ |
oldid = avp[i]; |
251 |
+ |
avp[i] = newid; |
252 |
+ |
break; |
253 |
+ |
} |
254 |
+ |
if (oldid == NULL) { |
255 |
+ |
newav[0] = av[0]; |
256 |
+ |
newav[1] = "-n"; |
257 |
+ |
newav[2] = newid; |
258 |
+ |
avp = newav; |
259 |
+ |
newac += 2; |
260 |
+ |
} |
261 |
+ |
if (oldid == NULL) |
262 |
+ |
sprintf(newid, "i%d", k); |
263 |
+ |
else |
264 |
+ |
sprintf(newid, "%s.%d", oldid, k); |
265 |
+ |
err |= main(newac, avp); |
266 |
+ |
k++; |
267 |
+ |
} |
268 |
+ |
fclose(argfp); |
269 |
+ |
return(err); |
270 |
+ |
} |
271 |
+ |
|
272 |
+ |
|
273 |
|
doarray(ac, av, ai) /* make array */ |
274 |
|
char **av; |
275 |
|
int ac, ai; |
277 |
|
char *newav[256], **avp; |
278 |
|
char newid[128], repts[32]; |
279 |
|
char *oldid = NULL; |
280 |
< |
int i, err; |
280 |
> |
int n, i, err; |
281 |
|
|
282 |
+ |
if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) { |
283 |
+ |
fprintf(stderr, "%s: missing count for -a option\n", av[0]); |
284 |
+ |
exit(1); |
285 |
+ |
} |
286 |
+ |
nrept *= n; |
287 |
|
avp = newav+2; |
288 |
|
avp[0] = av[0]; |
289 |
|
for (i = 1; i < ac; i++) |
303 |
|
ac += 2; |
304 |
|
} |
305 |
|
err = 0; |
306 |
< |
for (i = 0; i < atoi(av[ai+1]); i++) { |
306 |
> |
for (i = 0; i < n; i++) { |
307 |
|
if (oldid == NULL) |
308 |
|
sprintf(newid, "a%d", i); |
309 |
|
else |
319 |
|
char *name; |
320 |
|
register FILE *fin; |
321 |
|
{ |
322 |
+ |
int nobjs = 0; |
323 |
|
register int c; |
324 |
|
|
325 |
|
while ((c = getc(fin)) != EOF) { |
335 |
|
} else if (c == '!') { /* command */ |
336 |
|
ungetc(c, fin); |
337 |
|
xfcomm(name, fin); |
338 |
+ |
nobjs++; |
339 |
|
} else { /* object */ |
340 |
|
ungetc(c, fin); |
341 |
|
xfobject(name, fin); |
342 |
+ |
nobjs++; |
343 |
|
} |
344 |
|
} |
345 |
+ |
if (nobjs == 0) |
346 |
+ |
fprintf(stderr, "%s: (%s): warning - empty file\n", |
347 |
+ |
progname, name); |
348 |
|
} |
349 |
|
|
350 |
|
|
351 |
|
xfcomm(fname, fin) /* transform a command */ |
352 |
+ |
char *fname; |
353 |
|
FILE *fin; |
354 |
|
{ |
202 |
– |
FILE *popen(); |
203 |
– |
char *fgetline(); |
355 |
|
FILE *pin; |
356 |
|
char buf[512]; |
357 |
|
int i; |
358 |
|
|
359 |
|
fgetline(buf, sizeof(buf), fin); |
360 |
|
if (expand) { |
361 |
< |
if (xac > 2) { |
362 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
363 |
< |
fprintf(stderr, |
364 |
< |
"%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); |
361 |
> |
if ((pin = popen(buf+1, "r")) == NULL) { |
362 |
> |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
363 |
> |
progname, fname, buf); |
364 |
> |
exit(1); |
365 |
|
} |
366 |
+ |
xform(buf, pin); |
367 |
+ |
pclose(pin); |
368 |
|
} else { |
369 |
|
printf("\n%s", buf); |
370 |
|
if (xac > 1) { |
371 |
< |
printf(" | %s -e", xav[0]); |
371 |
> |
printf(" | %s -e", xav[0]); /* expand next time */ |
372 |
|
for (i = 1; i < xac; i++) |
373 |
< |
printf(" %s", xav[i]); |
373 |
> |
if (i >= xfa || strcmp(xav[i], "-c")) |
374 |
> |
printf(" %s", xav[i]); |
375 |
|
} |
376 |
|
putchar('\n'); |
377 |
|
} |
382 |
|
char *fname; |
383 |
|
FILE *fin; |
384 |
|
{ |
239 |
– |
extern char *strcpy(); |
385 |
|
char typ[16], nam[MAXSTR]; |
386 |
|
int fn; |
387 |
|
/* modifier and type */ |
393 |
|
progname, fname, typ); |
394 |
|
exit(1); |
395 |
|
} |
396 |
< |
if (issurface(fn)) |
396 |
> |
if (ismodifier(fn)) |
397 |
> |
printf("\n%s %s ", nam, typ); |
398 |
> |
else |
399 |
|
printf("\n%s %s ", newmod != NULL ? newmod : nam, |
400 |
|
invert ? ofun[tinvers[fn]].funame : typ); |
254 |
– |
else |
255 |
– |
printf("\n%s %s ", nam, typ); |
401 |
|
/* object name */ |
402 |
|
fgetword(nam, sizeof(nam), fin); |
403 |
< |
if (idprefix != NULL && issurface(fn)) |
259 |
< |
printf("%s.%s\n", idprefix, nam); |
260 |
< |
else |
403 |
> |
if (idprefix == NULL || ismodifier(fn)) |
404 |
|
printf("%s\n", nam); |
405 |
+ |
else |
406 |
+ |
printf("%s.%s\n", idprefix, nam); |
407 |
|
/* transform arguments */ |
408 |
|
if ((*ofun[fn].funp)(fin) < 0) { |
409 |
|
fprintf(stderr, "%s: (%s): bad %s \"%s\"\n", |
417 |
|
FILE *fin; |
418 |
|
{ |
419 |
|
register int i; |
420 |
< |
FUNARGS fa; |
420 |
> |
FUNARGS fa; |
421 |
|
|
422 |
|
if (readfargs(&fa, fin) != 1) |
423 |
|
return(-1); |
424 |
|
/* string arguments */ |
425 |
|
printf("%d", fa.nsargs); |
426 |
< |
for (i = 0; i < fa.nsargs; i++) |
427 |
< |
printf(" %s", fa.sarg[i]); |
426 |
> |
for (i = 0; i < fa.nsargs; i++) { |
427 |
> |
fputc(' ', stdout); |
428 |
> |
fputword(fa.sarg[i], stdout); |
429 |
> |
} |
430 |
|
printf("\n"); |
431 |
< |
#ifdef IARGS |
431 |
> |
#ifdef IARGS |
432 |
|
/* integer arguments */ |
433 |
|
printf("%d", fa.niargs); |
434 |
|
for (i = 0; i < fa.niargs; i++) |
451 |
|
FILE *fin; |
452 |
|
{ |
453 |
|
register int i; |
454 |
< |
FUNARGS fa; |
454 |
> |
int resetarr = 0; |
455 |
> |
FUNARGS fa; |
456 |
|
|
457 |
|
if (readfargs(&fa, fin) != 1) |
458 |
|
return(-1); |
459 |
|
/* string arguments */ |
460 |
< |
printf("%d", fa.nsargs + xac-xfa); |
461 |
< |
for (i = 0; i < fa.nsargs; i++) |
462 |
< |
printf(" %s", fa.sarg[i]); |
460 |
> |
if (xac > xfa && strcmp(xav[xfa], "-i")) |
461 |
> |
resetarr = 2; |
462 |
> |
printf("%d", fa.nsargs + resetarr + xac-xfa); |
463 |
> |
for (i = 0; i < fa.nsargs; i++) { |
464 |
> |
fputc(' ', stdout); |
465 |
> |
fputword(fa.sarg[i], stdout); |
466 |
> |
} |
467 |
> |
if (resetarr) |
468 |
> |
printf(" -i 1"); |
469 |
|
for (i = xfa; i < xac; i++) /* add xf arguments */ |
470 |
|
printf(" %s", xav[i]); |
471 |
|
printf("\n"); |
472 |
< |
#ifdef IARGS |
472 |
> |
#ifdef IARGS |
473 |
|
/* integer arguments */ |
474 |
|
printf("%d", fa.niargs); |
475 |
|
for (i = 0; i < fa.niargs; i++) |
488 |
|
} |
489 |
|
|
490 |
|
|
337 |
– |
int |
338 |
– |
otype(ofname) /* get object function number from its name */ |
339 |
– |
register char *ofname; |
340 |
– |
{ |
341 |
– |
register int i; |
342 |
– |
|
343 |
– |
for (i = 0; i < NUMTYPES; i++) |
344 |
– |
if (!strcmp(ofun[i].funame, ofname)) |
345 |
– |
return(i); |
346 |
– |
|
347 |
– |
return(-1); /* not found */ |
348 |
– |
} |
349 |
– |
|
350 |
– |
|
491 |
|
alias(fin) /* transfer alias */ |
492 |
|
FILE *fin; |
493 |
|
{ |
503 |
|
m_glow(fin) /* transform arguments for proximity light */ |
504 |
|
FILE *fin; |
505 |
|
{ |
506 |
< |
FUNARGS fa; |
506 |
> |
FUNARGS fa; |
507 |
|
|
508 |
|
if (readfargs(&fa, fin) != 1) |
509 |
|
return(-1); |
522 |
|
FILE *fin; |
523 |
|
{ |
524 |
|
FVECT v; |
525 |
< |
FUNARGS fa; |
525 |
> |
FUNARGS fa; |
526 |
|
|
527 |
|
if (readfargs(&fa, fin) != 1) |
528 |
|
return(-1); |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
+ |
m_mist(fin) /* transform arguments for mist */ |
542 |
+ |
FILE *fin; |
543 |
+ |
{ |
544 |
+ |
FUNARGS fa; |
545 |
+ |
int i; |
546 |
+ |
|
547 |
+ |
if (readfargs(&fa, fin) != 1) |
548 |
+ |
return(-1); |
549 |
+ |
if (fa.nfargs > 7) |
550 |
+ |
return(-1); |
551 |
+ |
printf("%d", fa.nsargs); |
552 |
+ |
if (idprefix == NULL) |
553 |
+ |
for (i = 0; i < fa.nsargs; i++) |
554 |
+ |
printf(" %s", fa.sarg[i]); |
555 |
+ |
else |
556 |
+ |
for (i = 0; i < fa.nsargs; i++) { |
557 |
+ |
char sname[256], *sp; |
558 |
+ |
register char *cp1, *cp2 = sname; |
559 |
+ |
/* add idprefix */ |
560 |
+ |
for (sp = fa.sarg[i]; *sp; sp = cp1) { |
561 |
+ |
for (cp1 = idprefix; *cp1; ) |
562 |
+ |
*cp2++ = *cp1++; |
563 |
+ |
*cp2++ = '.'; |
564 |
+ |
for (cp1 = sp; *cp1 && |
565 |
+ |
(*cp2++ = *cp1++) != '>'; ) |
566 |
+ |
; |
567 |
+ |
} |
568 |
+ |
*cp2 = '\0'; |
569 |
+ |
printf(" %s", sname); |
570 |
+ |
} |
571 |
+ |
printf("\n0\n%d", fa.nfargs); |
572 |
+ |
if (fa.nfargs > 2) |
573 |
+ |
printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca, |
574 |
+ |
fa.farg[1]/tot.sca, fa.farg[2]/tot.sca); |
575 |
+ |
for (i = 3; i < fa.nfargs; i++) |
576 |
+ |
printf(" %12.6g", fa.farg[i]); |
577 |
+ |
printf("\n"); |
578 |
+ |
freefargs(&fa); |
579 |
+ |
return(0); |
580 |
+ |
} |
581 |
+ |
|
582 |
+ |
|
583 |
|
m_dielectric(fin) /* transform arguments for dielectric */ |
584 |
|
FILE *fin; |
585 |
|
{ |
586 |
< |
double pow(); |
405 |
< |
FUNARGS fa; |
586 |
> |
FUNARGS fa; |
587 |
|
|
588 |
|
if (readfargs(&fa, fin) != 1) |
589 |
|
return(-1); |
590 |
|
if (fa.nsargs != 0 || fa.nfargs != 5) |
591 |
|
return(-1); |
592 |
|
printf("0\n0\n5"); |
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 %18.12g\n", fa.farg[3], fa.farg[4]); |
597 |
> |
printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]); |
598 |
|
freefargs(&fa); |
599 |
|
return(0); |
600 |
|
} |
603 |
|
m_interface(fin) /* transform arguments for interface */ |
604 |
|
FILE *fin; |
605 |
|
{ |
606 |
< |
double pow(); |
426 |
< |
FUNARGS fa; |
606 |
> |
FUNARGS fa; |
607 |
|
|
608 |
|
if (readfargs(&fa, fin) != 1) |
609 |
|
return(-1); |
610 |
|
if (fa.nsargs != 0 || fa.nfargs != 8) |
611 |
|
return(-1); |
612 |
|
printf("0\n0\n8\n"); |
613 |
< |
printf("%18.12g %18.12g %18.12g", |
613 |
> |
printf("%12.6g %12.6g %12.6g", |
614 |
|
pow(fa.farg[0], 1.0/tot.sca), |
615 |
|
pow(fa.farg[1], 1.0/tot.sca), |
616 |
|
pow(fa.farg[2], 1.0/tot.sca)); |
617 |
< |
printf(" %18.12g\n", fa.farg[3]); |
618 |
< |
printf("%18.12g %18.12g %18.12g", |
617 |
> |
printf(" %12.6g\n", fa.farg[3]); |
618 |
> |
printf("%12.6g %12.6g %12.6g", |
619 |
|
pow(fa.farg[4], 1.0/tot.sca), |
620 |
|
pow(fa.farg[5], 1.0/tot.sca), |
621 |
|
pow(fa.farg[6], 1.0/tot.sca)); |
622 |
< |
printf(" %18.12g\n", fa.farg[7]); |
622 |
> |
printf(" %12.6g\n", fa.farg[7]); |
623 |
|
freefargs(&fa); |
624 |
|
return(0); |
625 |
|
} |
630 |
|
{ |
631 |
|
int i; |
632 |
|
FVECT v; |
633 |
< |
FUNARGS fa; |
633 |
> |
FUNARGS fa; |
634 |
|
|
635 |
|
if (readfargs(&fa, fin) != 1) |
636 |
|
return(-1); |
637 |
< |
if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15) |
637 |
> |
if (fa.nfargs < 9) |
638 |
|
return(-1); |
639 |
|
/* string arguments */ |
640 |
|
printf("%d", fa.nsargs); |
641 |
< |
for (i = 0; i < fa.nsargs; i++) |
642 |
< |
printf(" %s", fa.sarg[i]); |
641 |
> |
for (i = 0; i < fa.nsargs; i++) { |
642 |
> |
fputc(' ', stdout); |
643 |
> |
fputword(fa.sarg[i], stdout); |
644 |
> |
} |
645 |
|
printf("\n0\n%d\n", fa.nfargs); |
646 |
|
/* anchor point */ |
647 |
|
multp3(v, fa.farg, tot.xfm); |
651 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
652 |
|
/* down vector */ |
653 |
|
multv3(v, fa.farg+6, tot.xfm); |
654 |
< |
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
655 |
< |
/* forground and background */ |
656 |
< |
if (fa.nfargs == 11) |
657 |
< |
printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]); |
658 |
< |
else if (fa.nfargs == 15) { |
659 |
< |
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]); |
654 |
> |
printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]); |
655 |
> |
/* remaining arguments */ |
656 |
> |
for (i = 9; i < fa.nfargs; i++) { |
657 |
> |
if (i%3 == 0) |
658 |
> |
putchar('\n'); |
659 |
> |
printf(" %18.12g", fa.farg[i]); |
660 |
|
} |
661 |
+ |
putchar('\n'); |
662 |
|
freefargs(&fa); |
663 |
|
return(0); |
664 |
|
} |
668 |
|
FILE *fin; |
669 |
|
{ |
670 |
|
FVECT dv; |
671 |
< |
FUNARGS fa; |
671 |
> |
FUNARGS fa; |
672 |
|
|
673 |
|
if (readfargs(&fa, fin) != 1) |
674 |
|
return(-1); |
689 |
|
FILE *fin; |
690 |
|
{ |
691 |
|
FVECT cent; |
692 |
< |
double rad; |
693 |
< |
FUNARGS fa; |
692 |
> |
double rad; |
693 |
> |
FUNARGS fa; |
694 |
|
|
695 |
|
if (readfargs(&fa, fin) != 1) |
696 |
|
return(-1); |
697 |
|
if (fa.nsargs != 0 || fa.nfargs != 4) |
698 |
|
return(-1); |
699 |
|
|
700 |
< |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
700 |
> |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
701 |
|
|
702 |
|
rad = fa.farg[3] * tot.sca; /* scale radius */ |
703 |
|
|
714 |
|
{ |
715 |
|
FVECT p; |
716 |
|
register int i; |
717 |
< |
FUNARGS fa; |
717 |
> |
FUNARGS fa; |
718 |
|
|
719 |
|
if (readfargs(&fa, fin) != 1) |
720 |
|
return(-1); |
739 |
|
FILE *fin; |
740 |
|
{ |
741 |
|
FVECT p0, p1; |
742 |
< |
double r0, r1; |
743 |
< |
FUNARGS fa; |
742 |
> |
double r0, r1; |
743 |
> |
FUNARGS fa; |
744 |
|
|
745 |
|
if (readfargs(&fa, fin) != 1) |
746 |
|
return(-1); |
766 |
|
FILE *fin; |
767 |
|
{ |
768 |
|
FVECT p0, p1; |
769 |
< |
double rad; |
770 |
< |
FUNARGS fa; |
769 |
> |
double rad; |
770 |
> |
FUNARGS fa; |
771 |
|
|
772 |
|
if (readfargs(&fa, fin) != 1) |
773 |
|
return(-1); |
791 |
|
FILE *fin; |
792 |
|
{ |
793 |
|
FVECT p0, pd; |
794 |
< |
double r0, r1; |
795 |
< |
FUNARGS fa; |
794 |
> |
double r0, r1; |
795 |
> |
FUNARGS fa; |
796 |
|
|
797 |
|
if (readfargs(&fa, fin) != 1) |
798 |
|
return(-1); |
820 |
|
|
821 |
|
initotypes() /* initialize ofun[] array */ |
822 |
|
{ |
643 |
– |
extern int o_source(); |
644 |
– |
extern int o_sphere(); |
645 |
– |
extern int o_face(); |
646 |
– |
extern int o_cone(); |
647 |
– |
extern int o_cylinder(); |
648 |
– |
extern int o_ring(); |
649 |
– |
extern int m_glow(); |
650 |
– |
extern int m_spot(); |
651 |
– |
extern int m_dielectric(); |
652 |
– |
extern int m_interface(); |
653 |
– |
extern int text(); |
654 |
– |
extern int alias(); |
655 |
– |
extern int passargs(); |
656 |
– |
extern int addxform(); |
823 |
|
register int i; |
824 |
|
|
825 |
|
if (ofun[OBJ_SOURCE].funp == o_source) |
826 |
|
return; /* done already */ |
661 |
– |
/* alias is additional */ |
662 |
– |
ofun[ALIAS].funame = ALIASID; |
663 |
– |
ofun[ALIAS].flags = 0; |
827 |
|
/* functions get new transform */ |
828 |
< |
for (i = 0; i < NUMTYPES; i++) |
828 |
> |
for (i = 0; i < NUMOTYPE; i++) |
829 |
|
if (hasfunc(i)) |
830 |
|
ofun[i].funp = addxform; |
831 |
|
/* special cases */ |
843 |
|
ofun[MAT_SPOT].funp = m_spot; |
844 |
|
ofun[MAT_DIELECTRIC].funp = m_dielectric; |
845 |
|
ofun[MAT_INTERFACE].funp = m_interface; |
846 |
+ |
ofun[MAT_MIST].funp = m_mist; |
847 |
|
ofun[PAT_CTEXT].funp = |
848 |
|
ofun[PAT_BTEXT].funp = |
849 |
|
ofun[MIX_TEXT].funp = text; |
850 |
< |
ofun[ALIAS].funp = alias; |
850 |
> |
ofun[MOD_ALIAS].funp = alias; |
851 |
|
/* surface inverses */ |
852 |
+ |
tinvers[OBJ_FACE] = OBJ_FACE; |
853 |
|
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
854 |
|
tinvers[OBJ_CONE] = OBJ_CUP; |
855 |
|
tinvers[OBJ_CUP] = OBJ_CONE; |
860 |
|
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
861 |
|
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
862 |
|
} |
863 |
+ |
|
864 |
+ |
|
865 |
+ |
#ifdef OLDXFORM |
866 |
+ |
openmain(fname) |
867 |
+ |
char *fname; |
868 |
+ |
{ |
869 |
+ |
if (fname == NULL) { |
870 |
+ |
strcpy(mainfn, "standard input"); |
871 |
+ |
mainfp = stdin; |
872 |
+ |
return; |
873 |
+ |
} |
874 |
+ |
if (mainfp != NULL) { |
875 |
+ |
if (!strcmp(fname, mainfn)) { |
876 |
+ |
rewind(mainfp); |
877 |
+ |
return; |
878 |
+ |
} |
879 |
+ |
fclose(mainfp); |
880 |
+ |
} |
881 |
+ |
if ((mainfp = fopen(fname, "r")) == NULL) { |
882 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
883 |
+ |
progname, fname); |
884 |
+ |
exit(1); |
885 |
+ |
} |
886 |
+ |
strcpy(mainfn, fname); |
887 |
+ |
} |
888 |
+ |
#else |
889 |
+ |
openmain(iname) /* open input, changing directory for file */ |
890 |
+ |
char *iname; |
891 |
+ |
{ |
892 |
+ |
static char origdir[MAXPATH]; |
893 |
+ |
static char curfn[MAXPATH]; |
894 |
+ |
static int diffdir; |
895 |
+ |
register char *fpath; |
896 |
+ |
|
897 |
+ |
if (iname == NULL) { /* standard input */ |
898 |
+ |
if (mainfp == NULL) { |
899 |
+ |
register int c; |
900 |
+ |
strcpy(mainfn, "standard input"); |
901 |
+ |
if (nrept <= 1) { |
902 |
+ |
mainfp = stdin; |
903 |
+ |
return; /* just read once */ |
904 |
+ |
} |
905 |
+ |
/* else copy */ |
906 |
+ |
if ((mainfp = tmpfile()) == NULL) { |
907 |
+ |
fprintf(stderr, |
908 |
+ |
"%s: cannot create temporary file\n", |
909 |
+ |
progname); |
910 |
+ |
exit(1); |
911 |
+ |
} |
912 |
+ |
while ((c = getc(stdin)) != EOF) |
913 |
+ |
putc(c, mainfp); |
914 |
+ |
} |
915 |
+ |
rewind(mainfp); /* rewind copy */ |
916 |
+ |
return; |
917 |
+ |
} |
918 |
+ |
if (mainfp == NULL) { /* first call, initialize */ |
919 |
+ |
getwd(origdir); |
920 |
+ |
} else if (!strcmp(iname, curfn)) { /* just need to rewind? */ |
921 |
+ |
rewind(mainfp); |
922 |
+ |
return; |
923 |
+ |
} else { /* else close old stream */ |
924 |
+ |
fclose(mainfp); |
925 |
+ |
mainfp = NULL; |
926 |
+ |
if (diffdir) { /* return to our directory */ |
927 |
+ |
chdir(origdir); |
928 |
+ |
diffdir = 0; |
929 |
+ |
} |
930 |
+ |
} |
931 |
+ |
strcpy(curfn, iname); /* remember input name */ |
932 |
+ |
/* get full path for file */ |
933 |
+ |
if ((fpath = getpath(iname, getlibpath(), R_OK)) == NULL) { |
934 |
+ |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
935 |
+ |
progname, iname); |
936 |
+ |
exit(1); |
937 |
+ |
} |
938 |
+ |
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
939 |
+ |
fpath += 2; |
940 |
+ |
/* record path name */ |
941 |
+ |
strcpy(mainfn, fpath); |
942 |
+ |
if (expand) { /* change to local directory */ |
943 |
+ |
register char *cp = fpath + strlen(fpath); /* get dir. */ |
944 |
+ |
while (cp > fpath) { |
945 |
+ |
cp--; |
946 |
+ |
if (ISDIRSEP(*cp)) { |
947 |
+ |
if (cp == fpath) |
948 |
+ |
cp++; /* root special case */ |
949 |
+ |
break; |
950 |
+ |
} |
951 |
+ |
} |
952 |
+ |
*cp = '\0'; |
953 |
+ |
if (fpath[0]) { /* change to new directory? */ |
954 |
+ |
if (chdir(fpath) < 0) { |
955 |
+ |
fprintf(stderr, |
956 |
+ |
"%s: cannot change directory to \"%s\"\n", |
957 |
+ |
progname, fpath); |
958 |
+ |
exit(1); |
959 |
+ |
} |
960 |
+ |
diffdir++; |
961 |
+ |
} |
962 |
+ |
/* get final path component */ |
963 |
+ |
for (fpath = iname+strlen(iname); |
964 |
+ |
fpath > iname && !ISDIRSEP(fpath[-1]); fpath--) |
965 |
+ |
; |
966 |
+ |
} |
967 |
+ |
/* finally, open the file */ |
968 |
+ |
if ((mainfp = fopen(fpath, "r")) == NULL) { |
969 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
970 |
+ |
progname, mainfn); |
971 |
+ |
exit(1); |
972 |
+ |
} |
973 |
+ |
} |
974 |
+ |
#endif |