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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static char *
|
||||||
apply_rule(Rule *r, char **regs, char *s)
|
match_rule(Rule *r, char **regs, char *s)
|
||||||
{
|
{
|
||||||
unsigned int i, id;
|
unsigned int i, id;
|
||||||
char c, *a = r->a, *b = r->b, *origin = dst_, *reg;
|
char c, *a = r->a, *reg;
|
||||||
/* phase: clean registers */
|
/* phase: clean registers */
|
||||||
for(i = 0; i < r->ptr; i++)
|
for(i = 0; i < r->ptr; i++)
|
||||||
regs[i] = NULL;
|
regs[i] = NULL;
|
||||||
|
@ -118,7 +118,7 @@ apply_rule(Rule *r, char **regs, char *s)
|
||||||
if((reg = regs[id])) { /* reg cmp */
|
if((reg = regs[id])) { /* reg cmp */
|
||||||
char *rcap = walk(reg), *pp = s;
|
char *rcap = walk(reg), *pp = s;
|
||||||
while(reg < rcap || pp < pcap)
|
while(reg < rcap || pp < pcap)
|
||||||
if(*reg++ != *pp++) return 0;
|
if(*reg++ != *pp++) return NULL;
|
||||||
} else /* reg set */
|
} else /* reg set */
|
||||||
regs[id] = s;
|
regs[id] = s;
|
||||||
c = *a++, s = pcap;
|
c = *a++, s = pcap;
|
||||||
|
@ -126,8 +126,17 @@ apply_rule(Rule *r, char **regs, char *s)
|
||||||
while((c = *a) && !spacer(c)) a++;
|
while((c = *a) && !spacer(c)) a++;
|
||||||
continue;
|
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 */
|
/* phase: write rule */
|
||||||
while((c = *b++)) {
|
while((c = *b++)) {
|
||||||
if(c == '?') {
|
if(c == '?') {
|
||||||
|
|
Loading…
Reference in New Issue