--- ray/src/ot/wfconv.c 2003/04/23 00:52:34 2.4 +++ ray/src/ot/wfconv.c 2004/04/23 16:20:56 2.9 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: wfconv.c,v 2.4 2003/04/23 00:52:34 greg Exp $"; +static const char RCSid[] = "$Id: wfconv.c,v 2.9 2004/04/23 16:20:56 greg Exp $"; #endif /* * Load Wavefront .OBJ file and convert to triangles with mesh info. @@ -15,13 +15,13 @@ typedef int VNDX[3]; /* vertex index (point,map,normal #define CHUNKSIZ 1024 /* vertex allocation chunk size */ -#define MAXARG 64 /* maximum # arguments in a statement */ +#define MAXARG 512 /* maximum # arguments in a statement */ static FVECT *vlist; /* our vertex list */ static int nvs; /* number of vertices in our list */ static FVECT *vnlist; /* vertex normal list */ static int nvns; -static FLOAT (*vtlist)[2]; /* map vertex list */ +static RREAL (*vtlist)[2]; /* map vertex list */ static int nvts; static char *inpfile; /* input file name */ @@ -31,27 +31,27 @@ static char group[64]; /* current group name */ static int lineno; /* current line number */ static int faceno; /* current face number */ -static int getstmt(); -static int cvtndx(); -static OBJECT getmod(); -static int putface(); -static int puttri(); -static void freeverts(); -static int newv(); -static int newvn(); -static int newvt(); -static void syntax(); +static int getstmt(char *av[MAXARG], FILE *fp); +static int cvtndx(VNDX vi, char *vs); +static int putface(int ac, char **av); +static OBJECT getmod(void); +static int puttri(char *v1, char *v2, char *v3); +static void freeverts(void); +static int newv(double x, double y, double z); +static int newvn(double x, double y, double z); +static int newvt(double x, double y); +static void syntax(char *er); void -wfreadobj(objfn) /* read in .OBJ file and convert */ -char *objfn; +wfreadobj( /* read in .OBJ file and convert */ + char *objfn +) { FILE *fp; char *argv[MAXARG]; int argc; int nstats, nunknown; - int i; if (objfn == NULL) { inpfile = ""; @@ -66,7 +66,7 @@ char *objfn; group[0] = '\0'; lineno = 0; faceno = 0; /* scan until EOF */ - while (argc = getstmt(argv, fp)) { + while ( (argc = getstmt(argv, fp)) ) { switch (argv[0][0]) { case 'v': /* vertex */ switch (argv[0][1]) { @@ -157,9 +157,10 @@ char *objfn; static int -getstmt(av, fp) /* read the next statement from fp */ -register char *av[MAXARG]; -FILE *fp; +getstmt( /* read the next statement from fp */ + register char *av[MAXARG], + FILE *fp +) { static char sbuf[MAXARG*16]; register char *cp; @@ -175,8 +176,14 @@ FILE *fp; lineno++; *cp++ = '\0'; } - if (!*cp || i >= MAXARG-1) + if (!*cp) break; + if (i >= MAXARG-1) { + sprintf(errmsg, + "%s: too many arguments near line %d (limit %d)\n", + inpfile, lineno+1, MAXARG-1); + break; + } av[i++] = cp; while (*++cp && !isspace(*cp)) ; @@ -190,9 +197,10 @@ FILE *fp; static int -cvtndx(vi, vs) /* convert vertex string to index */ -register VNDX vi; -register char *vs; +cvtndx( /* convert vertex string to index */ + register VNDX vi, + register char *vs +) { /* get point */ vi[0] = atoi(vs); @@ -238,9 +246,10 @@ register char *vs; static int -putface(ac, av) /* put out an N-sided polygon */ -int ac; -register char **av; +putface( /* put out an N-sided polygon */ + int ac, + register char **av +) { char *cp; register int i; @@ -259,7 +268,7 @@ register char **av; static OBJECT -getmod() /* get current modifier ID */ +getmod(void) /* get current modifier ID */ { char *mnam; OBJECT mod; @@ -285,16 +294,20 @@ getmod() /* get current modifier ID */ static int -puttri(v1, v2, v3) /* convert a triangle */ -char *v1, *v2, *v3; +puttri( /* convert a triangle */ + char *v1, + char *v2, + char *v3 +) { VNDX v1i, v2i, v3i; - FLOAT *v1c, *v2c, *v3c; - FLOAT *v1n, *v2n, *v3n; + RREAL *v1c, *v2c, *v3c; + RREAL *v1n, *v2n, *v3n; - if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) + if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) { + error(WARNING, "bad vertex reference"); return(0); - + } if (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0) { v1c = vtlist[v1i[1]]; v2c = vtlist[v2i[1]]; @@ -315,7 +328,7 @@ char *v1, *v2, *v3; static void -freeverts() /* free all vertices */ +freeverts(void) /* free all vertices */ { if (nvs) { free((void *)vlist); @@ -333,8 +346,11 @@ freeverts() /* free all vertices */ static int -newv(x, y, z) /* create a new vertex */ -double x, y, z; +newv( /* create a new vertex */ + double x, + double y, + double z +) { if (!(nvs%CHUNKSIZ)) { /* allocate next block */ if (nvs == 0) @@ -354,8 +370,11 @@ double x, y, z; static int -newvn(x, y, z) /* create a new vertex normal */ -double x, y, z; +newvn( /* create a new vertex normal */ + double x, + double y, + double z +) { if (!(nvns%CHUNKSIZ)) { /* allocate next block */ if (nvns == 0) @@ -377,15 +396,17 @@ double x, y, z; static int -newvt(x, y) /* create a new texture map vertex */ -double x, y; +newvt( /* create a new texture map vertex */ + double x, + double y +) { if (!(nvts%CHUNKSIZ)) { /* allocate next block */ if (nvts == 0) - vtlist = (FLOAT (*)[2])malloc(CHUNKSIZ*2*sizeof(FLOAT)); + vtlist = (RREAL (*)[2])malloc(CHUNKSIZ*2*sizeof(RREAL)); else - vtlist = (FLOAT (*)[2])realloc((void *)vtlist, - (nvts+CHUNKSIZ)*2*sizeof(FLOAT)); + vtlist = (RREAL (*)[2])realloc((void *)vtlist, + (nvts+CHUNKSIZ)*2*sizeof(RREAL)); if (vtlist == NULL) error(SYSTEM, "out of memory in newvt"); } @@ -397,8 +418,9 @@ double x, y; static void -syntax(er) /* report syntax error and exit */ -char *er; +syntax( /* report syntax error and exit */ + char *er +) { sprintf(errmsg, "%s: Wavefront syntax error near line %d: %s\n", inpfile, lineno, er);