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.10 by greg, Fri Dec 8 18:29:06 1995 UTC vs.
Revision 2.34 by schorsch, Mon Oct 27 10:27:25 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 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
12   #include  <ctype.h>
13  
14 + #include  "platform.h"
15 + #include  "rtmath.h"
16 + #include  "rtprocess.h" /* win_popen() */
17 + #include  "paths.h"
18   #include  "object.h"
20
19   #include  "otypes.h"
20  
21   int  xac;                               /* global xform argument count */
# Line 27 | 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 = 0;                        /* 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  
38 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
38 > short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
39  
40 < FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
40 > int  nrept = 1;                         /* number of array repetitions */
41  
42 < short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
42 > int stdinused = 0;                      /* stdin has been used by -f option? */
43  
44 < extern char  *malloc(), *fgetword();
44 > char  mainfn[PATH_MAX];                 /* main file name */
45 > FILE  *mainfp = NULL;                   /* main file pointer */
46  
47   #define  progname  (xav[0])
48  
# Line 52 | Line 51 | main(argc, argv)               /* get transform options and transfo
51   int  argc;
52   char  *argv[];
53   {
54 <        FILE  *fopen();
55 <        FILE  *fp;
54 >        int  mal_prefix = 0;
55 >        char  *fname;
56          int  a;
57 <                                        /* check for array */
57 >                                        /* check for argument list file */
58          for (a = 1; a < argc; a++)
59 +                if (!strcmp(argv[a], "-f"))
60 +                        return(doargf(argc, argv, a));
61 +                                        /* check for regular array */
62 +        for (a = 1; a < argc; a++)
63                  if (!strcmp(argv[a], "-a"))
64                          return(doarray(argc, argv, a));
65  
66 <        initotypes();
66 >        initotypes();                   /* initialize */
67 >        invert = 0;
68 >        expand = 1;
69 >        newmod = NULL;
70 >        idprefix = NULL;
71  
72          for (a = 1; a < argc; a++) {
73                  if (argv[a][0] == '-')
74                          switch (argv[a][1]) {
75                          case 'm':
76 <                                if (argv[a][2] || a+1 >= argc)
76 >                                if (argv[a][2] | (a+1 >= argc))
77                                          break;
78 <                                newmod = argv[++a];
78 >                                a++;
79 >                                if (newmod == NULL)
80 >                                        newmod = argv[a];
81                                  continue;
82                          case 'n':
83 <                                if (argv[a][2] || a+1 >= argc)
83 >                                if (argv[a][2] | (a+1 >= argc))
84                                          break;
85 <                                idprefix = argv[++a];
85 >                                a++;
86 >                                if (idprefix == NULL)
87 >                                        idprefix = argv[a];
88 >                                else {
89 >                                        register char   *newp;
90 >                                        newp = (char *)malloc(strlen(idprefix)+
91 >                                                        strlen(argv[a])+2);
92 >                                        if (newp == NULL)
93 >                                                exit(2);
94 >                                        sprintf(newp, "%s.%s",
95 >                                                        idprefix, argv[a]);
96 >                                        if (mal_prefix++)
97 >                                                free((void *)idprefix);
98 >                                        idprefix = newp;
99 >                                }
100                                  continue;
101 +                        case 'c':
102 +                                if (argv[a][2])
103 +                                        break;
104 +                                expand = 0;
105 +                                continue;
106                          case 'e':
107                                  if (argv[a][2])
108                                          break;
# Line 83 | Line 111 | char  *argv[];
111                          case 'I':
112                                  if (argv[a][2])
113                                          break;
114 <                                invert = 1;
114 >                                invert = !invert;
115                                  continue;
116                          }
117                  break;
# Line 94 | Line 122 | char  *argv[];
122  
123          a += xf(&tot, argc-a, argv+a);
124  
125 <        if (reverse = tot.sca < 0.0)
125 >        if ( (reverse = tot.sca < 0.0) )
126                  tot.sca = -tot.sca;
127          if (invert)
128                  reverse = !reverse;
# Line 112 | Line 140 | char  *argv[];
140                  printf(" %s", xav[a]);
141          putchar('\n');
142                                          /* transform input */
143 <        if (xac == argc)
144 <                xform("standard input", stdin);
145 <        else
143 >        if (xac == argc) {
144 >                if (stdinused) {
145 >                        fprintf(stderr, "%s: cannot use stdin more than once\n",
146 >                                        argv[0]);
147 >                        exit(1);
148 >                }
149 >                openmain(NULL);
150 >                xform(mainfn, mainfp);
151 >        } else
152                  for (a = xac; a < argc; a++) {
153 <                        if ((fp = fopen(argv[a], "r")) == NULL) {
154 <                                fprintf(stderr, "%s: cannot open \"%s\"\n",
121 <                                                progname, argv[a]);
122 <                                exit(1);
123 <                        }
124 <                        xform(argv[a], fp);
125 <                        fclose(fp);
153 >                        openmain(argv[a]);
154 >                        xform(mainfn, mainfp);
155                  }
156  
157 +        if (mal_prefix)
158 +                free((void *)idprefix);
159          return(0);
160   }
161  
162  
163 + doargf(ac, av, fi)                      /* take argument list from file */
164 + char  **av;
165 + int  ac, fi;
166 + {
167 +        int  inquote;
168 +        char  *newav[256], **avp;
169 +        char  argbuf[1024];
170 +        char  newid[128];
171 +        char  *oldid;
172 +        register char   *cp;
173 +        FILE    *argfp;
174 +        int  n, i, k, newac, err;
175 +        
176 +        if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) {
177 +                fprintf(stderr, "%s: missing file for -f option\n", av[0]);
178 +                exit(1);
179 +        }
180 +        if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
181 +                if (stdinused++) {
182 +                        fprintf(stderr,
183 +                                "%s: cannot use stdin more than once\n",
184 +                                        av[0]);
185 +                        exit(1);
186 +                }
187 +                argfp = stdin;
188 +                n = 100;                /* we just don't know! */
189 +        } else {
190 +                if ((argfp = fopen(av[fi+1], "r")) == NULL) {
191 +                        fprintf(stderr,
192 +                                "%s: cannot open argument file \"%s\"\n",
193 +                                        av[0], av[fi+1]);
194 +                        exit(1);
195 +                }
196 +                n = 0;                  /* count number of lines in file */
197 +                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
198 +                        n += argbuf[0] && argbuf[0] != '#';
199 +                if (!n) {
200 +                        fprintf(stderr, "%s: empty argument file \"%s\"\n",
201 +                                        av[0], av[fi+1]);
202 +                        exit(1);
203 +                }
204 +                nrept *= n;
205 +                rewind(argfp);
206 +        }
207 +        err = 0; k = 0;                 /* read each arg list and call main */
208 +        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
209 +                if (!argbuf[0] || argbuf[0] == '#')
210 +                        continue;
211 +                avp = newav+2;
212 +                avp[0] = av[0];
213 +                for (i = 1; i < fi; i++)
214 +                        avp[i] = av[i];
215 +                newac = i;
216 +                cp = argbuf;            /* parse new words */
217 +                if (*cp == '!') cp++;
218 +                if (!strncmp(cp, "xform ", 6)) cp += 6;
219 +                inquote = 0;
220 +                for ( ; ; ) {
221 +                skipspaces:
222 +                        while (isspace(*cp))    /* nullify spaces */
223 +                                *cp++ = '\0';
224 +                        if ((*cp == '"') | (*cp == '\''))
225 +                                inquote = *cp++;
226 +                        if (!*cp)               /* all done? */
227 +                                break;
228 +                        if (cp[0] == '\\' && cp[1])
229 +                                if (*++cp == '\n')
230 +                                        goto skipspaces;
231 +                        avp[newac++] = cp;      /* add argument to list */
232 +                        if (inquote) {
233 +                                while (*++cp)
234 +                                        if (*cp == inquote) {
235 +                                                *cp++ = '\0';
236 +                                                break;
237 +                                        }
238 +                        } else {
239 +                                while (*++cp && !isspace(*cp))
240 +                                        ;
241 +                        }
242 +                }
243 +                for (i = fi+2; i < ac; i++)
244 +                        avp[newac++] = av[i];
245 +                avp[newac] = NULL;
246 +                oldid = NULL;
247 +                for (i = 2; i < newac; i++)
248 +                        if (!strcmp(avp[i-1], "-n")) {
249 +                                oldid = avp[i];
250 +                                avp[i] = newid;
251 +                                break;
252 +                        }
253 +                if (oldid == NULL) {
254 +                        newav[0] = av[0];
255 +                        newav[1] = "-n";
256 +                        newav[2] = newid;
257 +                        avp = newav;
258 +                        newac += 2;
259 +                }
260 +                if (oldid == NULL)
261 +                        sprintf(newid, "i%d", k);
262 +                else
263 +                        sprintf(newid, "%s.%d", oldid, k);
264 +                err |= main(newac, avp);
265 +                k++;
266 +        }
267 +        fclose(argfp);
268 +        return(err);
269 + }
270 +
271 +
272   doarray(ac, av, ai)                     /* make array */
273   char  **av;
274   int  ac, ai;
# Line 136 | Line 276 | int  ac, ai;
276          char  *newav[256], **avp;
277          char  newid[128], repts[32];
278          char  *oldid = NULL;
279 <        int  i, err;
279 >        int  n, i, err;
280          
281 +        if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) {
282 +                fprintf(stderr, "%s: missing count for -a option\n", av[0]);
283 +                exit(1);
284 +        }
285 +        nrept *= n;
286          avp = newav+2;
287          avp[0] = av[0];
288          for (i = 1; i < ac; i++)
# Line 157 | Line 302 | int  ac, ai;
302                  ac += 2;
303          }
304          err = 0;
305 <        for (i = 0; i < atoi(av[ai+1]); i++) {
305 >        for (i = 0; i < n; i++) {
306                  if (oldid == NULL)
307                          sprintf(newid, "a%d", i);
308                  else
# Line 206 | Line 351 | xfcomm(fname, fin)                     /* transform a command */
351   char  *fname;
352   FILE  *fin;
353   {
209        FILE  *popen();
210        char  *fgetline();
354          FILE  *pin;
355          char  buf[512];
356          int  i;
# Line 224 | Line 367 | FILE  *fin;
367          } else {
368                  printf("\n%s", buf);
369                  if (xac > 1) {
370 <                        printf(" | %s -e", xav[0]);
370 >                        printf(" | %s -e", xav[0]);     /* expand next time */
371                          for (i = 1; i < xac; i++)
372 <                                printf(" %s", xav[i]);
372 >                                if (i >= xfa || strcmp(xav[i], "-c"))
373 >                                        printf(" %s", xav[i]);
374                  }
375                  putchar('\n');
376          }
# Line 237 | Line 381 | xfobject(fname, fin)                           /* transform an object */
381   char  *fname;
382   FILE  *fin;
383   {
240        extern char  *strcpy();
384          char  typ[16], nam[MAXSTR];
385          int  fn;
386                                                  /* modifier and type */
# Line 279 | Line 422 | FILE  *fin;
422                  return(-1);
423                                          /* string arguments */
424          printf("%d", fa.nsargs);
425 <        for (i = 0; i < fa.nsargs; i++)
426 <                printf(" %s", fa.sarg[i]);
425 >        for (i = 0; i < fa.nsargs; i++) {
426 >                fputc(' ', stdout);
427 >                fputword(fa.sarg[i], stdout);
428 >        }
429          printf("\n");
430   #ifdef  IARGS
431                                          /* integer arguments */
# Line 314 | Line 459 | FILE  *fin;
459          if (xac > xfa && strcmp(xav[xfa], "-i"))
460                  resetarr = 2;
461          printf("%d", fa.nsargs + resetarr + xac-xfa);
462 <        for (i = 0; i < fa.nsargs; i++)
463 <                printf(" %s", fa.sarg[i]);
462 >        for (i = 0; i < fa.nsargs; i++) {
463 >                fputc(' ', stdout);
464 >                fputword(fa.sarg[i], stdout);
465 >        }
466          if (resetarr)
467                  printf(" -i 1");
468          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 340 | Line 487 | FILE  *fin;
487   }
488  
489  
343 int
344 otype(ofname)                   /* get object function number from its name */
345 register char  *ofname;
346 {
347        register int  i;
348
349        for (i = 0; i < NUMTYPES; i++)
350                if (!strcmp(ofun[i].funame, ofname))
351                        return(i);
352
353        return(-1);             /* not found */
354 }
355
356
490   alias(fin)                      /* transfer alias */
491   FILE  *fin;
492   {
# Line 408 | Line 541 | m_mist(fin)            /* transform arguments for mist */
541   FILE  *fin;
542   {
543          FUNARGS  fa;
544 +        int     i;
545  
546          if (readfargs(&fa, fin) != 1)
547                  return(-1);
548 <        if (fa.nsargs != 0  || fa.nfargs != 4)
548 >        if (fa.nfargs > 7)
549                  return(-1);
550 <        printf("0\n0\n4");
551 <        printf(" %18.12g %18.12g %18.12g", fa.farg[0]/tot.sca,
552 <                        fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
553 <        printf(" %18.12g\n", fa.farg[3]);
550 >        printf("%d", fa.nsargs);
551 >        if (idprefix == NULL)
552 >                for (i = 0; i < fa.nsargs; i++)
553 >                        printf(" %s", fa.sarg[i]);
554 >        else
555 >                for (i = 0; i < fa.nsargs; i++) {
556 >                        char    sname[256], *sp;
557 >                        register char   *cp1, *cp2 = sname;
558 >                                                        /* add idprefix */
559 >                        for (sp = fa.sarg[i]; *sp; sp = cp1) {
560 >                                for (cp1 = idprefix; *cp1; )
561 >                                        *cp2++ = *cp1++;
562 >                                *cp2++ = '.';
563 >                                for (cp1 = sp; *cp1 &&
564 >                                                (*cp2++ = *cp1++) != '>'; )
565 >                                        ;
566 >                        }
567 >                        *cp2 = '\0';
568 >                        printf(" %s", sname);
569 >                }
570 >        printf("\n0\n%d", fa.nfargs);
571 >        if (fa.nfargs > 2)
572 >                printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
573 >                                fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
574 >        for (i = 3; i < fa.nfargs; i++)
575 >                printf(" %12.6g", fa.farg[i]);
576 >        printf("\n");
577          freefargs(&fa);
578          return(0);
579   }
# Line 432 | Line 589 | FILE  *fin;
589          if (fa.nsargs != 0  || fa.nfargs != 5)
590                  return(-1);
591          printf("0\n0\n5");
592 <        printf(" %18.12g %18.12g %18.12g",
592 >        printf(" %12.6g %12.6g %12.6g",
593                  pow(fa.farg[0], 1.0/tot.sca),
594                  pow(fa.farg[1], 1.0/tot.sca),
595                  pow(fa.farg[2], 1.0/tot.sca));
596 <        printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]);
596 >        printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]);
597          freefargs(&fa);
598          return(0);
599   }
# Line 452 | Line 609 | FILE  *fin;
609          if (fa.nsargs != 0  || fa.nfargs != 8)
610                  return(-1);
611          printf("0\n0\n8\n");
612 <        printf("%18.12g %18.12g %18.12g",
612 >        printf("%12.6g %12.6g %12.6g",
613                  pow(fa.farg[0], 1.0/tot.sca),
614                  pow(fa.farg[1], 1.0/tot.sca),
615                  pow(fa.farg[2], 1.0/tot.sca));
616 <        printf(" %18.12g\n", fa.farg[3]);
617 <        printf("%18.12g %18.12g %18.12g",
616 >        printf(" %12.6g\n", fa.farg[3]);
617 >        printf("%12.6g %12.6g %12.6g",
618                  pow(fa.farg[4], 1.0/tot.sca),
619                  pow(fa.farg[5], 1.0/tot.sca),
620                  pow(fa.farg[6], 1.0/tot.sca));
621 <        printf(" %18.12g\n", fa.farg[7]);
621 >        printf(" %12.6g\n", fa.farg[7]);
622          freefargs(&fa);
623          return(0);
624   }
# Line 480 | Line 637 | FILE  *fin;
637                  return(-1);
638                                          /* string arguments */
639          printf("%d", fa.nsargs);
640 <        for (i = 0; i < fa.nsargs; i++)
641 <                printf(" %s", fa.sarg[i]);
640 >        for (i = 0; i < fa.nsargs; i++) {
641 >                fputc(' ', stdout);
642 >                fputword(fa.sarg[i], stdout);
643 >        }
644          printf("\n0\n%d\n", fa.nfargs);
645                                          /* anchor point */
646          multp3(v, fa.farg, tot.xfm);
# Line 664 | Line 823 | initotypes()                   /* initialize ofun[] array */
823  
824          if (ofun[OBJ_SOURCE].funp == o_source)
825                  return;                 /* done already */
667                                        /* alias is additional */
668        ofun[ALIAS].funame = ALIASID;
669        ofun[ALIAS].flags = 0;
826                                          /* functions get new transform */
827 <        for (i = 0; i < NUMTYPES; i++)
827 >        for (i = 0; i < NUMOTYPE; i++)
828                  if (hasfunc(i))
829                          ofun[i].funp = addxform;
830                                          /* special cases */
# Line 681 | Line 837 | initotypes()                   /* initialize ofun[] array */
837          ofun[OBJ_CYLINDER].funp =
838          ofun[OBJ_TUBE].funp = o_cylinder;
839          ofun[OBJ_RING].funp = o_ring;
840 <        ofun[OBJ_INSTANCE].funp = addxform;
840 >        ofun[OBJ_INSTANCE].funp =
841 >        ofun[OBJ_MESH].funp = addxform;
842          ofun[MAT_GLOW].funp = m_glow;
843          ofun[MAT_SPOT].funp = m_spot;
844          ofun[MAT_DIELECTRIC].funp = m_dielectric;
# Line 690 | Line 847 | initotypes()                   /* initialize ofun[] array */
847          ofun[PAT_CTEXT].funp =
848          ofun[PAT_BTEXT].funp =
849          ofun[MIX_TEXT].funp = text;
850 <        ofun[ALIAS].funp = alias;
850 >        ofun[MOD_ALIAS].funp = alias;
851                                          /* surface inverses */
852          tinvers[OBJ_FACE] = OBJ_FACE;
853          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 703 | Line 860 | initotypes()                   /* initialize ofun[] array */
860          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
861          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
862   }
863 +
864 +
865 + #ifdef  OLDXFORM
866 + openmain(fname)
867 + char  *fname;
868 + {
869 +        if (fname == NULL) {
870 +                strcpy(mainfn, "standard input");
871 +                mainfp = stdin;
872 +                return;
873 +        }
874 +        if (mainfp != NULL) {
875 +                if (!strcmp(fname, mainfn)) {
876 +                        rewind(mainfp);
877 +                        return;
878 +                }
879 +                fclose(mainfp);
880 +        }
881 +        if ((mainfp = fopen(fname, "r")) == NULL) {
882 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
883 +                                progname, fname);
884 +                exit(1);
885 +        }
886 +        strcpy(mainfn, fname);
887 + }
888 + #else
889 + openmain(iname)         /* open input, changing directory for file */
890 + char  *iname;
891 + {
892 +        static char  origdir[PATH_MAX];
893 +        static char  curfn[PATH_MAX];
894 +        static int  diffdir;
895 +        register char  *fpath;
896 +
897 +        if (iname == NULL) {                    /* standard input */
898 +                if (mainfp == NULL) {
899 +                        register int  c;
900 +                        strcpy(mainfn, "standard input");
901 +                        if (nrept <= 1) {
902 +                                mainfp = stdin;
903 +                                return;                 /* just read once */
904 +                        }
905 +                                                        /* else copy */
906 +                        if ((mainfp = tmpfile()) == NULL) {
907 +                                fprintf(stderr,
908 +                                        "%s: cannot create temporary file\n",
909 +                                                progname);
910 +                                exit(1);
911 +                        }
912 +                        while ((c = getc(stdin)) != EOF)
913 +                                putc(c, mainfp);
914 +                }
915 +                rewind(mainfp);                 /* rewind copy */
916 +                return;
917 +        }
918 +        if (mainfp == NULL) {                   /* first call, initialize */
919 +                getcwd(origdir, sizeof(origdir));
920 +        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
921 +                rewind(mainfp);
922 +                return;
923 +        } else {                                /* else close old stream */
924 +                fclose(mainfp);
925 +                mainfp = NULL;
926 +                if (diffdir) {                  /* return to our directory */
927 +                        chdir(origdir);
928 +                        diffdir = 0;
929 +                }
930 +        }
931 +        strcpy(curfn, iname);                   /* remember input name */
932 +                                                /* get full path for file */
933 +        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
934 +                fprintf(stderr, "%s: cannot find file \"%s\"\n",
935 +                                progname, iname);
936 +                exit(1);
937 +        }
938 +        if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
939 +                fpath += 2;
940 +                                                /* record path name */
941 +        strcpy(mainfn, fpath);
942 +        if (expand) {                           /* change to local directory */
943 +                register char  *cp = fpath + strlen(fpath);     /* get dir. */
944 +                while (cp > fpath) {
945 +                        cp--;
946 +                        if (ISDIRSEP(*cp)) {
947 +                                if (cp == fpath)
948 +                                        cp++;   /* root special case */
949 +                                break;
950 +                        }
951 +                }
952 +                *cp = '\0';
953 +                if (fpath[0]) {                 /* change to new directory? */
954 +                        if (chdir(fpath) < 0) {
955 +                                fprintf(stderr,
956 +                                "%s: cannot change directory to \"%s\"\n",
957 +                                                progname, fpath);
958 +                                exit(1);
959 +                        }
960 +                        diffdir++;
961 +                }
962 +                                                /* get final path component */
963 +                for (fpath = iname+strlen(iname);
964 +                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
965 +                        ;
966 +        }
967 +                                                /* finally, open the file */
968 +        if ((mainfp = fopen(fpath, "r")) == NULL) {
969 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
970 +                                progname, mainfn);
971 +                exit(1);
972 +        }
973 + }
974 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines