Split apply_rule
This commit is contained in:
parent
d8325fabcc
commit
6d10bb3b66
19
src/modal.c
19
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 == '?') {
|
||||
|
|
Loading…
Reference in New Issue