From 9b034eac9528895e66afc0786b7f5f0151fde918 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 22 Apr 2024 17:43:35 -0700 Subject: [PATCH] Merged all regs needing functions --- src/modal.c | 69 +++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/src/modal.c b/src/modal.c index 86a888d..4661f8f 100644 --- a/src/modal.c +++ b/src/modal.c @@ -77,41 +77,6 @@ put_reg(char r, char *reg) while(reg < cap) *dst_++ = *reg++; } -static char * -match_rule(Rule *r, char *p) -{ - int i; - char c, *a = r->a; - if(rmax) { - for(i = rmin; i <= rmax; i++) - regs[i] = 0; - rmin = 0xff, rmax = 0x00; - } - while((c = *a)) { - if(c == '?') { - int regid = (int)*(++a); - char *pcap = walk(p), *reg = regs[regid]; - if(reg) { /* reg cmp */ - char *rcap = walk(reg), *pp = p; - while(reg < rcap || pp < pcap) - if(*reg++ != *pp++) return NULL; - } else { /* reg set */ - regs[regid] = p; - if(regid < rmin) rmin = regid; - if(regid > rmax) rmax = regid; - } - a++, p = pcap; - if(!spacer(*a)) - while((c = *a) && !spacer(c)) a++; - continue; - } - if(c != *p) return NULL; - a++, p++; - } - c = *p; - return spacer(c) ? p : NULL; -} - static int commit_rule(Rule *r, char *s, int create) { @@ -168,10 +133,36 @@ parse_frag(char *s) static int run_rule(Rule *r, char *s) { - char *res; - if((res = match_rule(r, s)) != NULL) - return write_rule(r, res); - return 0; + int i; + char c, *a = r->a, *p = s; + if(rmax) { + for(i = rmin; i <= rmax; i++) + regs[i] = 0; + rmin = 0xff, rmax = 0x00; + } + while((c = *a)) { + if(c == '?') { + int regid = (int)*(++a); + char *pcap = walk(p), *reg = regs[regid]; + if(reg) { /* reg cmp */ + char *rcap = walk(reg), *pp = p; + while(reg < rcap || pp < pcap) + if(*reg++ != *pp++) return 0; + } else { /* reg set */ + regs[regid] = p; + if(regid < rmin) rmin = regid; + if(regid > rmax) rmax = regid; + } + a++, p = pcap; + if(!spacer(*a)) + while((c = *a) && !spacer(c)) a++; + continue; + } + if(c != *p) return 0; + a++, p++; + } + c = *p; + return spacer(c) ? write_rule(r, p) : 0; } static int