34 |
|
#define NHASH 521 /* hash size (a prime!) */ |
35 |
|
#endif |
36 |
|
|
37 |
+ |
#define hash(s) (shash(s)%NHASH) |
38 |
+ |
|
39 |
|
#define newnode() (EPNODE *)ecalloc(1, sizeof(EPNODE)) |
40 |
|
|
41 |
|
extern char *ecalloc(), *emalloc(), *savestr(), *strcpy(); |
42 |
|
|
41 |
– |
static int hash(); |
42 |
– |
|
43 |
|
static double dvalue(); |
44 |
|
|
45 |
< |
long eclock = -1; /* value storage timer */ |
45 |
> |
unsigned long eclock = 0; /* value storage timer */ |
46 |
|
|
47 |
|
static char context[MAXWORD+1]; /* current context path */ |
48 |
|
|
55 |
|
#endif |
56 |
|
|
57 |
|
#ifdef FUNCTION |
58 |
< |
EPNODE *curfunc; |
58 |
> |
EPNODE *curfunc = NULL; |
59 |
|
#define dname(ep) ((ep)->v.kid->type == SYM ? \ |
60 |
|
(ep)->v.kid->v.name : \ |
61 |
|
(ep)->v.kid->v.kid->v.name) |
189 |
|
|
190 |
|
if (ctx == NULL) |
191 |
|
return(context); /* just asking */ |
192 |
+ |
while (*ctx == CNTXMARK) |
193 |
+ |
ctx++; /* skip past marks */ |
194 |
|
if (!*ctx) { |
195 |
< |
context[0] = '\0'; /* clear context */ |
195 |
> |
context[0] = '\0'; /* empty means clear context */ |
196 |
|
return(context); |
197 |
|
} |
198 |
< |
cpp = context; /* else copy it (carefully!) */ |
199 |
< |
if (*ctx != CNTXMARK) |
200 |
< |
*cpp++ = CNTXMARK; /* make sure there's a mark */ |
199 |
< |
do { |
198 |
> |
cpp = context; /* start context with mark */ |
199 |
> |
*cpp++ = CNTXMARK; |
200 |
> |
do { /* carefully copy new context */ |
201 |
|
if (cpp >= context+MAXWORD) |
202 |
|
break; /* just copy what we can */ |
203 |
|
if (isid(*ctx)) |
206 |
|
*cpp++ = '_'; ctx++; |
207 |
|
} |
208 |
|
} while (*ctx); |
209 |
+ |
while (cpp[-1] == CNTXMARK) /* cannot end in context mark */ |
210 |
+ |
cpp--; |
211 |
|
*cpp = '\0'; |
212 |
|
return(context); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
char * |
217 |
+ |
pushcontext(ctx) /* push on another context */ |
218 |
+ |
char *ctx; |
219 |
+ |
{ |
220 |
+ |
extern char *strncpy(), *strcpy(); |
221 |
+ |
char oldcontext[MAXWORD+1]; |
222 |
+ |
register int n; |
223 |
+ |
|
224 |
+ |
strcpy(oldcontext, context); /* save old context */ |
225 |
+ |
setcontext(ctx); /* set new context */ |
226 |
+ |
n = strlen(context); /* tack on old */ |
227 |
+ |
if (n+strlen(oldcontext) > MAXWORD) { |
228 |
+ |
strncpy(context+n, oldcontext, MAXWORD-n); |
229 |
+ |
context[MAXWORD] = '\0'; |
230 |
+ |
} else |
231 |
+ |
strcpy(context+n, oldcontext); |
232 |
+ |
return(context); |
233 |
+ |
} |
234 |
+ |
|
235 |
+ |
|
236 |
+ |
char * |
237 |
+ |
popcontext() /* pop off top context */ |
238 |
+ |
{ |
239 |
+ |
register char *cp1, *cp2; |
240 |
+ |
|
241 |
+ |
if (!context[0]) /* nothing left to pop */ |
242 |
+ |
return(context); |
243 |
+ |
cp2 = context; /* find mark */ |
244 |
+ |
while (*++cp2 && *cp2 != CNTXMARK) |
245 |
+ |
; |
246 |
+ |
cp1 = context; /* copy tail to front */ |
247 |
+ |
while (*cp1++ = *cp2++) |
248 |
+ |
; |
249 |
+ |
return(context); |
250 |
+ |
} |
251 |
+ |
|
252 |
+ |
|
253 |
+ |
char * |
254 |
|
qualname(nam, lvl) /* get qualified name */ |
255 |
|
register char *nam; |
256 |
|
int lvl; |
299 |
|
incontext(qn) /* is qualified name in current context? */ |
300 |
|
register char *qn; |
301 |
|
{ |
302 |
+ |
if (!context[0]) /* global context accepts all */ |
303 |
+ |
return(1); |
304 |
|
while (*qn && *qn != CNTXMARK) /* find context mark */ |
305 |
|
qn++; |
306 |
|
return(!strcmp(qn, context)); |
329 |
|
/* if context is global, clear all */ |
330 |
|
for (i = 0; i < NHASH; i++) |
331 |
|
for (vp = hashtbl[i]; vp != NULL; vp = vp->next) |
332 |
< |
if (!context[0] || incontext(vp->name)) |
332 |
> |
if (incontext(vp->name)) |
333 |
|
if (lvl >= 2) |
334 |
|
dremove(vp->name); |
335 |
|
else |
558 |
|
qname = qualname(dname(ep), 0); |
559 |
|
#ifdef REDEFW |
560 |
|
if ((vdef = varlookup(qname)) != NULL) |
561 |
< |
if (vdef->def != NULL) { |
561 |
> |
if (vdef->def != NULL && epcmp(ep, vdef->def)) { |
562 |
|
wputs(qname); |
563 |
|
if (vdef->def->type == ':') |
564 |
|
wputs(": redefined constant expression\n"); |
620 |
|
syntax("')' expected"); |
621 |
|
scan(); |
622 |
|
curfunc = ep1; |
623 |
< |
} else |
582 |
< |
curfunc = NULL; |
623 |
> |
} |
624 |
|
#endif |
625 |
|
|
626 |
|
if (nextc != '=' && nextc != ':') |
639 |
|
ep1->sibling->type != NUM) { |
640 |
|
ep1 = newnode(); |
641 |
|
ep1->type = TICK; |
642 |
< |
ep1->v.tick = -1; |
642 |
> |
ep1->v.tick = 0; |
643 |
|
addekid(ep2, ep1); |
644 |
|
ep1 = newnode(); |
645 |
|
ep1->type = NUM; |
646 |
|
addekid(ep2, ep1); |
647 |
|
} |
648 |
|
|
649 |
+ |
#ifdef FUNCTION |
650 |
+ |
curfunc = NULL; |
651 |
+ |
#endif |
652 |
+ |
|
653 |
|
return(ep2); |
654 |
|
} |
655 |
|
|
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 (ep2->v.tick == 0 || ep2->v.tick < eclock) { |
708 |
> |
ep2->v.tick = d->type == ':' ? ~0L : eclock; |
709 |
|
ep2 = ep2->sibling; |
710 |
|
ep2->v.num = evalue(ep1); /* needs new value */ |
711 |
|
} else |
712 |
|
ep2 = ep2->sibling; /* else reuse old value */ |
713 |
|
|
714 |
|
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); |
715 |
|
} |