1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
12 |
|
* 11/6/86 Finally added error checking! |
13 |
|
*/ |
14 |
|
|
15 |
< |
#include <stdio.h> |
15 |
> |
#include "standard.h" |
16 |
|
|
17 |
|
#include <ctype.h> |
18 |
|
|
19 |
+ |
#include "object.h" |
20 |
|
|
21 |
< |
typedef struct { |
21 |
< |
char *funame; /* function name */ |
22 |
< |
int (*funp)(); /* pointer to function */ |
23 |
< |
} FUN; |
21 |
> |
#include "otypes.h" |
22 |
|
|
23 |
|
int xac; /* global xform argument count */ |
24 |
|
char **xav; /* global xform argument pointer */ |
25 |
|
int xfa; /* start of xf arguments */ |
26 |
|
|
27 |
< |
double totxform[4][4]; /* total transformation matrix */ |
28 |
< |
double totscale; /* total scale factor */ |
31 |
< |
int reverse; /* boolean true if scene inverted */ |
27 |
> |
XF tot; /* total transformation */ |
28 |
> |
int reverse; /* boolean true if scene mirrored */ |
29 |
|
|
30 |
+ |
int invert = 0; /* boolean true to invert surfaces */ |
31 |
+ |
|
32 |
|
int expand = 0; /* boolean true to expand commands */ |
33 |
|
|
34 |
+ |
char *newmod = NULL; /* new modifier for surfaces */ |
35 |
+ |
|
36 |
|
char *idprefix = NULL; /* prefix for object identifiers */ |
37 |
|
|
38 |
< |
extern int o_source(); |
38 |
< |
extern int o_sphere(); |
39 |
< |
extern int o_face(); |
40 |
< |
extern int o_cone(); |
41 |
< |
extern int o_cylinder(); |
42 |
< |
extern int o_ring(); |
43 |
< |
extern int m_glow(); |
44 |
< |
extern int m_spot(); |
45 |
< |
extern int m_dielectric(); |
46 |
< |
extern int m_interface(); |
47 |
< |
extern int text(); |
48 |
< |
extern int alias(); |
49 |
< |
extern int passargs(); |
50 |
< |
extern int addxform(); |
38 |
> |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
39 |
|
|
40 |
< |
FUN ofun[] = { |
53 |
< |
{ "source", o_source }, |
54 |
< |
{ "sphere", o_sphere }, |
55 |
< |
{ "bubble", o_sphere }, |
56 |
< |
{ "polygon", o_face }, |
57 |
< |
{ "cone", o_cone }, |
58 |
< |
{ "cup", o_cone }, |
59 |
< |
{ "cylinder", o_cylinder }, |
60 |
< |
{ "tube", o_cylinder }, |
61 |
< |
{ "ring", o_ring }, |
62 |
< |
{ "instance", addxform }, |
63 |
< |
{ "alias", alias }, |
64 |
< |
{ "antimatter", passargs }, |
65 |
< |
{ "glow", m_glow }, |
66 |
< |
{ "spotlight", m_spot }, |
67 |
< |
{ "dielectric", m_dielectric }, |
68 |
< |
{ "interface", m_interface }, |
69 |
< |
{ "colortext", text }, |
70 |
< |
{ "brighttext", text }, |
71 |
< |
{ "texfunc", addxform }, |
72 |
< |
{ "texdata", addxform }, |
73 |
< |
{ "colorfunc", addxform }, |
74 |
< |
{ "brightfunc", addxform }, |
75 |
< |
{ "colorpict", addxform }, |
76 |
< |
{ "colordata", addxform }, |
77 |
< |
{ "brightdata", addxform }, |
78 |
< |
{ "mixfunc", addxform }, |
79 |
< |
{ "mixdata", addxform }, |
80 |
< |
{ "mixtext", text }, |
81 |
< |
{ "light", passargs }, |
82 |
< |
{ "illum", passargs }, |
83 |
< |
{ "plastic", passargs }, |
84 |
< |
{ "metal", passargs }, |
85 |
< |
{ "trans", passargs }, |
86 |
< |
{ "glass", passargs }, |
87 |
< |
{ 0 } /* terminator */ |
88 |
< |
}; |
40 |
> |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
41 |
|
|
42 |
< |
#define issurface(t) ((t)<=9) |
42 |
> |
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
43 |
|
|
44 |
< |
typedef struct { |
93 |
< |
short nsargs; /* # of string arguments */ |
94 |
< |
char **sarg; /* string arguments */ |
95 |
< |
short niargs; /* # of integer arguments */ |
96 |
< |
int *iarg; /* integer arguments */ |
97 |
< |
short nfargs; /* # of float arguments */ |
98 |
< |
double *farg; /* float arguments */ |
99 |
< |
} FUNARGS; |
44 |
> |
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
45 |
|
|
46 |
< |
#define MAXSTR 512 /* maximum string length */ |
46 |
> |
extern char *malloc(), *fgetword(); |
47 |
|
|
103 |
– |
FUNARGS *getfargs(); |
104 |
– |
char *malloc(); |
105 |
– |
|
48 |
|
#define progname (xav[0]) |
49 |
|
|
50 |
|
|
55 |
|
FILE *fopen(); |
56 |
|
FILE *fp; |
57 |
|
int a; |
58 |
+ |
/* check for array */ |
59 |
+ |
for (a = 1; a < argc; a++) |
60 |
+ |
if (!strcmp(argv[a], "-a")) |
61 |
+ |
return(doarray(argc, argv, a)); |
62 |
|
|
63 |
< |
xav = argv; |
63 |
> |
initotypes(); |
64 |
|
|
65 |
|
for (a = 1; a < argc; a++) { |
66 |
|
if (argv[a][0] == '-') |
67 |
|
switch (argv[a][1]) { |
68 |
+ |
case 'm': |
69 |
+ |
if (argv[a][2] || a+1 >= argc) |
70 |
+ |
break; |
71 |
+ |
newmod = argv[++a]; |
72 |
+ |
continue; |
73 |
|
case 'n': |
74 |
+ |
if (argv[a][2] || a+1 >= argc) |
75 |
+ |
break; |
76 |
|
idprefix = argv[++a]; |
77 |
|
continue; |
78 |
|
case 'e': |
79 |
+ |
if (argv[a][2]) |
80 |
+ |
break; |
81 |
|
expand = 1; |
82 |
|
continue; |
83 |
+ |
case 'I': |
84 |
+ |
if (argv[a][2]) |
85 |
+ |
break; |
86 |
+ |
invert = 1; |
87 |
+ |
continue; |
88 |
|
} |
89 |
|
break; |
90 |
|
} |
91 |
|
|
92 |
+ |
xav = argv; |
93 |
|
xfa = a; |
94 |
|
|
95 |
< |
totscale = 1.0; |
135 |
< |
setident4(totxform); |
95 |
> |
a += xf(&tot, argc-a, argv+a); |
96 |
|
|
97 |
< |
a += xf(totxform, &totscale, argc-a, argv+a); |
97 |
> |
if (reverse = tot.sca < 0.0) |
98 |
> |
tot.sca = -tot.sca; |
99 |
> |
if (invert) |
100 |
> |
reverse = !reverse; |
101 |
|
|
102 |
< |
if (reverse = totscale < 0.0) |
103 |
< |
totscale = -totscale; |
102 |
> |
if (a < argc && argv[a][0] == '-') { |
103 |
> |
fprintf(stderr, "%s: command line error at '%s'\n", |
104 |
> |
argv[0], argv[a]); |
105 |
> |
exit(1); |
106 |
> |
} |
107 |
|
|
108 |
|
xac = a; |
109 |
< |
|
110 |
< |
putchar('#'); /* simple header */ |
109 |
> |
/* simple header */ |
110 |
> |
putchar('#'); |
111 |
|
for (a = 0; a < xac; a++) |
112 |
|
printf(" %s", xav[a]); |
113 |
|
putchar('\n'); |
114 |
< |
|
115 |
< |
if (a == argc) |
114 |
> |
/* transform input */ |
115 |
> |
if (xac == argc) |
116 |
|
xform("standard input", stdin); |
117 |
|
else |
118 |
< |
for ( ; a < argc; a++) { |
118 |
> |
for (a = xac; a < argc; a++) { |
119 |
|
if ((fp = fopen(argv[a], "r")) == NULL) { |
120 |
|
fprintf(stderr, "%s: cannot open \"%s\"\n", |
121 |
|
progname, argv[a]); |
125 |
|
fclose(fp); |
126 |
|
} |
127 |
|
|
128 |
< |
exit(0); |
128 |
> |
return(0); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
< |
xform(name, fin) /* transform stream by totxform */ |
132 |
> |
doarray(ac, av, ai) /* make array */ |
133 |
> |
char **av; |
134 |
> |
int ac, ai; |
135 |
> |
{ |
136 |
> |
char *newav[256], **avp; |
137 |
> |
char newid[128], repts[32]; |
138 |
> |
char *oldid = NULL; |
139 |
> |
int i, err; |
140 |
> |
|
141 |
> |
avp = newav+2; |
142 |
> |
avp[0] = av[0]; |
143 |
> |
for (i = 1; i < ac; i++) |
144 |
> |
if (!strcmp(av[i-1], "-n")) { |
145 |
> |
oldid = av[i]; |
146 |
> |
avp[i] = newid; |
147 |
> |
} else |
148 |
> |
avp[i] = av[i]; |
149 |
> |
avp[ai] = "-i"; |
150 |
> |
avp[ai+1] = repts; |
151 |
> |
avp[i] = NULL; |
152 |
> |
if (oldid == NULL) { |
153 |
> |
newav[0] = av[0]; |
154 |
> |
newav[1] = "-n"; |
155 |
> |
newav[2] = newid; |
156 |
> |
avp = newav; |
157 |
> |
ac += 2; |
158 |
> |
} |
159 |
> |
err = 0; |
160 |
> |
for (i = 0; i < atoi(av[ai+1]); i++) { |
161 |
> |
if (oldid == NULL) |
162 |
> |
sprintf(newid, "a%d", i); |
163 |
> |
else |
164 |
> |
sprintf(newid, "%s.%d", oldid, i); |
165 |
> |
sprintf(repts, "%d", i); |
166 |
> |
err |= main(ac, avp); |
167 |
> |
} |
168 |
> |
return(err); |
169 |
> |
} |
170 |
> |
|
171 |
> |
|
172 |
> |
xform(name, fin) /* transform stream by tot.xfm */ |
173 |
|
char *name; |
174 |
|
register FILE *fin; |
175 |
|
{ |
187 |
|
} while (c != '\n'); |
188 |
|
} else if (c == '!') { /* command */ |
189 |
|
ungetc(c, fin); |
190 |
< |
if (expand) |
185 |
< |
xfcomm(name, fin); |
186 |
< |
else { |
187 |
< |
putchar('\n'); |
188 |
< |
while ((c = getc(fin)) != EOF && c != '\n') |
189 |
< |
putchar(c); |
190 |
< |
printf(" |"); |
191 |
< |
for (c = 0; c < xac; c++) |
192 |
< |
printf(" %s", xav[c]); |
193 |
< |
putchar('\n'); |
194 |
< |
} |
190 |
> |
xfcomm(name, fin); |
191 |
|
} else { /* object */ |
192 |
|
ungetc(c, fin); |
193 |
|
xfobject(name, fin); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
< |
xfcomm(fname, fin) /* expand a command */ |
199 |
> |
xfcomm(fname, fin) /* transform a command */ |
200 |
|
FILE *fin; |
201 |
|
{ |
202 |
|
FILE *popen(); |
203 |
< |
char *fgets(); |
203 |
> |
char *fgetline(); |
204 |
|
FILE *pin; |
205 |
|
char buf[512]; |
206 |
+ |
int i; |
207 |
|
|
208 |
< |
fgets(buf, sizeof(buf), fin); |
209 |
< |
if (buf[strlen(buf)-1] == '\n') |
210 |
< |
buf[strlen(buf)-1] = '\0'; |
211 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
212 |
< |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
213 |
< |
progname, fname, buf); |
214 |
< |
exit(1); |
208 |
> |
fgetline(buf, sizeof(buf), fin); |
209 |
> |
if (expand) { |
210 |
> |
if (xac > 2) { |
211 |
> |
if ((pin = popen(buf+1, "r")) == NULL) { |
212 |
> |
fprintf(stderr, |
213 |
> |
"%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); |
222 |
> |
} |
223 |
> |
} else { |
224 |
> |
printf("\n%s", buf); |
225 |
> |
if (xac > 1) { |
226 |
> |
printf(" | %s -e", xav[0]); |
227 |
> |
for (i = 1; i < xac; i++) |
228 |
> |
printf(" %s", xav[i]); |
229 |
> |
} |
230 |
> |
putchar('\n'); |
231 |
|
} |
219 |
– |
xform(buf, pin); |
220 |
– |
pclose(pin); |
232 |
|
} |
233 |
|
|
234 |
|
|
236 |
|
char *fname; |
237 |
|
FILE *fin; |
238 |
|
{ |
239 |
< |
char stmp[MAXSTR]; |
239 |
> |
extern char *strcpy(); |
240 |
> |
char typ[16], nam[MAXSTR]; |
241 |
|
int fn; |
242 |
< |
|
243 |
< |
fscanf(fin, "%s", stmp); /* modifier */ |
244 |
< |
printf("\n%s ", stmp); |
245 |
< |
fscanf(fin, "%s", stmp); /* object type */ |
246 |
< |
if ((fn = otype(stmp)) < 0) { |
242 |
> |
/* modifier and type */ |
243 |
> |
strcpy(typ, "EOF"); |
244 |
> |
fgetword(nam, sizeof(nam), fin); |
245 |
> |
fgetword(typ, sizeof(typ), fin); |
246 |
> |
if ((fn = otype(typ)) < 0) { |
247 |
|
fprintf(stderr, "%s: (%s): unknown object type \"%s\"\n", |
248 |
< |
progname, fname, stmp); |
248 |
> |
progname, fname, typ); |
249 |
|
exit(1); |
250 |
|
} |
251 |
< |
printf("%s ", stmp); |
252 |
< |
fscanf(fin, "%s", stmp); /* object name */ |
251 |
> |
if (issurface(fn)) |
252 |
> |
printf("\n%s %s ", newmod != NULL ? newmod : nam, |
253 |
> |
invert ? ofun[tinvers[fn]].funame : typ); |
254 |
> |
else |
255 |
> |
printf("\n%s %s ", nam, typ); |
256 |
> |
/* object name */ |
257 |
> |
fgetword(nam, sizeof(nam), fin); |
258 |
|
if (idprefix != NULL && issurface(fn)) |
259 |
< |
printf("%s.%s\n", idprefix, stmp); |
259 |
> |
printf("%s.%s\n", idprefix, nam); |
260 |
|
else |
261 |
< |
printf("%s\n", stmp); |
262 |
< |
/* transform arguments */ |
261 |
> |
printf("%s\n", nam); |
262 |
> |
/* transform arguments */ |
263 |
|
if ((*ofun[fn].funp)(fin) < 0) { |
264 |
|
fprintf(stderr, "%s: (%s): bad %s \"%s\"\n", |
265 |
< |
progname, fname, ofun[fn].funame, stmp); |
265 |
> |
progname, fname, ofun[fn].funame, nam); |
266 |
|
exit(1); |
267 |
|
} |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
< |
passargs(fin) /* pass on arguments unchanged */ |
271 |
> |
o_default(fin) /* pass on arguments unchanged */ |
272 |
|
FILE *fin; |
273 |
|
{ |
274 |
|
register int i; |
275 |
< |
register FUNARGS *fa; |
275 |
> |
FUNARGS fa; |
276 |
|
|
277 |
< |
if ((fa = getfargs(fin)) == NULL) |
277 |
> |
if (readfargs(&fa, fin) != 1) |
278 |
|
return(-1); |
279 |
|
/* string arguments */ |
280 |
< |
printf("%d", fa->nsargs); |
281 |
< |
for (i = 0; i < fa->nsargs; i++) |
282 |
< |
printf(" %s", fa->sarg[i]); |
280 |
> |
printf("%d", fa.nsargs); |
281 |
> |
for (i = 0; i < fa.nsargs; i++) |
282 |
> |
printf(" %s", fa.sarg[i]); |
283 |
|
printf("\n"); |
284 |
+ |
#ifdef IARGS |
285 |
|
/* integer arguments */ |
286 |
< |
printf("%d", fa->niargs); |
287 |
< |
for (i = 0; i < fa->niargs; i++) |
288 |
< |
printf(" %d", fa->iarg[i]); |
286 |
> |
printf("%d", fa.niargs); |
287 |
> |
for (i = 0; i < fa.niargs; i++) |
288 |
> |
printf(" %d", fa.iarg[i]); |
289 |
|
printf("\n"); |
290 |
+ |
#else |
291 |
+ |
printf("0\n"); |
292 |
+ |
#endif |
293 |
|
/* float arguments */ |
294 |
< |
printf("%d", fa->nfargs); |
295 |
< |
for (i = 0; i < fa->nfargs; i++) |
296 |
< |
printf(" %18.12g", fa->farg[i]); |
294 |
> |
printf("%d", fa.nfargs); |
295 |
> |
for (i = 0; i < fa.nfargs; i++) |
296 |
> |
printf(" %18.12g", fa.farg[i]); |
297 |
|
printf("\n"); |
298 |
< |
freefargs(fa); |
298 |
> |
freefargs(&fa); |
299 |
|
return(0); |
300 |
|
} |
301 |
|
|
304 |
|
FILE *fin; |
305 |
|
{ |
306 |
|
register int i; |
307 |
< |
register FUNARGS *fa; |
307 |
> |
FUNARGS fa; |
308 |
|
|
309 |
< |
if ((fa = getfargs(fin)) == NULL) |
309 |
> |
if (readfargs(&fa, fin) != 1) |
310 |
|
return(-1); |
311 |
|
/* string arguments */ |
312 |
< |
printf("%d", fa->nsargs + xac-xfa); |
313 |
< |
for (i = 0; i < fa->nsargs; i++) |
314 |
< |
printf(" %s", fa->sarg[i]); |
312 |
> |
printf("%d", fa.nsargs + xac-xfa); |
313 |
> |
for (i = 0; i < fa.nsargs; i++) |
314 |
> |
printf(" %s", fa.sarg[i]); |
315 |
|
for (i = xfa; i < xac; i++) /* add xf arguments */ |
316 |
|
printf(" %s", xav[i]); |
317 |
|
printf("\n"); |
318 |
+ |
#ifdef IARGS |
319 |
|
/* integer arguments */ |
320 |
< |
printf("%d", fa->niargs); |
321 |
< |
for (i = 0; i < fa->niargs; i++) |
322 |
< |
printf(" %d", fa->iarg[i]); |
320 |
> |
printf("%d", fa.niargs); |
321 |
> |
for (i = 0; i < fa.niargs; i++) |
322 |
> |
printf(" %d", fa.iarg[i]); |
323 |
|
printf("\n"); |
324 |
+ |
#else |
325 |
+ |
printf("0\n"); |
326 |
+ |
#endif |
327 |
|
/* float arguments */ |
328 |
< |
printf("%d", fa->nfargs); |
329 |
< |
for (i = 0; i < fa->nfargs; i++) |
330 |
< |
printf(" %18.12g", fa->farg[i]); |
328 |
> |
printf("%d", fa.nfargs); |
329 |
> |
for (i = 0; i < fa.nfargs; i++) |
330 |
> |
printf(" %18.12g", fa.farg[i]); |
331 |
|
printf("\n"); |
332 |
< |
freefargs(fa); |
332 |
> |
freefargs(&fa); |
333 |
|
return(0); |
334 |
|
} |
335 |
|
|
340 |
|
{ |
341 |
|
register int i; |
342 |
|
|
343 |
< |
for (i = 0; ofun[i].funame != NULL; i++) |
343 |
> |
for (i = 0; i < NUMTYPES; i++) |
344 |
|
if (!strcmp(ofun[i].funame, ofname)) |
345 |
|
return(i); |
346 |
|
|
351 |
|
alias(fin) /* transfer alias */ |
352 |
|
FILE *fin; |
353 |
|
{ |
354 |
< |
char alias[MAXSTR]; |
354 |
> |
char aliasnm[MAXSTR]; |
355 |
|
|
356 |
< |
if (fscanf(fin, "%s", alias) != 1) |
356 |
> |
if (fgetword(aliasnm, MAXSTR, fin) == NULL) |
357 |
|
return(-1); |
358 |
< |
printf("\t%s\n", alias); |
358 |
> |
printf("\t%s\n", aliasnm); |
359 |
|
return(0); |
360 |
|
} |
361 |
|
|
363 |
|
m_glow(fin) /* transform arguments for proximity light */ |
364 |
|
FILE *fin; |
365 |
|
{ |
366 |
< |
register FUNARGS *fa; |
366 |
> |
FUNARGS fa; |
367 |
|
|
368 |
< |
if ((fa = getfargs(fin)) == NULL) |
368 |
> |
if (readfargs(&fa, fin) != 1) |
369 |
|
return(-1); |
370 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
370 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
371 |
|
return(-1); |
372 |
|
printf("0\n0\n4"); |
373 |
|
printf(" %18.12g %18.12g %18.12g", |
374 |
< |
fa->farg[0], fa->farg[1], fa->farg[2]); |
375 |
< |
printf(" %18.12g\n", fa->farg[3] * totscale); |
376 |
< |
freefargs(fa); |
374 |
> |
fa.farg[0], fa.farg[1], fa.farg[2]); |
375 |
> |
printf(" %18.12g\n", fa.farg[3] * tot.sca); |
376 |
> |
freefargs(&fa); |
377 |
|
return(0); |
378 |
|
} |
379 |
|
|
382 |
|
FILE *fin; |
383 |
|
{ |
384 |
|
double v[3]; |
385 |
< |
register FUNARGS *fa; |
385 |
> |
FUNARGS fa; |
386 |
|
|
387 |
< |
if ((fa = getfargs(fin)) == NULL) |
387 |
> |
if (readfargs(&fa, fin) != 1) |
388 |
|
return(-1); |
389 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 7) |
389 |
> |
if (fa.nsargs != 0 || fa.nfargs != 7) |
390 |
|
return(-1); |
391 |
|
printf("0\n0\n7"); |
392 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
393 |
< |
fa->farg[0], fa->farg[1], fa->farg[2], fa->farg[3]); |
394 |
< |
multv3(v, fa->farg+4, totxform); |
393 |
> |
fa.farg[0], fa.farg[1], fa.farg[2], fa.farg[3]); |
394 |
> |
multv3(v, fa.farg+4, tot.xfm); |
395 |
|
printf("\t%18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
396 |
< |
freefargs(fa); |
396 |
> |
freefargs(&fa); |
397 |
|
return(0); |
398 |
|
} |
399 |
|
|
402 |
|
FILE *fin; |
403 |
|
{ |
404 |
|
double pow(); |
405 |
< |
register FUNARGS *fa; |
405 |
> |
FUNARGS fa; |
406 |
|
|
407 |
< |
if ((fa = getfargs(fin)) == NULL) |
407 |
> |
if (readfargs(&fa, fin) != 1) |
408 |
|
return(-1); |
409 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 5) |
409 |
> |
if (fa.nsargs != 0 || fa.nfargs != 5) |
410 |
|
return(-1); |
411 |
|
printf("0\n0\n5"); |
412 |
|
printf(" %18.12g %18.12g %18.12g", |
413 |
< |
pow(fa->farg[0], 1.0/totscale), |
414 |
< |
pow(fa->farg[1], 1.0/totscale), |
415 |
< |
pow(fa->farg[2], 1.0/totscale)); |
416 |
< |
printf(" %18.12g %18.12g\n", fa->farg[3], fa->farg[4]); |
417 |
< |
freefargs(fa); |
413 |
> |
pow(fa.farg[0], 1.0/tot.sca), |
414 |
> |
pow(fa.farg[1], 1.0/tot.sca), |
415 |
> |
pow(fa.farg[2], 1.0/tot.sca)); |
416 |
> |
printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]); |
417 |
> |
freefargs(&fa); |
418 |
|
return(0); |
419 |
|
} |
420 |
|
|
423 |
|
FILE *fin; |
424 |
|
{ |
425 |
|
double pow(); |
426 |
< |
register FUNARGS *fa; |
426 |
> |
FUNARGS fa; |
427 |
|
|
428 |
< |
if ((fa = getfargs(fin)) == NULL) |
428 |
> |
if (readfargs(&fa, fin) != 1) |
429 |
|
return(-1); |
430 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
430 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
431 |
|
return(-1); |
432 |
|
printf("0\n0\n8\n"); |
433 |
|
printf("%18.12g %18.12g %18.12g", |
434 |
< |
pow(fa->farg[0], 1.0/totscale), |
435 |
< |
pow(fa->farg[1], 1.0/totscale), |
436 |
< |
pow(fa->farg[2], 1.0/totscale)); |
437 |
< |
printf(" %18.12g\n", fa->farg[3]); |
434 |
> |
pow(fa.farg[0], 1.0/tot.sca), |
435 |
> |
pow(fa.farg[1], 1.0/tot.sca), |
436 |
> |
pow(fa.farg[2], 1.0/tot.sca)); |
437 |
> |
printf(" %18.12g\n", fa.farg[3]); |
438 |
|
printf("%18.12g %18.12g %18.12g", |
439 |
< |
pow(fa->farg[4], 1.0/totscale), |
440 |
< |
pow(fa->farg[5], 1.0/totscale), |
441 |
< |
pow(fa->farg[6], 1.0/totscale)); |
442 |
< |
printf(" %18.12g\n", fa->farg[7]); |
443 |
< |
freefargs(fa); |
439 |
> |
pow(fa.farg[4], 1.0/tot.sca), |
440 |
> |
pow(fa.farg[5], 1.0/tot.sca), |
441 |
> |
pow(fa.farg[6], 1.0/tot.sca)); |
442 |
> |
printf(" %18.12g\n", fa.farg[7]); |
443 |
> |
freefargs(&fa); |
444 |
|
return(0); |
445 |
|
} |
446 |
|
|
450 |
|
{ |
451 |
|
int i; |
452 |
|
double v[3]; |
453 |
< |
register FUNARGS *fa; |
453 |
> |
FUNARGS fa; |
454 |
|
|
455 |
< |
if ((fa = getfargs(fin)) == NULL) |
455 |
> |
if (readfargs(&fa, fin) != 1) |
456 |
|
return(-1); |
457 |
< |
if (fa->niargs != 0 || (fa->nfargs != 9 && |
433 |
< |
fa->nfargs != 11 && fa->nfargs != 15)) |
457 |
> |
if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15) |
458 |
|
return(-1); |
459 |
|
/* string arguments */ |
460 |
< |
printf("%d", fa->nsargs); |
461 |
< |
for (i = 0; i < fa->nsargs; i++) |
462 |
< |
printf(" %s", fa->sarg[i]); |
463 |
< |
printf("\n0\n%d\n", fa->nfargs); |
460 |
> |
printf("%d", fa.nsargs); |
461 |
> |
for (i = 0; i < fa.nsargs; i++) |
462 |
> |
printf(" %s", fa.sarg[i]); |
463 |
> |
printf("\n0\n%d\n", fa.nfargs); |
464 |
|
/* anchor point */ |
465 |
< |
multp3(v, fa->farg, totxform); |
465 |
> |
multp3(v, fa.farg, tot.xfm); |
466 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
467 |
|
/* right vector */ |
468 |
< |
multv3(v, fa->farg+3, totxform); |
468 |
> |
multv3(v, fa.farg+3, tot.xfm); |
469 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
470 |
|
/* down vector */ |
471 |
< |
multv3(v, fa->farg+6, totxform); |
471 |
> |
multv3(v, fa.farg+6, tot.xfm); |
472 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
473 |
|
/* forground and background */ |
474 |
< |
if (fa->nfargs == 11) |
475 |
< |
printf(" %18.12g %18.12g\n", fa->farg[9], fa->farg[10]); |
476 |
< |
else if (fa->nfargs == 15) { |
474 |
> |
if (fa.nfargs == 11) |
475 |
> |
printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]); |
476 |
> |
else if (fa.nfargs == 15) { |
477 |
|
printf(" %18.12g %18.12g %18.12g\n", |
478 |
< |
fa->farg[9], fa->farg[10], fa->farg[11]); |
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]); |
480 |
> |
fa.farg[12], fa.farg[13], fa.farg[14]); |
481 |
|
} |
482 |
< |
freefargs(fa); |
482 |
> |
freefargs(&fa); |
483 |
|
return(0); |
484 |
|
} |
485 |
|
|
488 |
|
FILE *fin; |
489 |
|
{ |
490 |
|
double dv[3]; |
491 |
< |
register FUNARGS *fa; |
491 |
> |
FUNARGS fa; |
492 |
|
|
493 |
< |
if ((fa = getfargs(fin)) == NULL) |
493 |
> |
if (readfargs(&fa, fin) != 1) |
494 |
|
return(-1); |
495 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
495 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
496 |
|
return(-1); |
497 |
|
/* transform direction vector */ |
498 |
< |
multv3(dv, fa->farg, totxform); |
498 |
> |
multv3(dv, fa.farg, tot.xfm); |
499 |
|
/* output */ |
500 |
|
printf("0\n0\n4"); |
501 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
502 |
< |
dv[0], dv[1], dv[2], fa->farg[3]); |
503 |
< |
freefargs(fa); |
502 |
> |
dv[0], dv[1], dv[2], fa.farg[3]); |
503 |
> |
freefargs(&fa); |
504 |
|
return(0); |
505 |
|
} |
506 |
|
|
509 |
|
FILE *fin; |
510 |
|
{ |
511 |
|
double cent[3], rad; |
512 |
< |
register FUNARGS *fa; |
512 |
> |
FUNARGS fa; |
513 |
|
|
514 |
< |
if ((fa = getfargs(fin)) == NULL) |
514 |
> |
if (readfargs(&fa, fin) != 1) |
515 |
|
return(-1); |
516 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
516 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
517 |
|
return(-1); |
518 |
|
|
519 |
< |
multp3(cent, fa->farg, totxform); /* transform center */ |
519 |
> |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
520 |
|
|
521 |
< |
rad = fa->farg[3] * totscale; /* scale radius */ |
521 |
> |
rad = fa.farg[3] * tot.sca; /* scale radius */ |
522 |
|
|
523 |
|
printf("0\n0\n4"); |
524 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
525 |
|
cent[0], cent[1], cent[2], rad); |
526 |
< |
freefargs(fa); |
526 |
> |
freefargs(&fa); |
527 |
|
return(0); |
528 |
|
} |
529 |
|
|
533 |
|
{ |
534 |
|
double p[3]; |
535 |
|
register int i; |
536 |
< |
register FUNARGS *fa; |
536 |
> |
FUNARGS fa; |
537 |
|
|
538 |
< |
if ((fa = getfargs(fin)) == NULL) |
538 |
> |
if (readfargs(&fa, fin) != 1) |
539 |
|
return(-1); |
540 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs % 3) |
540 |
> |
if (fa.nsargs != 0 || fa.nfargs % 3) |
541 |
|
return(-1); |
542 |
|
|
543 |
< |
printf("0\n0\n%d\n", fa->nfargs); |
543 |
> |
printf("0\n0\n%d\n", fa.nfargs); |
544 |
|
|
545 |
< |
for (i = 0; i < fa->nfargs; i += 3) { |
545 |
> |
for (i = 0; i < fa.nfargs; i += 3) { |
546 |
|
if (reverse) |
547 |
< |
multp3(p, fa->farg+(fa->nfargs-i-3), totxform); |
547 |
> |
multp3(p, fa.farg+(fa.nfargs-i-3), tot.xfm); |
548 |
|
else |
549 |
< |
multp3(p, fa->farg+i, totxform); |
549 |
> |
multp3(p, fa.farg+i, tot.xfm); |
550 |
|
printf(" %18.12g %18.12g %18.12g\n", p[0], p[1], p[2]); |
551 |
|
} |
552 |
< |
freefargs(fa); |
552 |
> |
freefargs(&fa); |
553 |
|
return(0); |
554 |
|
} |
555 |
|
|
558 |
|
FILE *fin; |
559 |
|
{ |
560 |
|
double p0[3], p1[3], r0, r1; |
561 |
< |
register FUNARGS *fa; |
561 |
> |
FUNARGS fa; |
562 |
|
|
563 |
< |
if ((fa = getfargs(fin)) == NULL) |
563 |
> |
if (readfargs(&fa, fin) != 1) |
564 |
|
return(-1); |
565 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
565 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
566 |
|
return(-1); |
567 |
|
|
568 |
|
printf("0\n0\n8\n"); |
569 |
|
|
570 |
< |
multp3(p0, fa->farg, totxform); |
571 |
< |
multp3(p1, fa->farg+3, totxform); |
572 |
< |
r0 = fa->farg[6] * totscale; |
573 |
< |
r1 = fa->farg[7] * totscale; |
570 |
> |
multp3(p0, fa.farg, tot.xfm); |
571 |
> |
multp3(p1, fa.farg+3, tot.xfm); |
572 |
> |
r0 = fa.farg[6] * tot.sca; |
573 |
> |
r1 = fa.farg[7] * tot.sca; |
574 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
575 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
576 |
|
printf(" %18.12g %18.12g\n", r0, r1); |
577 |
|
|
578 |
< |
freefargs(fa); |
578 |
> |
freefargs(&fa); |
579 |
|
return(0); |
580 |
|
} |
581 |
|
|
584 |
|
FILE *fin; |
585 |
|
{ |
586 |
|
double p0[3], p1[3], rad; |
587 |
< |
register FUNARGS *fa; |
587 |
> |
FUNARGS fa; |
588 |
|
|
589 |
< |
if ((fa = getfargs(fin)) == NULL) |
589 |
> |
if (readfargs(&fa, fin) != 1) |
590 |
|
return(-1); |
591 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 7) |
591 |
> |
if (fa.nsargs != 0 || fa.nfargs != 7) |
592 |
|
return(-1); |
593 |
|
|
594 |
|
printf("0\n0\n7\n"); |
595 |
|
|
596 |
< |
multp3(p0, fa->farg, totxform); |
597 |
< |
multp3(p1, fa->farg+3, totxform); |
598 |
< |
rad = fa->farg[6] * totscale; |
596 |
> |
multp3(p0, fa.farg, tot.xfm); |
597 |
> |
multp3(p1, fa.farg+3, tot.xfm); |
598 |
> |
rad = fa.farg[6] * tot.sca; |
599 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
600 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
601 |
|
printf(" %18.12g\n", rad); |
602 |
< |
freefargs(fa); |
602 |
> |
freefargs(&fa); |
603 |
|
return(0); |
604 |
|
} |
605 |
|
|
608 |
|
FILE *fin; |
609 |
|
{ |
610 |
|
double p0[3], pd[3], r0, r1; |
611 |
< |
register FUNARGS *fa; |
611 |
> |
FUNARGS fa; |
612 |
|
|
613 |
< |
if ((fa = getfargs(fin)) == NULL) |
613 |
> |
if (readfargs(&fa, fin) != 1) |
614 |
|
return(-1); |
615 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
615 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
616 |
|
return(-1); |
617 |
|
|
618 |
|
printf("0\n0\n8\n"); |
619 |
|
|
620 |
< |
multp3(p0, fa->farg, totxform); |
621 |
< |
multv3(pd, fa->farg+3, totxform); |
622 |
< |
r0 = fa->farg[6] * totscale; |
623 |
< |
r1 = fa->farg[7] * totscale; |
620 |
> |
multp3(p0, fa.farg, tot.xfm); |
621 |
> |
multv3(pd, fa.farg+3, tot.xfm); |
622 |
> |
if (invert) { |
623 |
> |
pd[0] = -pd[0]; |
624 |
> |
pd[1] = -pd[1]; |
625 |
> |
pd[2] = -pd[2]; |
626 |
> |
} |
627 |
> |
r0 = fa.farg[6] * tot.sca; |
628 |
> |
r1 = fa.farg[7] * tot.sca; |
629 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
630 |
|
printf(" %18.12g %18.12g %18.12g\n", pd[0], pd[1], pd[2]); |
631 |
|
printf(" %18.12g %18.12g\n", r0, r1); |
632 |
< |
freefargs(fa); |
632 |
> |
freefargs(&fa); |
633 |
|
return(0); |
634 |
|
} |
635 |
|
|
636 |
|
|
637 |
< |
FUNARGS * |
609 |
< |
getfargs(fp) /* get function arguments from stream */ |
610 |
< |
FILE *fp; |
637 |
> |
initotypes() /* initialize ofun[] array */ |
638 |
|
{ |
639 |
< |
char *strcpy(); |
640 |
< |
char sbuf[MAXSTR]; |
641 |
< |
int n; |
642 |
< |
register FUNARGS *fa; |
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(); |
653 |
|
register int i; |
654 |
|
|
655 |
< |
if ((fa = (FUNARGS *)malloc((unsigned)sizeof(FUNARGS))) == NULL) |
656 |
< |
goto memerr; |
657 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
658 |
< |
return(NULL); |
659 |
< |
if (fa->nsargs = n) { |
660 |
< |
fa->sarg = (char **)malloc((unsigned)fa->nsargs*sizeof(char *)); |
661 |
< |
if (fa->sarg == NULL) |
662 |
< |
goto memerr; |
663 |
< |
for (i = 0; i < fa->nsargs; i++) { |
664 |
< |
if (fscanf(fp, "%s", sbuf) != 1) |
665 |
< |
return(NULL); |
666 |
< |
if ((fa->sarg[i] = malloc((unsigned)strlen(sbuf)+1)) == NULL) |
667 |
< |
goto memerr; |
668 |
< |
strcpy(fa->sarg[i], sbuf); |
669 |
< |
} |
670 |
< |
} else |
671 |
< |
fa->sarg = NULL; |
672 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
673 |
< |
return(NULL); |
674 |
< |
if (fa->niargs = n) { |
675 |
< |
fa->iarg = (int *)malloc((unsigned)fa->niargs*sizeof(int)); |
676 |
< |
if (fa->iarg == NULL) |
677 |
< |
goto memerr; |
678 |
< |
for (i = 0; i < fa->niargs; i++) |
679 |
< |
if (fscanf(fp, "%d", &fa->iarg[i]) != 1) |
680 |
< |
return(NULL); |
681 |
< |
} else |
682 |
< |
fa->iarg = NULL; |
683 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
684 |
< |
return(NULL); |
685 |
< |
if (fa->nfargs = n) { |
686 |
< |
fa->farg = (double *)malloc((unsigned)fa->nfargs*sizeof(double)); |
687 |
< |
if (fa->farg == NULL) |
688 |
< |
goto memerr; |
689 |
< |
for (i = 0; i < fa->nfargs; i++) |
690 |
< |
if (fscanf(fp, "%lf", &fa->farg[i]) != 1) |
691 |
< |
return(NULL); |
692 |
< |
} else |
656 |
< |
fa->farg = NULL; |
657 |
< |
return(fa); |
658 |
< |
memerr: |
659 |
< |
fprintf(stderr, "%s: out of memory in getfargs\n", progname); |
660 |
< |
exit(1); |
661 |
< |
} |
662 |
< |
|
663 |
< |
|
664 |
< |
freefargs(fa) /* free memory associated with fa */ |
665 |
< |
register FUNARGS *fa; |
666 |
< |
{ |
667 |
< |
register int i; |
668 |
< |
|
669 |
< |
for (i = 0; i < fa->nsargs; i++) |
670 |
< |
free(fa->sarg[i]); |
671 |
< |
if (fa->nsargs) |
672 |
< |
free(fa->sarg); |
673 |
< |
if (fa->niargs) |
674 |
< |
free(fa->iarg); |
675 |
< |
if (fa->nfargs) |
676 |
< |
free(fa->farg); |
677 |
< |
free(fa); |
655 |
> |
if (ofun[OBJ_SOURCE].funp == o_source) |
656 |
> |
return; /* done already */ |
657 |
> |
/* alias is additional */ |
658 |
> |
ofun[ALIAS].funame = ALIASID; |
659 |
> |
ofun[ALIAS].flags = 0; |
660 |
> |
/* functions get new transform */ |
661 |
> |
for (i = 0; i < NUMTYPES; i++) |
662 |
> |
if (hasfunc(i)) |
663 |
> |
ofun[i].funp = addxform; |
664 |
> |
/* special cases */ |
665 |
> |
ofun[OBJ_SOURCE].funp = o_source; |
666 |
> |
ofun[OBJ_SPHERE].funp = |
667 |
> |
ofun[OBJ_BUBBLE].funp = o_sphere; |
668 |
> |
ofun[OBJ_FACE].funp = o_face; |
669 |
> |
ofun[OBJ_CONE].funp = |
670 |
> |
ofun[OBJ_CUP].funp = o_cone; |
671 |
> |
ofun[OBJ_CYLINDER].funp = |
672 |
> |
ofun[OBJ_TUBE].funp = o_cylinder; |
673 |
> |
ofun[OBJ_RING].funp = o_ring; |
674 |
> |
ofun[OBJ_INSTANCE].funp = addxform; |
675 |
> |
ofun[MAT_GLOW].funp = m_glow; |
676 |
> |
ofun[MAT_SPOT].funp = m_spot; |
677 |
> |
ofun[MAT_DIELECTRIC].funp = m_dielectric; |
678 |
> |
ofun[MAT_INTERFACE].funp = m_interface; |
679 |
> |
ofun[PAT_CTEXT].funp = |
680 |
> |
ofun[PAT_BTEXT].funp = |
681 |
> |
ofun[MIX_TEXT].funp = text; |
682 |
> |
ofun[ALIAS].funp = alias; |
683 |
> |
/* surface inverses */ |
684 |
> |
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
685 |
> |
tinvers[OBJ_CONE] = OBJ_CUP; |
686 |
> |
tinvers[OBJ_CUP] = OBJ_CONE; |
687 |
> |
tinvers[OBJ_SPHERE] = OBJ_BUBBLE; |
688 |
> |
tinvers[OBJ_BUBBLE] = OBJ_SPHERE; |
689 |
> |
tinvers[OBJ_RING] = OBJ_RING; |
690 |
> |
tinvers[OBJ_CYLINDER] = OBJ_TUBE; |
691 |
> |
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
692 |
> |
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
693 |
|
} |