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.6 by greg, Mon Sep 21 12:01:54 1992 UTC vs.
Revision 2.16 by greg, Thu Feb 16 09:49:29 1995 UTC

# Line 24 | Line 24 | static char SCCSid[] = "$SunId$ LBL";
24  
25   #include  <errno.h>
26  
27 + #include  <math.h>
28 +
29   #include  "calcomp.h"
30  
31   #define  MAXLINE        256             /* maximum line length */
# Line 32 | Line 34 | static char SCCSid[] = "$SunId$ LBL";
34  
35   #define  isdecimal(c)   (isdigit(c) || (c) == '.')
36  
37 < #ifndef atof
36 < extern double  atof();
37 < #endif
38 < extern double  pow();
39 < 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 124 | 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 148 | 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 371 | Line 425 | scan()                         /* scan next character, return literal next
425  
426  
427   char *
428 < ltoa(l)                         /* convert long to ascii */
428 > long2ascii(l)                         /* convert long to ascii */
429   long  l;
430   {
431      static char  buf[16];
# Line 405 | Line 459 | char  *err;
459          if (infile != NULL) eputs(infile);
460          if (lineno != 0) {
461              eputs(infile != NULL ? ", line " : "line ");
462 <            eputs(ltoa((long)lineno));
462 >            eputs(long2ascii((long)lineno));
463          }
464 <        eputs(": syntax error:\n");
464 >        eputs(":\n");
465      }
466      eputs(linbuf);
467      if (linbuf[strlen(linbuf)-1] != '\n')

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines