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.18 by gwlarson, Fri Jun 4 15:51:04 1999 UTC vs.
Revision 2.49 by greg, Tue Feb 2 18:02:32 2016 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 + #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
22 + #undef getc
23 + #define getc    getc_unlocked
24 + #endif
25 +
26   int  xac;                               /* global xform argument count */
27   char  **xav;                            /* global xform argument pointer */
28   int  xfa;                               /* start of xf arguments */
# Line 29 | Line 30 | int  xfa;                              /* start of xf arguments */
30   XF  tot;                                /* total transformation */
31   int  reverse;                           /* boolean true if scene mirrored */
32  
33 < int  invert = 0;                        /* boolean true to invert surfaces */
33 > int  invert;                            /* boolean true to invert surfaces */
34  
35 < int  expand = 1;                        /* boolean true to expand commands */
35 > int  expand;                            /* boolean true to expand commands */
36  
37 < char  *newmod = NULL;                   /* new modifier for surfaces */
37 > char  *newmod;                          /* new modifier for surfaces */
38  
39 < char  *idprefix = NULL;                 /* prefix for object identifiers */
39 > char  *idprefix;                        /* prefix for object identifiers */
40  
41 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
41 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
42  
42 #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
43
44 FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
45
43   short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
44  
45   int  nrept = 1;                         /* number of array repetitions */
46  
47   int stdinused = 0;                      /* stdin has been used by -f option? */
48  
49 < extern char  *malloc(), *fgets(), *fgetword();
53 <
54 < char  mainfn[MAXPATH];                  /* main file name */
49 > char  mainfn[PATH_MAX];                 /* main file name */
50   FILE  *mainfp = NULL;                   /* main file pointer */
51  
52   #define  progname  (xav[0])
53  
54 + static int doargf(int ac, char **av, int fi);
55 + static int doarray(int ac, char **av, int ai);
56 + static void xform(char *name, FILE *fin);
57 + static void xfcomm(char *fname, FILE *fin);
58 + static void xfobject(char *fname, FILE *fin);
59 + static int addxform(FILE *fin);
60 + static int alias(FILE *fin);
61 + void initotypes(void); /* XXX conflict with otypes.h */
62 + static void openmain(char *iname);
63  
64 < main(argc, argv)                /* get transform options and transform file */
65 < int  argc;
66 < char  *argv[];
64 >
65 > int
66 > main(           /* get transform options and transform file */
67 >        int  argc,
68 >        char  *argv[]
69 > )
70   {
71 <        char  *fname;
71 >        int  mal_prefix = 0;
72          int  a;
73                                          /* check for argument list file */
74          for (a = 1; a < argc; a++)
# Line 72 | Line 79 | char  *argv[];
79                  if (!strcmp(argv[a], "-a"))
80                          return(doarray(argc, argv, a));
81  
82 <        initotypes();
82 >        initotypes();                   /* initialize */
83 >        invert = 0;
84 >        expand = 1;
85 >        newmod = NULL;
86 >        idprefix = NULL;
87  
88          for (a = 1; a < argc; a++) {
89                  if (argv[a][0] == '-')
90                          switch (argv[a][1]) {
91                          case 'm':
92 <                                if (argv[a][2] || a+1 >= argc)
92 >                                if (argv[a][2] | (a+1 >= argc))
93                                          break;
94 <                                newmod = argv[++a];
94 >                                a++;
95 >                                if (newmod == NULL)
96 >                                        newmod = argv[a];
97                                  continue;
98                          case 'n':
99 <                                if (argv[a][2] || a+1 >= argc)
99 >                                if (argv[a][2] | (a+1 >= argc))
100                                          break;
101 <                                idprefix = argv[++a];
101 >                                a++;
102 >                                if (idprefix == NULL)
103 >                                        idprefix = argv[a];
104 >                                else {
105 >                                        char    *newp;
106 >                                        newp = (char *)malloc(strlen(idprefix)+
107 >                                                        strlen(argv[a])+2);
108 >                                        if (newp == NULL)
109 >                                                exit(2);
110 >                                        sprintf(newp, "%s.%s",
111 >                                                        idprefix, argv[a]);
112 >                                        if (mal_prefix++)
113 >                                                free(idprefix);
114 >                                        idprefix = newp;
115 >                                }
116                                  continue;
117                          case 'c':
118                                  if (argv[a][2])
# Line 100 | Line 127 | char  *argv[];
127                          case 'I':
128                                  if (argv[a][2])
129                                          break;
130 <                                invert = 1;
130 >                                invert = !invert;
131                                  continue;
132                          }
133                  break;
# Line 111 | Line 138 | char  *argv[];
138  
139          a += xf(&tot, argc-a, argv+a);
140  
141 <        if (reverse = tot.sca < 0.0)
141 >        if ( (reverse = (tot.sca < 0.0)) )
142                  tot.sca = -tot.sca;
143          if (invert)
144                  reverse = !reverse;
# Line 143 | Line 170 | char  *argv[];
170                          xform(mainfn, mainfp);
171                  }
172  
173 +        if (mal_prefix)
174 +                free(idprefix);
175          return(0);
176   }
177  
178  
179 < doargf(ac, av, fi)                      /* take argument list from file */
180 < char  **av;
181 < int  ac, fi;
179 > int
180 > doargf(                 /* take argument list from file */
181 >        int ac,
182 >        char  **av,
183 >        int fi
184 > )
185   {
186 +        int  inquote;
187          char  *newav[256], **avp;
188          char  argbuf[2048];
189 <        char  newid[128];
189 >        char  *newid, newidbuf[128];
190          char  *oldid;
191 <        register char   *cp;
191 >        char    *cp;
192          FILE    *argfp;
193          int  n, i, k, newac, err;
194          
# Line 165 | Line 198 | int  ac, fi;
198          }
199          if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
200                  if (stdinused++) {
201 <                        fprintf(stderr, "%s: cannot use stdin more than once\n",
201 >                        fprintf(stderr,
202 >                                "%s: cannot use stdin more than once\n",
203                                          av[0]);
204                          exit(1);
205                  }
# Line 173 | Line 207 | int  ac, fi;
207                  n = 100;                /* we just don't know! */
208          } else {
209                  if ((argfp = fopen(av[fi+1], "r")) == NULL) {
210 <                        fprintf(stderr, "%s: cannot open argument file \"%s\"\n",
210 >                        fprintf(stderr,
211 >                                "%s: cannot open argument file \"%s\"\n",
212                                          av[0], av[fi+1]);
213                          exit(1);
214                  }
215                  n = 0;                  /* count number of lines in file */
216 <                while (fgets(argbuf,sizeof(argbuf),argfp) != NULL)
217 <                        n += argbuf[0] != '\n' & argbuf[0] != '#';
216 >                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
217 >                        n += argbuf[0] && argbuf[0] != '#';
218                  if (!n) {
219                          fprintf(stderr, "%s: empty argument file \"%s\"\n",
220                                          av[0], av[fi+1]);
# Line 189 | Line 224 | int  ac, fi;
224                  rewind(argfp);
225          }
226          err = 0; k = 0;                 /* read each arg list and call main */
227 <        while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) {
228 <                if (argbuf[0] == '\n' | argbuf[0] == '#')
227 >        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
228 >                if (!argbuf[0] || argbuf[0] == '#')
229                          continue;
230                  avp = newav+2;
231                  avp[0] = av[0];
232                  for (i = 1; i < fi; i++)
233                          avp[i] = av[i];
234                  newac = i;
235 <                cp = argbuf;                    /* parse new words */
235 >                cp = argbuf;            /* parse new words */
236 >                if (*cp == '!') cp++;
237 >                if (!strncmp(cp, "xform ", 6)) cp += 6;
238 >                inquote = 0;
239                  for ( ; ; ) {
240 +                skipspaces:
241                          while (isspace(*cp))    /* nullify spaces */
242                                  *cp++ = '\0';
243 +                        if ((*cp == '"') | (*cp == '\''))
244 +                                inquote = *cp++;
245                          if (!*cp)               /* all done? */
246                                  break;
247 +                        if (cp[0] == '\\' && cp[1])
248 +                                if (*++cp == '\n')
249 +                                        goto skipspaces;
250                          avp[newac++] = cp;      /* add argument to list */
251 <                        while (*++cp && !isspace(*cp))
252 <                                ;
251 >                        if (inquote) {
252 >                                while (*++cp)
253 >                                        if (*cp == inquote) {
254 >                                                *cp++ = '\0';
255 >                                                break;
256 >                                        }
257 >                        } else {
258 >                                while (*++cp && !isspace(*cp))
259 >                                        ;
260 >                        }
261                  }
262                  for (i = fi+2; i < ac; i++)
263                          avp[newac++] = av[i];
264                  avp[newac] = NULL;
265 +                newid = newidbuf;
266                  oldid = NULL;
267                  for (i = 2; i < newac; i++)
268                          if (!strcmp(avp[i-1], "-n")) {
269                                  oldid = avp[i];
270 +                                if (strlen(oldid)+32 > sizeof(newidbuf)) {
271 +                                        newid = (char *)malloc(strlen(oldid)+32);
272 +                                        if (newid == NULL)
273 +                                                exit(2);
274 +                                }
275                                  avp[i] = newid;
276                                  break;
277                          }
# Line 229 | Line 287 | int  ac, fi;
287                  else
288                          sprintf(newid, "%s.%d", oldid, k);
289                  err |= main(newac, avp);
290 +                if (newid != newidbuf)
291 +                        free(newid);
292                  k++;
293          }
294          fclose(argfp);
# Line 236 | Line 296 | int  ac, fi;
296   }
297  
298  
299 < doarray(ac, av, ai)                     /* make array */
300 < char  **av;
301 < int  ac, ai;
299 > int
300 > doarray(                        /* make array */
301 >        int  ac,
302 >        char  **av,
303 >        int  ai
304 > )
305   {
306          char  *newav[256], **avp;
307          char  newid[128], repts[32];
# Line 281 | Line 344 | int  ac, ai;
344   }
345  
346  
347 < xform(name, fin)                        /* transform stream by tot.xfm */
348 < char  *name;
349 < register FILE  *fin;
347 > void
348 > xform(                  /* transform stream by tot.xfm */
349 >        char  *name,
350 >        FILE  *fin
351 > )
352   {
353          int  nobjs = 0;
354 <        register int  c;
354 >        int  c;
355  
356          while ((c = getc(fin)) != EOF) {
357                  if (isspace(c))                         /* blank */
# Line 314 | Line 379 | register FILE  *fin;
379   }
380  
381  
382 < xfcomm(fname, fin)                      /* transform a command */
383 < char  *fname;
384 < FILE  *fin;
382 > void
383 > xfcomm(                 /* transform a command */
384 >        char  *fname,
385 >        FILE  *fin
386 > )
387   {
321        extern FILE  *popen();
322        extern char  *fgetline();
388          FILE  *pin;
389 <        char  buf[512];
389 >        char  buf[2048];
390          int  i;
391  
392          fgetline(buf, sizeof(buf), fin);
# Line 336 | Line 401 | FILE  *fin;
401          } else {
402                  printf("\n%s", buf);
403                  if (xac > 1) {
404 <                        printf(" | %s", xav[0]);
404 >                        printf(" | %s -e", xav[0]);     /* expand next time */
405                          for (i = 1; i < xac; i++)
406 <                                printf(" %s", xav[i]);
406 >                                if (i >= xfa || strcmp(xav[i], "-c"))
407 >                                        printf(" %s", xav[i]);
408                  }
409                  putchar('\n');
410          }
411   }
412  
413  
414 < xfobject(fname, fin)                            /* transform an object */
415 < char  *fname;
416 < FILE  *fin;
414 > void
415 > xfobject(                               /* transform an object */
416 >        char  *fname,
417 >        FILE  *fin
418 > )
419   {
352        extern char  *strcpy();
420          char  typ[16], nam[MAXSTR];
421          int  fn;
422                                                  /* modifier and type */
# Line 361 | Line 428 | FILE  *fin;
428                                  progname, fname, typ);
429                  exit(1);
430          }
431 <        if (ismodifier(fn))
432 <                printf("\n%s %s ", nam, typ);
433 <        else
434 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
435 <                                invert ? ofun[tinvers[fn]].funame : typ);
431 >        putchar('\n');
432 >        if (ismodifier(fn)) {
433 >                fputword(nam, stdout);
434 >                printf(" %s ", typ);
435 >        } else {
436 >                fputword(newmod != NULL ? newmod : nam, stdout);
437 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
438 >        }
439                                                  /* object name */
440          fgetword(nam, sizeof(nam), fin);
441          if (idprefix == NULL || ismodifier(fn))
442 <                printf("%s\n", nam);
443 <        else
444 <                printf("%s.%s\n", idprefix, nam);
442 >                fputword(nam, stdout);
443 >        else {
444 >                char    nnam[MAXSTR];
445 >                sprintf(nnam, "%s.%s", idprefix, nam);
446 >                fputword(nnam, stdout);
447 >        }
448 >        putchar('\n');
449                                                  /* transform arguments */
450          if ((*ofun[fn].funp)(fin) < 0) {
451                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 381 | Line 455 | FILE  *fin;
455   }
456  
457  
458 < o_default(fin)                  /* pass on arguments unchanged */
459 < FILE  *fin;
458 > int
459 > o_default(                      /* pass on arguments unchanged */
460 >        FILE  *fin
461 > )
462   {
463 <        register int  i;
463 >        int  i;
464          FUNARGS  fa;
465  
466          if (readfargs(&fa, fin) != 1)
467                  return(-1);
468                                          /* string arguments */
469          printf("%d", fa.nsargs);
470 <        for (i = 0; i < fa.nsargs; i++)
471 <                printf(" %s", fa.sarg[i]);
470 >        for (i = 0; i < fa.nsargs; i++) {
471 >                fputc(' ', stdout);
472 >                fputword(fa.sarg[i], stdout);
473 >        }
474          printf("\n");
475   #ifdef  IARGS
476                                          /* integer arguments */
# Line 413 | Line 491 | FILE  *fin;
491   }
492  
493  
494 < addxform(fin)                   /* add xf arguments to strings */
495 < FILE  *fin;
494 > int
495 > addxform(                       /* add xf arguments to strings */
496 >        FILE  *fin
497 > )
498   {
499 <        register int  i;
499 >        int  i;
500          int  resetarr = 0;
501          FUNARGS  fa;
502  
# Line 426 | Line 506 | FILE  *fin;
506          if (xac > xfa && strcmp(xav[xfa], "-i"))
507                  resetarr = 2;
508          printf("%d", fa.nsargs + resetarr + xac-xfa);
509 <        for (i = 0; i < fa.nsargs; i++)
510 <                printf(" %s", fa.sarg[i]);
509 >        for (i = 0; i < fa.nsargs; i++) {
510 >                fputc(' ', stdout);
511 >                fputword(fa.sarg[i], stdout);
512 >        }
513          if (resetarr)
514                  printf(" -i 1");
515          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 453 | Line 535 | FILE  *fin;
535  
536  
537   int
538 < otype(ofname)                   /* get object function number from its name */
539 < register char  *ofname;
538 > alias(                  /* transfer alias */
539 >        FILE  *fin
540 > )
541   {
459        register int  i;
460
461        for (i = 0; i < NUMTYPES; i++)
462                if (!strcmp(ofun[i].funame, ofname))
463                        return(i);
464
465        return(-1);             /* not found */
466 }
467
468
469 alias(fin)                      /* transfer alias */
470 FILE  *fin;
471 {
542          char  aliasnm[MAXSTR];
543  
544          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 478 | Line 548 | FILE  *fin;
548   }
549  
550  
551 < m_glow(fin)                     /* transform arguments for proximity light */
552 < FILE  *fin;
551 > int
552 > m_glow(                 /* transform arguments for proximity light */
553 >        FILE  *fin
554 > )
555   {
556          FUNARGS  fa;
557  
# Line 496 | Line 568 | FILE  *fin;
568   }
569  
570  
571 < m_spot(fin)                     /* transform arguments for spotlight */
572 < FILE  *fin;
571 > int
572 > m_spot(                 /* transform arguments for spotlight */
573 >        FILE  *fin
574 > )
575   {
576          FVECT  v;
577          FUNARGS  fa;
# Line 516 | Line 590 | FILE  *fin;
590   }
591  
592  
593 < m_mist(fin)             /* transform arguments for mist */
594 < FILE  *fin;
593 > int
594 > m_mist(         /* transform arguments for mist */
595 >        FILE  *fin
596 > )
597   {
598          FUNARGS  fa;
599          int     i;
# Line 533 | Line 609 | FILE  *fin;
609          else
610                  for (i = 0; i < fa.nsargs; i++) {
611                          char    sname[256], *sp;
612 <                        register char   *cp1, *cp2 = sname;
612 >                        char    *cp1, *cp2 = sname;
613                                                          /* add idprefix */
614                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
615                                  for (cp1 = idprefix; *cp1; )
# Line 558 | Line 634 | FILE  *fin;
634   }
635  
636  
637 < m_dielectric(fin)               /* transform arguments for dielectric */
638 < FILE  *fin;
637 > int
638 > m_dielectric(           /* transform arguments for dielectric */
639 >        FILE  *fin
640 > )
641   {
642          FUNARGS  fa;
643  
# Line 578 | Line 656 | FILE  *fin;
656   }
657  
658  
659 < m_interface(fin)                /* transform arguments for interface */
660 < FILE  *fin;
659 > int
660 > m_interface(            /* transform arguments for interface */
661 >        FILE  *fin
662 > )
663   {
664          FUNARGS  fa;
665  
# Line 603 | Line 683 | FILE  *fin;
683   }
684  
685  
686 < text(fin)                       /* transform text arguments */
687 < FILE  *fin;
686 > int
687 > text(                   /* transform text arguments */
688 >        FILE  *fin
689 > )
690   {
691          int  i;
692          FVECT  v;
# Line 616 | Line 698 | FILE  *fin;
698                  return(-1);
699                                          /* string arguments */
700          printf("%d", fa.nsargs);
701 <        for (i = 0; i < fa.nsargs; i++)
702 <                printf(" %s", fa.sarg[i]);
701 >        for (i = 0; i < fa.nsargs; i++) {
702 >                fputc(' ', stdout);
703 >                fputword(fa.sarg[i], stdout);
704 >        }
705          printf("\n0\n%d\n", fa.nfargs);
706                                          /* anchor point */
707          multp3(v, fa.farg, tot.xfm);
# Line 640 | Line 724 | FILE  *fin;
724   }
725  
726  
727 < o_source(fin)                   /* transform source arguments */
728 < FILE  *fin;
727 > int
728 > o_source(                       /* transform source arguments */
729 >        FILE  *fin
730 > )
731   {
732          FVECT  dv;
733          FUNARGS  fa;
# Line 661 | Line 747 | FILE  *fin;
747   }
748  
749  
750 < o_sphere(fin)                   /* transform sphere arguments */
751 < FILE  *fin;
750 > int
751 > o_sphere(                       /* transform sphere arguments */
752 >        FILE  *fin
753 > )
754   {
755          FVECT  cent;
756          double  rad;
# Line 685 | Line 773 | FILE  *fin;
773   }
774  
775  
776 < o_face(fin)                     /* transform face arguments */
777 < FILE  *fin;
776 > int
777 > o_face(                 /* transform face arguments */
778 >        FILE  *fin
779 > )
780   {
781          FVECT  p;
782 <        register int  i;
782 >        int  i;
783          FUNARGS  fa;
784  
785          if (readfargs(&fa, fin) != 1)
# Line 711 | Line 801 | FILE  *fin;
801   }
802  
803  
804 < o_cone(fin)                     /* transform cone and cup arguments */
805 < FILE  *fin;
804 > int
805 > o_cone(                 /* transform cone and cup arguments */
806 >        FILE  *fin
807 > )
808   {
809          FVECT  p0, p1;
810          double  r0, r1;
# Line 738 | Line 830 | FILE  *fin;
830   }
831  
832  
833 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
834 < FILE  *fin;
833 > int
834 > o_cylinder(                     /* transform cylinder and tube arguments */
835 >        FILE  *fin
836 > )
837   {
838          FVECT  p0, p1;
839          double  rad;
# Line 763 | Line 857 | FILE  *fin;
857   }
858  
859  
860 < o_ring(fin)                     /* transform ring arguments */
861 < FILE  *fin;
860 > int
861 > o_ring(                 /* transform ring arguments */
862 >        FILE  *fin
863 > )
864   {
865          FVECT  p0, pd;
866          double  r0, r1;
# Line 794 | Line 890 | FILE  *fin;
890   }
891  
892  
893 < initotypes()                    /* initialize ofun[] array */
893 > void
894 > initotypes(void)                        /* initialize ofun[] array */
895   {
896 <        register int  i;
896 >        int  i;
897  
898          if (ofun[OBJ_SOURCE].funp == o_source)
899                  return;                 /* done already */
803                                        /* alias is additional */
804        ofun[ALIAS].funame = ALIASID;
805        ofun[ALIAS].flags = 0;
900                                          /* functions get new transform */
901 <        for (i = 0; i < NUMTYPES; i++)
901 >        for (i = 0; i < NUMOTYPE; i++)
902                  if (hasfunc(i))
903                          ofun[i].funp = addxform;
904                                          /* special cases */
# Line 817 | Line 911 | initotypes()                   /* initialize ofun[] array */
911          ofun[OBJ_CYLINDER].funp =
912          ofun[OBJ_TUBE].funp = o_cylinder;
913          ofun[OBJ_RING].funp = o_ring;
914 <        ofun[OBJ_INSTANCE].funp = addxform;
914 >        ofun[OBJ_INSTANCE].funp =
915 >        ofun[OBJ_MESH].funp = addxform;
916          ofun[MAT_GLOW].funp = m_glow;
917          ofun[MAT_SPOT].funp = m_spot;
918          ofun[MAT_DIELECTRIC].funp = m_dielectric;
# Line 826 | Line 921 | initotypes()                   /* initialize ofun[] array */
921          ofun[PAT_CTEXT].funp =
922          ofun[PAT_BTEXT].funp =
923          ofun[MIX_TEXT].funp = text;
924 <        ofun[ALIAS].funp = alias;
924 >        ofun[MOD_ALIAS].funp = alias;
925                                          /* surface inverses */
926          tinvers[OBJ_FACE] = OBJ_FACE;
927          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 838 | Line 933 | initotypes()                   /* initialize ofun[] array */
933          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
934          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
935          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
936 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
937   }
938  
939  
940   #ifdef  OLDXFORM
941 < openmain(fname)
942 < char  *fname;
941 > void
942 > openmain(
943 >        char  *fname
944 > )
945   {
946          if (fname == NULL) {
947                  strcpy(mainfn, "standard input");
# Line 865 | Line 963 | char  *fname;
963          strcpy(mainfn, fname);
964   }
965   #else
966 < openmain(fname)         /* open fname for input, changing to its directory */
967 < char  *fname;
966 > void
967 > openmain(               /* open input, changing directory for file */
968 >        char  *iname
969 > )
970   {
971 <        extern FILE  *tmpfile();
972 <        extern char  *getlibpath(), *getpath();
873 <        static char  origdir[MAXPATH];
874 <        static char  curfn[MAXPATH];
971 >        static char  origdir[PATH_MAX];
972 >        static char  curfn[PATH_MAX];
973          static int  diffdir;
974 <        register char  *fpath;
974 >        char  *fpath;
975  
976 <        if (fname == NULL) {                    /* standard input */
976 >        if (iname == NULL) {                    /* standard input */
977                  if (mainfp == NULL) {
978 <                        register int  c;
978 >                        int  c;
979                          strcpy(mainfn, "standard input");
980                          if (nrept <= 1) {
981                                  mainfp = stdin;
# Line 892 | Line 990 | char  *fname;
990                          }
991                          while ((c = getc(stdin)) != EOF)
992                                  putc(c, mainfp);
895                        fclose(stdin);
993                  }
994                  rewind(mainfp);                 /* rewind copy */
995                  return;
996          }
997          if (mainfp == NULL) {                   /* first call, initialize */
998 <                getwd(origdir);
999 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
998 >                getcwd(origdir, sizeof(origdir));
999 >        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
1000                  rewind(mainfp);
1001                  return;
1002          } else {                                /* else close old stream */
1003                  fclose(mainfp);
1004 <                if (diffdir) {
1004 >                mainfp = NULL;
1005 >                if (diffdir) {                  /* return to our directory */
1006                          chdir(origdir);
1007                          diffdir = 0;
1008                  }
1009          }
1010 <        strcpy(curfn, fname);                   /* remember file name */
1011 <                                                /* get full path */
1012 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
1010 >        strcpy(curfn, iname);                   /* remember input name */
1011 >                                                /* get full path for file */
1012 >        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1013                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
1014 <                                progname, fname);
1014 >                                progname, iname);
1015                  exit(1);
1016          }
1017          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 921 | Line 1019 | char  *fname;
1019                                                  /* record path name */
1020          strcpy(mainfn, fpath);
1021          if (expand) {                           /* change to local directory */
1022 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1022 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1023                  while (cp > fpath) {
1024                          cp--;
1025                          if (ISDIRSEP(*cp)) {
# Line 941 | Line 1039 | char  *fname;
1039                          diffdir++;
1040                  }
1041                                                  /* get final path component */
1042 <                for (fpath = fname+strlen(fname);
1043 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
1042 >                for (fpath = iname+strlen(iname);
1043 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1044                          ;
1045          }
1046 <                                                /* open the file */
1046 >                                                /* finally, open the file */
1047          if ((mainfp = fopen(fpath, "r")) == NULL) {
1048                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
1049                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines