ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/xform.c
(Generate patch)

Comparing ray/src/gen/xform.c (file contents):
Revision 1.16 by greg, Tue Oct 22 13:32:58 1991 UTC vs.
Revision 2.53 by greg, Tue Apr 22 14:51:29 2025 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  xform.c - program to transform object files.
6   *              Transformations must preserve aspect ratio.
# Line 12 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   *     11/6/86          Finally added error checking!
10   */
11  
15 #include  "standard.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"
20
19   #include  "otypes.h"
20  
21   int  xac;                               /* global xform argument count */
# Line 27 | Line 25 | int  xfa;                              /* start of xf arguments */
25   XF  tot;                                /* total transformation */
26   int  reverse;                           /* boolean true if scene mirrored */
27  
28 < int  invert = 0;                        /* boolean true to invert surfaces */
28 > int  invert;                            /* boolean true to invert surfaces */
29  
30 < int  expand = 0;                        /* boolean true to expand commands */
30 > int  expand;                            /* boolean true to expand commands */
31  
32 < char  *newmod = NULL;                   /* new modifier for surfaces */
32 > char  *newmod;                          /* new modifier for surfaces */
33  
34 < char  *idprefix = NULL;                 /* prefix for object identifiers */
34 > char  *idprefix;                        /* prefix for object identifiers */
35  
36 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
36 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
37  
38 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
38 > short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
39  
40 < FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
40 > int  nrept = 1;                         /* number of array repetitions */
41  
42 < short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
42 > int stdinused = 0;                      /* stdin has been used by -f option? */
43  
44 < extern char  *malloc(), *fgetword();
44 > char  mainfn[PATH_MAX];                 /* main file name */
45 > FILE  *mainfp = NULL;                   /* main file pointer */
46  
47 < #define  progname  (xav[0])
47 > #define  progname  (xav[0])
48  
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 < main(argc, argv)                /* get transform options and transform file */
60 < int  argc;
61 < char  *argv[];
59 >
60 > int
61 > main(           /* get transform options and transform file */
62 >        int  argc,
63 >        char  *argv[]
64 > )
65   {
66 <        FILE  *fopen();
56 <        FILE  *fp;
66 >        int  mal_prefix = 0;
67          int  a;
68 <                                        /* check for array */
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 <        initotypes();
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)
87 >                                if (argv[a][2] | (a+1 >= argc))
88                                          break;
89 <                                newmod = argv[++a];
89 >                                a++;
90 >                                if (newmod == NULL)
91 >                                        newmod = argv[a];
92                                  continue;
93                          case 'n':
94 <                                if (argv[a][2] || a+1 >= argc)
94 >                                if (argv[a][2] | (a+1 >= argc))
95                                          break;
96 <                                idprefix = argv[++a];
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;
# Line 83 | Line 122 | char  *argv[];
122                          case 'I':
123                                  if (argv[a][2])
124                                          break;
125 <                                invert = 1;
125 >                                invert = !invert;
126                                  continue;
127                          }
128                  break;
# Line 94 | Line 133 | char  *argv[];
133  
134          a += xf(&tot, argc-a, argv+a);
135  
136 <        if (reverse = tot.sca < 0.0)
136 >        if ( (reverse = (tot.sca < 0.0)) )
137                  tot.sca = -tot.sca;
138          if (invert)
139                  reverse = !reverse;
# Line 112 | Line 151 | char  *argv[];
151                  printf(" %s", xav[a]);
152          putchar('\n');
153                                          /* transform input */
154 <        if (xac == argc)
155 <                xform("standard input", stdin);
156 <        else
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 <                        if ((fp = fopen(argv[a], "r")) == NULL) {
165 <                                fprintf(stderr, "%s: cannot open \"%s\"\n",
121 <                                                progname, argv[a]);
122 <                                exit(1);
123 <                        }
124 <                        xform(argv[a], fp);
125 <                        fclose(fp);
164 >                        openmain(argv[a]);
165 >                        xform(mainfn, mainfp);
166                  }
167  
168 +        if (mal_prefix)
169 +                free(idprefix);
170          return(0);
171   }
172  
173  
174 < doarray(ac, av, ai)                     /* make array */
175 < char  **av;
176 < int  ac, ai;
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] != '\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 +                rewind(argfp);
219 +        }
220 +        nrept *= n;
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 +                        printf("%s\n", argbuf);
225 +                        continue;
226 +                }
227 +                avp = newav+2;
228 +                avp[0] = av[0];
229 +                for (i = 1; i < fi; i++)
230 +                        avp[i] = av[i];
231 +                newac = i;
232 +                cp = argbuf;            /* parse new words */
233 +                if (*cp == '!') cp++;
234 +                if (!strncmp(cp, "xform ", 6)) cp += 6;
235 +                inquote = 0;
236 +                for ( ; ; ) {
237 +                skipspaces:
238 +                        while (isspace(*cp))    /* nullify spaces */
239 +                                *cp++ = '\0';
240 +                        if ((*cp == '"') | (*cp == '\''))
241 +                                inquote = *cp++;
242 +                        if (!*cp)               /* all done? */
243 +                                break;
244 +                        if (cp[0] == '\\' && cp[1])
245 +                                if (*++cp == '\n')
246 +                                        goto skipspaces;
247 +                        avp[newac++] = cp;      /* add argument to list */
248 +                        if (inquote) {
249 +                                while (*++cp)
250 +                                        if (*cp == inquote) {
251 +                                                *cp++ = '\0';
252 +                                                break;
253 +                                        }
254 +                        } else {
255 +                                while (*++cp && !isspace(*cp))
256 +                                        ;
257 +                        }
258 +                }
259 +                for (i = fi+2; i < ac; i++)
260 +                        avp[newac++] = av[i];
261 +                avp[newac] = NULL;
262 +                newid = newidbuf;
263 +                oldid = NULL;
264 +                for (i = 2; i < newac; i++)
265 +                        if (!strcmp(avp[i-1], "-n")) {
266 +                                oldid = avp[i];
267 +                                if (strlen(oldid)+32 > sizeof(newidbuf)) {
268 +                                        newid = (char *)malloc(strlen(oldid)+32);
269 +                                        if (newid == NULL)
270 +                                                exit(2);
271 +                                }
272 +                                avp[i] = newid;
273 +                                break;
274 +                        }
275 +                if (oldid == NULL) {
276 +                        newav[0] = av[0];
277 +                        newav[1] = "-n";
278 +                        newav[2] = newid;
279 +                        avp = newav;
280 +                        newac += 2;
281 +                }
282 +                if (oldid == NULL)
283 +                        sprintf(newid, "i%d", k);
284 +                else
285 +                        sprintf(newid, "%s.%d", oldid, k);
286 +                err |= main(newac, avp);
287 +                if (newid != newidbuf)
288 +                        free(newid);
289 +                k++;
290 +        }
291 +        fclose(argfp);
292 +        return(err);
293 + }
294 +
295 +
296 + int
297 + doarray(                        /* make array */
298 +        int  ac,
299 +        char  **av,
300 +        int  ai
301 + )
302 + {
303 +        char  *newav[256], **avp;
304          char  newid[128], repts[32];
305          char  *oldid = NULL;
306 <        int  i, err;
306 >        int  n, i, err;
307          
308 +        if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) {
309 +                fprintf(stderr, "%s: missing count for -a option\n", av[0]);
310 +                exit(1);
311 +        }
312 +        nrept *= n;
313          avp = newav+2;
314          avp[0] = av[0];
315          for (i = 1; i < ac; i++)
# Line 157 | Line 329 | int  ac, ai;
329                  ac += 2;
330          }
331          err = 0;
332 <        for (i = 0; i < atoi(av[ai+1]); i++) {
332 >        for (i = 0; i < n; i++) {
333                  if (oldid == NULL)
334                          sprintf(newid, "a%d", i);
335                  else
# Line 169 | Line 341 | int  ac, ai;
341   }
342  
343  
344 < xform(name, fin)                        /* transform stream by tot.xfm */
345 < char  *name;
346 < register FILE  *fin;
344 > void
345 > xform(                  /* transform stream by tot.xfm */
346 >        char  *name,
347 >        FILE  *fin
348 > )
349   {
350 <        register int  c;
350 >        int  nobjs = 0;
351 >        int  c;
352  
353          while ((c = getc(fin)) != EOF) {
354                  if (isspace(c))                         /* blank */
# Line 188 | Line 363 | register FILE  *fin;
363                  } else if (c == '!') {                  /* command */
364                          ungetc(c, fin);
365                          xfcomm(name, fin);
366 +                        nobjs++;
367                  } else {                                /* object */
368                          ungetc(c, fin);
369                          xfobject(name, fin);
370 +                        nobjs++;
371                  }
372          }
373 +        if (nobjs == 0)
374 +                fprintf(stderr, "%s: (%s): warning - empty file\n",
375 +                                progname, name);
376   }
377  
378  
379 < xfcomm(fname, fin)                      /* transform a command */
380 < FILE  *fin;
379 > void
380 > xfcomm(                 /* transform a command */
381 >        char  *fname,
382 >        FILE  *fin
383 > )
384   {
202        FILE  *popen();
203        char  *fgetline();
385          FILE  *pin;
386 <        char  buf[512];
386 >        char  buf[2048];
387          int  i;
388  
389          fgetline(buf, sizeof(buf), fin);
390          if (expand) {
391 <                if (xac > 2) {
392 <                        if ((pin = popen(buf+1, "r")) == NULL) {
393 <                                fprintf(stderr,
394 <                                "%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);
391 >                if ((pin = popen(buf+1, "r")) == NULL) {
392 >                        fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n",
393 >                                        progname, fname, buf);
394 >                        exit(1);
395                  }
396 +                xform(buf, pin);
397 +                if (pclose(pin) != 0)
398 +                        fprintf(stderr, "%s: (%s): warning - bad status from \"%s\"\n",
399 +                                        progname, fname, buf);
400          } else {
401                  printf("\n%s", buf);
402                  if (xac > 1) {
403 <                        printf(" | %s -e", xav[0]);
403 >                        printf(" | %s -e", xav[0]);     /* expand next time */
404                          for (i = 1; i < xac; i++)
405 <                                printf(" %s", xav[i]);
405 >                                if (i >= xfa || strcmp(xav[i], "-c"))
406 >                                        printf(" %s", xav[i]);
407                  }
408                  putchar('\n');
409          }
410   }
411  
412  
413 < xfobject(fname, fin)                            /* transform an object */
414 < char  *fname;
415 < FILE  *fin;
413 > void
414 > xfobject(                               /* transform an object */
415 >        char  *fname,
416 >        FILE  *fin
417 > )
418   {
239        extern char  *strcpy();
419          char  typ[16], nam[MAXSTR];
420          int  fn;
421                                                  /* modifier and type */
# Line 248 | Line 427 | FILE  *fin;
427                                  progname, fname, typ);
428                  exit(1);
429          }
430 <        if (issurface(fn))
431 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
432 <                                invert ? ofun[tinvers[fn]].funame : typ);
433 <        else
434 <                printf("\n%s %s ", nam, typ);
430 >        putchar('\n');
431 >        if (ismodifier(fn)) {
432 >                fputword(nam, stdout);
433 >                printf(" %s ", typ);
434 >        } else {
435 >                fputword(newmod != NULL ? newmod : nam, stdout);
436 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
437 >        }
438                                                  /* object name */
439          fgetword(nam, sizeof(nam), fin);
440 <        if (idprefix != NULL && issurface(fn))
441 <                printf("%s.%s\n", idprefix, nam);
442 <        else
443 <                printf("%s\n", nam);
440 >        if (idprefix == NULL || ismodifier(fn))
441 >                fputword(nam, stdout);
442 >        else {
443 >                char    nnam[MAXSTR];
444 >                sprintf(nnam, "%s.%s", idprefix, nam);
445 >                fputword(nnam, stdout);
446 >        }
447 >        putchar('\n');
448                                                  /* transform arguments */
449          if ((*ofun[fn].funp)(fin) < 0) {
450                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 268 | Line 454 | FILE  *fin;
454   }
455  
456  
457 < o_default(fin)                  /* pass on arguments unchanged */
458 < FILE  *fin;
457 > int
458 > o_default(                      /* pass on arguments unchanged */
459 >        FILE  *fin
460 > )
461   {
462 <        register int  i;
463 <        FUNARGS  fa;
462 >        int  i;
463 >        FUNARGS  fa;
464  
465          if (readfargs(&fa, fin) != 1)
466                  return(-1);
467                                          /* string arguments */
468          printf("%d", fa.nsargs);
469 <        for (i = 0; i < fa.nsargs; i++)
470 <                printf(" %s", fa.sarg[i]);
469 >        for (i = 0; i < fa.nsargs; i++) {
470 >                fputc(' ', stdout);
471 >                fputword(fa.sarg[i], stdout);
472 >        }
473          printf("\n");
474 < #ifdef  IARGS
474 > #ifdef  IARGS
475                                          /* integer arguments */
476          printf("%d", fa.niargs);
477          for (i = 0; i < fa.niargs; i++)
# Line 300 | Line 490 | FILE  *fin;
490   }
491  
492  
493 < addxform(fin)                   /* add xf arguments to strings */
494 < FILE  *fin;
493 > int
494 > addxform(                       /* add xf arguments to strings */
495 >        FILE  *fin
496 > )
497   {
498 <        register int  i;
499 <        FUNARGS  fa;
498 >        int  i;
499 >        int  resetarr = 0;
500 >        FUNARGS  fa;
501  
502          if (readfargs(&fa, fin) != 1)
503                  return(-1);
504                                          /* string arguments */
505 <        printf("%d", fa.nsargs + xac-xfa);
506 <        for (i = 0; i < fa.nsargs; i++)
507 <                printf(" %s", fa.sarg[i]);
505 >        if (xac > xfa && strcmp(xav[xfa], "-i"))
506 >                resetarr = 2;
507 >        printf("%d", fa.nsargs + resetarr + xac-xfa);
508 >        for (i = 0; i < fa.nsargs; i++) {
509 >                fputc(' ', stdout);
510 >                fputword(fa.sarg[i], stdout);
511 >        }
512 >        if (resetarr)
513 >                printf(" -i 1");
514          for (i = xfa; i < xac; i++)     /* add xf arguments */
515                  printf(" %s", xav[i]);
516          printf("\n");
517 < #ifdef  IARGS
517 > #ifdef  IARGS
518                                          /* integer arguments */
519          printf("%d", fa.niargs);
520          for (i = 0; i < fa.niargs; i++)
# Line 335 | Line 534 | FILE  *fin;
534  
535  
536   int
537 < otype(ofname)                   /* get object function number from its name */
538 < register char  *ofname;
537 > alias(                  /* transfer alias */
538 >        FILE  *fin
539 > )
540   {
341        register int  i;
342
343        for (i = 0; i < NUMTYPES; i++)
344                if (!strcmp(ofun[i].funame, ofname))
345                        return(i);
346
347        return(-1);             /* not found */
348 }
349
350
351 alias(fin)                      /* transfer alias */
352 FILE  *fin;
353 {
541          char  aliasnm[MAXSTR];
542  
543          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 360 | Line 547 | FILE  *fin;
547   }
548  
549  
550 < m_glow(fin)                     /* transform arguments for proximity light */
551 < FILE  *fin;
550 > int
551 > m_glow(                 /* transform arguments for proximity light */
552 >        FILE  *fin
553 > )
554   {
555 <        FUNARGS  fa;
555 >        FUNARGS  fa;
556  
557          if (readfargs(&fa, fin) != 1)
558                  return(-1);
559 <        if (fa.nsargs != 0  || fa.nfargs != 4)
559 >        if ((fa.nsargs != 0) | (fa.nfargs != 4))
560                  return(-1);
561          printf("0\n0\n4");
562          printf(" %18.12g %18.12g %18.12g",
# Line 378 | Line 567 | FILE  *fin;
567   }
568  
569  
570 < m_spot(fin)                     /* transform arguments for spotlight */
571 < FILE  *fin;
570 > int
571 > m_spot(                 /* transform arguments for spotlight */
572 >        FILE  *fin
573 > )
574   {
575 <        double  v[3];
576 <        FUNARGS  fa;
575 >        FVECT  v;
576 >        FUNARGS  fa;
577  
578          if (readfargs(&fa, fin) != 1)
579                  return(-1);
580 <        if (fa.nsargs != 0  || fa.nfargs != 7)
580 >        if ((fa.nsargs != 0) | ( fa.nfargs != 7))
581                  return(-1);
582          printf("0\n0\n7");
583          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 398 | Line 589 | FILE  *fin;
589   }
590  
591  
592 < m_dielectric(fin)               /* transform arguments for dielectric */
593 < FILE  *fin;
592 > int
593 > m_mist(         /* transform arguments for mist */
594 >        FILE  *fin
595 > )
596   {
597 <        double  pow();
598 <        FUNARGS  fa;
597 >        FUNARGS  fa;
598 >        int     i;
599  
600          if (readfargs(&fa, fin) != 1)
601                  return(-1);
602 +        if (fa.nfargs > 7)
603 +                return(-1);
604 +        printf("%d", fa.nsargs);
605 +        if (idprefix == NULL)
606 +                for (i = 0; i < fa.nsargs; i++)
607 +                        printf(" %s", fa.sarg[i]);
608 +        else
609 +                for (i = 0; i < fa.nsargs; i++) {
610 +                        char    sname[256], *sp;
611 +                        char    *cp1, *cp2 = sname;
612 +                                                        /* add idprefix */
613 +                        for (sp = fa.sarg[i]; *sp; sp = cp1) {
614 +                                for (cp1 = idprefix; *cp1; )
615 +                                        *cp2++ = *cp1++;
616 +                                *cp2++ = '.';
617 +                                for (cp1 = sp; *cp1 &&
618 +                                                (*cp2++ = *cp1++) != '>'; )
619 +                                        ;
620 +                        }
621 +                        *cp2 = '\0';
622 +                        printf(" %s", sname);
623 +                }
624 +        printf("\n0\n%d", fa.nfargs);
625 +        if (fa.nfargs > 2)
626 +                printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
627 +                                fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
628 +        for (i = 3; i < fa.nfargs; i++)
629 +                printf(" %12.6g", fa.farg[i]);
630 +        printf("\n");
631 +        freefargs(&fa);
632 +        return(0);
633 + }
634 +
635 +
636 + int
637 + m_dielectric(           /* transform arguments for dielectric */
638 +        FILE  *fin
639 + )
640 + {
641 +        FUNARGS  fa;
642 +
643 +        if (readfargs(&fa, fin) != 1)
644 +                return(-1);
645          if (fa.nsargs != 0  || fa.nfargs != 5)
646                  return(-1);
647          printf("0\n0\n5");
648 <        printf(" %18.12g %18.12g %18.12g",
648 >        printf(" %12.6g %12.6g %12.6g",
649                  pow(fa.farg[0], 1.0/tot.sca),
650                  pow(fa.farg[1], 1.0/tot.sca),
651                  pow(fa.farg[2], 1.0/tot.sca));
652 <        printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]);
652 >        printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]);
653          freefargs(&fa);
654          return(0);
655   }
656  
657  
658 < m_interface(fin)                /* transform arguments for interface */
659 < FILE  *fin;
658 > int
659 > m_interface(            /* transform arguments for interface */
660 >        FILE  *fin
661 > )
662   {
663 <        double  pow();
426 <        FUNARGS  fa;
663 >        FUNARGS  fa;
664  
665          if (readfargs(&fa, fin) != 1)
666                  return(-1);
667          if (fa.nsargs != 0  || fa.nfargs != 8)
668                  return(-1);
669          printf("0\n0\n8\n");
670 <        printf("%18.12g %18.12g %18.12g",
670 >        printf("%12.6g %12.6g %12.6g",
671                  pow(fa.farg[0], 1.0/tot.sca),
672                  pow(fa.farg[1], 1.0/tot.sca),
673                  pow(fa.farg[2], 1.0/tot.sca));
674 <        printf(" %18.12g\n", fa.farg[3]);
675 <        printf("%18.12g %18.12g %18.12g",
674 >        printf(" %12.6g\n", fa.farg[3]);
675 >        printf("%12.6g %12.6g %12.6g",
676                  pow(fa.farg[4], 1.0/tot.sca),
677                  pow(fa.farg[5], 1.0/tot.sca),
678                  pow(fa.farg[6], 1.0/tot.sca));
679 <        printf(" %18.12g\n", fa.farg[7]);
679 >        printf(" %12.6g\n", fa.farg[7]);
680          freefargs(&fa);
681          return(0);
682   }
683  
684  
685 < text(fin)                       /* transform text arguments */
686 < FILE  *fin;
685 > int
686 > text(                   /* transform text arguments */
687 >        FILE  *fin
688 > )
689   {
690          int  i;
691 <        double  v[3];
692 <        FUNARGS  fa;
691 >        FVECT  v;
692 >        FUNARGS  fa;
693  
694          if (readfargs(&fa, fin) != 1)
695                  return(-1);
696 <        if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15)
696 >        if (fa.nfargs < 9)
697                  return(-1);
698                                          /* string arguments */
699          printf("%d", fa.nsargs);
700 <        for (i = 0; i < fa.nsargs; i++)
701 <                printf(" %s", fa.sarg[i]);
700 >        for (i = 0; i < fa.nsargs; i++) {
701 >                fputc(' ', stdout);
702 >                fputword(fa.sarg[i], stdout);
703 >        }
704          printf("\n0\n%d\n", fa.nfargs);
705                                          /* anchor point */
706          multp3(v, fa.farg, tot.xfm);
# Line 469 | Line 710 | FILE  *fin;
710          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
711                                          /* down vector */
712          multv3(v, fa.farg+6, tot.xfm);
713 <        printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
714 <                                        /* forground and background */
715 <        if (fa.nfargs == 11)
716 <                printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]);
717 <        else if (fa.nfargs == 15) {
718 <                printf(" %18.12g %18.12g %18.12g\n",
478 <                                fa.farg[9], fa.farg[10], fa.farg[11]);
479 <                printf(" %18.12g %18.12g %18.12g\n",
480 <                                fa.farg[12], fa.farg[13], fa.farg[14]);
713 >        printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]);
714 >                                        /* remaining arguments */
715 >        for (i = 9; i < fa.nfargs; i++) {
716 >                if (i%3 == 0)
717 >                        putchar('\n');
718 >                printf(" %18.12g", fa.farg[i]);
719          }
720 +        putchar('\n');
721          freefargs(&fa);
722          return(0);
723   }
724  
725  
726 < o_source(fin)                   /* transform source arguments */
727 < FILE  *fin;
726 > int
727 > o_source(                       /* transform source arguments */
728 >        FILE  *fin
729 > )
730   {
731 <        double  dv[3];
732 <        FUNARGS  fa;
731 >        FVECT  dv;
732 >        FUNARGS  fa;
733  
734          if (readfargs(&fa, fin) != 1)
735                  return(-1);
# Line 505 | Line 746 | FILE  *fin;
746   }
747  
748  
749 < o_sphere(fin)                   /* transform sphere arguments */
750 < FILE  *fin;
749 > int
750 > o_sphere(                       /* transform sphere arguments */
751 >        FILE  *fin
752 > )
753   {
754 <        double  cent[3], rad;
755 <        FUNARGS  fa;
754 >        FVECT  cent;
755 >        double  rad;
756 >        FUNARGS  fa;
757  
758          if (readfargs(&fa, fin) != 1)
759                  return(-1);
760          if (fa.nsargs != 0  || fa.nfargs != 4)
761                  return(-1);
762          
763 <        multp3(cent, fa.farg, tot.xfm); /* transform center */
763 >        multp3(cent, fa.farg, tot.xfm); /* transform center */
764          
765          rad = fa.farg[3] * tot.sca;             /* scale radius */
766          
# Line 528 | Line 772 | FILE  *fin;
772   }
773  
774  
775 < o_face(fin)                     /* transform face arguments */
776 < FILE  *fin;
775 > int
776 > o_face(                 /* transform face arguments */
777 >        FILE  *fin
778 > )
779   {
780 <        double  p[3];
781 <        register int  i;
782 <        FUNARGS  fa;
780 >        FVECT  p;
781 >        int  i;
782 >        FUNARGS  fa;
783  
784          if (readfargs(&fa, fin) != 1)
785                  return(-1);
# Line 554 | Line 800 | FILE  *fin;
800   }
801  
802  
803 < o_cone(fin)                     /* transform cone and cup arguments */
804 < FILE  *fin;
803 > int
804 > o_cone(                 /* transform cone and cup arguments */
805 >        FILE  *fin
806 > )
807   {
808 <        double  p0[3], p1[3], r0, r1;
809 <        FUNARGS  fa;
808 >        FVECT  p0, p1;
809 >        double  r0, r1;
810 >        FUNARGS  fa;
811  
812          if (readfargs(&fa, fin) != 1)
813                  return(-1);
# Line 580 | Line 829 | FILE  *fin;
829   }
830  
831  
832 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
833 < FILE  *fin;
832 > int
833 > o_cylinder(                     /* transform cylinder and tube arguments */
834 >        FILE  *fin
835 > )
836   {
837 <        double  p0[3], p1[3], rad;
838 <        FUNARGS  fa;
837 >        FVECT  p0, p1;
838 >        double  rad;
839 >        FUNARGS  fa;
840  
841          if (readfargs(&fa, fin) != 1)
842                  return(-1);
# Line 604 | Line 856 | FILE  *fin;
856   }
857  
858  
859 < o_ring(fin)                     /* transform ring arguments */
860 < FILE  *fin;
859 > int
860 > o_ring(                 /* transform ring arguments */
861 >        FILE  *fin
862 > )
863   {
864 <        double  p0[3], pd[3], r0, r1;
865 <        FUNARGS  fa;
864 >        FVECT  p0, pd;
865 >        double  r0, r1;
866 >        FUNARGS  fa;
867  
868          if (readfargs(&fa, fin) != 1)
869                  return(-1);
# Line 634 | Line 889 | FILE  *fin;
889   }
890  
891  
892 < initotypes()                    /* initialize ofun[] array */
892 > void
893 > initotypes(void)                        /* initialize ofun[] array */
894   {
895 <        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;
895 >        int  i;
896  
897          if (ofun[OBJ_SOURCE].funp == o_source)
898                  return;                 /* done already */
657                                        /* alias is additional */
658        ofun[ALIAS].funame = ALIASID;
659        ofun[ALIAS].flags = 0;
899                                          /* functions get new transform */
900 <        for (i = 0; i < NUMTYPES; i++)
900 >        for (i = 0; i < NUMOTYPE; i++)
901                  if (hasfunc(i))
902                          ofun[i].funp = addxform;
903                                          /* special cases */
# Line 671 | Line 910 | initotypes()                   /* initialize ofun[] array */
910          ofun[OBJ_CYLINDER].funp =
911          ofun[OBJ_TUBE].funp = o_cylinder;
912          ofun[OBJ_RING].funp = o_ring;
913 <        ofun[OBJ_INSTANCE].funp = addxform;
913 >        ofun[OBJ_INSTANCE].funp =
914 >        ofun[OBJ_MESH].funp = addxform;
915          ofun[MAT_GLOW].funp = m_glow;
916          ofun[MAT_SPOT].funp = m_spot;
917          ofun[MAT_DIELECTRIC].funp = m_dielectric;
918          ofun[MAT_INTERFACE].funp = m_interface;
919 +        ofun[MAT_MIST].funp = m_mist;
920          ofun[PAT_CTEXT].funp =
921          ofun[PAT_BTEXT].funp =
922          ofun[MIX_TEXT].funp = text;
923 <        ofun[ALIAS].funp = alias;
923 >        ofun[MOD_ALIAS].funp = alias;
924                                          /* surface inverses */
925 +        tinvers[OBJ_FACE] = OBJ_FACE;
926          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
927          tinvers[OBJ_CONE] = OBJ_CUP;
928          tinvers[OBJ_CUP] = OBJ_CONE;
# Line 690 | Line 932 | initotypes()                   /* initialize ofun[] array */
932          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
933          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
934          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
935 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
936   }
937 +
938 +
939 + #ifdef  OLDXFORM
940 + void
941 + openmain(
942 +        char  *fname
943 + )
944 + {
945 +        if (fname == NULL) {
946 +                strcpy(mainfn, "standard input");
947 +                mainfp = stdin;
948 +                return;
949 +        }
950 +        if (mainfp != NULL) {
951 +                if (!strcmp(fname, mainfn)) {
952 +                        rewind(mainfp);
953 +                        return;
954 +                }
955 +                fclose(mainfp);
956 +        }
957 +        if ((mainfp = fopen(fname, "r")) == NULL) {
958 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
959 +                                progname, fname);
960 +                exit(1);
961 +        }
962 +        strcpy(mainfn, fname);
963 + }
964 + #else
965 + void
966 + openmain(               /* open input, changing directory for file */
967 +        char  *iname
968 + )
969 + {
970 +        static char  origdir[PATH_MAX];
971 +        static char  curfn[PATH_MAX];
972 +        static int  diffdir;
973 +        char  *fpath;
974 +
975 +        if (iname == NULL) {                    /* standard input */
976 +                if (mainfp == NULL) {
977 +                        int  c;
978 +                        strcpy(mainfn, "standard input");
979 +                        if (nrept <= 1) {
980 +                                mainfp = stdin;
981 +                                return;                 /* just read once */
982 +                        }
983 +                                                        /* else copy */
984 +                        if ((mainfp = tmpfile()) == NULL) {
985 +                                fprintf(stderr,
986 +                                        "%s: cannot create temporary file\n",
987 +                                                progname);
988 +                                exit(1);
989 +                        }
990 +                        while ((c = getc(stdin)) != EOF)
991 +                                putc(c, mainfp);
992 +                }
993 +                rewind(mainfp);                 /* rewind copy */
994 +                return;
995 +        }
996 +        if (mainfp == NULL) {                   /* first call, initialize */
997 +                getcwd(origdir, sizeof(origdir));
998 +        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
999 +                rewind(mainfp);
1000 +                return;
1001 +        } else {                                /* else close old stream */
1002 +                fclose(mainfp);
1003 +                mainfp = NULL;
1004 +                if (diffdir) {                  /* return to our directory */
1005 +                        chdir(origdir);
1006 +                        diffdir = 0;
1007 +                }
1008 +        }
1009 +        strcpy(curfn, iname);                   /* remember input name */
1010 +                                                /* get full path for file */
1011 +        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1012 +                fprintf(stderr, "%s: cannot find file \"%s\"\n",
1013 +                                progname, iname);
1014 +                exit(1);
1015 +        }
1016 +        if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
1017 +                fpath += 2;
1018 +                                                /* record path name */
1019 +        strcpy(mainfn, fpath);
1020 +        if (expand) {                           /* change to local directory */
1021 +                char  *cp = fpath + strlen(fpath);      /* get dir. */
1022 +                while (cp > fpath) {
1023 +                        cp--;
1024 +                        if (ISDIRSEP(*cp)) {
1025 +                                if (cp == fpath)
1026 +                                        cp++;   /* root special case */
1027 +                                break;
1028 +                        }
1029 +                }
1030 +                *cp = '\0';
1031 +                if (fpath[0]) {                 /* change to new directory? */
1032 +                        if (chdir(fpath) < 0) {
1033 +                                fprintf(stderr,
1034 +                                "%s: cannot change directory to \"%s\"\n",
1035 +                                                progname, fpath);
1036 +                                exit(1);
1037 +                        }
1038 +                        diffdir++;
1039 +                }
1040 +                                                /* get final path component */
1041 +                for (fpath = iname+strlen(iname);
1042 +                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1043 +                        ;
1044 +        }
1045 +                                                /* finally, open the file */
1046 +        if ((mainfp = fopen(fpath, "r")) == NULL) {
1047 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
1048 +                                progname, mainfn);
1049 +                exit(1);
1050 +        }
1051 + }
1052 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines