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 1.14 by greg, Fri Jul 19 09:43:40 1991 UTC vs.
Revision 2.34 by schorsch, Mon Oct 27 10:27:25 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  "platform.h"
15 + #include  "rtmath.h"
16 + #include  "rtprocess.h" /* win_popen() */
17 + #include  "paths.h"
18   #include  "object.h"
20
19   #include  "otypes.h"
20  
21   int  xac;                               /* global xform argument count */
# Line 25 | Line 23 | char  **xav;                           /* global xform argument pointer */
23   int  xfa;                               /* start of xf arguments */
24  
25   XF  tot;                                /* total transformation */
26 < int  reverse;                           /* boolean true if scene inverted */
26 > int  reverse;                           /* boolean true if scene mirrored */
27  
28 < int  expand = 0;                        /* boolean true to expand commands */
28 > int  invert;                            /* boolean true to invert surfaces */
29  
30 < char  *newmod = NULL;                   /* new modifier for surfaces */
30 > int  expand;                            /* boolean true to expand commands */
31  
32 < char  *idprefix = NULL;                 /* prefix for object identifiers */
32 > char  *newmod;                          /* new modifier for surfaces */
33  
34 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
34 > char  *idprefix;                        /* prefix for object identifiers */
35  
36 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
36 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
37  
38 < FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
38 > short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
39  
40 < extern char  *malloc();
40 > int  nrept = 1;                         /* number of array repetitions */
41  
42 < #define  progname  (xav[0])
42 > int stdinused = 0;                      /* stdin has been used by -f option? */
43  
44 + char  mainfn[PATH_MAX];                 /* main file name */
45 + FILE  *mainfp = NULL;                   /* main file pointer */
46  
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;
109                                  expand = 1;
110                                  continue;
111 +                        case 'I':
112 +                                if (argv[a][2])
113 +                                        break;
114 +                                invert = !invert;
115 +                                continue;
116                          }
117                  break;
118          }
# Line 85 | Line 122 | char  *argv[];
122  
123          a += xf(&tot, argc-a, argv+a);
124  
125 <        if (reverse = tot.sca < 0.0)
125 >        if ( (reverse = tot.sca < 0.0) )
126                  tot.sca = -tot.sca;
127 +        if (invert)
128 +                reverse = !reverse;
129  
130          if (a < argc && argv[a][0] == '-') {
131                  fprintf(stderr, "%s: command line error at '%s'\n",
# Line 101 | 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",
110 <                                                progname, argv[a]);
111 <                                exit(1);
112 <                        }
113 <                        xform(argv[a], fp);
114 <                        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 125 | 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 146 | 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 162 | 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 177 | 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   {
191        FILE  *popen();
192        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",
203 <                                                progname, fname, buf);
204 <                                exit(1);
205 <                        }
206 <                        xform(buf, pin);
207 <                        pclose(pin);
208 <                } else {
209 <                        fflush(stdout);
210 <                        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 228 | Line 384 | FILE  *fin;
384          char  typ[16], nam[MAXSTR];
385          int  fn;
386                                                  /* modifier and type */
387 <        fscanf(fin, "%s %s", nam, typ);
387 >        strcpy(typ, "EOF");
388 >        fgetword(nam, sizeof(nam), fin);
389 >        fgetword(typ, sizeof(typ), fin);
390          if ((fn = otype(typ)) < 0) {
391                  fprintf(stderr, "%s: (%s): unknown object type \"%s\"\n",
392                                  progname, fname, typ);
393                  exit(1);
394          }
395 <        printf("\n%s %s ", newmod!=NULL && issurface(fn) ? newmod : nam, typ);
396 <                                                /* object name */
239 <        fscanf(fin, "%s", nam);
240 <        if (idprefix != NULL && issurface(fn))
241 <                printf("%s.%s\n", idprefix, nam);
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);
400 +                                                /* object name */
401 +        fgetword(nam, sizeof(nam), fin);
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 254 | 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) <= 0)
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++)
434                  printf(" %d", fa.iarg[i]);
435          printf("\n");
436 + #else
437 +        printf("0\n");
438   #endif
439                                          /* float arguments */
440          printf("%d", fa.nfargs);
# Line 284 | Line 450 | addxform(fin)                  /* add xf arguments to strings */
450   FILE  *fin;
451   {
452          register int  i;
453 <        FUNARGS  fa;
453 >        int  resetarr = 0;
454 >        FUNARGS  fa;
455  
456 <        if (readfargs(&fa, fin) <= 0)
456 >        if (readfargs(&fa, fin) != 1)
457                  return(-1);
458                                          /* string arguments */
459 <        printf("%d", fa.nsargs + xac-xfa);
460 <        for (i = 0; i < fa.nsargs; i++)
461 <                printf(" %s", fa.sarg[i]);
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 >                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++)
475                  printf(" %d", fa.iarg[i]);
476          printf("\n");
477 + #else
478 +        printf("0\n");
479   #endif
480                                          /* float arguments */
481          printf("%d", fa.nfargs);
# Line 312 | Line 487 | FILE  *fin;
487   }
488  
489  
315 int
316 otype(ofname)                   /* get object function number from its name */
317 register char  *ofname;
318 {
319        register int  i;
320
321        for (i = 0; i < NUMTYPES; i++)
322                if (!strcmp(ofun[i].funame, ofname))
323                        return(i);
324
325        return(-1);             /* not found */
326 }
327
328
490   alias(fin)                      /* transfer alias */
491   FILE  *fin;
492   {
493          char  aliasnm[MAXSTR];
494  
495 <        if (fscanf(fin, "%s", aliasnm) != 1)
495 >        if (fgetword(aliasnm, MAXSTR, fin) == NULL)
496                  return(-1);
497          printf("\t%s\n", aliasnm);
498          return(0);
# Line 341 | 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) <= 0)
507 >        if (readfargs(&fa, fin) != 1)
508                  return(-1);
509          if (fa.nsargs != 0  || fa.nfargs != 4)
510                  return(-1);
# Line 359 | Line 520 | FILE  *fin;
520   m_spot(fin)                     /* transform arguments for spotlight */
521   FILE  *fin;
522   {
523 <        double  v[3];
524 <        FUNARGS  fa;
523 >        FVECT  v;
524 >        FUNARGS  fa;
525  
526 <        if (readfargs(&fa, fin) <= 0)
526 >        if (readfargs(&fa, fin) != 1)
527                  return(-1);
528          if (fa.nsargs != 0  || fa.nfargs != 7)
529                  return(-1);
# Line 376 | 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();
383 <        FUNARGS  fa;
585 >        FUNARGS  fa;
586  
587 <        if (readfargs(&fa, fin) <= 0)
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 400 | Line 602 | FILE  *fin;
602   m_interface(fin)                /* transform arguments for interface */
603   FILE  *fin;
604   {
605 <        double  pow();
404 <        FUNARGS  fa;
605 >        FUNARGS  fa;
606  
607 <        if (readfargs(&fa, fin) <= 0)
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 427 | Line 628 | text(fin)                      /* transform text arguments */
628   FILE  *fin;
629   {
630          int  i;
631 <        double  v[3];
632 <        FUNARGS  fa;
631 >        FVECT  v;
632 >        FUNARGS  fa;
633  
634 <        if (readfargs(&fa, fin) <= 0)
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 447 | 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",
456 <                                fa.farg[9], fa.farg[10], fa.farg[11]);
457 <                printf(" %18.12g %18.12g %18.12g\n",
458 <                                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 465 | Line 666 | FILE  *fin;
666   o_source(fin)                   /* transform source arguments */
667   FILE  *fin;
668   {
669 <        double  dv[3];
670 <        FUNARGS  fa;
669 >        FVECT  dv;
670 >        FUNARGS  fa;
671  
672 <        if (readfargs(&fa, fin) <= 0)
672 >        if (readfargs(&fa, fin) != 1)
673                  return(-1);
674          if (fa.nsargs != 0  || fa.nfargs != 4)
675                  return(-1);
# Line 486 | Line 687 | FILE  *fin;
687   o_sphere(fin)                   /* transform sphere arguments */
688   FILE  *fin;
689   {
690 <        double  cent[3], rad;
691 <        FUNARGS  fa;
690 >        FVECT  cent;
691 >        double  rad;
692 >        FUNARGS  fa;
693  
694 <        if (readfargs(&fa, fin) <= 0)
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 509 | Line 711 | FILE  *fin;
711   o_face(fin)                     /* transform face arguments */
712   FILE  *fin;
713   {
714 <        double  p[3];
714 >        FVECT  p;
715          register int  i;
716 <        FUNARGS  fa;
716 >        FUNARGS  fa;
717  
718 <        if (readfargs(&fa, fin) <= 0)
718 >        if (readfargs(&fa, fin) != 1)
719                  return(-1);
720          if (fa.nsargs != 0  || fa.nfargs % 3)
721                  return(-1);
# Line 535 | Line 737 | FILE  *fin;
737   o_cone(fin)                     /* transform cone and cup arguments */
738   FILE  *fin;
739   {
740 <        double  p0[3], p1[3], r0, r1;
741 <        FUNARGS  fa;
740 >        FVECT  p0, p1;
741 >        double  r0, r1;
742 >        FUNARGS  fa;
743  
744 <        if (readfargs(&fa, fin) <= 0)
744 >        if (readfargs(&fa, fin) != 1)
745                  return(-1);
746          if (fa.nsargs != 0  || fa.nfargs != 8)
747                  return(-1);
# Line 561 | Line 764 | FILE  *fin;
764   o_cylinder(fin)                 /* transform cylinder and tube arguments */
765   FILE  *fin;
766   {
767 <        double  p0[3], p1[3], rad;
768 <        FUNARGS  fa;
767 >        FVECT  p0, p1;
768 >        double  rad;
769 >        FUNARGS  fa;
770  
771 <        if (readfargs(&fa, fin) <= 0)
771 >        if (readfargs(&fa, fin) != 1)
772                  return(-1);
773          if (fa.nsargs != 0  || fa.nfargs != 7)
774                  return(-1);
# Line 585 | Line 789 | FILE  *fin;
789   o_ring(fin)                     /* transform ring arguments */
790   FILE  *fin;
791   {
792 <        double  p0[3], pd[3], r0, r1;
793 <        FUNARGS  fa;
792 >        FVECT  p0, pd;
793 >        double  r0, r1;
794 >        FUNARGS  fa;
795  
796 <        if (readfargs(&fa, fin) <= 0)
796 >        if (readfargs(&fa, fin) != 1)
797                  return(-1);
798          if (fa.nsargs != 0  || fa.nfargs != 8)
799                  return(-1);
# Line 597 | Line 802 | FILE  *fin;
802  
803          multp3(p0, fa.farg, tot.xfm);
804          multv3(pd, fa.farg+3, tot.xfm);
805 +        if (invert) {
806 +                pd[0] = -pd[0];
807 +                pd[1] = -pd[1];
808 +                pd[2] = -pd[2];
809 +        }
810          r0 = fa.farg[6] * tot.sca;
811          r1 = fa.farg[7] * tot.sca;
812          printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]);
# Line 609 | Line 819 | FILE  *fin;
819  
820   initotypes()                    /* initialize ofun[] array */
821   {
612        extern int  o_source();
613        extern int  o_sphere();
614        extern int  o_face();
615        extern int  o_cone();
616        extern int  o_cylinder();
617        extern int  o_ring();
618        extern int  m_glow();
619        extern int  m_spot();
620        extern int  m_dielectric();
621        extern int  m_interface();
622        extern int  text();
623        extern int  alias();
624        extern int  passargs();
625        extern int  addxform();
822          register int  i;
823  
824          if (ofun[OBJ_SOURCE].funp == o_source)
825                  return;                 /* done already */
630                                        /* alias is additional */
631        ofun[ALIAS].funame = ALIASID;
632        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 644 | Line 837 | initotypes()                   /* initialize ofun[] array */
837          ofun[OBJ_CYLINDER].funp =
838          ofun[OBJ_TUBE].funp = o_cylinder;
839          ofun[OBJ_RING].funp = o_ring;
840 <        ofun[OBJ_INSTANCE].funp = addxform;
840 >        ofun[OBJ_INSTANCE].funp =
841 >        ofun[OBJ_MESH].funp = addxform;
842          ofun[MAT_GLOW].funp = m_glow;
843          ofun[MAT_SPOT].funp = m_spot;
844          ofun[MAT_DIELECTRIC].funp = m_dielectric;
845          ofun[MAT_INTERFACE].funp = m_interface;
846 +        ofun[MAT_MIST].funp = m_mist;
847          ofun[PAT_CTEXT].funp =
848          ofun[PAT_BTEXT].funp =
849          ofun[MIX_TEXT].funp = text;
850 <        ofun[ALIAS].funp = alias;
850 >        ofun[MOD_ALIAS].funp = alias;
851 >                                        /* surface inverses */
852 >        tinvers[OBJ_FACE] = OBJ_FACE;
853 >        tinvers[OBJ_SOURCE] = OBJ_SOURCE;
854 >        tinvers[OBJ_CONE] = OBJ_CUP;
855 >        tinvers[OBJ_CUP] = OBJ_CONE;
856 >        tinvers[OBJ_SPHERE] = OBJ_BUBBLE;
857 >        tinvers[OBJ_BUBBLE] = OBJ_SPHERE;
858 >        tinvers[OBJ_RING] = OBJ_RING;
859 >        tinvers[OBJ_CYLINDER] = OBJ_TUBE;
860 >        tinvers[OBJ_TUBE] = OBJ_CYLINDER;
861 >        tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
862   }
863 +
864 +
865 + #ifdef  OLDXFORM
866 + openmain(fname)
867 + char  *fname;
868 + {
869 +        if (fname == NULL) {
870 +                strcpy(mainfn, "standard input");
871 +                mainfp = stdin;
872 +                return;
873 +        }
874 +        if (mainfp != NULL) {
875 +                if (!strcmp(fname, mainfn)) {
876 +                        rewind(mainfp);
877 +                        return;
878 +                }
879 +                fclose(mainfp);
880 +        }
881 +        if ((mainfp = fopen(fname, "r")) == NULL) {
882 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
883 +                                progname, fname);
884 +                exit(1);
885 +        }
886 +        strcpy(mainfn, fname);
887 + }
888 + #else
889 + openmain(iname)         /* open input, changing directory for file */
890 + char  *iname;
891 + {
892 +        static char  origdir[PATH_MAX];
893 +        static char  curfn[PATH_MAX];
894 +        static int  diffdir;
895 +        register char  *fpath;
896 +
897 +        if (iname == NULL) {                    /* standard input */
898 +                if (mainfp == NULL) {
899 +                        register int  c;
900 +                        strcpy(mainfn, "standard input");
901 +                        if (nrept <= 1) {
902 +                                mainfp = stdin;
903 +                                return;                 /* just read once */
904 +                        }
905 +                                                        /* else copy */
906 +                        if ((mainfp = tmpfile()) == NULL) {
907 +                                fprintf(stderr,
908 +                                        "%s: cannot create temporary file\n",
909 +                                                progname);
910 +                                exit(1);
911 +                        }
912 +                        while ((c = getc(stdin)) != EOF)
913 +                                putc(c, mainfp);
914 +                }
915 +                rewind(mainfp);                 /* rewind copy */
916 +                return;
917 +        }
918 +        if (mainfp == NULL) {                   /* first call, initialize */
919 +                getcwd(origdir, sizeof(origdir));
920 +        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
921 +                rewind(mainfp);
922 +                return;
923 +        } else {                                /* else close old stream */
924 +                fclose(mainfp);
925 +                mainfp = NULL;
926 +                if (diffdir) {                  /* return to our directory */
927 +                        chdir(origdir);
928 +                        diffdir = 0;
929 +                }
930 +        }
931 +        strcpy(curfn, iname);                   /* remember input name */
932 +                                                /* get full path for file */
933 +        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
934 +                fprintf(stderr, "%s: cannot find file \"%s\"\n",
935 +                                progname, iname);
936 +                exit(1);
937 +        }
938 +        if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
939 +                fpath += 2;
940 +                                                /* record path name */
941 +        strcpy(mainfn, fpath);
942 +        if (expand) {                           /* change to local directory */
943 +                register char  *cp = fpath + strlen(fpath);     /* get dir. */
944 +                while (cp > fpath) {
945 +                        cp--;
946 +                        if (ISDIRSEP(*cp)) {
947 +                                if (cp == fpath)
948 +                                        cp++;   /* root special case */
949 +                                break;
950 +                        }
951 +                }
952 +                *cp = '\0';
953 +                if (fpath[0]) {                 /* change to new directory? */
954 +                        if (chdir(fpath) < 0) {
955 +                                fprintf(stderr,
956 +                                "%s: cannot change directory to \"%s\"\n",
957 +                                                progname, fpath);
958 +                                exit(1);
959 +                        }
960 +                        diffdir++;
961 +                }
962 +                                                /* get final path component */
963 +                for (fpath = iname+strlen(iname);
964 +                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
965 +                        ;
966 +        }
967 +                                                /* finally, open the file */
968 +        if ((mainfp = fopen(fpath, "r")) == NULL) {
969 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
970 +                                progname, mainfn);
971 +                exit(1);
972 +        }
973 + }
974 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines