1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
#include <math.h> |
13 |
+ |
#include <stdlib.h> |
14 |
|
#include <ctype.h> |
15 |
|
#include <string.h> |
16 |
|
#include "parser.h" |
64 |
|
|
65 |
|
static int e_any_toss(), /* discard unneeded entity */ |
66 |
|
e_ies(), /* IES luminaire file */ |
66 |
– |
e_include(), /* include file */ |
67 |
– |
e_sph(), /* sphere */ |
67 |
|
e_cct(), /* color temperature */ |
68 |
|
e_cmix(), /* color mixtures */ |
69 |
< |
e_cspec(), /* color spectra */ |
71 |
< |
e_cyl(), /* cylinder */ |
72 |
< |
e_cone(), /* cone */ |
73 |
< |
e_prism(), /* prism */ |
74 |
< |
e_ring(), /* ring */ |
75 |
< |
e_torus(); /* torus */ |
69 |
> |
e_cspec(); /* color spectra */ |
70 |
|
|
71 |
|
/* alternate handler support functions */ |
72 |
|
|
117 |
|
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
118 |
|
} else |
119 |
|
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
120 |
+ |
if (mg_ehand[MG_E_FACE] == NULL) |
121 |
+ |
mg_ehand[MG_E_FACE] = mg_ehand[MG_E_FACEH]; |
122 |
+ |
else if (mg_ehand[MG_E_FACEH] == NULL) |
123 |
+ |
mg_ehand[MG_E_FACEH] = e_faceh; |
124 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
125 |
|
if (mg_ehand[MG_E_CMIX] == NULL) { |
126 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
258 |
|
register MG_FCTXT *ctx = mg_file; |
259 |
|
|
260 |
|
mg_file = ctx->prev; /* restore enclosing context */ |
261 |
< |
if (ctx->fp == stdin) |
262 |
< |
return; /* don't close standard input */ |
265 |
< |
fclose(ctx->fp); |
261 |
> |
if (ctx->fp != stdin) /* close file if it's a file */ |
262 |
> |
fclose(ctx->fp); |
263 |
|
} |
264 |
|
|
265 |
|
|
267 |
|
mg_fgetpos(pos) /* get current position in input file */ |
268 |
|
register MG_FPOS *pos; |
269 |
|
{ |
273 |
– |
extern long ftell(); |
274 |
– |
|
270 |
|
pos->fid = mg_file->fid; |
271 |
|
pos->lineno = mg_file->lineno; |
272 |
|
pos->offset = ftell(mg_file->fp); |
299 |
|
if (fgets(mg_file->inpline+len, |
300 |
|
MG_MAXLINE-len, mg_file->fp) == NULL) |
301 |
|
return(len); |
307 |
– |
mg_file->lineno++; |
302 |
|
len += strlen(mg_file->inpline+len); |
303 |
< |
if (len > 1 && mg_file->inpline[len-2] == '\\') |
304 |
< |
mg_file->inpline[--len-1] = ' '; |
305 |
< |
} while (mg_file->inpline[len]); |
303 |
> |
if (len >= MG_MAXLINE-1) |
304 |
> |
return(len); |
305 |
> |
mg_file->lineno++; |
306 |
> |
} while (len > 1 && mg_file->inpline[len-2] == '\\'); |
307 |
|
|
308 |
|
return(len); |
309 |
|
} |
314 |
|
{ |
315 |
|
char abuf[MG_MAXLINE]; |
316 |
|
char *argv[MG_MAXARGC]; |
317 |
< |
int en; |
318 |
< |
register char *cp, **ap; |
319 |
< |
|
320 |
< |
strcpy(cp=abuf, mg_file->inpline); |
321 |
< |
ap = argv; /* break into words */ |
317 |
> |
register char *cp, *cp2, **ap; |
318 |
> |
/* copy line, removing escape chars */ |
319 |
> |
cp = abuf; cp2 = mg_file->inpline; |
320 |
> |
while ((*cp++ = *cp2++)) |
321 |
> |
if (cp2[0] == '\n' && cp2[-1] == '\\') |
322 |
> |
cp--; |
323 |
> |
cp = abuf; ap = argv; /* break into words */ |
324 |
|
for ( ; ; ) { |
325 |
|
while (isspace(*cp)) |
326 |
|
*cp++ = '\0'; |
353 |
|
return(rval); |
354 |
|
} |
355 |
|
while ((nbr = mg_read()) > 0) { /* parse each line */ |
356 |
< |
if (nbr >= MG_MAXLINE-1 && cntxt.inpline[nbr-1] != '\n') { |
356 |
> |
if (nbr >= MG_MAXLINE-1) { |
357 |
|
fprintf(stderr, "%s: %d: %s\n", cntxt.fname, |
358 |
|
cntxt.lineno, mg_err[rval=MG_ELINE]); |
359 |
|
break; |
386 |
|
mg_clear() /* clear parser history */ |
387 |
|
{ |
388 |
|
c_clearall(); /* clear context tables */ |
389 |
< |
mg_file = NULL; /* reset our context */ |
389 |
> |
while (mg_file != NULL) /* reset our file context */ |
390 |
> |
mg_close(); |
391 |
|
} |
392 |
|
|
393 |
|
|
405 |
|
} |
406 |
|
|
407 |
|
|
408 |
< |
static int |
408 |
> |
int |
409 |
|
e_include(ac, av) /* include file */ |
410 |
|
int ac; |
411 |
|
char **av; |
433 |
|
} |
434 |
|
do { |
435 |
|
while ((rv = mg_read()) > 0) { |
436 |
< |
if (rv >= MG_MAXLINE-1 && ictx.inpline[rv-1] != '\n') { |
436 |
> |
if (rv >= MG_MAXLINE-1) { |
437 |
|
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
438 |
|
ictx.lineno, mg_err[MG_ELINE]); |
439 |
|
mg_close(); |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
+ |
int |
462 |
+ |
e_faceh(ac, av) /* replace face+holes with single contour */ |
463 |
+ |
int ac; |
464 |
+ |
char **av; |
465 |
+ |
{ |
466 |
+ |
char *newav[MG_MAXARGC]; |
467 |
+ |
int lastp = 0; |
468 |
+ |
register int i, j; |
469 |
+ |
|
470 |
+ |
newav[0] = mg_ename[MG_E_FACE]; |
471 |
+ |
for (i = 1; i < ac; i++) |
472 |
+ |
if (av[i][0] == '-') { |
473 |
+ |
if (i < 4) |
474 |
+ |
return(MG_EARGC); |
475 |
+ |
if (i >= ac-1) |
476 |
+ |
break; |
477 |
+ |
if (!lastp) |
478 |
+ |
lastp = i-1; |
479 |
+ |
for (j = i+1; j < ac-1 && av[j+1][0] != '-'; j++) |
480 |
+ |
; |
481 |
+ |
if (j - i < 3) |
482 |
+ |
return(MG_EARGC); |
483 |
+ |
newav[i] = av[j]; /* connect hole loop */ |
484 |
+ |
} else |
485 |
+ |
newav[i] = av[i]; /* hole or perimeter vertex */ |
486 |
+ |
if (lastp) |
487 |
+ |
newav[i++] = av[lastp]; /* finish seam to outside */ |
488 |
+ |
newav[i] = NULL; |
489 |
+ |
return(mg_handle(MG_E_FACE, i, newav)); |
490 |
+ |
} |
491 |
+ |
|
492 |
+ |
|
493 |
|
static void |
494 |
|
make_axes(u, v, w) /* compute u and v given w (normalized) */ |
495 |
|
FVECT u, v, w; |
507 |
|
} |
508 |
|
|
509 |
|
|
510 |
< |
static int |
510 |
> |
int |
511 |
|
e_sph(ac, av) /* expand a sphere into cones */ |
512 |
|
int ac; |
513 |
|
char **av; |
559 |
|
} |
560 |
|
|
561 |
|
|
562 |
< |
static int |
562 |
> |
int |
563 |
|
e_torus(ac, av) /* expand a torus into cones */ |
564 |
|
int ac; |
565 |
|
char **av; |
651 |
|
} |
652 |
|
|
653 |
|
|
654 |
< |
static int |
654 |
> |
int |
655 |
|
e_cyl(ac, av) /* replace a cylinder with equivalent cone */ |
656 |
|
int ac; |
657 |
|
char **av; |
668 |
|
} |
669 |
|
|
670 |
|
|
671 |
< |
static int |
671 |
> |
int |
672 |
|
e_ring(ac, av) /* turn a ring into polygons */ |
673 |
|
int ac; |
674 |
|
char **av; |
766 |
|
} |
767 |
|
|
768 |
|
|
769 |
< |
static int |
769 |
> |
int |
770 |
|
e_cone(ac, av) /* turn a cone into polygons */ |
771 |
|
int ac; |
772 |
|
char **av; |
808 |
|
if (rad2 == 0.) |
809 |
|
return(MG_EILL); |
810 |
|
} else if (rad2 != 0.) { |
811 |
< |
if (rad1 < 0. ^ rad2 < 0.) |
811 |
> |
if ((rad1 < 0.) ^ (rad2 < 0.)) |
812 |
|
return(MG_EILL); |
813 |
|
} else { /* swap */ |
814 |
|
C_VERTEX *cv; |
936 |
|
} |
937 |
|
|
938 |
|
|
939 |
< |
static int |
939 |
> |
int |
940 |
|
e_prism(ac, av) /* turn a prism into polygons */ |
941 |
|
int ac; |
942 |
|
char **av; |
1048 |
|
{ |
1049 |
|
static char xbuf[24], ybuf[24]; |
1050 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
1021 |
– |
int rv; |
1051 |
|
|
1052 |
|
sprintf(xbuf, "%.4f", c_ccolor->cx); |
1053 |
|
sprintf(ybuf, "%.4f", c_ccolor->cy); |
1054 |
< |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
1026 |
< |
return(rv); |
1027 |
< |
return(MG_OK); |
1054 |
> |
return(mg_handle(MG_E_CXY, 3, ccom)); |
1055 |
|
} |
1056 |
|
|
1057 |
|
|