--- ray/src/cv/mgflib/parser.c 1995/11/29 19:14:49 1.21 +++ ray/src/cv/mgflib/parser.c 1996/06/19 22:34:59 1.23 @@ -1,4 +1,4 @@ -/* Copyright (c) 1995 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -63,11 +63,12 @@ int mg_nqcdivs = MG_NQCD; /* number of divisions per q static int e_any_toss(), /* discard unneeded entity */ e_ies(), /* IES luminaire file */ - e_include(), /* include file */ - e_sph(), /* sphere */ e_cct(), /* color temperature */ e_cmix(), /* color mixtures */ - e_cspec(), /* color spectra */ + e_cspec(); /* color spectra */ + +int e_include(), /* include file */ + e_sph(), /* sphere */ e_cyl(), /* cylinder */ e_cone(), /* cone */ e_prism(), /* prism */ @@ -260,9 +261,8 @@ mg_close() /* close input file */ register MG_FCTXT *ctx = mg_file; mg_file = ctx->prev; /* restore enclosing context */ - if (ctx->fp == stdin) - return; /* don't close standard input */ - fclose(ctx->fp); + if (ctx->fp != stdin) /* close file if it's a file */ + fclose(ctx->fp); } @@ -304,11 +304,11 @@ mg_read() /* read next line from file */ if (fgets(mg_file->inpline+len, MG_MAXLINE-len, mg_file->fp) == NULL) return(len); - mg_file->lineno++; len += strlen(mg_file->inpline+len); - if (len > 1 && mg_file->inpline[len-2] == '\\') - mg_file->inpline[--len-1] = ' '; - } while (mg_file->inpline[len]); + if (len >= MG_MAXLINE-1) + return(len); + mg_file->lineno++; + } while (len > 1 && mg_file->inpline[len-2] == '\\'); return(len); } @@ -320,10 +320,13 @@ mg_parse() /* parse current input line */ char abuf[MG_MAXLINE]; char *argv[MG_MAXARGC]; int en; - register char *cp, **ap; - - strcpy(cp=abuf, mg_file->inpline); - ap = argv; /* break into words */ + register char *cp, *cp2, **ap; + /* copy line, removing escape chars */ + cp = abuf; cp2 = mg_file->inpline; + while ((*cp++ = *cp2++)) + if (cp2[0] == '\n' && cp2[-1] == '\\') + cp--; + cp = abuf; ap = argv; /* break into words */ for ( ; ; ) { while (isspace(*cp)) *cp++ = '\0'; @@ -356,7 +359,7 @@ char *fn; return(rval); } while ((nbr = mg_read()) > 0) { /* parse each line */ - if (nbr >= MG_MAXLINE-1 && cntxt.inpline[nbr-1] != '\n') { + if (nbr >= MG_MAXLINE-1) { fprintf(stderr, "%s: %d: %s\n", cntxt.fname, cntxt.lineno, mg_err[rval=MG_ELINE]); break; @@ -389,7 +392,8 @@ void mg_clear() /* clear parser history */ { c_clearall(); /* clear context tables */ - mg_file = NULL; /* reset our context */ + while (mg_file != NULL) /* reset our file context */ + mg_close(); } @@ -407,7 +411,7 @@ char **av; } -static int +int e_include(ac, av) /* include file */ int ac; char **av; @@ -435,7 +439,7 @@ char **av; } do { while ((rv = mg_read()) > 0) { - if (rv >= MG_MAXLINE-1 && ictx.inpline[rv-1] != '\n') { + if (rv >= MG_MAXLINE-1) { fprintf(stderr, "%s: %d: %s\n", ictx.fname, ictx.lineno, mg_err[MG_ELINE]); mg_close(); @@ -477,7 +481,7 @@ FVECT u, v, w; } -static int +int e_sph(ac, av) /* expand a sphere into cones */ int ac; char **av; @@ -529,7 +533,7 @@ char **av; } -static int +int e_torus(ac, av) /* expand a torus into cones */ int ac; char **av; @@ -621,7 +625,7 @@ char **av; } -static int +int e_cyl(ac, av) /* replace a cylinder with equivalent cone */ int ac; char **av; @@ -638,7 +642,7 @@ char **av; } -static int +int e_ring(ac, av) /* turn a ring into polygons */ int ac; char **av; @@ -736,7 +740,7 @@ char **av; } -static int +int e_cone(ac, av) /* turn a cone into polygons */ int ac; char **av; @@ -906,7 +910,7 @@ char **av; } -static int +int e_prism(ac, av) /* turn a prism into polygons */ int ac; char **av; @@ -1018,13 +1022,10 @@ put_cxy() /* put out current xy chromaticities */ { static char xbuf[24], ybuf[24]; static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; - int rv; sprintf(xbuf, "%.4f", c_ccolor->cx); sprintf(ybuf, "%.4f", c_ccolor->cy); - if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) - return(rv); - return(MG_OK); + return(mg_handle(MG_E_CXY, 3, ccom)); }