allow cshell $variable substitution with and without $&var
This commit is contained in:
parent
73bec459fa
commit
54529d0e42
|
|
@ -676,6 +676,41 @@ char cp_dol = '$';
|
||||||
|
|
||||||
#define VALIDCHARS "$-_<#?@.()[]&"
|
#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 *
|
wordlist *
|
||||||
cp_variablesubst(wordlist *wlist)
|
cp_variablesubst(wordlist *wlist)
|
||||||
{
|
{
|
||||||
|
|
@ -694,8 +729,11 @@ cp_variablesubst(wordlist *wlist)
|
||||||
t++;
|
t++;
|
||||||
s = buf;
|
s = buf;
|
||||||
/* Get s and t past the end of the var name. */
|
/* Get s and t past the end of the var name. */
|
||||||
while (*t && (isalphanum(*t) || strchr(VALIDCHARS, *t)))
|
{
|
||||||
|
char *end = span_var_expr(t);
|
||||||
|
while (t < end)
|
||||||
*s++ = *t++;
|
*s++ = *t++;
|
||||||
|
}
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
nwl = vareval(buf);
|
nwl = vareval(buf);
|
||||||
if (i) {
|
if (i) {
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ extern void cp_remvar(char *varname);
|
||||||
extern void cp_vset(char *varname, enum cp_types type, void *value);
|
extern void cp_vset(char *varname, enum cp_types type, void *value);
|
||||||
extern struct variable *cp_setparse(wordlist *wl);
|
extern struct variable *cp_setparse(wordlist *wl);
|
||||||
extern wordlist *vareval(char *string);
|
extern wordlist *vareval(char *string);
|
||||||
|
extern char *span_var_expr(char *t);
|
||||||
|
|
||||||
/* var2.c */
|
/* var2.c */
|
||||||
extern void cp_vprint(void);
|
extern void cp_vprint(void);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue