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.4 by greg, Fri Jun 24 09:32:51 1994 UTC vs.
Revision 1.11 by greg, Fri Jul 1 18:06:58 1994 UTC

# Line 53 | Line 53 | int    mg_nqcdivs = MG_NQCD;   /* number of divisions per q
53  
54   /* temporary settings for testing */
55   #define e_ies e_any_toss
56 #define e_cmix e_any_toss
57 #define e_cspec e_any_toss
56                                  /* alternate handler routines */
57  
58   static int      e_any_toss(),           /* discard unneeded entity */
# Line 62 | Line 60 | static int     e_any_toss(),           /* discard unneeded entity *
60                  e_include(),            /* include file */
61                  e_sph(),                /* sphere */
62                  e_cmix(),               /* color mixtures */
63 <                e_cspec();              /* color spectra */
63 >                e_cspec(),              /* color spectra */
64                  e_cyl(),                /* cylinder */
65                  e_cone(),               /* cone */
66                  e_prism(),              /* prism */
# Line 119 | Line 117 | mg_init()                      /* initialize alternate entity handlers */
117          } else
118                  uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF;
119          if (mg_ehand[MG_E_COLOR] != NULL) {
120 <                if (mg_ehand[MG_E_CMIX] == NULL)
120 >                if (mg_ehand[MG_E_CMIX] == NULL) {
121                          mg_ehand[MG_E_CMIX] = e_cmix;
122 <                if (mg_ehand[MG_E_CSPEC] == NULL)
122 >                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
123 >                }
124 >                if (mg_ehand[MG_E_CSPEC] == NULL) {
125                          mg_ehand[MG_E_CSPEC] = e_cspec;
126 +                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
127 +                }
128          }
129                                          /* check for consistency */
130          if (mg_ehand[MG_E_FACE] != NULL)
131                  uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF;
132 <        if (mg_ehand[MG_E_CXY] != NULL)
132 >        if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL ||
133 >                        mg_ehand[MG_E_CMIX] != NULL)
134                  uneed |= 1<<MG_E_COLOR;
135          if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL ||
136                          mg_ehand[MG_E_ED] != NULL ||
137                          mg_ehand[MG_E_RS] != NULL ||
138 <                        mg_ehand[MG_E_TS] != NULL)
138 >                        mg_ehand[MG_E_TS] != NULL ||
139 >                        mg_ehand[MG_E_SIDES] != NULL)
140                  uneed |= 1<<MG_E_MATERIAL;
141          for (i = 0; i < MG_NENTITIES; i++)
142                  if (uneed & 1<<i && mg_ehand[i] == NULL) {
# Line 147 | Line 151 | mg_init()                      /* initialize alternate entity handlers */
151                  e_supp[MG_E_POINT] = c_hvertex;
152          if (ineed & 1<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex)
153                  e_supp[MG_E_NORMAL] = c_hvertex;
154 +        if (ineed & 1<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor)
155 +                e_supp[MG_E_COLOR] = c_hcolor;
156 +        if (ineed & 1<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor)
157 +                e_supp[MG_E_CXY] = c_hcolor;
158 +        if (ineed & 1<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor)
159 +                e_supp[MG_E_CSPEC] = c_hcolor;
160 +        if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor)
161 +                e_supp[MG_E_CMIX] = c_hcolor;
162                                          /* discard remaining entities */
163          for (i = 0; i < MG_NENTITIES; i++)
164                  if (mg_ehand[i] == NULL)
# Line 159 | Line 171 | int
171   mg_entity(name)                 /* get entity number from its name */
172   char    *name;
173   {
174 <        static LUTAB    ent_tab;        /* entity lookup table */
174 >        static LUTAB    ent_tab = LU_SINIT(NULL,NULL);  /* lookup table */
175          register char   *cp;
176  
177          if (!ent_tab.tsiz) {            /* initialize hash table */
# Line 176 | Line 188 | char   *name;
188   }
189  
190  
191 < static int
192 < handle_it(en, ac, av)           /* pass entity to appropriate handler */
191 > int
192 > mg_handle(en, ac, av)           /* pass entity to appropriate handler */
193   register int    en;
194   int     ac;
195   char    **av;
# Line 199 | Line 211 | mg_open(ctx, fn)                       /* open new input file */
211   register MG_FCTXT       *ctx;
212   char    *fn;
213   {
214 +        static int      nfids;
215          int     olen;
216          register char   *cp;
217  
218 +        ctx->fid = ++nfids;
219          ctx->lineno = 0;
220          if (fn == NULL) {
221 <                ctx->fname = "<stdin>";
221 >                strcpy(ctx->fname, "<stdin>");
222                  ctx->fp = stdin;
223                  ctx->prev = mg_file;
224                  mg_file = ctx;
# Line 216 | Line 230 | char   *fn;
230                  olen = cp - mg_file->fname + 1;
231          else
232                  olen = 0;
219        ctx->fname = (char *)malloc(olen+strlen(fn)+1);
220        if (ctx->fname == NULL)
221                return(MG_EMEM);
233          if (olen)
234                  strcpy(ctx->fname, mg_file->fname);
235          strcpy(ctx->fname+olen, fn);
236          ctx->fp = fopen(ctx->fname, "r");
237 <        if (ctx->fp == NULL) {
227 <                free((MEM_PTR)ctx->fname);
237 >        if (ctx->fp == NULL)
238                  return(MG_ENOFILE);
229        }
239          ctx->prev = mg_file;            /* establish new context */
240          mg_file = ctx;
241          return(MG_OK);
# Line 242 | Line 251 | mg_close()                     /* close input file */
251          if (ctx->fp == stdin)
252                  return;                 /* don't close standard input */
253          fclose(ctx->fp);
245        free((MEM_PTR)ctx->fname);
254   }
255  
256  
257 + void
258 + mg_fgetpos(pos)                 /* get current position in input file */
259 + register MG_FPOS        *pos;
260 + {
261 +        extern long     ftell();
262 +
263 +        pos->fid = mg_file->fid;
264 +        pos->lineno = mg_file->lineno;
265 +        pos->offset = ftell(mg_file->fp);
266 + }
267 +
268 +
269   int
270 < mg_rewind()                     /* rewind input file */
270 > mg_fgoto(pos)                   /* reposition input file pointer */
271 > register MG_FPOS        *pos;
272   {
273 <        if (mg_file->lineno == 0)
273 >        if (pos->fid != mg_file->fid)
274 >                return(MG_ESEEK);
275 >        if (pos->lineno == mg_file->lineno)
276                  return(MG_OK);
277          if (mg_file->fp == stdin)
278                  return(MG_ESEEK);       /* cannot seek on standard input */
279 <        if (fseek(mg_file->fp, 0L, 0) == EOF)
279 >        if (fseek(mg_file->fp, pos->offset, 0) == EOF)
280                  return(MG_ESEEK);
281 <        mg_file->lineno = 0;
281 >        mg_file->lineno = pos->lineno;
282          return(MG_OK);
283   }
284  
# Line 304 | Line 327 | mg_parse()                     /* parse current input line */
327                  return(MG_OK);          /* no words in line */
328          *ap = NULL;
329                                          /* else handle it */
330 <        return(handle_it(-1, ap-argv, argv));
330 >        return(mg_handle(-1, ap-argv, argv));
331   }
332  
333  
# Line 339 | Line 362 | mg_clear()                     /* clear parser history */
362   }
363  
364  
342 int
343 mg_iterate(ac, av, f)           /* iterate on statement */
344 int     ac;
345 register char   **av;
346 int     (*f)();
347 {
348        int     niter, rval;
349        register int    i, j;
350        char    *argv[MG_MAXARGC];
351        char    cntbuf[10];
352                                        /* build partial transformation */
353        for (i = 0; i < ac; i++) {
354                if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0')
355                        break;
356                argv[i+1] = av[i];
357        }
358        argv[i+1] = NULL;
359        if (i) {                        /* handle transformation */
360                argv[0] = mg_ename[MG_E_XF];
361                if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK)
362                        return(rval);
363        }
364        if (i < ac) {                   /* run array */
365                if (i+1 >= ac || !isint(av[i+1]))
366                        return(MG_ETYPE);
367                niter = atoi(av[i+1]);
368                argv[0] = mg_ename[MG_E_OBJECT];
369                argv[1] = cntbuf;
370                for (j = 2; j+i < ac; j++)
371                        argv[j] = av[j+i];
372                argv[j] = NULL;
373                for (j = 0; j < niter; j++) {
374                        sprintf(cntbuf, "%d", j);
375                        if ((rval = handle_it(MG_E_OBJECT, 2, argv)) != MG_OK)
376                                return(rval);
377                        argv[0] = "-i";
378                        if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK)
379                                return(rval);
380                        argv[0] = mg_ename[MG_E_OBJECT];
381                        if ((rval = handle_it(MG_E_OBJECT, 1, argv)) != MG_OK)
382                                return(rval);
383                }
384        } else if ((rval = (*f)()) != MG_OK)    /* else do this instance */
385                        return(rval);
386        if (i) {                        /* reset the transform */
387                argv[0] = mg_ename[MG_E_XF];
388                argv[1] = NULL;
389                (void)handle_it(MG_E_XF, 1, argv);
390        }
391        return(MG_OK);
392 }
393
394
365   /****************************************************************************
366   *      The following routines handle unsupported entities
367   */
# Line 407 | Line 377 | char   **av;
377  
378  
379   static int
410 reload_file()                   /* reload current MGF file */
411 {
412        register int    rval;
413
414        if ((rval = mg_rewind()) != MG_OK)
415                return(rval);
416        while (mg_read())
417                if ((rval = mg_parse()) != MG_OK)
418                        return(rval);
419        return(MG_OK);
420 }
421
422
423 static int
380   e_include(ac, av)               /* include file */
381   int     ac;
382   char    **av;
383   {
384 +        char    *xfarg[MG_MAXARGC];
385          MG_FCTXT        ictx;
386          int     rv;
387  
# Line 432 | Line 389 | char   **av;
389                  return(MG_EARGC);
390          if ((rv = mg_open(&ictx, av[1])) != MG_OK)
391                  return(rv);
392 <        if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) {
393 <                fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname,
394 <                                ictx.lineno, mg_err[rv], ictx.inpline);
395 <                mg_close();
396 <                return(MG_EINCL);
392 >        if (ac > 2) {
393 >                register int    i;
394 >
395 >                xfarg[0] = mg_ename[MG_E_XF];
396 >                for (i = 1; i < ac-1; i++)
397 >                        xfarg[i] = av[i+1];
398 >                xfarg[ac-1] = NULL;
399 >                if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK)
400 >                        return(rv);
401          }
402 +        while (!feof(mg_file->fp)) {
403 +                while (mg_read())
404 +                        if ((rv = mg_parse()) != MG_OK) {
405 +                                fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname,
406 +                                                ictx.lineno, mg_err[rv],
407 +                                                ictx.inpline);
408 +                                mg_close();
409 +                                return(MG_EINCL);
410 +                        }
411 +                if (ac > 2)
412 +                        if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK)
413 +                                return(rv);
414 +        }
415          mg_close();
416          return(MG_OK);
417   }
# Line 485 | Line 459 | char   **av;
459          rad = atof(av[2]);
460                                          /* initialize */
461          warpconends = 1;
462 <        if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK)
462 >        if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK)
463                  return(rval);
464          sprintf(p2x, FLTFMT, cv->p[0]);
465          sprintf(p2y, FLTFMT, cv->p[1]);
466          sprintf(p2z, FLTFMT, cv->p[2]+rad);
467 <        if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
467 >        if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
468                  return(rval);
469          r2[0] = '0'; r2[1] = '\0';
470          for (i = 1; i <= 2*mg_nqcdivs; i++) {
471                  theta = i*(PI/2)/mg_nqcdivs;
472 <                if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
472 >                if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
473                          return(rval);
474                  sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta));
475 <                if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK)
475 >                if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
476                          return(rval);
477 <                if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
477 >                if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
478                          return(rval);
479                  strcpy(r1, r2);
480                  sprintf(r2, FLTFMT, rad*sin(theta));
481 <                if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK)
481 >                if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
482                          return(rval);
483          }
484          warpconends = 0;
# Line 559 | Line 533 | char   **av;
533          for (j = 0; j < 3; j++)
534                  sprintf(p2[j], FLTFMT, cv->p[j] +
535                                  .5*sgn*(maxrad-minrad)*cv->n[j]);
536 <        if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
536 >        if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
537                  return(rval);
538 <        if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
538 >        if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
539                  return(rval);
540          sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad));
541                                          /* run outer section */
542          for (i = 1; i <= 2*mg_nqcdivs; i++) {
543                  theta = i*(PI/2)/mg_nqcdivs;
544 <                if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
544 >                if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
545                          return(rval);
546                  for (j = 0; j < 3; j++)
547                          sprintf(p2[j], FLTFMT, cv->p[j] +
548                                  .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]);
549 <                if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK)
549 >                if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
550                          return(rval);
551 <                if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
551 >                if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
552                          return(rval);
553                  strcpy(r1, r2);
554                  sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta));
555 <                if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK)
555 >                if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
556                          return(rval);
557          }
558                                          /* run inner section */
# Line 588 | Line 562 | char   **av;
562                  for (j = 0; j < 3; j++)
563                          sprintf(p2[j], FLTFMT, cv->p[j] +
564                                  .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]);
565 <                if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
565 >                if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
566                          return(rval);
567 <                if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK)
567 >                if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
568                          return(rval);
569 <                if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK)
569 >                if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
570                          return(rval);
571                  strcpy(r1, r2);
572                  sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta));
573 <                if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK)
573 >                if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
574                          return(rval);
575          }
576          warpconends = 0;
# Line 617 | Line 591 | char   **av;
591          avnew[2] = av[2];
592          avnew[3] = av[3];
593          avnew[4] = av[2];
594 <        return(handle_it(MG_E_CONE, 5, avnew));
594 >        return(mg_handle(MG_E_CONE, 5, avnew));
595   }
596  
597  
# Line 659 | Line 633 | char   **av;
633          make_axes(u, v, cv->n);
634          for (j = 0; j < 3; j++)
635                  sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]);
636 <        if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK)
636 >        if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK)
637                  return(rv);
638 <        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
638 >        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
639                  return(rv);
640          if (minrad == 0.) {             /* closed */
641                  v1ent[3] = av[1];
642 <                if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
642 >                if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
643                          return(rv);
644 <                if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK)
644 >                if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK)
645                          return(rv);
646                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
647                          theta = i*(PI/2)/mg_nqcdivs;
648 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
648 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
649                                  return(rv);
650                          for (j = 0; j < 3; j++)
651                                  sprintf(p3[j], FLTFMT, cv->p[j] +
652                                                  maxrad*u[j]*cos(theta) +
653                                                  maxrad*v[j]*sin(theta));
654 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
654 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
655                                  return(rv);
656 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
656 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
657                                  return(rv);
658 <                        if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK)
658 >                        if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK)
659                                  return(rv);
660                  }
661          } else {                        /* open */
662 <                if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK)
662 >                if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK)
663                          return(rv);
664                  for (j = 0; j < 3; j++)
665                          sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]);
666 <                if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
666 >                if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
667                          return(rv);
668                  v1ent[3] = "_rv4";
669                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
670                          theta = i*(PI/2)/mg_nqcdivs;
671 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
671 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
672                                  return(rv);
673 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
673 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
674                                  return(rv);
675                          for (j = 0; j < 3; j++) {
676                                  d = u[j]*cos(theta) + v[j]*sin(theta);
677                                  sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d);
678                                  sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d);
679                          }
680 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
680 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
681                                  return(rv);
682 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
682 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
683                                  return(rv);
684 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK)
684 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK)
685                                  return(rv);
686 <                        if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
686 >                        if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
687                                  return(rv);
688 <                        if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK)
688 >                        if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK)
689                                  return(rv);
690                  }
691          }
# Line 793 | Line 767 | char   **av;
767                  else
768                          sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off);
769          }
770 <        if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK)
770 >        if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK)
771                  return(rv);
772 <        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
772 >        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
773                  return(rv);
774 <        if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK)
774 >        if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
775                  return(rv);
776          if (rad1 == 0.) {               /* triangles */
777                  v1ent[3] = av[1];
778 <                if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
778 >                if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
779                          return(rv);
780                  for (j = 0; j < 3; j++)
781                          sprintf(n4[j], FLTFMT, w[j]);
782 <                if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK)
782 >                if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
783                          return(rv);
784                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
785                          theta = sgn*i*(PI/2)/mg_nqcdivs;
786 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
786 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
787                                  return(rv);
788                          for (j = 0; j < 3; j++) {
789                                  d = u[j]*cos(theta) + v[j]*sin(theta);
# Line 817 | Line 791 | char   **av;
791                                  if (n2off > -FHUGE)
792                                          sprintf(n3[j], FLTFMT, d + w[j]*n2off);
793                          }
794 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
794 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
795                                  return(rv);
796 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
796 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
797                                  return(rv);
798                          if (n2off > -FHUGE &&
799 <                        (rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK)
799 >                        (rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
800                                  return(rv);
801 <                        if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK)
801 >                        if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK)
802                                  return(rv);
803                  }
804          } else {                        /* quads */
# Line 843 | Line 817 | char   **av;
817                          else
818                                  sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off);
819                  }
820 <                if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK)
820 >                if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK)
821                          return(rv);
822 <                if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
822 >                if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
823                          return(rv);
824 <                if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK)
824 >                if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
825                          return(rv);
826                  for (i = 1; i <= 4*mg_nqcdivs; i++) {
827                          theta = sgn*i*(PI/2)/mg_nqcdivs;
828 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK)
828 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
829                                  return(rv);
830 <                        if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK)
830 >                        if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
831                                  return(rv);
832                          for (j = 0; j < 3; j++) {
833                                  d = u[j]*cos(theta) + v[j]*sin(theta);
# Line 864 | Line 838 | char   **av;
838                                  if (n1off < FHUGE)
839                                          sprintf(n4[j], FLTFMT, d + w[j]*n1off);
840                          }
841 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK)
841 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
842                                  return(rv);
843 <                        if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK)
843 >                        if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
844                                  return(rv);
845                          if (n2off > -FHUGE &&
846 <                        (rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK)
846 >                        (rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
847                                  return(rv);
848 <                        if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK)
848 >                        if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK)
849                                  return(rv);
850 <                        if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK)
850 >                        if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
851                                  return(rv);
852                          if (n1off < FHUGE &&
853 <                        (rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK)
853 >                        (rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
854                                  return(rv);
855 <                        if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK)
855 >                        if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK)
856                                  return(rv);
857                  }
858          }
# Line 904 | Line 878 | char   **av;
878  
879          if (ac < 5)
880                  return(MG_EARGC);
881 <        if (!isflt(av[1]))
881 >        if (!isflt(av[ac-1]))
882                  return(MG_ETYPE);
883 <        length = atof(av[1]);
883 >        length = atof(av[ac-1]);
884          if (length <= FTINY && length >= -FTINY)
885                  return(MG_EILL);
886                                          /* do bottom face */
887          newav[0] = mg_ename[MG_E_FACE];
888          for (i = 1; i < ac-1; i++)
889 <                newav[i] = av[i+1];
889 >                newav[i] = av[i];
890          newav[i] = NULL;
891 <        if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK)
891 >        if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK)
892                  return(rv);
893                                          /* compute face normal */
894 <        if ((cv0 = c_getvert(av[2])) == NULL)
894 >        if ((cv0 = c_getvert(av[1])) == NULL)
895                  return(MG_EUNDEF);
896          norm[0] = norm[1] = norm[2] = 0.;
897          v1[0] = v1[1] = v1[2] = 0.;
898          for (i = 2; i < ac-1; i++) {
899 <                if ((cv = c_getvert(av[i+1])) == NULL)
899 >                if ((cv = c_getvert(av[i])) == NULL)
900                          return(MG_EUNDEF);
901                  v2[0] = cv->p[0] - cv0->p[0];
902                  v2[1] = cv->p[1] - cv0->p[1];
# Line 939 | Line 913 | char   **av;
913          for (i = 1; i < ac-1; i++) {
914                  sprintf(nvn[i-1], "_pv%d", i);
915                  vent[1] = nvn[i-1];
916 <                if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK)
916 >                if ((rv = mg_handle(MG_E_VERTEX, 3, vent)) != MG_OK)
917                          return(rv);
918 <                cv = c_getvert(av[i+1]);        /* checked above */
918 >                cv = c_getvert(av[i]);          /* checked above */
919                  for (j = 0; j < 3; j++)
920                          sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]);
921 <                if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK)
921 >                if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK)
922                          return(rv);
923                  newav[ac-1-i] = nvn[i-1];       /* reverse */
924          }
925                                                  /* do top face */
926 <        if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK)
926 >        if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK)
927                  return(rv);
928                                                  /* do the side faces */
929          newav[5] = NULL;
930 <        newav[3] = av[ac-1];
930 >        newav[3] = av[ac-2];
931          newav[4] = nvn[ac-3];
932          for (i = 1; i < ac-1; i++) {
933                  newav[1] = nvn[i-1];
934 <                newav[2] = av[i+1];
935 <                if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK)
934 >                newav[2] = av[i];
935 >                if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK)
936                          return(rv);
937                  newav[3] = newav[2];
938                  newav[4] = newav[1];
939 +        }
940 +        return(MG_OK);
941 + }
942 +
943 +
944 + static int
945 + e_cspec(ac, av)                 /* handle spectral color */
946 + int     ac;
947 + char    **av;
948 + {
949 +        static char     xbuf[24], ybuf[24];
950 +        static char     *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf};
951 +        int     rv;
952 +
953 +        c_ccvt(c_ccolor, C_CSXY);
954 +                                /* if it's really their handler, use it */
955 +        if (mg_ehand[MG_E_CXY] != c_hcolor) {
956 +                sprintf(xbuf, "%.4f", c_ccolor->cx);
957 +                sprintf(ybuf, "%.4f", c_ccolor->cy);
958 +                if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK)
959 +                        return(rv);
960 +        }
961 +        return(MG_OK);
962 + }
963 +
964 +
965 + static int
966 + e_cmix(ac, av)                  /* handle mixing of colors */
967 + int     ac;
968 + char    **av;
969 + {
970 +        char    wl[2][6], vbuf[C_CNSS][24];
971 +        char    *newav[C_CNSS+4];
972 +        int     rv;
973 +        register int    i;
974 +        /*
975 +         * Contorted logic works as follows:
976 +         *      1. the colors are already mixed in c_hcolor() support function
977 +         *      2. if we would handle a spectral result, make sure it's not
978 +         *      3. if c_hcolor() would handle a spectral result, don't bother
979 +         *      4. otherwise, make cspec entity and pass it to their handler
980 +         *      5. if we have only xy results, handle it as c_spec() would
981 +         */
982 +        if (mg_ehand[MG_E_CSPEC] == e_cspec)
983 +                c_ccvt(c_ccolor, C_CSXY);
984 +        else if (c_ccolor->flags & C_CDSPEC) {
985 +                if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
986 +                        sprintf(wl[0], "%d", C_CMINWL);
987 +                        sprintf(wl[1], "%d", C_CMAXWL);
988 +                        newav[0] = mg_ename[MG_E_CSPEC];
989 +                        newav[1] = wl[0];
990 +                        newav[2] = wl[1];
991 +                        for (i = 0; i < C_CNSS; i++) {
992 +                                sprintf(vbuf[i], "%.6f",
993 +                                                (double)c_ccolor->ssamp[i] /
994 +                                                c_ccolor->ssum);
995 +                                newav[i+3] = vbuf[i];
996 +                        }
997 +                        newav[C_CNSS+3] = NULL;
998 +                        if ((rv = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
999 +                                return(rv);
1000 +                }
1001 +                return(MG_OK);
1002 +        }
1003 +        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1004 +                sprintf(vbuf[0], "%.4f", c_ccolor->cx);
1005 +                sprintf(vbuf[1], "%.4f", c_ccolor->cy);
1006 +                newav[0] = mg_ename[MG_E_CXY];
1007 +                newav[1] = vbuf[0];
1008 +                newav[2] = vbuf[1];
1009 +                newav[3] = NULL;
1010 +                if ((rv = mg_handle(MG_E_CXY, 3, newav)) != MG_OK)
1011 +                        return(rv);
1012          }
1013          return(MG_OK);
1014   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines