42 |
|
|
43 |
|
long eclock = -1; /* value storage timer */ |
44 |
|
|
45 |
< |
static char context[MAXWORD]; /* current context path */ |
45 |
> |
static char context[MAXWORD+1]; /* current context path */ |
46 |
|
|
47 |
|
static VARDEF *hashtbl[NHASH]; /* definition list */ |
48 |
|
static int htndx; /* index for */ |
195 |
|
if (*ctx != CNTXMARK) |
196 |
|
*cpp++ = CNTXMARK; /* make sure there's a mark */ |
197 |
|
do { |
198 |
< |
if (cpp >= context+MAXWORD-1) { |
199 |
< |
*cpp = '\0'; |
200 |
< |
wputs(context); |
201 |
< |
wputs(": context path too long\n"); |
202 |
< |
return(NULL); |
203 |
< |
} |
198 |
> |
if (cpp >= context+MAXWORD) |
199 |
> |
break; /* just copy what we can */ |
200 |
|
if (isid(*ctx)) |
201 |
|
*cpp++ = *ctx++; |
202 |
|
else { |
213 |
|
register char *nam; |
214 |
|
int lvl; |
215 |
|
{ |
216 |
< |
static char nambuf[MAXWORD]; |
217 |
< |
register char *cp = nambuf, *cpp = context; |
218 |
< |
/* check for explicit global */ |
216 |
> |
static char nambuf[MAXWORD+1]; |
217 |
> |
register char *cp = nambuf, *cpp; |
218 |
> |
/* check for explicit local */ |
219 |
|
if (*nam == CNTXMARK) |
220 |
< |
return(lvl > 0 ? NULL : nam+1); |
221 |
< |
/* check for repeat call */ |
222 |
< |
if (nam == nambuf) |
223 |
< |
return(lvl > 0 ? NULL : nambuf); |
220 |
> |
if (lvl > 0) /* only action is to refuse search */ |
221 |
> |
return(NULL); |
222 |
> |
else |
223 |
> |
nam++; |
224 |
> |
else if (nam == nambuf) /* check for repeat call */ |
225 |
> |
return(lvl > 0 ? NULL : nam); |
226 |
|
/* copy name to static buffer */ |
227 |
|
while (*nam) { |
228 |
< |
if (cp >= nambuf+MAXWORD-1) |
228 |
> |
if (cp >= nambuf+MAXWORD) |
229 |
|
goto toolong; |
230 |
< |
if ((*cp++ = *nam++) == CNTXMARK) |
233 |
< |
cpp = NULL; /* flag a qualified name */ |
230 |
> |
*cp++ = *nam++; |
231 |
|
} |
232 |
< |
if (cpp == NULL) { |
232 |
> |
/* check for explicit global */ |
233 |
> |
if (cp > nambuf && cp[-1] == CNTXMARK) { |
234 |
|
if (lvl > 0) |
235 |
< |
return(NULL); /* no higher level */ |
236 |
< |
if (cp[-1] == CNTXMARK) { |
237 |
< |
cp--; cpp = context; /* current context explicitly */ |
238 |
< |
} else |
239 |
< |
cpp = ""; /* else fully qualified */ |
240 |
< |
} else /* else skip the requested levels */ |
241 |
< |
while (lvl-- > 0) { |
242 |
< |
if (!*cpp) |
243 |
< |
return(NULL); /* return NULL if past global level */ |
244 |
< |
while (*++cpp && *cpp != CNTXMARK) |
245 |
< |
; |
248 |
< |
} |
235 |
> |
return(NULL); |
236 |
> |
*--cp = '\0'; |
237 |
> |
return(nambuf); /* already qualified */ |
238 |
> |
} |
239 |
> |
cpp = context; /* else skip the requested levels */ |
240 |
> |
while (lvl-- > 0) { |
241 |
> |
if (!*cpp) |
242 |
> |
return(NULL); /* return NULL if past global level */ |
243 |
> |
while (*++cpp && *cpp != CNTXMARK) |
244 |
> |
; |
245 |
> |
} |
246 |
|
while (*cpp) { /* copy context to static buffer */ |
247 |
< |
if (cp >= nambuf+MAXWORD-1) |
247 |
> |
if (cp >= nambuf+MAXWORD) |
248 |
|
goto toolong; |
249 |
|
*cp++ = *cpp++; |
250 |
|
} |
254 |
– |
*cp = '\0'; |
255 |
– |
return(nambuf); /* return qualified name */ |
251 |
|
toolong: |
252 |
|
*cp = '\0'; |
253 |
< |
eputs(nambuf); |
259 |
< |
eputs(": name too long\n"); |
260 |
< |
quit(1); |
253 |
> |
return(nambuf); /* return qualified name */ |
254 |
|
} |
255 |
|
|
256 |
|
|
258 |
|
register char *qn; |
259 |
|
{ |
260 |
|
while (*qn && *qn != CNTXMARK) /* find context mark */ |
261 |
< |
; |
261 |
> |
qn++; |
262 |
|
return(!strcmp(qn, context)); |
263 |
|
} |
264 |
|
|
398 |
|
dnext() /* return pointer to next definition */ |
399 |
|
{ |
400 |
|
register EPNODE *ep; |
401 |
+ |
register char *nm; |
402 |
|
|
403 |
|
while (htndx < NHASH) { |
404 |
|
if (htpos == NULL) |
405 |
|
htpos = hashtbl[htndx++]; |
406 |
|
while (htpos != NULL) { |
407 |
|
ep = htpos->def; |
408 |
+ |
nm = htpos->name; |
409 |
|
htpos = htpos->next; |
410 |
< |
if (ep != NULL) |
410 |
> |
if (ep != NULL && incontext(nm)) |
411 |
|
return(ep); |
412 |
|
} |
413 |
|
} |
537 |
|
{ |
538 |
|
register EPNODE *ep1, *ep2; |
539 |
|
|
540 |
< |
if (!isalpha(nextc)) |
540 |
> |
if (!isalpha(nextc) && nextc != CNTXMARK) |
541 |
|
syntax("illegal variable name"); |
542 |
|
|
543 |
|
ep1 = newnode(); |