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.21 by gwlarson, Fri Jun 4 17:06:31 1999 UTC vs.
Revision 2.29 by schorsch, Thu Jul 3 22:41:44 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 + #ifndef _WIN32
14 +  #include  <unistd.h>
15 + #endif
16  
17 + #include  "standard.h"
18 + #include  "platform.h"
19 + #include  "paths.h"
20   #include  "object.h"
22
21   #include  "otypes.h"
22  
23   int  xac;                               /* global xform argument count */
# Line 37 | Line 35 | char  *newmod;                         /* new modifier for surfaces */
35  
36   char  *idprefix;                        /* prefix for object identifiers */
37  
38 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
38 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
39  
42 #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
43
44 FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
45
40   short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
41  
42   int  nrept = 1;                         /* number of array repetitions */
43  
44   int stdinused = 0;                      /* stdin has been used by -f option? */
45  
46 < extern char  *malloc(), *fgets(), *fgetword();
53 <
54 < char  mainfn[MAXPATH];                  /* main file name */
46 > char  mainfn[PATH_MAX];                 /* main file name */
47   FILE  *mainfp = NULL;                   /* main file pointer */
48  
49   #define  progname  (xav[0])
# Line 104 | Line 96 | char  *argv[];
96                                          sprintf(newp, "%s.%s",
97                                                          idprefix, argv[a]);
98                                          if (mal_prefix++)
99 <                                                free((char *)idprefix);
99 >                                                free((void *)idprefix);
100                                          idprefix = newp;
101                                  }
102                                  continue;
# Line 165 | Line 157 | char  *argv[];
157                  }
158  
159          if (mal_prefix)
160 <                free((char *)idprefix);
160 >                free((void *)idprefix);
161          return(0);
162   }
163  
# Line 174 | Line 166 | doargf(ac, av, fi)                     /* take argument list from file *
166   char  **av;
167   int  ac, fi;
168   {
169 +        int  inquote;
170          char  *newav[256], **avp;
171          char  argbuf[1024];
172          char  newid[128];
# Line 188 | Line 181 | int  ac, fi;
181          }
182          if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
183                  if (stdinused++) {
184 <                        fprintf(stderr, "%s: cannot use stdin more than once\n",
184 >                        fprintf(stderr,
185 >                                "%s: cannot use stdin more than once\n",
186                                          av[0]);
187                          exit(1);
188                  }
# Line 196 | Line 190 | int  ac, fi;
190                  n = 100;                /* we just don't know! */
191          } else {
192                  if ((argfp = fopen(av[fi+1], "r")) == NULL) {
193 <                        fprintf(stderr, "%s: cannot open argument file \"%s\"\n",
193 >                        fprintf(stderr,
194 >                                "%s: cannot open argument file \"%s\"\n",
195                                          av[0], av[fi+1]);
196                          exit(1);
197                  }
198                  n = 0;                  /* count number of lines in file */
199 <                while (fgets(argbuf,sizeof(argbuf),argfp) != NULL)
200 <                        n += argbuf[0] != '\n' & argbuf[0] != '#';
199 >                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
200 >                        n += argbuf[0] && argbuf[0] != '#';
201                  if (!n) {
202                          fprintf(stderr, "%s: empty argument file \"%s\"\n",
203                                          av[0], av[fi+1]);
# Line 212 | Line 207 | int  ac, fi;
207                  rewind(argfp);
208          }
209          err = 0; k = 0;                 /* read each arg list and call main */
210 <        while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) {
211 <                if (argbuf[0] == '\n' | argbuf[0] == '#')
210 >        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
211 >                if (!argbuf[0] || argbuf[0] == '#')
212                          continue;
213                  avp = newav+2;
214                  avp[0] = av[0];
# Line 223 | Line 218 | int  ac, fi;
218                  cp = argbuf;            /* parse new words */
219                  if (*cp == '!') cp++;
220                  if (!strncmp(cp, "xform ", 6)) cp += 6;
221 +                inquote = 0;
222                  for ( ; ; ) {
223 +                skipspaces:
224                          while (isspace(*cp))    /* nullify spaces */
225                                  *cp++ = '\0';
226 +                        if ((*cp == '"' | *cp == '\''))
227 +                                inquote = *cp++;
228                          if (!*cp)               /* all done? */
229                                  break;
230 +                        if (cp[0] == '\\' && cp[1])
231 +                                if (*++cp == '\n')
232 +                                        goto skipspaces;
233                          avp[newac++] = cp;      /* add argument to list */
234 <                        while (*++cp && !isspace(*cp))
235 <                                ;
234 >                        if (inquote) {
235 >                                while (*++cp)
236 >                                        if (*cp == inquote) {
237 >                                                *cp++ = '\0';
238 >                                                break;
239 >                                        }
240 >                        } else {
241 >                                while (*++cp && !isspace(*cp))
242 >                                        ;
243 >                        }
244                  }
245                  for (i = fi+2; i < ac; i++)
246                          avp[newac++] = av[i];
# Line 343 | Line 353 | xfcomm(fname, fin)                     /* transform a command */
353   char  *fname;
354   FILE  *fin;
355   {
346        extern FILE  *popen();
347        extern char  *fgetline();
356          FILE  *pin;
357          char  buf[512];
358          int  i;
# Line 361 | Line 369 | FILE  *fin;
369          } else {
370                  printf("\n%s", buf);
371                  if (xac > 1) {
372 <                        printf(" | %s", xav[0]);
372 >                        printf(" | %s -e", xav[0]);     /* expand next time */
373                          for (i = 1; i < xac; i++)
374 <                                printf(" %s", xav[i]);
374 >                                if (i >= xfa || strcmp(xav[i], "-c"))
375 >                                        printf(" %s", xav[i]);
376                  }
377                  putchar('\n');
378          }
# Line 374 | Line 383 | xfobject(fname, fin)                           /* transform an object */
383   char  *fname;
384   FILE  *fin;
385   {
377        extern char  *strcpy();
386          char  typ[16], nam[MAXSTR];
387          int  fn;
388                                                  /* modifier and type */
# Line 416 | Line 424 | FILE  *fin;
424                  return(-1);
425                                          /* string arguments */
426          printf("%d", fa.nsargs);
427 <        for (i = 0; i < fa.nsargs; i++)
428 <                printf(" %s", fa.sarg[i]);
427 >        for (i = 0; i < fa.nsargs; i++) {
428 >                fputc(' ', stdout);
429 >                fputword(fa.sarg[i], stdout);
430 >        }
431          printf("\n");
432   #ifdef  IARGS
433                                          /* integer arguments */
# Line 451 | Line 461 | FILE  *fin;
461          if (xac > xfa && strcmp(xav[xfa], "-i"))
462                  resetarr = 2;
463          printf("%d", fa.nsargs + resetarr + xac-xfa);
464 <        for (i = 0; i < fa.nsargs; i++)
465 <                printf(" %s", fa.sarg[i]);
464 >        for (i = 0; i < fa.nsargs; i++) {
465 >                fputc(' ', stdout);
466 >                fputword(fa.sarg[i], stdout);
467 >        }
468          if (resetarr)
469                  printf(" -i 1");
470          for (i = xfa; i < xac; i++)     /* add xf arguments */
# Line 477 | Line 489 | FILE  *fin;
489   }
490  
491  
480 int
481 otype(ofname)                   /* get object function number from its name */
482 register char  *ofname;
483 {
484        register int  i;
485
486        for (i = 0; i < NUMTYPES; i++)
487                if (!strcmp(ofun[i].funame, ofname))
488                        return(i);
489
490        return(-1);             /* not found */
491 }
492
493
492   alias(fin)                      /* transfer alias */
493   FILE  *fin;
494   {
# Line 641 | Line 639 | FILE  *fin;
639                  return(-1);
640                                          /* string arguments */
641          printf("%d", fa.nsargs);
642 <        for (i = 0; i < fa.nsargs; i++)
643 <                printf(" %s", fa.sarg[i]);
642 >        for (i = 0; i < fa.nsargs; i++) {
643 >                fputc(' ', stdout);
644 >                fputword(fa.sarg[i], stdout);
645 >        }
646          printf("\n0\n%d\n", fa.nfargs);
647                                          /* anchor point */
648          multp3(v, fa.farg, tot.xfm);
# Line 825 | Line 825 | initotypes()                   /* initialize ofun[] array */
825  
826          if (ofun[OBJ_SOURCE].funp == o_source)
827                  return;                 /* done already */
828                                        /* alias is additional */
829        ofun[ALIAS].funame = ALIASID;
830        ofun[ALIAS].flags = 0;
828                                          /* functions get new transform */
829 <        for (i = 0; i < NUMTYPES; i++)
829 >        for (i = 0; i < NUMOTYPE; i++)
830                  if (hasfunc(i))
831                          ofun[i].funp = addxform;
832                                          /* special cases */
# Line 851 | Line 848 | initotypes()                   /* initialize ofun[] array */
848          ofun[PAT_CTEXT].funp =
849          ofun[PAT_BTEXT].funp =
850          ofun[MIX_TEXT].funp = text;
851 <        ofun[ALIAS].funp = alias;
851 >        ofun[MOD_ALIAS].funp = alias;
852                                          /* surface inverses */
853          tinvers[OBJ_FACE] = OBJ_FACE;
854          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
# Line 890 | Line 887 | char  *fname;
887          strcpy(mainfn, fname);
888   }
889   #else
890 < openmain(fname)         /* open fname for input, changing to its directory */
891 < char  *fname;
890 > openmain(iname)         /* open input, changing directory for file */
891 > char  *iname;
892   {
893 <        extern FILE  *tmpfile();
894 <        extern char  *getlibpath(), *getpath();
898 <        static char  origdir[MAXPATH];
899 <        static char  curfn[MAXPATH];
893 >        static char  origdir[PATH_MAX];
894 >        static char  curfn[PATH_MAX];
895          static int  diffdir;
896          register char  *fpath;
897  
898 <        if (fname == NULL) {                    /* standard input */
898 >        if (iname == NULL) {                    /* standard input */
899                  if (mainfp == NULL) {
900                          register int  c;
901                          strcpy(mainfn, "standard input");
# Line 917 | Line 912 | char  *fname;
912                          }
913                          while ((c = getc(stdin)) != EOF)
914                                  putc(c, mainfp);
920                        fclose(stdin);
915                  }
916                  rewind(mainfp);                 /* rewind copy */
917                  return;
918          }
919          if (mainfp == NULL) {                   /* first call, initialize */
920 <                getwd(origdir);
921 <        } else if (!strcmp(fname, curfn)) {     /* just need to rewind? */
920 >                getcwd(origdir, sizeof(origdir));
921 >        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
922                  rewind(mainfp);
923                  return;
924          } else {                                /* else close old stream */
925                  fclose(mainfp);
926 <                if (diffdir) {
926 >                mainfp = NULL;
927 >                if (diffdir) {                  /* return to our directory */
928                          chdir(origdir);
929                          diffdir = 0;
930                  }
931          }
932 <        strcpy(curfn, fname);                   /* remember file name */
933 <                                                /* get full path */
934 <        if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) {
932 >        strcpy(curfn, iname);                   /* remember input name */
933 >                                                /* get full path for file */
934 >        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
935                  fprintf(stderr, "%s: cannot find file \"%s\"\n",
936 <                                progname, fname);
936 >                                progname, iname);
937                  exit(1);
938          }
939          if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
# Line 966 | Line 961 | char  *fname;
961                          diffdir++;
962                  }
963                                                  /* get final path component */
964 <                for (fpath = fname+strlen(fname);
965 <                                fpath > fname && !ISDIRSEP(fpath[-1]); fpath--)
964 >                for (fpath = iname+strlen(iname);
965 >                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
966                          ;
967          }
968 <                                                /* open the file */
968 >                                                /* finally, open the file */
969          if ((mainfp = fopen(fpath, "r")) == NULL) {
970                  fprintf(stderr, "%s: cannot open file \"%s\"\n",
971                                  progname, mainfn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines