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.24 by greg, Tue Mar 11 19:29:05 2003 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 37 | Line 34 | char  *newmod;                         /* new modifier for surfaces */
34  
35   char  *idprefix;                        /* prefix for object identifiers */
36  
37 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
37 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
38  
42 #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
43
44 FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
45
39   short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
40  
41   int  nrept = 1;                         /* number of array repetitions */
42  
43   int stdinused = 0;                      /* stdin has been used by -f option? */
44  
52 extern char  *malloc(), *fgets(), *fgetword();
53
45   char  mainfn[MAXPATH];                  /* main file name */
46   FILE  *mainfp = NULL;                   /* main file pointer */
47  
# Line 104 | Line 95 | char  *argv[];
95                                          sprintf(newp, "%s.%s",
96                                                          idprefix, argv[a]);
97                                          if (mal_prefix++)
98 <                                                free((char *)idprefix);
98 >                                                free((void *)idprefix);
99                                          idprefix = newp;
100                                  }
101                                  continue;
# Line 165 | Line 156 | char  *argv[];
156                  }
157  
158          if (mal_prefix)
159 <                free((char *)idprefix);
159 >                free((void *)idprefix);
160          return(0);
161   }
162  
# Line 174 | Line 165 | doargf(ac, av, fi)                     /* take argument list from file *
165   char  **av;
166   int  ac, fi;
167   {
168 +        int  inquote;
169          char  *newav[256], **avp;
170          char  argbuf[1024];
171          char  newid[128];
# Line 188 | Line 180 | int  ac, fi;
180          }
181          if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
182                  if (stdinused++) {
183 <                        fprintf(stderr, "%s: cannot use stdin more than once\n",
183 >                        fprintf(stderr,
184 >                                "%s: cannot use stdin more than once\n",
185                                          av[0]);
186                          exit(1);
187                  }
# Line 196 | Line 189 | int  ac, fi;
189                  n = 100;                /* we just don't know! */
190          } else {
191                  if ((argfp = fopen(av[fi+1], "r")) == NULL) {
192 <                        fprintf(stderr, "%s: cannot open argument file \"%s\"\n",
192 >                        fprintf(stderr,
193 >                                "%s: cannot open argument file \"%s\"\n",
194                                          av[0], av[fi+1]);
195                          exit(1);
196                  }
197                  n = 0;                  /* count number of lines in file */
198 <                while (fgets(argbuf,sizeof(argbuf),argfp) != NULL)
199 <                        n += argbuf[0] != '\n' & argbuf[0] != '#';
198 >                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
199 >                        n += argbuf[0] && argbuf[0] != '#';
200                  if (!n) {
201                          fprintf(stderr, "%s: empty argument file \"%s\"\n",
202                                          av[0], av[fi+1]);
# Line 212 | Line 206 | int  ac, fi;
206                  rewind(argfp);
207          }
208          err = 0; k = 0;                 /* read each arg list and call main */
209 <        while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) {
210 <                if (argbuf[0] == '\n' | argbuf[0] == '#')
209 >        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
210 >                if (!argbuf[0] || argbuf[0] == '#')
211                          continue;
212                  avp = newav+2;
213                  avp[0] = av[0];
# Line 223 | Line 217 | int  ac, fi;
217                  cp = argbuf;            /* parse new words */
218                  if (*cp == '!') cp++;
219                  if (!strncmp(cp, "xform ", 6)) cp += 6;
220 +                inquote = 0;
221                  for ( ; ; ) {
222 +                skipspaces:
223                          while (isspace(*cp))    /* nullify spaces */
224                                  *cp++ = '\0';
225 +                        if ((*cp == '"' | *cp == '\''))
226 +                                inquote = *cp++;
227                          if (!*cp)               /* all done? */
228                                  break;
229 +                        if (cp[0] == '\\' && cp[1])
230 +                                if (*++cp == '\n')
231 +                                        goto skipspaces;
232                          avp[newac++] = cp;      /* add argument to list */
233 <                        while (*++cp && !isspace(*cp))
234 <                                ;
233 >                        if (inquote) {
234 >                                while (*++cp)
235 >                                        if (*cp == inquote) {
236 >                                                *cp++ = '\0';
237 >                                                break;
238 >                                        }
239 >                        } else {
240 >                                while (*++cp && !isspace(*cp))
241 >                                        ;
242 >                        }
243                  }
244                  for (i = fi+2; i < ac; i++)
245                          avp[newac++] = av[i];
# Line 343 | Line 352 | xfcomm(fname, fin)                     /* transform a command */
352   char  *fname;
353   FILE  *fin;
354   {
346        extern FILE  *popen();
347        extern char  *fgetline();
355          FILE  *pin;
356          char  buf[512];
357          int  i;
# Line 375 | Line 382 | xfobject(fname, fin)                           /* transform an object */
382   char  *fname;
383   FILE  *fin;
384   {
378        extern char  *strcpy();
385          char  typ[16], nam[MAXSTR];
386          int  fn;
387                                                  /* modifier and type */
# Line 417 | Line 423 | FILE  *fin;
423                  return(-1);
424                                          /* string arguments */
425          printf("%d", fa.nsargs);
426 <        for (i = 0; i < fa.nsargs; i++)
427 <                printf(" %s", fa.sarg[i]);
426 >        for (i = 0; i < fa.nsargs; i++) {
427 >                fputc(' ', stdout);
428 >                fputword(fa.sarg[i], stdout);
429 >        }
430          printf("\n");
431   #ifdef  IARGS
432                                          /* integer arguments */
# Line 452 | Line 460 | FILE  *fin;
460          if (xac > xfa && strcmp(xav[xfa], "-i"))
461                  resetarr = 2;
462          printf("%d", fa.nsargs + resetarr + xac-xfa);
463 <        for (i = 0; i < fa.nsargs; i++)
464 <                printf(" %s", fa.sarg[i]);
463 >        for (i = 0; i < fa.nsargs; i++) {
464 >                fputc(' ', stdout);
465 >                fputword(fa.sarg[i], stdout);
466 >        }
467          if (resetarr)
468                  printf(" -i 1");
469          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 478 | Line 488 | FILE  *fin;
488   }
489  
490  
481 int
482 otype(ofname)                   /* get object function number from its name */
483 register char  *ofname;
484 {
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
491   alias(fin)                      /* transfer alias */
492   FILE  *fin;
493   {
# Line 642 | Line 638 | FILE  *fin;
638                  return(-1);
639                                          /* string arguments */
640          printf("%d", fa.nsargs);
641 <        for (i = 0; i < fa.nsargs; i++)
642 <                printf(" %s", fa.sarg[i]);
641 >        for (i = 0; i < fa.nsargs; i++) {
642 >                fputc(' ', stdout);
643 >                fputword(fa.sarg[i], stdout);
644 >        }
645          printf("\n0\n%d\n", fa.nfargs);
646                                          /* anchor point */
647          multp3(v, fa.farg, tot.xfm);
# Line 826 | Line 824 | initotypes()                   /* initialize ofun[] array */
824  
825          if (ofun[OBJ_SOURCE].funp == o_source)
826                  return;                 /* done already */
829                                        /* alias is additional */
830        ofun[ALIAS].funame = ALIASID;
831        ofun[ALIAS].flags = 0;
827                                          /* functions get new transform */
828 <        for (i = 0; i < NUMTYPES; i++)
828 >        for (i = 0; i < NUMOTYPE; i++)
829                  if (hasfunc(i))
830                          ofun[i].funp = addxform;
831                                          /* special cases */
# Line 852 | 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 891 | Line 886 | char  *fname;
886          strcpy(mainfn, fname);
887   }
888   #else
889 < openmain(fname)         /* open fname for input, changing to its directory */
890 < char  *fname;
889 > openmain(iname)         /* open input, changing directory for file */
890 > char  *iname;
891   {
897        extern FILE  *tmpfile();
898        extern char  *getlibpath(), *getpath();
892          static char  origdir[MAXPATH];
893          static char  curfn[MAXPATH];
894          static int  diffdir;
895          register char  *fpath;
896  
897 <        if (fname == NULL) {                    /* standard input */
897 >        if (iname == NULL) {                    /* standard input */
898                  if (mainfp == NULL) {
899                          register int  c;
900                          strcpy(mainfn, "standard input");
# Line 918 | Line 911 | char  *fname;
911                          }
912                          while ((c = getc(stdin)) != EOF)
913                                  putc(c, mainfp);
921                        fclose(stdin);
914                  }
915                  rewind(mainfp);                 /* rewind copy */
916                  return;
917          }
918          if (mainfp == NULL) {                   /* first call, initialize */
919                  getwd(origdir);
920 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
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 <                if (diffdir) {
925 >                mainfp = NULL;
926 >                if (diffdir) {                  /* return to our directory */
927                          chdir(origdir);
928                          diffdir = 0;
929                  }
930          }
931 <        strcpy(curfn, fname);                   /* remember file name */
932 <                                                /* get full path */
933 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
931 >        strcpy(curfn, iname);                   /* remember input name */
932 >                                                /* get full path for file */
933 >        if ((fpath = getpath(iname, getlibpath(), R_OK)) == NULL) {
934                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
935 <                                progname, fname);
935 >                                progname, iname);
936                  exit(1);
937          }
938          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 967 | Line 960 | char  *fname;
960                          diffdir++;
961                  }
962                                                  /* get final path component */
963 <                for (fpath = fname+strlen(fname);
964 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
963 >                for (fpath = iname+strlen(iname);
964 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
965                          ;
966          }
967 <                                                /* open the file */
967 >                                                /* finally, open the file */
968          if ((mainfp = fopen(fpath, "r")) == NULL) {
969                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
970                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines