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.27 by greg, Fri Jun 27 22:27:45 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  
14 + #include  "standard.h"
15 + #include  "platform.h"
16 + #include  "paths.h"
17   #include  "object.h"
20
18   #include  "otypes.h"
19  
20   int  xac;                               /* global xform argument count */
# Line 27 | Line 24 | int  xfa;                              /* start of xf arguments */
24   XF  tot;                                /* total transformation */
25   int  reverse;                           /* boolean true if scene mirrored */
26  
27 < int  invert = 0;                        /* boolean true to invert surfaces */
27 > int  invert;                            /* boolean true to invert surfaces */
28  
29 < int  expand = 0;                        /* boolean true to expand commands */
29 > int  expand;                            /* boolean true to expand commands */
30  
31 < char  *newmod = NULL;                   /* new modifier for surfaces */
31 > char  *newmod;                          /* new modifier for surfaces */
32  
33 < char  *idprefix = NULL;                 /* prefix for object identifiers */
33 > char  *idprefix;                        /* prefix for object identifiers */
34  
35 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
35 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
36  
37 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
37 > short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
38  
39 < FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
39 > int  nrept = 1;                         /* number of array repetitions */
40  
41 < short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
41 > int stdinused = 0;                      /* stdin has been used by -f option? */
42  
43 < extern char  *malloc(), *fgetword();
43 > char  mainfn[MAXPATH];                  /* main file name */
44 > FILE  *mainfp = NULL;                   /* main file pointer */
45  
46 < #define  progname  (xav[0])
46 > #define  progname  (xav[0])
47  
48  
49   main(argc, argv)                /* get transform options and transform file */
50   int  argc;
51   char  *argv[];
52   {
53 <        FILE  *fopen();
54 <        FILE  *fp;
53 >        int  mal_prefix = 0;
54 >        char  *fname;
55          int  a;
56 <                                        /* check for array */
56 >                                        /* check for argument list file */
57          for (a = 1; a < argc; a++)
58 +                if (!strcmp(argv[a], "-f"))
59 +                        return(doargf(argc, argv, a));
60 +                                        /* check for regular array */
61 +        for (a = 1; a < argc; a++)
62                  if (!strcmp(argv[a], "-a"))
63                          return(doarray(argc, argv, a));
64  
65 <        initotypes();
65 >        initotypes();                   /* initialize */
66 >        invert = 0;
67 >        expand = 1;
68 >        newmod = NULL;
69 >        idprefix = NULL;
70  
71          for (a = 1; a < argc; a++) {
72                  if (argv[a][0] == '-')
73                          switch (argv[a][1]) {
74                          case 'm':
75 <                                if (argv[a][2] || a+1 >= argc)
75 >                                if (argv[a][2] | a+1 >= argc)
76                                          break;
77 <                                newmod = argv[++a];
77 >                                a++;
78 >                                if (newmod == NULL)
79 >                                        newmod = argv[a];
80                                  continue;
81                          case 'n':
82 <                                if (argv[a][2] || a+1 >= argc)
82 >                                if (argv[a][2] | a+1 >= argc)
83                                          break;
84 <                                idprefix = argv[++a];
84 >                                a++;
85 >                                if (idprefix == NULL)
86 >                                        idprefix = argv[a];
87 >                                else {
88 >                                        register char   *newp;
89 >                                        newp = (char *)malloc(strlen(idprefix)+
90 >                                                        strlen(argv[a])+2);
91 >                                        if (newp == NULL)
92 >                                                exit(2);
93 >                                        sprintf(newp, "%s.%s",
94 >                                                        idprefix, argv[a]);
95 >                                        if (mal_prefix++)
96 >                                                free((void *)idprefix);
97 >                                        idprefix = newp;
98 >                                }
99                                  continue;
100 +                        case 'c':
101 +                                if (argv[a][2])
102 +                                        break;
103 +                                expand = 0;
104 +                                continue;
105                          case 'e':
106                                  if (argv[a][2])
107                                          break;
# Line 83 | Line 110 | char  *argv[];
110                          case 'I':
111                                  if (argv[a][2])
112                                          break;
113 <                                invert = 1;
113 >                                invert = !invert;
114                                  continue;
115                          }
116                  break;
# Line 112 | Line 139 | char  *argv[];
139                  printf(" %s", xav[a]);
140          putchar('\n');
141                                          /* transform input */
142 <        if (xac == argc)
143 <                xform("standard input", stdin);
144 <        else
142 >        if (xac == argc) {
143 >                if (stdinused) {
144 >                        fprintf(stderr, "%s: cannot use stdin more than once\n",
145 >                                        argv[0]);
146 >                        exit(1);
147 >                }
148 >                openmain(NULL);
149 >                xform(mainfn, mainfp);
150 >        } else
151                  for (a = xac; a < argc; a++) {
152 <                        if ((fp = fopen(argv[a], "r")) == NULL) {
153 <                                fprintf(stderr, "%s: cannot open \"%s\"\n",
121 <                                                progname, argv[a]);
122 <                                exit(1);
123 <                        }
124 <                        xform(argv[a], fp);
125 <                        fclose(fp);
152 >                        openmain(argv[a]);
153 >                        xform(mainfn, mainfp);
154                  }
155  
156 +        if (mal_prefix)
157 +                free((void *)idprefix);
158          return(0);
159   }
160  
161  
162 + doargf(ac, av, fi)                      /* take argument list from file */
163 + char  **av;
164 + int  ac, fi;
165 + {
166 +        int  inquote;
167 +        char  *newav[256], **avp;
168 +        char  argbuf[1024];
169 +        char  newid[128];
170 +        char  *oldid;
171 +        register char   *cp;
172 +        FILE    *argfp;
173 +        int  n, i, k, newac, err;
174 +        
175 +        if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) {
176 +                fprintf(stderr, "%s: missing file for -f option\n", av[0]);
177 +                exit(1);
178 +        }
179 +        if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
180 +                if (stdinused++) {
181 +                        fprintf(stderr,
182 +                                "%s: cannot use stdin more than once\n",
183 +                                        av[0]);
184 +                        exit(1);
185 +                }
186 +                argfp = stdin;
187 +                n = 100;                /* we just don't know! */
188 +        } else {
189 +                if ((argfp = fopen(av[fi+1], "r")) == NULL) {
190 +                        fprintf(stderr,
191 +                                "%s: cannot open argument file \"%s\"\n",
192 +                                        av[0], av[fi+1]);
193 +                        exit(1);
194 +                }
195 +                n = 0;                  /* count number of lines in file */
196 +                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
197 +                        n += argbuf[0] && argbuf[0] != '#';
198 +                if (!n) {
199 +                        fprintf(stderr, "%s: empty argument file \"%s\"\n",
200 +                                        av[0], av[fi+1]);
201 +                        exit(1);
202 +                }
203 +                nrept *= n;
204 +                rewind(argfp);
205 +        }
206 +        err = 0; k = 0;                 /* read each arg list and call main */
207 +        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
208 +                if (!argbuf[0] || argbuf[0] == '#')
209 +                        continue;
210 +                avp = newav+2;
211 +                avp[0] = av[0];
212 +                for (i = 1; i < fi; i++)
213 +                        avp[i] = av[i];
214 +                newac = i;
215 +                cp = argbuf;            /* parse new words */
216 +                if (*cp == '!') cp++;
217 +                if (!strncmp(cp, "xform ", 6)) cp += 6;
218 +                inquote = 0;
219 +                for ( ; ; ) {
220 +                skipspaces:
221 +                        while (isspace(*cp))    /* nullify spaces */
222 +                                *cp++ = '\0';
223 +                        if ((*cp == '"' | *cp == '\''))
224 +                                inquote = *cp++;
225 +                        if (!*cp)               /* all done? */
226 +                                break;
227 +                        if (cp[0] == '\\' && cp[1])
228 +                                if (*++cp == '\n')
229 +                                        goto skipspaces;
230 +                        avp[newac++] = cp;      /* add argument to list */
231 +                        if (inquote) {
232 +                                while (*++cp)
233 +                                        if (*cp == inquote) {
234 +                                                *cp++ = '\0';
235 +                                                break;
236 +                                        }
237 +                        } else {
238 +                                while (*++cp && !isspace(*cp))
239 +                                        ;
240 +                        }
241 +                }
242 +                for (i = fi+2; i < ac; i++)
243 +                        avp[newac++] = av[i];
244 +                avp[newac] = NULL;
245 +                oldid = NULL;
246 +                for (i = 2; i < newac; i++)
247 +                        if (!strcmp(avp[i-1], "-n")) {
248 +                                oldid = avp[i];
249 +                                avp[i] = newid;
250 +                                break;
251 +                        }
252 +                if (oldid == NULL) {
253 +                        newav[0] = av[0];
254 +                        newav[1] = "-n";
255 +                        newav[2] = newid;
256 +                        avp = newav;
257 +                        newac += 2;
258 +                }
259 +                if (oldid == NULL)
260 +                        sprintf(newid, "i%d", k);
261 +                else
262 +                        sprintf(newid, "%s.%d", oldid, k);
263 +                err |= main(newac, avp);
264 +                k++;
265 +        }
266 +        fclose(argfp);
267 +        return(err);
268 + }
269 +
270 +
271   doarray(ac, av, ai)                     /* make array */
272   char  **av;
273   int  ac, ai;
# Line 136 | Line 275 | int  ac, ai;
275          char  *newav[256], **avp;
276          char  newid[128], repts[32];
277          char  *oldid = NULL;
278 <        int  i, err;
278 >        int  n, i, err;
279          
280 +        if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) {
281 +                fprintf(stderr, "%s: missing count for -a option\n", av[0]);
282 +                exit(1);
283 +        }
284 +        nrept *= n;
285          avp = newav+2;
286          avp[0] = av[0];
287          for (i = 1; i < ac; i++)
# Line 157 | Line 301 | int  ac, ai;
301                  ac += 2;
302          }
303          err = 0;
304 <        for (i = 0; i < atoi(av[ai+1]); i++) {
304 >        for (i = 0; i < n; i++) {
305                  if (oldid == NULL)
306                          sprintf(newid, "a%d", i);
307                  else
# Line 173 | Line 317 | xform(name, fin)                       /* transform stream by tot.xfm */
317   char  *name;
318   register FILE  *fin;
319   {
320 +        int  nobjs = 0;
321          register int  c;
322  
323          while ((c = getc(fin)) != EOF) {
# Line 188 | Line 333 | register FILE  *fin;
333                  } else if (c == '!') {                  /* command */
334                          ungetc(c, fin);
335                          xfcomm(name, fin);
336 +                        nobjs++;
337                  } else {                                /* object */
338                          ungetc(c, fin);
339                          xfobject(name, fin);
340 +                        nobjs++;
341                  }
342          }
343 +        if (nobjs == 0)
344 +                fprintf(stderr, "%s: (%s): warning - empty file\n",
345 +                                progname, name);
346   }
347  
348  
349   xfcomm(fname, fin)                      /* transform a command */
350 + char  *fname;
351   FILE  *fin;
352   {
202        FILE  *popen();
203        char  *fgetline();
353          FILE  *pin;
354          char  buf[512];
355          int  i;
356  
357          fgetline(buf, sizeof(buf), fin);
358          if (expand) {
359 <                if (xac > 2) {
360 <                        if ((pin = popen(buf+1, "r")) == NULL) {
361 <                                fprintf(stderr,
362 <                                "%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);
359 >                if ((pin = popen(buf+1, "r")) == NULL) {
360 >                        fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n",
361 >                                        progname, fname, buf);
362 >                        exit(1);
363                  }
364 +                xform(buf, pin);
365 +                pclose(pin);
366          } else {
367                  printf("\n%s", buf);
368                  if (xac > 1) {
369 <                        printf(" | %s -e", xav[0]);
369 >                        printf(" | %s -e", xav[0]);     /* expand next time */
370                          for (i = 1; i < xac; i++)
371 <                                printf(" %s", xav[i]);
371 >                                if (i >= xfa || strcmp(xav[i], "-c"))
372 >                                        printf(" %s", xav[i]);
373                  }
374                  putchar('\n');
375          }
# Line 236 | Line 380 | xfobject(fname, fin)                           /* transform an object */
380   char  *fname;
381   FILE  *fin;
382   {
239        extern char  *strcpy();
383          char  typ[16], nam[MAXSTR];
384          int  fn;
385                                                  /* modifier and type */
# Line 248 | Line 391 | FILE  *fin;
391                                  progname, fname, typ);
392                  exit(1);
393          }
394 <        if (issurface(fn))
394 >        if (ismodifier(fn))
395 >                printf("\n%s %s ", nam, typ);
396 >        else
397                  printf("\n%s %s ", newmod != NULL ? newmod : nam,
398                                  invert ? ofun[tinvers[fn]].funame : typ);
254        else
255                printf("\n%s %s ", nam, typ);
399                                                  /* object name */
400          fgetword(nam, sizeof(nam), fin);
401 <        if (idprefix != NULL && issurface(fn))
259 <                printf("%s.%s\n", idprefix, nam);
260 <        else
401 >        if (idprefix == NULL || ismodifier(fn))
402                  printf("%s\n", nam);
403 +        else
404 +                printf("%s.%s\n", idprefix, nam);
405                                                  /* transform arguments */
406          if ((*ofun[fn].funp)(fin) < 0) {
407                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 272 | Line 415 | o_default(fin)                 /* pass on arguments unchanged */
415   FILE  *fin;
416   {
417          register int  i;
418 <        FUNARGS  fa;
418 >        FUNARGS  fa;
419  
420          if (readfargs(&fa, fin) != 1)
421                  return(-1);
422                                          /* string arguments */
423          printf("%d", fa.nsargs);
424 <        for (i = 0; i < fa.nsargs; i++)
425 <                printf(" %s", fa.sarg[i]);
424 >        for (i = 0; i < fa.nsargs; i++) {
425 >                fputc(' ', stdout);
426 >                fputword(fa.sarg[i], stdout);
427 >        }
428          printf("\n");
429 < #ifdef  IARGS
429 > #ifdef  IARGS
430                                          /* integer arguments */
431          printf("%d", fa.niargs);
432          for (i = 0; i < fa.niargs; i++)
# Line 304 | Line 449 | addxform(fin)                  /* add xf arguments to strings */
449   FILE  *fin;
450   {
451          register int  i;
452 <        FUNARGS  fa;
452 >        int  resetarr = 0;
453 >        FUNARGS  fa;
454  
455          if (readfargs(&fa, fin) != 1)
456                  return(-1);
457                                          /* string arguments */
458 <        printf("%d", fa.nsargs + xac-xfa);
459 <        for (i = 0; i < fa.nsargs; i++)
460 <                printf(" %s", fa.sarg[i]);
458 >        if (xac > xfa && strcmp(xav[xfa], "-i"))
459 >                resetarr = 2;
460 >        printf("%d", fa.nsargs + resetarr + xac-xfa);
461 >        for (i = 0; i < fa.nsargs; i++) {
462 >                fputc(' ', stdout);
463 >                fputword(fa.sarg[i], stdout);
464 >        }
465 >        if (resetarr)
466 >                printf(" -i 1");
467          for (i = xfa; i < xac; i++)     /* add xf arguments */
468                  printf(" %s", xav[i]);
469          printf("\n");
470 < #ifdef  IARGS
470 > #ifdef  IARGS
471                                          /* integer arguments */
472          printf("%d", fa.niargs);
473          for (i = 0; i < fa.niargs; i++)
# Line 334 | Line 486 | FILE  *fin;
486   }
487  
488  
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
489   alias(fin)                      /* transfer alias */
490   FILE  *fin;
491   {
# Line 363 | Line 501 | FILE  *fin;
501   m_glow(fin)                     /* transform arguments for proximity light */
502   FILE  *fin;
503   {
504 <        FUNARGS  fa;
504 >        FUNARGS  fa;
505  
506          if (readfargs(&fa, fin) != 1)
507                  return(-1);
# Line 382 | Line 520 | m_spot(fin)                    /* transform arguments for spotlight */
520   FILE  *fin;
521   {
522          FVECT  v;
523 <        FUNARGS  fa;
523 >        FUNARGS  fa;
524  
525          if (readfargs(&fa, fin) != 1)
526                  return(-1);
# Line 398 | Line 536 | FILE  *fin;
536   }
537  
538  
539 + m_mist(fin)             /* transform arguments for mist */
540 + FILE  *fin;
541 + {
542 +        FUNARGS  fa;
543 +        int     i;
544 +
545 +        if (readfargs(&fa, fin) != 1)
546 +                return(-1);
547 +        if (fa.nfargs > 7)
548 +                return(-1);
549 +        printf("%d", fa.nsargs);
550 +        if (idprefix == NULL)
551 +                for (i = 0; i < fa.nsargs; i++)
552 +                        printf(" %s", fa.sarg[i]);
553 +        else
554 +                for (i = 0; i < fa.nsargs; i++) {
555 +                        char    sname[256], *sp;
556 +                        register char   *cp1, *cp2 = sname;
557 +                                                        /* add idprefix */
558 +                        for (sp = fa.sarg[i]; *sp; sp = cp1) {
559 +                                for (cp1 = idprefix; *cp1; )
560 +                                        *cp2++ = *cp1++;
561 +                                *cp2++ = '.';
562 +                                for (cp1 = sp; *cp1 &&
563 +                                                (*cp2++ = *cp1++) != '>'; )
564 +                                        ;
565 +                        }
566 +                        *cp2 = '\0';
567 +                        printf(" %s", sname);
568 +                }
569 +        printf("\n0\n%d", fa.nfargs);
570 +        if (fa.nfargs > 2)
571 +                printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
572 +                                fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
573 +        for (i = 3; i < fa.nfargs; i++)
574 +                printf(" %12.6g", fa.farg[i]);
575 +        printf("\n");
576 +        freefargs(&fa);
577 +        return(0);
578 + }
579 +
580 +
581   m_dielectric(fin)               /* transform arguments for dielectric */
582   FILE  *fin;
583   {
584 <        double  pow();
405 <        FUNARGS  fa;
584 >        FUNARGS  fa;
585  
586          if (readfargs(&fa, fin) != 1)
587                  return(-1);
588          if (fa.nsargs != 0  || fa.nfargs != 5)
589                  return(-1);
590          printf("0\n0\n5");
591 <        printf(" %18.12g %18.12g %18.12g",
591 >        printf(" %12.6g %12.6g %12.6g",
592                  pow(fa.farg[0], 1.0/tot.sca),
593                  pow(fa.farg[1], 1.0/tot.sca),
594                  pow(fa.farg[2], 1.0/tot.sca));
595 <        printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]);
595 >        printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]);
596          freefargs(&fa);
597          return(0);
598   }
# Line 422 | Line 601 | FILE  *fin;
601   m_interface(fin)                /* transform arguments for interface */
602   FILE  *fin;
603   {
604 <        double  pow();
426 <        FUNARGS  fa;
604 >        FUNARGS  fa;
605  
606          if (readfargs(&fa, fin) != 1)
607                  return(-1);
608          if (fa.nsargs != 0  || fa.nfargs != 8)
609                  return(-1);
610          printf("0\n0\n8\n");
611 <        printf("%18.12g %18.12g %18.12g",
611 >        printf("%12.6g %12.6g %12.6g",
612                  pow(fa.farg[0], 1.0/tot.sca),
613                  pow(fa.farg[1], 1.0/tot.sca),
614                  pow(fa.farg[2], 1.0/tot.sca));
615 <        printf(" %18.12g\n", fa.farg[3]);
616 <        printf("%18.12g %18.12g %18.12g",
615 >        printf(" %12.6g\n", fa.farg[3]);
616 >        printf("%12.6g %12.6g %12.6g",
617                  pow(fa.farg[4], 1.0/tot.sca),
618                  pow(fa.farg[5], 1.0/tot.sca),
619                  pow(fa.farg[6], 1.0/tot.sca));
620 <        printf(" %18.12g\n", fa.farg[7]);
620 >        printf(" %12.6g\n", fa.farg[7]);
621          freefargs(&fa);
622          return(0);
623   }
# Line 450 | Line 628 | FILE  *fin;
628   {
629          int  i;
630          FVECT  v;
631 <        FUNARGS  fa;
631 >        FUNARGS  fa;
632  
633          if (readfargs(&fa, fin) != 1)
634                  return(-1);
635 <        if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15)
635 >        if (fa.nfargs < 9)
636                  return(-1);
637                                          /* string arguments */
638          printf("%d", fa.nsargs);
639 <        for (i = 0; i < fa.nsargs; i++)
640 <                printf(" %s", fa.sarg[i]);
639 >        for (i = 0; i < fa.nsargs; i++) {
640 >                fputc(' ', stdout);
641 >                fputword(fa.sarg[i], stdout);
642 >        }
643          printf("\n0\n%d\n", fa.nfargs);
644                                          /* anchor point */
645          multp3(v, fa.farg, tot.xfm);
# Line 469 | Line 649 | FILE  *fin;
649          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
650                                          /* down vector */
651          multv3(v, fa.farg+6, tot.xfm);
652 <        printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
653 <                                        /* forground and background */
654 <        if (fa.nfargs == 11)
655 <                printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]);
656 <        else if (fa.nfargs == 15) {
657 <                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]);
652 >        printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]);
653 >                                        /* remaining arguments */
654 >        for (i = 9; i < fa.nfargs; i++) {
655 >                if (i%3 == 0)
656 >                        putchar('\n');
657 >                printf(" %18.12g", fa.farg[i]);
658          }
659 +        putchar('\n');
660          freefargs(&fa);
661          return(0);
662   }
# Line 488 | Line 666 | o_source(fin)                  /* transform source arguments */
666   FILE  *fin;
667   {
668          FVECT  dv;
669 <        FUNARGS  fa;
669 >        FUNARGS  fa;
670  
671          if (readfargs(&fa, fin) != 1)
672                  return(-1);
# Line 509 | Line 687 | o_sphere(fin)                  /* transform sphere arguments */
687   FILE  *fin;
688   {
689          FVECT  cent;
690 <        double  rad;
691 <        FUNARGS  fa;
690 >        double  rad;
691 >        FUNARGS  fa;
692  
693          if (readfargs(&fa, fin) != 1)
694                  return(-1);
695          if (fa.nsargs != 0  || fa.nfargs != 4)
696                  return(-1);
697          
698 <        multp3(cent, fa.farg, tot.xfm); /* transform center */
698 >        multp3(cent, fa.farg, tot.xfm); /* transform center */
699          
700          rad = fa.farg[3] * tot.sca;             /* scale radius */
701          
# Line 534 | Line 712 | FILE  *fin;
712   {
713          FVECT  p;
714          register int  i;
715 <        FUNARGS  fa;
715 >        FUNARGS  fa;
716  
717          if (readfargs(&fa, fin) != 1)
718                  return(-1);
# Line 559 | Line 737 | o_cone(fin)                    /* transform cone and cup arguments */
737   FILE  *fin;
738   {
739          FVECT  p0, p1;
740 <        double  r0, r1;
741 <        FUNARGS  fa;
740 >        double  r0, r1;
741 >        FUNARGS  fa;
742  
743          if (readfargs(&fa, fin) != 1)
744                  return(-1);
# Line 586 | Line 764 | o_cylinder(fin)                        /* transform cylinder and tube argum
764   FILE  *fin;
765   {
766          FVECT  p0, p1;
767 <        double  rad;
768 <        FUNARGS  fa;
767 >        double  rad;
768 >        FUNARGS  fa;
769  
770          if (readfargs(&fa, fin) != 1)
771                  return(-1);
# Line 611 | Line 789 | o_ring(fin)                    /* transform ring arguments */
789   FILE  *fin;
790   {
791          FVECT  p0, pd;
792 <        double  r0, r1;
793 <        FUNARGS  fa;
792 >        double  r0, r1;
793 >        FUNARGS  fa;
794  
795          if (readfargs(&fa, fin) != 1)
796                  return(-1);
# Line 640 | Line 818 | FILE  *fin;
818  
819   initotypes()                    /* initialize ofun[] array */
820   {
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();
821          register int  i;
822  
823          if (ofun[OBJ_SOURCE].funp == o_source)
824                  return;                 /* done already */
661                                        /* alias is additional */
662        ofun[ALIAS].funame = ALIASID;
663        ofun[ALIAS].flags = 0;
825                                          /* functions get new transform */
826 <        for (i = 0; i < NUMTYPES; i++)
826 >        for (i = 0; i < NUMOTYPE; i++)
827                  if (hasfunc(i))
828                          ofun[i].funp = addxform;
829                                          /* special cases */
# Line 680 | Line 841 | initotypes()                   /* initialize ofun[] array */
841          ofun[MAT_SPOT].funp = m_spot;
842          ofun[MAT_DIELECTRIC].funp = m_dielectric;
843          ofun[MAT_INTERFACE].funp = m_interface;
844 +        ofun[MAT_MIST].funp = m_mist;
845          ofun[PAT_CTEXT].funp =
846          ofun[PAT_BTEXT].funp =
847          ofun[MIX_TEXT].funp = text;
848 <        ofun[ALIAS].funp = alias;
848 >        ofun[MOD_ALIAS].funp = alias;
849                                          /* surface inverses */
850 +        tinvers[OBJ_FACE] = OBJ_FACE;
851          tinvers[OBJ_SOURCE] = OBJ_SOURCE;
852          tinvers[OBJ_CONE] = OBJ_CUP;
853          tinvers[OBJ_CUP] = OBJ_CONE;
# Line 695 | Line 858 | initotypes()                   /* initialize ofun[] array */
858          tinvers[OBJ_TUBE] = OBJ_CYLINDER;
859          tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
860   }
861 +
862 +
863 + #ifdef  OLDXFORM
864 + openmain(fname)
865 + char  *fname;
866 + {
867 +        if (fname == NULL) {
868 +                strcpy(mainfn, "standard input");
869 +                mainfp = stdin;
870 +                return;
871 +        }
872 +        if (mainfp != NULL) {
873 +                if (!strcmp(fname, mainfn)) {
874 +                        rewind(mainfp);
875 +                        return;
876 +                }
877 +                fclose(mainfp);
878 +        }
879 +        if ((mainfp = fopen(fname, "r")) == NULL) {
880 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
881 +                                progname, fname);
882 +                exit(1);
883 +        }
884 +        strcpy(mainfn, fname);
885 + }
886 + #else
887 + openmain(iname)         /* open input, changing directory for file */
888 + char  *iname;
889 + {
890 +        static char  origdir[MAXPATH];
891 +        static char  curfn[MAXPATH];
892 +        static int  diffdir;
893 +        register char  *fpath;
894 +
895 +        if (iname == NULL) {                    /* standard input */
896 +                if (mainfp == NULL) {
897 +                        register int  c;
898 +                        strcpy(mainfn, "standard input");
899 +                        if (nrept <= 1) {
900 +                                mainfp = stdin;
901 +                                return;                 /* just read once */
902 +                        }
903 +                                                        /* else copy */
904 +                        if ((mainfp = tmpfile()) == NULL) {
905 +                                fprintf(stderr,
906 +                                        "%s: cannot create temporary file\n",
907 +                                                progname);
908 +                                exit(1);
909 +                        }
910 +                        while ((c = getc(stdin)) != EOF)
911 +                                putc(c, mainfp);
912 +                }
913 +                rewind(mainfp);                 /* rewind copy */
914 +                return;
915 +        }
916 +        if (mainfp == NULL) {                   /* first call, initialize */
917 +                getwd(origdir);
918 +        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
919 +                rewind(mainfp);
920 +                return;
921 +        } else {                                /* else close old stream */
922 +                fclose(mainfp);
923 +                mainfp = NULL;
924 +                if (diffdir) {                  /* return to our directory */
925 +                        chdir(origdir);
926 +                        diffdir = 0;
927 +                }
928 +        }
929 +        strcpy(curfn, iname);                   /* remember input name */
930 +                                                /* get full path for file */
931 +        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
932 +                fprintf(stderr, "%s: cannot find file \"%s\"\n",
933 +                                progname, iname);
934 +                exit(1);
935 +        }
936 +        if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
937 +                fpath += 2;
938 +                                                /* record path name */
939 +        strcpy(mainfn, fpath);
940 +        if (expand) {                           /* change to local directory */
941 +                register char  *cp = fpath + strlen(fpath);     /* get dir. */
942 +                while (cp > fpath) {
943 +                        cp--;
944 +                        if (ISDIRSEP(*cp)) {
945 +                                if (cp == fpath)
946 +                                        cp++;   /* root special case */
947 +                                break;
948 +                        }
949 +                }
950 +                *cp = '\0';
951 +                if (fpath[0]) {                 /* change to new directory? */
952 +                        if (chdir(fpath) < 0) {
953 +                                fprintf(stderr,
954 +                                "%s: cannot change directory to \"%s\"\n",
955 +                                                progname, fpath);
956 +                                exit(1);
957 +                        }
958 +                        diffdir++;
959 +                }
960 +                                                /* get final path component */
961 +                for (fpath = iname+strlen(iname);
962 +                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
963 +                        ;
964 +        }
965 +                                                /* finally, open the file */
966 +        if ((mainfp = fopen(fpath, "r")) == NULL) {
967 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
968 +                                progname, mainfn);
969 +                exit(1);
970 +        }
971 + }
972 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines