--- ray/src/cv/mgflib/parser.c 1995/12/01 11:03:57 1.22 +++ ray/src/cv/mgflib/parser.c 1997/12/15 09:41:37 1.26 @@ -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"; @@ -10,6 +10,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include +#include #include #include #include "parser.h" @@ -63,16 +64,9 @@ 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_cyl(), /* cylinder */ - e_cone(), /* cone */ - e_prism(), /* prism */ - e_ring(), /* ring */ - e_torus(); /* torus */ + e_cspec(); /* color spectra */ /* alternate handler support functions */ @@ -123,6 +117,10 @@ mg_init() /* initialize alternate entity handlers */ ineed |= 1L<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); } @@ -270,8 +267,6 @@ void mg_fgetpos(pos) /* get current position in input file */ register MG_FPOS *pos; { - extern long ftell(); - pos->fid = mg_file->fid; pos->lineno = mg_file->lineno; pos->offset = ftell(mg_file->fp); @@ -319,7 +314,6 @@ mg_parse() /* parse current input line */ { char abuf[MG_MAXLINE]; char *argv[MG_MAXARGC]; - int en; register char *cp, *cp2, **ap; /* copy line, removing escape chars */ cp = abuf; cp2 = mg_file->inpline; @@ -392,7 +386,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(); } @@ -410,7 +405,7 @@ char **av; } -static int +int e_include(ac, av) /* include file */ int ac; char **av; @@ -463,6 +458,38 @@ char **av; } +int +e_faceh(ac, av) /* replace face+holes with single contour */ +int ac; +char **av; +{ + char *newav[MG_MAXARGC]; + int lastp = 0; + register int i, j; + + newav[0] = mg_ename[MG_E_FACE]; + for (i = 1; i < ac; i++) + if (av[i][0] == '-') { + if (i < 4) + return(MG_EARGC); + if (i >= ac-1) + break; + if (!lastp) + lastp = i-1; + for (j = i+1; j < ac-1 && av[j+1][0] != '-'; j++) + ; + if (j - i < 3) + return(MG_EARGC); + newav[i] = av[j]; /* connect hole loop */ + } else + newav[i] = av[i]; /* hole or perimeter vertex */ + if (lastp) + newav[i++] = av[lastp]; /* finish seam to outside */ + newav[i] = NULL; + return(mg_handle(MG_E_FACE, i, newav)); +} + + static void make_axes(u, v, w) /* compute u and v given w (normalized) */ FVECT u, v, w; @@ -480,7 +507,7 @@ FVECT u, v, w; } -static int +int e_sph(ac, av) /* expand a sphere into cones */ int ac; char **av; @@ -532,7 +559,7 @@ char **av; } -static int +int e_torus(ac, av) /* expand a torus into cones */ int ac; char **av; @@ -624,7 +651,7 @@ char **av; } -static int +int e_cyl(ac, av) /* replace a cylinder with equivalent cone */ int ac; char **av; @@ -641,7 +668,7 @@ char **av; } -static int +int e_ring(ac, av) /* turn a ring into polygons */ int ac; char **av; @@ -739,7 +766,7 @@ char **av; } -static int +int e_cone(ac, av) /* turn a cone into polygons */ int ac; char **av; @@ -781,7 +808,7 @@ char **av; if (rad2 == 0.) return(MG_EILL); } else if (rad2 != 0.) { - if (rad1 < 0. ^ rad2 < 0.) + if ((rad1 < 0.) ^ (rad2 < 0.)) return(MG_EILL); } else { /* swap */ C_VERTEX *cv; @@ -909,7 +936,7 @@ char **av; } -static int +int e_prism(ac, av) /* turn a prism into polygons */ int ac; char **av; @@ -1021,13 +1048,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)); }