--- ray/src/cv/mgflib/parser.c 1994/06/24 09:40:29 1.5 +++ ray/src/cv/mgflib/parser.c 1994/06/25 09:48:03 1.8 @@ -53,8 +53,6 @@ int mg_nqcdivs = MG_NQCD; /* number of divisions per q /* temporary settings for testing */ #define e_ies e_any_toss -#define e_cmix e_any_toss -#define e_cspec e_any_toss /* alternate handler routines */ static int e_any_toss(), /* discard unneeded entity */ @@ -62,7 +60,7 @@ static int e_any_toss(), /* discard unneeded entity * e_include(), /* include file */ e_sph(), /* sphere */ e_cmix(), /* color mixtures */ - e_cspec(); /* color spectra */ + e_cspec(), /* color spectra */ e_cyl(), /* cylinder */ e_cone(), /* cone */ e_prism(), /* prism */ @@ -119,15 +117,20 @@ mg_init() /* initialize alternate entity handlers */ } else uneed |= 1<lineno = 0; if (fn == NULL) { - ctx->fname = ""; + strcpy(ctx->fname, ""); ctx->fp = stdin; ctx->prev = mg_file; mg_file = ctx; @@ -216,17 +227,12 @@ char *fn; olen = cp - mg_file->fname + 1; else olen = 0; - ctx->fname = (char *)malloc(olen+strlen(fn)+1); - if (ctx->fname == NULL) - return(MG_EMEM); if (olen) strcpy(ctx->fname, mg_file->fname); strcpy(ctx->fname+olen, fn); ctx->fp = fopen(ctx->fname, "r"); - if (ctx->fp == NULL) { - free((MEM_PTR)ctx->fname); + if (ctx->fp == NULL) return(MG_ENOFILE); - } ctx->prev = mg_file; /* establish new context */ mg_file = ctx; return(MG_OK); @@ -242,7 +248,6 @@ mg_close() /* close input file */ if (ctx->fp == stdin) return; /* don't close standard input */ fclose(ctx->fp); - free((MEM_PTR)ctx->fname); } @@ -917,7 +922,7 @@ char **av; if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK) return(rv); /* compute face normal */ - if ((cv0 = c_getvert(av[2])) == NULL) + if ((cv0 = c_getvert(av[1])) == NULL) return(MG_EUNDEF); norm[0] = norm[1] = norm[2] = 0.; v1[0] = v1[1] = v1[2] = 0.; @@ -962,6 +967,79 @@ char **av; return(rv); newav[3] = newav[2]; newav[4] = newav[1]; + } + return(MG_OK); +} + + +static int +e_cspec(ac, av) /* handle spectral color */ +int ac; +char **av; +{ + static char xbuf[24], ybuf[24]; + static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; + int rv; + + c_ccvt(c_ccolor, C_CSXY); + /* if it's really their handler, use it */ + if (mg_ehand[MG_E_CXY] != c_hcolor) { + sprintf(xbuf, "%.4f", c_ccolor->cx); + sprintf(ybuf, "%.4f", c_ccolor->cy); + if ((rv = handle_it(MG_E_CXY, 3, ccom)) != MG_OK) + return(rv); + } + return(MG_OK); +} + + +static int +e_cmix(ac, av) /* handle mixing of colors */ +int ac; +char **av; +{ + char wl[2][6], vbuf[C_CNSS][24]; + char *newav[C_CNSS+4]; + int rv; + register int i; + /* + * Contorted logic works as follows: + * 1. the colors are already mixed in c_hcolor() support function + * 2. if we would handle a spectral result, make sure it's not + * 3. if c_hcolor() would handle a spectral result, don't bother + * 4. otherwise, make cspec entity and pass it to their handler + * 5. if we have only xy results, handle it as c_spec() would + */ + if (mg_ehand[MG_E_CSPEC] == e_cspec) + c_ccvt(c_ccolor, C_CSXY); + else if (c_ccolor->flags & C_CDSPEC) { + if (mg_ehand[MG_E_CSPEC] != c_hcolor) { + sprintf(wl[0], "%d", C_CMINWL); + sprintf(wl[1], "%d", C_CMAXWL); + newav[0] = mg_ename[MG_E_CSPEC]; + newav[1] = wl[0]; + newav[2] = wl[1]; + for (i = 0; i < C_CNSS; i++) { + sprintf(vbuf[i], "%.6f", + (double)c_ccolor->ssamp[i] / + c_ccolor->ssum); + newav[i+3] = vbuf[i]; + } + newav[C_CNSS+3] = NULL; + if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) + return(rv); + } + return(MG_OK); + } + if (mg_ehand[MG_E_CXY] != c_hcolor) { + sprintf(vbuf[0], "%.4f", c_ccolor->cx); + sprintf(vbuf[1], "%.4f", c_ccolor->cy); + newav[0] = mg_ename[MG_E_CXY]; + newav[1] = vbuf[0]; + newav[2] = vbuf[1]; + newav[3] = NULL; + if ((rv = handle_it(MG_E_CXY, 3, newav)) != MG_OK) + return(rv); } return(MG_OK); }