| 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; |
| 209 |
|
{ |
| 210 |
|
int rv; |
| 211 |
|
|
| 212 |
< |
if (en < 0 && (en = mg_entity(av[0])) < 0) |
| 212 |
> |
if (en < 0 && (en = mg_entity(av[0])) < 0) { /* unknown entity */ |
| 213 |
> |
if (mg_uhand != NULL) |
| 214 |
> |
return((*mg_uhand)(ac, av)); |
| 215 |
|
return(MG_EUNK); |
| 216 |
< |
if (e_supp[en] != NULL) { |
| 216 |
> |
} |
| 217 |
> |
if (e_supp[en] != NULL) { /* support handler */ |
| 218 |
|
if ((rv = (*e_supp[en])(ac, av)) != MG_OK) |
| 219 |
|
return(rv); |
| 220 |
|
} |
| 221 |
< |
return((*mg_ehand[en])(ac, av)); |
| 221 |
> |
return((*mg_ehand[en])(ac, av)); /* assigned handler */ |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
|
| 348 |
|
char *fn; |
| 349 |
|
{ |
| 350 |
|
MG_FCTXT cntxt; |
| 351 |
< |
int rval; |
| 351 |
> |
register int rval; |
| 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 ((rval = mg_read()) > 0) { /* parse each line */ |
| 358 |
> |
if (rval >= MG_MAXLINE-1 && cntxt.inpline[rval-1] != '\n') { |
| 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 |
|
} |
| 373 |
|
|
| 374 |
|
|
| 375 |
+ |
int |
| 376 |
+ |
mg_defuhand(ac, av) /* default handler for unknown entities */ |
| 377 |
+ |
int ac; |
| 378 |
+ |
char **av; |
| 379 |
+ |
{ |
| 380 |
+ |
if (mg_nunknown++ == 0) /* report first incident */ |
| 381 |
+ |
fprintf(stderr, "%s: %d: %s: %s\n", mg_file->fname, |
| 382 |
+ |
mg_file->lineno, mg_err[MG_EUNK], av[0]); |
| 383 |
+ |
return(MG_OK); |
| 384 |
+ |
} |
| 385 |
+ |
|
| 386 |
+ |
|
| 387 |
|
void |
| 388 |
|
mg_clear() /* clear parser history */ |
| 389 |
|
{ |
| 414 |
|
char *xfarg[MG_MAXARGC]; |
| 415 |
|
MG_FCTXT ictx; |
| 416 |
|
XF_SPEC *xf_orig = xf_context; |
| 417 |
< |
int rv; |
| 417 |
> |
register int rv; |
| 418 |
|
|
| 419 |
|
if (ac < 2) |
| 420 |
|
return(MG_EARGC); |
| 431 |
|
return(rv); |
| 432 |
|
} |
| 433 |
|
do { |
| 434 |
< |
while (mg_read()) |
| 434 |
> |
while ((rv = mg_read()) > 0) { |
| 435 |
> |
if (rv >= MG_MAXLINE-1 && ictx.inpline[rv-1] != '\n') { |
| 436 |
> |
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
| 437 |
> |
ictx.lineno, mg_err[MG_ELINE]); |
| 438 |
> |
mg_close(); |
| 439 |
> |
return(MG_EINCL); |
| 440 |
> |
} |
| 441 |
|
if ((rv = mg_parse()) != MG_OK) { |
| 442 |
|
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
| 443 |
|
ictx.lineno, mg_err[rv], |
| 445 |
|
mg_close(); |
| 446 |
|
return(MG_EINCL); |
| 447 |
|
} |
| 448 |
+ |
} |
| 449 |
|
if (ac > 2) |
| 450 |
|
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
| 451 |
|
return(rv); |
| 746 |
|
static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; |
| 747 |
|
static char *n4ent[5] = {mg_ename[MG_E_NORMAL],n4[0],n4[1],n4[2]}; |
| 748 |
|
static char *fent[6] = {mg_ename[MG_E_FACE],"_cv1","_cv2","_cv3","_cv4"}; |
| 749 |
+ |
char *v1n; |
| 750 |
|
register C_VERTEX *cv1, *cv2; |
| 751 |
|
register int i, j; |
| 752 |
|
FVECT u, v, w; |
| 762 |
|
if ((cv1 = c_getvert(av[1])) == NULL || |
| 763 |
|
(cv2 = c_getvert(av[3])) == NULL) |
| 764 |
|
return(MG_EUNDEF); |
| 765 |
+ |
v1n = av[1]; |
| 766 |
|
if (!isflt(av[2]) || !isflt(av[4])) |
| 767 |
|
return(MG_ETYPE); |
| 768 |
|
rad1 = atof(av[2]); |
| 781 |
|
cv = cv1; |
| 782 |
|
cv1 = cv2; |
| 783 |
|
cv2 = cv; |
| 784 |
+ |
v1n = av[3]; |
| 785 |
|
d = rad1; |
| 786 |
|
rad1 = rad2; |
| 787 |
|
rad2 = d; |
| 815 |
|
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
| 816 |
|
return(rv); |
| 817 |
|
if (rad1 == 0.) { /* triangles */ |
| 818 |
< |
v1ent[3] = av[1]; |
| 818 |
> |
v1ent[3] = v1n; |
| 819 |
|
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
| 820 |
|
return(rv); |
| 821 |
|
for (j = 0; j < 3; j++) |