mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
plumber: use strtoul to parse subexpression match variable substitutions
This commit is contained in:
parent
0790296f73
commit
a4d35dc3fd
1 changed files with 9 additions and 24 deletions
|
@ -254,36 +254,21 @@ filename(Exec *e, char *name)
|
||||||
return cleanname(buf);
|
return cleanname(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char*
|
|
||||||
subexpmatch(Exec *e, char *s, int *numlen)
|
|
||||||
{
|
|
||||||
int n, d, ok;
|
|
||||||
char *t;
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
ok = 1;
|
|
||||||
for(t = s; '0'<=*t && *t<='9'; t++)
|
|
||||||
if(ok){
|
|
||||||
d = *t-'0';
|
|
||||||
if(d<NMATCHSUBEXP && n<=(NMATCHSUBEXP-1-d)/10)
|
|
||||||
n = 10*n+d;
|
|
||||||
else
|
|
||||||
ok = 0;
|
|
||||||
}
|
|
||||||
*numlen = t-s;
|
|
||||||
if(t==s || !ok)
|
|
||||||
return nil;
|
|
||||||
return e->match[n];
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
dollar(Exec *e, char *s, int *namelen)
|
dollar(Exec *e, char *s, int *namelen)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
ulong m;
|
||||||
|
char *t;
|
||||||
static char *abuf;
|
static char *abuf;
|
||||||
|
|
||||||
if(e!=nil && '0'<=s[0] && s[0]<='9')
|
if(e!=nil && '0'<=s[0] && s[0]<='9'){
|
||||||
return nonnil(subexpmatch(e, s, namelen));
|
m = strtoul(s, &t, 10);
|
||||||
|
*namelen = t-s;
|
||||||
|
if(t==s || m>=NMATCHSUBEXP)
|
||||||
|
return "";
|
||||||
|
return nonnil(e->match[m]);
|
||||||
|
}
|
||||||
|
|
||||||
n = scanvarname(s)-s;
|
n = scanvarname(s)-s;
|
||||||
*namelen = n;
|
*namelen = n;
|
||||||
|
|
Loading…
Reference in a new issue