1 |
– |
/* Copyright (c) 1986 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. |
9 |
|
* 11/6/86 Finally added error checking! |
10 |
|
*/ |
11 |
|
|
15 |
– |
#include <stdio.h> |
16 |
– |
|
12 |
|
#include <ctype.h> |
13 |
|
|
14 |
+ |
#include "platform.h" |
15 |
+ |
#include "paths.h" |
16 |
+ |
#include "rtio.h" |
17 |
+ |
#include "rtmath.h" |
18 |
+ |
#include "object.h" |
19 |
+ |
#include "otypes.h" |
20 |
|
|
20 |
– |
typedef struct { |
21 |
– |
char *funame; /* function name */ |
22 |
– |
int (*funp)(); /* pointer to function */ |
23 |
– |
} FUN; |
24 |
– |
|
21 |
|
int xac; /* global xform argument count */ |
22 |
|
char **xav; /* global xform argument pointer */ |
23 |
|
int xfa; /* start of xf arguments */ |
24 |
|
|
25 |
< |
double totxform[4][4]; /* total transformation matrix */ |
26 |
< |
double totscale; /* total scale factor */ |
31 |
< |
int reverse; /* boolean true if scene inverted */ |
25 |
> |
XF tot; /* total transformation */ |
26 |
> |
int reverse; /* boolean true if scene mirrored */ |
27 |
|
|
28 |
< |
int expand = 0; /* boolean true to expand commands */ |
28 |
> |
int invert; /* boolean true to invert surfaces */ |
29 |
|
|
30 |
< |
char *idprefix = NULL; /* prefix for object identifiers */ |
30 |
> |
int expand; /* boolean true to expand commands */ |
31 |
|
|
32 |
< |
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(); |
32 |
> |
char *newmod; /* new modifier for surfaces */ |
33 |
|
|
34 |
< |
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 |
< |
}; |
34 |
> |
char *idprefix; /* prefix for object identifiers */ |
35 |
|
|
36 |
< |
#define issurface(t) ((t)<=9) |
36 |
> |
FUN ofun[NUMOTYPE] = INIT_OTYPE; /* default types and actions */ |
37 |
|
|
38 |
< |
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; |
38 |
> |
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
39 |
|
|
40 |
< |
#define MAXSTR 512 /* maximum string length */ |
40 |
> |
int nrept = 1; /* number of array repetitions */ |
41 |
|
|
42 |
< |
FUNARGS *getfargs(); |
104 |
< |
char *malloc(); |
42 |
> |
int stdinused = 0; /* stdin has been used by -f option? */ |
43 |
|
|
44 |
< |
#define progname (xav[0]) |
44 |
> |
char mainfn[PATH_MAX]; /* main file name */ |
45 |
> |
FILE *mainfp = NULL; /* main file pointer */ |
46 |
|
|
47 |
+ |
#define progname (xav[0]) |
48 |
|
|
49 |
< |
main(argc, argv) /* get transform options and transform file */ |
50 |
< |
int argc; |
51 |
< |
char *argv[]; |
49 |
> |
static int doargf(int ac, char **av, int fi); |
50 |
> |
static int doarray(int ac, char **av, int ai); |
51 |
> |
static void xform(char *name, FILE *fin); |
52 |
> |
static void xfcomm(char *fname, FILE *fin); |
53 |
> |
static void xfobject(char *fname, FILE *fin); |
54 |
> |
static int addxform(FILE *fin); |
55 |
> |
static int alias(FILE *fin); |
56 |
> |
void initotypes(void); /* XXX conflict with otypes.h */ |
57 |
> |
static void openmain(char *iname); |
58 |
> |
|
59 |
> |
|
60 |
> |
int |
61 |
> |
main( /* get transform options and transform file */ |
62 |
> |
int argc, |
63 |
> |
char *argv[] |
64 |
> |
) |
65 |
|
{ |
66 |
< |
FILE *fopen(); |
114 |
< |
FILE *fp; |
66 |
> |
int mal_prefix = 0; |
67 |
|
int a; |
68 |
+ |
/* check for argument list file */ |
69 |
+ |
for (a = 1; a < argc; a++) |
70 |
+ |
if (!strcmp(argv[a], "-f")) |
71 |
+ |
return(doargf(argc, argv, a)); |
72 |
+ |
/* check for regular array */ |
73 |
+ |
for (a = 1; a < argc; a++) |
74 |
+ |
if (!strcmp(argv[a], "-a")) |
75 |
+ |
return(doarray(argc, argv, a)); |
76 |
|
|
77 |
< |
xav = argv; |
77 |
> |
initotypes(); /* initialize */ |
78 |
> |
invert = 0; |
79 |
> |
expand = 1; |
80 |
> |
newmod = NULL; |
81 |
> |
idprefix = NULL; |
82 |
|
|
83 |
|
for (a = 1; a < argc; a++) { |
84 |
|
if (argv[a][0] == '-') |
85 |
|
switch (argv[a][1]) { |
86 |
+ |
case 'm': |
87 |
+ |
if (argv[a][2] | (a+1 >= argc)) |
88 |
+ |
break; |
89 |
+ |
a++; |
90 |
+ |
if (newmod == NULL) |
91 |
+ |
newmod = argv[a]; |
92 |
+ |
continue; |
93 |
|
case 'n': |
94 |
< |
idprefix = argv[++a]; |
94 |
> |
if (argv[a][2] | (a+1 >= argc)) |
95 |
> |
break; |
96 |
> |
a++; |
97 |
> |
if (idprefix == NULL) |
98 |
> |
idprefix = argv[a]; |
99 |
> |
else { |
100 |
> |
char *newp; |
101 |
> |
newp = (char *)malloc(strlen(idprefix)+ |
102 |
> |
strlen(argv[a])+2); |
103 |
> |
if (newp == NULL) |
104 |
> |
exit(2); |
105 |
> |
sprintf(newp, "%s.%s", |
106 |
> |
idprefix, argv[a]); |
107 |
> |
if (mal_prefix++) |
108 |
> |
free(idprefix); |
109 |
> |
idprefix = newp; |
110 |
> |
} |
111 |
|
continue; |
112 |
+ |
case 'c': |
113 |
+ |
if (argv[a][2]) |
114 |
+ |
break; |
115 |
+ |
expand = 0; |
116 |
+ |
continue; |
117 |
|
case 'e': |
118 |
+ |
if (argv[a][2]) |
119 |
+ |
break; |
120 |
|
expand = 1; |
121 |
|
continue; |
122 |
+ |
case 'I': |
123 |
+ |
if (argv[a][2]) |
124 |
+ |
break; |
125 |
+ |
invert = !invert; |
126 |
+ |
continue; |
127 |
|
} |
128 |
|
break; |
129 |
|
} |
130 |
|
|
131 |
+ |
xav = argv; |
132 |
|
xfa = a; |
133 |
|
|
134 |
< |
totscale = 1.0; |
135 |
< |
setident4(totxform); |
134 |
> |
a += xf(&tot, argc-a, argv+a); |
135 |
|
|
136 |
< |
a += xf(totxform, &totscale, argc-a, argv+a); |
136 |
> |
if ( (reverse = (tot.sca < 0.0)) ) |
137 |
> |
tot.sca = -tot.sca; |
138 |
> |
if (invert) |
139 |
> |
reverse = !reverse; |
140 |
|
|
141 |
< |
if (reverse = totscale < 0.0) |
142 |
< |
totscale = -totscale; |
141 |
> |
if (a < argc && argv[a][0] == '-') { |
142 |
> |
fprintf(stderr, "%s: command line error at '%s'\n", |
143 |
> |
argv[0], argv[a]); |
144 |
> |
exit(1); |
145 |
> |
} |
146 |
|
|
147 |
|
xac = a; |
148 |
< |
|
149 |
< |
putchar('#'); /* simple header */ |
148 |
> |
/* simple header */ |
149 |
> |
putchar('#'); |
150 |
|
for (a = 0; a < xac; a++) |
151 |
|
printf(" %s", xav[a]); |
152 |
|
putchar('\n'); |
153 |
+ |
/* transform input */ |
154 |
+ |
if (xac == argc) { |
155 |
+ |
if (stdinused) { |
156 |
+ |
fprintf(stderr, "%s: cannot use stdin more than once\n", |
157 |
+ |
argv[0]); |
158 |
+ |
exit(1); |
159 |
+ |
} |
160 |
+ |
openmain(NULL); |
161 |
+ |
xform(mainfn, mainfp); |
162 |
+ |
} else |
163 |
+ |
for (a = xac; a < argc; a++) { |
164 |
+ |
openmain(argv[a]); |
165 |
+ |
xform(mainfn, mainfp); |
166 |
+ |
} |
167 |
|
|
168 |
< |
if (a == argc) |
169 |
< |
xform("standard input", stdin); |
170 |
< |
else |
171 |
< |
for ( ; a < argc; a++) { |
172 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
173 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
174 |
< |
progname, argv[a]); |
175 |
< |
exit(1); |
168 |
> |
if (mal_prefix) |
169 |
> |
free(idprefix); |
170 |
> |
return(0); |
171 |
> |
} |
172 |
> |
|
173 |
> |
|
174 |
> |
int |
175 |
> |
doargf( /* take argument list from file */ |
176 |
> |
int ac, |
177 |
> |
char **av, |
178 |
> |
int fi |
179 |
> |
) |
180 |
> |
{ |
181 |
> |
int inquote; |
182 |
> |
char *newav[256], **avp; |
183 |
> |
char argbuf[2048]; |
184 |
> |
char *newid, newidbuf[128]; |
185 |
> |
char *oldid; |
186 |
> |
char *cp; |
187 |
> |
FILE *argfp; |
188 |
> |
int n, i, k, newac, err; |
189 |
> |
|
190 |
> |
if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) { |
191 |
> |
fprintf(stderr, "%s: missing file for -f option\n", av[0]); |
192 |
> |
exit(1); |
193 |
> |
} |
194 |
> |
if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') { |
195 |
> |
if (stdinused++) { |
196 |
> |
fprintf(stderr, |
197 |
> |
"%s: cannot use stdin more than once\n", |
198 |
> |
av[0]); |
199 |
> |
exit(1); |
200 |
> |
} |
201 |
> |
argfp = stdin; |
202 |
> |
n = 100; /* we just don't know! */ |
203 |
> |
} else { |
204 |
> |
if ((argfp = fopen(av[fi+1], "r")) == NULL) { |
205 |
> |
fprintf(stderr, |
206 |
> |
"%s: cannot open argument file \"%s\"\n", |
207 |
> |
av[0], av[fi+1]); |
208 |
> |
exit(1); |
209 |
> |
} |
210 |
> |
n = 0; /* count number of lines in file */ |
211 |
> |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) |
212 |
> |
n += argbuf[0] && argbuf[0] != '#'; |
213 |
> |
if (!n) { |
214 |
> |
fprintf(stderr, "%s: empty argument file \"%s\"\n", |
215 |
> |
av[0], av[fi+1]); |
216 |
> |
exit(1); |
217 |
> |
} |
218 |
> |
nrept *= n; |
219 |
> |
rewind(argfp); |
220 |
> |
} |
221 |
> |
err = 0; k = 0; /* read each arg list and call main */ |
222 |
> |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) { |
223 |
> |
if (!argbuf[0] || argbuf[0] == '#') |
224 |
> |
continue; |
225 |
> |
avp = newav+2; |
226 |
> |
avp[0] = av[0]; |
227 |
> |
for (i = 1; i < fi; i++) |
228 |
> |
avp[i] = av[i]; |
229 |
> |
newac = i; |
230 |
> |
cp = argbuf; /* parse new words */ |
231 |
> |
if (*cp == '!') cp++; |
232 |
> |
if (!strncmp(cp, "xform ", 6)) cp += 6; |
233 |
> |
inquote = 0; |
234 |
> |
for ( ; ; ) { |
235 |
> |
skipspaces: |
236 |
> |
while (isspace(*cp)) /* nullify spaces */ |
237 |
> |
*cp++ = '\0'; |
238 |
> |
if ((*cp == '"') | (*cp == '\'')) |
239 |
> |
inquote = *cp++; |
240 |
> |
if (!*cp) /* all done? */ |
241 |
> |
break; |
242 |
> |
if (cp[0] == '\\' && cp[1]) |
243 |
> |
if (*++cp == '\n') |
244 |
> |
goto skipspaces; |
245 |
> |
avp[newac++] = cp; /* add argument to list */ |
246 |
> |
if (inquote) { |
247 |
> |
while (*++cp) |
248 |
> |
if (*cp == inquote) { |
249 |
> |
*cp++ = '\0'; |
250 |
> |
break; |
251 |
> |
} |
252 |
> |
} else { |
253 |
> |
while (*++cp && !isspace(*cp)) |
254 |
> |
; |
255 |
|
} |
158 |
– |
xform(argv[a], fp); |
159 |
– |
fclose(fp); |
256 |
|
} |
257 |
+ |
for (i = fi+2; i < ac; i++) |
258 |
+ |
avp[newac++] = av[i]; |
259 |
+ |
avp[newac] = NULL; |
260 |
+ |
newid = newidbuf; |
261 |
+ |
oldid = NULL; |
262 |
+ |
for (i = 2; i < newac; i++) |
263 |
+ |
if (!strcmp(avp[i-1], "-n")) { |
264 |
+ |
oldid = avp[i]; |
265 |
+ |
if (strlen(oldid)+32 > sizeof(newidbuf)) { |
266 |
+ |
newid = (char *)malloc(strlen(oldid)+32); |
267 |
+ |
if (newid == NULL) |
268 |
+ |
exit(2); |
269 |
+ |
} |
270 |
+ |
avp[i] = newid; |
271 |
+ |
break; |
272 |
+ |
} |
273 |
+ |
if (oldid == NULL) { |
274 |
+ |
newav[0] = av[0]; |
275 |
+ |
newav[1] = "-n"; |
276 |
+ |
newav[2] = newid; |
277 |
+ |
avp = newav; |
278 |
+ |
newac += 2; |
279 |
+ |
} |
280 |
+ |
if (oldid == NULL) |
281 |
+ |
sprintf(newid, "i%d", k); |
282 |
+ |
else |
283 |
+ |
sprintf(newid, "%s.%d", oldid, k); |
284 |
+ |
err |= main(newac, avp); |
285 |
+ |
if (newid != newidbuf) |
286 |
+ |
free(newid); |
287 |
+ |
k++; |
288 |
+ |
} |
289 |
+ |
fclose(argfp); |
290 |
+ |
return(err); |
291 |
+ |
} |
292 |
|
|
293 |
< |
exit(0); |
293 |
> |
|
294 |
> |
int |
295 |
> |
doarray( /* make array */ |
296 |
> |
int ac, |
297 |
> |
char **av, |
298 |
> |
int ai |
299 |
> |
) |
300 |
> |
{ |
301 |
> |
char *newav[256], **avp; |
302 |
> |
char newid[128], repts[32]; |
303 |
> |
char *oldid = NULL; |
304 |
> |
int n, i, err; |
305 |
> |
|
306 |
> |
if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) { |
307 |
> |
fprintf(stderr, "%s: missing count for -a option\n", av[0]); |
308 |
> |
exit(1); |
309 |
> |
} |
310 |
> |
nrept *= n; |
311 |
> |
avp = newav+2; |
312 |
> |
avp[0] = av[0]; |
313 |
> |
for (i = 1; i < ac; i++) |
314 |
> |
if (!strcmp(av[i-1], "-n")) { |
315 |
> |
oldid = av[i]; |
316 |
> |
avp[i] = newid; |
317 |
> |
} else |
318 |
> |
avp[i] = av[i]; |
319 |
> |
avp[ai] = "-i"; |
320 |
> |
avp[ai+1] = repts; |
321 |
> |
avp[i] = NULL; |
322 |
> |
if (oldid == NULL) { |
323 |
> |
newav[0] = av[0]; |
324 |
> |
newav[1] = "-n"; |
325 |
> |
newav[2] = newid; |
326 |
> |
avp = newav; |
327 |
> |
ac += 2; |
328 |
> |
} |
329 |
> |
err = 0; |
330 |
> |
for (i = 0; i < n; i++) { |
331 |
> |
if (oldid == NULL) |
332 |
> |
sprintf(newid, "a%d", i); |
333 |
> |
else |
334 |
> |
sprintf(newid, "%s.%d", oldid, i); |
335 |
> |
sprintf(repts, "%d", i); |
336 |
> |
err |= main(ac, avp); |
337 |
> |
} |
338 |
> |
return(err); |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
< |
xform(name, fin) /* transform stream by totxform */ |
343 |
< |
char *name; |
344 |
< |
register FILE *fin; |
342 |
> |
void |
343 |
> |
xform( /* transform stream by tot.xfm */ |
344 |
> |
char *name, |
345 |
> |
FILE *fin |
346 |
> |
) |
347 |
|
{ |
348 |
< |
register int c; |
348 |
> |
int nobjs = 0; |
349 |
> |
int c; |
350 |
|
|
351 |
|
while ((c = getc(fin)) != EOF) { |
352 |
|
if (isspace(c)) /* blank */ |
360 |
|
} while (c != '\n'); |
361 |
|
} else if (c == '!') { /* command */ |
362 |
|
ungetc(c, fin); |
363 |
< |
if (expand) |
364 |
< |
xfcomm(name, fin); |
186 |
< |
else { |
187 |
< |
putchar('\n'); |
188 |
< |
while ((c = getc(fin)) != EOF && c != '\n') |
189 |
< |
putchar(c); |
190 |
< |
printf(" | %s -e", xav[0]); |
191 |
< |
for (c = 1; c < xac; c++) |
192 |
< |
printf(" %s", xav[c]); |
193 |
< |
putchar('\n'); |
194 |
< |
} |
363 |
> |
xfcomm(name, fin); |
364 |
> |
nobjs++; |
365 |
|
} else { /* object */ |
366 |
|
ungetc(c, fin); |
367 |
|
xfobject(name, fin); |
368 |
+ |
nobjs++; |
369 |
|
} |
370 |
|
} |
371 |
+ |
if (nobjs == 0) |
372 |
+ |
fprintf(stderr, "%s: (%s): warning - empty file\n", |
373 |
+ |
progname, name); |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
xfcomm(fname, fin) /* expand a command */ |
378 |
< |
FILE *fin; |
377 |
> |
void |
378 |
> |
xfcomm( /* transform a command */ |
379 |
> |
char *fname, |
380 |
> |
FILE *fin |
381 |
> |
) |
382 |
|
{ |
206 |
– |
FILE *popen(); |
207 |
– |
char *fgets(); |
383 |
|
FILE *pin; |
384 |
< |
char buf[512]; |
384 |
> |
char buf[2048]; |
385 |
> |
int i; |
386 |
|
|
387 |
< |
fgets(buf, sizeof(buf), fin); |
388 |
< |
if (buf[strlen(buf)-1] == '\n') |
389 |
< |
buf[strlen(buf)-1] = '\0'; |
390 |
< |
if ((pin = popen(buf+1, "r")) == NULL) { |
391 |
< |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
392 |
< |
progname, fname, buf); |
393 |
< |
exit(1); |
387 |
> |
fgetline(buf, sizeof(buf), fin); |
388 |
> |
if (expand) { |
389 |
> |
if ((pin = popen(buf+1, "r")) == NULL) { |
390 |
> |
fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n", |
391 |
> |
progname, fname, buf); |
392 |
> |
exit(1); |
393 |
> |
} |
394 |
> |
xform(buf, pin); |
395 |
> |
pclose(pin); |
396 |
> |
} else { |
397 |
> |
printf("\n%s", buf); |
398 |
> |
if (xac > 1) { |
399 |
> |
printf(" | %s -e", xav[0]); /* expand next time */ |
400 |
> |
for (i = 1; i < xac; i++) |
401 |
> |
if (i >= xfa || strcmp(xav[i], "-c")) |
402 |
> |
printf(" %s", xav[i]); |
403 |
> |
} |
404 |
> |
putchar('\n'); |
405 |
|
} |
219 |
– |
xform(buf, pin); |
220 |
– |
pclose(pin); |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
< |
xfobject(fname, fin) /* transform an object */ |
410 |
< |
char *fname; |
411 |
< |
FILE *fin; |
409 |
> |
void |
410 |
> |
xfobject( /* transform an object */ |
411 |
> |
char *fname, |
412 |
> |
FILE *fin |
413 |
> |
) |
414 |
|
{ |
415 |
< |
char stmp[MAXSTR]; |
415 |
> |
char typ[16], nam[MAXSTR]; |
416 |
|
int fn; |
417 |
< |
|
418 |
< |
fscanf(fin, "%s", stmp); /* modifier */ |
419 |
< |
printf("\n%s ", stmp); |
420 |
< |
fscanf(fin, "%s", stmp); /* object type */ |
421 |
< |
if ((fn = otype(stmp)) < 0) { |
417 |
> |
/* modifier and type */ |
418 |
> |
strcpy(typ, "EOF"); |
419 |
> |
fgetword(nam, sizeof(nam), fin); |
420 |
> |
fgetword(typ, sizeof(typ), fin); |
421 |
> |
if ((fn = otype(typ)) < 0) { |
422 |
|
fprintf(stderr, "%s: (%s): unknown object type \"%s\"\n", |
423 |
< |
progname, fname, stmp); |
423 |
> |
progname, fname, typ); |
424 |
|
exit(1); |
425 |
|
} |
426 |
< |
printf("%s ", stmp); |
427 |
< |
fscanf(fin, "%s", stmp); /* object name */ |
428 |
< |
if (idprefix != NULL && issurface(fn)) |
429 |
< |
printf("%s.%s\n", idprefix, stmp); |
430 |
< |
else |
431 |
< |
printf("%s\n", stmp); |
432 |
< |
/* transform arguments */ |
426 |
> |
putchar('\n'); |
427 |
> |
if (ismodifier(fn)) { |
428 |
> |
fputword(nam, stdout); |
429 |
> |
printf(" %s ", typ); |
430 |
> |
} else { |
431 |
> |
fputword(newmod != NULL ? newmod : nam, stdout); |
432 |
> |
printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ); |
433 |
> |
} |
434 |
> |
/* object name */ |
435 |
> |
fgetword(nam, sizeof(nam), fin); |
436 |
> |
if (idprefix == NULL || ismodifier(fn)) |
437 |
> |
fputword(nam, stdout); |
438 |
> |
else { |
439 |
> |
char nnam[MAXSTR]; |
440 |
> |
sprintf(nnam, "%s.%s", idprefix, nam); |
441 |
> |
fputword(nnam, stdout); |
442 |
> |
} |
443 |
> |
putchar('\n'); |
444 |
> |
/* transform arguments */ |
445 |
|
if ((*ofun[fn].funp)(fin) < 0) { |
446 |
|
fprintf(stderr, "%s: (%s): bad %s \"%s\"\n", |
447 |
< |
progname, fname, ofun[fn].funame, stmp); |
447 |
> |
progname, fname, ofun[fn].funame, nam); |
448 |
|
exit(1); |
449 |
|
} |
450 |
|
} |
451 |
|
|
452 |
|
|
453 |
< |
passargs(fin) /* pass on arguments unchanged */ |
454 |
< |
FILE *fin; |
453 |
> |
int |
454 |
> |
o_default( /* pass on arguments unchanged */ |
455 |
> |
FILE *fin |
456 |
> |
) |
457 |
|
{ |
458 |
< |
register int i; |
459 |
< |
register FUNARGS *fa; |
458 |
> |
int i; |
459 |
> |
FUNARGS fa; |
460 |
|
|
461 |
< |
if ((fa = getfargs(fin)) == NULL) |
461 |
> |
if (readfargs(&fa, fin) != 1) |
462 |
|
return(-1); |
463 |
|
/* string arguments */ |
464 |
< |
printf("%d", fa->nsargs); |
465 |
< |
for (i = 0; i < fa->nsargs; i++) |
466 |
< |
printf(" %s", fa->sarg[i]); |
464 |
> |
printf("%d", fa.nsargs); |
465 |
> |
for (i = 0; i < fa.nsargs; i++) { |
466 |
> |
fputc(' ', stdout); |
467 |
> |
fputword(fa.sarg[i], stdout); |
468 |
> |
} |
469 |
|
printf("\n"); |
470 |
+ |
#ifdef IARGS |
471 |
|
/* integer arguments */ |
472 |
< |
printf("%d", fa->niargs); |
473 |
< |
for (i = 0; i < fa->niargs; i++) |
474 |
< |
printf(" %d", fa->iarg[i]); |
472 |
> |
printf("%d", fa.niargs); |
473 |
> |
for (i = 0; i < fa.niargs; i++) |
474 |
> |
printf(" %d", fa.iarg[i]); |
475 |
|
printf("\n"); |
476 |
+ |
#else |
477 |
+ |
printf("0\n"); |
478 |
+ |
#endif |
479 |
|
/* float arguments */ |
480 |
< |
printf("%d", fa->nfargs); |
481 |
< |
for (i = 0; i < fa->nfargs; i++) |
482 |
< |
printf(" %18.12g", fa->farg[i]); |
480 |
> |
printf("%d", fa.nfargs); |
481 |
> |
for (i = 0; i < fa.nfargs; i++) |
482 |
> |
printf(" %18.12g", fa.farg[i]); |
483 |
|
printf("\n"); |
484 |
< |
freefargs(fa); |
484 |
> |
freefargs(&fa); |
485 |
|
return(0); |
486 |
|
} |
487 |
|
|
488 |
|
|
489 |
< |
addxform(fin) /* add xf arguments to strings */ |
490 |
< |
FILE *fin; |
489 |
> |
int |
490 |
> |
addxform( /* add xf arguments to strings */ |
491 |
> |
FILE *fin |
492 |
> |
) |
493 |
|
{ |
494 |
< |
register int i; |
495 |
< |
register FUNARGS *fa; |
494 |
> |
int i; |
495 |
> |
int resetarr = 0; |
496 |
> |
FUNARGS fa; |
497 |
|
|
498 |
< |
if ((fa = getfargs(fin)) == NULL) |
498 |
> |
if (readfargs(&fa, fin) != 1) |
499 |
|
return(-1); |
500 |
|
/* string arguments */ |
501 |
< |
printf("%d", fa->nsargs + xac-xfa); |
502 |
< |
for (i = 0; i < fa->nsargs; i++) |
503 |
< |
printf(" %s", fa->sarg[i]); |
501 |
> |
if (xac > xfa && strcmp(xav[xfa], "-i")) |
502 |
> |
resetarr = 2; |
503 |
> |
printf("%d", fa.nsargs + resetarr + xac-xfa); |
504 |
> |
for (i = 0; i < fa.nsargs; i++) { |
505 |
> |
fputc(' ', stdout); |
506 |
> |
fputword(fa.sarg[i], stdout); |
507 |
> |
} |
508 |
> |
if (resetarr) |
509 |
> |
printf(" -i 1"); |
510 |
|
for (i = xfa; i < xac; i++) /* add xf arguments */ |
511 |
|
printf(" %s", xav[i]); |
512 |
|
printf("\n"); |
513 |
+ |
#ifdef IARGS |
514 |
|
/* integer arguments */ |
515 |
< |
printf("%d", fa->niargs); |
516 |
< |
for (i = 0; i < fa->niargs; i++) |
517 |
< |
printf(" %d", fa->iarg[i]); |
515 |
> |
printf("%d", fa.niargs); |
516 |
> |
for (i = 0; i < fa.niargs; i++) |
517 |
> |
printf(" %d", fa.iarg[i]); |
518 |
|
printf("\n"); |
519 |
+ |
#else |
520 |
+ |
printf("0\n"); |
521 |
+ |
#endif |
522 |
|
/* float arguments */ |
523 |
< |
printf("%d", fa->nfargs); |
524 |
< |
for (i = 0; i < fa->nfargs; i++) |
525 |
< |
printf(" %18.12g", fa->farg[i]); |
523 |
> |
printf("%d", fa.nfargs); |
524 |
> |
for (i = 0; i < fa.nfargs; i++) |
525 |
> |
printf(" %18.12g", fa.farg[i]); |
526 |
|
printf("\n"); |
527 |
< |
freefargs(fa); |
527 |
> |
freefargs(&fa); |
528 |
|
return(0); |
529 |
|
} |
530 |
|
|
531 |
|
|
532 |
|
int |
533 |
< |
otype(ofname) /* get object function number from its name */ |
534 |
< |
register char *ofname; |
533 |
> |
alias( /* transfer alias */ |
534 |
> |
FILE *fin |
535 |
> |
) |
536 |
|
{ |
537 |
< |
register int i; |
537 |
> |
char aliasnm[MAXSTR]; |
538 |
|
|
539 |
< |
for (i = 0; ofun[i].funame != NULL; i++) |
319 |
< |
if (!strcmp(ofun[i].funame, ofname)) |
320 |
< |
return(i); |
321 |
< |
|
322 |
< |
return(-1); /* not found */ |
323 |
< |
} |
324 |
< |
|
325 |
< |
|
326 |
< |
alias(fin) /* transfer alias */ |
327 |
< |
FILE *fin; |
328 |
< |
{ |
329 |
< |
char alias[MAXSTR]; |
330 |
< |
|
331 |
< |
if (fscanf(fin, "%s", alias) != 1) |
539 |
> |
if (fgetword(aliasnm, MAXSTR, fin) == NULL) |
540 |
|
return(-1); |
541 |
< |
printf("\t%s\n", alias); |
541 |
> |
printf("\t%s\n", aliasnm); |
542 |
|
return(0); |
543 |
|
} |
544 |
|
|
545 |
|
|
546 |
< |
m_glow(fin) /* transform arguments for proximity light */ |
547 |
< |
FILE *fin; |
546 |
> |
int |
547 |
> |
m_glow( /* transform arguments for proximity light */ |
548 |
> |
FILE *fin |
549 |
> |
) |
550 |
|
{ |
551 |
< |
register FUNARGS *fa; |
551 |
> |
FUNARGS fa; |
552 |
|
|
553 |
< |
if ((fa = getfargs(fin)) == NULL) |
553 |
> |
if (readfargs(&fa, fin) != 1) |
554 |
|
return(-1); |
555 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
555 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
556 |
|
return(-1); |
557 |
|
printf("0\n0\n4"); |
558 |
|
printf(" %18.12g %18.12g %18.12g", |
559 |
< |
fa->farg[0], fa->farg[1], fa->farg[2]); |
560 |
< |
printf(" %18.12g\n", fa->farg[3] * totscale); |
561 |
< |
freefargs(fa); |
559 |
> |
fa.farg[0], fa.farg[1], fa.farg[2]); |
560 |
> |
printf(" %18.12g\n", fa.farg[3] * tot.sca); |
561 |
> |
freefargs(&fa); |
562 |
|
return(0); |
563 |
|
} |
564 |
|
|
565 |
|
|
566 |
< |
m_spot(fin) /* transform arguments for spotlight */ |
567 |
< |
FILE *fin; |
566 |
> |
int |
567 |
> |
m_spot( /* transform arguments for spotlight */ |
568 |
> |
FILE *fin |
569 |
> |
) |
570 |
|
{ |
571 |
< |
double v[3]; |
572 |
< |
register FUNARGS *fa; |
571 |
> |
FVECT v; |
572 |
> |
FUNARGS fa; |
573 |
|
|
574 |
< |
if ((fa = getfargs(fin)) == NULL) |
574 |
> |
if (readfargs(&fa, fin) != 1) |
575 |
|
return(-1); |
576 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 7) |
576 |
> |
if (fa.nsargs != 0 || fa.nfargs != 7) |
577 |
|
return(-1); |
578 |
|
printf("0\n0\n7"); |
579 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
580 |
< |
fa->farg[0], fa->farg[1], fa->farg[2], fa->farg[3]); |
581 |
< |
multv3(v, fa->farg+4, totxform); |
580 |
> |
fa.farg[0], fa.farg[1], fa.farg[2], fa.farg[3]); |
581 |
> |
multv3(v, fa.farg+4, tot.xfm); |
582 |
|
printf("\t%18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
583 |
< |
freefargs(fa); |
583 |
> |
freefargs(&fa); |
584 |
|
return(0); |
585 |
|
} |
586 |
|
|
587 |
|
|
588 |
< |
m_dielectric(fin) /* transform arguments for dielectric */ |
589 |
< |
FILE *fin; |
588 |
> |
int |
589 |
> |
m_mist( /* transform arguments for mist */ |
590 |
> |
FILE *fin |
591 |
> |
) |
592 |
|
{ |
593 |
< |
double pow(); |
594 |
< |
register FUNARGS *fa; |
593 |
> |
FUNARGS fa; |
594 |
> |
int i; |
595 |
|
|
596 |
< |
if ((fa = getfargs(fin)) == NULL) |
596 |
> |
if (readfargs(&fa, fin) != 1) |
597 |
|
return(-1); |
598 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 5) |
598 |
> |
if (fa.nfargs > 7) |
599 |
|
return(-1); |
600 |
+ |
printf("%d", fa.nsargs); |
601 |
+ |
if (idprefix == NULL) |
602 |
+ |
for (i = 0; i < fa.nsargs; i++) |
603 |
+ |
printf(" %s", fa.sarg[i]); |
604 |
+ |
else |
605 |
+ |
for (i = 0; i < fa.nsargs; i++) { |
606 |
+ |
char sname[256], *sp; |
607 |
+ |
char *cp1, *cp2 = sname; |
608 |
+ |
/* add idprefix */ |
609 |
+ |
for (sp = fa.sarg[i]; *sp; sp = cp1) { |
610 |
+ |
for (cp1 = idprefix; *cp1; ) |
611 |
+ |
*cp2++ = *cp1++; |
612 |
+ |
*cp2++ = '.'; |
613 |
+ |
for (cp1 = sp; *cp1 && |
614 |
+ |
(*cp2++ = *cp1++) != '>'; ) |
615 |
+ |
; |
616 |
+ |
} |
617 |
+ |
*cp2 = '\0'; |
618 |
+ |
printf(" %s", sname); |
619 |
+ |
} |
620 |
+ |
printf("\n0\n%d", fa.nfargs); |
621 |
+ |
if (fa.nfargs > 2) |
622 |
+ |
printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca, |
623 |
+ |
fa.farg[1]/tot.sca, fa.farg[2]/tot.sca); |
624 |
+ |
for (i = 3; i < fa.nfargs; i++) |
625 |
+ |
printf(" %12.6g", fa.farg[i]); |
626 |
+ |
printf("\n"); |
627 |
+ |
freefargs(&fa); |
628 |
+ |
return(0); |
629 |
+ |
} |
630 |
+ |
|
631 |
+ |
|
632 |
+ |
int |
633 |
+ |
m_dielectric( /* transform arguments for dielectric */ |
634 |
+ |
FILE *fin |
635 |
+ |
) |
636 |
+ |
{ |
637 |
+ |
FUNARGS fa; |
638 |
+ |
|
639 |
+ |
if (readfargs(&fa, fin) != 1) |
640 |
+ |
return(-1); |
641 |
+ |
if (fa.nsargs != 0 || fa.nfargs != 5) |
642 |
+ |
return(-1); |
643 |
|
printf("0\n0\n5"); |
644 |
< |
printf(" %18.12g %18.12g %18.12g", |
645 |
< |
pow(fa->farg[0], 1.0/totscale), |
646 |
< |
pow(fa->farg[1], 1.0/totscale), |
647 |
< |
pow(fa->farg[2], 1.0/totscale)); |
648 |
< |
printf(" %18.12g %18.12g\n", fa->farg[3], fa->farg[4]); |
649 |
< |
freefargs(fa); |
644 |
> |
printf(" %12.6g %12.6g %12.6g", |
645 |
> |
pow(fa.farg[0], 1.0/tot.sca), |
646 |
> |
pow(fa.farg[1], 1.0/tot.sca), |
647 |
> |
pow(fa.farg[2], 1.0/tot.sca)); |
648 |
> |
printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]); |
649 |
> |
freefargs(&fa); |
650 |
|
return(0); |
651 |
|
} |
652 |
|
|
653 |
|
|
654 |
< |
m_interface(fin) /* transform arguments for interface */ |
655 |
< |
FILE *fin; |
654 |
> |
int |
655 |
> |
m_interface( /* transform arguments for interface */ |
656 |
> |
FILE *fin |
657 |
> |
) |
658 |
|
{ |
659 |
< |
double pow(); |
401 |
< |
register FUNARGS *fa; |
659 |
> |
FUNARGS fa; |
660 |
|
|
661 |
< |
if ((fa = getfargs(fin)) == NULL) |
661 |
> |
if (readfargs(&fa, fin) != 1) |
662 |
|
return(-1); |
663 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
663 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
664 |
|
return(-1); |
665 |
|
printf("0\n0\n8\n"); |
666 |
< |
printf("%18.12g %18.12g %18.12g", |
667 |
< |
pow(fa->farg[0], 1.0/totscale), |
668 |
< |
pow(fa->farg[1], 1.0/totscale), |
669 |
< |
pow(fa->farg[2], 1.0/totscale)); |
670 |
< |
printf(" %18.12g\n", fa->farg[3]); |
671 |
< |
printf("%18.12g %18.12g %18.12g", |
672 |
< |
pow(fa->farg[4], 1.0/totscale), |
673 |
< |
pow(fa->farg[5], 1.0/totscale), |
674 |
< |
pow(fa->farg[6], 1.0/totscale)); |
675 |
< |
printf(" %18.12g\n", fa->farg[7]); |
676 |
< |
freefargs(fa); |
666 |
> |
printf("%12.6g %12.6g %12.6g", |
667 |
> |
pow(fa.farg[0], 1.0/tot.sca), |
668 |
> |
pow(fa.farg[1], 1.0/tot.sca), |
669 |
> |
pow(fa.farg[2], 1.0/tot.sca)); |
670 |
> |
printf(" %12.6g\n", fa.farg[3]); |
671 |
> |
printf("%12.6g %12.6g %12.6g", |
672 |
> |
pow(fa.farg[4], 1.0/tot.sca), |
673 |
> |
pow(fa.farg[5], 1.0/tot.sca), |
674 |
> |
pow(fa.farg[6], 1.0/tot.sca)); |
675 |
> |
printf(" %12.6g\n", fa.farg[7]); |
676 |
> |
freefargs(&fa); |
677 |
|
return(0); |
678 |
|
} |
679 |
|
|
680 |
|
|
681 |
< |
text(fin) /* transform text arguments */ |
682 |
< |
FILE *fin; |
681 |
> |
int |
682 |
> |
text( /* transform text arguments */ |
683 |
> |
FILE *fin |
684 |
> |
) |
685 |
|
{ |
686 |
|
int i; |
687 |
< |
double v[3]; |
688 |
< |
register FUNARGS *fa; |
687 |
> |
FVECT v; |
688 |
> |
FUNARGS fa; |
689 |
|
|
690 |
< |
if ((fa = getfargs(fin)) == NULL) |
690 |
> |
if (readfargs(&fa, fin) != 1) |
691 |
|
return(-1); |
692 |
< |
if (fa->niargs != 0 || (fa->nfargs != 9 && |
433 |
< |
fa->nfargs != 11 && fa->nfargs != 15)) |
692 |
> |
if (fa.nfargs < 9) |
693 |
|
return(-1); |
694 |
|
/* string arguments */ |
695 |
< |
printf("%d", fa->nsargs); |
696 |
< |
for (i = 0; i < fa->nsargs; i++) |
697 |
< |
printf(" %s", fa->sarg[i]); |
698 |
< |
printf("\n0\n%d\n", fa->nfargs); |
695 |
> |
printf("%d", fa.nsargs); |
696 |
> |
for (i = 0; i < fa.nsargs; i++) { |
697 |
> |
fputc(' ', stdout); |
698 |
> |
fputword(fa.sarg[i], stdout); |
699 |
> |
} |
700 |
> |
printf("\n0\n%d\n", fa.nfargs); |
701 |
|
/* anchor point */ |
702 |
< |
multp3(v, fa->farg, totxform); |
702 |
> |
multp3(v, fa.farg, tot.xfm); |
703 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
704 |
|
/* right vector */ |
705 |
< |
multv3(v, fa->farg+3, totxform); |
705 |
> |
multv3(v, fa.farg+3, tot.xfm); |
706 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
707 |
|
/* down vector */ |
708 |
< |
multv3(v, fa->farg+6, totxform); |
709 |
< |
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
710 |
< |
/* forground and background */ |
711 |
< |
if (fa->nfargs == 11) |
712 |
< |
printf(" %18.12g %18.12g\n", fa->farg[9], fa->farg[10]); |
713 |
< |
else if (fa->nfargs == 15) { |
714 |
< |
printf(" %18.12g %18.12g %18.12g\n", |
454 |
< |
fa->farg[9], fa->farg[10], fa->farg[11]); |
455 |
< |
printf(" %18.12g %18.12g %18.12g\n", |
456 |
< |
fa->farg[12], fa->farg[13], fa->farg[14]); |
708 |
> |
multv3(v, fa.farg+6, tot.xfm); |
709 |
> |
printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]); |
710 |
> |
/* remaining arguments */ |
711 |
> |
for (i = 9; i < fa.nfargs; i++) { |
712 |
> |
if (i%3 == 0) |
713 |
> |
putchar('\n'); |
714 |
> |
printf(" %18.12g", fa.farg[i]); |
715 |
|
} |
716 |
< |
freefargs(fa); |
716 |
> |
putchar('\n'); |
717 |
> |
freefargs(&fa); |
718 |
|
return(0); |
719 |
|
} |
720 |
|
|
721 |
|
|
722 |
< |
o_source(fin) /* transform source arguments */ |
723 |
< |
FILE *fin; |
722 |
> |
int |
723 |
> |
o_source( /* transform source arguments */ |
724 |
> |
FILE *fin |
725 |
> |
) |
726 |
|
{ |
727 |
< |
double dv[3]; |
728 |
< |
register FUNARGS *fa; |
727 |
> |
FVECT dv; |
728 |
> |
FUNARGS fa; |
729 |
|
|
730 |
< |
if ((fa = getfargs(fin)) == NULL) |
730 |
> |
if (readfargs(&fa, fin) != 1) |
731 |
|
return(-1); |
732 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
732 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
733 |
|
return(-1); |
734 |
|
/* transform direction vector */ |
735 |
< |
multv3(dv, fa->farg, totxform); |
735 |
> |
multv3(dv, fa.farg, tot.xfm); |
736 |
|
/* output */ |
737 |
|
printf("0\n0\n4"); |
738 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
739 |
< |
dv[0], dv[1], dv[2], fa->farg[3]); |
740 |
< |
freefargs(fa); |
739 |
> |
dv[0], dv[1], dv[2], fa.farg[3]); |
740 |
> |
freefargs(&fa); |
741 |
|
return(0); |
742 |
|
} |
743 |
|
|
744 |
|
|
745 |
< |
o_sphere(fin) /* transform sphere arguments */ |
746 |
< |
FILE *fin; |
745 |
> |
int |
746 |
> |
o_sphere( /* transform sphere arguments */ |
747 |
> |
FILE *fin |
748 |
> |
) |
749 |
|
{ |
750 |
< |
double cent[3], rad; |
751 |
< |
register FUNARGS *fa; |
750 |
> |
FVECT cent; |
751 |
> |
double rad; |
752 |
> |
FUNARGS fa; |
753 |
|
|
754 |
< |
if ((fa = getfargs(fin)) == NULL) |
754 |
> |
if (readfargs(&fa, fin) != 1) |
755 |
|
return(-1); |
756 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
756 |
> |
if (fa.nsargs != 0 || fa.nfargs != 4) |
757 |
|
return(-1); |
758 |
|
|
759 |
< |
multp3(cent, fa->farg, totxform); /* transform center */ |
759 |
> |
multp3(cent, fa.farg, tot.xfm); /* transform center */ |
760 |
|
|
761 |
< |
rad = fa->farg[3] * totscale; /* scale radius */ |
761 |
> |
rad = fa.farg[3] * tot.sca; /* scale radius */ |
762 |
|
|
763 |
|
printf("0\n0\n4"); |
764 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
765 |
|
cent[0], cent[1], cent[2], rad); |
766 |
< |
freefargs(fa); |
766 |
> |
freefargs(&fa); |
767 |
|
return(0); |
768 |
|
} |
769 |
|
|
770 |
|
|
771 |
< |
o_face(fin) /* transform face arguments */ |
772 |
< |
FILE *fin; |
771 |
> |
int |
772 |
> |
o_face( /* transform face arguments */ |
773 |
> |
FILE *fin |
774 |
> |
) |
775 |
|
{ |
776 |
< |
double p[3]; |
777 |
< |
register int i; |
778 |
< |
register FUNARGS *fa; |
776 |
> |
FVECT p; |
777 |
> |
int i; |
778 |
> |
FUNARGS fa; |
779 |
|
|
780 |
< |
if ((fa = getfargs(fin)) == NULL) |
780 |
> |
if (readfargs(&fa, fin) != 1) |
781 |
|
return(-1); |
782 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs % 3) |
782 |
> |
if (fa.nsargs != 0 || fa.nfargs % 3) |
783 |
|
return(-1); |
784 |
|
|
785 |
< |
printf("0\n0\n%d\n", fa->nfargs); |
785 |
> |
printf("0\n0\n%d\n", fa.nfargs); |
786 |
|
|
787 |
< |
for (i = 0; i < fa->nfargs; i += 3) { |
787 |
> |
for (i = 0; i < fa.nfargs; i += 3) { |
788 |
|
if (reverse) |
789 |
< |
multp3(p, fa->farg+(fa->nfargs-i-3), totxform); |
789 |
> |
multp3(p, fa.farg+(fa.nfargs-i-3), tot.xfm); |
790 |
|
else |
791 |
< |
multp3(p, fa->farg+i, totxform); |
791 |
> |
multp3(p, fa.farg+i, tot.xfm); |
792 |
|
printf(" %18.12g %18.12g %18.12g\n", p[0], p[1], p[2]); |
793 |
|
} |
794 |
< |
freefargs(fa); |
794 |
> |
freefargs(&fa); |
795 |
|
return(0); |
796 |
|
} |
797 |
|
|
798 |
|
|
799 |
< |
o_cone(fin) /* transform cone and cup arguments */ |
800 |
< |
FILE *fin; |
799 |
> |
int |
800 |
> |
o_cone( /* transform cone and cup arguments */ |
801 |
> |
FILE *fin |
802 |
> |
) |
803 |
|
{ |
804 |
< |
double p0[3], p1[3], r0, r1; |
805 |
< |
register FUNARGS *fa; |
804 |
> |
FVECT p0, p1; |
805 |
> |
double r0, r1; |
806 |
> |
FUNARGS fa; |
807 |
|
|
808 |
< |
if ((fa = getfargs(fin)) == NULL) |
808 |
> |
if (readfargs(&fa, fin) != 1) |
809 |
|
return(-1); |
810 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
810 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
811 |
|
return(-1); |
812 |
|
|
813 |
|
printf("0\n0\n8\n"); |
814 |
|
|
815 |
< |
multp3(p0, fa->farg, totxform); |
816 |
< |
multp3(p1, fa->farg+3, totxform); |
817 |
< |
r0 = fa->farg[6] * totscale; |
818 |
< |
r1 = fa->farg[7] * totscale; |
815 |
> |
multp3(p0, fa.farg, tot.xfm); |
816 |
> |
multp3(p1, fa.farg+3, tot.xfm); |
817 |
> |
r0 = fa.farg[6] * tot.sca; |
818 |
> |
r1 = fa.farg[7] * tot.sca; |
819 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
820 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
821 |
|
printf(" %18.12g %18.12g\n", r0, r1); |
822 |
|
|
823 |
< |
freefargs(fa); |
823 |
> |
freefargs(&fa); |
824 |
|
return(0); |
825 |
|
} |
826 |
|
|
827 |
|
|
828 |
< |
o_cylinder(fin) /* transform cylinder and tube arguments */ |
829 |
< |
FILE *fin; |
828 |
> |
int |
829 |
> |
o_cylinder( /* transform cylinder and tube arguments */ |
830 |
> |
FILE *fin |
831 |
> |
) |
832 |
|
{ |
833 |
< |
double p0[3], p1[3], rad; |
834 |
< |
register FUNARGS *fa; |
833 |
> |
FVECT p0, p1; |
834 |
> |
double rad; |
835 |
> |
FUNARGS fa; |
836 |
|
|
837 |
< |
if ((fa = getfargs(fin)) == NULL) |
837 |
> |
if (readfargs(&fa, fin) != 1) |
838 |
|
return(-1); |
839 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 7) |
839 |
> |
if (fa.nsargs != 0 || fa.nfargs != 7) |
840 |
|
return(-1); |
841 |
|
|
842 |
|
printf("0\n0\n7\n"); |
843 |
|
|
844 |
< |
multp3(p0, fa->farg, totxform); |
845 |
< |
multp3(p1, fa->farg+3, totxform); |
846 |
< |
rad = fa->farg[6] * totscale; |
844 |
> |
multp3(p0, fa.farg, tot.xfm); |
845 |
> |
multp3(p1, fa.farg+3, tot.xfm); |
846 |
> |
rad = fa.farg[6] * tot.sca; |
847 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
848 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
849 |
|
printf(" %18.12g\n", rad); |
850 |
< |
freefargs(fa); |
850 |
> |
freefargs(&fa); |
851 |
|
return(0); |
852 |
|
} |
853 |
|
|
854 |
|
|
855 |
< |
o_ring(fin) /* transform ring arguments */ |
856 |
< |
FILE *fin; |
855 |
> |
int |
856 |
> |
o_ring( /* transform ring arguments */ |
857 |
> |
FILE *fin |
858 |
> |
) |
859 |
|
{ |
860 |
< |
double p0[3], pd[3], r0, r1; |
861 |
< |
register FUNARGS *fa; |
860 |
> |
FVECT p0, pd; |
861 |
> |
double r0, r1; |
862 |
> |
FUNARGS fa; |
863 |
|
|
864 |
< |
if ((fa = getfargs(fin)) == NULL) |
864 |
> |
if (readfargs(&fa, fin) != 1) |
865 |
|
return(-1); |
866 |
< |
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 8) |
866 |
> |
if (fa.nsargs != 0 || fa.nfargs != 8) |
867 |
|
return(-1); |
868 |
|
|
869 |
|
printf("0\n0\n8\n"); |
870 |
|
|
871 |
< |
multp3(p0, fa->farg, totxform); |
872 |
< |
multv3(pd, fa->farg+3, totxform); |
873 |
< |
r0 = fa->farg[6] * totscale; |
874 |
< |
r1 = fa->farg[7] * totscale; |
871 |
> |
multp3(p0, fa.farg, tot.xfm); |
872 |
> |
multv3(pd, fa.farg+3, tot.xfm); |
873 |
> |
if (invert) { |
874 |
> |
pd[0] = -pd[0]; |
875 |
> |
pd[1] = -pd[1]; |
876 |
> |
pd[2] = -pd[2]; |
877 |
> |
} |
878 |
> |
r0 = fa.farg[6] * tot.sca; |
879 |
> |
r1 = fa.farg[7] * tot.sca; |
880 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
881 |
|
printf(" %18.12g %18.12g %18.12g\n", pd[0], pd[1], pd[2]); |
882 |
|
printf(" %18.12g %18.12g\n", r0, r1); |
883 |
< |
freefargs(fa); |
883 |
> |
freefargs(&fa); |
884 |
|
return(0); |
885 |
|
} |
886 |
|
|
887 |
|
|
888 |
< |
FUNARGS * |
889 |
< |
getfargs(fp) /* get function arguments from stream */ |
610 |
< |
FILE *fp; |
888 |
> |
void |
889 |
> |
initotypes(void) /* initialize ofun[] array */ |
890 |
|
{ |
891 |
< |
char *strcpy(); |
613 |
< |
char sbuf[MAXSTR]; |
614 |
< |
int n; |
615 |
< |
register FUNARGS *fa; |
616 |
< |
register int i; |
891 |
> |
int i; |
892 |
|
|
893 |
< |
if ((fa = (FUNARGS *)malloc((unsigned)sizeof(FUNARGS))) == NULL) |
894 |
< |
goto memerr; |
895 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
896 |
< |
return(NULL); |
897 |
< |
if (fa->nsargs = n) { |
898 |
< |
fa->sarg = (char **)malloc((unsigned)fa->nsargs*sizeof(char *)); |
899 |
< |
if (fa->sarg == NULL) |
900 |
< |
goto memerr; |
901 |
< |
for (i = 0; i < fa->nsargs; i++) { |
902 |
< |
if (fscanf(fp, "%s", sbuf) != 1) |
903 |
< |
return(NULL); |
904 |
< |
if ((fa->sarg[i] = malloc((unsigned)strlen(sbuf)+1)) == NULL) |
905 |
< |
goto memerr; |
906 |
< |
strcpy(fa->sarg[i], sbuf); |
907 |
< |
} |
908 |
< |
} else |
909 |
< |
fa->sarg = NULL; |
910 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
911 |
< |
return(NULL); |
912 |
< |
if (fa->niargs = n) { |
913 |
< |
fa->iarg = (int *)malloc((unsigned)fa->niargs*sizeof(int)); |
914 |
< |
if (fa->iarg == NULL) |
915 |
< |
goto memerr; |
916 |
< |
for (i = 0; i < fa->niargs; i++) |
917 |
< |
if (fscanf(fp, "%d", &fa->iarg[i]) != 1) |
918 |
< |
return(NULL); |
919 |
< |
} else |
920 |
< |
fa->iarg = NULL; |
921 |
< |
if (fscanf(fp, "%d", &n) != 1 || n < 0) |
922 |
< |
return(NULL); |
923 |
< |
if (fa->nfargs = n) { |
924 |
< |
fa->farg = (double *)malloc((unsigned)fa->nfargs*sizeof(double)); |
925 |
< |
if (fa->farg == NULL) |
926 |
< |
goto memerr; |
927 |
< |
for (i = 0; i < fa->nfargs; i++) |
928 |
< |
if (fscanf(fp, "%lf", &fa->farg[i]) != 1) |
929 |
< |
return(NULL); |
930 |
< |
} else |
931 |
< |
fa->farg = NULL; |
657 |
< |
return(fa); |
658 |
< |
memerr: |
659 |
< |
fprintf(stderr, "%s: out of memory in getfargs\n", progname); |
660 |
< |
exit(1); |
893 |
> |
if (ofun[OBJ_SOURCE].funp == o_source) |
894 |
> |
return; /* done already */ |
895 |
> |
/* functions get new transform */ |
896 |
> |
for (i = 0; i < NUMOTYPE; i++) |
897 |
> |
if (hasfunc(i)) |
898 |
> |
ofun[i].funp = addxform; |
899 |
> |
/* special cases */ |
900 |
> |
ofun[OBJ_SOURCE].funp = o_source; |
901 |
> |
ofun[OBJ_SPHERE].funp = |
902 |
> |
ofun[OBJ_BUBBLE].funp = o_sphere; |
903 |
> |
ofun[OBJ_FACE].funp = o_face; |
904 |
> |
ofun[OBJ_CONE].funp = |
905 |
> |
ofun[OBJ_CUP].funp = o_cone; |
906 |
> |
ofun[OBJ_CYLINDER].funp = |
907 |
> |
ofun[OBJ_TUBE].funp = o_cylinder; |
908 |
> |
ofun[OBJ_RING].funp = o_ring; |
909 |
> |
ofun[OBJ_INSTANCE].funp = |
910 |
> |
ofun[OBJ_MESH].funp = addxform; |
911 |
> |
ofun[MAT_GLOW].funp = m_glow; |
912 |
> |
ofun[MAT_SPOT].funp = m_spot; |
913 |
> |
ofun[MAT_DIELECTRIC].funp = m_dielectric; |
914 |
> |
ofun[MAT_INTERFACE].funp = m_interface; |
915 |
> |
ofun[MAT_MIST].funp = m_mist; |
916 |
> |
ofun[PAT_CTEXT].funp = |
917 |
> |
ofun[PAT_BTEXT].funp = |
918 |
> |
ofun[MIX_TEXT].funp = text; |
919 |
> |
ofun[MOD_ALIAS].funp = alias; |
920 |
> |
/* surface inverses */ |
921 |
> |
tinvers[OBJ_FACE] = OBJ_FACE; |
922 |
> |
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
923 |
> |
tinvers[OBJ_CONE] = OBJ_CUP; |
924 |
> |
tinvers[OBJ_CUP] = OBJ_CONE; |
925 |
> |
tinvers[OBJ_SPHERE] = OBJ_BUBBLE; |
926 |
> |
tinvers[OBJ_BUBBLE] = OBJ_SPHERE; |
927 |
> |
tinvers[OBJ_RING] = OBJ_RING; |
928 |
> |
tinvers[OBJ_CYLINDER] = OBJ_TUBE; |
929 |
> |
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
930 |
> |
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
931 |
> |
tinvers[OBJ_MESH] = OBJ_MESH; /* ditto */ |
932 |
|
} |
933 |
|
|
934 |
|
|
935 |
< |
freefargs(fa) /* free memory associated with fa */ |
936 |
< |
register FUNARGS *fa; |
935 |
> |
#ifdef OLDXFORM |
936 |
> |
void |
937 |
> |
openmain( |
938 |
> |
char *fname |
939 |
> |
) |
940 |
|
{ |
941 |
< |
register int i; |
941 |
> |
if (fname == NULL) { |
942 |
> |
strcpy(mainfn, "standard input"); |
943 |
> |
mainfp = stdin; |
944 |
> |
return; |
945 |
> |
} |
946 |
> |
if (mainfp != NULL) { |
947 |
> |
if (!strcmp(fname, mainfn)) { |
948 |
> |
rewind(mainfp); |
949 |
> |
return; |
950 |
> |
} |
951 |
> |
fclose(mainfp); |
952 |
> |
} |
953 |
> |
if ((mainfp = fopen(fname, "r")) == NULL) { |
954 |
> |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
955 |
> |
progname, fname); |
956 |
> |
exit(1); |
957 |
> |
} |
958 |
> |
strcpy(mainfn, fname); |
959 |
> |
} |
960 |
> |
#else |
961 |
> |
void |
962 |
> |
openmain( /* open input, changing directory for file */ |
963 |
> |
char *iname |
964 |
> |
) |
965 |
> |
{ |
966 |
> |
static char origdir[PATH_MAX]; |
967 |
> |
static char curfn[PATH_MAX]; |
968 |
> |
static int diffdir; |
969 |
> |
char *fpath; |
970 |
|
|
971 |
< |
for (i = 0; i < fa->nsargs; i++) |
972 |
< |
free(fa->sarg[i]); |
973 |
< |
if (fa->nsargs) |
974 |
< |
free(fa->sarg); |
975 |
< |
if (fa->niargs) |
976 |
< |
free(fa->iarg); |
977 |
< |
if (fa->nfargs) |
978 |
< |
free(fa->farg); |
979 |
< |
free(fa); |
971 |
> |
if (iname == NULL) { /* standard input */ |
972 |
> |
if (mainfp == NULL) { |
973 |
> |
int c; |
974 |
> |
strcpy(mainfn, "standard input"); |
975 |
> |
if (nrept <= 1) { |
976 |
> |
mainfp = stdin; |
977 |
> |
return; /* just read once */ |
978 |
> |
} |
979 |
> |
/* else copy */ |
980 |
> |
if ((mainfp = tmpfile()) == NULL) { |
981 |
> |
fprintf(stderr, |
982 |
> |
"%s: cannot create temporary file\n", |
983 |
> |
progname); |
984 |
> |
exit(1); |
985 |
> |
} |
986 |
> |
while ((c = getc(stdin)) != EOF) |
987 |
> |
putc(c, mainfp); |
988 |
> |
} |
989 |
> |
rewind(mainfp); /* rewind copy */ |
990 |
> |
return; |
991 |
> |
} |
992 |
> |
if (mainfp == NULL) { /* first call, initialize */ |
993 |
> |
getcwd(origdir, sizeof(origdir)); |
994 |
> |
} else if (!strcmp(iname, curfn)) { /* just need to rewind? */ |
995 |
> |
rewind(mainfp); |
996 |
> |
return; |
997 |
> |
} else { /* else close old stream */ |
998 |
> |
fclose(mainfp); |
999 |
> |
mainfp = NULL; |
1000 |
> |
if (diffdir) { /* return to our directory */ |
1001 |
> |
chdir(origdir); |
1002 |
> |
diffdir = 0; |
1003 |
> |
} |
1004 |
> |
} |
1005 |
> |
strcpy(curfn, iname); /* remember input name */ |
1006 |
> |
/* get full path for file */ |
1007 |
> |
if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) { |
1008 |
> |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
1009 |
> |
progname, iname); |
1010 |
> |
exit(1); |
1011 |
> |
} |
1012 |
> |
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
1013 |
> |
fpath += 2; |
1014 |
> |
/* record path name */ |
1015 |
> |
strcpy(mainfn, fpath); |
1016 |
> |
if (expand) { /* change to local directory */ |
1017 |
> |
char *cp = fpath + strlen(fpath); /* get dir. */ |
1018 |
> |
while (cp > fpath) { |
1019 |
> |
cp--; |
1020 |
> |
if (ISDIRSEP(*cp)) { |
1021 |
> |
if (cp == fpath) |
1022 |
> |
cp++; /* root special case */ |
1023 |
> |
break; |
1024 |
> |
} |
1025 |
> |
} |
1026 |
> |
*cp = '\0'; |
1027 |
> |
if (fpath[0]) { /* change to new directory? */ |
1028 |
> |
if (chdir(fpath) < 0) { |
1029 |
> |
fprintf(stderr, |
1030 |
> |
"%s: cannot change directory to \"%s\"\n", |
1031 |
> |
progname, fpath); |
1032 |
> |
exit(1); |
1033 |
> |
} |
1034 |
> |
diffdir++; |
1035 |
> |
} |
1036 |
> |
/* get final path component */ |
1037 |
> |
for (fpath = iname+strlen(iname); |
1038 |
> |
fpath > iname && !ISDIRSEP(fpath[-1]); fpath--) |
1039 |
> |
; |
1040 |
> |
} |
1041 |
> |
/* finally, open the file */ |
1042 |
> |
if ((mainfp = fopen(fpath, "r")) == NULL) { |
1043 |
> |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
1044 |
> |
progname, mainfn); |
1045 |
> |
exit(1); |
1046 |
> |
} |
1047 |
|
} |
1048 |
+ |
#endif |