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.53 by greg, Tue Apr 22 14:51:29 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  "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 228 | Line 394 | FILE  *fin;
394                          exit(1);
395                  }
396                  xform(buf, pin);
397 <                pclose(pin);
397 >                if (pclose(pin) != 0)
398 >                        fprintf(stderr, "%s: (%s): warning - bad status from \"%s\"\n",
399 >                                        progname, fname, buf);
400          } else {
401                  printf("\n%s", buf);
402                  if (xac > 1) {
403 <                        printf(" | %s", xav[0]);
403 >                        printf(" | %s -e", xav[0]);     /* expand next time */
404                          for (i = 1; i < xac; i++)
405 <                                printf(" %s", xav[i]);
405 >                                if (i >= xfa || strcmp(xav[i], "-c"))
406 >                                        printf(" %s", xav[i]);
407                  }
408                  putchar('\n');
409          }
410   }
411  
412  
413 < xfobject(fname, fin)                            /* transform an object */
414 < char  *fname;
415 < FILE  *fin;
413 > void
414 > xfobject(                               /* transform an object */
415 >        char  *fname,
416 >        FILE  *fin
417 > )
418   {
248        extern char  *strcpy();
419          char  typ[16], nam[MAXSTR];
420          int  fn;
421                                                  /* modifier and type */
# Line 257 | Line 427 | FILE  *fin;
427                                  progname, fname, typ);
428                  exit(1);
429          }
430 <        if (ismodifier(fn))
431 <                printf("\n%s %s ", nam, typ);
432 <        else
433 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
434 <                                invert ? ofun[tinvers[fn]].funame : typ);
430 >        putchar('\n');
431 >        if (ismodifier(fn)) {
432 >                fputword(nam, stdout);
433 >                printf(" %s ", typ);
434 >        } else {
435 >                fputword(newmod != NULL ? newmod : nam, stdout);
436 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
437 >        }
438                                                  /* object name */
439          fgetword(nam, sizeof(nam), fin);
440          if (idprefix == NULL || ismodifier(fn))
441 <                printf("%s\n", nam);
442 <        else
443 <                printf("%s.%s\n", idprefix, nam);
441 >                fputword(nam, stdout);
442 >        else {
443 >                char    nnam[MAXSTR];
444 >                sprintf(nnam, "%s.%s", idprefix, nam);
445 >                fputword(nnam, stdout);
446 >        }
447 >        putchar('\n');
448                                                  /* transform arguments */
449          if ((*ofun[fn].funp)(fin) < 0) {
450                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 277 | Line 454 | FILE  *fin;
454   }
455  
456  
457 < o_default(fin)                  /* pass on arguments unchanged */
458 < FILE  *fin;
457 > int
458 > o_default(                      /* pass on arguments unchanged */
459 >        FILE  *fin
460 > )
461   {
462 <        register int  i;
462 >        int  i;
463          FUNARGS  fa;
464  
465          if (readfargs(&fa, fin) != 1)
466                  return(-1);
467                                          /* string arguments */
468          printf("%d", fa.nsargs);
469 <        for (i = 0; i < fa.nsargs; i++)
470 <                printf(" %s", fa.sarg[i]);
469 >        for (i = 0; i < fa.nsargs; i++) {
470 >                fputc(' ', stdout);
471 >                fputword(fa.sarg[i], stdout);
472 >        }
473          printf("\n");
474   #ifdef  IARGS
475                                          /* integer arguments */
# Line 309 | Line 490 | FILE  *fin;
490   }
491  
492  
493 < addxform(fin)                   /* add xf arguments to strings */
494 < FILE  *fin;
493 > int
494 > addxform(                       /* add xf arguments to strings */
495 >        FILE  *fin
496 > )
497   {
498 <        register int  i;
498 >        int  i;
499          int  resetarr = 0;
500          FUNARGS  fa;
501  
# Line 322 | Line 505 | FILE  *fin;
505          if (xac > xfa && strcmp(xav[xfa], "-i"))
506                  resetarr = 2;
507          printf("%d", fa.nsargs + resetarr + xac-xfa);
508 <        for (i = 0; i < fa.nsargs; i++)
509 <                printf(" %s", fa.sarg[i]);
508 >        for (i = 0; i < fa.nsargs; i++) {
509 >                fputc(' ', stdout);
510 >                fputword(fa.sarg[i], stdout);
511 >        }
512          if (resetarr)
513                  printf(" -i 1");
514          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 349 | Line 534 | FILE  *fin;
534  
535  
536   int
537 < otype(ofname)                   /* get object function number from its name */
538 < register char  *ofname;
537 > alias(                  /* transfer alias */
538 >        FILE  *fin
539 > )
540   {
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 {
541          char  aliasnm[MAXSTR];
542  
543          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 374 | Line 547 | FILE  *fin;
547   }
548  
549  
550 < m_glow(fin)                     /* transform arguments for proximity light */
551 < FILE  *fin;
550 > int
551 > m_glow(                 /* transform arguments for proximity light */
552 >        FILE  *fin
553 > )
554   {
555          FUNARGS  fa;
556  
557          if (readfargs(&fa, fin) != 1)
558                  return(-1);
559 <        if (fa.nsargs != 0  || fa.nfargs != 4)
559 >        if ((fa.nsargs != 0) | (fa.nfargs != 4))
560                  return(-1);
561          printf("0\n0\n4");
562          printf(" %18.12g %18.12g %18.12g",
# Line 392 | Line 567 | FILE  *fin;
567   }
568  
569  
570 < m_spot(fin)                     /* transform arguments for spotlight */
571 < FILE  *fin;
570 > int
571 > m_spot(                 /* transform arguments for spotlight */
572 >        FILE  *fin
573 > )
574   {
575          FVECT  v;
576          FUNARGS  fa;
577  
578          if (readfargs(&fa, fin) != 1)
579                  return(-1);
580 <        if (fa.nsargs != 0  || fa.nfargs != 7)
580 >        if ((fa.nsargs != 0) | ( fa.nfargs != 7))
581                  return(-1);
582          printf("0\n0\n7");
583          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 412 | Line 589 | FILE  *fin;
589   }
590  
591  
592 < m_mist(fin)             /* transform arguments for mist */
593 < FILE  *fin;
592 > int
593 > m_mist(         /* transform arguments for mist */
594 >        FILE  *fin
595 > )
596   {
597          FUNARGS  fa;
598          int     i;
599  
600          if (readfargs(&fa, fin) != 1)
601                  return(-1);
602 <        if (fa.nfargs > 5)
602 >        if (fa.nfargs > 7)
603                  return(-1);
604          printf("%d", fa.nsargs);
605          if (idprefix == NULL)
# Line 429 | Line 608 | FILE  *fin;
608          else
609                  for (i = 0; i < fa.nsargs; i++) {
610                          char    sname[256], *sp;
611 <                        register char   *cp1, *cp2 = sname;
611 >                        char    *cp1, *cp2 = sname;
612                                                          /* add idprefix */
613                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
614                                  for (cp1 = idprefix; *cp1; )
# Line 446 | Line 625 | FILE  *fin;
625          if (fa.nfargs > 2)
626                  printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
627                                  fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
628 <        if (fa.nfargs > 3)
629 <                printf(" %12.6g", fa.farg[3]);
451 <        if (fa.nfargs > 4)
452 <                printf(" %12.6g", fa.farg[4]);
628 >        for (i = 3; i < fa.nfargs; i++)
629 >                printf(" %12.6g", fa.farg[i]);
630          printf("\n");
631          freefargs(&fa);
632          return(0);
633   }
634  
635  
636 < m_dielectric(fin)               /* transform arguments for dielectric */
637 < FILE  *fin;
636 > int
637 > m_dielectric(           /* transform arguments for dielectric */
638 >        FILE  *fin
639 > )
640   {
641          FUNARGS  fa;
642  
# Line 476 | Line 655 | FILE  *fin;
655   }
656  
657  
658 < m_interface(fin)                /* transform arguments for interface */
659 < FILE  *fin;
658 > int
659 > m_interface(            /* transform arguments for interface */
660 >        FILE  *fin
661 > )
662   {
663          FUNARGS  fa;
664  
# Line 501 | Line 682 | FILE  *fin;
682   }
683  
684  
685 < text(fin)                       /* transform text arguments */
686 < FILE  *fin;
685 > int
686 > text(                   /* transform text arguments */
687 >        FILE  *fin
688 > )
689   {
690          int  i;
691          FVECT  v;
# Line 514 | Line 697 | FILE  *fin;
697                  return(-1);
698                                          /* string arguments */
699          printf("%d", fa.nsargs);
700 <        for (i = 0; i < fa.nsargs; i++)
701 <                printf(" %s", fa.sarg[i]);
700 >        for (i = 0; i < fa.nsargs; i++) {
701 >                fputc(' ', stdout);
702 >                fputword(fa.sarg[i], stdout);
703 >        }
704          printf("\n0\n%d\n", fa.nfargs);
705                                          /* anchor point */
706          multp3(v, fa.farg, tot.xfm);
# Line 538 | Line 723 | FILE  *fin;
723   }
724  
725  
726 < o_source(fin)                   /* transform source arguments */
727 < FILE  *fin;
726 > int
727 > o_source(                       /* transform source arguments */
728 >        FILE  *fin
729 > )
730   {
731          FVECT  dv;
732          FUNARGS  fa;
# Line 559 | Line 746 | FILE  *fin;
746   }
747  
748  
749 < o_sphere(fin)                   /* transform sphere arguments */
750 < FILE  *fin;
749 > int
750 > o_sphere(                       /* transform sphere arguments */
751 >        FILE  *fin
752 > )
753   {
754          FVECT  cent;
755          double  rad;
# Line 583 | Line 772 | FILE  *fin;
772   }
773  
774  
775 < o_face(fin)                     /* transform face arguments */
776 < FILE  *fin;
775 > int
776 > o_face(                 /* transform face arguments */
777 >        FILE  *fin
778 > )
779   {
780          FVECT  p;
781 <        register int  i;
781 >        int  i;
782          FUNARGS  fa;
783  
784          if (readfargs(&fa, fin) != 1)
# Line 609 | Line 800 | FILE  *fin;
800   }
801  
802  
803 < o_cone(fin)                     /* transform cone and cup arguments */
804 < FILE  *fin;
803 > int
804 > o_cone(                 /* transform cone and cup arguments */
805 >        FILE  *fin
806 > )
807   {
808          FVECT  p0, p1;
809          double  r0, r1;
# Line 636 | Line 829 | FILE  *fin;
829   }
830  
831  
832 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
833 < FILE  *fin;
832 > int
833 > o_cylinder(                     /* transform cylinder and tube arguments */
834 >        FILE  *fin
835 > )
836   {
837          FVECT  p0, p1;
838          double  rad;
# Line 661 | Line 856 | FILE  *fin;
856   }
857  
858  
859 < o_ring(fin)                     /* transform ring arguments */
860 < FILE  *fin;
859 > int
860 > o_ring(                 /* transform ring arguments */
861 >        FILE  *fin
862 > )
863   {
864          FVECT  p0, pd;
865          double  r0, r1;
# Line 692 | Line 889 | FILE  *fin;
889   }
890  
891  
892 < initotypes()                    /* initialize ofun[] array */
892 > void
893 > initotypes(void)                        /* initialize ofun[] array */
894   {
895 <        register int  i;
895 >        int  i;
896  
897          if (ofun[OBJ_SOURCE].funp == o_source)
898                  return;                 /* done already */
701                                        /* alias is additional */
702        ofun[ALIAS].funame = ALIASID;
703        ofun[ALIAS].flags = 0;
899                                          /* functions get new transform */
900 <        for (i = 0; i < NUMTYPES; i++)
900 >        for (i = 0; i < NUMOTYPE; i++)
901                  if (hasfunc(i))
902                          ofun[i].funp = addxform;
903                                          /* special cases */
# Line 715 | Line 910 | initotypes()                   /* initialize ofun[] array */
910          ofun[OBJ_CYLINDER].funp =
911          ofun[OBJ_TUBE].funp = o_cylinder;
912          ofun[OBJ_RING].funp = o_ring;
913 <        ofun[OBJ_INSTANCE].funp = addxform;
913 >        ofun[OBJ_INSTANCE].funp =
914 >        ofun[OBJ_MESH].funp = addxform;
915          ofun[MAT_GLOW].funp = m_glow;
916          ofun[MAT_SPOT].funp = m_spot;
917          ofun[MAT_DIELECTRIC].funp = m_dielectric;
# Line 724 | Line 920 | initotypes()                   /* initialize ofun[] array */
920          ofun[PAT_CTEXT].funp =
921          ofun[PAT_BTEXT].funp =
922          ofun[MIX_TEXT].funp = text;
923 <        ofun[ALIAS].funp = alias;
923 >        ofun[MOD_ALIAS].funp = alias;
924                                          /* surface inverses */
925          tinvers[OBJ_FACE] = OBJ_FACE;
926          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 736 | Line 932 | initotypes()                   /* initialize ofun[] array */
932          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
933          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
934          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
935 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
936   }
937  
938  
939   #ifdef  OLDXFORM
940 < openmain(fname)
941 < char  *fname;
940 > void
941 > openmain(
942 >        char  *fname
943 > )
944   {
945          if (fname == NULL) {
946                  strcpy(mainfn, "standard input");
# Line 763 | Line 962 | char  *fname;
962          strcpy(mainfn, fname);
963   }
964   #else
965 < openmain(fname)         /* open fname for input, changing to its directory */
966 < char  *fname;
965 > void
966 > openmain(               /* open input, changing directory for file */
967 >        char  *iname
968 > )
969   {
970 <        extern FILE  *tmpfile();
971 <        extern char  *getlibpath(), *getpath();
771 <        static char  origdir[MAXPATH];
772 <        static char  curfn[MAXPATH];
970 >        static char  origdir[PATH_MAX];
971 >        static char  curfn[PATH_MAX];
972          static int  diffdir;
973 <        register char  *fpath;
973 >        char  *fpath;
974  
975 <        if (fname == NULL) {                    /* standard input */
975 >        if (iname == NULL) {                    /* standard input */
976                  if (mainfp == NULL) {
977 <                        register int  c;
977 >                        int  c;
978                          strcpy(mainfn, "standard input");
979                          if (nrept <= 1) {
980                                  mainfp = stdin;
# Line 790 | Line 989 | char  *fname;
989                          }
990                          while ((c = getc(stdin)) != EOF)
991                                  putc(c, mainfp);
793                        fclose(stdin);
992                  }
993                  rewind(mainfp);                 /* rewind copy */
994                  return;
995          }
996          if (mainfp == NULL) {                   /* first call, initialize */
997 <                getwd(origdir);
998 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
997 >                getcwd(origdir, sizeof(origdir));
998 >        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
999                  rewind(mainfp);
1000                  return;
1001          } else {                                /* else close old stream */
1002                  fclose(mainfp);
1003 <                if (diffdir) {
1003 >                mainfp = NULL;
1004 >                if (diffdir) {                  /* return to our directory */
1005                          chdir(origdir);
1006                          diffdir = 0;
1007                  }
1008          }
1009 <        strcpy(curfn, fname);                   /* remember file name */
1010 <                                                /* get full path */
1011 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
1009 >        strcpy(curfn, iname);                   /* remember input name */
1010 >                                                /* get full path for file */
1011 >        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1012                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
1013 <                                progname, fname);
1013 >                                progname, iname);
1014                  exit(1);
1015          }
1016          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 819 | Line 1018 | char  *fname;
1018                                                  /* record path name */
1019          strcpy(mainfn, fpath);
1020          if (expand) {                           /* change to local directory */
1021 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1021 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1022                  while (cp > fpath) {
1023                          cp--;
1024                          if (ISDIRSEP(*cp)) {
# Line 839 | Line 1038 | char  *fname;
1038                          diffdir++;
1039                  }
1040                                                  /* get final path component */
1041 <                for (fpath = fname+strlen(fname);
1042 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
1041 >                for (fpath = iname+strlen(iname);
1042 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1043                          ;
1044          }
1045 <                                                /* open the file */
1045 >                                                /* finally, open the file */
1046          if ((mainfp = fopen(fpath, "r")) == NULL) {
1047                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
1048                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines