allow cshell $variable substitution with and without $&var

This commit is contained in:
dwarning 2013-08-27 14:28:59 +02:00 committed by rlar
parent 73bec459fa
commit 54529d0e42
2 changed files with 41 additions and 2 deletions

View File

@ -676,6 +676,41 @@ char cp_dol = '$';
#define VALIDCHARS "$-_<#?@.()[]&"
char *
span_var_expr(char *t)
{
int parenthesis = 0;
int brackets = 0;
while (*t && (isalphanum(*t) || strchr(VALIDCHARS, *t)))
switch (*t++)
{
case '[':
brackets++;
break;
case '(':
parenthesis++;
break;
case ']':
if (brackets <= 0)
return t-1;
if (--brackets <= 0)
return t;
break;
case ')':
if (parenthesis <= 0)
return t-1;
if (--parenthesis <= 0)
return t;
break;
default:
break;
}
return t;
}
wordlist *
cp_variablesubst(wordlist *wlist)
{
@ -694,8 +729,11 @@ cp_variablesubst(wordlist *wlist)
t++;
s = buf;
/* Get s and t past the end of the var name. */
while (*t && (isalphanum(*t) || strchr(VALIDCHARS, *t)))
*s++ = *t++;
{
char *end = span_var_expr(t);
while (t < end)
*s++ = *t++;
}
*s = '\0';
nwl = vareval(buf);
if (i) {

View File

@ -167,6 +167,7 @@ extern void cp_remvar(char *varname);
extern void cp_vset(char *varname, enum cp_types type, void *value);
extern struct variable *cp_setparse(wordlist *wl);
extern wordlist *vareval(char *string);
extern char *span_var_expr(char *t);
/* var2.c */
extern void cp_vprint(void);