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.28 by schorsch, Mon Jun 30 14:59:11 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 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 + #include  <unistd.h>
14  
15 + #include  "standard.h"
16 + #include  "platform.h"
17 + #include  "paths.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])
# Line 104 | Line 94 | char  *argv[];
94                                          sprintf(newp, "%s.%s",
95                                                          idprefix, argv[a]);
96                                          if (mal_prefix++)
97 <                                                free((char *)idprefix);
97 >                                                free((void *)idprefix);
98                                          idprefix = newp;
99                                  }
100                                  continue;
# Line 165 | Line 155 | char  *argv[];
155                  }
156  
157          if (mal_prefix)
158 <                free((char *)idprefix);
158 >                free((void *)idprefix);
159          return(0);
160   }
161  
# Line 174 | Line 164 | 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];
# Line 188 | Line 179 | int  ac, fi;
179          }
180          if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
181                  if (stdinused++) {
182 <                        fprintf(stderr, "%s: cannot use stdin more than once\n",
182 >                        fprintf(stderr,
183 >                                "%s: cannot use stdin more than once\n",
184                                          av[0]);
185                          exit(1);
186                  }
# Line 196 | Line 188 | int  ac, fi;
188                  n = 100;                /* we just don't know! */
189          } else {
190                  if ((argfp = fopen(av[fi+1], "r")) == NULL) {
191 <                        fprintf(stderr, "%s: cannot open argument file \"%s\"\n",
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 (fgets(argbuf,sizeof(argbuf),argfp) != NULL)
198 <                        n += argbuf[0] != '\n' & argbuf[0] != '#';
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]);
# Line 212 | Line 205 | int  ac, fi;
205                  rewind(argfp);
206          }
207          err = 0; k = 0;                 /* read each arg list and call main */
208 <        while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) {
209 <                if (argbuf[0] == '\n' | argbuf[0] == '#')
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];
# Line 223 | Line 216 | int  ac, fi;
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 <                        while (*++cp && !isspace(*cp))
233 <                                ;
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];
# Line 343 | Line 351 | xfcomm(fname, fin)                     /* transform a command */
351   char  *fname;
352   FILE  *fin;
353   {
346        extern FILE  *popen();
347        extern char  *fgetline();
354          FILE  *pin;
355          char  buf[512];
356          int  i;
# Line 375 | Line 381 | xfobject(fname, fin)                           /* transform an object */
381   char  *fname;
382   FILE  *fin;
383   {
378        extern char  *strcpy();
384          char  typ[16], nam[MAXSTR];
385          int  fn;
386                                                  /* modifier and type */
# Line 417 | 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 452 | 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 478 | Line 487 | FILE  *fin;
487   }
488  
489  
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
490   alias(fin)                      /* transfer alias */
491   FILE  *fin;
492   {
# Line 642 | 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 826 | Line 823 | initotypes()                   /* initialize ofun[] array */
823  
824          if (ofun[OBJ_SOURCE].funp == o_source)
825                  return;                 /* done already */
829                                        /* alias is additional */
830        ofun[ALIAS].funame = ALIASID;
831        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 852 | Line 846 | initotypes()                   /* initialize ofun[] array */
846          ofun[PAT_CTEXT].funp =
847          ofun[PAT_BTEXT].funp =
848          ofun[MIX_TEXT].funp = text;
849 <        ofun[ALIAS].funp = alias;
849 >        ofun[MOD_ALIAS].funp = alias;
850                                          /* surface inverses */
851          tinvers[OBJ_FACE] = OBJ_FACE;
852          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 891 | Line 885 | char  *fname;
885          strcpy(mainfn, fname);
886   }
887   #else
888 < openmain(fname)         /* open fname for input, changing to its directory */
889 < char  *fname;
888 > openmain(iname)         /* open input, changing directory for file */
889 > char  *iname;
890   {
891 <        extern FILE  *tmpfile();
892 <        extern char  *getlibpath(), *getpath();
899 <        static char  origdir[MAXPATH];
900 <        static char  curfn[MAXPATH];
891 >        static char  origdir[PATH_MAX];
892 >        static char  curfn[PATH_MAX];
893          static int  diffdir;
894          register char  *fpath;
895  
896 <        if (fname == NULL) {                    /* standard input */
896 >        if (iname == NULL) {                    /* standard input */
897                  if (mainfp == NULL) {
898                          register int  c;
899                          strcpy(mainfn, "standard input");
# Line 918 | Line 910 | char  *fname;
910                          }
911                          while ((c = getc(stdin)) != EOF)
912                                  putc(c, mainfp);
921                        fclose(stdin);
913                  }
914                  rewind(mainfp);                 /* rewind copy */
915                  return;
916          }
917          if (mainfp == NULL) {                   /* first call, initialize */
918 <                getwd(origdir);
919 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
918 >                getcwd(origdir, sizeof(origdir));
919 >        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
920                  rewind(mainfp);
921                  return;
922          } else {                                /* else close old stream */
923                  fclose(mainfp);
924 <                if (diffdir) {
924 >                mainfp = NULL;
925 >                if (diffdir) {                  /* return to our directory */
926                          chdir(origdir);
927                          diffdir = 0;
928                  }
929          }
930 <        strcpy(curfn, fname);                   /* remember file name */
931 <                                                /* get full path */
932 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
930 >        strcpy(curfn, iname);                   /* remember input name */
931 >                                                /* get full path for file */
932 >        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
933                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
934 <                                progname, fname);
934 >                                progname, iname);
935                  exit(1);
936          }
937          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 967 | Line 959 | char  *fname;
959                          diffdir++;
960                  }
961                                                  /* get final path component */
962 <                for (fpath = fname+strlen(fname);
963 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
962 >                for (fpath = iname+strlen(iname);
963 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
964                          ;
965          }
966 <                                                /* open the file */
966 >                                                /* finally, open the file */
967          if ((mainfp = fopen(fpath, "r")) == NULL) {
968                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
969                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines