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"; |
63 |
|
|
64 |
|
static int e_any_toss(), /* discard unneeded entity */ |
65 |
|
e_ies(), /* IES luminaire file */ |
66 |
– |
e_include(), /* include file */ |
67 |
– |
e_sph(), /* sphere */ |
66 |
|
e_cct(), /* color temperature */ |
67 |
|
e_cmix(), /* color mixtures */ |
68 |
< |
e_cspec(), /* color spectra */ |
71 |
< |
e_cyl(), /* cylinder */ |
72 |
< |
e_cone(), /* cone */ |
73 |
< |
e_prism(), /* prism */ |
74 |
< |
e_ring(), /* ring */ |
75 |
< |
e_torus(); /* torus */ |
68 |
> |
e_cspec(); /* color spectra */ |
69 |
|
|
70 |
|
/* alternate handler support functions */ |
71 |
|
|
116 |
|
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
117 |
|
} else |
118 |
|
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
119 |
+ |
if (mg_ehand[MG_E_FACE] == NULL) |
120 |
+ |
mg_ehand[MG_E_FACE] = mg_ehand[MG_E_FACEH]; |
121 |
+ |
else if (mg_ehand[MG_E_FACEH] == NULL) |
122 |
+ |
mg_ehand[MG_E_FACEH] = e_faceh; |
123 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
124 |
|
if (mg_ehand[MG_E_CMIX] == NULL) { |
125 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
257 |
|
register MG_FCTXT *ctx = mg_file; |
258 |
|
|
259 |
|
mg_file = ctx->prev; /* restore enclosing context */ |
260 |
< |
if (ctx->fp == stdin) |
261 |
< |
return; /* don't close standard input */ |
265 |
< |
fclose(ctx->fp); |
260 |
> |
if (ctx->fp != stdin) /* close file if it's a file */ |
261 |
> |
fclose(ctx->fp); |
262 |
|
} |
263 |
|
|
264 |
|
|
300 |
|
if (fgets(mg_file->inpline+len, |
301 |
|
MG_MAXLINE-len, mg_file->fp) == NULL) |
302 |
|
return(len); |
307 |
– |
mg_file->lineno++; |
303 |
|
len += strlen(mg_file->inpline+len); |
304 |
< |
if (len > 1 && mg_file->inpline[len-2] == '\\') |
305 |
< |
mg_file->inpline[--len-1] = ' '; |
306 |
< |
} while (mg_file->inpline[len]); |
304 |
> |
if (len >= MG_MAXLINE-1) |
305 |
> |
return(len); |
306 |
> |
mg_file->lineno++; |
307 |
> |
} while (len > 1 && mg_file->inpline[len-2] == '\\'); |
308 |
|
|
309 |
|
return(len); |
310 |
|
} |
316 |
|
char abuf[MG_MAXLINE]; |
317 |
|
char *argv[MG_MAXARGC]; |
318 |
|
int en; |
319 |
< |
register char *cp, **ap; |
320 |
< |
|
321 |
< |
strcpy(cp=abuf, mg_file->inpline); |
322 |
< |
ap = argv; /* break into words */ |
319 |
> |
register char *cp, *cp2, **ap; |
320 |
> |
/* copy line, removing escape chars */ |
321 |
> |
cp = abuf; cp2 = mg_file->inpline; |
322 |
> |
while ((*cp++ = *cp2++)) |
323 |
> |
if (cp2[0] == '\n' && cp2[-1] == '\\') |
324 |
> |
cp--; |
325 |
> |
cp = abuf; ap = argv; /* break into words */ |
326 |
|
for ( ; ; ) { |
327 |
|
while (isspace(*cp)) |
328 |
|
*cp++ = '\0'; |
348 |
|
{ |
349 |
|
MG_FCTXT cntxt; |
350 |
|
int rval; |
351 |
+ |
register int nbr; |
352 |
|
|
353 |
|
if ((rval = mg_open(&cntxt, fn)) != MG_OK) { |
354 |
|
fprintf(stderr, "%s: %s\n", fn, mg_err[rval]); |
355 |
|
return(rval); |
356 |
|
} |
357 |
< |
while (mg_read()) /* parse each line */ |
357 |
> |
while ((nbr = mg_read()) > 0) { /* parse each line */ |
358 |
> |
if (nbr >= MG_MAXLINE-1) { |
359 |
> |
fprintf(stderr, "%s: %d: %s\n", cntxt.fname, |
360 |
> |
cntxt.lineno, mg_err[rval=MG_ELINE]); |
361 |
> |
break; |
362 |
> |
} |
363 |
|
if ((rval = mg_parse()) != MG_OK) { |
364 |
|
fprintf(stderr, "%s: %d: %s:\n%s", cntxt.fname, |
365 |
|
cntxt.lineno, mg_err[rval], |
366 |
|
cntxt.inpline); |
367 |
|
break; |
368 |
|
} |
369 |
+ |
} |
370 |
|
mg_close(); |
371 |
|
return(rval); |
372 |
|
} |
388 |
|
mg_clear() /* clear parser history */ |
389 |
|
{ |
390 |
|
c_clearall(); /* clear context tables */ |
391 |
< |
mg_file = NULL; /* reset our context */ |
391 |
> |
while (mg_file != NULL) /* reset our file context */ |
392 |
> |
mg_close(); |
393 |
|
} |
394 |
|
|
395 |
|
|
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
< |
static int |
410 |
> |
int |
411 |
|
e_include(ac, av) /* include file */ |
412 |
|
int ac; |
413 |
|
char **av; |
415 |
|
char *xfarg[MG_MAXARGC]; |
416 |
|
MG_FCTXT ictx; |
417 |
|
XF_SPEC *xf_orig = xf_context; |
418 |
< |
int rv; |
418 |
> |
register int rv; |
419 |
|
|
420 |
|
if (ac < 2) |
421 |
|
return(MG_EARGC); |
428 |
|
for (i = 1; i < ac-1; i++) |
429 |
|
xfarg[i] = av[i+1]; |
430 |
|
xfarg[ac-1] = NULL; |
431 |
< |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
431 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) { |
432 |
> |
mg_close(); |
433 |
|
return(rv); |
434 |
+ |
} |
435 |
|
} |
436 |
|
do { |
437 |
< |
while (mg_read()) |
437 |
> |
while ((rv = mg_read()) > 0) { |
438 |
> |
if (rv >= MG_MAXLINE-1) { |
439 |
> |
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
440 |
> |
ictx.lineno, mg_err[MG_ELINE]); |
441 |
> |
mg_close(); |
442 |
> |
return(MG_EINCL); |
443 |
> |
} |
444 |
|
if ((rv = mg_parse()) != MG_OK) { |
445 |
|
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
446 |
|
ictx.lineno, mg_err[rv], |
448 |
|
mg_close(); |
449 |
|
return(MG_EINCL); |
450 |
|
} |
451 |
+ |
} |
452 |
|
if (ac > 2) |
453 |
< |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
453 |
> |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) { |
454 |
> |
mg_close(); |
455 |
|
return(rv); |
456 |
+ |
} |
457 |
|
} while (xf_context != xf_orig); |
458 |
|
mg_close(); |
459 |
|
return(MG_OK); |
460 |
|
} |
461 |
|
|
462 |
|
|
463 |
+ |
int |
464 |
+ |
e_faceh(ac, av) /* replace face+holes with single contour */ |
465 |
+ |
int ac; |
466 |
+ |
char **av; |
467 |
+ |
{ |
468 |
+ |
char *newav[MG_MAXARGC]; |
469 |
+ |
int lastp = 0; |
470 |
+ |
register int i, j; |
471 |
+ |
|
472 |
+ |
newav[0] = mg_ename[MG_E_FACE]; |
473 |
+ |
for (i = 1; i < ac; i++) |
474 |
+ |
if (av[i][0] == '-') { |
475 |
+ |
if (i < 4) |
476 |
+ |
return(MG_EARGC); |
477 |
+ |
if (i >= ac-1) |
478 |
+ |
break; |
479 |
+ |
if (!lastp) |
480 |
+ |
lastp = i-1; |
481 |
+ |
for (j = i+1; j < ac-1 && av[j+1][0] != '-'; j++) |
482 |
+ |
; |
483 |
+ |
if (j - i < 3) |
484 |
+ |
return(MG_EARGC); |
485 |
+ |
newav[i] = av[j]; /* connect hole loop */ |
486 |
+ |
} else |
487 |
+ |
newav[i] = av[i]; /* hole or perimeter vertex */ |
488 |
+ |
if (lastp) |
489 |
+ |
newav[i++] = av[lastp]; /* finish seam to outside */ |
490 |
+ |
newav[i] = NULL; |
491 |
+ |
return(mg_handle(MG_E_FACE, i, newav)); |
492 |
+ |
} |
493 |
+ |
|
494 |
+ |
|
495 |
|
static void |
496 |
|
make_axes(u, v, w) /* compute u and v given w (normalized) */ |
497 |
|
FVECT u, v, w; |
509 |
|
} |
510 |
|
|
511 |
|
|
512 |
< |
static int |
512 |
> |
int |
513 |
|
e_sph(ac, av) /* expand a sphere into cones */ |
514 |
|
int ac; |
515 |
|
char **av; |
561 |
|
} |
562 |
|
|
563 |
|
|
564 |
< |
static int |
564 |
> |
int |
565 |
|
e_torus(ac, av) /* expand a torus into cones */ |
566 |
|
int ac; |
567 |
|
char **av; |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
< |
static int |
656 |
> |
int |
657 |
|
e_cyl(ac, av) /* replace a cylinder with equivalent cone */ |
658 |
|
int ac; |
659 |
|
char **av; |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
< |
static int |
673 |
> |
int |
674 |
|
e_ring(ac, av) /* turn a ring into polygons */ |
675 |
|
int ac; |
676 |
|
char **av; |
768 |
|
} |
769 |
|
|
770 |
|
|
771 |
< |
static int |
771 |
> |
int |
772 |
|
e_cone(ac, av) /* turn a cone into polygons */ |
773 |
|
int ac; |
774 |
|
char **av; |
938 |
|
} |
939 |
|
|
940 |
|
|
941 |
< |
static int |
941 |
> |
int |
942 |
|
e_prism(ac, av) /* turn a prism into polygons */ |
943 |
|
int ac; |
944 |
|
char **av; |
1050 |
|
{ |
1051 |
|
static char xbuf[24], ybuf[24]; |
1052 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
1003 |
– |
int rv; |
1053 |
|
|
1054 |
|
sprintf(xbuf, "%.4f", c_ccolor->cx); |
1055 |
|
sprintf(ybuf, "%.4f", c_ccolor->cy); |
1056 |
< |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
1008 |
< |
return(rv); |
1009 |
< |
return(MG_OK); |
1056 |
> |
return(mg_handle(MG_E_CXY, 3, ccom)); |
1057 |
|
} |
1058 |
|
|
1059 |
|
|