ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calexpr.c
(Generate patch)

Comparing ray/src/common/calexpr.c (file contents):
Revision 2.9 by greg, Tue Oct 6 12:29:36 1992 UTC vs.
Revision 2.17 by gwlarson, Mon Aug 17 17:57:30 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 34 | Line 34 | static char SCCSid[] = "$SunId$ LBL";
34  
35   #define  isdecimal(c)   (isdigit(c) || (c) == '.')
36  
37 < #ifndef atof
38 < extern double  atof();
39 < #endif
40 < extern char  *fgets(), *savestr();
37 > extern char  *savestr();
38   extern char  *emalloc(), *ecalloc();
39   extern EPNODE  *curfunc;
40   extern double  efunc(), evariable();
41 < static double  euminus(), echannel(), eargument(), enumber();
41 > static double  euminus(), eargument(), enumber();
42 > #ifdef  INCHAN
43 > static double  echannel();
44 > #endif
45   static double  eadd(), esubtr(), emult(), edivi(), epow();
46   static double  ebotch();
47  
48 + #ifdef  DCL_ATOF
49 + extern double  atof();
50 + #endif
51 +
52   int  nextc;                             /* lookahead character */
53  
54   double  (*eoper[])() = {                /* expression operations */
# Line 125 | Line 129 | char  *expr;
129   }
130  
131  
132 + epcmp(ep1, ep2)                 /* compare two expressions for equivalence */
133 + register EPNODE  *ep1, *ep2;
134 + {
135 +        double  d;
136 +
137 +        if (ep1->type != ep2->type)
138 +                return(1);
139 +
140 +        switch (ep1->type) {
141 +
142 +        case VAR:
143 +                return(ep1->v.ln != ep2->v.ln);
144 +
145 +        case NUM:
146 +                if (ep2->v.num == 0)
147 +                        return(ep1->v.num != 0);
148 +                d = ep1->v.num / ep2->v.num;
149 +                return(d > 1.000000000001 | d < 0.999999999999);
150 +
151 +        case CHAN:
152 +        case ARG:
153 +                return(ep1->v.chan != ep2->v.chan);
154 +
155 +        case '=':
156 +        case ':':
157 +                return(epcmp(ep1->v.kid->sibling, ep2->v.kid->sibling));
158 +
159 +        case TICK:
160 +        case SYM:                       /* should never get this one */
161 +                return(0);
162 +
163 +        default:
164 +                ep1 = ep1->v.kid;
165 +                ep2 = ep2->v.kid;
166 +                while (ep1 != NULL) {
167 +                        if (ep2 == NULL)
168 +                                return(1);
169 +                        if (epcmp(ep1, ep2))
170 +                                return(1);
171 +                        ep1 = ep1->sibling;
172 +                        ep2 = ep2->sibling;
173 +                }
174 +                return(ep2 != NULL);
175 +        }
176 + }
177 +
178 +
179   epfree(epar)                    /* free a parse tree */
180   register EPNODE  *epar;
181   {
# Line 149 | Line 200 | register EPNODE         *epar;
200              break;
201  
202          default:
203 <            for (ep = epar->v.kid; ep != NULL; ep = ep->sibling)
203 >            while ((ep = epar->v.kid) != NULL) {
204 >                epar->v.kid = ep->sibling;
205                  epfree(ep);
206 +            }
207              break;
208  
209      }
# Line 486 | Line 539 | getnum()                       /* scan a positive float */
539      if (lnext == '.' && i < MAXWORD) {
540          str[i++] = lnext;
541          lnext = scan();
542 +        if (i == 1 && !isdigit(lnext))
543 +            syntax("badly formed number");
544          while (isdigit(lnext) && i < MAXWORD) {
545              str[i++] = lnext;
546              lnext = scan();
547          }
548      }
549 <    if ((lnext == 'e' || lnext == 'E') && i < MAXWORD) {
549 >    if ((lnext == 'e' | lnext == 'E') && i < MAXWORD) {
550          str[i++] = lnext;
551          lnext = scan();
552 <        if ((lnext == '-' || lnext == '+') && i < MAXWORD) {
552 >        if ((lnext == '-' | lnext == '+') && i < MAXWORD) {
553              str[i++] = lnext;
554              lnext = scan();
555          }
556 +        if (!isdigit(lnext))
557 +            syntax("missing exponent");
558          while (isdigit(lnext) && i < MAXWORD) {
559              str[i++] = lnext;
560              lnext = scan();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines