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.9 by greg, Fri Oct 27 08:56:18 1995 UTC vs.
Revision 2.39 by greg, Wed Dec 28 18:35:42 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 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  "rtprocess.h" /* win_popen() */
17 + #include  "rtio.h"
18 + #include  "rtmath.h"
19   #include  "object.h"
20
20   #include  "otypes.h"
21  
22   int  xac;                               /* global xform argument count */
# Line 27 | Line 26 | int  xfa;                              /* start of xf arguments */
26   XF  tot;                                /* total transformation */
27   int  reverse;                           /* boolean true if scene mirrored */
28  
29 < int  invert = 0;                        /* boolean true to invert surfaces */
29 > int  invert;                            /* boolean true to invert surfaces */
30  
31 < int  expand = 0;                        /* boolean true to expand commands */
31 > int  expand;                            /* boolean true to expand commands */
32  
33 < char  *newmod = NULL;                   /* new modifier for surfaces */
33 > char  *newmod;                          /* new modifier for surfaces */
34  
35 < char  *idprefix = NULL;                 /* prefix for object identifiers */
35 > char  *idprefix;                        /* prefix for object identifiers */
36  
37 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
37 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
38  
39 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
39 > short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
40  
41 < FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
41 > int  nrept = 1;                         /* number of array repetitions */
42  
43 < short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
43 > int stdinused = 0;                      /* stdin has been used by -f option? */
44  
45 < extern char  *malloc(), *fgetword();
45 > char  mainfn[PATH_MAX];                 /* main file name */
46 > FILE  *mainfp = NULL;                   /* main file pointer */
47  
48   #define  progname  (xav[0])
49  
50 + static int doargf(int ac, char **av, int fi);
51 + static int doarray(int ac, char **av, int ai);
52 + static void xform(char *name, FILE *fin);
53 + static void xfcomm(char *fname, FILE *fin);
54 + static void xfobject(char *fname, FILE *fin);
55 + static int addxform(FILE *fin);
56 + static int alias(FILE *fin);
57 + void initotypes(void); /* XXX conflict with otypes.h */
58 + static void openmain(char *iname);
59  
60 < main(argc, argv)                /* get transform options and transform file */
61 < int  argc;
62 < char  *argv[];
60 >
61 > int
62 > main(           /* get transform options and transform file */
63 >        int  argc,
64 >        char  *argv[]
65 > )
66   {
67 <        FILE  *fopen();
56 <        FILE  *fp;
67 >        int  mal_prefix = 0;
68          int  a;
69 <                                        /* check for array */
69 >                                        /* check for argument list file */
70          for (a = 1; a < argc; a++)
71 +                if (!strcmp(argv[a], "-f"))
72 +                        return(doargf(argc, argv, a));
73 +                                        /* check for regular array */
74 +        for (a = 1; a < argc; a++)
75                  if (!strcmp(argv[a], "-a"))
76                          return(doarray(argc, argv, a));
77  
78 <        initotypes();
78 >        initotypes();                   /* initialize */
79 >        invert = 0;
80 >        expand = 1;
81 >        newmod = NULL;
82 >        idprefix = NULL;
83  
84          for (a = 1; a < argc; a++) {
85                  if (argv[a][0] == '-')
86                          switch (argv[a][1]) {
87                          case 'm':
88 <                                if (argv[a][2] || a+1 >= argc)
88 >                                if (argv[a][2] | (a+1 >= argc))
89                                          break;
90 <                                newmod = argv[++a];
90 >                                a++;
91 >                                if (newmod == NULL)
92 >                                        newmod = argv[a];
93                                  continue;
94                          case 'n':
95 <                                if (argv[a][2] || a+1 >= argc)
95 >                                if (argv[a][2] | (a+1 >= argc))
96                                          break;
97 <                                idprefix = argv[++a];
97 >                                a++;
98 >                                if (idprefix == NULL)
99 >                                        idprefix = argv[a];
100 >                                else {
101 >                                        register char   *newp;
102 >                                        newp = (char *)malloc(strlen(idprefix)+
103 >                                                        strlen(argv[a])+2);
104 >                                        if (newp == NULL)
105 >                                                exit(2);
106 >                                        sprintf(newp, "%s.%s",
107 >                                                        idprefix, argv[a]);
108 >                                        if (mal_prefix++)
109 >                                                free((void *)idprefix);
110 >                                        idprefix = newp;
111 >                                }
112                                  continue;
113 +                        case 'c':
114 +                                if (argv[a][2])
115 +                                        break;
116 +                                expand = 0;
117 +                                continue;
118                          case 'e':
119                                  if (argv[a][2])
120                                          break;
# Line 83 | Line 123 | char  *argv[];
123                          case 'I':
124                                  if (argv[a][2])
125                                          break;
126 <                                invert = 1;
126 >                                invert = !invert;
127                                  continue;
128                          }
129                  break;
# Line 94 | Line 134 | char  *argv[];
134  
135          a += xf(&tot, argc-a, argv+a);
136  
137 <        if (reverse = tot.sca < 0.0)
137 >        if ( (reverse = tot.sca < 0.0) )
138                  tot.sca = -tot.sca;
139          if (invert)
140                  reverse = !reverse;
# Line 112 | Line 152 | char  *argv[];
152                  printf(" %s", xav[a]);
153          putchar('\n');
154                                          /* transform input */
155 <        if (xac == argc)
156 <                xform("standard input", stdin);
157 <        else
155 >        if (xac == argc) {
156 >                if (stdinused) {
157 >                        fprintf(stderr, "%s: cannot use stdin more than once\n",
158 >                                        argv[0]);
159 >                        exit(1);
160 >                }
161 >                openmain(NULL);
162 >                xform(mainfn, mainfp);
163 >        } else
164                  for (a = xac; a < argc; a++) {
165 <                        if ((fp = fopen(argv[a], "r")) == NULL) {
166 <                                fprintf(stderr, "%s: cannot open \"%s\"\n",
121 <                                                progname, argv[a]);
122 <                                exit(1);
123 <                        }
124 <                        xform(argv[a], fp);
125 <                        fclose(fp);
165 >                        openmain(argv[a]);
166 >                        xform(mainfn, mainfp);
167                  }
168  
169 +        if (mal_prefix)
170 +                free((void *)idprefix);
171          return(0);
172   }
173  
174  
175 < doarray(ac, av, ai)                     /* make array */
176 < char  **av;
177 < int  ac, ai;
175 > int
176 > doargf(                 /* take argument list from file */
177 >        int ac,
178 >        char  **av,
179 >        int fi
180 > )
181   {
182 +        int  inquote;
183          char  *newav[256], **avp;
184 +        char  argbuf[2048];
185 +        char  newid[128];
186 +        char  *oldid;
187 +        register char   *cp;
188 +        FILE    *argfp;
189 +        int  n, i, k, newac, err;
190 +        
191 +        if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) {
192 +                fprintf(stderr, "%s: missing file for -f option\n", av[0]);
193 +                exit(1);
194 +        }
195 +        if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
196 +                if (stdinused++) {
197 +                        fprintf(stderr,
198 +                                "%s: cannot use stdin more than once\n",
199 +                                        av[0]);
200 +                        exit(1);
201 +                }
202 +                argfp = stdin;
203 +                n = 100;                /* we just don't know! */
204 +        } else {
205 +                if ((argfp = fopen(av[fi+1], "r")) == NULL) {
206 +                        fprintf(stderr,
207 +                                "%s: cannot open argument file \"%s\"\n",
208 +                                        av[0], av[fi+1]);
209 +                        exit(1);
210 +                }
211 +                n = 0;                  /* count number of lines in file */
212 +                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
213 +                        n += argbuf[0] && argbuf[0] != '#';
214 +                if (!n) {
215 +                        fprintf(stderr, "%s: empty argument file \"%s\"\n",
216 +                                        av[0], av[fi+1]);
217 +                        exit(1);
218 +                }
219 +                nrept *= n;
220 +                rewind(argfp);
221 +        }
222 +        err = 0; k = 0;                 /* read each arg list and call main */
223 +        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
224 +                if (!argbuf[0] || argbuf[0] == '#')
225 +                        continue;
226 +                avp = newav+2;
227 +                avp[0] = av[0];
228 +                for (i = 1; i < fi; i++)
229 +                        avp[i] = av[i];
230 +                newac = i;
231 +                cp = argbuf;            /* parse new words */
232 +                if (*cp == '!') cp++;
233 +                if (!strncmp(cp, "xform ", 6)) cp += 6;
234 +                inquote = 0;
235 +                for ( ; ; ) {
236 +                skipspaces:
237 +                        while (isspace(*cp))    /* nullify spaces */
238 +                                *cp++ = '\0';
239 +                        if ((*cp == '"') | (*cp == '\''))
240 +                                inquote = *cp++;
241 +                        if (!*cp)               /* all done? */
242 +                                break;
243 +                        if (cp[0] == '\\' && cp[1])
244 +                                if (*++cp == '\n')
245 +                                        goto skipspaces;
246 +                        avp[newac++] = cp;      /* add argument to list */
247 +                        if (inquote) {
248 +                                while (*++cp)
249 +                                        if (*cp == inquote) {
250 +                                                *cp++ = '\0';
251 +                                                break;
252 +                                        }
253 +                        } else {
254 +                                while (*++cp && !isspace(*cp))
255 +                                        ;
256 +                        }
257 +                }
258 +                for (i = fi+2; i < ac; i++)
259 +                        avp[newac++] = av[i];
260 +                avp[newac] = NULL;
261 +                oldid = NULL;
262 +                for (i = 2; i < newac; i++)
263 +                        if (!strcmp(avp[i-1], "-n")) {
264 +                                oldid = avp[i];
265 +                                avp[i] = newid;
266 +                                break;
267 +                        }
268 +                if (oldid == NULL) {
269 +                        newav[0] = av[0];
270 +                        newav[1] = "-n";
271 +                        newav[2] = newid;
272 +                        avp = newav;
273 +                        newac += 2;
274 +                }
275 +                if (oldid == NULL)
276 +                        sprintf(newid, "i%d", k);
277 +                else
278 +                        sprintf(newid, "%s.%d", oldid, k);
279 +                err |= main(newac, avp);
280 +                k++;
281 +        }
282 +        fclose(argfp);
283 +        return(err);
284 + }
285 +
286 +
287 + int
288 + doarray(                        /* make array */
289 +        int  ac,
290 +        char  **av,
291 +        int  ai
292 + )
293 + {
294 +        char  *newav[256], **avp;
295          char  newid[128], repts[32];
296          char  *oldid = NULL;
297 <        int  i, err;
297 >        int  n, i, err;
298          
299 +        if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) {
300 +                fprintf(stderr, "%s: missing count for -a option\n", av[0]);
301 +                exit(1);
302 +        }
303 +        nrept *= n;
304          avp = newav+2;
305          avp[0] = av[0];
306          for (i = 1; i < ac; i++)
# Line 157 | Line 320 | int  ac, ai;
320                  ac += 2;
321          }
322          err = 0;
323 <        for (i = 0; i < atoi(av[ai+1]); i++) {
323 >        for (i = 0; i < n; i++) {
324                  if (oldid == NULL)
325                          sprintf(newid, "a%d", i);
326                  else
# Line 169 | Line 332 | int  ac, ai;
332   }
333  
334  
335 < xform(name, fin)                        /* transform stream by tot.xfm */
336 < char  *name;
337 < register FILE  *fin;
335 > void
336 > xform(                  /* transform stream by tot.xfm */
337 >        char  *name,
338 >        register FILE  *fin
339 > )
340   {
341          int  nobjs = 0;
342          register int  c;
# Line 202 | Line 367 | register FILE  *fin;
367   }
368  
369  
370 < xfcomm(fname, fin)                      /* transform a command */
371 < char  *fname;
372 < FILE  *fin;
370 > void
371 > xfcomm(                 /* transform a command */
372 >        char  *fname,
373 >        FILE  *fin
374 > )
375   {
209        FILE  *popen();
210        char  *fgetline();
376          FILE  *pin;
377 <        char  buf[512];
377 >        char  buf[2048];
378          int  i;
379  
380          fgetline(buf, sizeof(buf), fin);
# Line 224 | Line 389 | FILE  *fin;
389          } else {
390                  printf("\n%s", buf);
391                  if (xac > 1) {
392 <                        printf(" | %s -e", xav[0]);
392 >                        printf(" | %s -e", xav[0]);     /* expand next time */
393                          for (i = 1; i < xac; i++)
394 <                                printf(" %s", xav[i]);
394 >                                if (i >= xfa || strcmp(xav[i], "-c"))
395 >                                        printf(" %s", xav[i]);
396                  }
397                  putchar('\n');
398          }
399   }
400  
401  
402 < xfobject(fname, fin)                            /* transform an object */
403 < char  *fname;
404 < FILE  *fin;
402 > void
403 > xfobject(                               /* transform an object */
404 >        char  *fname,
405 >        FILE  *fin
406 > )
407   {
240        extern char  *strcpy();
408          char  typ[16], nam[MAXSTR];
409          int  fn;
410                                                  /* modifier and type */
# Line 249 | Line 416 | FILE  *fin;
416                                  progname, fname, typ);
417                  exit(1);
418          }
419 <        if (ismodifier(fn))
420 <                printf("\n%s %s ", nam, typ);
421 <        else
422 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
423 <                                invert ? ofun[tinvers[fn]].funame : typ);
419 >        putchar('\n');
420 >        if (ismodifier(fn)) {
421 >                fputword(nam, stdout);
422 >                printf(" %s ", typ);
423 >        } else {
424 >                fputword(newmod != NULL ? newmod : nam, stdout);
425 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
426 >        }
427                                                  /* object name */
428          fgetword(nam, sizeof(nam), fin);
429          if (idprefix == NULL || ismodifier(fn))
430 <                printf("%s\n", nam);
431 <        else
432 <                printf("%s.%s\n", idprefix, nam);
430 >                fputword(nam, stdout);
431 >        else {
432 >                char    nnam[MAXSTR];
433 >                sprintf(nnam, "%s.%s", idprefix, nam);
434 >                fputword(nnam, stdout);
435 >        }
436 >        putchar('\n');
437                                                  /* transform arguments */
438          if ((*ofun[fn].funp)(fin) < 0) {
439                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 269 | Line 443 | FILE  *fin;
443   }
444  
445  
446 < o_default(fin)                  /* pass on arguments unchanged */
447 < FILE  *fin;
446 > int
447 > o_default(                      /* pass on arguments unchanged */
448 >        FILE  *fin
449 > )
450   {
451          register int  i;
452          FUNARGS  fa;
# Line 279 | Line 455 | FILE  *fin;
455                  return(-1);
456                                          /* string arguments */
457          printf("%d", fa.nsargs);
458 <        for (i = 0; i < fa.nsargs; i++)
459 <                printf(" %s", fa.sarg[i]);
458 >        for (i = 0; i < fa.nsargs; i++) {
459 >                fputc(' ', stdout);
460 >                fputword(fa.sarg[i], stdout);
461 >        }
462          printf("\n");
463   #ifdef  IARGS
464                                          /* integer arguments */
# Line 301 | Line 479 | FILE  *fin;
479   }
480  
481  
482 < addxform(fin)                   /* add xf arguments to strings */
483 < FILE  *fin;
482 > int
483 > addxform(                       /* add xf arguments to strings */
484 >        FILE  *fin
485 > )
486   {
487          register int  i;
488          int  resetarr = 0;
# Line 314 | Line 494 | FILE  *fin;
494          if (xac > xfa && strcmp(xav[xfa], "-i"))
495                  resetarr = 2;
496          printf("%d", fa.nsargs + resetarr + xac-xfa);
497 <        for (i = 0; i < fa.nsargs; i++)
498 <                printf(" %s", fa.sarg[i]);
497 >        for (i = 0; i < fa.nsargs; i++) {
498 >                fputc(' ', stdout);
499 >                fputword(fa.sarg[i], stdout);
500 >        }
501          if (resetarr)
502                  printf(" -i 1");
503          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 341 | Line 523 | FILE  *fin;
523  
524  
525   int
526 < otype(ofname)                   /* get object function number from its name */
527 < register char  *ofname;
526 > alias(                  /* transfer alias */
527 >        FILE  *fin
528 > )
529   {
347        register int  i;
348
349        for (i = 0; i < NUMTYPES; i++)
350                if (!strcmp(ofun[i].funame, ofname))
351                        return(i);
352
353        return(-1);             /* not found */
354 }
355
356
357 alias(fin)                      /* transfer alias */
358 FILE  *fin;
359 {
530          char  aliasnm[MAXSTR];
531  
532          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 366 | Line 536 | FILE  *fin;
536   }
537  
538  
539 < m_glow(fin)                     /* transform arguments for proximity light */
540 < FILE  *fin;
539 > int
540 > m_glow(                 /* transform arguments for proximity light */
541 >        FILE  *fin
542 > )
543   {
544          FUNARGS  fa;
545  
# Line 384 | Line 556 | FILE  *fin;
556   }
557  
558  
559 < m_spot(fin)                     /* transform arguments for spotlight */
560 < FILE  *fin;
559 > int
560 > m_spot(                 /* transform arguments for spotlight */
561 >        FILE  *fin
562 > )
563   {
564          FVECT  v;
565          FUNARGS  fa;
# Line 404 | Line 578 | FILE  *fin;
578   }
579  
580  
581 < m_dielectric(fin)               /* transform arguments for dielectric */
582 < FILE  *fin;
581 > int
582 > m_mist(         /* transform arguments for mist */
583 >        FILE  *fin
584 > )
585   {
586          FUNARGS  fa;
587 +        int     i;
588  
589          if (readfargs(&fa, fin) != 1)
590                  return(-1);
591 +        if (fa.nfargs > 7)
592 +                return(-1);
593 +        printf("%d", fa.nsargs);
594 +        if (idprefix == NULL)
595 +                for (i = 0; i < fa.nsargs; i++)
596 +                        printf(" %s", fa.sarg[i]);
597 +        else
598 +                for (i = 0; i < fa.nsargs; i++) {
599 +                        char    sname[256], *sp;
600 +                        register char   *cp1, *cp2 = sname;
601 +                                                        /* add idprefix */
602 +                        for (sp = fa.sarg[i]; *sp; sp = cp1) {
603 +                                for (cp1 = idprefix; *cp1; )
604 +                                        *cp2++ = *cp1++;
605 +                                *cp2++ = '.';
606 +                                for (cp1 = sp; *cp1 &&
607 +                                                (*cp2++ = *cp1++) != '>'; )
608 +                                        ;
609 +                        }
610 +                        *cp2 = '\0';
611 +                        printf(" %s", sname);
612 +                }
613 +        printf("\n0\n%d", fa.nfargs);
614 +        if (fa.nfargs > 2)
615 +                printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
616 +                                fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
617 +        for (i = 3; i < fa.nfargs; i++)
618 +                printf(" %12.6g", fa.farg[i]);
619 +        printf("\n");
620 +        freefargs(&fa);
621 +        return(0);
622 + }
623 +
624 +
625 + int
626 + m_dielectric(           /* transform arguments for dielectric */
627 +        FILE  *fin
628 + )
629 + {
630 +        FUNARGS  fa;
631 +
632 +        if (readfargs(&fa, fin) != 1)
633 +                return(-1);
634          if (fa.nsargs != 0  || fa.nfargs != 5)
635                  return(-1);
636          printf("0\n0\n5");
637 <        printf(" %18.12g %18.12g %18.12g",
637 >        printf(" %12.6g %12.6g %12.6g",
638                  pow(fa.farg[0], 1.0/tot.sca),
639                  pow(fa.farg[1], 1.0/tot.sca),
640                  pow(fa.farg[2], 1.0/tot.sca));
641 <        printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]);
641 >        printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]);
642          freefargs(&fa);
643          return(0);
644   }
645  
646  
647 < m_interface(fin)                /* transform arguments for interface */
648 < FILE  *fin;
647 > int
648 > m_interface(            /* transform arguments for interface */
649 >        FILE  *fin
650 > )
651   {
652          FUNARGS  fa;
653  
# Line 434 | Line 656 | FILE  *fin;
656          if (fa.nsargs != 0  || fa.nfargs != 8)
657                  return(-1);
658          printf("0\n0\n8\n");
659 <        printf("%18.12g %18.12g %18.12g",
659 >        printf("%12.6g %12.6g %12.6g",
660                  pow(fa.farg[0], 1.0/tot.sca),
661                  pow(fa.farg[1], 1.0/tot.sca),
662                  pow(fa.farg[2], 1.0/tot.sca));
663 <        printf(" %18.12g\n", fa.farg[3]);
664 <        printf("%18.12g %18.12g %18.12g",
663 >        printf(" %12.6g\n", fa.farg[3]);
664 >        printf("%12.6g %12.6g %12.6g",
665                  pow(fa.farg[4], 1.0/tot.sca),
666                  pow(fa.farg[5], 1.0/tot.sca),
667                  pow(fa.farg[6], 1.0/tot.sca));
668 <        printf(" %18.12g\n", fa.farg[7]);
668 >        printf(" %12.6g\n", fa.farg[7]);
669          freefargs(&fa);
670          return(0);
671   }
672  
673  
674 < text(fin)                       /* transform text arguments */
675 < FILE  *fin;
674 > int
675 > text(                   /* transform text arguments */
676 >        FILE  *fin
677 > )
678   {
679          int  i;
680          FVECT  v;
# Line 462 | Line 686 | FILE  *fin;
686                  return(-1);
687                                          /* string arguments */
688          printf("%d", fa.nsargs);
689 <        for (i = 0; i < fa.nsargs; i++)
690 <                printf(" %s", fa.sarg[i]);
689 >        for (i = 0; i < fa.nsargs; i++) {
690 >                fputc(' ', stdout);
691 >                fputword(fa.sarg[i], stdout);
692 >        }
693          printf("\n0\n%d\n", fa.nfargs);
694                                          /* anchor point */
695          multp3(v, fa.farg, tot.xfm);
# Line 486 | Line 712 | FILE  *fin;
712   }
713  
714  
715 < o_source(fin)                   /* transform source arguments */
716 < FILE  *fin;
715 > int
716 > o_source(                       /* transform source arguments */
717 >        FILE  *fin
718 > )
719   {
720          FVECT  dv;
721          FUNARGS  fa;
# Line 507 | Line 735 | FILE  *fin;
735   }
736  
737  
738 < o_sphere(fin)                   /* transform sphere arguments */
739 < FILE  *fin;
738 > int
739 > o_sphere(                       /* transform sphere arguments */
740 >        FILE  *fin
741 > )
742   {
743          FVECT  cent;
744          double  rad;
# Line 531 | Line 761 | FILE  *fin;
761   }
762  
763  
764 < o_face(fin)                     /* transform face arguments */
765 < FILE  *fin;
764 > int
765 > o_face(                 /* transform face arguments */
766 >        FILE  *fin
767 > )
768   {
769          FVECT  p;
770          register int  i;
# Line 557 | Line 789 | FILE  *fin;
789   }
790  
791  
792 < o_cone(fin)                     /* transform cone and cup arguments */
793 < FILE  *fin;
792 > int
793 > o_cone(                 /* transform cone and cup arguments */
794 >        FILE  *fin
795 > )
796   {
797          FVECT  p0, p1;
798          double  r0, r1;
# Line 584 | Line 818 | FILE  *fin;
818   }
819  
820  
821 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
822 < FILE  *fin;
821 > int
822 > o_cylinder(                     /* transform cylinder and tube arguments */
823 >        FILE  *fin
824 > )
825   {
826          FVECT  p0, p1;
827          double  rad;
# Line 609 | Line 845 | FILE  *fin;
845   }
846  
847  
848 < o_ring(fin)                     /* transform ring arguments */
849 < FILE  *fin;
848 > int
849 > o_ring(                 /* transform ring arguments */
850 >        FILE  *fin
851 > )
852   {
853          FVECT  p0, pd;
854          double  r0, r1;
# Line 640 | Line 878 | FILE  *fin;
878   }
879  
880  
881 < initotypes()                    /* initialize ofun[] array */
881 > void
882 > initotypes(void)                        /* initialize ofun[] array */
883   {
884          register int  i;
885  
886          if (ofun[OBJ_SOURCE].funp == o_source)
887                  return;                 /* done already */
649                                        /* alias is additional */
650        ofun[ALIAS].funame = ALIASID;
651        ofun[ALIAS].flags = 0;
888                                          /* functions get new transform */
889 <        for (i = 0; i < NUMTYPES; i++)
889 >        for (i = 0; i < NUMOTYPE; i++)
890                  if (hasfunc(i))
891                          ofun[i].funp = addxform;
892                                          /* special cases */
# Line 663 | Line 899 | initotypes()                   /* initialize ofun[] array */
899          ofun[OBJ_CYLINDER].funp =
900          ofun[OBJ_TUBE].funp = o_cylinder;
901          ofun[OBJ_RING].funp = o_ring;
902 <        ofun[OBJ_INSTANCE].funp = addxform;
902 >        ofun[OBJ_INSTANCE].funp =
903 >        ofun[OBJ_MESH].funp = addxform;
904          ofun[MAT_GLOW].funp = m_glow;
905          ofun[MAT_SPOT].funp = m_spot;
906          ofun[MAT_DIELECTRIC].funp = m_dielectric;
907          ofun[MAT_INTERFACE].funp = m_interface;
908 +        ofun[MAT_MIST].funp = m_mist;
909          ofun[PAT_CTEXT].funp =
910          ofun[PAT_BTEXT].funp =
911          ofun[MIX_TEXT].funp = text;
912 <        ofun[ALIAS].funp = alias;
912 >        ofun[MOD_ALIAS].funp = alias;
913                                          /* surface inverses */
914          tinvers[OBJ_FACE] = OBJ_FACE;
915          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 684 | Line 922 | initotypes()                   /* initialize ofun[] array */
922          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
923          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
924   }
925 +
926 +
927 + #ifdef  OLDXFORM
928 + void
929 + openmain(
930 +        char  *fname
931 + )
932 + {
933 +        if (fname == NULL) {
934 +                strcpy(mainfn, "standard input");
935 +                mainfp = stdin;
936 +                return;
937 +        }
938 +        if (mainfp != NULL) {
939 +                if (!strcmp(fname, mainfn)) {
940 +                        rewind(mainfp);
941 +                        return;
942 +                }
943 +                fclose(mainfp);
944 +        }
945 +        if ((mainfp = fopen(fname, "r")) == NULL) {
946 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
947 +                                progname, fname);
948 +                exit(1);
949 +        }
950 +        strcpy(mainfn, fname);
951 + }
952 + #else
953 + void
954 + openmain(               /* open input, changing directory for file */
955 +        char  *iname
956 + )
957 + {
958 +        static char  origdir[PATH_MAX];
959 +        static char  curfn[PATH_MAX];
960 +        static int  diffdir;
961 +        register char  *fpath;
962 +
963 +        if (iname == NULL) {                    /* standard input */
964 +                if (mainfp == NULL) {
965 +                        register int  c;
966 +                        strcpy(mainfn, "standard input");
967 +                        if (nrept <= 1) {
968 +                                mainfp = stdin;
969 +                                return;                 /* just read once */
970 +                        }
971 +                                                        /* else copy */
972 +                        if ((mainfp = tmpfile()) == NULL) {
973 +                                fprintf(stderr,
974 +                                        "%s: cannot create temporary file\n",
975 +                                                progname);
976 +                                exit(1);
977 +                        }
978 +                        while ((c = getc(stdin)) != EOF)
979 +                                putc(c, mainfp);
980 +                }
981 +                rewind(mainfp);                 /* rewind copy */
982 +                return;
983 +        }
984 +        if (mainfp == NULL) {                   /* first call, initialize */
985 +                getcwd(origdir, sizeof(origdir));
986 +        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
987 +                rewind(mainfp);
988 +                return;
989 +        } else {                                /* else close old stream */
990 +                fclose(mainfp);
991 +                mainfp = NULL;
992 +                if (diffdir) {                  /* return to our directory */
993 +                        chdir(origdir);
994 +                        diffdir = 0;
995 +                }
996 +        }
997 +        strcpy(curfn, iname);                   /* remember input name */
998 +                                                /* get full path for file */
999 +        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1000 +                fprintf(stderr, "%s: cannot find file \"%s\"\n",
1001 +                                progname, iname);
1002 +                exit(1);
1003 +        }
1004 +        if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
1005 +                fpath += 2;
1006 +                                                /* record path name */
1007 +        strcpy(mainfn, fpath);
1008 +        if (expand) {                           /* change to local directory */
1009 +                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1010 +                while (cp > fpath) {
1011 +                        cp--;
1012 +                        if (ISDIRSEP(*cp)) {
1013 +                                if (cp == fpath)
1014 +                                        cp++;   /* root special case */
1015 +                                break;
1016 +                        }
1017 +                }
1018 +                *cp = '\0';
1019 +                if (fpath[0]) {                 /* change to new directory? */
1020 +                        if (chdir(fpath) < 0) {
1021 +                                fprintf(stderr,
1022 +                                "%s: cannot change directory to \"%s\"\n",
1023 +                                                progname, fpath);
1024 +                                exit(1);
1025 +                        }
1026 +                        diffdir++;
1027 +                }
1028 +                                                /* get final path component */
1029 +                for (fpath = iname+strlen(iname);
1030 +                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1031 +                        ;
1032 +        }
1033 +                                                /* finally, open the file */
1034 +        if ((mainfp = fopen(fpath, "r")) == NULL) {
1035 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
1036 +                                progname, mainfn);
1037 +                exit(1);
1038 +        }
1039 + }
1040 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines