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.15 by greg, Thu Aug 8 12:28:30 1991 UTC vs.
Revision 2.12 by greg, Sat Feb 22 02:07:21 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 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 + /* ====================================================================
29 + * The Radiance Software License, Version 1.0
30 + *
31 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
32 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
33 + *
34 + * Redistribution and use in source and binary forms, with or without
35 + * modification, are permitted provided that the following conditions
36 + * are met:
37 + *
38 + * 1. Redistributions of source code must retain the above copyright
39 + *         notice, this list of conditions and the following disclaimer.
40 + *
41 + * 2. Redistributions in binary form must reproduce the above copyright
42 + *       notice, this list of conditions and the following disclaimer in
43 + *       the documentation and/or other materials provided with the
44 + *       distribution.
45 + *
46 + * 3. The end-user documentation included with the redistribution,
47 + *           if any, must include the following acknowledgment:
48 + *             "This product includes Radiance software
49 + *                 (http://radsite.lbl.gov/)
50 + *                 developed by the Lawrence Berkeley National Laboratory
51 + *               (http://www.lbl.gov/)."
52 + *       Alternately, this acknowledgment may appear in the software itself,
53 + *       if and wherever such third-party acknowledgments normally appear.
54 + *
55 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
56 + *       and "The Regents of the University of California" must
57 + *       not be used to endorse or promote products derived from this
58 + *       software without prior written permission. For written
59 + *       permission, please contact [email protected].
60 + *
61 + * 5. Products derived from this software may not be called "Radiance",
62 + *       nor may "Radiance" appear in their name, without prior written
63 + *       permission of Lawrence Berkeley National Laboratory.
64 + *
65 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
66 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
67 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
68 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
69 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
70 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
71 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
72 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
73 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
74 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
75 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76 + * SUCH DAMAGE.
77 + * ====================================================================
78 + *
79 + * This software consists of voluntary contributions made by many
80 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
81 + * information on Lawrence Berkeley National Laboratory, please see
82 + * <http://www.lbl.gov/>.
83 + */
84 +
85   #include  <stdio.h>
86  
87 + #include  <string.h>
88 +
89   #include  <ctype.h>
90  
91   #include  "calcomp.h"
92  
93 < #ifndef  NHASH
94 < #define  NHASH          521             /* hash size (a prime!) */
93 > #ifndef  NHASH
94 > #define  NHASH          521             /* hash size (a prime!) */
95   #endif
96  
97 < #define  newnode()      (EPNODE *)ecalloc(1, sizeof(EPNODE))
97 > #define  hash(s)        (shash(s)%NHASH)
98  
99 < extern char  *ecalloc(), *savestr(), *strcpy();
99 > #define  newnode()      (EPNODE *)ecalloc(1, sizeof(EPNODE))
100  
101   static double  dvalue();
102  
103 < long  eclock = -1;                      /* value storage timer */
103 > #define  MAXCLOCK       (1L<<31)        /* clock wrap value */
104  
105 < static char  context[MAXWORD];          /* current context path */
105 > unsigned long  eclock = 0;              /* value storage timer */
106  
107 + #define  MAXCNTX        1023            /* maximum context length */
108 +
109 + static char  context[MAXCNTX+1];        /* current context path */
110 +
111   static VARDEF  *hashtbl[NHASH];         /* definition list */
112   static int  htndx;                      /* index for */        
113   static VARDEF  *htpos;                  /* ...dfirst() and */
50 #ifdef  OUTCHAN
114   static EPNODE  *ochpos;                 /* ...dnext */
115   static EPNODE  *outchan;
53 #endif
116  
117 < #ifdef  FUNCTION
118 < EPNODE  *curfunc;
57 < #define  dname(ep)      ((ep)->v.kid->type == SYM ? \
117 > EPNODE  *curfunc = NULL;
118 > #define  dname(ep)      ((ep)->v.kid->type == SYM ? \
119                          (ep)->v.kid->v.name : \
120                          (ep)->v.kid->v.kid->v.name)
60 #else
61 #define  dname(ep)      ((ep)->v.kid->v.name)
62 #endif
121  
122  
123 + void
124   fcompile(fname)                 /* get definitions from a file */
125   char  *fname;
126   {
# Line 82 | Line 141 | char  *fname;
141   }
142  
143  
144 + void
145   scompile(str, fn, ln)           /* get definitions from a string */
146   char  *str;
147   char  *fn;
# Line 103 | Line 163 | char  *vname;
163  
164   double
165   evariable(ep)                   /* evaluate a variable */
166 < EPNODE  *ep;
166 > EPNODE  *ep;
167   {
168      register VARDEF  *dp = ep->v.ln;
169  
# Line 111 | Line 171 | EPNODE  *ep;
171   }
172  
173  
174 + void
175   varset(vname, assign, val)      /* set a variable's value */
176   char  *vname;
177   int  assign;
178 < double  val;
178 > double  val;
179   {
180      char  *qname;
181      register EPNODE  *ep1, *ep2;
# Line 145 | Line 206 | double  val;
206   }
207  
208  
209 + void
210   dclear(name)                    /* delete variable definitions of name */
211   char  *name;
212   {
# Line 160 | Line 222 | char  *name;
222   }
223  
224  
225 + void
226   dremove(name)                   /* delete all definitions of name */
227   char  *name;
228   {
# Line 170 | Line 233 | char  *name;
233   }
234  
235  
236 + int
237   vardefined(name)        /* return non-zero if variable defined */
238   char  *name;
239   {
# Line 187 | Line 251 | register char  *ctx;
251  
252      if (ctx == NULL)
253          return(context);                /* just asking */
254 +    while (*ctx == CNTXMARK)
255 +        ctx++;                          /* skip past marks */
256      if (!*ctx) {
257 <        context[0] = '\0';              /* clear context */
257 >        context[0] = '\0';              /* empty means clear context */
258          return(context);
259      }
260 <    cpp = context;                      /* else copy it (carefully!) */
261 <    if (*ctx != CNTXMARK)
262 <        *cpp++ = CNTXMARK;              /* make sure there's a mark */
263 <    do {
264 <        if (cpp >= context+MAXWORD-1) {
199 <            *cpp = '\0';
200 <            wputs(context);
201 <            wputs(": context path too long\n");
202 <            return(NULL);
203 <        }
260 >    cpp = context;                      /* start context with mark */
261 >    *cpp++ = CNTXMARK;
262 >    do {                                /* carefully copy new context */
263 >        if (cpp >= context+MAXCNTX)
264 >            break;                      /* just copy what we can */
265          if (isid(*ctx))
266              *cpp++ = *ctx++;
267          else {
268              *cpp++ = '_'; ctx++;
269          }
270      } while (*ctx);
271 +    while (cpp[-1] == CNTXMARK)         /* cannot end in context mark */
272 +        cpp--;
273      *cpp = '\0';
274      return(context);
275   }
276  
277  
278   char *
279 + pushcontext(ctx)                /* push on another context */
280 + char  *ctx;
281 + {
282 +    extern char  *strncpy(), *strcpy();
283 +    char  oldcontext[MAXCNTX+1];
284 +    register int  n;
285 +
286 +    strcpy(oldcontext, context);        /* save old context */
287 +    setcontext(ctx);                    /* set new context */
288 +    n = strlen(context);                /* tack on old */
289 +    if (n+strlen(oldcontext) > MAXCNTX) {
290 +        strncpy(context+n, oldcontext, MAXCNTX-n);
291 +        context[MAXCNTX] = '\0';
292 +    } else
293 +        strcpy(context+n, oldcontext);
294 +    return(context);
295 + }
296 +
297 +
298 + char *
299 + popcontext()                    /* pop off top context */
300 + {
301 +    register char  *cp1, *cp2;
302 +
303 +    if (!context[0])                    /* nothing left to pop */
304 +        return(context);
305 +    cp2 = context;                      /* find mark */
306 +    while (*++cp2 && *cp2 != CNTXMARK)
307 +        ;
308 +    cp1 = context;                      /* copy tail to front */
309 +    while (*cp1++ = *cp2++)
310 +        ;
311 +    return(context);
312 + }
313 +
314 +
315 + char *
316   qualname(nam, lvl)              /* get qualified name */
317   register char  *nam;
318   int  lvl;
319   {
320 <    static char  nambuf[MAXWORD];
321 <    register char  *cp = nambuf, *cpp = context;
322 <                                /* check for explicit global */
320 >    static char  nambuf[MAXWORD+1];
321 >    register char  *cp = nambuf, *cpp;
322 >                                /* check for explicit local */
323      if (*nam == CNTXMARK)
324 <        return(lvl > 0 ? NULL : nam+1);
325 <                                /* check for repeat call */
326 <    if (nam == nambuf)
327 <        return(lvl > 0 ? NULL : nambuf);
324 >        if (lvl > 0)            /* only action is to refuse search */
325 >            return(NULL);
326 >        else
327 >            nam++;
328 >    else if (nam == nambuf)     /* check for repeat call */
329 >        return(lvl > 0 ? NULL : nam);
330                                  /* copy name to static buffer */
331      while (*nam) {
332 <        if (cp >= nambuf+MAXWORD-1)
332 >        if (cp >= nambuf+MAXWORD)
333                  goto toolong;
334 <        if ((*cp++ = *nam++) == CNTXMARK)
233 <            cpp = NULL;         /* flag a qualified name */
334 >        *cp++ = *nam++;
335      }
336 <    if (cpp == NULL) {
336 >                                /* check for explicit global */
337 >    if (cp > nambuf && cp[-1] == CNTXMARK) {
338          if (lvl > 0)
339 <            return(NULL);               /* no higher level */
340 <        if (cp[-1] == CNTXMARK) {
341 <            cp--; cpp = context;        /* current context explicitly */
342 <        } else
343 <            cpp = "";                   /* else fully qualified */
344 <    } else                      /* else skip the requested levels */
345 <        while (lvl-- > 0) {
346 <            if (!*cpp)
347 <                return(NULL);   /* return NULL if past global level */
348 <            while (*++cpp && *cpp != CNTXMARK)
349 <                ;
248 <        }
339 >            return(NULL);
340 >        *--cp = '\0';
341 >        return(nambuf);         /* already qualified */
342 >    }
343 >    cpp = context;              /* else skip the requested levels */
344 >    while (lvl-- > 0) {
345 >        if (!*cpp)
346 >            return(NULL);       /* return NULL if past global level */
347 >        while (*++cpp && *cpp != CNTXMARK)
348 >            ;
349 >    }
350      while (*cpp) {              /* copy context to static buffer */
351 <        if (cp >= nambuf+MAXWORD-1)
351 >        if (cp >= nambuf+MAXWORD)
352              goto toolong;
353          *cp++ = *cpp++;
354      }
254    *cp = '\0';
255    return(nambuf);             /* return qualified name */
355   toolong:
356      *cp = '\0';
357 <    eputs(nambuf);
259 <    eputs(": name too long\n");
260 <    quit(1);
357 >    return(nambuf);             /* return qualified name */
358   }
359  
360  
361 + int
362   incontext(qn)                   /* is qualified name in current context? */
363   register char  *qn;
364   {
365 +    if (!context[0])                    /* global context accepts all */
366 +        return(1);
367      while (*qn && *qn != CNTXMARK)      /* find context mark */
368 <        ;
368 >        qn++;
369      return(!strcmp(qn, context));
370   }
371  
372  
373 < #ifdef  OUTCHAN
373 > void
374   chanout(cs)                     /* set output channels */
375   int  (*cs)();
376   {
# Line 280 | Line 380 | int  (*cs)();
380          (*cs)(ep->v.kid->v.chan, evalue(ep->v.kid->sibling));
381  
382   }
283 #endif
383  
384  
385 + void
386   dcleanup(lvl)           /* clear definitions (0->vars,1->output,2->consts) */
387   int  lvl;
388   {
# Line 292 | Line 392 | int  lvl;
392                                  /* if context is global, clear all */
393      for (i = 0; i < NHASH; i++)
394          for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
395 <            if (!context[0] || incontext(vp->name))
395 >            if (incontext(vp->name))
396                  if (lvl >= 2)
397                      dremove(vp->name);
398                  else
399                      dclear(vp->name);
300 #ifdef  OUTCHAN
400      if (lvl >= 1) {
401          for (ep = outchan; ep != NULL; ep = ep->sibling)
402              epfree(ep);
403          outchan = NULL;
404      }
306 #endif
405   }
406  
407  
# Line 314 | Line 412 | char  *name;
412      register VARDEF  *vp;
413      
414      if ((vp = varlookup(name)) == NULL)
415 <        return(NULL);
415 >        return(NULL);
416      return(vp->def);
417   }
418  
# Line 323 | Line 421 | VARDEF *
421   varlookup(name)                 /* look up a variable */
422   char  *name;
423   {
424 <    int  lvl = 0;
424 >    int  lvl = 0;
425      register char  *qname;
426      register VARDEF  *vp;
427 <                                /* find most qualified match */
427 >                                /* find most qualified match */
428      while ((qname = qualname(name, lvl++)) != NULL)
429          for (vp = hashtbl[hash(qname)]; vp != NULL; vp = vp->next)
430              if (!strcmp(vp->name, qname))
# Line 340 | Line 438 | varinsert(name)                        /* get a link to a variable */
438   char  *name;
439   {
440      register VARDEF  *vp;
441 <    int  hv;
441 >    int  hv;
442      
443      if ((vp = varlookup(name)) != NULL) {
444          vp->nlinks++;
445          return(vp);
446      }
349    name = qualname(name, 0);           /* use fully qualified name */
350    hv = hash(name);
447      vp = (VARDEF *)emalloc(sizeof(VARDEF));
448 +    vp->lib = liblookup(name);
449 +    if (vp->lib == NULL)                /* if name not in library */
450 +        name = qualname(name, 0);       /* use fully qualified version */
451 +    hv = hash(name);
452      vp->name = savestr(name);
453      vp->nlinks = 1;
454      vp->def = NULL;
355    vp->lib = NULL;
455      vp->next = hashtbl[hv];
456      hashtbl[hv] = vp;
457      return(vp);
458   }
459  
460  
461 + void
462 + libupdate(fn)                   /* update library links */
463 + char  *fn;
464 + {
465 +    register int  i;
466 +    register VARDEF  *vp;
467 +                                        /* if fn is NULL then relink all */
468 +    for (i = 0; i < NHASH; i++)
469 +        for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
470 +            if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name))
471 +                vp->lib = liblookup(vp->name);
472 + }
473 +
474 +
475 + void
476   varfree(ln)                             /* release link to variable */
477 < register VARDEF  *ln;
477 > register VARDEF  *ln;
478   {
479      register VARDEF  *vp;
480 <    int  hv;
480 >    int  hv;
481  
482      if (--ln->nlinks > 0)
483 <        return;                         /* still active */
483 >        return;                         /* still active */
484  
485      hv = hash(ln->name);
486      vp = hashtbl[hv];
487      if (vp == ln)
488 <        hashtbl[hv] = vp->next;
488 >        hashtbl[hv] = vp->next;
489      else {
490 <        while (vp->next != ln)          /* must be in list */
491 <                vp = vp->next;
492 <        vp->next = ln->next;
490 >        while (vp->next != ln)          /* must be in list */
491 >                vp = vp->next;
492 >        vp->next = ln->next;
493      }
494      freestr(ln->name);
495      efree((char *)ln);
# Line 387 | Line 501 | dfirst()                       /* return pointer to first definition */
501   {
502      htndx = 0;
503      htpos = NULL;
390 #ifdef  OUTCHAN
504      ochpos = outchan;
392 #endif
505      return(dnext());
506   }
507  
# Line 398 | Line 510 | EPNODE *
510   dnext()                         /* return pointer to next definition */
511   {
512      register EPNODE  *ep;
513 +    register char  *nm;
514  
515      while (htndx < NHASH) {
516 <        if (htpos == NULL)
517 <                htpos = hashtbl[htndx++];
518 <        while (htpos != NULL) {
519 <            ep = htpos->def;
520 <            htpos = htpos->next;
521 <            if (ep != NULL)
522 <                return(ep);
523 <        }
516 >        if (htpos == NULL)
517 >                htpos = hashtbl[htndx++];
518 >        while (htpos != NULL) {
519 >            ep = htpos->def;
520 >            nm = htpos->name;
521 >            htpos = htpos->next;
522 >            if (ep != NULL && incontext(nm))
523 >                return(ep);
524 >        }
525      }
412 #ifdef  OUTCHAN
526      if ((ep = ochpos) != NULL)
527 <        ochpos = ep->sibling;
527 >        ochpos = ep->sibling;
528      return(ep);
416 #else
417    return(NULL);
418 #endif
529   }
530  
531  
# Line 427 | Line 537 | char  *name;
537      register EPNODE  *dp;
538      
539      if ((vp = varlookup(name)) == NULL || vp->def == NULL)
540 <        return(NULL);
540 >        return(NULL);
541      dp = vp->def;
542      vp->def = dp->sibling;
543      varfree(vp);
# Line 435 | Line 545 | char  *name;
545   }
546  
547  
548 + void
549   dpush(nm, ep)                   /* push on a definition */
550   char  *nm;
551 < register EPNODE  *ep;
551 > register EPNODE  *ep;
552   {
553      register VARDEF  *vp;
554  
# Line 447 | Line 558 | register EPNODE  *ep;
558   }
559  
560  
561 < #ifdef  OUTCHAN
561 > void
562   addchan(sp)                     /* add an output channel assignment */
563 < EPNODE  *sp;
563 > EPNODE  *sp;
564   {
565 <    int  ch = sp->v.kid->v.chan;
565 >    int  ch = sp->v.kid->v.chan;
566      register EPNODE  *ep, *epl;
567  
568      for (epl = NULL, ep = outchan; ep != NULL; epl = ep, ep = ep->sibling)
# Line 475 | Line 586 | EPNODE  *sp;
586      sp->sibling = NULL;
587  
588   }
478 #endif
589  
590  
591 + void
592   getstatement()                  /* get next statement */
593   {
594      register EPNODE  *ep;
595      char  *qname;
596 <    EPNODE  *lastdef;
596 >    register VARDEF  *vdef;
597  
598      if (nextc == ';') {         /* empty statement */
599          scan();
600          return;
601      }
602 < #ifdef  OUTCHAN
603 <    if (nextc == '$') {         /* channel assignment */
602 >    if (esupport&E_OUTCHAN &&
603 >                nextc == '$') {         /* channel assignment */
604          ep = getchan();
605          addchan(ep);
606 <    } else
496 < #endif
497 <    {                           /* ordinary definition */
606 >    } else {                            /* ordinary definition */
607          ep = getdefn();
608          qname = qualname(dname(ep), 0);
609 < #ifdef  REDEFW
610 <        if ((lastdef = dlookup(qname)) != NULL) {
611 <            wputs(qname);
612 <            if (lastdef->type == ':')
613 <                wputs(": redefined constant expression\n");
614 <            else
615 <                wputs(": redefined\n");
616 <        }
617 < #ifdef  FUNCTION
618 <        else if (ep->v.kid->type == FUNC && liblookup(qname) != NULL) {
619 <            wputs(qname);
511 <            wputs(": definition hides library function\n");
512 <        }
513 < #endif
514 < #endif
609 >        if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL)
610 >            if (vdef->def != NULL && epcmp(ep, vdef->def)) {
611 >                wputs(qname);
612 >                if (vdef->def->type == ':')
613 >                    wputs(": redefined constant expression\n");
614 >                else
615 >                    wputs(": redefined\n");
616 >            } else if (ep->v.kid->type == FUNC && vdef->lib != NULL) {
617 >                wputs(qname);
618 >                wputs(": definition hides library function\n");
619 >            }
620          if (ep->type == ':')
621              dremove(qname);
622          else
# Line 529 | Line 634 | getstatement()                 /* get next statement */
634   EPNODE *
635   getdefn()                       /* A -> SYM = E1 */
636                                  /*      SYM : E1 */
637 <                                /*      FUNC(SYM,..) = E1 */
637 >                                /*      FUNC(SYM,..) = E1 */
638                                  /*      FUNC(SYM,..) : E1 */
639   {
640      register EPNODE  *ep1, *ep2;
641  
642 <    if (!isalpha(nextc))
642 >    if (!isalpha(nextc) && nextc != CNTXMARK)
643          syntax("illegal variable name");
644  
645      ep1 = newnode();
646      ep1->type = SYM;
647      ep1->v.name = savestr(getname());
648  
649 < #ifdef  FUNCTION
545 <    if (nextc == '(') {
649 >    if (esupport&E_FUNCTION && nextc == '(') {
650          ep2 = newnode();
651          ep2->type = FUNC;
652          addekid(ep2, ep1);
# Line 560 | Line 664 | getdefn()                      /* A -> SYM = E1 */
664              syntax("')' expected");
665          scan();
666          curfunc = ep1;
667 <    } else
564 <        curfunc = NULL;
565 < #endif
667 >    }
668  
669      if (nextc != '=' && nextc != ':')
670          syntax("'=' or ':' expected");
# Line 573 | Line 675 | getdefn()                      /* A -> SYM = E1 */
675      addekid(ep2, ep1);
676      addekid(ep2, getE1());
677  
678 <    if (
577 < #ifdef  FUNCTION
578 <            ep1->type == SYM &&
579 < #endif
580 <            ep1->sibling->type != NUM) {
678 >    if (ep1->type == SYM && ep1->sibling->type != NUM) {
679          ep1 = newnode();
680          ep1->type = TICK;
681 <        ep1->v.tick = -1;
681 >        ep1->v.tick = 0;
682          addekid(ep2, ep1);
683          ep1 = newnode();
684          ep1->type = NUM;
685          addekid(ep2, ep1);
686      }
687 +    curfunc = NULL;
688  
689      return(ep2);
690   }
691  
692  
594 #ifdef  OUTCHAN
693   EPNODE *
694   getchan()                       /* A -> $N = E1 */
695   {
# Line 616 | Line 714 | getchan()                      /* A -> $N = E1 */
714  
715      return(ep2);
716   }
619 #endif
717  
718  
719  
# Line 628 | Line 725 | getchan()                      /* A -> $N = E1 */
725   static double
726   dvalue(name, d)                 /* evaluate a variable */
727   char  *name;
728 < EPNODE  *d;
728 > EPNODE  *d;
729   {
730      register EPNODE  *ep1, *ep2;
731      
# Line 641 | Line 738 | EPNODE  *d;
738      if (ep1->type == NUM)
739          return(ep1->v.num);                     /* return if number */
740      ep2 = ep1->sibling;                         /* check time */
741 <    if (ep2->v.tick < 0 || ep2->v.tick < eclock) {
742 <        ep2->v.tick = d->type == ':' ? 1L<<30 : eclock;
741 >    if (eclock >= MAXCLOCK)
742 >        eclock = 1;                             /* wrap clock counter */
743 >    if (ep2->v.tick < MAXCLOCK &&
744 >                ep2->v.tick == 0 | ep2->v.tick != eclock) {
745 >        ep2->v.tick = d->type == ':' ? MAXCLOCK : eclock;
746          ep2 = ep2->sibling;
747          ep2->v.num = evalue(ep1);               /* needs new value */
748      } else
749          ep2 = ep2->sibling;                     /* else reuse old value */
750  
751      return(ep2->v.num);
652 }
653
654
655 static int
656 hash(s)                         /* hash a string */
657 register char  *s;
658 {
659    register int  rval = 0;
660
661    while (*s)
662        rval += *s++;
663    
664    return(rval % NHASH);
752   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines