diff options
| author | Igor Burago <igor@igorburago.com> | 2022-07-27 16:28:14 +0800 |
|---|---|---|
| committer | Dan Cross <crossd@gmail.com> | 2023-03-30 10:44:30 -0400 |
| commit | 760cf867056b1ef1ca2bf23dbe477d066e6562fb (patch) | |
| tree | 9808c9bd46010c850ca0061a656975e348e7e7dd /src/cmd | |
| parent | 0392f49cfc9d0fc94282fdf85854b31c67b1cd02 (diff) | |
plumber: parametrize the number of stored match pattern subexpressions
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/plumb/match.c | 17 | ||||
| -rw-r--r-- | 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; i<NMATCHSUBEXP; i++){ free(match[i]); match[i] = nil; if(rs[i].s.sp != nil){ @@ -55,7 +55,7 @@ setvar(Resub rs[10], char *match[10]) } int -clickmatch(Reprog *re, char *text, Resub rs[10], int click) +clickmatch(Reprog *re, char *text, Resub rs[NMATCHSUBEXP], int click) { char *clickp; int i, w; @@ -66,8 +66,8 @@ clickmatch(Reprog *re, char *text, Resub rs[10], int click) w = chartorune(&r, text+i); clickp = text+i; for(i=0; i<=click; i++){ - memset(rs, 0, 10*sizeof(Resub)); - if(regexec(re, text+i, rs, 10)) + memset(rs, 0, NMATCHSUBEXP*sizeof(Resub)); + if(regexec(re, text+i, rs, NMATCHSUBEXP)) if(rs[0].s.sp<=clickp && clickp<=rs[0].e.ep) return 1; } @@ -77,7 +77,7 @@ clickmatch(Reprog *re, char *text, Resub rs[10], int click) int verbmatches(int obj, Plumbmsg *m, Rule *r, Exec *e) { - Resub rs[10]; + Resub rs[NMATCHSUBEXP]; char *clickval, *alltext; int p0, p1, ntext; @@ -122,7 +122,8 @@ verbmatches(int obj, Plumbmsg *m, Rule *r, Exec *e) /* must match full text */ if(ntext < 0) ntext = strlen(alltext); - if(!regexec(r->regex, 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; i<NMATCHSUBEXP; i++) free(exec->match[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 */ |