aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Burago <igor@igorburago.com>2022-07-27 17:27:06 +0800
committerDan Cross <crossd@gmail.com>2023-03-30 10:44:30 -0400
commit6c0efecd1303f22f86194d6eee7038651582f086 (patch)
tree67fab531cdcc6d9872a4fc7a90d188fefc32cf6b /src
parent760cf867056b1ef1ca2bf23dbe477d066e6562fb (diff)
plumber: allow multi-digit subexpression match variable substitutions
Diffstat (limited to 'src')
-rw-r--r--src/cmd/plumb/rules.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/cmd/plumb/rules.c b/src/cmd/plumb/rules.c
index e1687d43..4bd02e44 100644
--- a/src/cmd/plumb/rules.c
+++ b/src/cmd/plumb/rules.c
@@ -254,15 +254,36 @@ filename(Exec *e, char *name)
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*
dollar(Exec *e, char *s, int *namelen)
{
int n;
static char *abuf;
- *namelen = 1;
if(e!=nil && '0'<=s[0] && s[0]<='9')
- return nonnil(e->match[s[0]-'0']);
+ return nonnil(subexpmatch(e, s, namelen));
n = scanvarname(s)-s;
*namelen = n;