/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif /* * Parse an MGF file, converting or discarding unsupported entities */ #include #include #include #include #include "parser.h" #include "lookup.h" #include "messages.h" /* * Global definitions of variables declared in parser.h */ /* entity names */ char mg_ename[MG_NENTITIES][MG_MAXELEN] = MG_NAMELIST; /* Handler routines for each entity */ int (*mg_ehand[MG_NENTITIES])(); /* error messages */ char *mg_err[MG_NERRS] = MG_ERRLIST; MG_FCTXT *mg_file; /* current file context pointer */ int mg_nqcdivs = MG_NQCD; /* number of divisions per quarter circle */ /* * The idea with this parser is to compensate for any missing entries in * mg_ehand with alternate handlers that express these entities in terms * of others that the calling program can handle. * * In some cases, no alternate handler is possible because the entity * has no approximate equivalent. These entities are simply discarded. * * Certain entities are dependent on others, and mg_init() will fail * if the supported entities are not consistent. * * Some alternate entity handlers require that earlier entities be * noted in some fashion, and we therefore keep another array of * parallel support handlers to assist in this effort. */ /* temporary settings for testing */ #define e_ies e_any_toss /* alternate handler routines */ static int e_any_toss(), /* discard unneeded entity */ e_ies(); /* IES luminaire file */ e_include(), /* include file */ e_sph(), /* sphere */ e_cyl(), /* cylinder */ e_cone(), /* cone */ e_ring(), /* ring */ e_torus(); /* torus */ /* alternate handler support functions */ static int (*e_supp[MG_NENTITIES])(); static char FLTFMT[] = "%.12g"; static int warpconends; /* hack for generating good normals */ void mg_init() /* initialize alternate entity handlers */ { unsigned long ineed = 0, uneed = 0; register int i; /* pick up slack */ if (mg_ehand[MG_E_IES] == NULL) mg_ehand[MG_E_IES] = e_ies; if (mg_ehand[MG_E_INCLUDE] == NULL) mg_ehand[MG_E_INCLUDE] = e_include; if (mg_ehand[MG_E_SPH] == NULL) { mg_ehand[MG_E_SPH] = e_sph; ineed |= 1<= mg_ename[0]; cp -= sizeof(mg_ename[0])) lu_find(&ent_tab, cp)->key = cp; } cp = lu_find(&ent_tab, name)->key; if (cp == NULL) return(-1); return((cp - mg_ename[0])/sizeof(mg_ename[0])); } static int handle_it(en, ac, av) /* pass entity to appropriate handler */ register int en; int ac; char **av; { int rv; if (en < 0 && (en = mg_entity(av[0])) < 0) return(MG_EUNK); if (e_supp[en] != NULL) { if ((rv = (*e_supp[en])(ac, av)) != MG_OK) return(rv); } return((*mg_ehand[en])(ac, av)); } int mg_open(ctx, fn) /* open new input file */ register MG_FCTXT *ctx; char *fn; { int olen; register char *cp; ctx->lineno = 0; if (fn == NULL) { ctx->fname = ""; ctx->fp = stdin; ctx->prev = mg_file; mg_file = ctx; return(MG_OK); } /* get name relative to this context */ if (mg_file != NULL && (cp = strrchr(mg_file->fname, '/')) != NULL) olen = cp - mg_file->fname + 1; else olen = 0; ctx->fname = (char *)malloc(olen+strlen(fn)+1); if (ctx->fname == NULL) return(MG_EMEM); if (olen) strcpy(ctx->fname, mg_file->fname); strcpy(ctx->fname+olen, fn); ctx->fp = fopen(ctx->fname, "r"); if (ctx->fp == NULL) { free((MEM_PTR)ctx->fname); return(MG_ENOFILE); } ctx->prev = mg_file; /* establish new context */ mg_file = ctx; return(MG_OK); } void mg_close() /* close input file */ { register MG_FCTXT *ctx = mg_file; mg_file = ctx->prev; /* restore enclosing context */ if (ctx->fp == stdin) return; /* don't close standard input */ fclose(ctx->fp); free((MEM_PTR)ctx->fname); } int mg_rewind() /* rewind input file */ { if (mg_file->lineno == 0) return(MG_OK); if (mg_file->fp == stdin) return(MG_ESEEK); /* cannot seek on standard input */ if (fseek(mg_file->fp, 0L, 0) == EOF) return(MG_ESEEK); mg_file->lineno = 0; return(MG_OK); } int mg_read() /* read next line from file */ { register int len = 0; do { if (fgets(mg_file->inpline+len, MG_MAXLINE-len, mg_file->fp) == NULL) return(len); mg_file->lineno++; len += strlen(mg_file->inpline+len); if (len > 1 && mg_file->inpline[len-2] == '\\') mg_file->inpline[--len-1] = ' '; } while (mg_file->inpline[len]); return(len); } int mg_parse() /* parse current input line */ { char abuf[MG_MAXLINE]; char *argv[MG_MAXARGC]; int en; register char *cp, **ap; strcpy(cp=abuf, mg_file->inpline); ap = argv; /* break into words */ for ( ; ; ) { while (isspace(*cp)) *cp++ = '\0'; if (!*cp) break; if (ap - argv >= MG_MAXARGC-1) return(MG_EARGC); *ap++ = cp; while (*++cp && !isspace(*cp)) ; } if (ap == argv) return(MG_OK); /* no words in line */ *ap = NULL; /* else handle it */ return(handle_it(-1, ap-argv, argv)); } int mg_load(fn) /* load an MGF file */ char *fn; { MG_FCTXT cntxt; int rval; if ((rval = mg_open(&cntxt, fn)) != MG_OK) { fprintf("%s: %s\n", fn, mg_err[rval]); return(rval); } while (mg_read()) /* parse each line */ if ((rval = mg_parse()) != MG_OK) { fprintf(stderr, "%s: %d: %s:\n%s", cntxt.fname, cntxt.lineno, mg_err[rval], cntxt.inpline); break; } mg_close(); return(rval); } void mg_clear() /* clear parser history */ { c_clearall(); /* clear context tables */ mg_file = NULL; /* reset our context */ } int mg_iterate(ac, av, f) /* iterate on statement */ int ac; register char **av; int (*f)(); { int niter, rval; register int i, j; char *argv[MG_MAXARGC]; char cntbuf[10]; /* build partial transformation */ for (i = 0; i < ac; i++) { if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0') break; argv[i+1] = av[i]; } argv[i+1] = NULL; if (i) { /* handle transformation */ argv[0] = mg_ename[MG_E_XF]; if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK) return(rval); } if (i < ac) { /* run array */ if (i+1 >= ac || !isint(av[i+1])) return(MG_ETYPE); niter = atoi(av[i+1]); argv[0] = "-i"; argv[1] = cntbuf; for (j = 2; j+i < ac; j++) argv[j] = av[j+i]; argv[j] = NULL; for (j = 0; j < niter; j++) { sprintf(cntbuf, "%d", j); if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK) return(rval); } } else if ((rval = (*f)()) != MG_OK) /* else do this instance */ return(rval); if (i) { /* reset the transform */ argv[0] = mg_ename[MG_E_XF]; argv[1] = NULL; (void)handle_it(MG_E_XF, 1, argv); } return(MG_OK); } /**************************************************************************** * The following routines handle unsupported entities */ static int e_any_toss(ac, av) /* discard an unwanted entity */ int ac; char **av; { return(MG_OK); } static int reload_file() /* reload current MGF file */ { register int rval; if ((rval = mg_rewind()) != MG_OK) return(rval); while (mg_read()) if ((rval = mg_parse()) != MG_OK) return(rval); return(MG_OK); } static int e_include(ac, av) /* include file */ int ac; char **av; { MG_FCTXT ictx; int rv; if (ac < 2) return(MG_EARGC); if ((rv = mg_open(&ictx, av[1])) != MG_OK) return(rv); if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) { fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, ictx.lineno, mg_err[rv], ictx.inpline); mg_close(); return(MG_EINCL); } mg_close(); return(MG_OK); } static void make_axes(u, v, w) /* compute u and v given w (normalized) */ FVECT u, v, w; { register int i; v[0] = v[1] = v[2] = 0.; for (i = 0; i < 3; i++) if (w[i] < .6 && w[i] > -.6) break; v[i] = 1.; fcross(u, v, w); normalize(u); fcross(v, w, u); } static int e_sph(ac, av) /* expand a sphere into cones */ int ac; char **av; { static char p2x[24], p2y[24], p2z[24], r1[24], r2[24]; static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_sv1","=","_sv2"}; static char *v2ent[4] = {mg_ename[MG_E_VERTEX],"_sv2","="}; static char *p2ent[5] = {mg_ename[MG_E_POINT],p2x,p2y,p2z}; static char *conent[6] = {mg_ename[MG_E_CONE],"_sv1",r1,"_sv2",r2}; register C_VERTEX *cv; register int i; int rval; double rad; double theta; if (ac != 3) return(MG_EARGC); if ((cv = c_getvert(av[1])) == NULL) return(MG_EUNDEF); if (!isflt(av[2])) return(MG_ETYPE); rad = atof(av[2]); /* initialize */ warpconends = 1; if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK) return(rval); sprintf(p2x, FLTFMT, cv->p[0]); sprintf(p2y, FLTFMT, cv->p[1]); sprintf(p2z, FLTFMT, cv->p[2]+rad); if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) return(rval); r2[0] = '0'; r2[1] = '\0'; for (i = 1; i <= 2*mg_nqcdivs; i++) { theta = i*(PI/2)/mg_nqcdivs; if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) return(rval); sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) return(rval); if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) return(rval); strcpy(r1, r2); sprintf(r2, FLTFMT, rad*sin(theta)); if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) return(rval); } warpconends = 0; return(MG_OK); } static int e_torus(ac, av) /* expand a torus into cones */ int ac; char **av; { static char p2[3][24], r1[24], r2[24]; static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_tv1","=","_tv2"}; static char *v2ent[5] = {mg_ename[MG_E_VERTEX],"_tv2","="}; static char *p2ent[5] = {mg_ename[MG_E_POINT],p2[0],p2[1],p2[2]}; static char *conent[6] = {mg_ename[MG_E_CONE],"_tv1",r1,"_tv2",r2}; register C_VERTEX *cv; register int i, j; int rval; int sgn; double minrad, maxrad, avgrad; double theta; if (ac != 4) return(MG_EARGC); if ((cv = c_getvert(av[1])) == NULL) return(MG_EUNDEF); if (cv->n[0]==0. && cv->n[1]==0. && cv->n[2]==0.) return(MG_EILL); if (!isflt(av[2]) || !isflt(av[3])) return(MG_ETYPE); minrad = atof(av[2]); maxrad = atof(av[3]); /* check orientation */ if (minrad > 0.) sgn = 1; else if (minrad < 0.) sgn = -1; else if (maxrad > 0.) sgn = 1; else if (maxrad < 0.) sgn = -1; else return(MG_EILL); if (sgn*(maxrad-minrad) <= 0.) return(MG_EILL); /* initialize */ warpconends = 1; v2ent[3] = av[1]; for (j = 0; j < 3; j++) sprintf(p2[j], FLTFMT, cv->p[j] + .5*sgn*(maxrad-minrad)*cv->n[j]); if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) return(rval); if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) return(rval); sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); /* run outer section */ for (i = 1; i <= 2*mg_nqcdivs; i++) { theta = i*(PI/2)/mg_nqcdivs; if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) return(rval); for (j = 0; j < 3; j++) sprintf(p2[j], FLTFMT, cv->p[j] + .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) return(rval); if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) return(rval); strcpy(r1, r2); sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) return(rval); } /* run inner section */ sprintf(r2, FLTFMT, -.5*(minrad+maxrad)); for ( ; i <= 4*mg_nqcdivs; i++) { theta = i*(PI/2)/mg_nqcdivs; for (j = 0; j < 3; j++) sprintf(p2[j], FLTFMT, cv->p[j] + .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) return(rval); if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) return(rval); if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) return(rval); strcpy(r1, r2); sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) return(rval); } warpconends = 0; return(MG_OK); } static int e_cyl(ac, av) /* replace a cylinder with equivalent cone */ int ac; char **av; { static char *avnew[6] = {mg_ename[MG_E_CONE]}; if (ac != 4) return(MG_EARGC); avnew[1] = av[1]; avnew[2] = av[2]; avnew[3] = av[3]; avnew[4] = av[2]; return(handle_it(MG_E_CONE, 5, avnew)); } static int e_ring(ac, av) /* turn a ring into polygons */ int ac; char **av; { static char p3[3][24], p4[3][24]; static char *nzent[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_rv1","="}; static char *v2ent[5] = {mg_ename[MG_E_VERTEX],"_rv2","=","_rv3"}; static char *v3ent[4] = {mg_ename[MG_E_VERTEX],"_rv3","="}; static char *p3ent[5] = {mg_ename[MG_E_POINT],p3[0],p3[1],p3[2]}; static char *v4ent[4] = {mg_ename[MG_E_VERTEX],"_rv4","="}; static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; static char *fent[6] = {mg_ename[MG_E_FACE],"_rv1","_rv2","_rv3","_rv4"}; register C_VERTEX *cv; register int i, j; FVECT u, v; double minrad, maxrad; int rv; double theta, d; if (ac != 4) return(MG_EARGC); if ((cv = c_getvert(av[1])) == NULL) return(MG_EUNDEF); if (cv->n[0]==0. && cv->n[1]==0. && cv->n[2]==0.) return(MG_EILL); if (!isflt(av[2]) || !isflt(av[3])) return(MG_ETYPE); minrad = atof(av[2]); maxrad = atof(av[3]); if (minrad < 0. || maxrad <= minrad) return(MG_EILL); /* initialize */ make_axes(u, v, cv->n); for (j = 0; j < 3; j++) sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) return(rv); if (minrad == 0.) { /* closed */ v1ent[3] = av[1]; if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK) return(rv); for (i = 1; i <= 4*mg_nqcdivs; i++) { theta = i*(PI/2)/mg_nqcdivs; if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) return(rv); for (j = 0; j < 3; j++) sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]*cos(theta) + maxrad*v[j]*sin(theta)); if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) return(rv); } } else { /* open */ if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) return(rv); for (j = 0; j < 3; j++) sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) return(rv); v1ent[3] = "_rv4"; for (i = 1; i <= 4*mg_nqcdivs; i++) { theta = i*(PI/2)/mg_nqcdivs; if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) return(rv); for (j = 0; j < 3; j++) { d = u[j]*cos(theta) + v[j]*sin(theta); sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); } if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) return(rv); } } return(MG_OK); } static int e_cone(ac, av) /* turn a cone into polygons */ int ac; char **av; { static char p3[3][24], p4[3][24], n3[3][24], n4[3][24]; static char *v1ent[5] = {mg_ename[MG_E_VERTEX],"_cv1","="}; static char *v2ent[5] = {mg_ename[MG_E_VERTEX],"_cv2","=","_cv3"}; static char *v3ent[4] = {mg_ename[MG_E_VERTEX],"_cv3","="}; static char *p3ent[5] = {mg_ename[MG_E_POINT],p3[0],p3[1],p3[2]}; static char *n3ent[5] = {mg_ename[MG_E_NORMAL],n3[0],n3[1],n3[2]}; static char *v4ent[4] = {mg_ename[MG_E_VERTEX],"_cv4","="}; static char *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]}; static char *n4ent[5] = {mg_ename[MG_E_NORMAL],n4[0],n4[1],n4[2]}; static char *fent[6] = {mg_ename[MG_E_FACE],"_cv1","_cv2","_cv3","_cv4"}; register C_VERTEX *cv1, *cv2; register int i, j; FVECT u, v, w; double rad1, rad2; int sgn; double n1off, n2off; double d; int rv; double theta; if (ac != 5) return(MG_EARGC); if ((cv1 = c_getvert(av[1])) == NULL || (cv2 = c_getvert(av[3])) == NULL) return(MG_EUNDEF); if (!isflt(av[2]) || !isflt(av[4])) return(MG_ETYPE); rad1 = atof(av[2]); rad2 = atof(av[4]); if (rad1 == 0.) { if (rad2 == 0.) return(MG_EILL); } else if (rad2 != 0.) { if (rad1 < 0. ^ rad2 < 0.) return(MG_EILL); } else { /* swap */ C_VERTEX *cv; cv = cv1; cv1 = cv2; cv2 = cv; d = rad1; rad1 = rad2; rad2 = d; } sgn = rad2 < 0. ? -1 : 1; /* initialize */ for (j = 0; j < 3; j++) w[j] = cv1->p[j] - cv2->p[j]; if ((d = normalize(w)) == 0.) return(MG_EILL); n1off = n2off = (rad2 - rad1)/d; if (warpconends) /* hack for e_sph and e_torus */ n2off = tan(atan(n2off)-(PI/4)/mg_nqcdivs); n2off = sgn*n2off; make_axes(u, v, w); for (j = 0; j < 3; j++) { sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*u[j]); sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); } if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) return(rv); if (rad1 == 0.) { /* triangles */ v1ent[3] = av[1]; if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) return(rv); for (j = 0; j < 3; j++) sprintf(n4[j], FLTFMT, w[j]); if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) return(rv); for (i = 1; i <= 4*mg_nqcdivs; i++) { theta = sgn*i*(PI/2)/mg_nqcdivs; if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) return(rv); for (j = 0; j < 3; j++) { d = u[j]*cos(theta) + v[j]*sin(theta); sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*d); sprintf(n3[j], FLTFMT, d + w[j]*n2off); } if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) return(rv); } } else { /* quads */ v1ent[3] = "_cv4"; if (warpconends) /* hack for e_sph and e_torus */ n1off = tan(atan(n1off)+(PI/4)/mg_nqcdivs); n1off = sgn*n1off; for (j = 0; j < 3; j++) { sprintf(p4[j], FLTFMT, cv1->p[j] + rad1*u[j]); sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); } if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) return(rv); for (i = 1; i <= 4*mg_nqcdivs; i++) { theta = sgn*i*(PI/2)/mg_nqcdivs; if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) return(rv); for (j = 0; j < 3; j++) { d = u[j]*cos(theta) + v[j]*sin(theta); sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*d); sprintf(n3[j], FLTFMT, d + w[j]*n2off); sprintf(p4[j], FLTFMT, cv1->p[j] + rad1*d); sprintf(n4[j], FLTFMT, d + w[j]*n1off); } if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) return(rv); if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) return(rv); } } return(MG_OK); }