From 6d10bb3b66b9d173ba29c3eb7d7eb0ad5216e755 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 25 Apr 2024 10:12:43 -0700 Subject: [PATCH] Split apply_rule --- src/modal.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modal.c b/src/modal.c index da2d9ec..1604ec6 100644 --- a/src/modal.c +++ b/src/modal.c @@ -102,11 +102,11 @@ write_rule(Rule *r, char *s, int create) return 1; } -static int -apply_rule(Rule *r, char **regs, char *s) +static char * +match_rule(Rule *r, char **regs, char *s) { unsigned int i, id; - char c, *a = r->a, *b = r->b, *origin = dst_, *reg; + char c, *a = r->a, *reg; /* phase: clean registers */ for(i = 0; i < r->ptr; i++) regs[i] = NULL; @@ -118,7 +118,7 @@ apply_rule(Rule *r, char **regs, char *s) if((reg = regs[id])) { /* reg cmp */ char *rcap = walk(reg), *pp = s; while(reg < rcap || pp < pcap) - if(*reg++ != *pp++) return 0; + if(*reg++ != *pp++) return NULL; } else /* reg set */ regs[id] = s; c = *a++, s = pcap; @@ -126,8 +126,17 @@ apply_rule(Rule *r, char **regs, char *s) while((c = *a) && !spacer(c)) a++; continue; } - if(c != *s++) return 0; + if(c != *s++) return NULL; } + return s; +} + +static int +apply_rule(Rule *r, char **regs, char *s) +{ + unsigned int id; + char c, *b = r->b, *origin = dst_, *reg; + if((s = match_rule(r, regs, s)) == NULL) return 0; /* phase: write rule */ while((c = *b++)) { if(c == '?') {