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.45 by greg, Wed Jun 22 17:05:00 2011 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  "paths.h"
16 + #include  "rtprocess.h" /* win_popen() */
17 + #include  "rtio.h"
18 + #include  "rtmath.h"
19   #include  "object.h"
20
20   #include  "otypes.h"
21  
22   int  xac;                               /* global xform argument count */
# Line 25 | Line 24 | char  **xav;                           /* global xform argument pointer */
24   int  xfa;                               /* start of xf arguments */
25  
26   XF  tot;                                /* total transformation */
27 < int  reverse;                           /* boolean true if scene inverted */
27 > int  reverse;                           /* boolean true if scene mirrored */
28  
29 < int  expand = 0;                        /* boolean true to expand commands */
29 > int  invert;                            /* boolean true to invert surfaces */
30  
31 < char  *newmod = NULL;                   /* new modifier for surfaces */
31 > int  expand;                            /* boolean true to expand commands */
32  
33 < char  *idprefix = NULL;                 /* prefix for object identifiers */
33 > char  *newmod;                          /* new modifier for surfaces */
34  
35 < #define  ALIAS          NUMOTYPE        /* put alias at end of array */
35 > char  *idprefix;                        /* prefix for object identifiers */
36  
37 < #define  NUMTYPES       (NUMOTYPE+1)    /* total number of object types */
37 > FUN  ofun[NUMOTYPE] = INIT_OTYPE;       /* default types and actions */
38  
39 < FUN  ofun[NUMTYPES] = INIT_OTYPE;       /* default types and actions */
39 > short  tinvers[NUMOTYPE];               /* inverse types for surfaces */
40  
41 < extern char  *malloc();
41 > int  nrept = 1;                         /* number of array repetitions */
42  
43 < #define  progname  (xav[0])
43 > int stdinused = 0;                      /* stdin has been used by -f option? */
44  
45 + char  mainfn[PATH_MAX];                 /* main file name */
46 + FILE  *mainfp = NULL;                   /* main file pointer */
47  
48 < main(argc, argv)                /* get transform options and transform file */
49 < int  argc;
50 < char  *argv[];
48 > #define  progname  (xav[0])
49 >
50 > static int doargf(int ac, char **av, int fi);
51 > static int doarray(int ac, char **av, int ai);
52 > static void xform(char *name, FILE *fin);
53 > static void xfcomm(char *fname, FILE *fin);
54 > static void xfobject(char *fname, FILE *fin);
55 > static int addxform(FILE *fin);
56 > static int alias(FILE *fin);
57 > void initotypes(void); /* XXX conflict with otypes.h */
58 > static void openmain(char *iname);
59 >
60 >
61 > int
62 > main(           /* get transform options and transform file */
63 >        int  argc,
64 >        char  *argv[]
65 > )
66   {
67 <        FILE  *fopen();
52 <        FILE  *fp;
67 >        int  mal_prefix = 0;
68          int  a;
69 <                                        /* check for array */
69 >                                        /* check for argument list file */
70          for (a = 1; a < argc; a++)
71 +                if (!strcmp(argv[a], "-f"))
72 +                        return(doargf(argc, argv, a));
73 +                                        /* check for regular array */
74 +        for (a = 1; a < argc; a++)
75                  if (!strcmp(argv[a], "-a"))
76                          return(doarray(argc, argv, a));
77  
78 <        initotypes();
78 >        initotypes();                   /* initialize */
79 >        invert = 0;
80 >        expand = 1;
81 >        newmod = NULL;
82 >        idprefix = NULL;
83  
84          for (a = 1; a < argc; a++) {
85                  if (argv[a][0] == '-')
86                          switch (argv[a][1]) {
87                          case 'm':
88 <                                if (argv[a][2] || a+1 >= argc)
88 >                                if (argv[a][2] | (a+1 >= argc))
89                                          break;
90 <                                newmod = argv[++a];
90 >                                a++;
91 >                                if (newmod == NULL)
92 >                                        newmod = argv[a];
93                                  continue;
94                          case 'n':
95 <                                if (argv[a][2] || a+1 >= argc)
95 >                                if (argv[a][2] | (a+1 >= argc))
96                                          break;
97 <                                idprefix = argv[++a];
97 >                                a++;
98 >                                if (idprefix == NULL)
99 >                                        idprefix = argv[a];
100 >                                else {
101 >                                        register char   *newp;
102 >                                        newp = (char *)malloc(strlen(idprefix)+
103 >                                                        strlen(argv[a])+2);
104 >                                        if (newp == NULL)
105 >                                                exit(2);
106 >                                        sprintf(newp, "%s.%s",
107 >                                                        idprefix, argv[a]);
108 >                                        if (mal_prefix++)
109 >                                                free((void *)idprefix);
110 >                                        idprefix = newp;
111 >                                }
112                                  continue;
113 +                        case 'c':
114 +                                if (argv[a][2])
115 +                                        break;
116 +                                expand = 0;
117 +                                continue;
118                          case 'e':
119                                  if (argv[a][2])
120                                          break;
121                                  expand = 1;
122                                  continue;
123 +                        case 'I':
124 +                                if (argv[a][2])
125 +                                        break;
126 +                                invert = !invert;
127 +                                continue;
128                          }
129                  break;
130          }
# Line 85 | Line 134 | char  *argv[];
134  
135          a += xf(&tot, argc-a, argv+a);
136  
137 <        if (reverse = tot.sca < 0.0)
137 >        if ( (reverse = tot.sca < 0.0) )
138                  tot.sca = -tot.sca;
139 +        if (invert)
140 +                reverse = !reverse;
141  
142          if (a < argc && argv[a][0] == '-') {
143                  fprintf(stderr, "%s: command line error at '%s'\n",
# Line 101 | Line 152 | char  *argv[];
152                  printf(" %s", xav[a]);
153          putchar('\n');
154                                          /* transform input */
155 <        if (xac == argc)
156 <                xform("standard input", stdin);
157 <        else
155 >        if (xac == argc) {
156 >                if (stdinused) {
157 >                        fprintf(stderr, "%s: cannot use stdin more than once\n",
158 >                                        argv[0]);
159 >                        exit(1);
160 >                }
161 >                openmain(NULL);
162 >                xform(mainfn, mainfp);
163 >        } else
164                  for (a = xac; a < argc; a++) {
165 <                        if ((fp = fopen(argv[a], "r")) == NULL) {
166 <                                fprintf(stderr, "%s: cannot open \"%s\"\n",
110 <                                                progname, argv[a]);
111 <                                exit(1);
112 <                        }
113 <                        xform(argv[a], fp);
114 <                        fclose(fp);
165 >                        openmain(argv[a]);
166 >                        xform(mainfn, mainfp);
167                  }
168  
169 +        if (mal_prefix)
170 +                free((void *)idprefix);
171          return(0);
172   }
173  
174  
175 < doarray(ac, av, ai)                     /* make array */
176 < char  **av;
177 < int  ac, ai;
175 > int
176 > doargf(                 /* take argument list from file */
177 >        int ac,
178 >        char  **av,
179 >        int fi
180 > )
181   {
182 +        int  inquote;
183          char  *newav[256], **avp;
184 +        char  argbuf[2048];
185 +        char  *newid, newidbuf[128];
186 +        char  *oldid;
187 +        register char   *cp;
188 +        FILE    *argfp;
189 +        int  n, i, k, newac, err;
190 +        
191 +        if (fi >= ac-1 || (av[fi+1][0] == '-' && av[fi+1][1] != '\0')) {
192 +                fprintf(stderr, "%s: missing file for -f option\n", av[0]);
193 +                exit(1);
194 +        }
195 +        if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') {
196 +                if (stdinused++) {
197 +                        fprintf(stderr,
198 +                                "%s: cannot use stdin more than once\n",
199 +                                        av[0]);
200 +                        exit(1);
201 +                }
202 +                argfp = stdin;
203 +                n = 100;                /* we just don't know! */
204 +        } else {
205 +                if ((argfp = fopen(av[fi+1], "r")) == NULL) {
206 +                        fprintf(stderr,
207 +                                "%s: cannot open argument file \"%s\"\n",
208 +                                        av[0], av[fi+1]);
209 +                        exit(1);
210 +                }
211 +                n = 0;                  /* count number of lines in file */
212 +                while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL)
213 +                        n += argbuf[0] && argbuf[0] != '#';
214 +                if (!n) {
215 +                        fprintf(stderr, "%s: empty argument file \"%s\"\n",
216 +                                        av[0], av[fi+1]);
217 +                        exit(1);
218 +                }
219 +                nrept *= n;
220 +                rewind(argfp);
221 +        }
222 +        err = 0; k = 0;                 /* read each arg list and call main */
223 +        while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) {
224 +                if (!argbuf[0] || argbuf[0] == '#')
225 +                        continue;
226 +                avp = newav+2;
227 +                avp[0] = av[0];
228 +                for (i = 1; i < fi; i++)
229 +                        avp[i] = av[i];
230 +                newac = i;
231 +                cp = argbuf;            /* parse new words */
232 +                if (*cp == '!') cp++;
233 +                if (!strncmp(cp, "xform ", 6)) cp += 6;
234 +                inquote = 0;
235 +                for ( ; ; ) {
236 +                skipspaces:
237 +                        while (isspace(*cp))    /* nullify spaces */
238 +                                *cp++ = '\0';
239 +                        if ((*cp == '"') | (*cp == '\''))
240 +                                inquote = *cp++;
241 +                        if (!*cp)               /* all done? */
242 +                                break;
243 +                        if (cp[0] == '\\' && cp[1])
244 +                                if (*++cp == '\n')
245 +                                        goto skipspaces;
246 +                        avp[newac++] = cp;      /* add argument to list */
247 +                        if (inquote) {
248 +                                while (*++cp)
249 +                                        if (*cp == inquote) {
250 +                                                *cp++ = '\0';
251 +                                                break;
252 +                                        }
253 +                        } else {
254 +                                while (*++cp && !isspace(*cp))
255 +                                        ;
256 +                        }
257 +                }
258 +                for (i = fi+2; i < ac; i++)
259 +                        avp[newac++] = av[i];
260 +                avp[newac] = NULL;
261 +                newid = newidbuf;
262 +                oldid = NULL;
263 +                for (i = 2; i < newac; i++)
264 +                        if (!strcmp(avp[i-1], "-n")) {
265 +                                oldid = avp[i];
266 +                                if (strlen(oldid)+32 > sizeof(newidbuf)) {
267 +                                        newid = (char *)malloc(strlen(oldid)+32);
268 +                                        if (newid == NULL)
269 +                                                exit(2);
270 +                                }
271 +                                avp[i] = newid;
272 +                                break;
273 +                        }
274 +                if (oldid == NULL) {
275 +                        newav[0] = av[0];
276 +                        newav[1] = "-n";
277 +                        newav[2] = newid;
278 +                        avp = newav;
279 +                        newac += 2;
280 +                }
281 +                if (oldid == NULL)
282 +                        sprintf(newid, "i%d", k);
283 +                else
284 +                        sprintf(newid, "%s.%d", oldid, k);
285 +                err |= main(newac, avp);
286 +                if (newid != newidbuf)
287 +                        free((void *)newid);
288 +                k++;
289 +        }
290 +        fclose(argfp);
291 +        return(err);
292 + }
293 +
294 +
295 + int
296 + doarray(                        /* make array */
297 +        int  ac,
298 +        char  **av,
299 +        int  ai
300 + )
301 + {
302 +        char  *newav[256], **avp;
303          char  newid[128], repts[32];
304          char  *oldid = NULL;
305 <        int  i, err;
305 >        int  n, i, err;
306          
307 +        if (ai >= ac-1 || (n = atoi(av[ai+1])) <= 0) {
308 +                fprintf(stderr, "%s: missing count for -a option\n", av[0]);
309 +                exit(1);
310 +        }
311 +        nrept *= n;
312          avp = newav+2;
313          avp[0] = av[0];
314          for (i = 1; i < ac; i++)
# Line 146 | Line 328 | int  ac, ai;
328                  ac += 2;
329          }
330          err = 0;
331 <        for (i = 0; i < atoi(av[ai+1]); i++) {
331 >        for (i = 0; i < n; i++) {
332                  if (oldid == NULL)
333                          sprintf(newid, "a%d", i);
334                  else
# Line 158 | Line 340 | int  ac, ai;
340   }
341  
342  
343 < xform(name, fin)                        /* transform stream by tot.xfm */
344 < char  *name;
345 < register FILE  *fin;
343 > void
344 > xform(                  /* transform stream by tot.xfm */
345 >        char  *name,
346 >        register FILE  *fin
347 > )
348   {
349 +        int  nobjs = 0;
350          register int  c;
351  
352          while ((c = getc(fin)) != EOF) {
# Line 177 | Line 362 | register FILE  *fin;
362                  } else if (c == '!') {                  /* command */
363                          ungetc(c, fin);
364                          xfcomm(name, fin);
365 +                        nobjs++;
366                  } else {                                /* object */
367                          ungetc(c, fin);
368                          xfobject(name, fin);
369 +                        nobjs++;
370                  }
371          }
372 +        if (nobjs == 0)
373 +                fprintf(stderr, "%s: (%s): warning - empty file\n",
374 +                                progname, name);
375   }
376  
377  
378 < xfcomm(fname, fin)                      /* transform a command */
379 < FILE  *fin;
378 > void
379 > xfcomm(                 /* transform a command */
380 >        char  *fname,
381 >        FILE  *fin
382 > )
383   {
191        FILE  *popen();
192        char  *fgetline();
384          FILE  *pin;
385 <        char  buf[512];
385 >        char  buf[2048];
386          int  i;
387  
388          fgetline(buf, sizeof(buf), fin);
389          if (expand) {
390 <                if (xac > 2) {
391 <                        if ((pin = popen(buf+1, "r")) == NULL) {
392 <                                fprintf(stderr,
393 <                                "%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);
390 >                if ((pin = popen(buf+1, "r")) == NULL) {
391 >                        fprintf(stderr, "%s: (%s): cannot execute \"%s\"\n",
392 >                                        progname, fname, buf);
393 >                        exit(1);
394                  }
395 +                xform(buf, pin);
396 +                pclose(pin);
397          } else {
398                  printf("\n%s", buf);
399                  if (xac > 1) {
400 <                        printf(" | %s -e", xav[0]);
400 >                        printf(" | %s -e", xav[0]);     /* expand next time */
401                          for (i = 1; i < xac; i++)
402 <                                printf(" %s", xav[i]);
402 >                                if (i >= xfa || strcmp(xav[i], "-c"))
403 >                                        printf(" %s", xav[i]);
404                  }
405                  putchar('\n');
406          }
407   }
408  
409  
410 < xfobject(fname, fin)                            /* transform an object */
411 < char  *fname;
412 < FILE  *fin;
410 > void
411 > xfobject(                               /* transform an object */
412 >        char  *fname,
413 >        FILE  *fin
414 > )
415   {
416          char  typ[16], nam[MAXSTR];
417          int  fn;
418                                                  /* modifier and type */
419 <        fscanf(fin, "%s %s", nam, typ);
419 >        strcpy(typ, "EOF");
420 >        fgetword(nam, sizeof(nam), fin);
421 >        fgetword(typ, sizeof(typ), fin);
422          if ((fn = otype(typ)) < 0) {
423                  fprintf(stderr, "%s: (%s): unknown object type \"%s\"\n",
424                                  progname, fname, typ);
425                  exit(1);
426          }
427 <        printf("\n%s %s ", newmod!=NULL && issurface(fn) ? newmod : nam, typ);
427 >        putchar('\n');
428 >        if (ismodifier(fn)) {
429 >                fputword(nam, stdout);
430 >                printf(" %s ", typ);
431 >        } else {
432 >                fputword(newmod != NULL ? newmod : nam, stdout);
433 >                printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ);
434 >        }
435                                                  /* object name */
436 <        fscanf(fin, "%s", nam);
437 <        if (idprefix != NULL && issurface(fn))
438 <                printf("%s.%s\n", idprefix, nam);
439 <        else
440 <                printf("%s\n", nam);
436 >        fgetword(nam, sizeof(nam), fin);
437 >        if (idprefix == NULL || ismodifier(fn))
438 >                fputword(nam, stdout);
439 >        else {
440 >                char    nnam[MAXSTR];
441 >                sprintf(nnam, "%s.%s", idprefix, nam);
442 >                fputword(nnam, stdout);
443 >        }
444 >        putchar('\n');
445                                                  /* transform arguments */
446          if ((*ofun[fn].funp)(fin) < 0) {
447                  fprintf(stderr, "%s: (%s): bad %s \"%s\"\n",
# Line 250 | Line 451 | FILE  *fin;
451   }
452  
453  
454 < o_default(fin)                  /* pass on arguments unchanged */
455 < FILE  *fin;
454 > int
455 > o_default(                      /* pass on arguments unchanged */
456 >        FILE  *fin
457 > )
458   {
459          register int  i;
460 <        FUNARGS  fa;
460 >        FUNARGS  fa;
461  
462 <        if (readfargs(&fa, fin) <= 0)
462 >        if (readfargs(&fa, fin) != 1)
463                  return(-1);
464                                          /* string arguments */
465          printf("%d", fa.nsargs);
466 <        for (i = 0; i < fa.nsargs; i++)
467 <                printf(" %s", fa.sarg[i]);
466 >        for (i = 0; i < fa.nsargs; i++) {
467 >                fputc(' ', stdout);
468 >                fputword(fa.sarg[i], stdout);
469 >        }
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 280 | Line 487 | FILE  *fin;
487   }
488  
489  
490 < addxform(fin)                   /* add xf arguments to strings */
491 < FILE  *fin;
490 > int
491 > addxform(                       /* add xf arguments to strings */
492 >        FILE  *fin
493 > )
494   {
495          register int  i;
496 <        FUNARGS  fa;
496 >        int  resetarr = 0;
497 >        FUNARGS  fa;
498  
499 <        if (readfargs(&fa, fin) <= 0)
499 >        if (readfargs(&fa, fin) != 1)
500                  return(-1);
501                                          /* string arguments */
502 <        printf("%d", fa.nsargs + xac-xfa);
503 <        for (i = 0; i < fa.nsargs; i++)
504 <                printf(" %s", fa.sarg[i]);
502 >        if (xac > xfa && strcmp(xav[xfa], "-i"))
503 >                resetarr = 2;
504 >        printf("%d", fa.nsargs + resetarr + xac-xfa);
505 >        for (i = 0; i < fa.nsargs; i++) {
506 >                fputc(' ', stdout);
507 >                fputword(fa.sarg[i], stdout);
508 >        }
509 >        if (resetarr)
510 >                printf(" -i 1");
511          for (i = xfa; i < xac; i++)     /* add xf arguments */
512                  printf(" %s", xav[i]);
513          printf("\n");
514 < #ifdef  IARGS
514 > #ifdef  IARGS
515                                          /* integer arguments */
516          printf("%d", fa.niargs);
517          for (i = 0; i < fa.niargs; i++)
518                  printf(" %d", fa.iarg[i]);
519          printf("\n");
520 + #else
521 +        printf("0\n");
522   #endif
523                                          /* float arguments */
524          printf("%d", fa.nfargs);
# Line 313 | Line 531 | FILE  *fin;
531  
532  
533   int
534 < otype(ofname)                   /* get object function number from its name */
535 < register char  *ofname;
534 > alias(                  /* transfer alias */
535 >        FILE  *fin
536 > )
537   {
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
329 alias(fin)                      /* transfer alias */
330 FILE  *fin;
331 {
538          char  aliasnm[MAXSTR];
539  
540 <        if (fscanf(fin, "%s", aliasnm) != 1)
540 >        if (fgetword(aliasnm, MAXSTR, fin) == NULL)
541                  return(-1);
542          printf("\t%s\n", aliasnm);
543          return(0);
544   }
545  
546  
547 < m_glow(fin)                     /* transform arguments for proximity light */
548 < FILE  *fin;
547 > int
548 > m_glow(                 /* transform arguments for proximity light */
549 >        FILE  *fin
550 > )
551   {
552 <        FUNARGS  fa;
552 >        FUNARGS  fa;
553  
554 <        if (readfargs(&fa, fin) <= 0)
554 >        if (readfargs(&fa, fin) != 1)
555                  return(-1);
556          if (fa.nsargs != 0  || fa.nfargs != 4)
557                  return(-1);
# Line 356 | Line 564 | FILE  *fin;
564   }
565  
566  
567 < m_spot(fin)                     /* transform arguments for spotlight */
568 < FILE  *fin;
567 > int
568 > m_spot(                 /* transform arguments for spotlight */
569 >        FILE  *fin
570 > )
571   {
572 <        double  v[3];
573 <        FUNARGS  fa;
572 >        FVECT  v;
573 >        FUNARGS  fa;
574  
575 <        if (readfargs(&fa, fin) <= 0)
575 >        if (readfargs(&fa, fin) != 1)
576                  return(-1);
577          if (fa.nsargs != 0  || fa.nfargs != 7)
578                  return(-1);
# Line 376 | Line 586 | FILE  *fin;
586   }
587  
588  
589 < m_dielectric(fin)               /* transform arguments for dielectric */
590 < FILE  *fin;
589 > int
590 > m_mist(         /* transform arguments for mist */
591 >        FILE  *fin
592 > )
593   {
594 <        double  pow();
595 <        FUNARGS  fa;
594 >        FUNARGS  fa;
595 >        int     i;
596  
597 <        if (readfargs(&fa, fin) <= 0)
597 >        if (readfargs(&fa, fin) != 1)
598                  return(-1);
599 +        if (fa.nfargs > 7)
600 +                return(-1);
601 +        printf("%d", fa.nsargs);
602 +        if (idprefix == NULL)
603 +                for (i = 0; i < fa.nsargs; i++)
604 +                        printf(" %s", fa.sarg[i]);
605 +        else
606 +                for (i = 0; i < fa.nsargs; i++) {
607 +                        char    sname[256], *sp;
608 +                        register char   *cp1, *cp2 = sname;
609 +                                                        /* add idprefix */
610 +                        for (sp = fa.sarg[i]; *sp; sp = cp1) {
611 +                                for (cp1 = idprefix; *cp1; )
612 +                                        *cp2++ = *cp1++;
613 +                                *cp2++ = '.';
614 +                                for (cp1 = sp; *cp1 &&
615 +                                                (*cp2++ = *cp1++) != '>'; )
616 +                                        ;
617 +                        }
618 +                        *cp2 = '\0';
619 +                        printf(" %s", sname);
620 +                }
621 +        printf("\n0\n%d", fa.nfargs);
622 +        if (fa.nfargs > 2)
623 +                printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca,
624 +                                fa.farg[1]/tot.sca, fa.farg[2]/tot.sca);
625 +        for (i = 3; i < fa.nfargs; i++)
626 +                printf(" %12.6g", fa.farg[i]);
627 +        printf("\n");
628 +        freefargs(&fa);
629 +        return(0);
630 + }
631 +
632 +
633 + int
634 + m_dielectric(           /* transform arguments for dielectric */
635 +        FILE  *fin
636 + )
637 + {
638 +        FUNARGS  fa;
639 +
640 +        if (readfargs(&fa, fin) != 1)
641 +                return(-1);
642          if (fa.nsargs != 0  || fa.nfargs != 5)
643                  return(-1);
644          printf("0\n0\n5");
645 <        printf(" %18.12g %18.12g %18.12g",
645 >        printf(" %12.6g %12.6g %12.6g",
646                  pow(fa.farg[0], 1.0/tot.sca),
647                  pow(fa.farg[1], 1.0/tot.sca),
648                  pow(fa.farg[2], 1.0/tot.sca));
649 <        printf(" %18.12g %18.12g\n", fa.farg[3], fa.farg[4]);
649 >        printf(" %12.6g %12.6g\n", fa.farg[3], fa.farg[4]);
650          freefargs(&fa);
651          return(0);
652   }
653  
654  
655 < m_interface(fin)                /* transform arguments for interface */
656 < FILE  *fin;
655 > int
656 > m_interface(            /* transform arguments for interface */
657 >        FILE  *fin
658 > )
659   {
660 <        double  pow();
404 <        FUNARGS  fa;
660 >        FUNARGS  fa;
661  
662 <        if (readfargs(&fa, fin) <= 0)
662 >        if (readfargs(&fa, fin) != 1)
663                  return(-1);
664          if (fa.nsargs != 0  || fa.nfargs != 8)
665                  return(-1);
666          printf("0\n0\n8\n");
667 <        printf("%18.12g %18.12g %18.12g",
667 >        printf("%12.6g %12.6g %12.6g",
668                  pow(fa.farg[0], 1.0/tot.sca),
669                  pow(fa.farg[1], 1.0/tot.sca),
670                  pow(fa.farg[2], 1.0/tot.sca));
671 <        printf(" %18.12g\n", fa.farg[3]);
672 <        printf("%18.12g %18.12g %18.12g",
671 >        printf(" %12.6g\n", fa.farg[3]);
672 >        printf("%12.6g %12.6g %12.6g",
673                  pow(fa.farg[4], 1.0/tot.sca),
674                  pow(fa.farg[5], 1.0/tot.sca),
675                  pow(fa.farg[6], 1.0/tot.sca));
676 <        printf(" %18.12g\n", fa.farg[7]);
676 >        printf(" %12.6g\n", fa.farg[7]);
677          freefargs(&fa);
678          return(0);
679   }
680  
681  
682 < text(fin)                       /* transform text arguments */
683 < FILE  *fin;
682 > int
683 > text(                   /* transform text arguments */
684 >        FILE  *fin
685 > )
686   {
687          int  i;
688 <        double  v[3];
689 <        FUNARGS  fa;
688 >        FVECT  v;
689 >        FUNARGS  fa;
690  
691 <        if (readfargs(&fa, fin) <= 0)
691 >        if (readfargs(&fa, fin) != 1)
692                  return(-1);
693 <        if (fa.nfargs != 9 && fa.nfargs != 11 && fa.nfargs != 15)
693 >        if (fa.nfargs < 9)
694                  return(-1);
695                                          /* string arguments */
696          printf("%d", fa.nsargs);
697 <        for (i = 0; i < fa.nsargs; i++)
698 <                printf(" %s", fa.sarg[i]);
697 >        for (i = 0; i < fa.nsargs; i++) {
698 >                fputc(' ', stdout);
699 >                fputword(fa.sarg[i], stdout);
700 >        }
701          printf("\n0\n%d\n", fa.nfargs);
702                                          /* anchor point */
703          multp3(v, fa.farg, tot.xfm);
# Line 447 | Line 707 | FILE  *fin;
707          printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
708                                          /* down vector */
709          multv3(v, fa.farg+6, tot.xfm);
710 <        printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]);
711 <                                        /* forground and background */
712 <        if (fa.nfargs == 11)
713 <                printf(" %18.12g %18.12g\n", fa.farg[9], fa.farg[10]);
714 <        else if (fa.nfargs == 15) {
715 <                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]);
710 >        printf(" %18.12g %18.12g %18.12g", v[0], v[1], v[2]);
711 >                                        /* remaining arguments */
712 >        for (i = 9; i < fa.nfargs; i++) {
713 >                if (i%3 == 0)
714 >                        putchar('\n');
715 >                printf(" %18.12g", fa.farg[i]);
716          }
717 +        putchar('\n');
718          freefargs(&fa);
719          return(0);
720   }
721  
722  
723 < o_source(fin)                   /* transform source arguments */
724 < FILE  *fin;
723 > int
724 > o_source(                       /* transform source arguments */
725 >        FILE  *fin
726 > )
727   {
728 <        double  dv[3];
729 <        FUNARGS  fa;
728 >        FVECT  dv;
729 >        FUNARGS  fa;
730  
731 <        if (readfargs(&fa, fin) <= 0)
731 >        if (readfargs(&fa, fin) != 1)
732                  return(-1);
733          if (fa.nsargs != 0  || fa.nfargs != 4)
734                  return(-1);
# Line 483 | Line 743 | FILE  *fin;
743   }
744  
745  
746 < o_sphere(fin)                   /* transform sphere arguments */
747 < FILE  *fin;
746 > int
747 > o_sphere(                       /* transform sphere arguments */
748 >        FILE  *fin
749 > )
750   {
751 <        double  cent[3], rad;
752 <        FUNARGS  fa;
751 >        FVECT  cent;
752 >        double  rad;
753 >        FUNARGS  fa;
754  
755 <        if (readfargs(&fa, fin) <= 0)
755 >        if (readfargs(&fa, fin) != 1)
756                  return(-1);
757          if (fa.nsargs != 0  || fa.nfargs != 4)
758                  return(-1);
759          
760 <        multp3(cent, fa.farg, tot.xfm); /* transform center */
760 >        multp3(cent, fa.farg, tot.xfm); /* transform center */
761          
762          rad = fa.farg[3] * tot.sca;             /* scale radius */
763          
# Line 506 | Line 769 | FILE  *fin;
769   }
770  
771  
772 < o_face(fin)                     /* transform face arguments */
773 < FILE  *fin;
772 > int
773 > o_face(                 /* transform face arguments */
774 >        FILE  *fin
775 > )
776   {
777 <        double  p[3];
777 >        FVECT  p;
778          register int  i;
779 <        FUNARGS  fa;
779 >        FUNARGS  fa;
780  
781 <        if (readfargs(&fa, fin) <= 0)
781 >        if (readfargs(&fa, fin) != 1)
782                  return(-1);
783          if (fa.nsargs != 0  || fa.nfargs % 3)
784                  return(-1);
# Line 532 | Line 797 | FILE  *fin;
797   }
798  
799  
800 < o_cone(fin)                     /* transform cone and cup arguments */
801 < FILE  *fin;
800 > int
801 > o_cone(                 /* transform cone and cup arguments */
802 >        FILE  *fin
803 > )
804   {
805 <        double  p0[3], p1[3], r0, r1;
806 <        FUNARGS  fa;
805 >        FVECT  p0, p1;
806 >        double  r0, r1;
807 >        FUNARGS  fa;
808  
809 <        if (readfargs(&fa, fin) <= 0)
809 >        if (readfargs(&fa, fin) != 1)
810                  return(-1);
811          if (fa.nsargs != 0  || fa.nfargs != 8)
812                  return(-1);
# Line 558 | Line 826 | FILE  *fin;
826   }
827  
828  
829 < o_cylinder(fin)                 /* transform cylinder and tube arguments */
830 < FILE  *fin;
829 > int
830 > o_cylinder(                     /* transform cylinder and tube arguments */
831 >        FILE  *fin
832 > )
833   {
834 <        double  p0[3], p1[3], rad;
835 <        FUNARGS  fa;
834 >        FVECT  p0, p1;
835 >        double  rad;
836 >        FUNARGS  fa;
837  
838 <        if (readfargs(&fa, fin) <= 0)
838 >        if (readfargs(&fa, fin) != 1)
839                  return(-1);
840          if (fa.nsargs != 0  || fa.nfargs != 7)
841                  return(-1);
# Line 582 | Line 853 | FILE  *fin;
853   }
854  
855  
856 < o_ring(fin)                     /* transform ring arguments */
857 < FILE  *fin;
856 > int
857 > o_ring(                 /* transform ring arguments */
858 >        FILE  *fin
859 > )
860   {
861 <        double  p0[3], pd[3], r0, r1;
862 <        FUNARGS  fa;
861 >        FVECT  p0, pd;
862 >        double  r0, r1;
863 >        FUNARGS  fa;
864  
865 <        if (readfargs(&fa, fin) <= 0)
865 >        if (readfargs(&fa, fin) != 1)
866                  return(-1);
867          if (fa.nsargs != 0  || fa.nfargs != 8)
868                  return(-1);
# Line 597 | Line 871 | FILE  *fin;
871  
872          multp3(p0, fa.farg, tot.xfm);
873          multv3(pd, fa.farg+3, tot.xfm);
874 +        if (invert) {
875 +                pd[0] = -pd[0];
876 +                pd[1] = -pd[1];
877 +                pd[2] = -pd[2];
878 +        }
879          r0 = fa.farg[6] * tot.sca;
880          r1 = fa.farg[7] * tot.sca;
881          printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]);
# Line 607 | Line 886 | FILE  *fin;
886   }
887  
888  
889 < initotypes()                    /* initialize ofun[] array */
889 > void
890 > initotypes(void)                        /* initialize ofun[] array */
891   {
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();
892          register int  i;
893  
894          if (ofun[OBJ_SOURCE].funp == o_source)
895                  return;                 /* done already */
630                                        /* alias is additional */
631        ofun[ALIAS].funame = ALIASID;
632        ofun[ALIAS].flags = 0;
896                                          /* functions get new transform */
897 <        for (i = 0; i < NUMTYPES; i++)
897 >        for (i = 0; i < NUMOTYPE; i++)
898                  if (hasfunc(i))
899                          ofun[i].funp = addxform;
900                                          /* special cases */
# Line 644 | Line 907 | initotypes()                   /* initialize ofun[] array */
907          ofun[OBJ_CYLINDER].funp =
908          ofun[OBJ_TUBE].funp = o_cylinder;
909          ofun[OBJ_RING].funp = o_ring;
910 <        ofun[OBJ_INSTANCE].funp = addxform;
910 >        ofun[OBJ_INSTANCE].funp =
911 >        ofun[OBJ_MESH].funp = addxform;
912          ofun[MAT_GLOW].funp = m_glow;
913          ofun[MAT_SPOT].funp = m_spot;
914          ofun[MAT_DIELECTRIC].funp = m_dielectric;
915          ofun[MAT_INTERFACE].funp = m_interface;
916 +        ofun[MAT_MIST].funp = m_mist;
917          ofun[PAT_CTEXT].funp =
918          ofun[PAT_BTEXT].funp =
919          ofun[MIX_TEXT].funp = text;
920 <        ofun[ALIAS].funp = alias;
920 >        ofun[MOD_ALIAS].funp = alias;
921 >                                        /* surface inverses */
922 >        tinvers[OBJ_FACE] = OBJ_FACE;
923 >        tinvers[OBJ_SOURCE] = OBJ_SOURCE;
924 >        tinvers[OBJ_CONE] = OBJ_CUP;
925 >        tinvers[OBJ_CUP] = OBJ_CONE;
926 >        tinvers[OBJ_SPHERE] = OBJ_BUBBLE;
927 >        tinvers[OBJ_BUBBLE] = OBJ_SPHERE;
928 >        tinvers[OBJ_RING] = OBJ_RING;
929 >        tinvers[OBJ_CYLINDER] = OBJ_TUBE;
930 >        tinvers[OBJ_TUBE] = OBJ_CYLINDER;
931 >        tinvers[OBJ_INSTANCE] = OBJ_INSTANCE;   /* oh, well */
932 >        tinvers[OBJ_MESH] = OBJ_MESH;           /* ditto */
933   }
934 +
935 +
936 + #ifdef  OLDXFORM
937 + void
938 + openmain(
939 +        char  *fname
940 + )
941 + {
942 +        if (fname == NULL) {
943 +                strcpy(mainfn, "standard input");
944 +                mainfp = stdin;
945 +                return;
946 +        }
947 +        if (mainfp != NULL) {
948 +                if (!strcmp(fname, mainfn)) {
949 +                        rewind(mainfp);
950 +                        return;
951 +                }
952 +                fclose(mainfp);
953 +        }
954 +        if ((mainfp = fopen(fname, "r")) == NULL) {
955 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
956 +                                progname, fname);
957 +                exit(1);
958 +        }
959 +        strcpy(mainfn, fname);
960 + }
961 + #else
962 + void
963 + openmain(               /* open input, changing directory for file */
964 +        char  *iname
965 + )
966 + {
967 +        static char  origdir[PATH_MAX];
968 +        static char  curfn[PATH_MAX];
969 +        static int  diffdir;
970 +        register char  *fpath;
971 +
972 +        if (iname == NULL) {                    /* standard input */
973 +                if (mainfp == NULL) {
974 +                        register int  c;
975 +                        strcpy(mainfn, "standard input");
976 +                        if (nrept <= 1) {
977 +                                mainfp = stdin;
978 +                                return;                 /* just read once */
979 +                        }
980 +                                                        /* else copy */
981 +                        if ((mainfp = tmpfile()) == NULL) {
982 +                                fprintf(stderr,
983 +                                        "%s: cannot create temporary file\n",
984 +                                                progname);
985 +                                exit(1);
986 +                        }
987 +                        while ((c = getc(stdin)) != EOF)
988 +                                putc(c, mainfp);
989 +                }
990 +                rewind(mainfp);                 /* rewind copy */
991 +                return;
992 +        }
993 +        if (mainfp == NULL) {                   /* first call, initialize */
994 +                getcwd(origdir, sizeof(origdir));
995 +        } else if (!strcmp(iname, curfn)) {     /* just need to rewind? */
996 +                rewind(mainfp);
997 +                return;
998 +        } else {                                /* else close old stream */
999 +                fclose(mainfp);
1000 +                mainfp = NULL;
1001 +                if (diffdir) {                  /* return to our directory */
1002 +                        chdir(origdir);
1003 +                        diffdir = 0;
1004 +                }
1005 +        }
1006 +        strcpy(curfn, iname);                   /* remember input name */
1007 +                                                /* get full path for file */
1008 +        if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) {
1009 +                fprintf(stderr, "%s: cannot find file \"%s\"\n",
1010 +                                progname, iname);
1011 +                exit(1);
1012 +        }
1013 +        if (fpath[0] == '.' && ISDIRSEP(fpath[1]))      /* remove leading ./ */
1014 +                fpath += 2;
1015 +                                                /* record path name */
1016 +        strcpy(mainfn, fpath);
1017 +        if (expand) {                           /* change to local directory */
1018 +                register char  *cp = fpath + strlen(fpath);     /* get dir. */
1019 +                while (cp > fpath) {
1020 +                        cp--;
1021 +                        if (ISDIRSEP(*cp)) {
1022 +                                if (cp == fpath)
1023 +                                        cp++;   /* root special case */
1024 +                                break;
1025 +                        }
1026 +                }
1027 +                *cp = '\0';
1028 +                if (fpath[0]) {                 /* change to new directory? */
1029 +                        if (chdir(fpath) < 0) {
1030 +                                fprintf(stderr,
1031 +                                "%s: cannot change directory to \"%s\"\n",
1032 +                                                progname, fpath);
1033 +                                exit(1);
1034 +                        }
1035 +                        diffdir++;
1036 +                }
1037 +                                                /* get final path component */
1038 +                for (fpath = iname+strlen(iname);
1039 +                                fpath > iname && !ISDIRSEP(fpath[-1]); fpath--)
1040 +                        ;
1041 +        }
1042 +                                                /* finally, open the file */
1043 +        if ((mainfp = fopen(fpath, "r")) == NULL) {
1044 +                fprintf(stderr, "%s: cannot open file \"%s\"\n",
1045 +                                progname, mainfn);
1046 +                exit(1);
1047 +        }
1048 + }
1049 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines