From 760cf867056b1ef1ca2bf23dbe477d066e6562fb Mon Sep 17 00:00:00 2001 From: Igor Burago Date: Wed, 27 Jul 2022 16:28:14 +0800 Subject: [PATCH] plumber: parametrize the number of stored match pattern subexpressions --- src/cmd/plumb/match.c | 17 +++++++++-------- src/cmd/plumb/plumber.h | 7 ++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/cmd/plumb/match.c b/src/cmd/plumb/match.c index 4cb32cc6..70d912a7 100644 --- a/src/cmd/plumb/match.c +++ b/src/cmd/plumb/match.c @@ -38,11 +38,11 @@ verbis(int obj, Plumbmsg *m, Rule *r) } static void -setvar(Resub rs[10], char *match[10]) +setvar(Resub rs[NMATCHSUBEXP], char *match[NMATCHSUBEXP]) { int i, n; - for(i=0; i<10; i++){ + for(i=0; iregex, alltext, rs, 10) || rs[0].s.sp!=alltext || rs[0].e.ep!=alltext+ntext) + if(!regexec(r->regex, alltext, rs, NMATCHSUBEXP) + || rs[0].s.sp!=alltext || rs[0].e.ep!=alltext+ntext) break; setvar(rs, e->match); return 1; @@ -300,7 +301,7 @@ freeexec(Exec *exec) return; free(exec->dir); free(exec->file); - for(i=0; i<10; i++) + for(i=0; imatch[i]); free(exec); } diff --git a/src/cmd/plumb/plumber.h b/src/cmd/plumb/plumber.h index 44700559..65d5d0ac 100644 --- a/src/cmd/plumb/plumber.h +++ b/src/cmd/plumb/plumber.h @@ -52,10 +52,15 @@ struct Ruleset char *port; }; +enum +{ + NMATCHSUBEXP = 10 +}; + struct Exec { Plumbmsg *msg; - char *match[10]; + char *match[NMATCHSUBEXP]; int p0; /* begin and end of match */ int p1; int clearclick; /* click was expanded; remove attribute */