Merged all regs needing functions

This commit is contained in:
Devine Lu Linvega 2024-04-22 17:43:35 -07:00
parent 4fce0e83e5
commit 9b034eac95
1 changed files with 30 additions and 39 deletions

View File

@ -77,41 +77,6 @@ put_reg(char r, char *reg)
while(reg < cap) *dst_++ = *reg++; while(reg < cap) *dst_++ = *reg++;
} }
static char *
match_rule(Rule *r, char *p)
{
int i;
char c, *a = r->a;
if(rmax) {
for(i = rmin; i <= rmax; i++)
regs[i] = 0;
rmin = 0xff, rmax = 0x00;
}
while((c = *a)) {
if(c == '?') {
int regid = (int)*(++a);
char *pcap = walk(p), *reg = regs[regid];
if(reg) { /* reg cmp */
char *rcap = walk(reg), *pp = p;
while(reg < rcap || pp < pcap)
if(*reg++ != *pp++) return NULL;
} else { /* reg set */
regs[regid] = p;
if(regid < rmin) rmin = regid;
if(regid > rmax) rmax = regid;
}
a++, p = pcap;
if(!spacer(*a))
while((c = *a) && !spacer(c)) a++;
continue;
}
if(c != *p) return NULL;
a++, p++;
}
c = *p;
return spacer(c) ? p : NULL;
}
static int static int
commit_rule(Rule *r, char *s, int create) commit_rule(Rule *r, char *s, int create)
{ {
@ -168,10 +133,36 @@ parse_frag(char *s)
static int static int
run_rule(Rule *r, char *s) run_rule(Rule *r, char *s)
{ {
char *res; int i;
if((res = match_rule(r, s)) != NULL) char c, *a = r->a, *p = s;
return write_rule(r, res); if(rmax) {
return 0; for(i = rmin; i <= rmax; i++)
regs[i] = 0;
rmin = 0xff, rmax = 0x00;
}
while((c = *a)) {
if(c == '?') {
int regid = (int)*(++a);
char *pcap = walk(p), *reg = regs[regid];
if(reg) { /* reg cmp */
char *rcap = walk(reg), *pp = p;
while(reg < rcap || pp < pcap)
if(*reg++ != *pp++) return 0;
} else { /* reg set */
regs[regid] = p;
if(regid < rmin) rmin = regid;
if(regid > rmax) rmax = regid;
}
a++, p = pcap;
if(!spacer(*a))
while((c = *a) && !spacer(c)) a++;
continue;
}
if(c != *p) return 0;
a++, p++;
}
c = *p;
return spacer(c) ? write_rule(r, p) : 0;
} }
static int static int