Abstracted match/write rule
This commit is contained in:
parent
8e7bbb51d7
commit
4fce0e83e5
14
src/modal.c
14
src/modal.c
|
@ -165,10 +165,19 @@ parse_frag(char *s)
|
||||||
return 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
|
static int
|
||||||
rewrite(void)
|
rewrite(void)
|
||||||
{
|
{
|
||||||
char c, last = 0, *cap, *s = src_, *res;
|
char c, last = 0, *cap, *s = src_;
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
while((c = *s)) {
|
while((c = *s)) {
|
||||||
if(spacer(last)) {
|
if(spacer(last)) {
|
||||||
|
@ -190,8 +199,7 @@ rewrite(void)
|
||||||
} else
|
} else
|
||||||
r = rules + 1;
|
r = rules + 1;
|
||||||
for(; r < rules_; r++)
|
for(; r < rules_; r++)
|
||||||
if((res = match_rule(r, s)) != NULL)
|
if(run_rule(r, s)) return 1;
|
||||||
return write_rule(r, res);
|
|
||||||
}
|
}
|
||||||
*dst_++ = last = c;
|
*dst_++ = last = c;
|
||||||
s++;
|
s++;
|
||||||
|
|
Loading…
Reference in New Issue