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.35 by schorsch, Sun Nov 16 09:23:46 2003 UTC vs.
Revision 2.48 by greg, Wed Jul 9 23:14:58 2014 UTC

# Line 19 | Line 19 | static const char RCSid[] = "$Id$";
19   #include  "object.h"
20   #include  "otypes.h"
21  
22 + #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
23 + #undef getc
24 + #define getc    getc_unlocked
25 + #endif
26 +
27   int  xac;                               /* global xform argument count */
28   char  **xav;                            /* global xform argument pointer */
29   int  xfa;                               /* start of xf arguments */
# Line 54 | Line 59 | static void xfcomm(char *fname, FILE *fin);
59   static void xfobject(char *fname, FILE *fin);
60   static int addxform(FILE *fin);
61   static int alias(FILE *fin);
62 < static void initotypes(void);
62 > void initotypes(void); /* XXX conflict with otypes.h */
63   static void openmain(char *iname);
64  
65  
# Line 98 | Line 103 | main(          /* get transform options and transform file */
103                                  if (idprefix == NULL)
104                                          idprefix = argv[a];
105                                  else {
106 <                                        register char   *newp;
106 >                                        char    *newp;
107                                          newp = (char *)malloc(strlen(idprefix)+
108                                                          strlen(argv[a])+2);
109                                          if (newp == NULL)
# Line 106 | Line 111 | main(          /* get transform options and transform file */
111                                          sprintf(newp, "%s.%s",
112                                                          idprefix, argv[a]);
113                                          if (mal_prefix++)
114 <                                                free((void *)idprefix);
114 >                                                free(idprefix);
115                                          idprefix = newp;
116                                  }
117                                  continue;
# Line 134 | Line 139 | main(          /* get transform options and transform file */
139  
140          a += xf(&tot, argc-a, argv+a);
141  
142 <        if ( (reverse = tot.sca < 0.0) )
142 >        if ( (reverse = (tot.sca < 0.0)) )
143                  tot.sca = -tot.sca;
144          if (invert)
145                  reverse = !reverse;
# Line 167 | Line 172 | main(          /* get transform options and transform file */
172                  }
173  
174          if (mal_prefix)
175 <                free((void *)idprefix);
175 >                free(idprefix);
176          return(0);
177   }
178  
# Line 181 | Line 186 | doargf(                        /* take argument list from file */
186   {
187          int  inquote;
188          char  *newav[256], **avp;
189 <        char  argbuf[1024];
190 <        char  newid[128];
189 >        char  argbuf[2048];
190 >        char  *newid, newidbuf[128];
191          char  *oldid;
192 <        register char   *cp;
192 >        char    *cp;
193          FILE    *argfp;
194          int  n, i, k, newac, err;
195          
# Line 258 | Line 263 | doargf(                        /* take argument list from file */
263                  for (i = fi+2; i < ac; i++)
264                          avp[newac++] = av[i];
265                  avp[newac] = NULL;
266 +                newid = newidbuf;
267                  oldid = NULL;
268                  for (i = 2; i < newac; i++)
269                          if (!strcmp(avp[i-1], "-n")) {
270                                  oldid = avp[i];
271 +                                if (strlen(oldid)+32 > sizeof(newidbuf)) {
272 +                                        newid = (char *)malloc(strlen(oldid)+32);
273 +                                        if (newid == NULL)
274 +                                                exit(2);
275 +                                }
276                                  avp[i] = newid;
277                                  break;
278                          }
# Line 277 | Line 288 | doargf(                        /* take argument list from file */
288                  else
289                          sprintf(newid, "%s.%d", oldid, k);
290                  err |= main(newac, avp);
291 +                if (newid != newidbuf)
292 +                        free(newid);
293                  k++;
294          }
295          fclose(argfp);
# Line 335 | Line 348 | doarray(                       /* make array */
348   void
349   xform(                  /* transform stream by tot.xfm */
350          char  *name,
351 <        register FILE  *fin
351 >        FILE  *fin
352   )
353   {
354          int  nobjs = 0;
355 <        register int  c;
355 >        int  c;
356  
357          while ((c = getc(fin)) != EOF) {
358                  if (isspace(c))                         /* blank */
# Line 374 | Line 387 | xfcomm(                        /* transform a command */
387   )
388   {
389          FILE  *pin;
390 <        char  buf[512];
390 >        char  buf[2048];
391          int  i;
392  
393          fgetline(buf, sizeof(buf), fin);
# Line 416 | Line 429 | xfobject(                              /* transform an object */
429                                  progname, fname, typ);
430                  exit(1);
431          }
432 <        if (ismodifier(fn))
433 <                printf("\n%s %s ", nam, typ);
434 <        else
435 <                printf("\n%s %s ", newmod != NULL ? newmod : nam,
436 <                                invert ? ofun[tinvers[fn]].funame : typ);
432 >        putchar('\n');
433 >        if (ismodifier(fn)) {
434 >                fputword(nam, stdout);
435 >                printf(" %s ", typ);
436 >        } else {
437 >                fputword(newmod != NULL ? newmod : nam, stdout);
438 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
439 >        }
440                                                  /* object name */
441          fgetword(nam, sizeof(nam), fin);
442          if (idprefix == NULL || ismodifier(fn))
443 <                printf("%s\n", nam);
444 <        else
445 <                printf("%s.%s\n", idprefix, nam);
443 >                fputword(nam, stdout);
444 >        else {
445 >                char    nnam[MAXSTR];
446 >                sprintf(nnam, "%s.%s", idprefix, nam);
447 >                fputword(nnam, stdout);
448 >        }
449 >        putchar('\n');
450                                                  /* transform arguments */
451          if ((*ofun[fn].funp)(fin) < 0) {
452                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 441 | Line 461 | o_default(                     /* pass on arguments unchanged */
461          FILE  *fin
462   )
463   {
464 <        register int  i;
464 >        int  i;
465          FUNARGS  fa;
466  
467          if (readfargs(&fa, fin) != 1)
# Line 477 | Line 497 | addxform(                      /* add xf arguments to strings */
497          FILE  *fin
498   )
499   {
500 <        register int  i;
500 >        int  i;
501          int  resetarr = 0;
502          FUNARGS  fa;
503  
# Line 590 | Line 610 | m_mist(                /* transform arguments for mist */
610          else
611                  for (i = 0; i < fa.nsargs; i++) {
612                          char    sname[256], *sp;
613 <                        register char   *cp1, *cp2 = sname;
613 >                        char    *cp1, *cp2 = sname;
614                                                          /* add idprefix */
615                          for (sp = fa.sarg[i]; *sp; sp = cp1) {
616                                  for (cp1 = idprefix; *cp1; )
# Line 760 | Line 780 | o_face(                        /* transform face arguments */
780   )
781   {
782          FVECT  p;
783 <        register int  i;
783 >        int  i;
784          FUNARGS  fa;
785  
786          if (readfargs(&fa, fin) != 1)
# Line 874 | Line 894 | o_ring(                        /* transform ring arguments */
894   void
895   initotypes(void)                        /* initialize ofun[] array */
896   {
897 <        register int  i;
897 >        int  i;
898  
899          if (ofun[OBJ_SOURCE].funp == o_source)
900                  return;                 /* done already */
# Line 914 | Line 934 | initotypes(void)                       /* initialize ofun[] array */
934          tinvers[OBJ_CYLINDER] = OBJ_TUBE;
935          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
936          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
937 +        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
938   }
939  
940  
# Line 951 | Line 972 | openmain(              /* open input, changing directory for file
972          static char  origdir[PATH_MAX];
973          static char  curfn[PATH_MAX];
974          static int  diffdir;
975 <        register char  *fpath;
975 >        char  *fpath;
976  
977          if (iname == NULL) {                    /* standard input */
978                  if (mainfp == NULL) {
979 <                        register int  c;
979 >                        int  c;
980                          strcpy(mainfn, "standard input");
981                          if (nrept <= 1) {
982                                  mainfp = stdin;
# Line 999 | Line 1020 | openmain(              /* open input, changing directory for file
1020                                                  /* record path name */
1021          strcpy(mainfn, fpath);
1022          if (expand) {                           /* change to local directory */
1023 <                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1023 >                char  *cp = fpath + strlen(fpath);      /* get dir. */
1024                  while (cp > fpath) {
1025                          cp--;
1026                          if (ISDIRSEP(*cp)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines