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.13 by greg, Tue Jun 18 21:12:51 1996 UTC vs.
Revision 2.54 by greg, Sat Jun 7 05:09:45 2025 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  "rtio.h"
16 + #include  "rtmath.h"
17   #include  "object.h"
22
18   #include  "otypes.h"
19  
20   int  xac;                               /* global xform argument count */
# Line 29 | Line 24 | int  xfa;                              /* start of xf arguments */
24   XF  tot;                                /* total transformation */
25   int  reverse;                           /* boolean true if scene mirrored */
26  
27 < int  invert = 0;                        /* boolean true to invert surfaces */
27 > int  invert;                            /* boolean true to invert surfaces */
28  
29 < int  expand = 1;                        /* boolean true to expand commands */
29 > int  expand;                            /* boolean true to expand commands */
30  
31 < char  *newmod = NULL;                   /* new modifier for surfaces */
31 > char  *newmod;                          /* new modifier for surfaces */
32  
33 < char  *idprefix = NULL;                 /* prefix for object identifiers */
33 > char  *idprefix;                        /* prefix for object identifiers */
34  
35 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
35 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
36  
42 #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
43
44 FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
45
37   short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
38  
39   int  nrept = 1;                         /* number of array repetitions */
40  
41 < extern char  *malloc(), *fgetword();
41 > int stdinused = 0;                      /* stdin has been used by -f option? */
42  
43 < char  *mainfn[MAXPATH];                 /* main file name */
43 > char  mainfn[PATH_MAX];                 /* main file name */
44   FILE  *mainfp = NULL;                   /* main file pointer */
45  
46   #define  progname  (xav[0])
47  
48 + static int doargf(int ac, char **av, int fi);
49 + static int doarray(int ac, char **av, int ai);
50 + static void xform(char *name, FILE *fin);
51 + static void xfcomm(char *fname, FILE *fin);
52 + static void xfobject(char *fname, FILE *fin);
53 + static int addxform(FILE *fin);
54 + static int alias(FILE *fin);
55 + void initotypes(void); /* XXX conflict with otypes.h */
56 + static void openmain(char *iname);
57  
58 < main(argc, argv)                /* get transform options and transform file */
59 < int  argc;
60 < char  *argv[];
58 >
59 > int
60 > main(           /* get transform options and transform file */
61 >        int  argc,
62 >        char  *argv[]
63 > )
64   {
65 <        char  *fname;
65 >        int  mal_prefix = 0;
66          int  a;
67 <                                        /* check for array */
67 >                                        /* check for argument list file */
68          for (a = 1; a < argc; a++)
69 +                if (!strcmp(argv[a], "-f"))
70 +                        return(doargf(argc, argv, a));
71 +                                        /* check for regular array */
72 +        for (a = 1; a < argc; a++)
73                  if (!strcmp(argv[a], "-a"))
74                          return(doarray(argc, argv, a));
75  
76 <        initotypes();
76 >        initotypes();                   /* initialize */
77 >        invert = 0;
78 >        expand = 1;
79 >        newmod = NULL;
80 >        idprefix = NULL;
81  
82          for (a = 1; a < argc; a++) {
83                  if (argv[a][0] == '-')
84                          switch (argv[a][1]) {
85                          case 'm':
86 <                                if (argv[a][2] || a+1 >= argc)
86 >                                if (argv[a][2] | (a+1 >= argc))
87                                          break;
88 <                                newmod = argv[++a];
88 >                                a++;
89 >                                if (newmod == NULL)
90 >                                        newmod = argv[a];
91                                  continue;
92                          case 'n':
93 <                                if (argv[a][2] || a+1 >= argc)
93 >                                if (argv[a][2] | (a+1 >= argc))
94                                          break;
95 <                                idprefix = argv[++a];
95 >                                a++;
96 >                                if (idprefix == NULL)
97 >                                        idprefix = argv[a];
98 >                                else {
99 >                                        char    *newp;
100 >                                        newp = (char *)malloc(strlen(idprefix)+
101 >                                                        strlen(argv[a])+2);
102 >                                        if (newp == NULL)
103 >                                                exit(2);
104 >                                        sprintf(newp, "%s.%s",
105 >                                                        idprefix, argv[a]);
106 >                                        if (mal_prefix++)
107 >                                                free(idprefix);
108 >                                        idprefix = newp;
109 >                                }
110                                  continue;
111                          case 'c':
112                                  if (argv[a][2])
# Line 94 | Line 121 | char  *argv[];
121                          case 'I':
122                                  if (argv[a][2])
123                                          break;
124 <                                invert = 1;
124 >                                invert = !invert;
125                                  continue;
126                          }
127                  break;
# Line 105 | Line 132 | char  *argv[];
132  
133          a += xf(&tot, argc-a, argv+a);
134  
135 <        if (reverse = tot.sca < 0.0)
135 >        if ( (reverse = (tot.sca < 0.0)) )
136                  tot.sca = -tot.sca;
137          if (invert)
138                  reverse = !reverse;
# Line 124 | Line 151 | char  *argv[];
151          putchar('\n');
152                                          /* transform input */
153          if (xac == argc) {
154 +                if (stdinused) {
155 +                        fprintf(stderr, "%s: cannot use stdin more than once\n",
156 +                                        argv[0]);
157 +                        exit(1);
158 +                }
159                  openmain(NULL);
160                  xform(mainfn, mainfp);
161          } else
# Line 132 | Line 164 | char  *argv[];
164                          xform(mainfn, mainfp);
165                  }
166  
167 +        if (mal_prefix)
168 +                free(idprefix);
169          return(0);
170   }
171  
172  
173 < doarray(ac, av, ai)                     /* make array */
174 < char  **av;
175 < int  ac, ai;
173 > int
174 > doargf(                 /* take argument list from file */
175 >        int ac,
176 >        char  **av,
177 >        int fi
178 > )
179   {
180 +        int  inquote;
181          char  *newav[256], **avp;
182 +        char  argbuf[2048];
183 +        char  *newid, newidbuf[128];
184 +        char  *oldid;
185 +        char    *cp;
186 +        FILE    *argfp;
187 +        int  n, i, k, newac, err;
188 +        
189 +        if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) {
190 +                fprintf(stderr, "%s: missing file for -f option\n", av[0]);
191 +                exit(1);
192 +        }
193 +        if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
194 +                if (stdinused++) {
195 +                        fprintf(stderr,
196 +                                "%s: cannot use stdin more than once\n",
197 +                                        av[0]);
198 +                        exit(1);
199 +                }
200 +                argfp = stdin;
201 +                n = 100;                /* we just don't know! */
202 +        } else {
203 +                if ((argfp = fopen(av[fi+1], "r")) == NULL) {
204 +                        fprintf(stderr,
205 +                                "%s: cannot open argument file \"%s\"\n",
206 +                                        av[0], av[fi+1]);
207 +                        exit(1);
208 +                }
209 +                n = 0;                  /* count number of lines in file */
210 +                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
211 +                        n += (argbuf[0] != '\0') & (argbuf[0] != '#');
212 +                if (!n) {
213 +                        fprintf(stderr, "%s: empty argument file \"%s\"\n",
214 +                                        av[0], av[fi+1]);
215 +                        exit(1);
216 +                }
217 +                rewind(argfp);
218 +        }
219 +        nrept *= n;
220 +        err = 0; k = 0;                 /* read each arg list and call main */
221 +        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
222 +                if (!argbuf[0] | (argbuf[0] == '#')) {
223 +                        printf("%s\n", argbuf);
224 +                        continue;
225 +                }
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 +                newid = newidbuf;
262 +                oldid = NULL;
263 +                for (i = 2; i < newac; i++)
264 +                        if (!strcmp(avp[i-1], "-n")) {
265 +                                oldid = avp[i];
266 +                                if (strlen(oldid)+32 > sizeof(newidbuf)) {
267 +                                        newid = (char *)malloc(strlen(oldid)+32);
268 +                                        if (newid == NULL)
269 +                                                exit(2);
270 +                                }
271 +                                avp[i] = newid;
272 +                                break;
273 +                        }
274 +                if (oldid == NULL) {
275 +                        newav[0] = av[0];
276 +                        newav[1] = "-n";
277 +                        newav[2] = newid;
278 +                        avp = newav;
279 +                        newac += 2;
280 +                }
281 +                if (oldid == NULL)
282 +                        sprintf(newid, "i%d", k);
283 +                else
284 +                        sprintf(newid, "%s.%d", oldid, k);
285 +                err |= main(newac, avp);
286 +                if (newid != newidbuf)
287 +                        free(newid);
288 +                k++;
289 +        }
290 +        fclose(argfp);
291 +        return(err);
292 + }
293 +
294 +
295 + int
296 + doarray(                        /* make array */
297 +        int  ac,
298 +        char  **av,
299 +        int  ai
300 + )
301 + {
302 +        char  *newav[256], **avp;
303          char  newid[128], repts[32];
304          char  *oldid = NULL;
305          int  n, i, err;
306          
307 +        if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) {
308 +                fprintf(stderr, "%s: missing count for -a option\n", av[0]);
309 +                exit(1);
310 +        }
311 +        nrept *= n;
312          avp = newav+2;
313          avp[0] = av[0];
314          for (i = 1; i < ac; i++)
# Line 163 | Line 327 | int  ac, ai;
327                  avp = newav;
328                  ac += 2;
329          }
166        nrept *= n = atoi(av[ai+1]);
330          err = 0;
331          for (i = 0; i < n; i++) {
332                  if (oldid == NULL)
# Line 177 | Line 340 | int  ac, ai;
340   }
341  
342  
343 < xform(name, fin)                        /* transform stream by tot.xfm */
344 < char  *name;
345 < register FILE  *fin;
343 > void
344 > xform(                  /* transform stream by tot.xfm */
345 >        char  *name,
346 >        FILE  *fin
347 > )
348   {
349          int  nobjs = 0;
350 <        register int  c;
350 >        int  c;
351  
352          while ((c = getc(fin)) != EOF) {
353                  if (isspace(c))                         /* blank */
# Line 210 | Line 375 | register FILE  *fin;
375   }
376  
377  
378 < xfcomm(fname, fin)                      /* transform a command */
379 < char  *fname;
380 < FILE  *fin;
378 > void
379 > xfcomm(                 /* transform a command */
380 >        char  *fname,
381 >        FILE  *fin
382 > )
383   {
217        extern FILE  *popen();
218        extern char  *fgetline();
384          FILE  *pin;
385 <        char  buf[512];
385 >        char  buf[2048];
386          int  i;
387  
388          fgetline(buf, sizeof(buf), fin);
# Line 228 | Line 393 | FILE  *fin;
393                          exit(1);
394                  }
395                  xform(buf, pin);
396 <                pclose(pin);
396 >                if (pclose(pin) != 0)
397 >                        fprintf(stderr, "%s: (%s): warning - bad status from \"%s\"\n",
398 >                                        progname, fname, buf);
399          } else {
400                  printf("\n%s", buf);
401                  if (xac > 1) {
402 <                        printf(" | %s", xav[0]);
402 >                        printf(" | %s -e", xav[0]);     /* expand next time */
403                          for (i = 1; i < xac; i++)
404 <                                printf(" %s", xav[i]);
404 >                                if (i >= xfa || strcmp(xav[i], "-c"))
405 >                                        printf(" %s", xav[i]);
406                  }
407                  putchar('\n');
408          }
409   }
410  
411  
412 < xfobject(fname, fin)                            /* transform an object */
413 < char  *fname;
414 < FILE  *fin;
412 > void
413 > xfobject(                               /* transform an object */
414 >        char  *fname,
415 >        FILE  *fin
416 > )
417   {
248        extern char  *strcpy();
418          char  typ[16], nam[MAXSTR];
419          int  fn;
420                                                  /* modifier and type */
# Line 257 | Line 426 | FILE  *fin;
426                                  progname, fname, typ);
427                  exit(1);
428          }
429 <        if (ismodifier(fn))
430 <                printf("\n%s %s ", nam, typ);
431 <        else
432 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
433 <                                invert ? ofun[tinvers[fn]].funame : typ);
429 >        putchar('\n');
430 >        if (ismodifier(fn)) {
431 >                fputword(nam, stdout);
432 >                printf(" %s ", typ);
433 >        } else {
434 >                fputword(newmod != NULL ? newmod : nam, stdout);
435 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
436 >        }
437                                                  /* object name */
438          fgetword(nam, sizeof(nam), fin);
439          if (idprefix == NULL || ismodifier(fn))
440 <                printf("%s\n", nam);
441 <        else
442 <                printf("%s.%s\n", idprefix, nam);
440 >                fputword(nam, stdout);
441 >        else {
442 >                char    nnam[MAXSTR];
443 >                sprintf(nnam, "%s.%s", idprefix, nam);
444 >                fputword(nnam, stdout);
445 >        }
446 >        putchar('\n');
447                                                  /* transform arguments */
448          if ((*ofun[fn].funp)(fin) < 0) {
449                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 277 | Line 453 | FILE  *fin;
453   }
454  
455  
456 < o_default(fin)                  /* pass on arguments unchanged */
457 < FILE  *fin;
456 > int
457 > o_default(                      /* pass on arguments unchanged */
458 >        FILE  *fin
459 > )
460   {
461 <        register int  i;
461 >        int  i;
462          FUNARGS  fa;
463  
464          if (readfargs(&fa, fin) != 1)
465                  return(-1);
466                                          /* string arguments */
467          printf("%d", fa.nsargs);
468 <        for (i = 0; i < fa.nsargs; i++)
469 <                printf(" %s", fa.sarg[i]);
468 >        for (i = 0; i < fa.nsargs; i++) {
469 >                fputc(' ', stdout);
470 >                fputword(fa.sarg[i], stdout);
471 >        }
472          printf("\n");
473   #ifdef  IARGS
474                                          /* integer arguments */
# Line 309 | Line 489 | FILE  *fin;
489   }
490  
491  
492 < addxform(fin)                   /* add xf arguments to strings */
493 < FILE  *fin;
492 > int
493 > addxform(                       /* add xf arguments to strings */
494 >        FILE  *fin
495 > )
496   {
497 <        register int  i;
497 >        int  i;
498          int  resetarr = 0;
499          FUNARGS  fa;
500  
# Line 322 | Line 504 | FILE  *fin;
504          if (xac > xfa && strcmp(xav[xfa], "-i"))
505                  resetarr = 2;
506          printf("%d", fa.nsargs + resetarr + xac-xfa);
507 <        for (i = 0; i < fa.nsargs; i++)
508 <                printf(" %s", fa.sarg[i]);
507 >        for (i = 0; i < fa.nsargs; i++) {
508 >                fputc(' ', stdout);
509 >                fputword(fa.sarg[i], stdout);
510 >        }
511          if (resetarr)
512                  printf(" -i 1");
513          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 349 | Line 533 | FILE  *fin;
533  
534  
535   int
536 < otype(ofname)                   /* get object function number from its name */
537 < register char  *ofname;
536 > alias(                  /* transfer alias */
537 >        FILE  *fin
538 > )
539   {
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 {
540          char  aliasnm[MAXSTR];
541  
542          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 374 | Line 546 | FILE  *fin;
546   }
547  
548  
549 < m_glow(fin)                     /* transform arguments for proximity light */
550 < FILE  *fin;
549 > int
550 > m_glow(                 /* transform arguments for proximity light */
551 >        FILE  *fin
552 > )
553   {
554          FUNARGS  fa;
555  
556          if (readfargs(&fa, fin) != 1)
557                  return(-1);
558 <        if (fa.nsargs != 0  || fa.nfargs != 4)
558 >        if ((fa.nsargs != 0) | (fa.nfargs != 4))
559                  return(-1);
560          printf("0\n0\n4");
561          printf(" %18.12g %18.12g %18.12g",
# Line 392 | Line 566 | FILE  *fin;
566   }
567  
568  
569 < m_spot(fin)                     /* transform arguments for spotlight */
570 < FILE  *fin;
569 > int
570 > m_spot(                 /* transform arguments for spotlight */
571 >        FILE  *fin
572 > )
573   {
574          FVECT  v;
575          FUNARGS  fa;
576  
577          if (readfargs(&fa, fin) != 1)
578                  return(-1);
579 <        if (fa.nsargs != 0  || fa.nfargs != 7)
579 >        if ((fa.nsargs != 0) | ( fa.nfargs != 7))
580                  return(-1);
581          printf("0\n0\n7");
582          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 412 | Line 588 | FILE  *fin;
588   }
589  
590  
591 < m_mist(fin)             /* transform arguments for mist */
592 < FILE  *fin;
591 > int
592 > m_mist(         /* transform arguments for mist */
593 >        FILE  *fin
594 > )
595   {
596          FUNARGS  fa;
597          int     i;
598  
599          if (readfargs(&fa, fin) != 1)
600                  return(-1);
601 <        if (fa.nfargs > 5)
601 >        if (fa.nfargs > 7)
602                  return(-1);
603          printf("%d", fa.nsargs);
604          if (idprefix == NULL)
# Line 429 | Line 607 | FILE  *fin;
607          else
608                  for (i = 0; i < fa.nsargs; i++) {
609                          char    sname[256], *sp;
610 <                        register char   *cp1, *cp2 = sname;
610 >                        char    *cp1, *cp2 = sname;
611                                                          /* add idprefix */
612                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
613                                  for (cp1 = idprefix; *cp1; )
# Line 446 | Line 624 | FILE  *fin;
624          if (fa.nfargs > 2)
625                  printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
626                                  fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
627 <        if (fa.nfargs > 3)
628 <                printf(" %12.6g", fa.farg[3]);
451 <        if (fa.nfargs > 4)
452 <                printf(" %12.6g", fa.farg[4]);
627 >        for (i = 3; i < fa.nfargs; i++)
628 >                printf(" %12.6g", fa.farg[i]);
629          printf("\n");
630          freefargs(&fa);
631          return(0);
632   }
633  
634  
635 < m_dielectric(fin)               /* transform arguments for dielectric */
636 < FILE  *fin;
635 > int
636 > m_dielectric(           /* transform arguments for dielectric */
637 >        FILE  *fin
638 > )
639   {
640          FUNARGS  fa;
641  
# Line 476 | Line 654 | FILE  *fin;
654   }
655  
656  
657 < m_interface(fin)                /* transform arguments for interface */
658 < FILE  *fin;
657 > int
658 > m_interface(            /* transform arguments for interface */
659 >        FILE  *fin
660 > )
661   {
662          FUNARGS  fa;
663  
# Line 501 | Line 681 | FILE  *fin;
681   }
682  
683  
684 < text(fin)                       /* transform text arguments */
685 < FILE  *fin;
684 > int
685 > text(                   /* transform text arguments */
686 >        FILE  *fin
687 > )
688   {
689          int  i;
690          FVECT  v;
# Line 514 | Line 696 | FILE  *fin;
696                  return(-1);
697                                          /* string arguments */
698          printf("%d", fa.nsargs);
699 <        for (i = 0; i < fa.nsargs; i++)
700 <                printf(" %s", fa.sarg[i]);
699 >        for (i = 0; i < fa.nsargs; i++) {
700 >                fputc(' ', stdout);
701 >                fputword(fa.sarg[i], stdout);
702 >        }
703          printf("\n0\n%d\n", fa.nfargs);
704                                          /* anchor point */
705          multp3(v, fa.farg, tot.xfm);
# Line 538 | Line 722 | FILE  *fin;
722   }
723  
724  
725 < o_source(fin)                   /* transform source arguments */
726 < FILE  *fin;
725 > int
726 > o_source(                       /* transform source arguments */
727 >        FILE  *fin
728 > )
729   {
730          FVECT  dv;
731          FUNARGS  fa;
# Line 559 | Line 745 | FILE  *fin;
745   }
746  
747  
748 < o_sphere(fin)                   /* transform sphere arguments */
749 < FILE  *fin;
748 > int
749 > o_sphere(                       /* transform sphere arguments */
750 >        FILE  *fin
751 > )
752   {
753          FVECT  cent;
754          double  rad;
# Line 583 | Line 771 | FILE  *fin;
771   }
772  
773  
774 < o_face(fin)                     /* transform face arguments */
775 < FILE  *fin;
774 > int
775 > o_face(                 /* transform face arguments */
776 >        FILE  *fin
777 > )
778   {
779          FVECT  p;
780 <        register int  i;
780 >        int  i;
781          FUNARGS  fa;
782  
783          if (readfargs(&fa, fin) != 1)
# Line 609 | Line 799 | FILE  *fin;
799   }
800  
801  
802 < o_cone(fin)                     /* transform cone and cup arguments */
803 < FILE  *fin;
802 > int
803 > o_cone(                 /* transform cone and cup arguments */
804 >        FILE  *fin
805 > )
806   {
807          FVECT  p0, p1;
808          double  r0, r1;
# Line 636 | Line 828 | FILE  *fin;
828   }
829  
830  
831 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
832 < FILE  *fin;
831 > int
832 > o_cylinder(                     /* transform cylinder and tube arguments */
833 >        FILE  *fin
834 > )
835   {
836          FVECT  p0, p1;
837          double  rad;
# Line 661 | Line 855 | FILE  *fin;
855   }
856  
857  
858 < o_ring(fin)                     /* transform ring arguments */
859 < FILE  *fin;
858 > int
859 > o_ring(                 /* transform ring arguments */
860 >        FILE  *fin
861 > )
862   {
863          FVECT  p0, pd;
864          double  r0, r1;
# Line 692 | Line 888 | FILE  *fin;
888   }
889  
890  
891 < initotypes()                    /* initialize ofun[] array */
891 > void
892 > initotypes(void)                        /* initialize ofun[] array */
893   {
894 <        register int  i;
894 >        int  i;
895  
896          if (ofun[OBJ_SOURCE].funp == o_source)
897                  return;                 /* done already */
701                                        /* alias is additional */
702        ofun[ALIAS].funame = ALIASID;
703        ofun[ALIAS].flags = 0;
898                                          /* functions get new transform */
899 <        for (i = 0; i < NUMTYPES; i++)
899 >        for (i = 0; i < NUMOTYPE; i++)
900                  if (hasfunc(i))
901                          ofun[i].funp = addxform;
902                                          /* special cases */
# Line 715 | Line 909 | initotypes()                   /* initialize ofun[] array */
909          ofun[OBJ_CYLINDER].funp =
910          ofun[OBJ_TUBE].funp = o_cylinder;
911          ofun[OBJ_RING].funp = o_ring;
912 <        ofun[OBJ_INSTANCE].funp = addxform;
912 >        ofun[OBJ_INSTANCE].funp =
913 >        ofun[OBJ_MESH].funp = addxform;
914          ofun[MAT_GLOW].funp = m_glow;
915          ofun[MAT_SPOT].funp = m_spot;
916          ofun[MAT_DIELECTRIC].funp = m_dielectric;
# Line 724 | Line 919 | initotypes()                   /* initialize ofun[] array */
919          ofun[PAT_CTEXT].funp =
920          ofun[PAT_BTEXT].funp =
921          ofun[MIX_TEXT].funp = text;
922 <        ofun[ALIAS].funp = alias;
922 >        ofun[MOD_ALIAS].funp = alias;
923                                          /* surface inverses */
924          tinvers[OBJ_FACE] = OBJ_FACE;
925          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 736 | Line 931 | initotypes()                   /* initialize ofun[] array */
931          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
932          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
933          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
934 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
935   }
936  
937  
938   #ifdef  OLDXFORM
939 < openmain(fname)
940 < char  *fname;
939 > void
940 > openmain(
941 >        char  *fname
942 > )
943   {
944          if (fname == NULL) {
945                  strcpy(mainfn, "standard input");
# Line 763 | Line 961 | char  *fname;
961          strcpy(mainfn, fname);
962   }
963   #else
964 < openmain(fname)         /* open fname for input, changing to its directory */
965 < char  *fname;
964 > void
965 > openmain(               /* open input, changing directory for file */
966 >        char  *iname
967 > )
968   {
969 <        extern FILE  *tmpfile();
970 <        extern char  *getlibpath(), *getpath();
771 <        static char  origdir[MAXPATH];
772 <        static char  curfn[MAXPATH];
969 >        static char  origdir[PATH_MAX];
970 >        static char  curfn[PATH_MAX];
971          static int  diffdir;
972 <        register char  *fpath;
972 >        char  *fpath;
973  
974 <        if (fname == NULL) {                    /* standard input */
974 >        if (iname == NULL) {                    /* standard input */
975                  if (mainfp == NULL) {
976 <                        register int  c;
976 >                        int  c;
977                          strcpy(mainfn, "standard input");
978                          if (nrept <= 1) {
979                                  mainfp = stdin;
# Line 790 | Line 988 | char  *fname;
988                          }
989                          while ((c = getc(stdin)) != EOF)
990                                  putc(c, mainfp);
793                        fclose(stdin);
991                  }
992                  rewind(mainfp);                 /* rewind copy */
993                  return;
994          }
995          if (mainfp == NULL) {                   /* first call, initialize */
996 <                getwd(origdir);
997 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
996 >                getcwd(origdir, sizeof(origdir));
997 >        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
998                  rewind(mainfp);
999                  return;
1000          } else {                                /* else close old stream */
1001                  fclose(mainfp);
1002 <                if (diffdir) {
1002 >                mainfp = NULL;
1003 >                if (diffdir) {                  /* return to our directory */
1004                          chdir(origdir);
1005                          diffdir = 0;
1006                  }
1007          }
1008 <        strcpy(curfn, fname);                   /* remember file name */
1009 <                                                /* get full path */
1010 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
1008 >        strcpy(curfn, iname);                   /* remember input name */
1009 >                                                /* get full path for file */
1010 >        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1011                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
1012 <                                progname, fname);
1012 >                                progname, iname);
1013                  exit(1);
1014          }
1015          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 819 | Line 1017 | char  *fname;
1017                                                  /* record path name */
1018          strcpy(mainfn, fpath);
1019          if (expand) {                           /* change to local directory */
1020 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1020 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1021                  while (cp > fpath) {
1022                          cp--;
1023                          if (ISDIRSEP(*cp)) {
# Line 839 | Line 1037 | char  *fname;
1037                          diffdir++;
1038                  }
1039                                                  /* get final path component */
1040 <                for (fpath = fname+strlen(fname);
1041 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
1040 >                for (fpath = iname+strlen(iname);
1041 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1042                          ;
1043          }
1044 <                                                /* open the file */
1044 >                                                /* finally, open the file */
1045          if ((mainfp = fopen(fpath, "r")) == NULL) {
1046                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
1047                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines