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.22 by gwlarson, Fri Jun 4 17:24:56 1999 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 37 | Line 33 | char  *newmod;                         /* new modifier for surfaces */
33  
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   int stdinused = 0;                      /* stdin has been used by -f option? */
43  
44 < extern char  *malloc(), *fgets(), *fgetword();
53 <
54 < 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          int  mal_prefix = 0;
65        char  *fname;
67          int  a;
68                                          /* check for argument list file */
69          for (a = 1; a < argc; a++)
# Line 83 | Line 84 | char  *argv[];
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                                  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                                  a++;
97                                  if (idprefix == NULL)
98                                          idprefix = argv[a];
99                                  else {
100 <                                        register char   *newp;
100 >                                        char    *newp;
101                                          newp = (char *)malloc(strlen(idprefix)+
102                                                          strlen(argv[a])+2);
103                                          if (newp == NULL)
# Line 104 | Line 105 | char  *argv[];
105                                          sprintf(newp, "%s.%s",
106                                                          idprefix, argv[a]);
107                                          if (mal_prefix++)
108 <                                                free((char *)idprefix);
108 >                                                free(idprefix);
109                                          idprefix = newp;
110                                  }
111                                  continue;
# Line 132 | 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 165 | Line 166 | char  *argv[];
166                  }
167  
168          if (mal_prefix)
169 <                free((char *)idprefix);
169 >                free(idprefix);
170          return(0);
171   }
172  
173  
174 < doargf(ac, av, fi)                      /* take argument list from file */
175 < char  **av;
176 < int  ac, fi;
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[1024];
184 <        char  newid[128];
183 >        char  argbuf[2048];
184 >        char  *newid, newidbuf[128];
185          char  *oldid;
186 <        register char   *cp;
186 >        char    *cp;
187          FILE    *argfp;
188          int  n, i, k, newac, err;
189          
# Line 188 | Line 193 | int  ac, fi;
193          }
194          if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
195                  if (stdinused++) {
196 <                        fprintf(stderr, "%s: cannot use stdin more than once\n",
196 >                        fprintf(stderr,
197 >                                "%s: cannot use stdin more than once\n",
198                                          av[0]);
199                          exit(1);
200                  }
# Line 196 | Line 202 | int  ac, fi;
202                  n = 100;                /* we just don't know! */
203          } else {
204                  if ((argfp = fopen(av[fi+1], "r")) == NULL) {
205 <                        fprintf(stderr, "%s: cannot open argument file \"%s\"\n",
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 (fgets(argbuf,sizeof(argbuf),argfp) != NULL)
212 <                        n += argbuf[0] != '\n' & argbuf[0] != '#';
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                  }
211                nrept *= n;
218                  rewind(argfp);
219          }
220 +        nrept *= n;
221          err = 0; k = 0;                 /* read each arg list and call main */
222 <        while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) {
223 <                if (argbuf[0] == '\n' | argbuf[0] == '#')
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++)
# Line 223 | Line 232 | int  ac, fi;
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 <                        while (*++cp && !isspace(*cp))
249 <                                ;
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                          }
# Line 254 | Line 284 | int  ac, fi;
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);
# Line 261 | Line 293 | int  ac, fi;
293   }
294  
295  
296 < doarray(ac, av, ai)                     /* make array */
297 < char  **av;
298 < int  ac, ai;
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];
# Line 306 | 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 339 | 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   {
346        extern FILE  *popen();
347        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 357 | 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) {
# Line 371 | Line 410 | FILE  *fin;
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   {
378        extern char  *strcpy();
419          char  typ[16], nam[MAXSTR];
420          int  fn;
421                                                  /* modifier and type */
# Line 387 | 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 407 | 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 439 | 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 452 | 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 479 | 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   {
485        register int  i;
486
487        for (i = 0; i < NUMTYPES; i++)
488                if (!strcmp(ofun[i].funame, ofname))
489                        return(i);
490
491        return(-1);             /* not found */
492 }
493
494
495 alias(fin)                      /* transfer alias */
496 FILE  *fin;
497 {
541          char  aliasnm[MAXSTR];
542  
543          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 504 | 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 522 | 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 542 | 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;
# Line 559 | 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 584 | Line 633 | FILE  *fin;
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 604 | 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 629 | 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 642 | 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 666 | 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 687 | 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 711 | 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 737 | 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 764 | 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 789 | 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 820 | 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 */
829                                        /* alias is additional */
830        ofun[ALIAS].funame = ALIASID;
831        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 843 | 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 852 | 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 864 | 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 891 | 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();
899 <        static char  origdir[MAXPATH];
900 <        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 918 | Line 989 | char  *fname;
989                          }
990                          while ((c = getc(stdin)) != EOF)
991                                  putc(c, mainfp);
921                        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 947 | 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 967 | 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