| 1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1997 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 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 */ |
| 47 |
> |
#define MAXCNTX 1023 /* maximum context length */ |
| 48 |
|
|
| 49 |
+ |
static char context[MAXCNTX+1]; /* current context path */ |
| 50 |
+ |
|
| 51 |
|
static VARDEF *hashtbl[NHASH]; /* definition list */ |
| 52 |
|
static int htndx; /* index for */ |
| 53 |
|
static VARDEF *htpos; /* ...dfirst() and */ |
| 57 |
|
#endif |
| 58 |
|
|
| 59 |
|
#ifdef FUNCTION |
| 60 |
< |
EPNODE *curfunc; |
| 60 |
> |
EPNODE *curfunc = NULL; |
| 61 |
|
#define dname(ep) ((ep)->v.kid->type == SYM ? \ |
| 62 |
|
(ep)->v.kid->v.name : \ |
| 63 |
|
(ep)->v.kid->v.kid->v.name) |
| 191 |
|
|
| 192 |
|
if (ctx == NULL) |
| 193 |
|
return(context); /* just asking */ |
| 194 |
+ |
while (*ctx == CNTXMARK) |
| 195 |
+ |
ctx++; /* skip past marks */ |
| 196 |
|
if (!*ctx) { |
| 197 |
< |
context[0] = '\0'; /* clear context */ |
| 197 |
> |
context[0] = '\0'; /* empty means clear context */ |
| 198 |
|
return(context); |
| 199 |
|
} |
| 200 |
< |
cpp = context; /* else copy it (carefully!) */ |
| 201 |
< |
if (*ctx != CNTXMARK) |
| 202 |
< |
*cpp++ = CNTXMARK; /* make sure there's a mark */ |
| 203 |
< |
do { |
| 200 |
< |
if (cpp >= context+MAXWORD) |
| 200 |
> |
cpp = context; /* start context with mark */ |
| 201 |
> |
*cpp++ = CNTXMARK; |
| 202 |
> |
do { /* carefully copy new context */ |
| 203 |
> |
if (cpp >= context+MAXCNTX) |
| 204 |
|
break; /* just copy what we can */ |
| 205 |
|
if (isid(*ctx)) |
| 206 |
|
*cpp++ = *ctx++; |
| 208 |
|
*cpp++ = '_'; ctx++; |
| 209 |
|
} |
| 210 |
|
} while (*ctx); |
| 211 |
+ |
while (cpp[-1] == CNTXMARK) /* cannot end in context mark */ |
| 212 |
+ |
cpp--; |
| 213 |
|
*cpp = '\0'; |
| 214 |
|
return(context); |
| 215 |
|
} |
| 216 |
|
|
| 217 |
|
|
| 218 |
|
char * |
| 219 |
+ |
pushcontext(ctx) /* push on another context */ |
| 220 |
+ |
char *ctx; |
| 221 |
+ |
{ |
| 222 |
+ |
extern char *strncpy(), *strcpy(); |
| 223 |
+ |
char oldcontext[MAXCNTX+1]; |
| 224 |
+ |
register int n; |
| 225 |
+ |
|
| 226 |
+ |
strcpy(oldcontext, context); /* save old context */ |
| 227 |
+ |
setcontext(ctx); /* set new context */ |
| 228 |
+ |
n = strlen(context); /* tack on old */ |
| 229 |
+ |
if (n+strlen(oldcontext) > MAXCNTX) { |
| 230 |
+ |
strncpy(context+n, oldcontext, MAXCNTX-n); |
| 231 |
+ |
context[MAXCNTX] = '\0'; |
| 232 |
+ |
} else |
| 233 |
+ |
strcpy(context+n, oldcontext); |
| 234 |
+ |
return(context); |
| 235 |
+ |
} |
| 236 |
+ |
|
| 237 |
+ |
|
| 238 |
+ |
char * |
| 239 |
+ |
popcontext() /* pop off top context */ |
| 240 |
+ |
{ |
| 241 |
+ |
register char *cp1, *cp2; |
| 242 |
+ |
|
| 243 |
+ |
if (!context[0]) /* nothing left to pop */ |
| 244 |
+ |
return(context); |
| 245 |
+ |
cp2 = context; /* find mark */ |
| 246 |
+ |
while (*++cp2 && *cp2 != CNTXMARK) |
| 247 |
+ |
; |
| 248 |
+ |
cp1 = context; /* copy tail to front */ |
| 249 |
+ |
while (*cp1++ = *cp2++) |
| 250 |
+ |
; |
| 251 |
+ |
return(context); |
| 252 |
+ |
} |
| 253 |
+ |
|
| 254 |
+ |
|
| 255 |
+ |
char * |
| 256 |
|
qualname(nam, lvl) /* get qualified name */ |
| 257 |
|
register char *nam; |
| 258 |
|
int lvl; |
| 301 |
|
incontext(qn) /* is qualified name in current context? */ |
| 302 |
|
register char *qn; |
| 303 |
|
{ |
| 304 |
+ |
if (!context[0]) /* global context accepts all */ |
| 305 |
+ |
return(1); |
| 306 |
|
while (*qn && *qn != CNTXMARK) /* find context mark */ |
| 307 |
|
qn++; |
| 308 |
|
return(!strcmp(qn, context)); |
| 331 |
|
/* if context is global, clear all */ |
| 332 |
|
for (i = 0; i < NHASH; i++) |
| 333 |
|
for (vp = hashtbl[i]; vp != NULL; vp = vp->next) |
| 334 |
< |
if (!context[0] || incontext(vp->name)) |
| 334 |
> |
if (incontext(vp->name)) |
| 335 |
|
if (lvl >= 2) |
| 336 |
|
dremove(vp->name); |
| 337 |
|
else |
| 560 |
|
qname = qualname(dname(ep), 0); |
| 561 |
|
#ifdef REDEFW |
| 562 |
|
if ((vdef = varlookup(qname)) != NULL) |
| 563 |
< |
if (vdef->def != NULL) { |
| 563 |
> |
if (vdef->def != NULL && epcmp(ep, vdef->def)) { |
| 564 |
|
wputs(qname); |
| 565 |
|
if (vdef->def->type == ':') |
| 566 |
|
wputs(": redefined constant expression\n"); |
| 622 |
|
syntax("')' expected"); |
| 623 |
|
scan(); |
| 624 |
|
curfunc = ep1; |
| 625 |
< |
} else |
| 582 |
< |
curfunc = NULL; |
| 625 |
> |
} |
| 626 |
|
#endif |
| 627 |
|
|
| 628 |
|
if (nextc != '=' && nextc != ':') |
| 641 |
|
ep1->sibling->type != NUM) { |
| 642 |
|
ep1 = newnode(); |
| 643 |
|
ep1->type = TICK; |
| 644 |
< |
ep1->v.tick = -1; |
| 644 |
> |
ep1->v.tick = 0; |
| 645 |
|
addekid(ep2, ep1); |
| 646 |
|
ep1 = newnode(); |
| 647 |
|
ep1->type = NUM; |
| 648 |
|
addekid(ep2, ep1); |
| 649 |
|
} |
| 650 |
|
|
| 651 |
+ |
#ifdef FUNCTION |
| 652 |
+ |
curfunc = NULL; |
| 653 |
+ |
#endif |
| 654 |
+ |
|
| 655 |
|
return(ep2); |
| 656 |
|
} |
| 657 |
|
|
| 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 (ep2->v.tick == 0 || ep2->v.tick < eclock) { |
| 710 |
> |
ep2->v.tick = d->type == ':' ? ~0L : eclock; |
| 711 |
|
ep2 = ep2->sibling; |
| 712 |
|
ep2->v.num = evalue(ep1); /* needs new value */ |
| 713 |
|
} else |
| 714 |
|
ep2 = ep2->sibling; /* else reuse old value */ |
| 715 |
|
|
| 716 |
|
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); |
| 717 |
|
} |