1 |
< |
/* Copyright (c) 1986 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"; |
12 |
|
* 11/6/86 Finally added error checking! |
13 |
|
*/ |
14 |
|
|
15 |
< |
#include <stdio.h> |
15 |
> |
#include "standard.h" |
16 |
|
|
17 |
+ |
#include "paths.h" |
18 |
+ |
|
19 |
|
#include <ctype.h> |
20 |
|
|
21 |
+ |
#include "object.h" |
22 |
|
|
23 |
< |
typedef struct { |
21 |
< |
char *funame; /* function name */ |
22 |
< |
int (*funp)(); /* pointer to function */ |
23 |
< |
} FUN; |
23 |
> |
#include "otypes.h" |
24 |
|
|
25 |
|
int xac; /* global xform argument count */ |
26 |
|
char **xav; /* global xform argument pointer */ |
27 |
|
int xfa; /* start of xf arguments */ |
28 |
|
|
29 |
< |
double totxform[4][4]; /* total transformation matrix */ |
30 |
< |
double totscale; /* total scale factor */ |
31 |
< |
int reverse; /* boolean true if scene inverted */ |
29 |
> |
XF tot; /* total transformation */ |
30 |
> |
int reverse; /* boolean true if scene mirrored */ |
31 |
|
|
32 |
< |
int expand = 0; /* boolean true to expand commands */ |
32 |
> |
int invert = 0; /* boolean true to invert surfaces */ |
33 |
|
|
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 |
< |
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_dielectric(); |
44 |
< |
extern int m_interface(); |
45 |
< |
extern int text(); |
46 |
< |
extern int alias(); |
47 |
< |
extern int passargs(); |
48 |
< |
extern int addxform(); |
40 |
> |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
41 |
|
|
42 |
< |
FUN ofun[] = { |
51 |
< |
{ "source", o_source }, |
52 |
< |
{ "sphere", o_sphere }, |
53 |
< |
{ "bubble", o_sphere }, |
54 |
< |
{ "polygon", o_face }, |
55 |
< |
{ "cone", o_cone }, |
56 |
< |
{ "cup", o_cone }, |
57 |
< |
{ "cylinder", o_cylinder }, |
58 |
< |
{ "tube", o_cylinder }, |
59 |
< |
{ "ring", o_ring }, |
60 |
< |
{ "instance", addxform }, |
61 |
< |
{ "alias", alias }, |
62 |
< |
{ "antimatter", passargs }, |
63 |
< |
{ "dielectric", m_dielectric }, |
64 |
< |
{ "interface", m_interface }, |
65 |
< |
{ "colortext", text }, |
66 |
< |
{ "brighttext", text }, |
67 |
< |
{ "texfunc", addxform }, |
68 |
< |
{ "texdata", addxform }, |
69 |
< |
{ "colorfunc", addxform }, |
70 |
< |
{ "brightfunc", addxform }, |
71 |
< |
{ "colorpict", addxform }, |
72 |
< |
{ "colordata", addxform }, |
73 |
< |
{ "brightdata", addxform }, |
74 |
< |
{ "mixfunc", addxform }, |
75 |
< |
{ "mixdata", addxform }, |
76 |
< |
{ "mixtext", text }, |
77 |
< |
{ "light", passargs }, |
78 |
< |
{ "illum", passargs }, |
79 |
< |
{ "glow", passargs }, |
80 |
< |
{ "plastic", passargs }, |
81 |
< |
{ "metal", passargs }, |
82 |
< |
{ "trans", passargs }, |
83 |
< |
{ "glass", passargs }, |
84 |
< |
{ 0 } /* terminator */ |
85 |
< |
}; |
42 |
> |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
43 |
|
|
44 |
< |
#define issurface(t) ((t)<=9) |
44 |
> |
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
45 |
|
|
46 |
< |
typedef struct { |
90 |
< |
short nsargs; /* # of string arguments */ |
91 |
< |
char **sarg; /* string arguments */ |
92 |
< |
short niargs; /* # of integer arguments */ |
93 |
< |
int *iarg; /* integer arguments */ |
94 |
< |
short nfargs; /* # of float arguments */ |
95 |
< |
double *farg; /* float arguments */ |
96 |
< |
} FUNARGS; |
46 |
> |
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
47 |
|
|
48 |
< |
#define MAXSTR 512 /* maximum string length */ |
48 |
> |
int nrept = 1; /* number of array repetitions */ |
49 |
|
|
50 |
< |
FUNARGS *getfargs(); |
101 |
< |
char *malloc(); |
50 |
> |
int stdinused = 0; /* stdin has been used by -f option? */ |
51 |
|
|
52 |
< |
#define progname (xav[0]) |
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(); |
111 |
< |
FILE *fp; |
64 |
> |
char *fname; |
65 |
|
int a; |
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 |
|
|
75 |
< |
xav = argv; |
75 |
> |
initotypes(); |
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) |
82 |
+ |
break; |
83 |
+ |
newmod = argv[++a]; |
84 |
+ |
continue; |
85 |
|
case 'n': |
86 |
+ |
if (argv[a][2] || a+1 >= argc) |
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; |
98 |
|
expand = 1; |
99 |
|
continue; |
100 |
+ |
case 'I': |
101 |
+ |
if (argv[a][2]) |
102 |
+ |
break; |
103 |
+ |
invert = 1; |
104 |
+ |
continue; |
105 |
|
} |
106 |
|
break; |
107 |
|
} |
108 |
|
|
109 |
+ |
xav = argv; |
110 |
|
xfa = a; |
111 |
|
|
112 |
< |
totscale = 1.0; |
132 |
< |
setident4(totxform); |
112 |
> |
a += xf(&tot, argc-a, argv+a); |
113 |
|
|
114 |
< |
a += xf(totxform, &totscale, argc-a, argv+a); |
114 |
> |
if (reverse = tot.sca < 0.0) |
115 |
> |
tot.sca = -tot.sca; |
116 |
> |
if (invert) |
117 |
> |
reverse = !reverse; |
118 |
|
|
119 |
< |
if (reverse = totscale < 0.0) |
120 |
< |
totscale = -totscale; |
119 |
> |
if (a < argc && argv[a][0] == '-') { |
120 |
> |
fprintf(stderr, "%s: command line error at '%s'\n", |
121 |
> |
argv[0], argv[a]); |
122 |
> |
exit(1); |
123 |
> |
} |
124 |
|
|
125 |
|
xac = a; |
126 |
< |
|
127 |
< |
putchar('#'); /* simple header */ |
126 |
> |
/* simple header */ |
127 |
> |
putchar('#'); |
128 |
|
for (a = 0; a < xac; a++) |
129 |
|
printf(" %s", xav[a]); |
130 |
|
putchar('\n'); |
131 |
+ |
/* transform input */ |
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 |
+ |
openmain(argv[a]); |
143 |
+ |
xform(mainfn, mainfp); |
144 |
+ |
} |
145 |
|
|
146 |
< |
if (a == argc) |
147 |
< |
xform("standard input", stdin); |
148 |
< |
else |
149 |
< |
for ( ; a < argc; a++) { |
150 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
151 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
152 |
< |
progname, argv[a]); |
153 |
< |
exit(1); |
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[2048]; |
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 |
< |
xform(argv[a], fp); |
223 |
< |
fclose(fp); |
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 |
< |
exit(0); |
240 |
> |
|
241 |
> |
doarray(ac, av, ai) /* make array */ |
242 |
> |
char **av; |
243 |
> |
int ac, ai; |
244 |
> |
{ |
245 |
> |
char *newav[256], **avp; |
246 |
> |
char newid[128], repts[32]; |
247 |
> |
char *oldid = NULL; |
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++) |
258 |
> |
if (!strcmp(av[i-1], "-n")) { |
259 |
> |
oldid = av[i]; |
260 |
> |
avp[i] = newid; |
261 |
> |
} else |
262 |
> |
avp[i] = av[i]; |
263 |
> |
avp[ai] = "-i"; |
264 |
> |
avp[ai+1] = repts; |
265 |
> |
avp[i] = NULL; |
266 |
> |
if (oldid == NULL) { |
267 |
> |
newav[0] = av[0]; |
268 |
> |
newav[1] = "-n"; |
269 |
> |
newav[2] = newid; |
270 |
> |
avp = newav; |
271 |
> |
ac += 2; |
272 |
> |
} |
273 |
> |
err = 0; |
274 |
> |
for (i = 0; i < n; i++) { |
275 |
> |
if (oldid == NULL) |
276 |
> |
sprintf(newid, "a%d", i); |
277 |
> |
else |
278 |
> |
sprintf(newid, "%s.%d", oldid, i); |
279 |
> |
sprintf(repts, "%d", i); |
280 |
> |
err |= main(ac, avp); |
281 |
> |
} |
282 |
> |
return(err); |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
< |
xform(name, fin) /* transform stream by totxform */ |
286 |
> |
xform(name, fin) /* transform stream by tot.xfm */ |
287 |
|
char *name; |
288 |
|
register FILE *fin; |
289 |
|
{ |
290 |
+ |
int nobjs = 0; |
291 |
|
register int c; |
292 |
|
|
293 |
|
while ((c = getc(fin)) != EOF) { |
302 |
|
} while (c != '\n'); |
303 |
|
} else if (c == '!') { /* command */ |
304 |
|
ungetc(c, fin); |
305 |
< |
if (expand) |
306 |
< |
xfcomm(name, fin); |
183 |
< |
else { |
184 |
< |
putchar('\n'); |
185 |
< |
while ((c = getc(fin)) != EOF && c != '\n') |
186 |
< |
putchar(c); |
187 |
< |
printf(" |"); |
188 |
< |
for (c = 0; c < xac; c++) |
189 |
< |
printf(" %s", xav[c]); |
190 |
< |
putchar('\n'); |
191 |
< |
} |
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) /* expand a command */ |
319 |
> |
xfcomm(fname, fin) /* transform a command */ |
320 |
> |
char *fname; |
321 |
|
FILE *fin; |
322 |
|
{ |
323 |
< |
FILE *popen(); |
324 |
< |
char *fgets(); |
323 |
> |
extern FILE *popen(); |
324 |
> |
extern char *fgetline(); |
325 |
|
FILE *pin; |
326 |
|
char buf[512]; |
327 |
+ |
int i; |
328 |
|
|
329 |
< |
fgets(buf, sizeof(buf), fin); |
330 |
< |
if (buf[strlen(buf)-1] == '\n') |
331 |
< |
buf[strlen(buf)-1] = '\0'; |
332 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
333 |
< |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
334 |
< |
progname, fname, buf); |
335 |
< |
exit(1); |
329 |
> |
fgetline(buf, sizeof(buf), fin); |
330 |
> |
if (expand) { |
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", xav[0]); |
342 |
> |
for (i = 1; i < xac; i++) |
343 |
> |
printf(" %s", xav[i]); |
344 |
> |
} |
345 |
> |
putchar('\n'); |
346 |
|
} |
216 |
– |
xform(buf, pin); |
217 |
– |
pclose(pin); |
347 |
|
} |
348 |
|
|
349 |
|
|
351 |
|
char *fname; |
352 |
|
FILE *fin; |
353 |
|
{ |
354 |
< |
char stmp[MAXSTR]; |
354 |
> |
extern char *strcpy(); |
355 |
> |
char typ[16], nam[MAXSTR]; |
356 |
|
int fn; |
357 |
< |
|
358 |
< |
fscanf(fin, "%s", stmp); /* modifier */ |
359 |
< |
printf("\n%s ", stmp); |
360 |
< |
fscanf(fin, "%s", stmp); /* object type */ |
361 |
< |
if ((fn = otype(stmp)) < 0) { |
357 |
> |
/* modifier and type */ |
358 |
> |
strcpy(typ, "EOF"); |
359 |
> |
fgetword(nam, sizeof(nam), fin); |
360 |
> |
fgetword(typ, sizeof(typ), fin); |
361 |
> |
if ((fn = otype(typ)) < 0) { |
362 |
|
fprintf(stderr, "%s: (%s): unknown object type \"%s\"\n", |
363 |
< |
progname, fname, stmp); |
363 |
> |
progname, fname, typ); |
364 |
|
exit(1); |
365 |
|
} |
366 |
< |
printf("%s ", stmp); |
367 |
< |
fscanf(fin, "%s", stmp); /* object name */ |
238 |
< |
if (idprefix != NULL && issurface(fn)) |
239 |
< |
printf("%s.%s\n", idprefix, stmp); |
366 |
> |
if (ismodifier(fn)) |
367 |
> |
printf("\n%s %s ", nam, typ); |
368 |
|
else |
369 |
< |
printf("%s\n", stmp); |
370 |
< |
/* transform arguments */ |
369 |
> |
printf("\n%s %s ", newmod != NULL ? newmod : nam, |
370 |
> |
invert ? ofun[tinvers[fn]].funame : typ); |
371 |
> |
/* object name */ |
372 |
> |
fgetword(nam, sizeof(nam), fin); |
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", |
380 |
< |
progname, fname, ofun[fn].funame, stmp); |
380 |
> |
progname, fname, ofun[fn].funame, nam); |
381 |
|
exit(1); |
382 |
|
} |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
< |
passargs(fin) /* pass on arguments unchanged */ |
386 |
> |
o_default(fin) /* pass on arguments unchanged */ |
387 |
|
FILE *fin; |
388 |
|
{ |
389 |
|
register int i; |
390 |
< |
register FUNARGS *fa; |
390 |
> |
FUNARGS fa; |
391 |
|
|
392 |
< |
if ((fa = getfargs(fin)) == NULL) |
392 |
> |
if (readfargs(&fa, fin) != 1) |
393 |
|
return(-1); |
394 |
|
/* string arguments */ |
395 |
< |
printf("%d", fa->nsargs); |
396 |
< |
for (i = 0; i < fa->nsargs; i++) |
397 |
< |
printf(" %s", fa->sarg[i]); |
395 |
> |
printf("%d", fa.nsargs); |
396 |
> |
for (i = 0; i < fa.nsargs; i++) |
397 |
> |
printf(" %s", fa.sarg[i]); |
398 |
|
printf("\n"); |
399 |
+ |
#ifdef IARGS |
400 |
|
/* integer arguments */ |
401 |
< |
printf("%d", fa->niargs); |
402 |
< |
for (i = 0; i < fa->niargs; i++) |
403 |
< |
printf(" %d", fa->iarg[i]); |
401 |
> |
printf("%d", fa.niargs); |
402 |
> |
for (i = 0; i < fa.niargs; i++) |
403 |
> |
printf(" %d", fa.iarg[i]); |
404 |
|
printf("\n"); |
405 |
+ |
#else |
406 |
+ |
printf("0\n"); |
407 |
+ |
#endif |
408 |
|
/* float arguments */ |
409 |
< |
printf("%d", fa->nfargs); |
410 |
< |
for (i = 0; i < fa->nfargs; i++) |
411 |
< |
printf(" %18.12g", fa->farg[i]); |
409 |
> |
printf("%d", fa.nfargs); |
410 |
> |
for (i = 0; i < fa.nfargs; i++) |
411 |
> |
printf(" %18.12g", fa.farg[i]); |
412 |
|
printf("\n"); |
413 |
< |
freefargs(fa); |
413 |
> |
freefargs(&fa); |
414 |
|
return(0); |
415 |
|
} |
416 |
|
|
419 |
|
FILE *fin; |
420 |
|
{ |
421 |
|
register int i; |
422 |
< |
register FUNARGS *fa; |
422 |
> |
int resetarr = 0; |
423 |
> |
FUNARGS fa; |
424 |
|
|
425 |
< |
if ((fa = getfargs(fin)) == NULL) |
425 |
> |
if (readfargs(&fa, fin) != 1) |
426 |
|
return(-1); |
427 |
|
/* string arguments */ |
428 |
< |
printf("%d", fa->nsargs + xac-xfa); |
429 |
< |
for (i = 0; i < fa->nsargs; i++) |
430 |
< |
printf(" %s", fa->sarg[i]); |
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 |
439 |
|
/* integer arguments */ |
440 |
< |
printf("%d", fa->niargs); |
441 |
< |
for (i = 0; i < fa->niargs; i++) |
442 |
< |
printf(" %d", fa->iarg[i]); |
440 |
> |
printf("%d", fa.niargs); |
441 |
> |
for (i = 0; i < fa.niargs; i++) |
442 |
> |
printf(" %d", fa.iarg[i]); |
443 |
|
printf("\n"); |
444 |
+ |
#else |
445 |
+ |
printf("0\n"); |
446 |
+ |
#endif |
447 |
|
/* float arguments */ |
448 |
< |
printf("%d", fa->nfargs); |
449 |
< |
for (i = 0; i < fa->nfargs; i++) |
450 |
< |
printf(" %18.12g", fa->farg[i]); |
448 |
> |
printf("%d", fa.nfargs); |
449 |
> |
for (i = 0; i < fa.nfargs; i++) |
450 |
> |
printf(" %18.12g", fa.farg[i]); |
451 |
|
printf("\n"); |
452 |
< |
freefargs(fa); |
452 |
> |
freefargs(&fa); |
453 |
|
return(0); |
454 |
|
} |
455 |
|
|
460 |
|
{ |
461 |
|
register int i; |
462 |
|
|
463 |
< |
for (i = 0; ofun[i].funame != NULL; i++) |
463 |
> |
for (i = 0; i < NUMTYPES; i++) |
464 |
|
if (!strcmp(ofun[i].funame, ofname)) |
465 |
|
return(i); |
466 |
|
|
471 |
|
alias(fin) /* transfer alias */ |
472 |
|
FILE *fin; |
473 |
|
{ |
474 |
< |
char alias[MAXSTR]; |
474 |
> |
char aliasnm[MAXSTR]; |
475 |
|
|
476 |
< |
if (fscanf(fin, "%s", alias) != 1) |
476 |
> |
if (fgetword(aliasnm, MAXSTR, fin) == NULL) |
477 |
|
return(-1); |
478 |
< |
printf("\t%s\n", alias); |
478 |
> |
printf("\t%s\n", aliasnm); |
479 |
|
return(0); |
480 |
|
} |
481 |
|
|
482 |
|
|
483 |
+ |
m_glow(fin) /* transform arguments for proximity light */ |
484 |
+ |
FILE *fin; |
485 |
+ |
{ |
486 |
+ |
FUNARGS fa; |
487 |
+ |
|
488 |
+ |
if (readfargs(&fa, fin) != 1) |
489 |
+ |
return(-1); |
490 |
+ |
if (fa.nsargs != 0 || fa.nfargs != 4) |
491 |
+ |
return(-1); |
492 |
+ |
printf("0\n0\n4"); |
493 |
+ |
printf(" %18.12g %18.12g %18.12g", |
494 |
+ |
fa.farg[0], fa.farg[1], fa.farg[2]); |
495 |
+ |
printf(" %18.12g\n", fa.farg[3] * tot.sca); |
496 |
+ |
freefargs(&fa); |
497 |
+ |
return(0); |
498 |
+ |
} |
499 |
+ |
|
500 |
+ |
|
501 |
+ |
m_spot(fin) /* transform arguments for spotlight */ |
502 |
+ |
FILE *fin; |
503 |
+ |
{ |
504 |
+ |
FVECT v; |
505 |
+ |
FUNARGS fa; |
506 |
+ |
|
507 |
+ |
if (readfargs(&fa, fin) != 1) |
508 |
+ |
return(-1); |
509 |
+ |
if (fa.nsargs != 0 || fa.nfargs != 7) |
510 |
+ |
return(-1); |
511 |
+ |
printf("0\n0\n7"); |
512 |
+ |
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
513 |
+ |
fa.farg[0], fa.farg[1], fa.farg[2], fa.farg[3]); |
514 |
+ |
multv3(v, fa.farg+4, tot.xfm); |
515 |
+ |
printf("\t%18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
516 |
+ |
freefargs(&fa); |
517 |
+ |
return(0); |
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(); |
339 |
< |
register FUNARGS *fa; |
566 |
> |
FUNARGS fa; |
567 |
|
|
568 |
< |
if ((fa = getfargs(fin)) == NULL) |
568 |
> |
if (readfargs(&fa, fin) != 1) |
569 |
|
return(-1); |
570 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 5) |
570 |
> |
if (fa.nsargs != 0 || fa.nfargs != 5) |
571 |
|
return(-1); |
572 |
|
printf("0\n0\n5"); |
573 |
< |
printf(" %18.12g %18.12g %18.12g", |
574 |
< |
pow(fa->farg[0], 1.0/totscale), |
575 |
< |
pow(fa->farg[1], 1.0/totscale), |
576 |
< |
pow(fa->farg[2], 1.0/totscale)); |
577 |
< |
printf(" %18.12g %18.12g\n", fa->farg[3], fa->farg[4]); |
578 |
< |
freefargs(fa); |
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(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]); |
578 |
> |
freefargs(&fa); |
579 |
|
return(0); |
580 |
|
} |
581 |
|
|
583 |
|
m_interface(fin) /* transform arguments for interface */ |
584 |
|
FILE *fin; |
585 |
|
{ |
586 |
< |
double pow(); |
360 |
< |
register FUNARGS *fa; |
586 |
> |
FUNARGS fa; |
587 |
|
|
588 |
< |
if ((fa = getfargs(fin)) == NULL) |
588 |
> |
if (readfargs(&fa, fin) != 1) |
589 |
|
return(-1); |
590 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
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", |
594 |
< |
pow(fa->farg[0], 1.0/totscale), |
595 |
< |
pow(fa->farg[1], 1.0/totscale), |
596 |
< |
pow(fa->farg[2], 1.0/totscale)); |
597 |
< |
printf(" %18.12g\n", fa->farg[3]); |
598 |
< |
printf("%18.12g %18.12g %18.12g", |
599 |
< |
pow(fa->farg[4], 1.0/totscale), |
600 |
< |
pow(fa->farg[5], 1.0/totscale), |
601 |
< |
pow(fa->farg[6], 1.0/totscale)); |
602 |
< |
printf(" %18.12g\n", fa->farg[7]); |
603 |
< |
freefargs(fa); |
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(" %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(" %12.6g\n", fa.farg[7]); |
603 |
> |
freefargs(&fa); |
604 |
|
return(0); |
605 |
|
} |
606 |
|
|
609 |
|
FILE *fin; |
610 |
|
{ |
611 |
|
int i; |
612 |
< |
double v[3]; |
613 |
< |
register FUNARGS *fa; |
612 |
> |
FVECT v; |
613 |
> |
FUNARGS fa; |
614 |
|
|
615 |
< |
if ((fa = getfargs(fin)) == NULL) |
615 |
> |
if (readfargs(&fa, fin) != 1) |
616 |
|
return(-1); |
617 |
< |
if (fa->niargs != 0 || (fa->nfargs != 9 && |
392 |
< |
fa->nfargs != 11 && fa->nfargs != 15)) |
617 |
> |
if (fa.nfargs < 9) |
618 |
|
return(-1); |
619 |
|
/* string arguments */ |
620 |
< |
printf("%d", fa->nsargs); |
621 |
< |
for (i = 0; i < fa->nsargs; i++) |
622 |
< |
printf(" %s", fa->sarg[i]); |
623 |
< |
printf("\n0\n%d\n", fa->nfargs); |
620 |
> |
printf("%d", fa.nsargs); |
621 |
> |
for (i = 0; i < fa.nsargs; i++) |
622 |
> |
printf(" %s", fa.sarg[i]); |
623 |
> |
printf("\n0\n%d\n", fa.nfargs); |
624 |
|
/* anchor point */ |
625 |
< |
multp3(v, fa->farg, totxform); |
625 |
> |
multp3(v, fa.farg, tot.xfm); |
626 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
627 |
|
/* right vector */ |
628 |
< |
multv3(v, fa->farg+3, totxform); |
628 |
> |
multv3(v, fa.farg+3, tot.xfm); |
629 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
630 |
|
/* down vector */ |
631 |
< |
multv3(v, fa->farg+6, totxform); |
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", |
413 |
< |
fa->farg[9], fa->farg[10], fa->farg[11]); |
414 |
< |
printf(" %18.12g %18.12g %18.12g\n", |
415 |
< |
fa->farg[12], fa->farg[13], fa->farg[14]); |
631 |
> |
multv3(v, fa.farg+6, tot.xfm); |
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 |
< |
freefargs(fa); |
639 |
> |
putchar('\n'); |
640 |
> |
freefargs(&fa); |
641 |
|
return(0); |
642 |
|
} |
643 |
|
|
645 |
|
o_source(fin) /* transform source arguments */ |
646 |
|
FILE *fin; |
647 |
|
{ |
648 |
< |
double dv[3]; |
649 |
< |
register FUNARGS *fa; |
648 |
> |
FVECT dv; |
649 |
> |
FUNARGS fa; |
650 |
|
|
651 |
< |
if ((fa = getfargs(fin)) == NULL) |
651 |
> |
if (readfargs(&fa, fin) != 1) |
652 |
|
return(-1); |
653 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
653 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
654 |
|
return(-1); |
655 |
|
/* transform direction vector */ |
656 |
< |
multv3(dv, fa->farg, totxform); |
656 |
> |
multv3(dv, fa.farg, tot.xfm); |
657 |
|
/* output */ |
658 |
|
printf("0\n0\n4"); |
659 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
660 |
< |
dv[0], dv[1], dv[2], fa->farg[3]); |
661 |
< |
freefargs(fa); |
660 |
> |
dv[0], dv[1], dv[2], fa.farg[3]); |
661 |
> |
freefargs(&fa); |
662 |
|
return(0); |
663 |
|
} |
664 |
|
|
666 |
|
o_sphere(fin) /* transform sphere arguments */ |
667 |
|
FILE *fin; |
668 |
|
{ |
669 |
< |
double cent[3], rad; |
670 |
< |
register FUNARGS *fa; |
669 |
> |
FVECT cent; |
670 |
> |
double rad; |
671 |
> |
FUNARGS fa; |
672 |
|
|
673 |
< |
if ((fa = getfargs(fin)) == NULL) |
673 |
> |
if (readfargs(&fa, fin) != 1) |
674 |
|
return(-1); |
675 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
675 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
676 |
|
return(-1); |
677 |
|
|
678 |
< |
multp3(cent, fa->farg, totxform); /* transform center */ |
678 |
> |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
679 |
|
|
680 |
< |
rad = fa->farg[3] * totscale; /* scale radius */ |
680 |
> |
rad = fa.farg[3] * tot.sca; /* scale radius */ |
681 |
|
|
682 |
|
printf("0\n0\n4"); |
683 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
684 |
|
cent[0], cent[1], cent[2], rad); |
685 |
< |
freefargs(fa); |
685 |
> |
freefargs(&fa); |
686 |
|
return(0); |
687 |
|
} |
688 |
|
|
690 |
|
o_face(fin) /* transform face arguments */ |
691 |
|
FILE *fin; |
692 |
|
{ |
693 |
< |
double p[3]; |
693 |
> |
FVECT p; |
694 |
|
register int i; |
695 |
< |
register FUNARGS *fa; |
695 |
> |
FUNARGS fa; |
696 |
|
|
697 |
< |
if ((fa = getfargs(fin)) == NULL) |
697 |
> |
if (readfargs(&fa, fin) != 1) |
698 |
|
return(-1); |
699 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs % 3) |
699 |
> |
if (fa.nsargs != 0 || fa.nfargs % 3) |
700 |
|
return(-1); |
701 |
|
|
702 |
< |
printf("0\n0\n%d\n", fa->nfargs); |
702 |
> |
printf("0\n0\n%d\n", fa.nfargs); |
703 |
|
|
704 |
< |
for (i = 0; i < fa->nfargs; i += 3) { |
704 |
> |
for (i = 0; i < fa.nfargs; i += 3) { |
705 |
|
if (reverse) |
706 |
< |
multp3(p, fa->farg+(fa->nfargs-i-3), totxform); |
706 |
> |
multp3(p, fa.farg+(fa.nfargs-i-3), tot.xfm); |
707 |
|
else |
708 |
< |
multp3(p, fa->farg+i, totxform); |
708 |
> |
multp3(p, fa.farg+i, tot.xfm); |
709 |
|
printf(" %18.12g %18.12g %18.12g\n", p[0], p[1], p[2]); |
710 |
|
} |
711 |
< |
freefargs(fa); |
711 |
> |
freefargs(&fa); |
712 |
|
return(0); |
713 |
|
} |
714 |
|
|
716 |
|
o_cone(fin) /* transform cone and cup arguments */ |
717 |
|
FILE *fin; |
718 |
|
{ |
719 |
< |
double p0[3], p1[3], r0, r1; |
720 |
< |
register FUNARGS *fa; |
719 |
> |
FVECT p0, p1; |
720 |
> |
double r0, r1; |
721 |
> |
FUNARGS fa; |
722 |
|
|
723 |
< |
if ((fa = getfargs(fin)) == NULL) |
723 |
> |
if (readfargs(&fa, fin) != 1) |
724 |
|
return(-1); |
725 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
725 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
726 |
|
return(-1); |
727 |
|
|
728 |
|
printf("0\n0\n8\n"); |
729 |
|
|
730 |
< |
multp3(p0, fa->farg, totxform); |
731 |
< |
multp3(p1, fa->farg+3, totxform); |
732 |
< |
r0 = fa->farg[6] * totscale; |
733 |
< |
r1 = fa->farg[7] * totscale; |
730 |
> |
multp3(p0, fa.farg, tot.xfm); |
731 |
> |
multp3(p1, fa.farg+3, tot.xfm); |
732 |
> |
r0 = fa.farg[6] * tot.sca; |
733 |
> |
r1 = fa.farg[7] * tot.sca; |
734 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
735 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
736 |
|
printf(" %18.12g %18.12g\n", r0, r1); |
737 |
|
|
738 |
< |
freefargs(fa); |
738 |
> |
freefargs(&fa); |
739 |
|
return(0); |
740 |
|
} |
741 |
|
|
743 |
|
o_cylinder(fin) /* transform cylinder and tube arguments */ |
744 |
|
FILE *fin; |
745 |
|
{ |
746 |
< |
double p0[3], p1[3], rad; |
747 |
< |
register FUNARGS *fa; |
746 |
> |
FVECT p0, p1; |
747 |
> |
double rad; |
748 |
> |
FUNARGS fa; |
749 |
|
|
750 |
< |
if ((fa = getfargs(fin)) == NULL) |
750 |
> |
if (readfargs(&fa, fin) != 1) |
751 |
|
return(-1); |
752 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 7) |
752 |
> |
if (fa.nsargs != 0 || fa.nfargs != 7) |
753 |
|
return(-1); |
754 |
|
|
755 |
|
printf("0\n0\n7\n"); |
756 |
|
|
757 |
< |
multp3(p0, fa->farg, totxform); |
758 |
< |
multp3(p1, fa->farg+3, totxform); |
759 |
< |
rad = fa->farg[6] * totscale; |
757 |
> |
multp3(p0, fa.farg, tot.xfm); |
758 |
> |
multp3(p1, fa.farg+3, tot.xfm); |
759 |
> |
rad = fa.farg[6] * tot.sca; |
760 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
761 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
762 |
|
printf(" %18.12g\n", rad); |
763 |
< |
freefargs(fa); |
763 |
> |
freefargs(&fa); |
764 |
|
return(0); |
765 |
|
} |
766 |
|
|
768 |
|
o_ring(fin) /* transform ring arguments */ |
769 |
|
FILE *fin; |
770 |
|
{ |
771 |
< |
double p0[3], pd[3], r0, r1; |
772 |
< |
register FUNARGS *fa; |
771 |
> |
FVECT p0, pd; |
772 |
> |
double r0, r1; |
773 |
> |
FUNARGS fa; |
774 |
|
|
775 |
< |
if ((fa = getfargs(fin)) == NULL) |
775 |
> |
if (readfargs(&fa, fin) != 1) |
776 |
|
return(-1); |
777 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
777 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
778 |
|
return(-1); |
779 |
|
|
780 |
|
printf("0\n0\n8\n"); |
781 |
|
|
782 |
< |
multp3(p0, fa->farg, totxform); |
783 |
< |
multv3(pd, fa->farg+3, totxform); |
784 |
< |
r0 = fa->farg[6] * totscale; |
785 |
< |
r1 = fa->farg[7] * totscale; |
782 |
> |
multp3(p0, fa.farg, tot.xfm); |
783 |
> |
multv3(pd, fa.farg+3, tot.xfm); |
784 |
> |
if (invert) { |
785 |
> |
pd[0] = -pd[0]; |
786 |
> |
pd[1] = -pd[1]; |
787 |
> |
pd[2] = -pd[2]; |
788 |
> |
} |
789 |
> |
r0 = fa.farg[6] * tot.sca; |
790 |
> |
r1 = fa.farg[7] * tot.sca; |
791 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
792 |
|
printf(" %18.12g %18.12g %18.12g\n", pd[0], pd[1], pd[2]); |
793 |
|
printf(" %18.12g %18.12g\n", r0, r1); |
794 |
< |
freefargs(fa); |
794 |
> |
freefargs(&fa); |
795 |
|
return(0); |
796 |
|
} |
797 |
|
|
798 |
|
|
799 |
< |
FUNARGS * |
568 |
< |
getfargs(fp) /* get function arguments from stream */ |
569 |
< |
FILE *fp; |
799 |
> |
initotypes() /* initialize ofun[] array */ |
800 |
|
{ |
571 |
– |
char *strcpy(); |
572 |
– |
char sbuf[MAXSTR]; |
573 |
– |
int n; |
574 |
– |
register FUNARGS *fa; |
801 |
|
register int i; |
802 |
|
|
803 |
< |
if ((fa = (FUNARGS *)malloc((unsigned)sizeof(FUNARGS))) == NULL) |
804 |
< |
goto memerr; |
805 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
806 |
< |
return(NULL); |
807 |
< |
if (fa->nsargs = n) { |
808 |
< |
fa->sarg = (char **)malloc((unsigned)fa->nsargs*sizeof(char *)); |
809 |
< |
if (fa->sarg == NULL) |
810 |
< |
goto memerr; |
811 |
< |
for (i = 0; i < fa->nsargs; i++) { |
812 |
< |
if (fscanf(fp, "%s", sbuf) != 1) |
813 |
< |
return(NULL); |
814 |
< |
if ((fa->sarg[i] = malloc((unsigned)strlen(sbuf)+1)) == NULL) |
815 |
< |
goto memerr; |
816 |
< |
strcpy(fa->sarg[i], sbuf); |
817 |
< |
} |
818 |
< |
} else |
819 |
< |
fa->sarg = NULL; |
820 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
821 |
< |
return(NULL); |
822 |
< |
if (fa->niargs = n) { |
823 |
< |
fa->iarg = (int *)malloc((unsigned)fa->niargs*sizeof(int)); |
824 |
< |
if (fa->iarg == NULL) |
825 |
< |
goto memerr; |
826 |
< |
for (i = 0; i < fa->niargs; i++) |
827 |
< |
if (fscanf(fp, "%d", &fa->iarg[i]) != 1) |
828 |
< |
return(NULL); |
829 |
< |
} else |
830 |
< |
fa->iarg = NULL; |
831 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
832 |
< |
return(NULL); |
833 |
< |
if (fa->nfargs = n) { |
834 |
< |
fa->farg = (double *)malloc((unsigned)fa->nfargs*sizeof(double)); |
835 |
< |
if (fa->farg == NULL) |
836 |
< |
goto memerr; |
837 |
< |
for (i = 0; i < fa->nfargs; i++) |
838 |
< |
if (fscanf(fp, "%lf", &fa->farg[i]) != 1) |
839 |
< |
return(NULL); |
840 |
< |
} else |
841 |
< |
fa->farg = NULL; |
842 |
< |
return(fa); |
617 |
< |
memerr: |
618 |
< |
fprintf(stderr, "%s: out of memory in getfargs\n", progname); |
619 |
< |
exit(1); |
803 |
> |
if (ofun[OBJ_SOURCE].funp == o_source) |
804 |
> |
return; /* done already */ |
805 |
> |
/* alias is additional */ |
806 |
> |
ofun[ALIAS].funame = ALIASID; |
807 |
> |
ofun[ALIAS].flags = 0; |
808 |
> |
/* functions get new transform */ |
809 |
> |
for (i = 0; i < NUMTYPES; i++) |
810 |
> |
if (hasfunc(i)) |
811 |
> |
ofun[i].funp = addxform; |
812 |
> |
/* special cases */ |
813 |
> |
ofun[OBJ_SOURCE].funp = o_source; |
814 |
> |
ofun[OBJ_SPHERE].funp = |
815 |
> |
ofun[OBJ_BUBBLE].funp = o_sphere; |
816 |
> |
ofun[OBJ_FACE].funp = o_face; |
817 |
> |
ofun[OBJ_CONE].funp = |
818 |
> |
ofun[OBJ_CUP].funp = o_cone; |
819 |
> |
ofun[OBJ_CYLINDER].funp = |
820 |
> |
ofun[OBJ_TUBE].funp = o_cylinder; |
821 |
> |
ofun[OBJ_RING].funp = o_ring; |
822 |
> |
ofun[OBJ_INSTANCE].funp = addxform; |
823 |
> |
ofun[MAT_GLOW].funp = m_glow; |
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; |
837 |
> |
tinvers[OBJ_SPHERE] = OBJ_BUBBLE; |
838 |
> |
tinvers[OBJ_BUBBLE] = OBJ_SPHERE; |
839 |
> |
tinvers[OBJ_RING] = OBJ_RING; |
840 |
> |
tinvers[OBJ_CYLINDER] = OBJ_TUBE; |
841 |
> |
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
842 |
> |
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
843 |
|
} |
844 |
|
|
845 |
|
|
846 |
< |
freefargs(fa) /* free memory associated with fa */ |
847 |
< |
register FUNARGS *fa; |
846 |
> |
#ifdef OLDXFORM |
847 |
> |
openmain(fname) |
848 |
> |
char *fname; |
849 |
|
{ |
850 |
< |
register int i; |
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 |
< |
for (i = 0; i < fa->nsargs; i++) |
881 |
< |
free(fa->sarg[i]); |
882 |
< |
if (fa->nsargs) |
883 |
< |
free(fa->sarg); |
884 |
< |
if (fa->niargs) |
885 |
< |
free(fa->iarg); |
886 |
< |
if (fa->nfargs) |
887 |
< |
free(fa->farg); |
888 |
< |
free(fa); |
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 |