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.38 by greg, Sat Aug 21 02:59:47 2004 UTC vs.
Revision 2.53 by greg, Tue Apr 22 14:51:29 2025 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13  
14   #include  "platform.h"
15   #include  "paths.h"
16 #include  "rtprocess.h" /* win_popen() */
16   #include  "rtio.h"
17   #include  "rtmath.h"
18   #include  "object.h"
# Line 98 | Line 97 | main(          /* get transform options and transform file */
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 106 | Line 105 | main(          /* get transform options and transform file */
105                                          sprintf(newp, "%s.%s",
106                                                          idprefix, argv[a]);
107                                          if (mal_prefix++)
108 <                                                free((void *)idprefix);
108 >                                                free(idprefix);
109                                          idprefix = newp;
110                                  }
111                                  continue;
# Line 134 | Line 133 | main(          /* get transform options and transform file */
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 167 | Line 166 | main(          /* get transform options and transform file */
166                  }
167  
168          if (mal_prefix)
169 <                free((void *)idprefix);
169 >                free(idprefix);
170          return(0);
171   }
172  
# Line 182 | Line 181 | doargf(                        /* take argument list from file */
181          int  inquote;
182          char  *newav[256], **avp;
183          char  argbuf[2048];
184 <        char  newid[128];
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 210 | Line 209 | doargf(                        /* take argument list from file */
209                  }
210                  n = 0;                  /* count number of lines in file */
211                  while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
212 <                        n += argbuf[0] && argbuf[0] != '#';
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                  }
219                nrept *= n;
218                  rewind(argfp);
219          }
220 +        nrept *= n;
221          err = 0; k = 0;                 /* read each arg list and call main */
222          while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
223 <                if (!argbuf[0] || argbuf[0] == '#')
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 258 | Line 259 | doargf(                        /* take argument list from file */
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 277 | Line 284 | doargf(                        /* take argument list from file */
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 335 | Line 344 | doarray(                       /* make array */
344   void
345   xform(                  /* transform stream by tot.xfm */
346          char  *name,
347 <        register FILE  *fin
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 385 | Line 394 | xfcomm(                        /* transform a command */
394                          exit(1);
395                  }
396                  xform(buf, pin);
397 <                pclose(pin);
397 >                if (pclose(pin) != 0)
398 >                        fprintf(stderr, "%s: (%s): warning - bad status from \"%s\"\n",
399 >                                        progname, fname, buf);
400          } else {
401                  printf("\n%s", buf);
402                  if (xac > 1) {
# Line 416 | Line 427 | xfobject(                              /* transform an object */
427                                  progname, fname, typ);
428                  exit(1);
429          }
430 <        if (ismodifier(fn))
431 <                printf("\n%s %s ", nam, typ);
432 <        else
433 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
434 <                                invert ? ofun[tinvers[fn]].funame : typ);
430 >        putchar('\n');
431 >        if (ismodifier(fn)) {
432 >                fputword(nam, stdout);
433 >                printf(" %s ", typ);
434 >        } else {
435 >                fputword(newmod != NULL ? newmod : nam, stdout);
436 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
437 >        }
438                                                  /* object name */
439          fgetword(nam, sizeof(nam), fin);
440          if (idprefix == NULL || ismodifier(fn))
441 <                printf("%s\n", nam);
442 <        else
443 <                printf("%s.%s\n", idprefix, nam);
441 >                fputword(nam, stdout);
442 >        else {
443 >                char    nnam[MAXSTR];
444 >                sprintf(nnam, "%s.%s", idprefix, nam);
445 >                fputword(nnam, stdout);
446 >        }
447 >        putchar('\n');
448                                                  /* transform arguments */
449          if ((*ofun[fn].funp)(fin) < 0) {
450                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 441 | Line 459 | o_default(                     /* pass on arguments unchanged */
459          FILE  *fin
460   )
461   {
462 <        register int  i;
462 >        int  i;
463          FUNARGS  fa;
464  
465          if (readfargs(&fa, fin) != 1)
# Line 477 | Line 495 | addxform(                      /* add xf arguments to strings */
495          FILE  *fin
496   )
497   {
498 <        register int  i;
498 >        int  i;
499          int  resetarr = 0;
500          FUNARGS  fa;
501  
# Line 538 | Line 556 | m_glow(                        /* transform arguments for proximity light *
556  
557          if (readfargs(&fa, fin) != 1)
558                  return(-1);
559 <        if (fa.nsargs != 0  || fa.nfargs != 4)
559 >        if ((fa.nsargs != 0) | (fa.nfargs != 4))
560                  return(-1);
561          printf("0\n0\n4");
562          printf(" %18.12g %18.12g %18.12g",
# Line 559 | Line 577 | m_spot(                        /* transform arguments for spotlight */
577  
578          if (readfargs(&fa, fin) != 1)
579                  return(-1);
580 <        if (fa.nsargs != 0  || fa.nfargs != 7)
580 >        if ((fa.nsargs != 0) | ( fa.nfargs != 7))
581                  return(-1);
582          printf("0\n0\n7");
583          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 590 | Line 608 | m_mist(                /* transform arguments for mist */
608          else
609                  for (i = 0; i < fa.nsargs; i++) {
610                          char    sname[256], *sp;
611 <                        register char   *cp1, *cp2 = sname;
611 >                        char    *cp1, *cp2 = sname;
612                                                          /* add idprefix */
613                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
614                                  for (cp1 = idprefix; *cp1; )
# Line 760 | Line 778 | o_face(                        /* transform face arguments */
778   )
779   {
780          FVECT  p;
781 <        register int  i;
781 >        int  i;
782          FUNARGS  fa;
783  
784          if (readfargs(&fa, fin) != 1)
# Line 874 | Line 892 | o_ring(                        /* transform ring arguments */
892   void
893   initotypes(void)                        /* initialize ofun[] array */
894   {
895 <        register int  i;
895 >        int  i;
896  
897          if (ofun[OBJ_SOURCE].funp == o_source)
898                  return;                 /* done already */
# Line 914 | Line 932 | initotypes(void)                       /* initialize ofun[] array */
932          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
933          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
934          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
935 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
936   }
937  
938  
# Line 951 | Line 970 | openmain(              /* open input, changing directory for file
970          static char  origdir[PATH_MAX];
971          static char  curfn[PATH_MAX];
972          static int  diffdir;
973 <        register char  *fpath;
973 >        char  *fpath;
974  
975          if (iname == NULL) {                    /* standard input */
976                  if (mainfp == NULL) {
977 <                        register int  c;
977 >                        int  c;
978                          strcpy(mainfn, "standard input");
979                          if (nrept <= 1) {
980                                  mainfp = stdin;
# Line 999 | Line 1018 | openmain(              /* open input, changing directory for file
1018                                                  /* record path name */
1019          strcpy(mainfn, fpath);
1020          if (expand) {                           /* change to local directory */
1021 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1021 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1022                  while (cp > fpath) {
1023                          cp--;
1024                          if (ISDIRSEP(*cp)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines