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.36 by schorsch, Sun Mar 28 20:33:12 2004 UTC vs.
Revision 2.54 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12   #include  <ctype.h>
13  
14   #include  "platform.h"
15 #include  "paths.h"
16 #include  "rtprocess.h" /* win_popen() */
15   #include  "rtio.h"
16   #include  "rtmath.h"
17   #include  "object.h"
# Line 98 | Line 96 | main(          /* get transform options and transform file */
96                                  if (idprefix == NULL)
97                                          idprefix = argv[a];
98                                  else {
99 <                                        register char   *newp;
99 >                                        char    *newp;
100                                          newp = (char *)malloc(strlen(idprefix)+
101                                                          strlen(argv[a])+2);
102                                          if (newp == NULL)
# Line 106 | Line 104 | main(          /* get transform options and transform file */
104                                          sprintf(newp, "%s.%s",
105                                                          idprefix, argv[a]);
106                                          if (mal_prefix++)
107 <                                                free((void *)idprefix);
107 >                                                free(idprefix);
108                                          idprefix = newp;
109                                  }
110                                  continue;
# Line 134 | Line 132 | main(          /* get transform options and transform file */
132  
133          a += xf(&tot, argc-a, argv+a);
134  
135 <        if ( (reverse = tot.sca < 0.0) )
135 >        if ( (reverse = (tot.sca < 0.0)) )
136                  tot.sca = -tot.sca;
137          if (invert)
138                  reverse = !reverse;
# Line 167 | Line 165 | main(          /* get transform options and transform file */
165                  }
166  
167          if (mal_prefix)
168 <                free((void *)idprefix);
168 >                free(idprefix);
169          return(0);
170   }
171  
# Line 181 | Line 179 | doargf(                        /* take argument list from file */
179   {
180          int  inquote;
181          char  *newav[256], **avp;
182 <        char  argbuf[1024];
183 <        char  newid[128];
182 >        char  argbuf[2048];
183 >        char  *newid, newidbuf[128];
184          char  *oldid;
185 <        register char   *cp;
185 >        char    *cp;
186          FILE    *argfp;
187          int  n, i, k, newac, err;
188          
# Line 210 | Line 208 | doargf(                        /* take argument list from file */
208                  }
209                  n = 0;                  /* count number of lines in file */
210                  while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
211 <                        n += argbuf[0] && argbuf[0] != '#';
211 >                        n += (argbuf[0] != '\0') & (argbuf[0] != '#');
212                  if (!n) {
213                          fprintf(stderr, "%s: empty argument file \"%s\"\n",
214                                          av[0], av[fi+1]);
215                          exit(1);
216                  }
219                nrept *= n;
217                  rewind(argfp);
218          }
219 +        nrept *= n;
220          err = 0; k = 0;                 /* read each arg list and call main */
221          while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
222 <                if (!argbuf[0] || argbuf[0] == '#')
222 >                if (!argbuf[0] | (argbuf[0] == '#')) {
223 >                        printf("%s\n", argbuf);
224                          continue;
225 +                }
226                  avp = newav+2;
227                  avp[0] = av[0];
228                  for (i = 1; i < fi; i++)
# Line 258 | Line 258 | doargf(                        /* take argument list from file */
258                  for (i = fi+2; i < ac; i++)
259                          avp[newac++] = av[i];
260                  avp[newac] = NULL;
261 +                newid = newidbuf;
262                  oldid = NULL;
263                  for (i = 2; i < newac; i++)
264                          if (!strcmp(avp[i-1], "-n")) {
265                                  oldid = avp[i];
266 +                                if (strlen(oldid)+32 > sizeof(newidbuf)) {
267 +                                        newid = (char *)malloc(strlen(oldid)+32);
268 +                                        if (newid == NULL)
269 +                                                exit(2);
270 +                                }
271                                  avp[i] = newid;
272                                  break;
273                          }
# Line 277 | Line 283 | doargf(                        /* take argument list from file */
283                  else
284                          sprintf(newid, "%s.%d", oldid, k);
285                  err |= main(newac, avp);
286 +                if (newid != newidbuf)
287 +                        free(newid);
288                  k++;
289          }
290          fclose(argfp);
# Line 335 | Line 343 | doarray(                       /* make array */
343   void
344   xform(                  /* transform stream by tot.xfm */
345          char  *name,
346 <        register FILE  *fin
346 >        FILE  *fin
347   )
348   {
349          int  nobjs = 0;
350 <        register int  c;
350 >        int  c;
351  
352          while ((c = getc(fin)) != EOF) {
353                  if (isspace(c))                         /* blank */
# Line 374 | Line 382 | xfcomm(                        /* transform a command */
382   )
383   {
384          FILE  *pin;
385 <        char  buf[512];
385 >        char  buf[2048];
386          int  i;
387  
388          fgetline(buf, sizeof(buf), fin);
# Line 385 | Line 393 | xfcomm(                        /* transform a command */
393                          exit(1);
394                  }
395                  xform(buf, pin);
396 <                pclose(pin);
396 >                if (pclose(pin) != 0)
397 >                        fprintf(stderr, "%s: (%s): warning - bad status from \"%s\"\n",
398 >                                        progname, fname, buf);
399          } else {
400                  printf("\n%s", buf);
401                  if (xac > 1) {
# Line 416 | Line 426 | xfobject(                              /* transform an object */
426                                  progname, fname, typ);
427                  exit(1);
428          }
429 <        if (ismodifier(fn))
430 <                printf("\n%s %s ", nam, typ);
431 <        else
432 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
433 <                                invert ? ofun[tinvers[fn]].funame : typ);
429 >        putchar('\n');
430 >        if (ismodifier(fn)) {
431 >                fputword(nam, stdout);
432 >                printf(" %s ", typ);
433 >        } else {
434 >                fputword(newmod != NULL ? newmod : nam, stdout);
435 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
436 >        }
437                                                  /* object name */
438          fgetword(nam, sizeof(nam), fin);
439          if (idprefix == NULL || ismodifier(fn))
440 <                printf("%s\n", nam);
441 <        else
442 <                printf("%s.%s\n", idprefix, nam);
440 >                fputword(nam, stdout);
441 >        else {
442 >                char    nnam[MAXSTR];
443 >                sprintf(nnam, "%s.%s", idprefix, nam);
444 >                fputword(nnam, stdout);
445 >        }
446 >        putchar('\n');
447                                                  /* transform arguments */
448          if ((*ofun[fn].funp)(fin) < 0) {
449                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 441 | Line 458 | o_default(                     /* pass on arguments unchanged */
458          FILE  *fin
459   )
460   {
461 <        register int  i;
461 >        int  i;
462          FUNARGS  fa;
463  
464          if (readfargs(&fa, fin) != 1)
# Line 477 | Line 494 | addxform(                      /* add xf arguments to strings */
494          FILE  *fin
495   )
496   {
497 <        register int  i;
497 >        int  i;
498          int  resetarr = 0;
499          FUNARGS  fa;
500  
# Line 538 | Line 555 | m_glow(                        /* transform arguments for proximity light *
555  
556          if (readfargs(&fa, fin) != 1)
557                  return(-1);
558 <        if (fa.nsargs != 0  || fa.nfargs != 4)
558 >        if ((fa.nsargs != 0) | (fa.nfargs != 4))
559                  return(-1);
560          printf("0\n0\n4");
561          printf(" %18.12g %18.12g %18.12g",
# Line 559 | Line 576 | m_spot(                        /* transform arguments for spotlight */
576  
577          if (readfargs(&fa, fin) != 1)
578                  return(-1);
579 <        if (fa.nsargs != 0  || fa.nfargs != 7)
579 >        if ((fa.nsargs != 0) | ( fa.nfargs != 7))
580                  return(-1);
581          printf("0\n0\n7");
582          printf(" %18.12g %18.12g %18.12g %18.12g\n",
# Line 590 | Line 607 | m_mist(                /* transform arguments for mist */
607          else
608                  for (i = 0; i < fa.nsargs; i++) {
609                          char    sname[256], *sp;
610 <                        register char   *cp1, *cp2 = sname;
610 >                        char    *cp1, *cp2 = sname;
611                                                          /* add idprefix */
612                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
613                                  for (cp1 = idprefix; *cp1; )
# Line 760 | Line 777 | o_face(                        /* transform face arguments */
777   )
778   {
779          FVECT  p;
780 <        register int  i;
780 >        int  i;
781          FUNARGS  fa;
782  
783          if (readfargs(&fa, fin) != 1)
# Line 874 | Line 891 | o_ring(                        /* transform ring arguments */
891   void
892   initotypes(void)                        /* initialize ofun[] array */
893   {
894 <        register int  i;
894 >        int  i;
895  
896          if (ofun[OBJ_SOURCE].funp == o_source)
897                  return;                 /* done already */
# Line 914 | Line 931 | initotypes(void)                       /* initialize ofun[] array */
931          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
932          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
933          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
934 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
935   }
936  
937  
# Line 951 | Line 969 | openmain(              /* open input, changing directory for file
969          static char  origdir[PATH_MAX];
970          static char  curfn[PATH_MAX];
971          static int  diffdir;
972 <        register char  *fpath;
972 >        char  *fpath;
973  
974          if (iname == NULL) {                    /* standard input */
975                  if (mainfp == NULL) {
976 <                        register int  c;
976 >                        int  c;
977                          strcpy(mainfn, "standard input");
978                          if (nrept <= 1) {
979                                  mainfp = stdin;
# Line 999 | Line 1017 | openmain(              /* open input, changing directory for file
1017                                                  /* record path name */
1018          strcpy(mainfn, fpath);
1019          if (expand) {                           /* change to local directory */
1020 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1020 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1021                  while (cp > fpath) {
1022                          cp--;
1023                          if (ISDIRSEP(*cp)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines