Fixed issue with writing empty register

This commit is contained in:
Devine Lu Linvega 2024-05-24 17:12:16 -07:00
parent 8431ac66f6
commit 9780e2aad7
1 changed files with 9 additions and 4 deletions

View File

@ -194,7 +194,7 @@ static int
apply_rule(Rule *r, char *s)
{
unsigned char rid;
char c, *a = r->a, *b = r->b, *origin = dst_, *reg;
char c, *a = r->a, *b = r->b, *origin = dst_, *reg, last = 0;
/* phase: clean regs */
while(stack_ != stack) regs[(int)*(--stack_)] = 0;
/* phase: match rule */
@ -216,10 +216,15 @@ apply_rule(Rule *r, char *s)
if(!spacer(c)) return 0;
/* phase: write rule */
while((c = *b++))
if(c == '?' && (rid = *b) && (reg = regs[rid]))
if(c == '?' && (rid = *b) && (reg = regs[rid])){
char *ori = dst_;
write_reg(rid, reg), b++;
else
*dst_++ = c;
if(dst_ == ori){
if(b[0] == ' ') b++;
else if(last == ' ') dst_--;
}
} else
*dst_++ = last = c;
if(dst_ == origin) {
while(*s == ' ') s++;
if(*s == ')' && *(dst_ - 1) == ' ') dst_--;