| 1 |
< |
/* Copyright (c) 1994 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"; |
| 27 |
|
|
| 28 |
|
int (*mg_ehand[MG_NENTITIES])(); |
| 29 |
|
|
| 30 |
+ |
/* Handler routine for unknown entities */ |
| 31 |
+ |
|
| 32 |
+ |
int (*mg_uhand)() = mg_defuhand; |
| 33 |
+ |
|
| 34 |
+ |
unsigned mg_nunknown; /* count of unknown entities */ |
| 35 |
+ |
|
| 36 |
|
/* error messages */ |
| 37 |
|
|
| 38 |
|
char *mg_err[MG_NERRS] = MG_ERRLIST; |
| 63 |
|
|
| 64 |
|
static int e_any_toss(), /* discard unneeded entity */ |
| 65 |
|
e_ies(), /* IES luminaire file */ |
| 66 |
< |
e_include(), /* include file */ |
| 61 |
< |
e_sph(), /* sphere */ |
| 66 |
> |
e_cct(), /* color temperature */ |
| 67 |
|
e_cmix(), /* color mixtures */ |
| 68 |
< |
e_cspec(), /* color spectra */ |
| 68 |
> |
e_cspec(); /* color spectra */ |
| 69 |
> |
|
| 70 |
> |
int e_include(), /* include file */ |
| 71 |
> |
e_sph(), /* sphere */ |
| 72 |
|
e_cyl(), /* cylinder */ |
| 73 |
|
e_cone(), /* cone */ |
| 74 |
|
e_prism(), /* prism */ |
| 96 |
|
mg_ehand[MG_E_INCLUDE] = e_include; |
| 97 |
|
if (mg_ehand[MG_E_SPH] == NULL) { |
| 98 |
|
mg_ehand[MG_E_SPH] = e_sph; |
| 99 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
| 99 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
| 100 |
|
} else |
| 101 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
| 101 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
| 102 |
|
if (mg_ehand[MG_E_CYL] == NULL) { |
| 103 |
|
mg_ehand[MG_E_CYL] = e_cyl; |
| 104 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
| 104 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
| 105 |
|
} else |
| 106 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
| 106 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
| 107 |
|
if (mg_ehand[MG_E_CONE] == NULL) { |
| 108 |
|
mg_ehand[MG_E_CONE] = e_cone; |
| 109 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
| 109 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
| 110 |
|
} else |
| 111 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
| 111 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
| 112 |
|
if (mg_ehand[MG_E_RING] == NULL) { |
| 113 |
|
mg_ehand[MG_E_RING] = e_ring; |
| 114 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
| 114 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
| 115 |
|
} else |
| 116 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
| 116 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
| 117 |
|
if (mg_ehand[MG_E_PRISM] == NULL) { |
| 118 |
|
mg_ehand[MG_E_PRISM] = e_prism; |
| 119 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
| 119 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
| 120 |
|
} else |
| 121 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
| 121 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
| 122 |
|
if (mg_ehand[MG_E_TORUS] == NULL) { |
| 123 |
|
mg_ehand[MG_E_TORUS] = e_torus; |
| 124 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
| 124 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
| 125 |
|
} else |
| 126 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
| 126 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
| 127 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
| 128 |
|
if (mg_ehand[MG_E_CMIX] == NULL) { |
| 129 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
| 130 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
| 130 |
> |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
| 131 |
|
} |
| 132 |
|
if (mg_ehand[MG_E_CSPEC] == NULL) { |
| 133 |
|
mg_ehand[MG_E_CSPEC] = e_cspec; |
| 134 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
| 134 |
> |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
| 135 |
|
} |
| 136 |
+ |
if (mg_ehand[MG_E_CCT] == NULL) { |
| 137 |
+ |
mg_ehand[MG_E_CCT] = e_cct; |
| 138 |
+ |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
| 139 |
+ |
} |
| 140 |
|
} |
| 141 |
|
/* check for consistency */ |
| 142 |
|
if (mg_ehand[MG_E_FACE] != NULL) |
| 143 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
| 143 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
| 144 |
|
if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL || |
| 145 |
|
mg_ehand[MG_E_CMIX] != NULL) |
| 146 |
< |
uneed |= 1<<MG_E_COLOR; |
| 146 |
> |
uneed |= 1L<<MG_E_COLOR; |
| 147 |
|
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
| 148 |
+ |
mg_ehand[MG_E_IR] != NULL || |
| 149 |
|
mg_ehand[MG_E_ED] != NULL || |
| 150 |
|
mg_ehand[MG_E_RS] != NULL || |
| 151 |
< |
mg_ehand[MG_E_TS] != NULL) |
| 152 |
< |
uneed |= 1<<MG_E_MATERIAL; |
| 151 |
> |
mg_ehand[MG_E_TS] != NULL || |
| 152 |
> |
mg_ehand[MG_E_SIDES] != NULL) |
| 153 |
> |
uneed |= 1L<<MG_E_MATERIAL; |
| 154 |
|
for (i = 0; i < MG_NENTITIES; i++) |
| 155 |
< |
if (uneed & 1<<i && mg_ehand[i] == NULL) { |
| 155 |
> |
if (uneed & 1L<<i && mg_ehand[i] == NULL) { |
| 156 |
|
fprintf(stderr, "Missing support for \"%s\" entity\n", |
| 157 |
|
mg_ename[i]); |
| 158 |
|
exit(1); |
| 159 |
|
} |
| 160 |
|
/* add support as needed */ |
| 161 |
< |
if (ineed & 1<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
| 161 |
> |
if (ineed & 1L<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
| 162 |
|
e_supp[MG_E_VERTEX] = c_hvertex; |
| 163 |
< |
if (ineed & 1<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
| 163 |
> |
if (ineed & 1L<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
| 164 |
|
e_supp[MG_E_POINT] = c_hvertex; |
| 165 |
< |
if (ineed & 1<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
| 165 |
> |
if (ineed & 1L<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
| 166 |
|
e_supp[MG_E_NORMAL] = c_hvertex; |
| 167 |
< |
if (ineed & 1<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
| 167 |
> |
if (ineed & 1L<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
| 168 |
|
e_supp[MG_E_COLOR] = c_hcolor; |
| 169 |
< |
if (ineed & 1<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
| 169 |
> |
if (ineed & 1L<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
| 170 |
|
e_supp[MG_E_CXY] = c_hcolor; |
| 171 |
< |
if (ineed & 1<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
| 171 |
> |
if (ineed & 1L<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
| 172 |
|
e_supp[MG_E_CSPEC] = c_hcolor; |
| 173 |
< |
if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
| 173 |
> |
if (ineed & 1L<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
| 174 |
|
e_supp[MG_E_CMIX] = c_hcolor; |
| 175 |
+ |
if (ineed & 1L<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
| 176 |
+ |
e_supp[MG_E_CCT] = c_hcolor; |
| 177 |
|
/* discard remaining entities */ |
| 178 |
|
for (i = 0; i < MG_NENTITIES; i++) |
| 179 |
|
if (mg_ehand[i] == NULL) |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
|
| 168 |
– |
|
| 184 |
|
int |
| 185 |
|
mg_entity(name) /* get entity number from its name */ |
| 186 |
|
char *name; |
| 210 |
|
{ |
| 211 |
|
int rv; |
| 212 |
|
|
| 213 |
< |
if (en < 0 && (en = mg_entity(av[0])) < 0) |
| 213 |
> |
if (en < 0 && (en = mg_entity(av[0])) < 0) { /* unknown entity */ |
| 214 |
> |
if (mg_uhand != NULL) |
| 215 |
> |
return((*mg_uhand)(ac, av)); |
| 216 |
|
return(MG_EUNK); |
| 217 |
< |
if (e_supp[en] != NULL) { |
| 217 |
> |
} |
| 218 |
> |
if (e_supp[en] != NULL) { /* support handler */ |
| 219 |
|
if ((rv = (*e_supp[en])(ac, av)) != MG_OK) |
| 220 |
|
return(rv); |
| 221 |
|
} |
| 222 |
< |
return((*mg_ehand[en])(ac, av)); |
| 222 |
> |
return((*mg_ehand[en])(ac, av)); /* assigned handler */ |
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
|
| 229 |
|
char *fn; |
| 230 |
|
{ |
| 231 |
|
static int nfids; |
| 214 |
– |
int olen; |
| 232 |
|
register char *cp; |
| 233 |
|
|
| 234 |
|
ctx->fid = ++nfids; |
| 241 |
|
return(MG_OK); |
| 242 |
|
} |
| 243 |
|
/* get name relative to this context */ |
| 244 |
< |
if (mg_file != NULL && |
| 228 |
< |
(cp = strrchr(mg_file->fname, '/')) != NULL) |
| 229 |
< |
olen = cp - mg_file->fname + 1; |
| 230 |
< |
else |
| 231 |
< |
olen = 0; |
| 232 |
< |
if (olen) |
| 244 |
> |
if (mg_file != NULL && (cp = strrchr(mg_file->fname, '/')) != NULL) { |
| 245 |
|
strcpy(ctx->fname, mg_file->fname); |
| 246 |
< |
strcpy(ctx->fname+olen, fn); |
| 246 |
> |
strcpy(ctx->fname+(cp-mg_file->fname+1), fn); |
| 247 |
> |
} else |
| 248 |
> |
strcpy(ctx->fname, fn); |
| 249 |
|
ctx->fp = fopen(ctx->fname, "r"); |
| 250 |
|
if (ctx->fp == NULL) |
| 251 |
|
return(MG_ENOFILE); |
| 261 |
|
register MG_FCTXT *ctx = mg_file; |
| 262 |
|
|
| 263 |
|
mg_file = ctx->prev; /* restore enclosing context */ |
| 264 |
< |
if (ctx->fp == stdin) |
| 265 |
< |
return; /* don't close standard input */ |
| 252 |
< |
fclose(ctx->fp); |
| 264 |
> |
if (ctx->fp != stdin) /* close file if it's a file */ |
| 265 |
> |
fclose(ctx->fp); |
| 266 |
|
} |
| 267 |
|
|
| 268 |
|
|
| 304 |
|
if (fgets(mg_file->inpline+len, |
| 305 |
|
MG_MAXLINE-len, mg_file->fp) == NULL) |
| 306 |
|
return(len); |
| 294 |
– |
mg_file->lineno++; |
| 307 |
|
len += strlen(mg_file->inpline+len); |
| 308 |
< |
if (len > 1 && mg_file->inpline[len-2] == '\\') |
| 309 |
< |
mg_file->inpline[--len-1] = ' '; |
| 310 |
< |
} while (mg_file->inpline[len]); |
| 308 |
> |
if (len >= MG_MAXLINE-1) |
| 309 |
> |
return(len); |
| 310 |
> |
mg_file->lineno++; |
| 311 |
> |
} while (len > 1 && mg_file->inpline[len-2] == '\\'); |
| 312 |
|
|
| 313 |
|
return(len); |
| 314 |
|
} |
| 320 |
|
char abuf[MG_MAXLINE]; |
| 321 |
|
char *argv[MG_MAXARGC]; |
| 322 |
|
int en; |
| 323 |
< |
register char *cp, **ap; |
| 324 |
< |
|
| 325 |
< |
strcpy(cp=abuf, mg_file->inpline); |
| 326 |
< |
ap = argv; /* break into words */ |
| 323 |
> |
register char *cp, *cp2, **ap; |
| 324 |
> |
/* copy line, removing escape chars */ |
| 325 |
> |
cp = abuf; cp2 = mg_file->inpline; |
| 326 |
> |
while ((*cp++ = *cp2++)) |
| 327 |
> |
if (cp2[0] == '\n' && cp2[-1] == '\\') |
| 328 |
> |
cp--; |
| 329 |
> |
cp = abuf; ap = argv; /* break into words */ |
| 330 |
|
for ( ; ; ) { |
| 331 |
|
while (isspace(*cp)) |
| 332 |
|
*cp++ = '\0'; |
| 352 |
|
{ |
| 353 |
|
MG_FCTXT cntxt; |
| 354 |
|
int rval; |
| 355 |
+ |
register int nbr; |
| 356 |
|
|
| 357 |
|
if ((rval = mg_open(&cntxt, fn)) != MG_OK) { |
| 358 |
|
fprintf(stderr, "%s: %s\n", fn, mg_err[rval]); |
| 359 |
|
return(rval); |
| 360 |
|
} |
| 361 |
< |
while (mg_read()) /* parse each line */ |
| 361 |
> |
while ((nbr = mg_read()) > 0) { /* parse each line */ |
| 362 |
> |
if (nbr >= MG_MAXLINE-1) { |
| 363 |
> |
fprintf(stderr, "%s: %d: %s\n", cntxt.fname, |
| 364 |
> |
cntxt.lineno, mg_err[rval=MG_ELINE]); |
| 365 |
> |
break; |
| 366 |
> |
} |
| 367 |
|
if ((rval = mg_parse()) != MG_OK) { |
| 368 |
|
fprintf(stderr, "%s: %d: %s:\n%s", cntxt.fname, |
| 369 |
|
cntxt.lineno, mg_err[rval], |
| 370 |
|
cntxt.inpline); |
| 371 |
|
break; |
| 372 |
|
} |
| 373 |
+ |
} |
| 374 |
|
mg_close(); |
| 375 |
|
return(rval); |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
|
| 379 |
+ |
int |
| 380 |
+ |
mg_defuhand(ac, av) /* default handler for unknown entities */ |
| 381 |
+ |
int ac; |
| 382 |
+ |
char **av; |
| 383 |
+ |
{ |
| 384 |
+ |
if (mg_nunknown++ == 0) /* report first incident */ |
| 385 |
+ |
fprintf(stderr, "%s: %d: %s: %s\n", mg_file->fname, |
| 386 |
+ |
mg_file->lineno, mg_err[MG_EUNK], av[0]); |
| 387 |
+ |
return(MG_OK); |
| 388 |
+ |
} |
| 389 |
+ |
|
| 390 |
+ |
|
| 391 |
|
void |
| 392 |
|
mg_clear() /* clear parser history */ |
| 393 |
|
{ |
| 394 |
|
c_clearall(); /* clear context tables */ |
| 395 |
< |
mg_file = NULL; /* reset our context */ |
| 395 |
> |
while (mg_file != NULL) /* reset our file context */ |
| 396 |
> |
mg_close(); |
| 397 |
|
} |
| 398 |
|
|
| 399 |
|
|
| 411 |
|
} |
| 412 |
|
|
| 413 |
|
|
| 414 |
< |
static int |
| 414 |
> |
int |
| 415 |
|
e_include(ac, av) /* include file */ |
| 416 |
|
int ac; |
| 417 |
|
char **av; |
| 418 |
|
{ |
| 419 |
|
char *xfarg[MG_MAXARGC]; |
| 420 |
|
MG_FCTXT ictx; |
| 421 |
< |
int rv; |
| 421 |
> |
XF_SPEC *xf_orig = xf_context; |
| 422 |
> |
register int rv; |
| 423 |
|
|
| 424 |
|
if (ac < 2) |
| 425 |
|
return(MG_EARGC); |
| 432 |
|
for (i = 1; i < ac-1; i++) |
| 433 |
|
xfarg[i] = av[i+1]; |
| 434 |
|
xfarg[ac-1] = NULL; |
| 435 |
< |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
| 435 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) { |
| 436 |
> |
mg_close(); |
| 437 |
|
return(rv); |
| 438 |
+ |
} |
| 439 |
|
} |
| 440 |
< |
while (!feof(mg_file->fp)) { |
| 441 |
< |
while (mg_read()) |
| 440 |
> |
do { |
| 441 |
> |
while ((rv = mg_read()) > 0) { |
| 442 |
> |
if (rv >= MG_MAXLINE-1) { |
| 443 |
> |
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
| 444 |
> |
ictx.lineno, mg_err[MG_ELINE]); |
| 445 |
> |
mg_close(); |
| 446 |
> |
return(MG_EINCL); |
| 447 |
> |
} |
| 448 |
|
if ((rv = mg_parse()) != MG_OK) { |
| 449 |
|
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
| 450 |
|
ictx.lineno, mg_err[rv], |
| 452 |
|
mg_close(); |
| 453 |
|
return(MG_EINCL); |
| 454 |
|
} |
| 455 |
+ |
} |
| 456 |
|
if (ac > 2) |
| 457 |
< |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
| 457 |
> |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) { |
| 458 |
> |
mg_close(); |
| 459 |
|
return(rv); |
| 460 |
< |
} |
| 460 |
> |
} |
| 461 |
> |
} while (xf_context != xf_orig); |
| 462 |
|
mg_close(); |
| 463 |
|
return(MG_OK); |
| 464 |
|
} |
| 481 |
|
} |
| 482 |
|
|
| 483 |
|
|
| 484 |
< |
static int |
| 484 |
> |
int |
| 485 |
|
e_sph(ac, av) /* expand a sphere into cones */ |
| 486 |
|
int ac; |
| 487 |
|
char **av; |
| 533 |
|
} |
| 534 |
|
|
| 535 |
|
|
| 536 |
< |
static int |
| 536 |
> |
int |
| 537 |
|
e_torus(ac, av) /* expand a torus into cones */ |
| 538 |
|
int ac; |
| 539 |
|
char **av; |
| 625 |
|
} |
| 626 |
|
|
| 627 |
|
|
| 628 |
< |
static int |
| 628 |
> |
int |
| 629 |
|
e_cyl(ac, av) /* replace a cylinder with equivalent cone */ |
| 630 |
|
int ac; |
| 631 |
|
char **av; |
| 642 |
|
} |
| 643 |
|
|
| 644 |
|
|
| 645 |
< |
static int |
| 645 |
> |
int |
| 646 |
|
e_ring(ac, av) /* turn a ring into polygons */ |
| 647 |
|
int ac; |
| 648 |
|
char **av; |
| 740 |
|
} |
| 741 |
|
|
| 742 |
|
|
| 743 |
< |
static int |
| 743 |
> |
int |
| 744 |
|
e_cone(ac, av) /* turn a cone into polygons */ |
| 745 |
|
int ac; |
| 746 |
|
char **av; |
| 755 |
|
static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; |
| 756 |
|
static char *n4ent[5] = {mg_ename[MG_E_NORMAL],n4[0],n4[1],n4[2]}; |
| 757 |
|
static char *fent[6] = {mg_ename[MG_E_FACE],"_cv1","_cv2","_cv3","_cv4"}; |
| 758 |
+ |
char *v1n; |
| 759 |
|
register C_VERTEX *cv1, *cv2; |
| 760 |
|
register int i, j; |
| 761 |
|
FVECT u, v, w; |
| 771 |
|
if ((cv1 = c_getvert(av[1])) == NULL || |
| 772 |
|
(cv2 = c_getvert(av[3])) == NULL) |
| 773 |
|
return(MG_EUNDEF); |
| 774 |
+ |
v1n = av[1]; |
| 775 |
|
if (!isflt(av[2]) || !isflt(av[4])) |
| 776 |
|
return(MG_ETYPE); |
| 777 |
|
rad1 = atof(av[2]); |
| 790 |
|
cv = cv1; |
| 791 |
|
cv1 = cv2; |
| 792 |
|
cv2 = cv; |
| 793 |
+ |
v1n = av[3]; |
| 794 |
|
d = rad1; |
| 795 |
|
rad1 = rad2; |
| 796 |
|
rad2 = d; |
| 824 |
|
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
| 825 |
|
return(rv); |
| 826 |
|
if (rad1 == 0.) { /* triangles */ |
| 827 |
< |
v1ent[3] = av[1]; |
| 827 |
> |
v1ent[3] = v1n; |
| 828 |
|
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
| 829 |
|
return(rv); |
| 830 |
|
for (j = 0; j < 3; j++) |
| 910 |
|
} |
| 911 |
|
|
| 912 |
|
|
| 913 |
< |
static int |
| 913 |
> |
int |
| 914 |
|
e_prism(ac, av) /* turn a prism into polygons */ |
| 915 |
|
int ac; |
| 916 |
|
char **av; |
| 917 |
|
{ |
| 918 |
|
static char p[3][24]; |
| 919 |
< |
static char *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
| 919 |
> |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
| 920 |
|
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
| 921 |
+ |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
| 922 |
|
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
| 923 |
|
double length; |
| 924 |
+ |
int hasnorm; |
| 925 |
|
FVECT v1, v2, v3, norm; |
| 926 |
|
register C_VERTEX *cv; |
| 927 |
|
C_VERTEX *cv0; |
| 928 |
|
int rv; |
| 929 |
|
register int i, j; |
| 930 |
< |
|
| 930 |
> |
/* check arguments */ |
| 931 |
|
if (ac < 5) |
| 932 |
|
return(MG_EARGC); |
| 933 |
|
if (!isflt(av[ac-1])) |
| 935 |
|
length = atof(av[ac-1]); |
| 936 |
|
if (length <= FTINY && length >= -FTINY) |
| 937 |
|
return(MG_EILL); |
| 938 |
< |
/* do bottom face */ |
| 886 |
< |
newav[0] = mg_ename[MG_E_FACE]; |
| 887 |
< |
for (i = 1; i < ac-1; i++) |
| 888 |
< |
newav[i] = av[i]; |
| 889 |
< |
newav[i] = NULL; |
| 890 |
< |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
| 891 |
< |
return(rv); |
| 892 |
< |
/* compute face normal */ |
| 938 |
> |
/* compute face normal */ |
| 939 |
|
if ((cv0 = c_getvert(av[1])) == NULL) |
| 940 |
|
return(MG_EUNDEF); |
| 941 |
+ |
hasnorm = 0; |
| 942 |
|
norm[0] = norm[1] = norm[2] = 0.; |
| 943 |
|
v1[0] = v1[1] = v1[2] = 0.; |
| 944 |
|
for (i = 2; i < ac-1; i++) { |
| 945 |
|
if ((cv = c_getvert(av[i])) == NULL) |
| 946 |
|
return(MG_EUNDEF); |
| 947 |
+ |
hasnorm += !is0vect(cv->n); |
| 948 |
|
v2[0] = cv->p[0] - cv0->p[0]; |
| 949 |
|
v2[1] = cv->p[1] - cv0->p[1]; |
| 950 |
|
v2[2] = cv->p[2] - cv0->p[2]; |
| 956 |
|
} |
| 957 |
|
if (normalize(norm) == 0.) |
| 958 |
|
return(MG_EILL); |
| 959 |
< |
/* create moved vertices */ |
| 959 |
> |
/* create moved vertices */ |
| 960 |
|
for (i = 1; i < ac-1; i++) { |
| 961 |
|
sprintf(nvn[i-1], "_pv%d", i); |
| 962 |
|
vent[1] = nvn[i-1]; |
| 963 |
< |
if ((rv = mg_handle(MG_E_VERTEX, 3, vent)) != MG_OK) |
| 963 |
> |
vent[3] = av[i]; |
| 964 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
| 965 |
|
return(rv); |
| 966 |
|
cv = c_getvert(av[i]); /* checked above */ |
| 967 |
|
for (j = 0; j < 3; j++) |
| 968 |
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
| 969 |
|
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
| 970 |
|
return(rv); |
| 922 |
– |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
| 971 |
|
} |
| 972 |
< |
/* do top face */ |
| 973 |
< |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
| 926 |
< |
return(rv); |
| 972 |
> |
/* make faces */ |
| 973 |
> |
newav[0] = mg_ename[MG_E_FACE]; |
| 974 |
|
/* do the side faces */ |
| 975 |
|
newav[5] = NULL; |
| 976 |
|
newav[3] = av[ac-2]; |
| 983 |
|
newav[3] = newav[2]; |
| 984 |
|
newav[4] = newav[1]; |
| 985 |
|
} |
| 986 |
+ |
/* do top face */ |
| 987 |
+ |
for (i = 1; i < ac-1; i++) { |
| 988 |
+ |
if (hasnorm) { /* zero normals */ |
| 989 |
+ |
vent[1] = nvn[i-1]; |
| 990 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
| 991 |
+ |
return(rv); |
| 992 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
| 993 |
+ |
return(rv); |
| 994 |
+ |
} |
| 995 |
+ |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
| 996 |
+ |
} |
| 997 |
+ |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
| 998 |
+ |
return(rv); |
| 999 |
+ |
/* do bottom face */ |
| 1000 |
+ |
if (hasnorm) |
| 1001 |
+ |
for (i = 1; i < ac-1; i++) { |
| 1002 |
+ |
vent[1] = nvn[i-1]; |
| 1003 |
+ |
vent[3] = av[i]; |
| 1004 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
| 1005 |
+ |
return(rv); |
| 1006 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
| 1007 |
+ |
return(rv); |
| 1008 |
+ |
newav[i] = nvn[i-1]; |
| 1009 |
+ |
} |
| 1010 |
+ |
else |
| 1011 |
+ |
for (i = 1; i < ac-1; i++) |
| 1012 |
+ |
newav[i] = av[i]; |
| 1013 |
+ |
newav[i] = NULL; |
| 1014 |
+ |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
| 1015 |
+ |
return(rv); |
| 1016 |
|
return(MG_OK); |
| 1017 |
|
} |
| 1018 |
|
|
| 1019 |
|
|
| 1020 |
|
static int |
| 1021 |
< |
e_cspec(ac, av) /* handle spectral color */ |
| 945 |
< |
int ac; |
| 946 |
< |
char **av; |
| 1021 |
> |
put_cxy() /* put out current xy chromaticities */ |
| 1022 |
|
{ |
| 1023 |
|
static char xbuf[24], ybuf[24]; |
| 1024 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
| 950 |
– |
int rv; |
| 1025 |
|
|
| 1026 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
| 1027 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
| 1028 |
+ |
return(mg_handle(MG_E_CXY, 3, ccom)); |
| 1029 |
+ |
} |
| 1030 |
+ |
|
| 1031 |
+ |
|
| 1032 |
+ |
static int |
| 1033 |
+ |
put_cspec() /* put out current color spectrum */ |
| 1034 |
+ |
{ |
| 1035 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
| 1036 |
+ |
char *newav[C_CNSS+4]; |
| 1037 |
+ |
double sf; |
| 1038 |
+ |
register int i; |
| 1039 |
+ |
|
| 1040 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
| 1041 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
| 1042 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
| 1043 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
| 1044 |
+ |
newav[1] = wl[0]; |
| 1045 |
+ |
newav[2] = wl[1]; |
| 1046 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
| 1047 |
+ |
for (i = 0; i < C_CNSS; i++) { |
| 1048 |
+ |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
| 1049 |
+ |
newav[i+3] = vbuf[i]; |
| 1050 |
+ |
} |
| 1051 |
+ |
newav[C_CNSS+3] = NULL; |
| 1052 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
| 1053 |
+ |
return(i); |
| 1054 |
+ |
} |
| 1055 |
+ |
return(MG_OK); |
| 1056 |
+ |
} |
| 1057 |
+ |
|
| 1058 |
+ |
|
| 1059 |
+ |
static int |
| 1060 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
| 1061 |
+ |
int ac; |
| 1062 |
+ |
char **av; |
| 1063 |
+ |
{ |
| 1064 |
+ |
/* convert to xy chromaticity */ |
| 1065 |
|
c_ccvt(c_ccolor, C_CSXY); |
| 1066 |
|
/* if it's really their handler, use it */ |
| 1067 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
| 1068 |
< |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
| 956 |
< |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
| 957 |
< |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
| 958 |
< |
return(rv); |
| 959 |
< |
} |
| 1067 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
| 1068 |
> |
return(put_cxy()); |
| 1069 |
|
return(MG_OK); |
| 1070 |
|
} |
| 1071 |
|
|
| 1075 |
|
int ac; |
| 1076 |
|
char **av; |
| 1077 |
|
{ |
| 969 |
– |
char wl[2][6], vbuf[C_CNSS][24]; |
| 970 |
– |
char *newav[C_CNSS+4]; |
| 971 |
– |
int rv; |
| 972 |
– |
register int i; |
| 1078 |
|
/* |
| 1079 |
|
* Contorted logic works as follows: |
| 1080 |
|
* 1. the colors are already mixed in c_hcolor() support function |
| 1085 |
|
*/ |
| 1086 |
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
| 1087 |
|
c_ccvt(c_ccolor, C_CSXY); |
| 1088 |
< |
else if (c_ccolor->flags & C_CDSPEC) { |
| 1089 |
< |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
| 1090 |
< |
sprintf(wl[0], "%d", C_CMINWL); |
| 1091 |
< |
sprintf(wl[1], "%d", C_CMAXWL); |
| 1092 |
< |
newav[0] = mg_ename[MG_E_CSPEC]; |
| 1093 |
< |
newav[1] = wl[0]; |
| 1094 |
< |
newav[2] = wl[1]; |
| 1095 |
< |
for (i = 0; i < C_CNSS; i++) { |
| 1096 |
< |
sprintf(vbuf[i], "%.6f", |
| 1097 |
< |
(double)c_ccolor->ssamp[i] / |
| 1098 |
< |
c_ccolor->ssum); |
| 1099 |
< |
newav[i+3] = vbuf[i]; |
| 1100 |
< |
} |
| 1101 |
< |
newav[C_CNSS+3] = NULL; |
| 1102 |
< |
if ((rv = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
| 1103 |
< |
return(rv); |
| 1104 |
< |
} |
| 1105 |
< |
return(MG_OK); |
| 1106 |
< |
} |
| 1107 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
| 1108 |
< |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
| 1109 |
< |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
| 1110 |
< |
newav[0] = mg_ename[MG_E_CXY]; |
| 1111 |
< |
newav[1] = vbuf[0]; |
| 1007 |
< |
newav[2] = vbuf[1]; |
| 1008 |
< |
newav[3] = NULL; |
| 1009 |
< |
if ((rv = mg_handle(MG_E_CXY, 3, newav)) != MG_OK) |
| 1010 |
< |
return(rv); |
| 1011 |
< |
} |
| 1088 |
> |
else if (c_ccolor->flags & C_CDSPEC) |
| 1089 |
> |
return(put_cspec()); |
| 1090 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
| 1091 |
> |
return(put_cxy()); |
| 1092 |
> |
return(MG_OK); |
| 1093 |
> |
} |
| 1094 |
> |
|
| 1095 |
> |
|
| 1096 |
> |
static int |
| 1097 |
> |
e_cct(ac, av) /* handle color temperature */ |
| 1098 |
> |
int ac; |
| 1099 |
> |
char **av; |
| 1100 |
> |
{ |
| 1101 |
> |
/* |
| 1102 |
> |
* Logic is similar to e_cmix here. Support handler has already |
| 1103 |
> |
* converted temperature to spectral color. Put it out as such |
| 1104 |
> |
* if they support it, otherwise convert to xy chromaticity and |
| 1105 |
> |
* put it out if they handle it. |
| 1106 |
> |
*/ |
| 1107 |
> |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
| 1108 |
> |
return(put_cspec()); |
| 1109 |
> |
c_ccvt(c_ccolor, C_CSXY); |
| 1110 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
| 1111 |
> |
return(put_cxy()); |
| 1112 |
|
return(MG_OK); |
| 1113 |
|
} |