1 |
– |
/* Copyright (c) 1992 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 |
|
* |
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 "calcomp.h" |
36 |
|
|
37 |
|
#ifndef NHASH |
38 |
|
#define NHASH 521 /* hash size (a prime!) */ |
39 |
|
#endif |
40 |
|
|
41 |
+ |
#define hash(s) (shash(s)%NHASH) |
42 |
+ |
|
43 |
|
#define newnode() (EPNODE *)ecalloc(1, sizeof(EPNODE)) |
44 |
|
|
45 |
< |
extern char *ecalloc(), *emalloc(), *savestr(), *strcpy(); |
45 |
> |
static double dvalue(char *name, EPNODE *d); |
46 |
|
|
47 |
< |
static int hash(); |
47 |
> |
#define MAXCLOCK (1L<<31) /* clock wrap value */ |
48 |
|
|
49 |
< |
static double dvalue(); |
49 |
> |
unsigned long eclock = 0; /* value storage timer */ |
50 |
|
|
51 |
< |
long eclock = -1; /* value storage timer */ |
51 |
> |
#define MAXCNTX 1023 /* maximum context length */ |
52 |
|
|
53 |
< |
static char context[MAXWORD+1]; /* current context path */ |
53 |
> |
static char context[MAXCNTX+1]; /* current context path */ |
54 |
|
|
55 |
|
static VARDEF *hashtbl[NHASH]; /* definition list */ |
56 |
|
static int htndx; /* index for */ |
57 |
|
static VARDEF *htpos; /* ...dfirst() and */ |
52 |
– |
#ifdef OUTCHAN |
58 |
|
static EPNODE *ochpos; /* ...dnext */ |
59 |
|
static EPNODE *outchan; |
55 |
– |
#endif |
60 |
|
|
61 |
< |
#ifdef FUNCTION |
58 |
< |
EPNODE *curfunc; |
61 |
> |
EPNODE *curfunc = NULL; |
62 |
|
#define dname(ep) ((ep)->v.kid->type == SYM ? \ |
63 |
|
(ep)->v.kid->v.name : \ |
64 |
|
(ep)->v.kid->v.kid->v.name) |
62 |
– |
#else |
63 |
– |
#define dname(ep) ((ep)->v.kid->v.name) |
64 |
– |
#endif |
65 |
|
|
66 |
|
|
67 |
< |
fcompile(fname) /* get definitions from a file */ |
68 |
< |
char *fname; |
67 |
> |
void |
68 |
> |
fcompile( /* get definitions from a file */ |
69 |
> |
char *fname |
70 |
> |
) |
71 |
|
{ |
72 |
|
FILE *fp; |
73 |
|
|
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
< |
scompile(str, fn, ln) /* get definitions from a string */ |
90 |
< |
char *str; |
91 |
< |
char *fn; |
92 |
< |
int ln; |
89 |
> |
void |
90 |
> |
scompile( /* get definitions from a string */ |
91 |
> |
char *str, |
92 |
> |
char *fn, |
93 |
> |
int ln |
94 |
> |
) |
95 |
|
{ |
96 |
|
initstr(str, fn, ln); |
97 |
|
while (nextc != EOF) |
100 |
|
|
101 |
|
|
102 |
|
double |
103 |
< |
varvalue(vname) /* return a variable's value */ |
104 |
< |
char *vname; |
103 |
> |
varvalue( /* return a variable's value */ |
104 |
> |
char *vname |
105 |
> |
) |
106 |
|
{ |
107 |
|
return(dvalue(vname, dlookup(vname))); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
double |
112 |
< |
evariable(ep) /* evaluate a variable */ |
113 |
< |
EPNODE *ep; |
112 |
> |
evariable( /* evaluate a variable */ |
113 |
> |
EPNODE *ep |
114 |
> |
) |
115 |
|
{ |
116 |
|
register VARDEF *dp = ep->v.ln; |
117 |
|
|
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
< |
varset(vname, assign, val) /* set a variable's value */ |
123 |
< |
char *vname; |
124 |
< |
int assign; |
125 |
< |
double val; |
122 |
> |
void |
123 |
> |
varset( /* set a variable's value */ |
124 |
> |
char *vname, |
125 |
> |
int assign, |
126 |
> |
double val |
127 |
> |
) |
128 |
|
{ |
129 |
|
char *qname; |
130 |
|
register EPNODE *ep1, *ep2; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
< |
dclear(name) /* delete variable definitions of name */ |
159 |
< |
char *name; |
158 |
> |
void |
159 |
> |
dclear( /* delete variable definitions of name */ |
160 |
> |
char *name |
161 |
> |
) |
162 |
|
{ |
163 |
|
register EPNODE *ep; |
164 |
|
|
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
< |
dremove(name) /* delete all definitions of name */ |
176 |
< |
char *name; |
175 |
> |
void |
176 |
> |
dremove( /* delete all definitions of name */ |
177 |
> |
char *name |
178 |
> |
) |
179 |
|
{ |
180 |
|
register EPNODE *ep; |
181 |
|
|
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
< |
vardefined(name) /* return non-zero if variable defined */ |
188 |
< |
char *name; |
187 |
> |
int |
188 |
> |
vardefined( /* return non-zero if variable defined */ |
189 |
> |
char *name |
190 |
> |
) |
191 |
|
{ |
192 |
|
register EPNODE *dp; |
193 |
|
|
196 |
|
|
197 |
|
|
198 |
|
char * |
199 |
< |
setcontext(ctx) /* set a new context path */ |
200 |
< |
register char *ctx; |
199 |
> |
setcontext( /* set a new context path */ |
200 |
> |
register char *ctx |
201 |
> |
) |
202 |
|
{ |
203 |
|
register char *cpp; |
204 |
|
|
205 |
|
if (ctx == NULL) |
206 |
|
return(context); /* just asking */ |
207 |
+ |
while (*ctx == CNTXMARK) |
208 |
+ |
ctx++; /* skip past marks */ |
209 |
|
if (!*ctx) { |
210 |
< |
context[0] = '\0'; /* clear context */ |
210 |
> |
context[0] = '\0'; /* empty means clear context */ |
211 |
|
return(context); |
212 |
|
} |
213 |
< |
cpp = context; /* else copy it (carefully!) */ |
214 |
< |
if (*ctx != CNTXMARK) |
215 |
< |
*cpp++ = CNTXMARK; /* make sure there's a mark */ |
216 |
< |
do { |
200 |
< |
if (cpp >= context+MAXWORD) |
213 |
> |
cpp = context; /* start context with mark */ |
214 |
> |
*cpp++ = CNTXMARK; |
215 |
> |
do { /* carefully copy new context */ |
216 |
> |
if (cpp >= context+MAXCNTX) |
217 |
|
break; /* just copy what we can */ |
218 |
|
if (isid(*ctx)) |
219 |
|
*cpp++ = *ctx++; |
221 |
|
*cpp++ = '_'; ctx++; |
222 |
|
} |
223 |
|
} while (*ctx); |
224 |
+ |
while (cpp[-1] == CNTXMARK) /* cannot end in context mark */ |
225 |
+ |
cpp--; |
226 |
|
*cpp = '\0'; |
227 |
|
return(context); |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
char * |
232 |
< |
qualname(nam, lvl) /* get qualified name */ |
233 |
< |
register char *nam; |
234 |
< |
int lvl; |
232 |
> |
pushcontext( /* push on another context */ |
233 |
> |
char *ctx |
234 |
> |
) |
235 |
|
{ |
236 |
< |
static char nambuf[MAXWORD+1]; |
236 |
> |
char oldcontext[MAXCNTX+1]; |
237 |
> |
register int n; |
238 |
> |
|
239 |
> |
strcpy(oldcontext, context); /* save old context */ |
240 |
> |
setcontext(ctx); /* set new context */ |
241 |
> |
n = strlen(context); /* tack on old */ |
242 |
> |
if (n+strlen(oldcontext) > MAXCNTX) { |
243 |
> |
strncpy(context+n, oldcontext, MAXCNTX-n); |
244 |
> |
context[MAXCNTX] = '\0'; |
245 |
> |
} else |
246 |
> |
strcpy(context+n, oldcontext); |
247 |
> |
return(context); |
248 |
> |
} |
249 |
> |
|
250 |
> |
|
251 |
> |
char * |
252 |
> |
popcontext(void) /* pop off top context */ |
253 |
> |
{ |
254 |
> |
register char *cp1, *cp2; |
255 |
> |
|
256 |
> |
if (!context[0]) /* nothing left to pop */ |
257 |
> |
return(context); |
258 |
> |
cp2 = context; /* find mark */ |
259 |
> |
while (*++cp2 && *cp2 != CNTXMARK) |
260 |
> |
; |
261 |
> |
cp1 = context; /* copy tail to front */ |
262 |
> |
while ( (*cp1++ = *cp2++) ) |
263 |
> |
; |
264 |
> |
return(context); |
265 |
> |
} |
266 |
> |
|
267 |
> |
|
268 |
> |
char * |
269 |
> |
qualname( /* get qualified name */ |
270 |
> |
register char *nam, |
271 |
> |
int lvl |
272 |
> |
) |
273 |
> |
{ |
274 |
> |
static char nambuf[RMAXWORD+1]; |
275 |
|
register char *cp = nambuf, *cpp; |
276 |
|
/* check for explicit local */ |
277 |
|
if (*nam == CNTXMARK) |
283 |
|
return(lvl > 0 ? NULL : nam); |
284 |
|
/* copy name to static buffer */ |
285 |
|
while (*nam) { |
286 |
< |
if (cp >= nambuf+MAXWORD) |
286 |
> |
if (cp >= nambuf+RMAXWORD) |
287 |
|
goto toolong; |
288 |
|
*cp++ = *nam++; |
289 |
|
} |
302 |
|
; |
303 |
|
} |
304 |
|
while (*cpp) { /* copy context to static buffer */ |
305 |
< |
if (cp >= nambuf+MAXWORD) |
305 |
> |
if (cp >= nambuf+RMAXWORD) |
306 |
|
goto toolong; |
307 |
|
*cp++ = *cpp++; |
308 |
|
} |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
< |
incontext(qn) /* is qualified name in current context? */ |
316 |
< |
register char *qn; |
315 |
> |
int |
316 |
> |
incontext( /* is qualified name in current context? */ |
317 |
> |
register char *qn |
318 |
> |
) |
319 |
|
{ |
320 |
+ |
if (!context[0]) /* global context accepts all */ |
321 |
+ |
return(1); |
322 |
|
while (*qn && *qn != CNTXMARK) /* find context mark */ |
323 |
|
qn++; |
324 |
|
return(!strcmp(qn, context)); |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
< |
#ifdef OUTCHAN |
329 |
< |
chanout(cs) /* set output channels */ |
330 |
< |
int (*cs)(); |
328 |
> |
void |
329 |
> |
chanout( /* set output channels */ |
330 |
> |
void (*cs)(int n, double v) |
331 |
> |
) |
332 |
|
{ |
333 |
|
register EPNODE *ep; |
334 |
|
|
336 |
|
(*cs)(ep->v.kid->v.chan, evalue(ep->v.kid->sibling)); |
337 |
|
|
338 |
|
} |
278 |
– |
#endif |
339 |
|
|
340 |
|
|
341 |
< |
dcleanup(lvl) /* clear definitions (0->vars,1->output,2->consts) */ |
342 |
< |
int lvl; |
341 |
> |
void |
342 |
> |
dcleanup( /* clear definitions (0->vars,1->output,2->consts) */ |
343 |
> |
int lvl |
344 |
> |
) |
345 |
|
{ |
346 |
|
register int i; |
347 |
|
register VARDEF *vp; |
349 |
|
/* if context is global, clear all */ |
350 |
|
for (i = 0; i < NHASH; i++) |
351 |
|
for (vp = hashtbl[i]; vp != NULL; vp = vp->next) |
352 |
< |
if (!context[0] || incontext(vp->name)) |
352 |
> |
if (incontext(vp->name)) { |
353 |
|
if (lvl >= 2) |
354 |
|
dremove(vp->name); |
355 |
|
else |
356 |
|
dclear(vp->name); |
357 |
< |
#ifdef OUTCHAN |
357 |
> |
} |
358 |
|
if (lvl >= 1) { |
359 |
|
for (ep = outchan; ep != NULL; ep = ep->sibling) |
360 |
|
epfree(ep); |
361 |
|
outchan = NULL; |
362 |
|
} |
301 |
– |
#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 |
|
|
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; |
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; |
406 |
|
return(vp); |
407 |
|
} |
408 |
|
vp = (VARDEF *)emalloc(sizeof(VARDEF)); |
345 |
– |
#ifdef FUNCTION |
409 |
|
vp->lib = liblookup(name); |
347 |
– |
#else |
348 |
– |
vp->lib = NULL; |
349 |
– |
#endif |
410 |
|
if (vp->lib == NULL) /* if name not in library */ |
411 |
|
name = qualname(name, 0); /* use fully qualified version */ |
412 |
|
hv = hash(name); |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
< |
#ifdef FUNCTION |
423 |
< |
libupdate(fn) /* update library links */ |
424 |
< |
char *fn; |
422 |
> |
void |
423 |
> |
libupdate( /* update library links */ |
424 |
> |
char *fn |
425 |
> |
) |
426 |
|
{ |
427 |
|
register int i; |
428 |
|
register VARDEF *vp; |
432 |
|
if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name)) |
433 |
|
vp->lib = liblookup(vp->name); |
434 |
|
} |
374 |
– |
#endif |
435 |
|
|
436 |
|
|
437 |
< |
varfree(ln) /* release link to variable */ |
438 |
< |
register VARDEF *ln; |
437 |
> |
void |
438 |
> |
varfree( /* release link to variable */ |
439 |
> |
register VARDEF *ln |
440 |
> |
) |
441 |
|
{ |
442 |
|
register VARDEF *vp; |
443 |
|
int hv; |
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; |
405 |
– |
#ifdef OUTCHAN |
467 |
|
ochpos = outchan; |
407 |
– |
#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; |
486 |
|
return(ep); |
487 |
|
} |
488 |
|
} |
429 |
– |
#ifdef OUTCHAN |
489 |
|
if ((ep = ochpos) != NULL) |
490 |
|
ochpos = ep->sibling; |
491 |
|
return(ep); |
433 |
– |
#else |
434 |
– |
return(NULL); |
435 |
– |
#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; |
509 |
|
} |
510 |
|
|
511 |
|
|
512 |
< |
dpush(nm, ep) /* push on a definition */ |
513 |
< |
char *nm; |
514 |
< |
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 |
|
|
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; |
532 |
|
register EPNODE *ep, *epl; |
552 |
|
sp->sibling = NULL; |
553 |
|
|
554 |
|
} |
495 |
– |
#endif |
555 |
|
|
556 |
|
|
557 |
< |
getstatement() /* get next statement */ |
557 |
> |
void |
558 |
> |
getstatement(void) /* get next statement */ |
559 |
|
{ |
560 |
|
register EPNODE *ep; |
561 |
|
char *qname; |
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 |
513 |
< |
#endif |
514 |
< |
{ /* ordinary definition */ |
572 |
> |
} else { /* ordinary definition */ |
573 |
|
ep = getdefn(); |
574 |
|
qname = qualname(dname(ep), 0); |
575 |
< |
#ifdef REDEFW |
576 |
< |
if ((vdef = varlookup(qname)) != NULL) |
519 |
< |
if (vdef->def != NULL) { |
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 |
< |
} |
526 |
< |
#ifdef FUNCTION |
527 |
< |
else if (ep->v.kid->type == FUNC && vdef->lib != NULL) { |
582 |
> |
} else if (ep->v.kid->type == FUNC && vdef->lib != NULL) { |
583 |
|
wputs(qname); |
584 |
|
wputs(": definition hides library function\n"); |
585 |
|
} |
586 |
< |
#endif |
532 |
< |
#endif |
586 |
> |
} |
587 |
|
if (ep->type == ':') |
588 |
|
dremove(qname); |
589 |
|
else |
599 |
|
|
600 |
|
|
601 |
|
EPNODE * |
602 |
< |
getdefn() /* A -> SYM = E1 */ |
603 |
< |
/* SYM : E1 */ |
604 |
< |
/* FUNC(SYM,..) = E1 */ |
605 |
< |
/* FUNC(SYM,..) : E1 */ |
602 |
> |
getdefn(void) |
603 |
> |
/* A -> SYM = E1 */ |
604 |
> |
/* SYM : E1 */ |
605 |
> |
/* FUNC(SYM,..) = E1 */ |
606 |
> |
/* FUNC(SYM,..) : E1 */ |
607 |
|
{ |
608 |
|
register EPNODE *ep1, *ep2; |
609 |
|
|
614 |
|
ep1->type = SYM; |
615 |
|
ep1->v.name = savestr(getname()); |
616 |
|
|
617 |
< |
#ifdef FUNCTION |
563 |
< |
if (nextc == '(') { |
617 |
> |
if (esupport&E_FUNCTION && nextc == '(') { |
618 |
|
ep2 = newnode(); |
619 |
|
ep2->type = FUNC; |
620 |
|
addekid(ep2, ep1); |
632 |
|
syntax("')' expected"); |
633 |
|
scan(); |
634 |
|
curfunc = ep1; |
635 |
< |
} else |
582 |
< |
curfunc = NULL; |
583 |
< |
#endif |
635 |
> |
} |
636 |
|
|
637 |
|
if (nextc != '=' && nextc != ':') |
638 |
|
syntax("'=' or ':' expected"); |
643 |
|
addekid(ep2, ep1); |
644 |
|
addekid(ep2, getE1()); |
645 |
|
|
646 |
< |
if ( |
595 |
< |
#ifdef FUNCTION |
596 |
< |
ep1->type == SYM && |
597 |
< |
#endif |
598 |
< |
ep1->sibling->type != NUM) { |
646 |
> |
if (ep1->type == SYM && ep1->sibling->type != NUM) { |
647 |
|
ep1 = newnode(); |
648 |
|
ep1->type = TICK; |
649 |
< |
ep1->v.tick = -1; |
649 |
> |
ep1->v.tick = 0; |
650 |
|
addekid(ep2, ep1); |
651 |
|
ep1 = newnode(); |
652 |
|
ep1->type = NUM; |
653 |
|
addekid(ep2, ep1); |
654 |
|
} |
655 |
+ |
curfunc = NULL; |
656 |
|
|
657 |
|
return(ep2); |
658 |
|
} |
659 |
|
|
660 |
|
|
612 |
– |
#ifdef OUTCHAN |
661 |
|
EPNODE * |
662 |
< |
getchan() /* A -> $N = E1 */ |
662 |
> |
getchan(void) /* A -> $N = E1 */ |
663 |
|
{ |
664 |
|
register EPNODE *ep1, *ep2; |
665 |
|
|
682 |
|
|
683 |
|
return(ep2); |
684 |
|
} |
637 |
– |
#endif |
685 |
|
|
686 |
|
|
687 |
|
|
690 |
|
*/ |
691 |
|
|
692 |
|
|
693 |
< |
static double |
694 |
< |
dvalue(name, d) /* evaluate a variable */ |
648 |
< |
char *name; |
649 |
< |
EPNODE *d; |
693 |
> |
static double /* evaluate a variable */ |
694 |
> |
dvalue(char *name, EPNODE *d) |
695 |
|
{ |
696 |
|
register EPNODE *ep1, *ep2; |
697 |
|
|
704 |
|
if (ep1->type == NUM) |
705 |
|
return(ep1->v.num); /* return if number */ |
706 |
|
ep2 = ep1->sibling; /* check time */ |
707 |
< |
if (ep2->v.tick < 0 || ep2->v.tick < eclock) { |
708 |
< |
ep2->v.tick = d->type == ':' ? 1L<<30 : eclock; |
707 |
> |
if (eclock >= MAXCLOCK) |
708 |
> |
eclock = 1; /* wrap clock counter */ |
709 |
> |
if (ep2->v.tick < MAXCLOCK && |
710 |
> |
(ep2->v.tick == 0) | (ep2->v.tick != eclock)) { |
711 |
> |
ep2->v.tick = d->type == ':' ? MAXCLOCK : eclock; |
712 |
|
ep2 = ep2->sibling; |
713 |
|
ep2->v.num = evalue(ep1); /* needs new value */ |
714 |
|
} else |
715 |
|
ep2 = ep2->sibling; /* else reuse old value */ |
716 |
|
|
717 |
|
return(ep2->v.num); |
670 |
– |
} |
671 |
– |
|
672 |
– |
|
673 |
– |
static int |
674 |
– |
hash(s) /* hash a string */ |
675 |
– |
register char *s; |
676 |
– |
{ |
677 |
– |
register int rval = 0; |
678 |
– |
|
679 |
– |
while (*s) |
680 |
– |
rval += *s++; |
681 |
– |
|
682 |
– |
return(rval % NHASH); |
718 |
|
} |