ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/wfconv.c
(Generate patch)

Comparing ray/src/ot/wfconv.c (file contents):
Revision 2.6 by schorsch, Sun Jul 27 22:12:03 2003 UTC vs.
Revision 2.9 by greg, Fri Apr 23 16:20:56 2004 UTC

# Line 15 | Line 15 | typedef int    VNDX[3];        /* vertex index (point,map,normal
15  
16   #define CHUNKSIZ        1024    /* vertex allocation chunk size */
17  
18 < #define MAXARG          64      /* maximum # arguments in a statement */
18 > #define MAXARG          512     /* maximum # arguments in a statement */
19  
20   static FVECT    *vlist;         /* our vertex list */
21   static int      nvs;            /* number of vertices in our list */
# Line 31 | Line 31 | static char    group[64];      /* current group name */
31   static int      lineno;         /* current line number */
32   static int      faceno;         /* current face number */
33  
34 < static int      getstmt();
35 < static int      cvtndx();
36 < static OBJECT   getmod();
37 < static int      putface();
38 < static int      puttri();
39 < static void     freeverts();
40 < static int      newv();
41 < static int      newvn();
42 < static int      newvt();
43 < static void     syntax();
34 > static int getstmt(char *av[MAXARG], FILE       *fp);
35 > static int cvtndx(VNDX  vi, char        *vs);
36 > static int putface(int  ac, char        **av);
37 > static OBJECT getmod(void);
38 > static int puttri(char  *v1, char       *v2, char       *v3);
39 > static void freeverts(void);
40 > static int newv(double  x, double       y, double       z);
41 > static int newvn(double x, double       y, double       z);
42 > static int newvt(double x, double       y);
43 > static void syntax(char *er);
44  
45  
46   void
47 < wfreadobj(objfn)                /* read in .OBJ file and convert */
48 < char    *objfn;
47 > wfreadobj(              /* read in .OBJ file and convert */
48 >        char    *objfn
49 > )
50   {
51          FILE    *fp;
52          char    *argv[MAXARG];
53          int     argc;
54          int     nstats, nunknown;
54        int     i;
55  
56          if (objfn == NULL) {
57                  inpfile = "<stdin>";
# Line 157 | Line 157 | char   *objfn;
157  
158  
159   static int
160 < getstmt(av, fp)                         /* read the next statement from fp */
161 < register char   *av[MAXARG];
162 < FILE    *fp;
160 > getstmt(                                /* read the next statement from fp */
161 >        register char   *av[MAXARG],
162 >        FILE    *fp
163 > )
164   {
165          static char     sbuf[MAXARG*16];
166          register char   *cp;
# Line 175 | Line 176 | FILE   *fp;
176                                          lineno++;
177                                  *cp++ = '\0';
178                          }
179 <                        if (!*cp || i >= MAXARG-1)
179 >                        if (!*cp)
180                                  break;
181 +                        if (i >= MAXARG-1) {
182 +                                sprintf(errmsg,
183 +                        "%s: too many arguments near line %d (limit %d)\n",
184 +                                        inpfile, lineno+1, MAXARG-1);
185 +                                break;
186 +                        }
187                          av[i++] = cp;
188                          while (*++cp && !isspace(*cp))
189                                  ;
# Line 190 | Line 197 | FILE   *fp;
197  
198  
199   static int
200 < cvtndx(vi, vs)                          /* convert vertex string to index */
201 < register VNDX   vi;
202 < register char   *vs;
200 > cvtndx(                         /* convert vertex string to index */
201 >        register VNDX   vi,
202 >        register char   *vs
203 > )
204   {
205                                          /* get point */
206          vi[0] = atoi(vs);
# Line 238 | Line 246 | register char  *vs;
246  
247  
248   static int
249 < putface(ac, av)                         /* put out an N-sided polygon */
250 < int     ac;
251 < register char   **av;
249 > putface(                                /* put out an N-sided polygon */
250 >        int     ac,
251 >        register char   **av
252 > )
253   {
254          char            *cp;
255          register int    i;
# Line 259 | Line 268 | register char  **av;
268  
269  
270   static OBJECT
271 < getmod()                                /* get current modifier ID */
271 > getmod(void)                            /* get current modifier ID */
272   {
273          char    *mnam;
274          OBJECT  mod;
# Line 285 | Line 294 | getmod()                               /* get current modifier ID */
294  
295  
296   static int
297 < puttri(v1, v2, v3)                      /* convert a triangle */
298 < char    *v1, *v2, *v3;
297 > puttri(                 /* convert a triangle */
298 >        char    *v1,
299 >        char    *v2,
300 >        char    *v3
301 > )
302   {
303          VNDX    v1i, v2i, v3i;
304          RREAL   *v1c, *v2c, *v3c;
305          RREAL   *v1n, *v2n, *v3n;
306          
307 <        if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3))
307 >        if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) {
308 >                error(WARNING, "bad vertex reference");
309                  return(0);
310 <
310 >        }
311          if (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0) {
312                  v1c = vtlist[v1i[1]];
313                  v2c = vtlist[v2i[1]];
# Line 315 | Line 328 | char   *v1, *v2, *v3;
328  
329  
330   static void
331 < freeverts()                     /* free all vertices */
331 > freeverts(void)                 /* free all vertices */
332   {
333          if (nvs) {
334                  free((void *)vlist);
# Line 333 | Line 346 | freeverts()                    /* free all vertices */
346  
347  
348   static int
349 < newv(x, y, z)                   /* create a new vertex */
350 < double  x, y, z;
349 > newv(                   /* create a new vertex */
350 >        double  x,
351 >        double  y,
352 >        double  z
353 > )
354   {
355          if (!(nvs%CHUNKSIZ)) {          /* allocate next block */
356                  if (nvs == 0)
# Line 354 | Line 370 | double x, y, z;
370  
371  
372   static int
373 < newvn(x, y, z)                  /* create a new vertex normal */
374 < double  x, y, z;
373 > newvn(                  /* create a new vertex normal */
374 >        double  x,
375 >        double  y,
376 >        double  z
377 > )
378   {
379          if (!(nvns%CHUNKSIZ)) {         /* allocate next block */
380                  if (nvns == 0)
# Line 377 | Line 396 | double x, y, z;
396  
397  
398   static int
399 < newvt(x, y)                     /* create a new texture map vertex */
400 < double  x, y;
399 > newvt(                  /* create a new texture map vertex */
400 >        double  x,
401 >        double  y
402 > )
403   {
404          if (!(nvts%CHUNKSIZ)) {         /* allocate next block */
405                  if (nvts == 0)
# Line 397 | Line 418 | double x, y;
418  
419  
420   static void
421 < syntax(er)                      /* report syntax error and exit */
422 < char    *er;
421 > syntax(                 /* report syntax error and exit */
422 >        char    *er
423 > )
424   {
425          sprintf(errmsg, "%s: Wavefront syntax error near line %d: %s\n",
426                          inpfile, lineno, er);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines