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 |
|
|