plumber: allow underscores in variable names in plumbing rules

Fixes #561.
This commit is contained in:
Igor Burago 2022-07-29 21:43:53 +08:00 committed by Dan Cross
parent 4f801be055
commit 29fae81fb7

View file

@ -215,6 +215,16 @@ setvariable(char *s, int n, char *val, char *qval)
var->qvalue = estrdup(qval); var->qvalue = estrdup(qval);
} }
static char*
scanvarname(char *s)
{
if(isalpha((uchar)*s) || *s=='_')
do
s++;
while(isalnum((uchar)*s) || *s=='_');
return s;
}
static char* static char*
nonnil(char *s) nonnil(char *s)
{ {
@ -249,16 +259,15 @@ dollar(Exec *e, char *s, int *namelen)
{ {
int n; int n;
static char *abuf; static char *abuf;
char *t;
*namelen = 1; *namelen = 1;
if(e!=nil && '0'<=s[0] && s[0]<='9') if(e!=nil && '0'<=s[0] && s[0]<='9')
return nonnil(e->match[s[0]-'0']); return nonnil(e->match[s[0]-'0']);
for(t=s; isalnum((uchar)*t); t++) n = scanvarname(s)-s;
;
n = t-s;
*namelen = n; *namelen = n;
if(n == 0)
return nil;
if(e != nil){ if(e != nil){
if(n == 3){ if(n == 3){
@ -391,17 +400,17 @@ assignment(char *p)
char *var, *qval; char *var, *qval;
int n; int n;
if(!isalpha((uchar)p[0])) var = p;
return 0; p = scanvarname(p);
for(var=p; isalnum((uchar)*p); p++)
;
n = p-var; n = p-var;
if(n == 0)
return 0;
while(*p==' ' || *p=='\t') while(*p==' ' || *p=='\t')
p++; p++;
if(*p++ != '=') if(*p++ != '=')
return 0; return 0;
while(*p==' ' || *p=='\t') while(*p==' ' || *p=='\t')
p++; p++;
qval = expand(nil, p, nil); qval = expand(nil, p, nil);
setvariable(var, n, p, qval); setvariable(var, n, p, qval);
return 1; return 1;