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 |
> |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
38 |
|
|
39 |
< |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
39 |
> |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
40 |
|
|
41 |
|
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
42 |
|
|
43 |
|
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
44 |
|
|
45 |
< |
extern char *malloc(), *fgetword(); |
45 |
> |
int nrept = 1; /* number of array repetitions */ |
46 |
|
|
47 |
< |
#define progname (xav[0]) |
47 |
> |
int stdinused = 0; /* stdin has been used by -f option? */ |
48 |
|
|
49 |
+ |
char mainfn[MAXPATH]; /* main file name */ |
50 |
+ |
FILE *mainfp = NULL; /* main file pointer */ |
51 |
|
|
52 |
+ |
#define progname (xav[0]) |
53 |
+ |
|
54 |
+ |
|
55 |
|
main(argc, argv) /* get transform options and transform file */ |
56 |
|
int argc; |
57 |
|
char *argv[]; |
58 |
|
{ |
59 |
< |
FILE *fopen(); |
60 |
< |
FILE *fp; |
59 |
> |
int mal_prefix = 0; |
60 |
> |
char *fname; |
61 |
|
int a; |
62 |
< |
/* check for array */ |
62 |
> |
/* check for argument list file */ |
63 |
|
for (a = 1; a < argc; a++) |
64 |
+ |
if (!strcmp(argv[a], "-f")) |
65 |
+ |
return(doargf(argc, argv, a)); |
66 |
+ |
/* check for regular array */ |
67 |
+ |
for (a = 1; a < argc; a++) |
68 |
|
if (!strcmp(argv[a], "-a")) |
69 |
|
return(doarray(argc, argv, a)); |
70 |
|
|
71 |
< |
initotypes(); |
71 |
> |
initotypes(); /* initialize */ |
72 |
> |
invert = 0; |
73 |
> |
expand = 1; |
74 |
> |
newmod = NULL; |
75 |
> |
idprefix = NULL; |
76 |
|
|
77 |
|
for (a = 1; a < argc; a++) { |
78 |
|
if (argv[a][0] == '-') |
79 |
|
switch (argv[a][1]) { |
80 |
|
case 'm': |
81 |
< |
if (argv[a][2] || a+1 >= argc) |
81 |
> |
if (argv[a][2] | a+1 >= argc) |
82 |
|
break; |
83 |
< |
newmod = argv[++a]; |
83 |
> |
a++; |
84 |
> |
if (newmod == NULL) |
85 |
> |
newmod = argv[a]; |
86 |
|
continue; |
87 |
|
case 'n': |
88 |
< |
if (argv[a][2] || a+1 >= argc) |
88 |
> |
if (argv[a][2] | a+1 >= argc) |
89 |
|
break; |
90 |
< |
idprefix = argv[++a]; |
90 |
> |
a++; |
91 |
> |
if (idprefix == NULL) |
92 |
> |
idprefix = argv[a]; |
93 |
> |
else { |
94 |
> |
register char *newp; |
95 |
> |
newp = (char *)malloc(strlen(idprefix)+ |
96 |
> |
strlen(argv[a])+2); |
97 |
> |
if (newp == NULL) |
98 |
> |
exit(2); |
99 |
> |
sprintf(newp, "%s.%s", |
100 |
> |
idprefix, argv[a]); |
101 |
> |
if (mal_prefix++) |
102 |
> |
free((void *)idprefix); |
103 |
> |
idprefix = newp; |
104 |
> |
} |
105 |
|
continue; |
106 |
+ |
case 'c': |
107 |
+ |
if (argv[a][2]) |
108 |
+ |
break; |
109 |
+ |
expand = 0; |
110 |
+ |
continue; |
111 |
|
case 'e': |
112 |
|
if (argv[a][2]) |
113 |
|
break; |
116 |
|
case 'I': |
117 |
|
if (argv[a][2]) |
118 |
|
break; |
119 |
< |
invert = 1; |
119 |
> |
invert = !invert; |
120 |
|
continue; |
121 |
|
} |
122 |
|
break; |
145 |
|
printf(" %s", xav[a]); |
146 |
|
putchar('\n'); |
147 |
|
/* transform input */ |
148 |
< |
if (xac == argc) |
149 |
< |
xform("standard input", stdin); |
150 |
< |
else |
148 |
> |
if (xac == argc) { |
149 |
> |
if (stdinused) { |
150 |
> |
fprintf(stderr, "%s: cannot use stdin more than once\n", |
151 |
> |
argv[0]); |
152 |
> |
exit(1); |
153 |
> |
} |
154 |
> |
openmain(NULL); |
155 |
> |
xform(mainfn, mainfp); |
156 |
> |
} else |
157 |
|
for (a = xac; a < argc; a++) { |
158 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
159 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
121 |
< |
progname, argv[a]); |
122 |
< |
exit(1); |
123 |
< |
} |
124 |
< |
xform(argv[a], fp); |
125 |
< |
fclose(fp); |
158 |
> |
openmain(argv[a]); |
159 |
> |
xform(mainfn, mainfp); |
160 |
|
} |
161 |
|
|
162 |
+ |
if (mal_prefix) |
163 |
+ |
free((void *)idprefix); |
164 |
|
return(0); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
+ |
doargf(ac, av, fi) /* take argument list from file */ |
169 |
+ |
char **av; |
170 |
+ |
int ac, fi; |
171 |
+ |
{ |
172 |
+ |
int inquote; |
173 |
+ |
char *newav[256], **avp; |
174 |
+ |
char argbuf[1024]; |
175 |
+ |
char newid[128]; |
176 |
+ |
char *oldid; |
177 |
+ |
register char *cp; |
178 |
+ |
FILE *argfp; |
179 |
+ |
int n, i, k, newac, err; |
180 |
+ |
|
181 |
+ |
if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) { |
182 |
+ |
fprintf(stderr, "%s: missing file for -f option\n", av[0]); |
183 |
+ |
exit(1); |
184 |
+ |
} |
185 |
+ |
if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') { |
186 |
+ |
if (stdinused++) { |
187 |
+ |
fprintf(stderr, |
188 |
+ |
"%s: cannot use stdin more than once\n", |
189 |
+ |
av[0]); |
190 |
+ |
exit(1); |
191 |
+ |
} |
192 |
+ |
argfp = stdin; |
193 |
+ |
n = 100; /* we just don't know! */ |
194 |
+ |
} else { |
195 |
+ |
if ((argfp = fopen(av[fi+1], "r")) == NULL) { |
196 |
+ |
fprintf(stderr, |
197 |
+ |
"%s: cannot open argument file \"%s\"\n", |
198 |
+ |
av[0], av[fi+1]); |
199 |
+ |
exit(1); |
200 |
+ |
} |
201 |
+ |
n = 0; /* count number of lines in file */ |
202 |
+ |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) |
203 |
+ |
n += argbuf[0] && argbuf[0] != '#'; |
204 |
+ |
if (!n) { |
205 |
+ |
fprintf(stderr, "%s: empty argument file \"%s\"\n", |
206 |
+ |
av[0], av[fi+1]); |
207 |
+ |
exit(1); |
208 |
+ |
} |
209 |
+ |
nrept *= n; |
210 |
+ |
rewind(argfp); |
211 |
+ |
} |
212 |
+ |
err = 0; k = 0; /* read each arg list and call main */ |
213 |
+ |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) { |
214 |
+ |
if (!argbuf[0] || argbuf[0] == '#') |
215 |
+ |
continue; |
216 |
+ |
avp = newav+2; |
217 |
+ |
avp[0] = av[0]; |
218 |
+ |
for (i = 1; i < fi; i++) |
219 |
+ |
avp[i] = av[i]; |
220 |
+ |
newac = i; |
221 |
+ |
cp = argbuf; /* parse new words */ |
222 |
+ |
if (*cp == '!') cp++; |
223 |
+ |
if (!strncmp(cp, "xform ", 6)) cp += 6; |
224 |
+ |
inquote = 0; |
225 |
+ |
for ( ; ; ) { |
226 |
+ |
skipspaces: |
227 |
+ |
while (isspace(*cp)) /* nullify spaces */ |
228 |
+ |
*cp++ = '\0'; |
229 |
+ |
if ((*cp == '"' | *cp == '\'')) |
230 |
+ |
inquote = *cp++; |
231 |
+ |
if (!*cp) /* all done? */ |
232 |
+ |
break; |
233 |
+ |
if (cp[0] == '\\' && cp[1]) |
234 |
+ |
if (*++cp == '\n') |
235 |
+ |
goto skipspaces; |
236 |
+ |
avp[newac++] = cp; /* add argument to list */ |
237 |
+ |
if (inquote) { |
238 |
+ |
while (*++cp) |
239 |
+ |
if (*cp == inquote) { |
240 |
+ |
*cp++ = '\0'; |
241 |
+ |
break; |
242 |
+ |
} |
243 |
+ |
} else { |
244 |
+ |
while (*++cp && !isspace(*cp)) |
245 |
+ |
; |
246 |
+ |
} |
247 |
+ |
} |
248 |
+ |
for (i = fi+2; i < ac; i++) |
249 |
+ |
avp[newac++] = av[i]; |
250 |
+ |
avp[newac] = NULL; |
251 |
+ |
oldid = NULL; |
252 |
+ |
for (i = 2; i < newac; i++) |
253 |
+ |
if (!strcmp(avp[i-1], "-n")) { |
254 |
+ |
oldid = avp[i]; |
255 |
+ |
avp[i] = newid; |
256 |
+ |
break; |
257 |
+ |
} |
258 |
+ |
if (oldid == NULL) { |
259 |
+ |
newav[0] = av[0]; |
260 |
+ |
newav[1] = "-n"; |
261 |
+ |
newav[2] = newid; |
262 |
+ |
avp = newav; |
263 |
+ |
newac += 2; |
264 |
+ |
} |
265 |
+ |
if (oldid == NULL) |
266 |
+ |
sprintf(newid, "i%d", k); |
267 |
+ |
else |
268 |
+ |
sprintf(newid, "%s.%d", oldid, k); |
269 |
+ |
err |= main(newac, avp); |
270 |
+ |
k++; |
271 |
+ |
} |
272 |
+ |
fclose(argfp); |
273 |
+ |
return(err); |
274 |
+ |
} |
275 |
+ |
|
276 |
+ |
|
277 |
|
doarray(ac, av, ai) /* make array */ |
278 |
|
char **av; |
279 |
|
int ac, ai; |
281 |
|
char *newav[256], **avp; |
282 |
|
char newid[128], repts[32]; |
283 |
|
char *oldid = NULL; |
284 |
< |
int i, err; |
284 |
> |
int n, i, err; |
285 |
|
|
286 |
+ |
if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) { |
287 |
+ |
fprintf(stderr, "%s: missing count for -a option\n", av[0]); |
288 |
+ |
exit(1); |
289 |
+ |
} |
290 |
+ |
nrept *= n; |
291 |
|
avp = newav+2; |
292 |
|
avp[0] = av[0]; |
293 |
|
for (i = 1; i < ac; i++) |
307 |
|
ac += 2; |
308 |
|
} |
309 |
|
err = 0; |
310 |
< |
for (i = 0; i < atoi(av[ai+1]); i++) { |
310 |
> |
for (i = 0; i < n; i++) { |
311 |
|
if (oldid == NULL) |
312 |
|
sprintf(newid, "a%d", i); |
313 |
|
else |
323 |
|
char *name; |
324 |
|
register FILE *fin; |
325 |
|
{ |
326 |
+ |
int nobjs = 0; |
327 |
|
register int c; |
328 |
|
|
329 |
|
while ((c = getc(fin)) != EOF) { |
339 |
|
} else if (c == '!') { /* command */ |
340 |
|
ungetc(c, fin); |
341 |
|
xfcomm(name, fin); |
342 |
+ |
nobjs++; |
343 |
|
} else { /* object */ |
344 |
|
ungetc(c, fin); |
345 |
|
xfobject(name, fin); |
346 |
+ |
nobjs++; |
347 |
|
} |
348 |
|
} |
349 |
+ |
if (nobjs == 0) |
350 |
+ |
fprintf(stderr, "%s: (%s): warning - empty file\n", |
351 |
+ |
progname, name); |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
|
xfcomm(fname, fin) /* transform a command */ |
356 |
+ |
char *fname; |
357 |
|
FILE *fin; |
358 |
|
{ |
202 |
– |
FILE *popen(); |
203 |
– |
char *fgetline(); |
359 |
|
FILE *pin; |
360 |
|
char buf[512]; |
361 |
|
int i; |
362 |
|
|
363 |
|
fgetline(buf, sizeof(buf), fin); |
364 |
|
if (expand) { |
365 |
< |
if (xac > 2) { |
366 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
367 |
< |
fprintf(stderr, |
368 |
< |
"%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); |
365 |
> |
if ((pin = popen(buf+1, "r")) == NULL) { |
366 |
> |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
367 |
> |
progname, fname, buf); |
368 |
> |
exit(1); |
369 |
|
} |
370 |
+ |
xform(buf, pin); |
371 |
+ |
pclose(pin); |
372 |
|
} else { |
373 |
|
printf("\n%s", buf); |
374 |
|
if (xac > 1) { |
375 |
< |
printf(" | %s -e", xav[0]); |
375 |
> |
printf(" | %s -e", xav[0]); /* expand next time */ |
376 |
|
for (i = 1; i < xac; i++) |
377 |
< |
printf(" %s", xav[i]); |
377 |
> |
if (i >= xfa || strcmp(xav[i], "-c")) |
378 |
> |
printf(" %s", xav[i]); |
379 |
|
} |
380 |
|
putchar('\n'); |
381 |
|
} |
386 |
|
char *fname; |
387 |
|
FILE *fin; |
388 |
|
{ |
239 |
– |
extern char *strcpy(); |
389 |
|
char typ[16], nam[MAXSTR]; |
390 |
|
int fn; |
391 |
|
/* modifier and type */ |
397 |
|
progname, fname, typ); |
398 |
|
exit(1); |
399 |
|
} |
400 |
< |
if (issurface(fn)) |
400 |
> |
if (ismodifier(fn)) |
401 |
> |
printf("\n%s %s ", nam, typ); |
402 |
> |
else |
403 |
|
printf("\n%s %s ", newmod != NULL ? newmod : nam, |
404 |
|
invert ? ofun[tinvers[fn]].funame : typ); |
254 |
– |
else |
255 |
– |
printf("\n%s %s ", nam, typ); |
405 |
|
/* object name */ |
406 |
|
fgetword(nam, sizeof(nam), fin); |
407 |
< |
if (idprefix != NULL && issurface(fn)) |
259 |
< |
printf("%s.%s\n", idprefix, nam); |
260 |
< |
else |
407 |
> |
if (idprefix == NULL || ismodifier(fn)) |
408 |
|
printf("%s\n", nam); |
409 |
+ |
else |
410 |
+ |
printf("%s.%s\n", idprefix, nam); |
411 |
|
/* transform arguments */ |
412 |
|
if ((*ofun[fn].funp)(fin) < 0) { |
413 |
|
fprintf(stderr, "%s: (%s): bad %s \"%s\"\n", |
421 |
|
FILE *fin; |
422 |
|
{ |
423 |
|
register int i; |
424 |
< |
FUNARGS fa; |
424 |
> |
FUNARGS fa; |
425 |
|
|
426 |
|
if (readfargs(&fa, fin) != 1) |
427 |
|
return(-1); |
428 |
|
/* string arguments */ |
429 |
|
printf("%d", fa.nsargs); |
430 |
< |
for (i = 0; i < fa.nsargs; i++) |
431 |
< |
printf(" %s", fa.sarg[i]); |
430 |
> |
for (i = 0; i < fa.nsargs; i++) { |
431 |
> |
fputc(' ', stdout); |
432 |
> |
fputword(fa.sarg[i], stdout); |
433 |
> |
} |
434 |
|
printf("\n"); |
435 |
< |
#ifdef IARGS |
435 |
> |
#ifdef IARGS |
436 |
|
/* integer arguments */ |
437 |
|
printf("%d", fa.niargs); |
438 |
|
for (i = 0; i < fa.niargs; i++) |
455 |
|
FILE *fin; |
456 |
|
{ |
457 |
|
register int i; |
458 |
< |
FUNARGS fa; |
458 |
> |
int resetarr = 0; |
459 |
> |
FUNARGS fa; |
460 |
|
|
461 |
|
if (readfargs(&fa, fin) != 1) |
462 |
|
return(-1); |
463 |
|
/* string arguments */ |
464 |
< |
printf("%d", fa.nsargs + xac-xfa); |
465 |
< |
for (i = 0; i < fa.nsargs; i++) |
466 |
< |
printf(" %s", fa.sarg[i]); |
464 |
> |
if (xac > xfa && strcmp(xav[xfa], "-i")) |
465 |
> |
resetarr = 2; |
466 |
> |
printf("%d", fa.nsargs + resetarr + xac-xfa); |
467 |
> |
for (i = 0; i < fa.nsargs; i++) { |
468 |
> |
fputc(' ', stdout); |
469 |
> |
fputword(fa.sarg[i], stdout); |
470 |
> |
} |
471 |
> |
if (resetarr) |
472 |
> |
printf(" -i 1"); |
473 |
|
for (i = xfa; i < xac; i++) /* add xf arguments */ |
474 |
|
printf(" %s", xav[i]); |
475 |
|
printf("\n"); |
476 |
< |
#ifdef IARGS |
476 |
> |
#ifdef IARGS |
477 |
|
/* integer arguments */ |
478 |
|
printf("%d", fa.niargs); |
479 |
|
for (i = 0; i < fa.niargs; i++) |
521 |
|
m_glow(fin) /* transform arguments for proximity light */ |
522 |
|
FILE *fin; |
523 |
|
{ |
524 |
< |
FUNARGS fa; |
524 |
> |
FUNARGS fa; |
525 |
|
|
526 |
|
if (readfargs(&fa, fin) != 1) |
527 |
|
return(-1); |
540 |
|
FILE *fin; |
541 |
|
{ |
542 |
|
FVECT v; |
543 |
< |
FUNARGS fa; |
543 |
> |
FUNARGS fa; |
544 |
|
|
545 |
|
if (readfargs(&fa, fin) != 1) |
546 |
|
return(-1); |
556 |
|
} |
557 |
|
|
558 |
|
|
559 |
+ |
m_mist(fin) /* transform arguments for mist */ |
560 |
+ |
FILE *fin; |
561 |
+ |
{ |
562 |
+ |
FUNARGS fa; |
563 |
+ |
int i; |
564 |
+ |
|
565 |
+ |
if (readfargs(&fa, fin) != 1) |
566 |
+ |
return(-1); |
567 |
+ |
if (fa.nfargs > 7) |
568 |
+ |
return(-1); |
569 |
+ |
printf("%d", fa.nsargs); |
570 |
+ |
if (idprefix == NULL) |
571 |
+ |
for (i = 0; i < fa.nsargs; i++) |
572 |
+ |
printf(" %s", fa.sarg[i]); |
573 |
+ |
else |
574 |
+ |
for (i = 0; i < fa.nsargs; i++) { |
575 |
+ |
char sname[256], *sp; |
576 |
+ |
register char *cp1, *cp2 = sname; |
577 |
+ |
/* add idprefix */ |
578 |
+ |
for (sp = fa.sarg[i]; *sp; sp = cp1) { |
579 |
+ |
for (cp1 = idprefix; *cp1; ) |
580 |
+ |
*cp2++ = *cp1++; |
581 |
+ |
*cp2++ = '.'; |
582 |
+ |
for (cp1 = sp; *cp1 && |
583 |
+ |
(*cp2++ = *cp1++) != '>'; ) |
584 |
+ |
; |
585 |
+ |
} |
586 |
+ |
*cp2 = '\0'; |
587 |
+ |
printf(" %s", sname); |
588 |
+ |
} |
589 |
+ |
printf("\n0\n%d", fa.nfargs); |
590 |
+ |
if (fa.nfargs > 2) |
591 |
+ |
printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca, |
592 |
+ |
fa.farg[1]/tot.sca, fa.farg[2]/tot.sca); |
593 |
+ |
for (i = 3; i < fa.nfargs; i++) |
594 |
+ |
printf(" %12.6g", fa.farg[i]); |
595 |
+ |
printf("\n"); |
596 |
+ |
freefargs(&fa); |
597 |
+ |
return(0); |
598 |
+ |
} |
599 |
+ |
|
600 |
+ |
|
601 |
|
m_dielectric(fin) /* transform arguments for dielectric */ |
602 |
|
FILE *fin; |
603 |
|
{ |
604 |
< |
double pow(); |
405 |
< |
FUNARGS fa; |
604 |
> |
FUNARGS fa; |
605 |
|
|
606 |
|
if (readfargs(&fa, fin) != 1) |
607 |
|
return(-1); |
608 |
|
if (fa.nsargs != 0 || fa.nfargs != 5) |
609 |
|
return(-1); |
610 |
|
printf("0\n0\n5"); |
611 |
< |
printf(" %18.12g %18.12g %18.12g", |
611 |
> |
printf(" %12.6g %12.6g %12.6g", |
612 |
|
pow(fa.farg[0], 1.0/tot.sca), |
613 |
|
pow(fa.farg[1], 1.0/tot.sca), |
614 |
|
pow(fa.farg[2], 1.0/tot.sca)); |
615 |
< |
printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]); |
615 |
> |
printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]); |
616 |
|
freefargs(&fa); |
617 |
|
return(0); |
618 |
|
} |
621 |
|
m_interface(fin) /* transform arguments for interface */ |
622 |
|
FILE *fin; |
623 |
|
{ |
624 |
< |
double pow(); |
426 |
< |
FUNARGS fa; |
624 |
> |
FUNARGS fa; |
625 |
|
|
626 |
|
if (readfargs(&fa, fin) != 1) |
627 |
|
return(-1); |
628 |
|
if (fa.nsargs != 0 || fa.nfargs != 8) |
629 |
|
return(-1); |
630 |
|
printf("0\n0\n8\n"); |
631 |
< |
printf("%18.12g %18.12g %18.12g", |
631 |
> |
printf("%12.6g %12.6g %12.6g", |
632 |
|
pow(fa.farg[0], 1.0/tot.sca), |
633 |
|
pow(fa.farg[1], 1.0/tot.sca), |
634 |
|
pow(fa.farg[2], 1.0/tot.sca)); |
635 |
< |
printf(" %18.12g\n", fa.farg[3]); |
636 |
< |
printf("%18.12g %18.12g %18.12g", |
635 |
> |
printf(" %12.6g\n", fa.farg[3]); |
636 |
> |
printf("%12.6g %12.6g %12.6g", |
637 |
|
pow(fa.farg[4], 1.0/tot.sca), |
638 |
|
pow(fa.farg[5], 1.0/tot.sca), |
639 |
|
pow(fa.farg[6], 1.0/tot.sca)); |
640 |
< |
printf(" %18.12g\n", fa.farg[7]); |
640 |
> |
printf(" %12.6g\n", fa.farg[7]); |
641 |
|
freefargs(&fa); |
642 |
|
return(0); |
643 |
|
} |
648 |
|
{ |
649 |
|
int i; |
650 |
|
FVECT v; |
651 |
< |
FUNARGS fa; |
651 |
> |
FUNARGS fa; |
652 |
|
|
653 |
|
if (readfargs(&fa, fin) != 1) |
654 |
|
return(-1); |
655 |
< |
if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15) |
655 |
> |
if (fa.nfargs < 9) |
656 |
|
return(-1); |
657 |
|
/* string arguments */ |
658 |
|
printf("%d", fa.nsargs); |
659 |
< |
for (i = 0; i < fa.nsargs; i++) |
660 |
< |
printf(" %s", fa.sarg[i]); |
659 |
> |
for (i = 0; i < fa.nsargs; i++) { |
660 |
> |
fputc(' ', stdout); |
661 |
> |
fputword(fa.sarg[i], stdout); |
662 |
> |
} |
663 |
|
printf("\n0\n%d\n", fa.nfargs); |
664 |
|
/* anchor point */ |
665 |
|
multp3(v, fa.farg, tot.xfm); |
669 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
670 |
|
/* down vector */ |
671 |
|
multv3(v, fa.farg+6, tot.xfm); |
672 |
< |
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
673 |
< |
/* forground and background */ |
674 |
< |
if (fa.nfargs == 11) |
675 |
< |
printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]); |
676 |
< |
else if (fa.nfargs == 15) { |
677 |
< |
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]); |
672 |
> |
printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]); |
673 |
> |
/* remaining arguments */ |
674 |
> |
for (i = 9; i < fa.nfargs; i++) { |
675 |
> |
if (i%3 == 0) |
676 |
> |
putchar('\n'); |
677 |
> |
printf(" %18.12g", fa.farg[i]); |
678 |
|
} |
679 |
+ |
putchar('\n'); |
680 |
|
freefargs(&fa); |
681 |
|
return(0); |
682 |
|
} |
686 |
|
FILE *fin; |
687 |
|
{ |
688 |
|
FVECT dv; |
689 |
< |
FUNARGS fa; |
689 |
> |
FUNARGS fa; |
690 |
|
|
691 |
|
if (readfargs(&fa, fin) != 1) |
692 |
|
return(-1); |
707 |
|
FILE *fin; |
708 |
|
{ |
709 |
|
FVECT cent; |
710 |
< |
double rad; |
711 |
< |
FUNARGS fa; |
710 |
> |
double rad; |
711 |
> |
FUNARGS fa; |
712 |
|
|
713 |
|
if (readfargs(&fa, fin) != 1) |
714 |
|
return(-1); |
715 |
|
if (fa.nsargs != 0 || fa.nfargs != 4) |
716 |
|
return(-1); |
717 |
|
|
718 |
< |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
718 |
> |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
719 |
|
|
720 |
|
rad = fa.farg[3] * tot.sca; /* scale radius */ |
721 |
|
|
732 |
|
{ |
733 |
|
FVECT p; |
734 |
|
register int i; |
735 |
< |
FUNARGS fa; |
735 |
> |
FUNARGS fa; |
736 |
|
|
737 |
|
if (readfargs(&fa, fin) != 1) |
738 |
|
return(-1); |
757 |
|
FILE *fin; |
758 |
|
{ |
759 |
|
FVECT p0, p1; |
760 |
< |
double r0, r1; |
761 |
< |
FUNARGS fa; |
760 |
> |
double r0, r1; |
761 |
> |
FUNARGS fa; |
762 |
|
|
763 |
|
if (readfargs(&fa, fin) != 1) |
764 |
|
return(-1); |
784 |
|
FILE *fin; |
785 |
|
{ |
786 |
|
FVECT p0, p1; |
787 |
< |
double rad; |
788 |
< |
FUNARGS fa; |
787 |
> |
double rad; |
788 |
> |
FUNARGS fa; |
789 |
|
|
790 |
|
if (readfargs(&fa, fin) != 1) |
791 |
|
return(-1); |
809 |
|
FILE *fin; |
810 |
|
{ |
811 |
|
FVECT p0, pd; |
812 |
< |
double r0, r1; |
813 |
< |
FUNARGS fa; |
812 |
> |
double r0, r1; |
813 |
> |
FUNARGS fa; |
814 |
|
|
815 |
|
if (readfargs(&fa, fin) != 1) |
816 |
|
return(-1); |
838 |
|
|
839 |
|
initotypes() /* initialize ofun[] array */ |
840 |
|
{ |
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(); |
841 |
|
register int i; |
842 |
|
|
843 |
|
if (ofun[OBJ_SOURCE].funp == o_source) |
864 |
|
ofun[MAT_SPOT].funp = m_spot; |
865 |
|
ofun[MAT_DIELECTRIC].funp = m_dielectric; |
866 |
|
ofun[MAT_INTERFACE].funp = m_interface; |
867 |
+ |
ofun[MAT_MIST].funp = m_mist; |
868 |
|
ofun[PAT_CTEXT].funp = |
869 |
|
ofun[PAT_BTEXT].funp = |
870 |
|
ofun[MIX_TEXT].funp = text; |
871 |
|
ofun[ALIAS].funp = alias; |
872 |
|
/* surface inverses */ |
873 |
+ |
tinvers[OBJ_FACE] = OBJ_FACE; |
874 |
|
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
875 |
|
tinvers[OBJ_CONE] = OBJ_CUP; |
876 |
|
tinvers[OBJ_CUP] = OBJ_CONE; |
881 |
|
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
882 |
|
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
883 |
|
} |
884 |
+ |
|
885 |
+ |
|
886 |
+ |
#ifdef OLDXFORM |
887 |
+ |
openmain(fname) |
888 |
+ |
char *fname; |
889 |
+ |
{ |
890 |
+ |
if (fname == NULL) { |
891 |
+ |
strcpy(mainfn, "standard input"); |
892 |
+ |
mainfp = stdin; |
893 |
+ |
return; |
894 |
+ |
} |
895 |
+ |
if (mainfp != NULL) { |
896 |
+ |
if (!strcmp(fname, mainfn)) { |
897 |
+ |
rewind(mainfp); |
898 |
+ |
return; |
899 |
+ |
} |
900 |
+ |
fclose(mainfp); |
901 |
+ |
} |
902 |
+ |
if ((mainfp = fopen(fname, "r")) == NULL) { |
903 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
904 |
+ |
progname, fname); |
905 |
+ |
exit(1); |
906 |
+ |
} |
907 |
+ |
strcpy(mainfn, fname); |
908 |
+ |
} |
909 |
+ |
#else |
910 |
+ |
openmain(iname) /* open input, changing directory for file */ |
911 |
+ |
char *iname; |
912 |
+ |
{ |
913 |
+ |
static char origdir[MAXPATH]; |
914 |
+ |
static char curfn[MAXPATH]; |
915 |
+ |
static int diffdir; |
916 |
+ |
register char *fpath; |
917 |
+ |
|
918 |
+ |
if (iname == NULL) { /* standard input */ |
919 |
+ |
if (mainfp == NULL) { |
920 |
+ |
register int c; |
921 |
+ |
strcpy(mainfn, "standard input"); |
922 |
+ |
if (nrept <= 1) { |
923 |
+ |
mainfp = stdin; |
924 |
+ |
return; /* just read once */ |
925 |
+ |
} |
926 |
+ |
/* else copy */ |
927 |
+ |
if ((mainfp = tmpfile()) == NULL) { |
928 |
+ |
fprintf(stderr, |
929 |
+ |
"%s: cannot create temporary file\n", |
930 |
+ |
progname); |
931 |
+ |
exit(1); |
932 |
+ |
} |
933 |
+ |
while ((c = getc(stdin)) != EOF) |
934 |
+ |
putc(c, mainfp); |
935 |
+ |
} |
936 |
+ |
rewind(mainfp); /* rewind copy */ |
937 |
+ |
return; |
938 |
+ |
} |
939 |
+ |
if (mainfp == NULL) { /* first call, initialize */ |
940 |
+ |
getwd(origdir); |
941 |
+ |
} else if (!strcmp(iname, curfn)) { /* just need to rewind? */ |
942 |
+ |
rewind(mainfp); |
943 |
+ |
return; |
944 |
+ |
} else { /* else close old stream */ |
945 |
+ |
fclose(mainfp); |
946 |
+ |
mainfp = NULL; |
947 |
+ |
if (diffdir) { /* return to our directory */ |
948 |
+ |
chdir(origdir); |
949 |
+ |
diffdir = 0; |
950 |
+ |
} |
951 |
+ |
} |
952 |
+ |
strcpy(curfn, iname); /* remember input name */ |
953 |
+ |
/* get full path for file */ |
954 |
+ |
if ((fpath = getpath(iname, getlibpath(), R_OK)) == NULL) { |
955 |
+ |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
956 |
+ |
progname, iname); |
957 |
+ |
exit(1); |
958 |
+ |
} |
959 |
+ |
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
960 |
+ |
fpath += 2; |
961 |
+ |
/* record path name */ |
962 |
+ |
strcpy(mainfn, fpath); |
963 |
+ |
if (expand) { /* change to local directory */ |
964 |
+ |
register char *cp = fpath + strlen(fpath); /* get dir. */ |
965 |
+ |
while (cp > fpath) { |
966 |
+ |
cp--; |
967 |
+ |
if (ISDIRSEP(*cp)) { |
968 |
+ |
if (cp == fpath) |
969 |
+ |
cp++; /* root special case */ |
970 |
+ |
break; |
971 |
+ |
} |
972 |
+ |
} |
973 |
+ |
*cp = '\0'; |
974 |
+ |
if (fpath[0]) { /* change to new directory? */ |
975 |
+ |
if (chdir(fpath) < 0) { |
976 |
+ |
fprintf(stderr, |
977 |
+ |
"%s: cannot change directory to \"%s\"\n", |
978 |
+ |
progname, fpath); |
979 |
+ |
exit(1); |
980 |
+ |
} |
981 |
+ |
diffdir++; |
982 |
+ |
} |
983 |
+ |
/* get final path component */ |
984 |
+ |
for (fpath = iname+strlen(iname); |
985 |
+ |
fpath > iname && !ISDIRSEP(fpath[-1]); fpath--) |
986 |
+ |
; |
987 |
+ |
} |
988 |
+ |
/* finally, open the file */ |
989 |
+ |
if ((mainfp = fopen(fpath, "r")) == NULL) { |
990 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
991 |
+ |
progname, mainfn); |
992 |
+ |
exit(1); |
993 |
+ |
} |
994 |
+ |
} |
995 |
+ |
#endif |