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.29 by schorsch, Thu Jul 3 22:41:44 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines