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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines