From 4fce0e83e54e329a731b1d1dea17d2688b002542 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 22 Apr 2024 17:39:39 -0700 Subject: [PATCH] Abstracted match/write rule --- src/modal.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/modal.c b/src/modal.c index c9e677c..86a888d 100644 --- a/src/modal.c +++ b/src/modal.c @@ -165,10 +165,19 @@ parse_frag(char *s) return 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; +} + static int rewrite(void) { - char c, last = 0, *cap, *s = src_, *res; + char c, last = 0, *cap, *s = src_; while(*s == ' ') s++; while((c = *s)) { if(spacer(last)) { @@ -190,8 +199,7 @@ rewrite(void) } else r = rules + 1; for(; r < rules_; r++) - if((res = match_rule(r, s)) != NULL) - return write_rule(r, res); + if(run_rule(r, s)) return 1; } *dst_++ = last = c; s++;