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 2.6 by greg, Mon Sep 21 12:15:44 1992 UTC vs.
Revision 2.50 by greg, Fri Mar 4 00:21:21 2016 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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])
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] && 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 +                        }
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 +
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  i, err;
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++)
# Line 157 | Line 327 | int  ac, ai;
327                  ac += 2;
328          }
329          err = 0;
330 <        for (i = 0; i < atoi(av[ai+1]); i++) {
330 >        for (i = 0; i < n; i++) {
331                  if (oldid == NULL)
332                          sprintf(newid, "a%d", i);
333                  else
# Line 169 | Line 339 | int  ac, ai;
339   }
340  
341  
342 < xform(name, fin)                        /* transform stream by tot.xfm */
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 */
# Line 188 | Line 361 | register FILE  *fin;
361                  } else if (c == '!') {                  /* command */
362                          ungetc(c, fin);
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)                      /* transform a command */
378 < char  *fname;
379 < FILE  *fin;
377 > void
378 > xfcomm(                 /* transform a command */
379 >        char  *fname,
380 >        FILE  *fin
381 > )
382   {
203        FILE  *popen();
204        char  *fgetline();
383          FILE  *pin;
384 <        char  buf[512];
384 >        char  buf[2048];
385          int  i;
386  
387          fgetline(buf, sizeof(buf), fin);
# Line 218 | Line 396 | FILE  *fin;
396          } else {
397                  printf("\n%s", buf);
398                  if (xac > 1) {
399 <                        printf(" | %s -e", xav[0]);
399 >                        printf(" | %s -e", xav[0]);     /* expand next time */
400                          for (i = 1; i < xac; i++)
401 <                                printf(" %s", xav[i]);
401 >                                if (i >= xfa || strcmp(xav[i], "-c"))
402 >                                        printf(" %s", xav[i]);
403                  }
404                  putchar('\n');
405          }
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   {
234        extern char  *strcpy();
415          char  typ[16], nam[MAXSTR];
416          int  fn;
417                                                  /* modifier and type */
# Line 243 | Line 423 | FILE  *fin;
423                                  progname, fname, typ);
424                  exit(1);
425          }
426 <        if (ismodifier(fn))
427 <                printf("\n%s %s ", nam, typ);
428 <        else
429 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
430 <                                invert ? ofun[tinvers[fn]].funame : typ);
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 <                printf("%s\n", nam);
438 <        else
439 <                printf("%s.%s\n", idprefix, nam);
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",
# Line 263 | Line 450 | FILE  *fin;
450   }
451  
452  
453 < o_default(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;
458 >        int  i;
459          FUNARGS  fa;
460  
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]);
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 */
# Line 295 | Line 486 | FILE  *fin;
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;
494 >        int  i;
495          int  resetarr = 0;
496          FUNARGS  fa;
497  
# Line 308 | Line 501 | FILE  *fin;
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 <                printf(" %s", fa.sarg[i]);
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 */
# Line 335 | Line 530 | FILE  *fin;
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   {
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 {
537          char  aliasnm[MAXSTR];
538  
539          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 360 | Line 543 | FILE  *fin;
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          FUNARGS  fa;
552  
# Line 378 | Line 563 | FILE  *fin;
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          FVECT  v;
572          FUNARGS  fa;
# Line 398 | Line 585 | FILE  *fin;
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   {
404        double  pow();
593          FUNARGS  fa;
594 +        int     i;
595  
596          if (readfargs(&fa, fin) != 1)
597                  return(-1);
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",
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(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]);
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   {
425        double  pow();
659          FUNARGS  fa;
660  
661          if (readfargs(&fa, fin) != 1)
# Line 430 | Line 663 | FILE  *fin;
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",
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(" %18.12g\n", fa.farg[3]);
671 <        printf("%18.12g %18.12g %18.12g",
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(" %18.12g\n", fa.farg[7]);
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          FVECT  v;
# Line 458 | Line 693 | FILE  *fin;
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]);
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, tot.xfm);
# Line 482 | Line 719 | FILE  *fin;
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          FVECT  dv;
728          FUNARGS  fa;
# Line 503 | Line 742 | FILE  *fin;
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          FVECT  cent;
751          double  rad;
# Line 527 | Line 768 | FILE  *fin;
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          FVECT  p;
777 <        register int  i;
777 >        int  i;
778          FUNARGS  fa;
779  
780          if (readfargs(&fa, fin) != 1)
# Line 553 | Line 796 | FILE  *fin;
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          FVECT  p0, p1;
805          double  r0, r1;
# Line 580 | Line 825 | FILE  *fin;
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          FVECT  p0, p1;
834          double  rad;
# Line 605 | Line 852 | FILE  *fin;
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          FVECT  p0, pd;
861          double  r0, r1;
# Line 636 | Line 885 | FILE  *fin;
885   }
886  
887  
888 < initotypes()                    /* initialize ofun[] array */
888 > void
889 > initotypes(void)                        /* initialize ofun[] array */
890   {
891 <        extern int  o_source();
642 <        extern int  o_sphere();
643 <        extern int  o_face();
644 <        extern int  o_cone();
645 <        extern int  o_cylinder();
646 <        extern int  o_ring();
647 <        extern int  m_glow();
648 <        extern int  m_spot();
649 <        extern int  m_dielectric();
650 <        extern int  m_interface();
651 <        extern int  text();
652 <        extern int  alias();
653 <        extern int  passargs();
654 <        extern int  addxform();
655 <        register int  i;
891 >        int  i;
892  
893          if (ofun[OBJ_SOURCE].funp == o_source)
894                  return;                 /* done already */
659                                        /* alias is additional */
660        ofun[ALIAS].funame = ALIASID;
661        ofun[ALIAS].flags = 0;
895                                          /* functions get new transform */
896 <        for (i = 0; i < NUMTYPES; i++)
896 >        for (i = 0; i < NUMOTYPE; i++)
897                  if (hasfunc(i))
898                          ofun[i].funp = addxform;
899                                          /* special cases */
# Line 673 | Line 906 | initotypes()                   /* initialize ofun[] array */
906          ofun[OBJ_CYLINDER].funp =
907          ofun[OBJ_TUBE].funp = o_cylinder;
908          ofun[OBJ_RING].funp = o_ring;
909 <        ofun[OBJ_INSTANCE].funp = addxform;
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[ALIAS].funp = alias;
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;
# Line 692 | Line 928 | initotypes()                   /* initialize ofun[] array */
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 + #ifdef  OLDXFORM
936 + void
937 + openmain(
938 +        char  *fname
939 + )
940 + {
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 +        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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines