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.52 by greg, Tue Apr 22 04:45:25 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): bad status from \"%s\"\n",
399 >                                        progname, fname, buf);
400 >                        exit(1);
401 >                }
402          } else {
403                  printf("\n%s", buf);
404                  if (xac > 1) {
# Line 371 | Line 412 | FILE  *fin;
412   }
413  
414  
415 < xfobject(fname, fin)                            /* transform an object */
416 < char  *fname;
417 < FILE  *fin;
415 > void
416 > xfobject(                               /* transform an object */
417 >        char  *fname,
418 >        FILE  *fin
419 > )
420   {
378        extern char  *strcpy();
421          char  typ[16], nam[MAXSTR];
422          int  fn;
423                                                  /* modifier and type */
# Line 387 | Line 429 | FILE  *fin;
429                                  progname, fname, typ);
430                  exit(1);
431          }
432 <        if (ismodifier(fn))
433 <                printf("\n%s %s ", nam, typ);
434 <        else
435 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
436 <                                invert ? ofun[tinvers[fn]].funame : typ);
432 >        putchar('\n');
433 >        if (ismodifier(fn)) {
434 >                fputword(nam, stdout);
435 >                printf(" %s ", typ);
436 >        } else {
437 >                fputword(newmod != NULL ? newmod : nam, stdout);
438 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
439 >        }
440                                                  /* object name */
441          fgetword(nam, sizeof(nam), fin);
442          if (idprefix == NULL || ismodifier(fn))
443 <                printf("%s\n", nam);
444 <        else
445 <                printf("%s.%s\n", idprefix, nam);
443 >                fputword(nam, stdout);
444 >        else {
445 >                char    nnam[MAXSTR];
446 >                sprintf(nnam, "%s.%s", idprefix, nam);
447 >                fputword(nnam, stdout);
448 >        }
449 >        putchar('\n');
450                                                  /* transform arguments */
451          if ((*ofun[fn].funp)(fin) < 0) {
452                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 407 | Line 456 | FILE  *fin;
456   }
457  
458  
459 < o_default(fin)                  /* pass on arguments unchanged */
460 < FILE  *fin;
459 > int
460 > o_default(                      /* pass on arguments unchanged */
461 >        FILE  *fin
462 > )
463   {
464 <        register int  i;
464 >        int  i;
465          FUNARGS  fa;
466  
467          if (readfargs(&fa, fin) != 1)
468                  return(-1);
469                                          /* string arguments */
470          printf("%d", fa.nsargs);
471 <        for (i = 0; i < fa.nsargs; i++)
472 <                printf(" %s", fa.sarg[i]);
471 >        for (i = 0; i < fa.nsargs; i++) {
472 >                fputc(' ', stdout);
473 >                fputword(fa.sarg[i], stdout);
474 >        }
475          printf("\n");
476   #ifdef  IARGS
477                                          /* integer arguments */
# Line 439 | Line 492 | FILE  *fin;
492   }
493  
494  
495 < addxform(fin)                   /* add xf arguments to strings */
496 < FILE  *fin;
495 > int
496 > addxform(                       /* add xf arguments to strings */
497 >        FILE  *fin
498 > )
499   {
500 <        register int  i;
500 >        int  i;
501          int  resetarr = 0;
502          FUNARGS  fa;
503  
# Line 452 | Line 507 | FILE  *fin;
507          if (xac > xfa && strcmp(xav[xfa], "-i"))
508                  resetarr = 2;
509          printf("%d", fa.nsargs + resetarr + xac-xfa);
510 <        for (i = 0; i < fa.nsargs; i++)
511 <                printf(" %s", fa.sarg[i]);
510 >        for (i = 0; i < fa.nsargs; i++) {
511 >                fputc(' ', stdout);
512 >                fputword(fa.sarg[i], stdout);
513 >        }
514          if (resetarr)
515                  printf(" -i 1");
516          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 479 | Line 536 | FILE  *fin;
536  
537  
538   int
539 < otype(ofname)                   /* get object function number from its name */
540 < register char  *ofname;
539 > alias(                  /* transfer alias */
540 >        FILE  *fin
541 > )
542   {
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 {
543          char  aliasnm[MAXSTR];
544  
545          if (fgetword(aliasnm, MAXSTR, fin) == NULL)
# Line 504 | Line 549 | FILE  *fin;
549   }
550  
551  
552 < m_glow(fin)                     /* transform arguments for proximity light */
553 < FILE  *fin;
552 > int
553 > m_glow(                 /* transform arguments for proximity light */
554 >        FILE  *fin
555 > )
556   {
557          FUNARGS  fa;
558  
559          if (readfargs(&fa, fin) != 1)
560                  return(-1);
561 <        if (fa.nsargs != 0  || fa.nfargs != 4)
561 >        if ((fa.nsargs != 0) | (fa.nfargs != 4))
562                  return(-1);
563          printf("0\n0\n4");
564          printf(" %18.12g %18.12g %18.12g",
# Line 522 | Line 569 | FILE  *fin;
569   }
570  
571  
572 < m_spot(fin)                     /* transform arguments for spotlight */
573 < FILE  *fin;
572 > int
573 > m_spot(                 /* transform arguments for spotlight */
574 >        FILE  *fin
575 > )
576   {
577          FVECT  v;
578          FUNARGS  fa;
579  
580          if (readfargs(&fa, fin) != 1)
581                  return(-1);
582 <        if (fa.nsargs != 0  || fa.nfargs != 7)
582 >        if ((fa.nsargs != 0) | ( fa.nfargs != 7))
583                  return(-1);
584          printf("0\n0\n7");
585          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 542 | Line 591 | FILE  *fin;
591   }
592  
593  
594 < m_mist(fin)             /* transform arguments for mist */
595 < FILE  *fin;
594 > int
595 > m_mist(         /* transform arguments for mist */
596 >        FILE  *fin
597 > )
598   {
599          FUNARGS  fa;
600          int     i;
# Line 559 | Line 610 | FILE  *fin;
610          else
611                  for (i = 0; i < fa.nsargs; i++) {
612                          char    sname[256], *sp;
613 <                        register char   *cp1, *cp2 = sname;
613 >                        char    *cp1, *cp2 = sname;
614                                                          /* add idprefix */
615                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
616                                  for (cp1 = idprefix; *cp1; )
# Line 584 | Line 635 | FILE  *fin;
635   }
636  
637  
638 < m_dielectric(fin)               /* transform arguments for dielectric */
639 < FILE  *fin;
638 > int
639 > m_dielectric(           /* transform arguments for dielectric */
640 >        FILE  *fin
641 > )
642   {
643          FUNARGS  fa;
644  
# Line 604 | Line 657 | FILE  *fin;
657   }
658  
659  
660 < m_interface(fin)                /* transform arguments for interface */
661 < FILE  *fin;
660 > int
661 > m_interface(            /* transform arguments for interface */
662 >        FILE  *fin
663 > )
664   {
665          FUNARGS  fa;
666  
# Line 629 | Line 684 | FILE  *fin;
684   }
685  
686  
687 < text(fin)                       /* transform text arguments */
688 < FILE  *fin;
687 > int
688 > text(                   /* transform text arguments */
689 >        FILE  *fin
690 > )
691   {
692          int  i;
693          FVECT  v;
# Line 642 | Line 699 | FILE  *fin;
699                  return(-1);
700                                          /* string arguments */
701          printf("%d", fa.nsargs);
702 <        for (i = 0; i < fa.nsargs; i++)
703 <                printf(" %s", fa.sarg[i]);
702 >        for (i = 0; i < fa.nsargs; i++) {
703 >                fputc(' ', stdout);
704 >                fputword(fa.sarg[i], stdout);
705 >        }
706          printf("\n0\n%d\n", fa.nfargs);
707                                          /* anchor point */
708          multp3(v, fa.farg, tot.xfm);
# Line 666 | Line 725 | FILE  *fin;
725   }
726  
727  
728 < o_source(fin)                   /* transform source arguments */
729 < FILE  *fin;
728 > int
729 > o_source(                       /* transform source arguments */
730 >        FILE  *fin
731 > )
732   {
733          FVECT  dv;
734          FUNARGS  fa;
# Line 687 | Line 748 | FILE  *fin;
748   }
749  
750  
751 < o_sphere(fin)                   /* transform sphere arguments */
752 < FILE  *fin;
751 > int
752 > o_sphere(                       /* transform sphere arguments */
753 >        FILE  *fin
754 > )
755   {
756          FVECT  cent;
757          double  rad;
# Line 711 | Line 774 | FILE  *fin;
774   }
775  
776  
777 < o_face(fin)                     /* transform face arguments */
778 < FILE  *fin;
777 > int
778 > o_face(                 /* transform face arguments */
779 >        FILE  *fin
780 > )
781   {
782          FVECT  p;
783 <        register int  i;
783 >        int  i;
784          FUNARGS  fa;
785  
786          if (readfargs(&fa, fin) != 1)
# Line 737 | Line 802 | FILE  *fin;
802   }
803  
804  
805 < o_cone(fin)                     /* transform cone and cup arguments */
806 < FILE  *fin;
805 > int
806 > o_cone(                 /* transform cone and cup arguments */
807 >        FILE  *fin
808 > )
809   {
810          FVECT  p0, p1;
811          double  r0, r1;
# Line 764 | Line 831 | FILE  *fin;
831   }
832  
833  
834 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
835 < FILE  *fin;
834 > int
835 > o_cylinder(                     /* transform cylinder and tube arguments */
836 >        FILE  *fin
837 > )
838   {
839          FVECT  p0, p1;
840          double  rad;
# Line 789 | Line 858 | FILE  *fin;
858   }
859  
860  
861 < o_ring(fin)                     /* transform ring arguments */
862 < FILE  *fin;
861 > int
862 > o_ring(                 /* transform ring arguments */
863 >        FILE  *fin
864 > )
865   {
866          FVECT  p0, pd;
867          double  r0, r1;
# Line 820 | Line 891 | FILE  *fin;
891   }
892  
893  
894 < initotypes()                    /* initialize ofun[] array */
894 > void
895 > initotypes(void)                        /* initialize ofun[] array */
896   {
897 <        register int  i;
897 >        int  i;
898  
899          if (ofun[OBJ_SOURCE].funp == o_source)
900                  return;                 /* done already */
829                                        /* alias is additional */
830        ofun[ALIAS].funame = ALIASID;
831        ofun[ALIAS].flags = 0;
901                                          /* functions get new transform */
902 <        for (i = 0; i < NUMTYPES; i++)
902 >        for (i = 0; i < NUMOTYPE; i++)
903                  if (hasfunc(i))
904                          ofun[i].funp = addxform;
905                                          /* special cases */
# Line 843 | Line 912 | initotypes()                   /* initialize ofun[] array */
912          ofun[OBJ_CYLINDER].funp =
913          ofun[OBJ_TUBE].funp = o_cylinder;
914          ofun[OBJ_RING].funp = o_ring;
915 <        ofun[OBJ_INSTANCE].funp = addxform;
915 >        ofun[OBJ_INSTANCE].funp =
916 >        ofun[OBJ_MESH].funp = addxform;
917          ofun[MAT_GLOW].funp = m_glow;
918          ofun[MAT_SPOT].funp = m_spot;
919          ofun[MAT_DIELECTRIC].funp = m_dielectric;
# Line 852 | Line 922 | initotypes()                   /* initialize ofun[] array */
922          ofun[PAT_CTEXT].funp =
923          ofun[PAT_BTEXT].funp =
924          ofun[MIX_TEXT].funp = text;
925 <        ofun[ALIAS].funp = alias;
925 >        ofun[MOD_ALIAS].funp = alias;
926                                          /* surface inverses */
927          tinvers[OBJ_FACE] = OBJ_FACE;
928          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 864 | Line 934 | initotypes()                   /* initialize ofun[] array */
934          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
935          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
936          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
937 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
938   }
939  
940  
941   #ifdef  OLDXFORM
942 < openmain(fname)
943 < char  *fname;
942 > void
943 > openmain(
944 >        char  *fname
945 > )
946   {
947          if (fname == NULL) {
948                  strcpy(mainfn, "standard input");
# Line 891 | Line 964 | char  *fname;
964          strcpy(mainfn, fname);
965   }
966   #else
967 < openmain(fname)         /* open fname for input, changing to its directory */
968 < char  *fname;
967 > void
968 > openmain(               /* open input, changing directory for file */
969 >        char  *iname
970 > )
971   {
972 <        extern FILE  *tmpfile();
973 <        extern char  *getlibpath(), *getpath();
899 <        static char  origdir[MAXPATH];
900 <        static char  curfn[MAXPATH];
972 >        static char  origdir[PATH_MAX];
973 >        static char  curfn[PATH_MAX];
974          static int  diffdir;
975 <        register char  *fpath;
975 >        char  *fpath;
976  
977 <        if (fname == NULL) {                    /* standard input */
977 >        if (iname == NULL) {                    /* standard input */
978                  if (mainfp == NULL) {
979 <                        register int  c;
979 >                        int  c;
980                          strcpy(mainfn, "standard input");
981                          if (nrept <= 1) {
982                                  mainfp = stdin;
# Line 918 | Line 991 | char  *fname;
991                          }
992                          while ((c = getc(stdin)) != EOF)
993                                  putc(c, mainfp);
921                        fclose(stdin);
994                  }
995                  rewind(mainfp);                 /* rewind copy */
996                  return;
997          }
998          if (mainfp == NULL) {                   /* first call, initialize */
999 <                getwd(origdir);
1000 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
999 >                getcwd(origdir, sizeof(origdir));
1000 >        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
1001                  rewind(mainfp);
1002                  return;
1003          } else {                                /* else close old stream */
1004                  fclose(mainfp);
1005 <                if (diffdir) {
1005 >                mainfp = NULL;
1006 >                if (diffdir) {                  /* return to our directory */
1007                          chdir(origdir);
1008                          diffdir = 0;
1009                  }
1010          }
1011 <        strcpy(curfn, fname);                   /* remember file name */
1012 <                                                /* get full path */
1013 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
1011 >        strcpy(curfn, iname);                   /* remember input name */
1012 >                                                /* get full path for file */
1013 >        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1014                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
1015 <                                progname, fname);
1015 >                                progname, iname);
1016                  exit(1);
1017          }
1018          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 947 | Line 1020 | char  *fname;
1020                                                  /* record path name */
1021          strcpy(mainfn, fpath);
1022          if (expand) {                           /* change to local directory */
1023 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1023 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1024                  while (cp > fpath) {
1025                          cp--;
1026                          if (ISDIRSEP(*cp)) {
# Line 967 | Line 1040 | char  *fname;
1040                          diffdir++;
1041                  }
1042                                                  /* get final path component */
1043 <                for (fpath = fname+strlen(fname);
1044 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
1043 >                for (fpath = iname+strlen(iname);
1044 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1045                          ;
1046          }
1047 <                                                /* open the file */
1047 >                                                /* finally, open the file */
1048          if ((mainfp = fopen(fpath, "r")) == NULL) {
1049                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
1050                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines