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.1 by greg, Tue Nov 12 17:04:57 1991 UTC vs.
Revision 2.29 by schorsch, Thu Jul 3 22:41:44 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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
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"
20
21   #include  "otypes.h"
22  
23   int  xac;                               /* global xform argument count */
# Line 27 | Line 27 | int  xfa;                              /* start of xf arguments */
27   XF  tot;                                /* total transformation */
28   int  reverse;                           /* boolean true if scene mirrored */
29  
30 < int  invert = 0;                        /* boolean true to invert surfaces */
30 > int  invert;                            /* boolean true to invert surfaces */
31  
32 < int  expand = 0;                        /* boolean true to expand commands */
32 > int  expand;                            /* boolean true to expand commands */
33  
34 < char  *newmod = NULL;                   /* new modifier for surfaces */
34 > char  *newmod;                          /* new modifier for surfaces */
35  
36 < char  *idprefix = NULL;                 /* prefix for object identifiers */
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  
40 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
40 > short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
41  
42 < FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
42 > int  nrept = 1;                         /* number of array repetitions */
43  
44 < short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
44 > int stdinused = 0;                      /* stdin has been used by -f option? */
45  
46 < extern char  *malloc(), *fgetword();
46 > char  mainfn[PATH_MAX];                 /* main file name */
47 > FILE  *mainfp = NULL;                   /* main file pointer */
48  
49 < #define  progname  (xav[0])
49 > #define  progname  (xav[0])
50  
51  
52   main(argc, argv)                /* get transform options and transform file */
53   int  argc;
54   char  *argv[];
55   {
56 <        FILE  *fopen();
57 <        FILE  *fp;
56 >        int  mal_prefix = 0;
57 >        char  *fname;
58          int  a;
59 <                                        /* check for array */
59 >                                        /* check for argument list file */
60          for (a = 1; a < argc; a++)
61 +                if (!strcmp(argv[a], "-f"))
62 +                        return(doargf(argc, argv, a));
63 +                                        /* check for regular array */
64 +        for (a = 1; a < argc; a++)
65                  if (!strcmp(argv[a], "-a"))
66                          return(doarray(argc, argv, a));
67  
68 <        initotypes();
68 >        initotypes();                   /* initialize */
69 >        invert = 0;
70 >        expand = 1;
71 >        newmod = NULL;
72 >        idprefix = NULL;
73  
74          for (a = 1; a < argc; a++) {
75                  if (argv[a][0] == '-')
76                          switch (argv[a][1]) {
77                          case 'm':
78 <                                if (argv[a][2] || a+1 >= argc)
78 >                                if (argv[a][2] | a+1 >= argc)
79                                          break;
80 <                                newmod = argv[++a];
80 >                                a++;
81 >                                if (newmod == NULL)
82 >                                        newmod = argv[a];
83                                  continue;
84                          case 'n':
85 <                                if (argv[a][2] || a+1 >= argc)
85 >                                if (argv[a][2] | a+1 >= argc)
86                                          break;
87 <                                idprefix = argv[++a];
87 >                                a++;
88 >                                if (idprefix == NULL)
89 >                                        idprefix = argv[a];
90 >                                else {
91 >                                        register char   *newp;
92 >                                        newp = (char *)malloc(strlen(idprefix)+
93 >                                                        strlen(argv[a])+2);
94 >                                        if (newp == NULL)
95 >                                                exit(2);
96 >                                        sprintf(newp, "%s.%s",
97 >                                                        idprefix, argv[a]);
98 >                                        if (mal_prefix++)
99 >                                                free((void *)idprefix);
100 >                                        idprefix = newp;
101 >                                }
102                                  continue;
103 +                        case 'c':
104 +                                if (argv[a][2])
105 +                                        break;
106 +                                expand = 0;
107 +                                continue;
108                          case 'e':
109                                  if (argv[a][2])
110                                          break;
# Line 83 | Line 113 | char  *argv[];
113                          case 'I':
114                                  if (argv[a][2])
115                                          break;
116 <                                invert = 1;
116 >                                invert = !invert;
117                                  continue;
118                          }
119                  break;
# Line 112 | Line 142 | char  *argv[];
142                  printf(" %s", xav[a]);
143          putchar('\n');
144                                          /* transform input */
145 <        if (xac == argc)
146 <                xform("standard input", stdin);
147 <        else
145 >        if (xac == argc) {
146 >                if (stdinused) {
147 >                        fprintf(stderr, "%s: cannot use stdin more than once\n",
148 >                                        argv[0]);
149 >                        exit(1);
150 >                }
151 >                openmain(NULL);
152 >                xform(mainfn, mainfp);
153 >        } else
154                  for (a = xac; a < argc; a++) {
155 <                        if ((fp = fopen(argv[a], "r")) == NULL) {
156 <                                fprintf(stderr, "%s: cannot open \"%s\"\n",
121 <                                                progname, argv[a]);
122 <                                exit(1);
123 <                        }
124 <                        xform(argv[a], fp);
125 <                        fclose(fp);
155 >                        openmain(argv[a]);
156 >                        xform(mainfn, mainfp);
157                  }
158  
159 +        if (mal_prefix)
160 +                free((void *)idprefix);
161          return(0);
162   }
163  
164  
165 + 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];
173 +        char  *oldid;
174 +        register char   *cp;
175 +        FILE    *argfp;
176 +        int  n, i, k, newac, err;
177 +        
178 +        if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) {
179 +                fprintf(stderr, "%s: missing file for -f option\n", av[0]);
180 +                exit(1);
181 +        }
182 +        if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
183 +                if (stdinused++) {
184 +                        fprintf(stderr,
185 +                                "%s: cannot use stdin more than once\n",
186 +                                        av[0]);
187 +                        exit(1);
188 +                }
189 +                argfp = stdin;
190 +                n = 100;                /* we just don't know! */
191 +        } else {
192 +                if ((argfp = fopen(av[fi+1], "r")) == NULL) {
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 (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]);
204 +                        exit(1);
205 +                }
206 +                nrept *= n;
207 +                rewind(argfp);
208 +        }
209 +        err = 0; k = 0;                 /* read each arg list and call main */
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];
215 +                for (i = 1; i < fi; i++)
216 +                        avp[i] = av[i];
217 +                newac = i;
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 +                        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];
247 +                avp[newac] = NULL;
248 +                oldid = NULL;
249 +                for (i = 2; i < newac; i++)
250 +                        if (!strcmp(avp[i-1], "-n")) {
251 +                                oldid = avp[i];
252 +                                avp[i] = newid;
253 +                                break;
254 +                        }
255 +                if (oldid == NULL) {
256 +                        newav[0] = av[0];
257 +                        newav[1] = "-n";
258 +                        newav[2] = newid;
259 +                        avp = newav;
260 +                        newac += 2;
261 +                }
262 +                if (oldid == NULL)
263 +                        sprintf(newid, "i%d", k);
264 +                else
265 +                        sprintf(newid, "%s.%d", oldid, k);
266 +                err |= main(newac, avp);
267 +                k++;
268 +        }
269 +        fclose(argfp);
270 +        return(err);
271 + }
272 +
273 +
274   doarray(ac, av, ai)                     /* make array */
275   char  **av;
276   int  ac, ai;
# Line 136 | Line 278 | int  ac, ai;
278          char  *newav[256], **avp;
279          char  newid[128], repts[32];
280          char  *oldid = NULL;
281 <        int  i, err;
281 >        int  n, i, err;
282          
283 +        if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) {
284 +                fprintf(stderr, "%s: missing count for -a option\n", av[0]);
285 +                exit(1);
286 +        }
287 +        nrept *= n;
288          avp = newav+2;
289          avp[0] = av[0];
290          for (i = 1; i < ac; i++)
# Line 157 | Line 304 | int  ac, ai;
304                  ac += 2;
305          }
306          err = 0;
307 <        for (i = 0; i < atoi(av[ai+1]); i++) {
307 >        for (i = 0; i < n; i++) {
308                  if (oldid == NULL)
309                          sprintf(newid, "a%d", i);
310                  else
# Line 173 | Line 320 | xform(name, fin)                       /* transform stream by tot.xfm */
320   char  *name;
321   register FILE  *fin;
322   {
323 +        int  nobjs = 0;
324          register int  c;
325  
326          while ((c = getc(fin)) != EOF) {
# Line 188 | Line 336 | register FILE  *fin;
336                  } else if (c == '!') {                  /* command */
337                          ungetc(c, fin);
338                          xfcomm(name, fin);
339 +                        nobjs++;
340                  } else {                                /* object */
341                          ungetc(c, fin);
342                          xfobject(name, fin);
343 +                        nobjs++;
344                  }
345          }
346 +        if (nobjs == 0)
347 +                fprintf(stderr, "%s: (%s): warning - empty file\n",
348 +                                progname, name);
349   }
350  
351  
352   xfcomm(fname, fin)                      /* transform a command */
353 + char  *fname;
354   FILE  *fin;
355   {
202        FILE  *popen();
203        char  *fgetline();
356          FILE  *pin;
357          char  buf[512];
358          int  i;
359  
360          fgetline(buf, sizeof(buf), fin);
361          if (expand) {
362 <                if (xac > 2) {
363 <                        if ((pin = popen(buf+1, "r")) == NULL) {
364 <                                fprintf(stderr,
365 <                                "%s: (%s): cannot execute \"%s\"\n",
214 <                                                progname, fname, buf);
215 <                                exit(1);
216 <                        }
217 <                        xform(buf, pin);
218 <                        pclose(pin);
219 <                } else {
220 <                        fflush(stdout);
221 <                        system(buf+1);
362 >                if ((pin = popen(buf+1, "r")) == NULL) {
363 >                        fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n",
364 >                                        progname, fname, buf);
365 >                        exit(1);
366                  }
367 +                xform(buf, pin);
368 +                pclose(pin);
369          } else {
370                  printf("\n%s", buf);
371                  if (xac > 1) {
372 <                        printf(" | %s -e", 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 236 | Line 383 | xfobject(fname, fin)                           /* transform an object */
383   char  *fname;
384   FILE  *fin;
385   {
239        extern char  *strcpy();
386          char  typ[16], nam[MAXSTR];
387          int  fn;
388                                                  /* modifier and type */
# Line 248 | Line 394 | FILE  *fin;
394                                  progname, fname, typ);
395                  exit(1);
396          }
397 <        if (issurface(fn))
397 >        if (ismodifier(fn))
398 >                printf("\n%s %s ", nam, typ);
399 >        else
400                  printf("\n%s %s ", newmod != NULL ? newmod : nam,
401                                  invert ? ofun[tinvers[fn]].funame : typ);
254        else
255                printf("\n%s %s ", nam, typ);
402                                                  /* object name */
403          fgetword(nam, sizeof(nam), fin);
404 <        if (idprefix != NULL && issurface(fn))
259 <                printf("%s.%s\n", idprefix, nam);
260 <        else
404 >        if (idprefix == NULL || ismodifier(fn))
405                  printf("%s\n", nam);
406 +        else
407 +                printf("%s.%s\n", idprefix, nam);
408                                                  /* transform arguments */
409          if ((*ofun[fn].funp)(fin) < 0) {
410                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 272 | Line 418 | o_default(fin)                 /* pass on arguments unchanged */
418   FILE  *fin;
419   {
420          register int  i;
421 <        FUNARGS  fa;
421 >        FUNARGS  fa;
422  
423          if (readfargs(&fa, fin) != 1)
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
432 > #ifdef  IARGS
433                                          /* integer arguments */
434          printf("%d", fa.niargs);
435          for (i = 0; i < fa.niargs; i++)
# Line 304 | Line 452 | addxform(fin)                  /* add xf arguments to strings */
452   FILE  *fin;
453   {
454          register int  i;
455 <        FUNARGS  fa;
455 >        int  resetarr = 0;
456 >        FUNARGS  fa;
457  
458          if (readfargs(&fa, fin) != 1)
459                  return(-1);
460                                          /* string arguments */
461 <        printf("%d", fa.nsargs + xac-xfa);
462 <        for (i = 0; i < fa.nsargs; i++)
463 <                printf(" %s", fa.sarg[i]);
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 >                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 */
471                  printf(" %s", xav[i]);
472          printf("\n");
473 < #ifdef  IARGS
473 > #ifdef  IARGS
474                                          /* integer arguments */
475          printf("%d", fa.niargs);
476          for (i = 0; i < fa.niargs; i++)
# Line 334 | Line 489 | FILE  *fin;
489   }
490  
491  
337 int
338 otype(ofname)                   /* get object function number from its name */
339 register char  *ofname;
340 {
341        register int  i;
342
343        for (i = 0; i < NUMTYPES; i++)
344                if (!strcmp(ofun[i].funame, ofname))
345                        return(i);
346
347        return(-1);             /* not found */
348 }
349
350
492   alias(fin)                      /* transfer alias */
493   FILE  *fin;
494   {
# Line 363 | Line 504 | FILE  *fin;
504   m_glow(fin)                     /* transform arguments for proximity light */
505   FILE  *fin;
506   {
507 <        FUNARGS  fa;
507 >        FUNARGS  fa;
508  
509          if (readfargs(&fa, fin) != 1)
510                  return(-1);
# Line 382 | Line 523 | m_spot(fin)                    /* transform arguments for spotlight */
523   FILE  *fin;
524   {
525          FVECT  v;
526 <        FUNARGS  fa;
526 >        FUNARGS  fa;
527  
528          if (readfargs(&fa, fin) != 1)
529                  return(-1);
# Line 398 | Line 539 | FILE  *fin;
539   }
540  
541  
542 + m_mist(fin)             /* transform arguments for mist */
543 + FILE  *fin;
544 + {
545 +        FUNARGS  fa;
546 +        int     i;
547 +
548 +        if (readfargs(&fa, fin) != 1)
549 +                return(-1);
550 +        if (fa.nfargs > 7)
551 +                return(-1);
552 +        printf("%d", fa.nsargs);
553 +        if (idprefix == NULL)
554 +                for (i = 0; i < fa.nsargs; i++)
555 +                        printf(" %s", fa.sarg[i]);
556 +        else
557 +                for (i = 0; i < fa.nsargs; i++) {
558 +                        char    sname[256], *sp;
559 +                        register char   *cp1, *cp2 = sname;
560 +                                                        /* add idprefix */
561 +                        for (sp = fa.sarg[i]; *sp; sp = cp1) {
562 +                                for (cp1 = idprefix; *cp1; )
563 +                                        *cp2++ = *cp1++;
564 +                                *cp2++ = '.';
565 +                                for (cp1 = sp; *cp1 &&
566 +                                                (*cp2++ = *cp1++) != '>'; )
567 +                                        ;
568 +                        }
569 +                        *cp2 = '\0';
570 +                        printf(" %s", sname);
571 +                }
572 +        printf("\n0\n%d", fa.nfargs);
573 +        if (fa.nfargs > 2)
574 +                printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
575 +                                fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
576 +        for (i = 3; i < fa.nfargs; i++)
577 +                printf(" %12.6g", fa.farg[i]);
578 +        printf("\n");
579 +        freefargs(&fa);
580 +        return(0);
581 + }
582 +
583 +
584   m_dielectric(fin)               /* transform arguments for dielectric */
585   FILE  *fin;
586   {
587 <        double  pow();
405 <        FUNARGS  fa;
587 >        FUNARGS  fa;
588  
589          if (readfargs(&fa, fin) != 1)
590                  return(-1);
591          if (fa.nsargs != 0  || fa.nfargs != 5)
592                  return(-1);
593          printf("0\n0\n5");
594 <        printf(" %18.12g %18.12g %18.12g",
594 >        printf(" %12.6g %12.6g %12.6g",
595                  pow(fa.farg[0], 1.0/tot.sca),
596                  pow(fa.farg[1], 1.0/tot.sca),
597                  pow(fa.farg[2], 1.0/tot.sca));
598 <        printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]);
598 >        printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]);
599          freefargs(&fa);
600          return(0);
601   }
# Line 422 | Line 604 | FILE  *fin;
604   m_interface(fin)                /* transform arguments for interface */
605   FILE  *fin;
606   {
607 <        double  pow();
426 <        FUNARGS  fa;
607 >        FUNARGS  fa;
608  
609          if (readfargs(&fa, fin) != 1)
610                  return(-1);
611          if (fa.nsargs != 0  || fa.nfargs != 8)
612                  return(-1);
613          printf("0\n0\n8\n");
614 <        printf("%18.12g %18.12g %18.12g",
614 >        printf("%12.6g %12.6g %12.6g",
615                  pow(fa.farg[0], 1.0/tot.sca),
616                  pow(fa.farg[1], 1.0/tot.sca),
617                  pow(fa.farg[2], 1.0/tot.sca));
618 <        printf(" %18.12g\n", fa.farg[3]);
619 <        printf("%18.12g %18.12g %18.12g",
618 >        printf(" %12.6g\n", fa.farg[3]);
619 >        printf("%12.6g %12.6g %12.6g",
620                  pow(fa.farg[4], 1.0/tot.sca),
621                  pow(fa.farg[5], 1.0/tot.sca),
622                  pow(fa.farg[6], 1.0/tot.sca));
623 <        printf(" %18.12g\n", fa.farg[7]);
623 >        printf(" %12.6g\n", fa.farg[7]);
624          freefargs(&fa);
625          return(0);
626   }
# Line 450 | Line 631 | FILE  *fin;
631   {
632          int  i;
633          FVECT  v;
634 <        FUNARGS  fa;
634 >        FUNARGS  fa;
635  
636          if (readfargs(&fa, fin) != 1)
637                  return(-1);
638 <        if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15)
638 >        if (fa.nfargs < 9)
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 469 | Line 652 | FILE  *fin;
652          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
653                                          /* down vector */
654          multv3(v, fa.farg+6, tot.xfm);
655 <        printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
656 <                                        /* forground and background */
657 <        if (fa.nfargs == 11)
658 <                printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]);
659 <        else if (fa.nfargs == 15) {
660 <                printf(" %18.12g %18.12g %18.12g\n",
478 <                                fa.farg[9], fa.farg[10], fa.farg[11]);
479 <                printf(" %18.12g %18.12g %18.12g\n",
480 <                                fa.farg[12], fa.farg[13], fa.farg[14]);
655 >        printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]);
656 >                                        /* remaining arguments */
657 >        for (i = 9; i < fa.nfargs; i++) {
658 >                if (i%3 == 0)
659 >                        putchar('\n');
660 >                printf(" %18.12g", fa.farg[i]);
661          }
662 +        putchar('\n');
663          freefargs(&fa);
664          return(0);
665   }
# Line 488 | Line 669 | o_source(fin)                  /* transform source arguments */
669   FILE  *fin;
670   {
671          FVECT  dv;
672 <        FUNARGS  fa;
672 >        FUNARGS  fa;
673  
674          if (readfargs(&fa, fin) != 1)
675                  return(-1);
# Line 509 | Line 690 | o_sphere(fin)                  /* transform sphere arguments */
690   FILE  *fin;
691   {
692          FVECT  cent;
693 <        double  rad;
694 <        FUNARGS  fa;
693 >        double  rad;
694 >        FUNARGS  fa;
695  
696          if (readfargs(&fa, fin) != 1)
697                  return(-1);
698          if (fa.nsargs != 0  || fa.nfargs != 4)
699                  return(-1);
700          
701 <        multp3(cent, fa.farg, tot.xfm); /* transform center */
701 >        multp3(cent, fa.farg, tot.xfm); /* transform center */
702          
703          rad = fa.farg[3] * tot.sca;             /* scale radius */
704          
# Line 534 | Line 715 | FILE  *fin;
715   {
716          FVECT  p;
717          register int  i;
718 <        FUNARGS  fa;
718 >        FUNARGS  fa;
719  
720          if (readfargs(&fa, fin) != 1)
721                  return(-1);
# Line 559 | Line 740 | o_cone(fin)                    /* transform cone and cup arguments */
740   FILE  *fin;
741   {
742          FVECT  p0, p1;
743 <        double  r0, r1;
744 <        FUNARGS  fa;
743 >        double  r0, r1;
744 >        FUNARGS  fa;
745  
746          if (readfargs(&fa, fin) != 1)
747                  return(-1);
# Line 586 | Line 767 | o_cylinder(fin)                        /* transform cylinder and tube argum
767   FILE  *fin;
768   {
769          FVECT  p0, p1;
770 <        double  rad;
771 <        FUNARGS  fa;
770 >        double  rad;
771 >        FUNARGS  fa;
772  
773          if (readfargs(&fa, fin) != 1)
774                  return(-1);
# Line 611 | Line 792 | o_ring(fin)                    /* transform ring arguments */
792   FILE  *fin;
793   {
794          FVECT  p0, pd;
795 <        double  r0, r1;
796 <        FUNARGS  fa;
795 >        double  r0, r1;
796 >        FUNARGS  fa;
797  
798          if (readfargs(&fa, fin) != 1)
799                  return(-1);
# Line 640 | Line 821 | FILE  *fin;
821  
822   initotypes()                    /* initialize ofun[] array */
823   {
643        extern int  o_source();
644        extern int  o_sphere();
645        extern int  o_face();
646        extern int  o_cone();
647        extern int  o_cylinder();
648        extern int  o_ring();
649        extern int  m_glow();
650        extern int  m_spot();
651        extern int  m_dielectric();
652        extern int  m_interface();
653        extern int  text();
654        extern int  alias();
655        extern int  passargs();
656        extern int  addxform();
824          register int  i;
825  
826          if (ofun[OBJ_SOURCE].funp == o_source)
827                  return;                 /* done already */
661                                        /* alias is additional */
662        ofun[ALIAS].funame = ALIASID;
663        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 680 | Line 844 | initotypes()                   /* initialize ofun[] array */
844          ofun[MAT_SPOT].funp = m_spot;
845          ofun[MAT_DIELECTRIC].funp = m_dielectric;
846          ofun[MAT_INTERFACE].funp = m_interface;
847 +        ofun[MAT_MIST].funp = m_mist;
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;
855          tinvers[OBJ_CONE] = OBJ_CUP;
856          tinvers[OBJ_CUP] = OBJ_CONE;
# Line 695 | Line 861 | initotypes()                   /* initialize ofun[] array */
861          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
862          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
863   }
864 +
865 +
866 + #ifdef  OLDXFORM
867 + openmain(fname)
868 + char  *fname;
869 + {
870 +        if (fname == NULL) {
871 +                strcpy(mainfn, "standard input");
872 +                mainfp = stdin;
873 +                return;
874 +        }
875 +        if (mainfp != NULL) {
876 +                if (!strcmp(fname, mainfn)) {
877 +                        rewind(mainfp);
878 +                        return;
879 +                }
880 +                fclose(mainfp);
881 +        }
882 +        if ((mainfp = fopen(fname, "r")) == NULL) {
883 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
884 +                                progname, fname);
885 +                exit(1);
886 +        }
887 +        strcpy(mainfn, fname);
888 + }
889 + #else
890 + openmain(iname)         /* open input, changing directory for file */
891 + char  *iname;
892 + {
893 +        static char  origdir[PATH_MAX];
894 +        static char  curfn[PATH_MAX];
895 +        static int  diffdir;
896 +        register char  *fpath;
897 +
898 +        if (iname == NULL) {                    /* standard input */
899 +                if (mainfp == NULL) {
900 +                        register int  c;
901 +                        strcpy(mainfn, "standard input");
902 +                        if (nrept <= 1) {
903 +                                mainfp = stdin;
904 +                                return;                 /* just read once */
905 +                        }
906 +                                                        /* else copy */
907 +                        if ((mainfp = tmpfile()) == NULL) {
908 +                                fprintf(stderr,
909 +                                        "%s: cannot create temporary file\n",
910 +                                                progname);
911 +                                exit(1);
912 +                        }
913 +                        while ((c = getc(stdin)) != EOF)
914 +                                putc(c, mainfp);
915 +                }
916 +                rewind(mainfp);                 /* rewind copy */
917 +                return;
918 +        }
919 +        if (mainfp == NULL) {                   /* first call, initialize */
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 +                mainfp = NULL;
927 +                if (diffdir) {                  /* return to our directory */
928 +                        chdir(origdir);
929 +                        diffdir = 0;
930 +                }
931 +        }
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, iname);
937 +                exit(1);
938 +        }
939 +        if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
940 +                fpath += 2;
941 +                                                /* record path name */
942 +        strcpy(mainfn, fpath);
943 +        if (expand) {                           /* change to local directory */
944 +                register char  *cp = fpath + strlen(fpath);     /* get dir. */
945 +                while (cp > fpath) {
946 +                        cp--;
947 +                        if (ISDIRSEP(*cp)) {
948 +                                if (cp == fpath)
949 +                                        cp++;   /* root special case */
950 +                                break;
951 +                        }
952 +                }
953 +                *cp = '\0';
954 +                if (fpath[0]) {                 /* change to new directory? */
955 +                        if (chdir(fpath) < 0) {
956 +                                fprintf(stderr,
957 +                                "%s: cannot change directory to \"%s\"\n",
958 +                                                progname, fpath);
959 +                                exit(1);
960 +                        }
961 +                        diffdir++;
962 +                }
963 +                                                /* get final path component */
964 +                for (fpath = iname+strlen(iname);
965 +                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
966 +                        ;
967 +        }
968 +                                                /* finally, open the file */
969 +        if ((mainfp = fopen(fpath, "r")) == NULL) {
970 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
971 +                                progname, mainfn);
972 +                exit(1);
973 +        }
974 + }
975 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines