ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/parser.c
(Generate patch)

Comparing ray/src/cv/mgflib/parser.c (file contents):
Revision 1.8 by greg, Sat Jun 25 09:48:03 1994 UTC vs.
Revision 1.14 by greg, Fri Mar 10 15:16:07 1995 UTC

# Line 59 | Line 59 | static int     e_any_toss(),           /* discard unneeded entity *
59                  e_ies(),                /* IES luminaire file */
60                  e_include(),            /* include file */
61                  e_sph(),                /* sphere */
62 +                e_cct(),                /* color temperature */
63                  e_cmix(),               /* color mixtures */
64                  e_cspec(),              /* color spectra */
65                  e_cyl(),                /* cylinder */
# Line 119 | Line 120 | mg_init()                      /* initialize alternate entity handlers */
120          if (mg_ehand[MG_E_COLOR] != NULL) {
121                  if (mg_ehand[MG_E_CMIX] == NULL) {
122                          mg_ehand[MG_E_CMIX] = e_cmix;
123 <                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
123 >                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT;
124                  }
125                  if (mg_ehand[MG_E_CSPEC] == NULL) {
126                          mg_ehand[MG_E_CSPEC] = e_cspec;
127 <                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
127 >                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT;
128                  }
129 +                if (mg_ehand[MG_E_CCT] == NULL) {
130 +                        mg_ehand[MG_E_CCT] = e_cct;
131 +                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT;
132 +                }
133          }
134                                          /* check for consistency */
135          if (mg_ehand[MG_E_FACE] != NULL)
# Line 135 | Line 140 | mg_init()                      /* initialize alternate entity handlers */
140          if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL ||
141                          mg_ehand[MG_E_ED] != NULL ||
142                          mg_ehand[MG_E_RS] != NULL ||
143 <                        mg_ehand[MG_E_TS] != NULL)
143 >                        mg_ehand[MG_E_TS] != NULL ||
144 >                        mg_ehand[MG_E_SIDES] != NULL)
145                  uneed |= 1<<MG_E_MATERIAL;
146          for (i = 0; i < MG_NENTITIES; i++)
147                  if (uneed & 1<<i && mg_ehand[i] == NULL) {
# Line 158 | Line 164 | mg_init()                      /* initialize alternate entity handlers */
164                  e_supp[MG_E_CSPEC] = c_hcolor;
165          if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor)
166                  e_supp[MG_E_CMIX] = c_hcolor;
167 +        if (ineed & 1<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor)
168 +                e_supp[MG_E_CCT] = c_hcolor;
169                                          /* discard remaining entities */
170          for (i = 0; i < MG_NENTITIES; i++)
171                  if (mg_ehand[i] == NULL)
# Line 165 | Line 173 | mg_init()                      /* initialize alternate entity handlers */
173   }
174  
175  
168
176   int
177   mg_entity(name)                 /* get entity number from its name */
178   char    *name;
179   {
180 <        static LUTAB    ent_tab;        /* entity lookup table */
180 >        static LUTAB    ent_tab = LU_SINIT(NULL,NULL);  /* lookup table */
181          register char   *cp;
182  
183          if (!ent_tab.tsiz) {            /* initialize hash table */
# Line 187 | Line 194 | char   *name;
194   }
195  
196  
197 < static int
198 < handle_it(en, ac, av)           /* pass entity to appropriate handler */
197 > int
198 > mg_handle(en, ac, av)           /* pass entity to appropriate handler */
199   register int    en;
200   int     ac;
201   char    **av;
# Line 210 | Line 217 | mg_open(ctx, fn)                       /* open new input file */
217   register MG_FCTXT       *ctx;
218   char    *fn;
219   {
220 +        static int      nfids;
221          int     olen;
222          register char   *cp;
223  
224 +        ctx->fid = ++nfids;
225          ctx->lineno = 0;
226          if (fn == NULL) {
227                  strcpy(ctx->fname, "<stdin>");
# Line 251 | Line 260 | mg_close()                     /* close input file */
260   }
261  
262  
263 + void
264 + mg_fgetpos(pos)                 /* get current position in input file */
265 + register MG_FPOS        *pos;
266 + {
267 +        extern long     ftell();
268 +
269 +        pos->fid = mg_file->fid;
270 +        pos->lineno = mg_file->lineno;
271 +        pos->offset = ftell(mg_file->fp);
272 + }
273 +
274 +
275   int
276 < mg_rewind()                     /* rewind input file */
276 > mg_fgoto(pos)                   /* reposition input file pointer */
277 > register MG_FPOS        *pos;
278   {
279 <        if (mg_file->lineno == 0)
279 >        if (pos->fid != mg_file->fid)
280 >                return(MG_ESEEK);
281 >        if (pos->lineno == mg_file->lineno)
282                  return(MG_OK);
283          if (mg_file->fp == stdin)
284                  return(MG_ESEEK);       /* cannot seek on standard input */
285 <        if (fseek(mg_file->fp, 0L, 0) == EOF)
285 >        if (fseek(mg_file->fp, pos->offset, 0) == EOF)
286                  return(MG_ESEEK);
287 <        mg_file->lineno = 0;
287 >        mg_file->lineno = pos->lineno;
288          return(MG_OK);
289   }
290  
# Line 309 | Line 333 | mg_parse()                     /* parse current input line */
333                  return(MG_OK);          /* no words in line */
334          *ap = NULL;
335                                          /* else handle it */
336 <        return(handle_it(-1, ap-argv, argv));
336 >        return(mg_handle(-1, ap-argv, argv));
337   }
338  
339  
# Line 344 | Line 368 | mg_clear()                     /* clear parser history */
368   }
369  
370  
347 int
348 mg_iterate(ac, av, f)           /* iterate on statement */
349 int     ac;
350 register char   **av;
351 int     (*f)();
352 {
353        int     niter, rval;
354        register int    i, j;
355        char    *argv[MG_MAXARGC];
356        char    cntbuf[10];
357                                        /* build partial transformation */
358        for (i = 0; i < ac; i++) {
359                if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0')
360                        break;
361                argv[i+1] = av[i];
362        }
363        argv[i+1] = NULL;
364        if (i) {                        /* handle transformation */
365                argv[0] = mg_ename[MG_E_XF];
366                if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK)
367                        return(rval);
368        }
369        if (i < ac) {                   /* run array */
370                if (i+1 >= ac || !isint(av[i+1]))
371                        return(MG_ETYPE);
372                niter = atoi(av[i+1]);
373                argv[0] = mg_ename[MG_E_OBJECT];
374                argv[1] = cntbuf;
375                for (j = 2; j+i < ac; j++)
376                        argv[j] = av[j+i];
377                argv[j] = NULL;
378                for (j = 0; j < niter; j++) {
379                        sprintf(cntbuf, "%d", j);
380                        if ((rval = handle_it(MG_E_OBJECT, 2, argv)) != MG_OK)
381                                return(rval);
382                        argv[0] = "-i";
383                        if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK)
384                                return(rval);
385                        argv[0] = mg_ename[MG_E_OBJECT];
386                        if ((rval = handle_it(MG_E_OBJECT, 1, argv)) != MG_OK)
387                                return(rval);
388                }
389        } else if ((rval = (*f)()) != MG_OK)    /* else do this instance */
390                        return(rval);
391        if (i) {                        /* reset the transform */
392                argv[0] = mg_ename[MG_E_XF];
393                argv[1] = NULL;
394                (void)handle_it(MG_E_XF, 1, argv);
395        }
396        return(MG_OK);
397 }
398
399
371   /****************************************************************************
372   *      The following routines handle unsupported entities
373   */
# Line 412 | Line 383 | char   **av;
383  
384  
385   static int
415 reload_file()                   /* reload current MGF file */
416 {
417        register int    rval;
418
419        if ((rval = mg_rewind()) != MG_OK)
420                return(rval);
421        while (mg_read())
422                if ((rval = mg_parse()) != MG_OK)
423                        return(rval);
424        return(MG_OK);
425 }
426
427
428 static int
386   e_include(ac, av)               /* include file */
387   int     ac;
388   char    **av;
389   {
390 +        char    *xfarg[MG_MAXARGC];
391          MG_FCTXT        ictx;
392          int     rv;
393  
# Line 437 | Line 395 | char   **av;
395                  return(MG_EARGC);
396          if ((rv = mg_open(&ictx, av[1])) != MG_OK)
397                  return(rv);
398 <        if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) {
399 <                fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname,
400 <                                ictx.lineno, mg_err[rv], ictx.inpline);
401 <                mg_close();
402 <                return(MG_EINCL);
398 >        if (ac > 2) {
399 >                register int    i;
400 >
401 >                xfarg[0] = mg_ename[MG_E_XF];
402 >                for (i = 1; i < ac-1; i++)
403 >                        xfarg[i] = av[i+1];
404 >                xfarg[ac-1] = NULL;
405 >                if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK)
406 >                        return(rv);
407          }
408 +        while (!feof(mg_file->fp)) {
409 +                while (mg_read())
410 +                        if ((rv = mg_parse()) != MG_OK) {
411 +                                fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname,
412 +                                                ictx.lineno, mg_err[rv],
413 +                                                ictx.inpline);
414 +                                mg_close();
415 +                                return(MG_EINCL);
416 +                        }
417 +                if (ac > 2)
418 +                        if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK)
419 +                                return(rv);
420 +        }
421          mg_close();
422          return(MG_OK);
423   }
# Line 490 | Line 465 | char   **av;
465          rad = atof(av[2]);
466                                          /* initialize */
467          warpconends = 1;
468 <        if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK)
468 >        if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK)
469                  return(rval);
470          sprintf(p2x, FLTFMT, cv->p[0]);
471          sprintf(p2y, FLTFMT, cv->p[1]);
472          sprintf(p2z, FLTFMT, cv->p[2]+rad);
473 <        if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
473 >        if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
474                  return(rval);
475          r2[0] = '0'; r2[1] = '\0';
476          for (i = 1; i <= 2*mg_nqcdivs; i++) {
477                  theta = i*(PI/2)/mg_nqcdivs;
478 <                if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
478 >                if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
479                          return(rval);
480                  sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta));
481 <                if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK)
481 >                if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
482                          return(rval);
483 <                if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
483 >                if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
484                          return(rval);
485                  strcpy(r1, r2);
486                  sprintf(r2, FLTFMT, rad*sin(theta));
487 <                if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK)
487 >                if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
488                          return(rval);
489          }
490          warpconends = 0;
# Line 564 | Line 539 | char   **av;
539          for (j = 0; j < 3; j++)
540                  sprintf(p2[j], FLTFMT, cv->p[j] +
541                                  .5*sgn*(maxrad-minrad)*cv->n[j]);
542 <        if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
542 >        if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
543                  return(rval);
544 <        if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
544 >        if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
545                  return(rval);
546          sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad));
547                                          /* run outer section */
548          for (i = 1; i <= 2*mg_nqcdivs; i++) {
549                  theta = i*(PI/2)/mg_nqcdivs;
550 <                if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
550 >                if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
551                          return(rval);
552                  for (j = 0; j < 3; j++)
553                          sprintf(p2[j], FLTFMT, cv->p[j] +
554                                  .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]);
555 <                if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK)
555 >                if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
556                          return(rval);
557 <                if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
557 >                if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
558                          return(rval);
559                  strcpy(r1, r2);
560                  sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta));
561 <                if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK)
561 >                if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
562                          return(rval);
563          }
564                                          /* run inner section */
# Line 593 | Line 568 | char   **av;
568                  for (j = 0; j < 3; j++)
569                          sprintf(p2[j], FLTFMT, cv->p[j] +
570                                  .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]);
571 <                if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
571 >                if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
572                          return(rval);
573 <                if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK)
573 >                if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
574                          return(rval);
575 <                if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
575 >                if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
576                          return(rval);
577                  strcpy(r1, r2);
578                  sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta));
579 <                if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK)
579 >                if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
580                          return(rval);
581          }
582          warpconends = 0;
# Line 622 | Line 597 | char   **av;
597          avnew[2] = av[2];
598          avnew[3] = av[3];
599          avnew[4] = av[2];
600 <        return(handle_it(MG_E_CONE, 5, avnew));
600 >        return(mg_handle(MG_E_CONE, 5, avnew));
601   }
602  
603  
# Line 664 | Line 639 | char   **av;
639          make_axes(u, v, cv->n);
640          for (j = 0; j < 3; j++)
641                  sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]);
642 <        if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK)
642 >        if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK)
643                  return(rv);
644 <        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
644 >        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
645                  return(rv);
646          if (minrad == 0.) {             /* closed */
647                  v1ent[3] = av[1];
648 <                if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
648 >                if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
649                          return(rv);
650 <                if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK)
650 >                if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK)
651                          return(rv);
652                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
653                          theta = i*(PI/2)/mg_nqcdivs;
654 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
654 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
655                                  return(rv);
656                          for (j = 0; j < 3; j++)
657                                  sprintf(p3[j], FLTFMT, cv->p[j] +
658                                                  maxrad*u[j]*cos(theta) +
659                                                  maxrad*v[j]*sin(theta));
660 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
660 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
661                                  return(rv);
662 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
662 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
663                                  return(rv);
664 <                        if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK)
664 >                        if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK)
665                                  return(rv);
666                  }
667          } else {                        /* open */
668 <                if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK)
668 >                if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK)
669                          return(rv);
670                  for (j = 0; j < 3; j++)
671                          sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]);
672 <                if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
672 >                if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
673                          return(rv);
674                  v1ent[3] = "_rv4";
675                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
676                          theta = i*(PI/2)/mg_nqcdivs;
677 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
677 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
678                                  return(rv);
679 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
679 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
680                                  return(rv);
681                          for (j = 0; j < 3; j++) {
682                                  d = u[j]*cos(theta) + v[j]*sin(theta);
683                                  sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d);
684                                  sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d);
685                          }
686 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
686 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
687                                  return(rv);
688 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
688 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
689                                  return(rv);
690 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK)
690 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK)
691                                  return(rv);
692 <                        if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
692 >                        if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
693                                  return(rv);
694 <                        if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK)
694 >                        if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK)
695                                  return(rv);
696                  }
697          }
# Line 798 | Line 773 | char   **av;
773                  else
774                          sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off);
775          }
776 <        if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK)
776 >        if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK)
777                  return(rv);
778 <        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
778 >        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
779                  return(rv);
780 <        if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK)
780 >        if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
781                  return(rv);
782          if (rad1 == 0.) {               /* triangles */
783                  v1ent[3] = av[1];
784 <                if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
784 >                if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
785                          return(rv);
786                  for (j = 0; j < 3; j++)
787                          sprintf(n4[j], FLTFMT, w[j]);
788 <                if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK)
788 >                if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
789                          return(rv);
790                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
791                          theta = sgn*i*(PI/2)/mg_nqcdivs;
792 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
792 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
793                                  return(rv);
794                          for (j = 0; j < 3; j++) {
795                                  d = u[j]*cos(theta) + v[j]*sin(theta);
# Line 822 | Line 797 | char   **av;
797                                  if (n2off > -FHUGE)
798                                          sprintf(n3[j], FLTFMT, d + w[j]*n2off);
799                          }
800 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
800 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
801                                  return(rv);
802 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
802 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
803                                  return(rv);
804                          if (n2off > -FHUGE &&
805 <                        (rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK)
805 >                        (rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
806                                  return(rv);
807 <                        if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK)
807 >                        if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK)
808                                  return(rv);
809                  }
810          } else {                        /* quads */
# Line 848 | Line 823 | char   **av;
823                          else
824                                  sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off);
825                  }
826 <                if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK)
826 >                if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK)
827                          return(rv);
828 <                if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
828 >                if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
829                          return(rv);
830 <                if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK)
830 >                if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
831                          return(rv);
832                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
833                          theta = sgn*i*(PI/2)/mg_nqcdivs;
834 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
834 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
835                                  return(rv);
836 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
836 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
837                                  return(rv);
838                          for (j = 0; j < 3; j++) {
839                                  d = u[j]*cos(theta) + v[j]*sin(theta);
# Line 869 | Line 844 | char   **av;
844                                  if (n1off < FHUGE)
845                                          sprintf(n4[j], FLTFMT, d + w[j]*n1off);
846                          }
847 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
847 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
848                                  return(rv);
849 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
849 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
850                                  return(rv);
851                          if (n2off > -FHUGE &&
852 <                        (rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK)
852 >                        (rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
853                                  return(rv);
854 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK)
854 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK)
855                                  return(rv);
856 <                        if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
856 >                        if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
857                                  return(rv);
858                          if (n1off < FHUGE &&
859 <                        (rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK)
859 >                        (rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
860                                  return(rv);
861 <                        if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK)
861 >                        if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK)
862                                  return(rv);
863                  }
864          }
# Line 897 | Line 872 | int    ac;
872   char    **av;
873   {
874          static char     p[3][24];
875 <        static char     *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="};
875 >        static char     *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="};
876          static char     *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]};
877 +        static char     *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"};
878          char    *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8];
879          double  length;
880 +        int     hasnorm;
881          FVECT   v1, v2, v3, norm;
882          register C_VERTEX       *cv;
883          C_VERTEX        *cv0;
884          int     rv;
885          register int    i, j;
886 <
886 >                                                /* check arguments */
887          if (ac < 5)
888                  return(MG_EARGC);
889          if (!isflt(av[ac-1]))
# Line 914 | Line 891 | char   **av;
891          length = atof(av[ac-1]);
892          if (length <= FTINY && length >= -FTINY)
893                  return(MG_EILL);
894 <                                        /* do bottom face */
918 <        newav[0] = mg_ename[MG_E_FACE];
919 <        for (i = 1; i < ac-1; i++)
920 <                newav[i] = av[i];
921 <        newav[i] = NULL;
922 <        if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK)
923 <                return(rv);
924 <                                        /* compute face normal */
894 >                                                /* compute face normal */
895          if ((cv0 = c_getvert(av[1])) == NULL)
896                  return(MG_EUNDEF);
897 +        hasnorm = 0;
898          norm[0] = norm[1] = norm[2] = 0.;
899          v1[0] = v1[1] = v1[2] = 0.;
900          for (i = 2; i < ac-1; i++) {
901                  if ((cv = c_getvert(av[i])) == NULL)
902                          return(MG_EUNDEF);
903 +                hasnorm += !is0vect(cv->n);
904                  v2[0] = cv->p[0] - cv0->p[0];
905                  v2[1] = cv->p[1] - cv0->p[1];
906                  v2[2] = cv->p[2] - cv0->p[2];
# Line 940 | Line 912 | char   **av;
912          }
913          if (normalize(norm) == 0.)
914                  return(MG_EILL);
915 <                                        /* create moved vertices */
915 >                                                /* create moved vertices */
916          for (i = 1; i < ac-1; i++) {
917                  sprintf(nvn[i-1], "_pv%d", i);
918                  vent[1] = nvn[i-1];
919 <                if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK)
919 >                vent[3] = av[i];
920 >                if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
921                          return(rv);
922                  cv = c_getvert(av[i]);          /* checked above */
923                  for (j = 0; j < 3; j++)
924                          sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]);
925 <                if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK)
925 >                if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK)
926                          return(rv);
954                newav[ac-1-i] = nvn[i-1];       /* reverse */
927          }
928 <                                                /* do top face */
929 <        if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK)
958 <                return(rv);
928 >                                                /* make faces */
929 >        newav[0] = mg_ename[MG_E_FACE];
930                                                  /* do the side faces */
931          newav[5] = NULL;
932          newav[3] = av[ac-2];
# Line 963 | Line 934 | char   **av;
934          for (i = 1; i < ac-1; i++) {
935                  newav[1] = nvn[i-1];
936                  newav[2] = av[i];
937 <                if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK)
937 >                if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK)
938                          return(rv);
939                  newav[3] = newav[2];
940                  newav[4] = newav[1];
941          }
942 +                                                /* do top face */
943 +        for (i = 1; i < ac-1; i++) {
944 +                if (hasnorm) {                  /* zero normals */
945 +                        vent[1] = nvn[i-1];
946 +                        if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK)
947 +                                return(rv);
948 +                        if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
949 +                                return(rv);
950 +                }
951 +                newav[ac-1-i] = nvn[i-1];       /* reverse */
952 +        }
953 +        if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK)
954 +                return(rv);
955 +                                                /* do bottom face */
956 +        if (hasnorm)
957 +                for (i = 1; i < ac-1; i++) {
958 +                        vent[1] = nvn[i-1];
959 +                        vent[3] = av[i];
960 +                        if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
961 +                                return(rv);
962 +                        if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
963 +                                return(rv);
964 +                        newav[i] = nvn[i-1];
965 +                }
966 +        else
967 +                for (i = 1; i < ac-1; i++)
968 +                        newav[i] = av[i];
969 +        newav[i] = NULL;
970 +        if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK)
971 +                return(rv);
972          return(MG_OK);
973   }
974  
975  
976   static int
977 < e_cspec(ac, av)                 /* handle spectral color */
977 < int     ac;
978 < char    **av;
977 > put_cxy()                       /* put out current xy chromaticities */
978   {
979          static char     xbuf[24], ybuf[24];
980          static char     *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf};
981          int     rv;
982  
983 +        sprintf(xbuf, "%.4f", c_ccolor->cx);
984 +        sprintf(ybuf, "%.4f", c_ccolor->cy);
985 +        if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK)
986 +                return(rv);
987 +        return(MG_OK);
988 + }
989 +
990 +
991 + static int
992 + put_cspec()                     /* put out current color spectrum */
993 + {
994 +        char    wl[2][6], vbuf[C_CNSS][24];
995 +        char    *newav[C_CNSS+4];
996 +        double  sf;
997 +        register int    i;
998 +
999 +        if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1000 +                sprintf(wl[0], "%d", C_CMINWL);
1001 +                sprintf(wl[1], "%d", C_CMAXWL);
1002 +                newav[0] = mg_ename[MG_E_CSPEC];
1003 +                newav[1] = wl[0];
1004 +                newav[2] = wl[1];
1005 +                sf = (double)C_CNSS / c_ccolor->ssum;
1006 +                for (i = 0; i < C_CNSS; i++) {
1007 +                        sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]);
1008 +                        newav[i+3] = vbuf[i];
1009 +                }
1010 +                newav[C_CNSS+3] = NULL;
1011 +                if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1012 +                        return(i);
1013 +        }
1014 +        return(MG_OK);
1015 + }
1016 +
1017 +
1018 + static int
1019 + e_cspec(ac, av)                 /* handle spectral color */
1020 + int     ac;
1021 + char    **av;
1022 + {
1023 +                                /* convert to xy chromaticity */
1024          c_ccvt(c_ccolor, C_CSXY);
1025                                  /* if it's really their handler, use it */
1026 <        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1027 <                sprintf(xbuf, "%.4f", c_ccolor->cx);
988 <                sprintf(ybuf, "%.4f", c_ccolor->cy);
989 <                if ((rv = handle_it(MG_E_CXY, 3, ccom)) != MG_OK)
990 <                        return(rv);
991 <        }
1026 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1027 >                return(put_cxy());
1028          return(MG_OK);
1029   }
1030  
# Line 998 | Line 1034 | e_cmix(ac, av)                 /* handle mixing of colors */
1034   int     ac;
1035   char    **av;
1036   {
1001        char    wl[2][6], vbuf[C_CNSS][24];
1002        char    *newav[C_CNSS+4];
1003        int     rv;
1004        register int    i;
1037          /*
1038           * Contorted logic works as follows:
1039           *      1. the colors are already mixed in c_hcolor() support function
# Line 1012 | Line 1044 | char   **av;
1044           */
1045          if (mg_ehand[MG_E_CSPEC] == e_cspec)
1046                  c_ccvt(c_ccolor, C_CSXY);
1047 <        else if (c_ccolor->flags & C_CDSPEC) {
1048 <                if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1049 <                        sprintf(wl[0], "%d", C_CMINWL);
1050 <                        sprintf(wl[1], "%d", C_CMAXWL);
1051 <                        newav[0] = mg_ename[MG_E_CSPEC];
1052 <                        newav[1] = wl[0];
1053 <                        newav[2] = wl[1];
1054 <                        for (i = 0; i < C_CNSS; i++) {
1055 <                                sprintf(vbuf[i], "%.6f",
1056 <                                                (double)c_ccolor->ssamp[i] /
1057 <                                                c_ccolor->ssum);
1058 <                                newav[i+3] = vbuf[i];
1059 <                        }
1060 <                        newav[C_CNSS+3] = NULL;
1061 <                        if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1062 <                                return(rv);
1063 <                }
1064 <                return(MG_OK);
1065 <        }
1066 <        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1067 <                sprintf(vbuf[0], "%.4f", c_ccolor->cx);
1068 <                sprintf(vbuf[1], "%.4f", c_ccolor->cy);
1069 <                newav[0] = mg_ename[MG_E_CXY];
1070 <                newav[1] = vbuf[0];
1039 <                newav[2] = vbuf[1];
1040 <                newav[3] = NULL;
1041 <                if ((rv = handle_it(MG_E_CXY, 3, newav)) != MG_OK)
1042 <                        return(rv);
1043 <        }
1047 >        else if (c_ccolor->flags & C_CDSPEC)
1048 >                return(put_cspec());
1049 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1050 >                return(put_cxy());
1051 >        return(MG_OK);
1052 > }
1053 >
1054 >
1055 > static int
1056 > e_cct(ac, av)                   /* handle color temperature */
1057 > int     ac;
1058 > char    **av;
1059 > {
1060 >        /*
1061 >         * Logic is similar to e_cmix here.  Support handler has already
1062 >         * converted temperature to spectral color.  Put it out as such
1063 >         * if they support it, otherwise convert to xy chromaticity and
1064 >         * put it out if they handle it.
1065 >         */
1066 >        if (mg_ehand[MG_E_CSPEC] != e_cspec)
1067 >                return(put_cspec());
1068 >        c_ccvt(c_ccolor, C_CSXY);
1069 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1070 >                return(put_cxy());
1071          return(MG_OK);
1072   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines