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.15 by gregl, Fri May 30 18:24:32 1997 UTC vs.
Revision 2.51 by greg, Sun Dec 2 16:30:30 2018 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 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
17 #include  "paths.h"
18
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"
22
19   #include  "otypes.h"
20  
21   int  xac;                               /* global xform argument count */
# Line 29 | 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 = 1;                        /* 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  
42 #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
43
44 FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
45
38   short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
39  
40   int  nrept = 1;                         /* number of array repetitions */
41  
42 < extern char  *malloc(), *fgetword();
42 > int stdinused = 0;                      /* stdin has been used by -f option? */
43  
44 < char  mainfn[MAXPATH];                  /* main file name */
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 <        char  *fname;
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])
# Line 94 | 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 105 | 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 124 | Line 152 | char  *argv[];
152          putchar('\n');
153                                          /* transform input */
154          if (xac == argc) {
155 +                if (stdinused) {
156 +                        fprintf(stderr, "%s: cannot use stdin more than once\n",
157 +                                        argv[0]);
158 +                        exit(1);
159 +                }
160                  openmain(NULL);
161                  xform(mainfn, mainfp);
162          } else
# Line 132 | Line 165 | char  *argv[];
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  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 163 | Line 328 | int  ac, ai;
328                  avp = newav;
329                  ac += 2;
330          }
166        nrept *= n = atoi(av[ai+1]);
331          err = 0;
332          for (i = 0; i < n; i++) {
333                  if (oldid == NULL)
# Line 177 | 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          int  nobjs = 0;
351 <        register int  c;
351 >        int  c;
352  
353          while ((c = getc(fin)) != EOF) {
354                  if (isspace(c))                         /* blank */
# Line 210 | Line 376 | register FILE  *fin;
376   }
377  
378  
379 < xfcomm(fname, fin)                      /* transform a command */
380 < char  *fname;
381 < FILE  *fin;
379 > void
380 > xfcomm(                 /* transform a command */
381 >        char  *fname,
382 >        FILE  *fin
383 > )
384   {
217        extern FILE  *popen();
218        extern char  *fgetline();
385          FILE  *pin;
386 <        char  buf[512];
386 >        char  buf[2048];
387          int  i;
388  
389          fgetline(buf, sizeof(buf), fin);
# Line 232 | Line 398 | FILE  *fin;
398          } else {
399                  printf("\n%s", buf);
400                  if (xac > 1) {
401 <                        printf(" | %s", xav[0]);
401 >                        printf(" | %s -e", xav[0]);     /* expand next time */
402                          for (i = 1; i < xac; i++)
403 <                                printf(" %s", xav[i]);
403 >                                if (i >= xfa || strcmp(xav[i], "-c"))
404 >                                        printf(" %s", xav[i]);
405                  }
406                  putchar('\n');
407          }
408   }
409  
410  
411 < xfobject(fname, fin)                            /* transform an object */
412 < char  *fname;
413 < FILE  *fin;
411 > void
412 > xfobject(                               /* transform an object */
413 >        char  *fname,
414 >        FILE  *fin
415 > )
416   {
248        extern char  *strcpy();
417          char  typ[16], nam[MAXSTR];
418          int  fn;
419                                                  /* modifier and type */
# Line 257 | Line 425 | FILE  *fin;
425                                  progname, fname, typ);
426                  exit(1);
427          }
428 <        if (ismodifier(fn))
429 <                printf("\n%s %s ", nam, typ);
430 <        else
431 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
432 <                                invert ? ofun[tinvers[fn]].funame : typ);
428 >        putchar('\n');
429 >        if (ismodifier(fn)) {
430 >                fputword(nam, stdout);
431 >                printf(" %s ", typ);
432 >        } else {
433 >                fputword(newmod != NULL ? newmod : nam, stdout);
434 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
435 >        }
436                                                  /* object name */
437          fgetword(nam, sizeof(nam), fin);
438          if (idprefix == NULL || ismodifier(fn))
439 <                printf("%s\n", nam);
440 <        else
441 <                printf("%s.%s\n", idprefix, nam);
439 >                fputword(nam, stdout);
440 >        else {
441 >                char    nnam[MAXSTR];
442 >                sprintf(nnam, "%s.%s", idprefix, nam);
443 >                fputword(nnam, stdout);
444 >        }
445 >        putchar('\n');
446                                                  /* transform arguments */
447          if ((*ofun[fn].funp)(fin) < 0) {
448                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 277 | Line 452 | FILE  *fin;
452   }
453  
454  
455 < o_default(fin)                  /* pass on arguments unchanged */
456 < FILE  *fin;
455 > int
456 > o_default(                      /* pass on arguments unchanged */
457 >        FILE  *fin
458 > )
459   {
460 <        register int  i;
460 >        int  i;
461          FUNARGS  fa;
462  
463          if (readfargs(&fa, fin) != 1)
464                  return(-1);
465                                          /* string arguments */
466          printf("%d", fa.nsargs);
467 <        for (i = 0; i < fa.nsargs; i++)
468 <                printf(" %s", fa.sarg[i]);
467 >        for (i = 0; i < fa.nsargs; i++) {
468 >                fputc(' ', stdout);
469 >                fputword(fa.sarg[i], stdout);
470 >        }
471          printf("\n");
472   #ifdef  IARGS
473                                          /* integer arguments */
# Line 309 | Line 488 | FILE  *fin;
488   }
489  
490  
491 < addxform(fin)                   /* add xf arguments to strings */
492 < FILE  *fin;
491 > int
492 > addxform(                       /* add xf arguments to strings */
493 >        FILE  *fin
494 > )
495   {
496 <        register int  i;
496 >        int  i;
497          int  resetarr = 0;
498          FUNARGS  fa;
499  
# Line 322 | Line 503 | FILE  *fin;
503          if (xac > xfa && strcmp(xav[xfa], "-i"))
504                  resetarr = 2;
505          printf("%d", fa.nsargs + resetarr + xac-xfa);
506 <        for (i = 0; i < fa.nsargs; i++)
507 <                printf(" %s", fa.sarg[i]);
506 >        for (i = 0; i < fa.nsargs; i++) {
507 >                fputc(' ', stdout);
508 >                fputword(fa.sarg[i], stdout);
509 >        }
510          if (resetarr)
511                  printf(" -i 1");
512          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 349 | Line 532 | FILE  *fin;
532  
533  
534   int
535 < otype(ofname)                   /* get object function number from its name */
536 < register char  *ofname;
535 > alias(                  /* transfer alias */
536 >        FILE  *fin
537 > )
538   {
355        register int  i;
356
357        for (i = 0; i < NUMTYPES; i++)
358                if (!strcmp(ofun[i].funame, ofname))
359                        return(i);
360
361        return(-1);             /* not found */
362 }
363
364
365 alias(fin)                      /* transfer alias */
366 FILE  *fin;
367 {
539          char  aliasnm[MAXSTR];
540  
541          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 374 | Line 545 | FILE  *fin;
545   }
546  
547  
548 < m_glow(fin)                     /* transform arguments for proximity light */
549 < FILE  *fin;
548 > int
549 > m_glow(                 /* transform arguments for proximity light */
550 >        FILE  *fin
551 > )
552   {
553          FUNARGS  fa;
554  
555          if (readfargs(&fa, fin) != 1)
556                  return(-1);
557 <        if (fa.nsargs != 0  || fa.nfargs != 4)
557 >        if ((fa.nsargs != 0) | (fa.nfargs != 4))
558                  return(-1);
559          printf("0\n0\n4");
560          printf(" %18.12g %18.12g %18.12g",
# Line 392 | Line 565 | FILE  *fin;
565   }
566  
567  
568 < m_spot(fin)                     /* transform arguments for spotlight */
569 < FILE  *fin;
568 > int
569 > m_spot(                 /* transform arguments for spotlight */
570 >        FILE  *fin
571 > )
572   {
573          FVECT  v;
574          FUNARGS  fa;
575  
576          if (readfargs(&fa, fin) != 1)
577                  return(-1);
578 <        if (fa.nsargs != 0  || fa.nfargs != 7)
578 >        if ((fa.nsargs != 0) | ( fa.nfargs != 7))
579                  return(-1);
580          printf("0\n0\n7");
581          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 412 | Line 587 | FILE  *fin;
587   }
588  
589  
590 < m_mist(fin)             /* transform arguments for mist */
591 < FILE  *fin;
590 > int
591 > m_mist(         /* transform arguments for mist */
592 >        FILE  *fin
593 > )
594   {
595          FUNARGS  fa;
596          int     i;
# Line 429 | Line 606 | FILE  *fin;
606          else
607                  for (i = 0; i < fa.nsargs; i++) {
608                          char    sname[256], *sp;
609 <                        register char   *cp1, *cp2 = sname;
609 >                        char    *cp1, *cp2 = sname;
610                                                          /* add idprefix */
611                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
612                                  for (cp1 = idprefix; *cp1; )
# Line 454 | Line 631 | FILE  *fin;
631   }
632  
633  
634 < m_dielectric(fin)               /* transform arguments for dielectric */
635 < FILE  *fin;
634 > int
635 > m_dielectric(           /* transform arguments for dielectric */
636 >        FILE  *fin
637 > )
638   {
639          FUNARGS  fa;
640  
# Line 474 | Line 653 | FILE  *fin;
653   }
654  
655  
656 < m_interface(fin)                /* transform arguments for interface */
657 < FILE  *fin;
656 > int
657 > m_interface(            /* transform arguments for interface */
658 >        FILE  *fin
659 > )
660   {
661          FUNARGS  fa;
662  
# Line 499 | Line 680 | FILE  *fin;
680   }
681  
682  
683 < text(fin)                       /* transform text arguments */
684 < FILE  *fin;
683 > int
684 > text(                   /* transform text arguments */
685 >        FILE  *fin
686 > )
687   {
688          int  i;
689          FVECT  v;
# Line 512 | Line 695 | FILE  *fin;
695                  return(-1);
696                                          /* string arguments */
697          printf("%d", fa.nsargs);
698 <        for (i = 0; i < fa.nsargs; i++)
699 <                printf(" %s", fa.sarg[i]);
698 >        for (i = 0; i < fa.nsargs; i++) {
699 >                fputc(' ', stdout);
700 >                fputword(fa.sarg[i], stdout);
701 >        }
702          printf("\n0\n%d\n", fa.nfargs);
703                                          /* anchor point */
704          multp3(v, fa.farg, tot.xfm);
# Line 536 | Line 721 | FILE  *fin;
721   }
722  
723  
724 < o_source(fin)                   /* transform source arguments */
725 < FILE  *fin;
724 > int
725 > o_source(                       /* transform source arguments */
726 >        FILE  *fin
727 > )
728   {
729          FVECT  dv;
730          FUNARGS  fa;
# Line 557 | Line 744 | FILE  *fin;
744   }
745  
746  
747 < o_sphere(fin)                   /* transform sphere arguments */
748 < FILE  *fin;
747 > int
748 > o_sphere(                       /* transform sphere arguments */
749 >        FILE  *fin
750 > )
751   {
752          FVECT  cent;
753          double  rad;
# Line 581 | Line 770 | FILE  *fin;
770   }
771  
772  
773 < o_face(fin)                     /* transform face arguments */
774 < FILE  *fin;
773 > int
774 > o_face(                 /* transform face arguments */
775 >        FILE  *fin
776 > )
777   {
778          FVECT  p;
779 <        register int  i;
779 >        int  i;
780          FUNARGS  fa;
781  
782          if (readfargs(&fa, fin) != 1)
# Line 607 | Line 798 | FILE  *fin;
798   }
799  
800  
801 < o_cone(fin)                     /* transform cone and cup arguments */
802 < FILE  *fin;
801 > int
802 > o_cone(                 /* transform cone and cup arguments */
803 >        FILE  *fin
804 > )
805   {
806          FVECT  p0, p1;
807          double  r0, r1;
# Line 634 | Line 827 | FILE  *fin;
827   }
828  
829  
830 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
831 < FILE  *fin;
830 > int
831 > o_cylinder(                     /* transform cylinder and tube arguments */
832 >        FILE  *fin
833 > )
834   {
835          FVECT  p0, p1;
836          double  rad;
# Line 659 | Line 854 | FILE  *fin;
854   }
855  
856  
857 < o_ring(fin)                     /* transform ring arguments */
858 < FILE  *fin;
857 > int
858 > o_ring(                 /* transform ring arguments */
859 >        FILE  *fin
860 > )
861   {
862          FVECT  p0, pd;
863          double  r0, r1;
# Line 690 | Line 887 | FILE  *fin;
887   }
888  
889  
890 < initotypes()                    /* initialize ofun[] array */
890 > void
891 > initotypes(void)                        /* initialize ofun[] array */
892   {
893 <        register int  i;
893 >        int  i;
894  
895          if (ofun[OBJ_SOURCE].funp == o_source)
896                  return;                 /* done already */
699                                        /* alias is additional */
700        ofun[ALIAS].funame = ALIASID;
701        ofun[ALIAS].flags = 0;
897                                          /* functions get new transform */
898 <        for (i = 0; i < NUMTYPES; i++)
898 >        for (i = 0; i < NUMOTYPE; i++)
899                  if (hasfunc(i))
900                          ofun[i].funp = addxform;
901                                          /* special cases */
# Line 713 | Line 908 | initotypes()                   /* initialize ofun[] array */
908          ofun[OBJ_CYLINDER].funp =
909          ofun[OBJ_TUBE].funp = o_cylinder;
910          ofun[OBJ_RING].funp = o_ring;
911 <        ofun[OBJ_INSTANCE].funp = addxform;
911 >        ofun[OBJ_INSTANCE].funp =
912 >        ofun[OBJ_MESH].funp = addxform;
913          ofun[MAT_GLOW].funp = m_glow;
914          ofun[MAT_SPOT].funp = m_spot;
915          ofun[MAT_DIELECTRIC].funp = m_dielectric;
# Line 722 | Line 918 | initotypes()                   /* initialize ofun[] array */
918          ofun[PAT_CTEXT].funp =
919          ofun[PAT_BTEXT].funp =
920          ofun[MIX_TEXT].funp = text;
921 <        ofun[ALIAS].funp = alias;
921 >        ofun[MOD_ALIAS].funp = alias;
922                                          /* surface inverses */
923          tinvers[OBJ_FACE] = OBJ_FACE;
924          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 734 | Line 930 | initotypes()                   /* initialize ofun[] array */
930          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
931          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
932          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
933 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
934   }
935  
936  
937   #ifdef  OLDXFORM
938 < openmain(fname)
939 < char  *fname;
938 > void
939 > openmain(
940 >        char  *fname
941 > )
942   {
943          if (fname == NULL) {
944                  strcpy(mainfn, "standard input");
# Line 761 | Line 960 | char  *fname;
960          strcpy(mainfn, fname);
961   }
962   #else
963 < openmain(fname)         /* open fname for input, changing to its directory */
964 < char  *fname;
963 > void
964 > openmain(               /* open input, changing directory for file */
965 >        char  *iname
966 > )
967   {
968 <        extern FILE  *tmpfile();
969 <        extern char  *getlibpath(), *getpath();
769 <        static char  origdir[MAXPATH];
770 <        static char  curfn[MAXPATH];
968 >        static char  origdir[PATH_MAX];
969 >        static char  curfn[PATH_MAX];
970          static int  diffdir;
971 <        register char  *fpath;
971 >        char  *fpath;
972  
973 <        if (fname == NULL) {                    /* standard input */
973 >        if (iname == NULL) {                    /* standard input */
974                  if (mainfp == NULL) {
975 <                        register int  c;
975 >                        int  c;
976                          strcpy(mainfn, "standard input");
977                          if (nrept <= 1) {
978                                  mainfp = stdin;
# Line 788 | Line 987 | char  *fname;
987                          }
988                          while ((c = getc(stdin)) != EOF)
989                                  putc(c, mainfp);
791                        fclose(stdin);
990                  }
991                  rewind(mainfp);                 /* rewind copy */
992                  return;
993          }
994          if (mainfp == NULL) {                   /* first call, initialize */
995 <                getwd(origdir);
996 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
995 >                getcwd(origdir, sizeof(origdir));
996 >        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
997                  rewind(mainfp);
998                  return;
999          } else {                                /* else close old stream */
1000                  fclose(mainfp);
1001 <                if (diffdir) {
1001 >                mainfp = NULL;
1002 >                if (diffdir) {                  /* return to our directory */
1003                          chdir(origdir);
1004                          diffdir = 0;
1005                  }
1006          }
1007 <        strcpy(curfn, fname);                   /* remember file name */
1008 <                                                /* get full path */
1009 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
1007 >        strcpy(curfn, iname);                   /* remember input name */
1008 >                                                /* get full path for file */
1009 >        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1010                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
1011 <                                progname, fname);
1011 >                                progname, iname);
1012                  exit(1);
1013          }
1014          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 817 | Line 1016 | char  *fname;
1016                                                  /* record path name */
1017          strcpy(mainfn, fpath);
1018          if (expand) {                           /* change to local directory */
1019 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1019 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1020                  while (cp > fpath) {
1021                          cp--;
1022                          if (ISDIRSEP(*cp)) {
# Line 837 | Line 1036 | char  *fname;
1036                          diffdir++;
1037                  }
1038                                                  /* get final path component */
1039 <                for (fpath = fname+strlen(fname);
1040 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
1039 >                for (fpath = iname+strlen(iname);
1040 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1041                          ;
1042          }
1043 <                                                /* open the file */
1043 >                                                /* finally, open the file */
1044          if ((mainfp = fopen(fpath, "r")) == NULL) {
1045                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
1046                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines