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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines