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

Comparing ray/src/common/caldefn.c (file contents):
Revision 1.10 by greg, Mon Apr 29 08:33:13 1991 UTC vs.
Revision 2.16 by schorsch, Sat Jun 7 12:50:20 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  Store variable definitions.
6   *
# Line 20 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17   *  5/31/90  Added conditional compile (REDEFW) for redefinition warning.
18   *
19   *  4/23/91  Added ':' assignment for constant expressions
20 + *
21 + *  8/7/91  Added optional context path to append to variable names
22 + *
23 + *  5/17/2001  Fixed clock counter wrapping behavior
24 + *
25 + *  2/19/03     Eliminated conditional compiles in favor of esupport extern.
26   */
27  
28 + #include "copyright.h"
29 +
30   #include  <stdio.h>
31  
32 + #include  <string.h>
33 +
34   #include  <ctype.h>
35  
36   #include  "calcomp.h"
37  
38 < #ifndef  NHASH
39 < #define  NHASH          521             /* hash size (a prime!) */
38 > #ifndef  NHASH
39 > #define  NHASH          521             /* hash size (a prime!) */
40   #endif
41  
42 < #define  newnode()      (EPNODE *)ecalloc(1, sizeof(EPNODE))
42 > #define  hash(s)        (shash(s)%NHASH)
43  
44 < extern char  *ecalloc(), *savestr();
44 > #define  newnode()      (EPNODE *)ecalloc(1, sizeof(EPNODE))
45  
46   static double  dvalue();
47  
48 < long  eclock = -1;                      /* value storage timer */
48 > #define  MAXCLOCK       (1L<<31)        /* clock wrap value */
49  
50 + unsigned long  eclock = 0;              /* value storage timer */
51 +
52 + #define  MAXCNTX        1023            /* maximum context length */
53 +
54 + static char  context[MAXCNTX+1];        /* current context path */
55 +
56   static VARDEF  *hashtbl[NHASH];         /* definition list */
57   static int  htndx;                      /* index for */        
58   static VARDEF  *htpos;                  /* ...dfirst() and */
46 #ifdef  OUTCHAN
59   static EPNODE  *ochpos;                 /* ...dnext */
60   static EPNODE  *outchan;
49 #endif
61  
62 < #ifdef  FUNCTION
63 < EPNODE  *curfunc;
53 < #define  dname(ep)      ((ep)->v.kid->type == SYM ? \
62 > EPNODE  *curfunc = NULL;
63 > #define  dname(ep)      ((ep)->v.kid->type == SYM ? \
64                          (ep)->v.kid->v.name : \
65                          (ep)->v.kid->v.kid->v.name)
56 #else
57 #define  dname(ep)      ((ep)->v.kid->v.name)
58 #endif
66  
67  
68 < fcompile(fname)                 /* get definitions from a file */
69 < char  *fname;
68 > void
69 > fcompile(                       /* get definitions from a file */
70 >        char  *fname
71 > )
72   {
73      FILE  *fp;
74  
# Line 72 | Line 81 | char  *fname;
81      }
82      initfile(fp, fname, 0);
83      while (nextc != EOF)
84 <        loaddefn();
84 >        getstatement();
85      if (fname != NULL)
86          fclose(fp);
87   }
88  
89  
90 < scompile(str, fn, ln)           /* get definitions from a string */
91 < char  *str;
92 < char  *fn;
93 < int  ln;
90 > void
91 > scompile(               /* get definitions from a string */
92 >        char  *str,
93 >        char  *fn,
94 >        int  ln
95 > )
96   {
97      initstr(str, fn, ln);
98      while (nextc != EOF)
99 <        loaddefn();
99 >        getstatement();
100   }
101  
102  
103   double
104 < varvalue(vname)                 /* return a variable's value */
105 < char  *vname;
104 > varvalue(                       /* return a variable's value */
105 >        char  *vname
106 > )
107   {
108      return(dvalue(vname, dlookup(vname)));
109   }
110  
111  
112   double
113 < evariable(ep)                   /* evaluate a variable */
114 < EPNODE  *ep;
113 > evariable(                      /* evaluate a variable */
114 >        EPNODE  *ep
115 > )
116   {
117      register VARDEF  *dp = ep->v.ln;
118  
# Line 107 | Line 120 | EPNODE  *ep;
120   }
121  
122  
123 < varset(vname, assign, val)      /* set a variable's value */
124 < char  *vname;
125 < int  assign;
126 < double  val;
123 > void
124 > varset(         /* set a variable's value */
125 >        char  *vname,
126 >        int  assign,
127 >        double  val
128 > )
129   {
130 +    char  *qname;
131      register EPNODE  *ep1, *ep2;
132 +                                        /* get qualified name */
133 +    qname = qualname(vname, 0);
134                                          /* check for quick set */
135 <    if ((ep1 = dlookup(vname)) != NULL && ep1->v.kid->type == SYM) {
135 >    if ((ep1 = dlookup(qname)) != NULL && ep1->v.kid->type == SYM) {
136          ep2 = ep1->v.kid->sibling;
137          if (ep2->type == NUM) {
138              ep2->v.num = val;
# Line 133 | Line 151 | double  val;
151      ep2->type = NUM;
152      ep2->v.num = val;
153      addekid(ep1, ep2);
154 <    dremove(vname);
155 <    dpush(ep1);
154 >    dremove(qname);
155 >    dpush(qname, ep1);
156   }
157  
158  
159 < dclear(name)                    /* delete variable definitions of name */
160 < char  *name;
159 > void
160 > dclear(                 /* delete variable definitions of name */
161 >        char  *name
162 > )
163   {
164      register EPNODE  *ep;
165  
166      while ((ep = dpop(name)) != NULL) {
167          if (ep->type == ':') {
168 <            dpush(ep);          /* don't clear constants */
168 >            dpush(name, ep);            /* don't clear constants */
169              return;
170          }
171          epfree(ep);
# Line 153 | Line 173 | char  *name;
173   }
174  
175  
176 < dremove(name)                   /* delete all definitions of name */
177 < char  *name;
176 > void
177 > dremove(                        /* delete all definitions of name */
178 >        char  *name
179 > )
180   {
181      register EPNODE  *ep;
182  
# Line 163 | Line 185 | char  *name;
185   }
186  
187  
188 < vardefined(name)        /* return non-zero if variable defined */
189 < char  *name;
188 > int
189 > vardefined(     /* return non-zero if variable defined */
190 >        char  *name
191 > )
192   {
193      register EPNODE  *dp;
194  
# Line 172 | Line 196 | char  *name;
196   }
197  
198  
199 < #ifdef  OUTCHAN
200 < chanout(cs)                     /* set output channels */
201 < int  (*cs)();
199 > char *
200 > setcontext(                     /* set a new context path */
201 >        register char  *ctx
202 > )
203   {
204 +    register char  *cpp;
205 +
206 +    if (ctx == NULL)
207 +        return(context);                /* just asking */
208 +    while (*ctx == CNTXMARK)
209 +        ctx++;                          /* skip past marks */
210 +    if (!*ctx) {
211 +        context[0] = '\0';              /* empty means clear context */
212 +        return(context);
213 +    }
214 +    cpp = context;                      /* start context with mark */
215 +    *cpp++ = CNTXMARK;
216 +    do {                                /* carefully copy new context */
217 +        if (cpp >= context+MAXCNTX)
218 +            break;                      /* just copy what we can */
219 +        if (isid(*ctx))
220 +            *cpp++ = *ctx++;
221 +        else {
222 +            *cpp++ = '_'; ctx++;
223 +        }
224 +    } while (*ctx);
225 +    while (cpp[-1] == CNTXMARK)         /* cannot end in context mark */
226 +        cpp--;
227 +    *cpp = '\0';
228 +    return(context);
229 + }
230 +
231 +
232 + char *
233 + pushcontext(            /* push on another context */
234 +        char  *ctx
235 + )
236 + {
237 +    char  oldcontext[MAXCNTX+1];
238 +    register int  n;
239 +
240 +    strcpy(oldcontext, context);        /* save old context */
241 +    setcontext(ctx);                    /* set new context */
242 +    n = strlen(context);                /* tack on old */
243 +    if (n+strlen(oldcontext) > MAXCNTX) {
244 +        strncpy(context+n, oldcontext, MAXCNTX-n);
245 +        context[MAXCNTX] = '\0';
246 +    } else
247 +        strcpy(context+n, oldcontext);
248 +    return(context);
249 + }
250 +
251 +
252 + char *
253 + popcontext(void)                        /* pop off top context */
254 + {
255 +    register char  *cp1, *cp2;
256 +
257 +    if (!context[0])                    /* nothing left to pop */
258 +        return(context);
259 +    cp2 = context;                      /* find mark */
260 +    while (*++cp2 && *cp2 != CNTXMARK)
261 +        ;
262 +    cp1 = context;                      /* copy tail to front */
263 +    while (*cp1++ = *cp2++)
264 +        ;
265 +    return(context);
266 + }
267 +
268 +
269 + char *
270 + qualname(               /* get qualified name */
271 +        register char  *nam,
272 +        int  lvl
273 + )
274 + {
275 +    static char  nambuf[MAXWORD+1];
276 +    register char  *cp = nambuf, *cpp;
277 +                                /* check for explicit local */
278 +    if (*nam == CNTXMARK)
279 +        if (lvl > 0)            /* only action is to refuse search */
280 +            return(NULL);
281 +        else
282 +            nam++;
283 +    else if (nam == nambuf)     /* check for repeat call */
284 +        return(lvl > 0 ? NULL : nam);
285 +                                /* copy name to static buffer */
286 +    while (*nam) {
287 +        if (cp >= nambuf+MAXWORD)
288 +                goto toolong;
289 +        *cp++ = *nam++;
290 +    }
291 +                                /* check for explicit global */
292 +    if (cp > nambuf && cp[-1] == CNTXMARK) {
293 +        if (lvl > 0)
294 +            return(NULL);
295 +        *--cp = '\0';
296 +        return(nambuf);         /* already qualified */
297 +    }
298 +    cpp = context;              /* else skip the requested levels */
299 +    while (lvl-- > 0) {
300 +        if (!*cpp)
301 +            return(NULL);       /* return NULL if past global level */
302 +        while (*++cpp && *cpp != CNTXMARK)
303 +            ;
304 +    }
305 +    while (*cpp) {              /* copy context to static buffer */
306 +        if (cp >= nambuf+MAXWORD)
307 +            goto toolong;
308 +        *cp++ = *cpp++;
309 +    }
310 + toolong:
311 +    *cp = '\0';
312 +    return(nambuf);             /* return qualified name */
313 + }
314 +
315 +
316 + int
317 + incontext(                      /* is qualified name in current context? */
318 +        register char  *qn
319 + )
320 + {
321 +    if (!context[0])                    /* global context accepts all */
322 +        return(1);
323 +    while (*qn && *qn != CNTXMARK)      /* find context mark */
324 +        qn++;
325 +    return(!strcmp(qn, context));
326 + }
327 +
328 +
329 + void
330 + chanout(                        /* set output channels */
331 +        void  (*cs)(int n, double v)
332 + )
333 + {
334      register EPNODE  *ep;
335  
336      for (ep = outchan; ep != NULL; ep = ep->sibling)
337          (*cs)(ep->v.kid->v.chan, evalue(ep->v.kid->sibling));
338  
339   }
185 #endif
340  
341  
342 < dcleanup(lvl)                   /* clear definitions (0->vars,1->consts,2->output) */
343 < int  lvl;
342 > void
343 > dcleanup(               /* clear definitions (0->vars,1->output,2->consts) */
344 >        int  lvl
345 > )
346   {
347      register int  i;
348      register VARDEF  *vp;
349      register EPNODE  *ep;
350 <
350 >                                /* if context is global, clear all */
351      for (i = 0; i < NHASH; i++)
352          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
353 <            if (lvl >= 1)
354 <                dremove(vp->name);
355 <            else
356 <                dclear(vp->name);
357 < #ifdef  OUTCHAN
358 <    if (lvl >= 2) {
353 >            if (incontext(vp->name))
354 >                if (lvl >= 2)
355 >                    dremove(vp->name);
356 >                else
357 >                    dclear(vp->name);
358 >    if (lvl >= 1) {
359          for (ep = outchan; ep != NULL; ep = ep->sibling)
360              epfree(ep);
361          outchan = NULL;
362      }
207 #endif
363   }
364  
365  
366   EPNODE *
367 < dlookup(name)                   /* look up a definition */
368 < char  *name;
367 > dlookup(                        /* look up a definition */
368 >        char  *name
369 > )
370   {
371      register VARDEF  *vp;
372      
373      if ((vp = varlookup(name)) == NULL)
374 <        return(NULL);
374 >        return(NULL);
375      return(vp->def);
376   }
377  
378  
379   VARDEF *
380 < varlookup(name)                 /* look up a variable */
381 < char  *name;
380 > varlookup(                      /* look up a variable */
381 >        char  *name
382 > )
383   {
384 +    int  lvl = 0;
385 +    register char  *qname;
386      register VARDEF  *vp;
387 <    
388 <    for (vp = hashtbl[hash(name)]; vp != NULL; vp = vp->next)
389 <        if (!strcmp(vp->name, name))
390 <            return(vp);
387 >                                /* find most qualified match */
388 >    while ((qname = qualname(name, lvl++)) != NULL)
389 >        for (vp = hashtbl[hash(qname)]; vp != NULL; vp = vp->next)
390 >            if (!strcmp(vp->name, qname))
391 >                return(vp);
392      return(NULL);
393   }
394  
395  
396   VARDEF *
397 < varinsert(name)                 /* get a link to a variable */
398 < char  *name;
397 > varinsert(                      /* get a link to a variable */
398 >        char  *name
399 > )
400   {
401      register VARDEF  *vp;
402 <    int  hv;
402 >    int  hv;
403      
404 <    hv = hash(name);
405 <    for (vp = hashtbl[hv]; vp != NULL; vp = vp->next)
406 <        if (!strcmp(vp->name, name)) {
407 <            vp->nlinks++;
247 <            return(vp);
248 <        }
404 >    if ((vp = varlookup(name)) != NULL) {
405 >        vp->nlinks++;
406 >        return(vp);
407 >    }
408      vp = (VARDEF *)emalloc(sizeof(VARDEF));
409 +    vp->lib = liblookup(name);
410 +    if (vp->lib == NULL)                /* if name not in library */
411 +        name = qualname(name, 0);       /* use fully qualified version */
412 +    hv = hash(name);
413      vp->name = savestr(name);
414      vp->nlinks = 1;
415      vp->def = NULL;
253    vp->lib = NULL;
416      vp->next = hashtbl[hv];
417      hashtbl[hv] = vp;
418      return(vp);
419   }
420  
421  
422 < varfree(ln)                             /* release link to variable */
423 < register VARDEF  *ln;
422 > void
423 > libupdate(                      /* update library links */
424 >        char  *fn
425 > )
426   {
427 +    register int  i;
428      register VARDEF  *vp;
429 <    int  hv;
429 >                                        /* if fn is NULL then relink all */
430 >    for (i = 0; i < NHASH; i++)
431 >        for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
432 >            if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name))
433 >                vp->lib = liblookup(vp->name);
434 > }
435  
436 +
437 + void
438 + varfree(                                /* release link to variable */
439 +        register VARDEF  *ln
440 + )
441 + {
442 +    register VARDEF  *vp;
443 +    int  hv;
444 +
445      if (--ln->nlinks > 0)
446 <        return;                         /* still active */
446 >        return;                         /* still active */
447  
448      hv = hash(ln->name);
449      vp = hashtbl[hv];
450      if (vp == ln)
451 <        hashtbl[hv] = vp->next;
451 >        hashtbl[hv] = vp->next;
452      else {
453 <        while (vp->next != ln)          /* must be in list */
454 <                vp = vp->next;
455 <        vp->next = ln->next;
453 >        while (vp->next != ln)          /* must be in list */
454 >                vp = vp->next;
455 >        vp->next = ln->next;
456      }
457      freestr(ln->name);
458      efree((char *)ln);
# Line 281 | Line 460 | register VARDEF  *ln;
460  
461  
462   EPNODE *
463 < dfirst()                        /* return pointer to first definition */
463 > dfirst(void)                    /* return pointer to first definition */
464   {
465      htndx = 0;
466      htpos = NULL;
288 #ifdef  OUTCHAN
467      ochpos = outchan;
290 #endif
468      return(dnext());
469   }
470  
471  
472   EPNODE *
473 < dnext()                         /* return pointer to next definition */
473 > dnext(void)                             /* return pointer to next definition */
474   {
475      register EPNODE  *ep;
476 +    register char  *nm;
477  
478      while (htndx < NHASH) {
479 <        if (htpos == NULL)
480 <                htpos = hashtbl[htndx++];
481 <        while (htpos != NULL) {
482 <            ep = htpos->def;
483 <            htpos = htpos->next;
484 <            if (ep != NULL)
485 <                return(ep);
486 <        }
479 >        if (htpos == NULL)
480 >                htpos = hashtbl[htndx++];
481 >        while (htpos != NULL) {
482 >            ep = htpos->def;
483 >            nm = htpos->name;
484 >            htpos = htpos->next;
485 >            if (ep != NULL && incontext(nm))
486 >                return(ep);
487 >        }
488      }
310 #ifdef  OUTCHAN
489      if ((ep = ochpos) != NULL)
490 <        ochpos = ep->sibling;
490 >        ochpos = ep->sibling;
491      return(ep);
314 #else
315    return(NULL);
316 #endif
492   }
493  
494  
495   EPNODE *
496 < dpop(name)                      /* pop a definition */
497 < char  *name;
496 > dpop(                   /* pop a definition */
497 >        char  *name
498 > )
499   {
500      register VARDEF  *vp;
501      register EPNODE  *dp;
502      
503      if ((vp = varlookup(name)) == NULL || vp->def == NULL)
504 <        return(NULL);
504 >        return(NULL);
505      dp = vp->def;
506      vp->def = dp->sibling;
507      varfree(vp);
# Line 333 | Line 509 | char  *name;
509   }
510  
511  
512 < dpush(ep)                       /* push on a definition */
513 < register EPNODE  *ep;
512 > void
513 > dpush(                  /* push on a definition */
514 >        char  *nm,
515 >        register EPNODE  *ep
516 > )
517   {
518      register VARDEF  *vp;
519  
520 <    vp = varinsert(dname(ep));
520 >    vp = varinsert(nm);
521      ep->sibling = vp->def;
522      vp->def = ep;
523   }
524  
525  
526 < #ifdef  OUTCHAN
527 < addchan(sp)                     /* add an output channel assignment */
528 < EPNODE  *sp;
526 > void
527 > addchan(                        /* add an output channel assignment */
528 >        EPNODE  *sp
529 > )
530   {
531 <    int  ch = sp->v.kid->v.chan;
531 >    int  ch = sp->v.kid->v.chan;
532      register EPNODE  *ep, *epl;
533  
534      for (epl = NULL, ep = outchan; ep != NULL; epl = ep, ep = ep->sibling)
# Line 372 | Line 552 | EPNODE  *sp;
552      sp->sibling = NULL;
553  
554   }
375 #endif
555  
556  
557 < loaddefn()                      /* load next definition */
557 > void
558 > getstatement(void)                      /* get next statement */
559   {
560      register EPNODE  *ep;
561 <    EPNODE  *lastdef;
561 >    char  *qname;
562 >    register VARDEF  *vdef;
563  
564      if (nextc == ';') {         /* empty statement */
565          scan();
566          return;
567      }
568 < #ifdef  OUTCHAN
569 <    if (nextc == '$') {         /* channel assignment */
568 >    if (esupport&E_OUTCHAN &&
569 >                nextc == '$') {         /* channel assignment */
570          ep = getchan();
571          addchan(ep);
572 <    } else
392 < #endif
393 <    {                           /* ordinary definition */
572 >    } else {                            /* ordinary definition */
573          ep = getdefn();
574 < #ifdef  REDEFW
575 <        if ((lastdef = dlookup(dname(ep))) != NULL) {
576 <            wputs(dname(ep));
577 <            if (lastdef->type == ':')
578 <                wputs(": redefined constant expression\n");
579 <            else
580 <                wputs(": redefined\n");
581 <        }
582 < #ifdef  FUNCTION
583 <        else if (ep->v.kid->type == FUNC &&
584 <                        liblookup(ep->v.kid->v.kid->v.name) != NULL) {
585 <            wputs(ep->v.kid->v.kid->v.name);
407 <            wputs(": redefined library function\n");
408 <        }
409 < #endif
410 < #endif
574 >        qname = qualname(dname(ep), 0);
575 >        if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL)
576 >            if (vdef->def != NULL && epcmp(ep, vdef->def)) {
577 >                wputs(qname);
578 >                if (vdef->def->type == ':')
579 >                    wputs(": redefined constant expression\n");
580 >                else
581 >                    wputs(": redefined\n");
582 >            } else if (ep->v.kid->type == FUNC && vdef->lib != NULL) {
583 >                wputs(qname);
584 >                wputs(": definition hides library function\n");
585 >            }
586          if (ep->type == ':')
587 <            dremove(dname(ep));
587 >            dremove(qname);
588          else
589 <            dclear(dname(ep));
590 <        dpush(ep);
589 >            dclear(qname);
590 >        dpush(qname, ep);
591      }
592      if (nextc != EOF) {
593          if (nextc != ';')
# Line 423 | Line 598 | loaddefn()                     /* load next definition */
598  
599  
600   EPNODE *
601 < getdefn()                       /* A -> SYM = E1 */
602 <                                /*      SYM : E1 */
603 <                                /*      FUNC(SYM,..) = E1 */
604 <                                /*      FUNC(SYM,..) : E1 */
601 > getdefn(void)
602 >        /* A -> SYM = E1 */
603 >        /*      SYM : E1 */
604 >        /*      FUNC(SYM,..) = E1 */
605 >        /*      FUNC(SYM,..) : E1 */
606   {
607      register EPNODE  *ep1, *ep2;
608  
609 <    if (!isalpha(nextc))
609 >    if (!isalpha(nextc) && nextc != CNTXMARK)
610          syntax("illegal variable name");
611  
612      ep1 = newnode();
613      ep1->type = SYM;
614      ep1->v.name = savestr(getname());
615  
616 < #ifdef  FUNCTION
441 <    if (nextc == '(') {
616 >    if (esupport&E_FUNCTION && nextc == '(') {
617          ep2 = newnode();
618          ep2->type = FUNC;
619          addekid(ep2, ep1);
# Line 456 | Line 631 | getdefn()                      /* A -> SYM = E1 */
631              syntax("')' expected");
632          scan();
633          curfunc = ep1;
634 <    } else
460 <        curfunc = NULL;
461 < #endif
634 >    }
635  
636      if (nextc != '=' && nextc != ':')
637          syntax("'=' or ':' expected");
# Line 469 | Line 642 | getdefn()                      /* A -> SYM = E1 */
642      addekid(ep2, ep1);
643      addekid(ep2, getE1());
644  
645 <    if (
473 < #ifdef  FUNCTION
474 <            ep1->type == SYM &&
475 < #endif
476 <            ep1->sibling->type != NUM) {
645 >    if (ep1->type == SYM && ep1->sibling->type != NUM) {
646          ep1 = newnode();
647          ep1->type = TICK;
648 <        ep1->v.tick = -1;
648 >        ep1->v.tick = 0;
649          addekid(ep2, ep1);
650          ep1 = newnode();
651          ep1->type = NUM;
652          addekid(ep2, ep1);
653      }
654 +    curfunc = NULL;
655  
656      return(ep2);
657   }
658  
659  
490 #ifdef  OUTCHAN
660   EPNODE *
661 < getchan()                       /* A -> $N = E1 */
661 > getchan(void)                   /* A -> $N = E1 */
662   {
663      register EPNODE  *ep1, *ep2;
664  
# Line 512 | Line 681 | getchan()                      /* A -> $N = E1 */
681  
682      return(ep2);
683   }
515 #endif
684  
685  
686  
# Line 522 | Line 690 | getchan()                      /* A -> $N = E1 */
690  
691  
692   static double
693 < dvalue(name, d)                 /* evaluate a variable */
694 < char  *name;
695 < EPNODE  *d;
693 > dvalue(                 /* evaluate a variable */
694 > char  *name,
695 > EPNODE  *d
696 > )
697   {
698      register EPNODE  *ep1, *ep2;
699      
# Line 537 | Line 706 | EPNODE  *d;
706      if (ep1->type == NUM)
707          return(ep1->v.num);                     /* return if number */
708      ep2 = ep1->sibling;                         /* check time */
709 <    if (ep2->v.tick < 0 || ep2->v.tick < eclock) {
710 <        ep2->v.tick = d->type == ':' ? 1L<<30 : eclock;
709 >    if (eclock >= MAXCLOCK)
710 >        eclock = 1;                             /* wrap clock counter */
711 >    if (ep2->v.tick < MAXCLOCK &&
712 >                ep2->v.tick == 0 | ep2->v.tick != eclock) {
713 >        ep2->v.tick = d->type == ':' ? MAXCLOCK : eclock;
714          ep2 = ep2->sibling;
715          ep2->v.num = evalue(ep1);               /* needs new value */
716      } else
717          ep2 = ep2->sibling;                     /* else reuse old value */
718  
719      return(ep2->v.num);
548 }
549
550
551 static int
552 hash(s)                         /* hash a string */
553 register char  *s;
554 {
555    register int  rval = 0;
556
557    while (*s)
558        rval += *s++;
559    
560    return(rval % NHASH);
720   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines