--- ray/src/cv/mgflib/parser.h 1995/03/10 15:16:42 1.19 +++ ray/src/cv/mgflib/parser.h 1995/11/08 09:40:26 1.26 @@ -1,4 +1,4 @@ -/* Copyright (c) 1994 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ /* SCCSid "$SunId$ LBL" */ @@ -8,53 +8,65 @@ /* must include stdio.h before us */ - /* Entities (order doesn't really matter) */ -#define MG_E_COMMENT 0 -#define MG_E_COLOR 1 -#define MG_E_CCT 2 -#define MG_E_CONE 3 -#define MG_E_CMIX 4 -#define MG_E_CSPEC 5 -#define MG_E_CXY 6 -#define MG_E_CYL 7 -#define MG_E_ED 8 -#define MG_E_FACE 9 -#define MG_E_INCLUDE 10 -#define MG_E_IES 11 -#define MG_E_MATERIAL 12 -#define MG_E_NORMAL 13 -#define MG_E_OBJECT 14 -#define MG_E_POINT 15 -#define MG_E_PRISM 16 -#define MG_E_RD 17 -#define MG_E_RING 18 -#define MG_E_RS 19 -#define MG_E_SIDES 20 -#define MG_E_SPH 21 -#define MG_E_TD 22 -#define MG_E_TORUS 23 -#define MG_E_TS 24 -#define MG_E_VERTEX 25 -#define MG_E_XF 26 +#define MG_VMAJOR 1 /* major version number */ +#define MG_VMINOR 0 /* minor version number */ -#define MG_NENTITIES 27 + /* Entities (list is only appended, never modified) */ +#define MG_E_COMMENT 0 /* # */ +#define MG_E_COLOR 1 /* c */ +#define MG_E_CCT 2 /* cct */ +#define MG_E_CONE 3 /* cone */ +#define MG_E_CMIX 4 /* cmix */ +#define MG_E_CSPEC 5 /* cspec */ +#define MG_E_CXY 6 /* cxy */ +#define MG_E_CYL 7 /* cyl */ +#define MG_E_ED 8 /* ed */ +#define MG_E_FACE 9 /* f */ +#define MG_E_INCLUDE 10 /* i */ +#define MG_E_IES 11 /* ies */ +#define MG_E_IR 12 /* ir */ +#define MG_E_MATERIAL 13 /* m */ +#define MG_E_NORMAL 14 /* n */ +#define MG_E_OBJECT 15 /* o */ +#define MG_E_POINT 16 /* p */ +#define MG_E_PRISM 17 /* prism */ +#define MG_E_RD 18 /* rd */ +#define MG_E_RING 19 /* ring */ +#define MG_E_RS 20 /* rs */ +#define MG_E_SIDES 21 /* sides */ +#define MG_E_SPH 22 /* sph */ +#define MG_E_TD 23 /* td */ +#define MG_E_TORUS 24 /* torus */ +#define MG_E_TS 25 /* ts */ +#define MG_E_VERTEX 26 /* v */ +#define MG_E_XF 27 /* xf */ + /* end of Version 1 entities */ +#define MG_NENTITIES 28 /* total # entities */ + +#define MG_NELIST {28} /* entity count for version 1 and up */ + #define MG_NAMELIST {"#","c","cct","cone","cmix","cspec","cxy","cyl","ed",\ - "f","i","ies","m","n","o","p","prism","rd","ring",\ - "rs","sides","sph","td","torus","ts","v","xf"} + "f","i","ies","ir","m","n","o","p","prism","rd",\ + "ring","rs","sides","sph","td","torus","ts","v","xf"} #define MG_MAXELEN 6 extern char mg_ename[MG_NENTITIES][MG_MAXELEN]; - /* Handler routines for each entity */ - + /* Handler routines for each entity and unknown ones */ #ifdef NOPROTO extern int (*mg_ehand[MG_NENTITIES])(); +extern int (*mg_uhand)(); +extern int mg_defuhand(); #else extern int (*mg_ehand[MG_NENTITIES])(int argc, char **argv); +extern int (*mg_uhand)(int argc, char **argv); +extern int mg_defuhand(int, char **); #endif +extern unsigned mg_nunknown; /* count of unknown entities */ + /* Error codes */ #define MG_OK 0 /* normal return value */ #define MG_EUNK 1 /* unknown entity */ @@ -67,10 +79,11 @@ extern int (*mg_ehand[MG_NENTITIES])(int argc, char ** #define MG_EMEM 8 /* out of memory */ #define MG_ESEEK 9 /* file seek error */ #define MG_EBADMAT 10 /* bad material specification */ +#define MG_ELINE 11 /* input line too long */ -#define MG_NERRS 11 +#define MG_NERRS 12 -extern char *mg_err[MG_NERRS]; +extern char *mg_err[MG_NERRS]; /* list of error messages */ /* * The general process for running the parser is to fill in the mg_ehand @@ -86,7 +99,7 @@ extern char *mg_err[MG_NERRS]; * (The first argument to mg_handle is the entity #, or -1.) * To free any data structures and clear the parser, use mg_clear. * If there is an error, mg_load, mg_open, mg_parse, mg_handle and - * mg_rewind will return an error from the list above. In addition, + * mg_fgoto will return an error from the list above. In addition, * mg_load will report the error to stderr. The mg_read routine * returns 0 when the end of file has been reached. */ @@ -149,10 +162,12 @@ extern int mg_nqcdivs; /* divisions per quarter circl extern int mg_entity(); /* get entity number from its name */ extern int isint(); /* non-zero if integer format */ extern int isflt(); /* non-zero if floating point format */ +extern int isname(); /* non-zero if legal identifier name */ #else extern int mg_entity(char *); /* get entity number from its name */ extern int isint(char *); /* non-zero if integer format */ extern int isflt(char *); /* non-zero if floating point format */ +extern int isname(char *); /* non-zero if legal identifier name */ #endif /************************************************************************ @@ -225,9 +240,12 @@ typedef struct { #define c_cval(c,l) ((double)(c)->ssamp[((l)-C_MINWL)/C_CWLI] / (c)->ssum) +#define C_1SIDEDTHICK 0.005 /* assumed thickness of 1-sided mat. */ + typedef struct { int clock; /* incremented each change -- resettable */ int sided; /* 1 if surface is 1-sided, 0 for 2-sided */ + float nr, ni; /* index of refraction, real and imaginary */ float rd; /* diffuse reflectance */ C_COLOR rd_c; /* diffuse reflectance color */ float td; /* diffuse transmittance */ @@ -247,7 +265,7 @@ typedef struct { FVECT p, n; /* point and normal */ } C_VERTEX; /* vertex context */ -#define C_DEFMATERIAL {1,0,0.,C_DEFCOLOR,0.,C_DEFCOLOR,0.,C_DEFCOLOR,\ +#define C_DEFMATERIAL {1,0,1.,0.,0.,C_DEFCOLOR,0.,C_DEFCOLOR,0.,C_DEFCOLOR,\ 0.,C_DEFCOLOR,0.,0.,C_DEFCOLOR,0.} #define C_DEFVERTEX {1,{0.,0.,0.},{0.,0.,0.}} @@ -335,17 +353,21 @@ struct xf_array { typedef struct xf_spec { long xid; /* unique transform id */ - short xav0; /* zeroeth argument in xf_argv array */ - short xac; /* transform argument count */ + short xac; /* context argument count */ short rev; /* boolean true if vertices reversed */ XF xf; /* cumulative transformation */ struct xf_array *xarr; /* transformation array pointer */ struct xf_spec *prev; /* previous transformation context */ } XF_SPEC; /* followed by argument buffer */ -extern int xf_argc; /* total # transform args. */ -extern char **xf_argv; /* transform arguments */ -extern XF_SPEC *xf_context; /* current context */ +extern XF_SPEC *xf_context; /* current transform context */ +extern char **xf_argend; /* last transform argument */ + +#define xf_ac(xf) ((xf)->xac) +#define xf_av(xf) (xf_argend - (xf)->xac) + +#define xf_argc (xf_context==NULL ? 0 : xf_ac(xf_context)) +#define xf_argv xf_av(xf_context) /* * The transformation handler should do most of the work that needs