--- ray/src/common/calexpr.c 1993/06/04 14:27:58 2.13 +++ ray/src/common/calexpr.c 1998/08/17 17:57:30 2.17 @@ -1,7 +1,7 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static char SCCSid[] = "$SunId$ SGI"; #endif /* @@ -34,7 +34,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define isdecimal(c) (isdigit(c) || (c) == '.') -extern char *fgets(), *savestr(); +extern char *savestr(); extern char *emalloc(), *ecalloc(); extern EPNODE *curfunc; extern double efunc(), evariable(); @@ -45,6 +45,10 @@ static double echannel(); static double eadd(), esubtr(), emult(), edivi(), epow(); static double ebotch(); +#ifdef DCL_ATOF +extern double atof(); +#endif + int nextc; /* lookahead character */ double (*eoper[])() = { /* expression operations */ @@ -125,6 +129,53 @@ char *expr; } +epcmp(ep1, ep2) /* compare two expressions for equivalence */ +register EPNODE *ep1, *ep2; +{ + double d; + + if (ep1->type != ep2->type) + return(1); + + switch (ep1->type) { + + case VAR: + return(ep1->v.ln != ep2->v.ln); + + case NUM: + if (ep2->v.num == 0) + return(ep1->v.num != 0); + d = ep1->v.num / ep2->v.num; + return(d > 1.000000000001 | d < 0.999999999999); + + case CHAN: + case ARG: + return(ep1->v.chan != ep2->v.chan); + + case '=': + case ':': + return(epcmp(ep1->v.kid->sibling, ep2->v.kid->sibling)); + + case TICK: + case SYM: /* should never get this one */ + return(0); + + default: + ep1 = ep1->v.kid; + ep2 = ep2->v.kid; + while (ep1 != NULL) { + if (ep2 == NULL) + return(1); + if (epcmp(ep1, ep2)) + return(1); + ep1 = ep1->sibling; + ep2 = ep2->sibling; + } + return(ep2 != NULL); + } +} + + epfree(epar) /* free a parse tree */ register EPNODE *epar; { @@ -488,18 +539,22 @@ getnum() /* scan a positive float */ if (lnext == '.' && i < MAXWORD) { str[i++] = lnext; lnext = scan(); + if (i == 1 && !isdigit(lnext)) + syntax("badly formed number"); while (isdigit(lnext) && i < MAXWORD) { str[i++] = lnext; lnext = scan(); } } - if ((lnext == 'e' || lnext == 'E') && i < MAXWORD) { + if ((lnext == 'e' | lnext == 'E') && i < MAXWORD) { str[i++] = lnext; lnext = scan(); - if ((lnext == '-' || lnext == '+') && i < MAXWORD) { + if ((lnext == '-' | lnext == '+') && i < MAXWORD) { str[i++] = lnext; lnext = scan(); } + if (!isdigit(lnext)) + syntax("missing exponent"); while (isdigit(lnext) && i < MAXWORD) { str[i++] = lnext; lnext = scan();