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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines