Abstracted match/write rule

This commit is contained in:
Devine Lu Linvega 2024-04-22 17:39:39 -07:00
parent 8e7bbb51d7
commit 4fce0e83e5
1 changed files with 11 additions and 3 deletions

View File

@ -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++;