Let save handle the rest of the string

This commit is contained in:
Devine Lu Linvega 2024-04-07 14:55:55 -07:00
parent 18d1987568
commit 6cb6c810d9
1 changed files with 8 additions and 11 deletions

View File

@ -121,9 +121,12 @@ commit(char r, char *incoming)
return 1; return 1;
} }
static void static int
save(int rule) save(int rule, char *p)
{ {
while((*outp_++ = *p++))
;
*outp_++ = 0;
if((direction = !direction)) if((direction = !direction))
prog_ = bank_b, outp_ = bank_a; prog_ = bank_b, outp_ = bank_a;
else else
@ -133,6 +136,7 @@ save(int rule)
while(program[1] && program[0] < 0x21) program++; while(program[1] && program[0] < 0x21) program++;
fprintf(stderr, "%02d %s\n", rule, program); fprintf(stderr, "%02d %s\n", rule, program);
} }
return 1;
} }
static char * static char *
@ -174,10 +178,7 @@ rewrite(char *incoming)
p += 3; p += 3;
r->a = parse_rulefrag(p), p = walk(p) + 1; r->a = parse_rulefrag(p), p = walk(p) + 1;
r->b = parse_rulefrag(p), p = walk(p); r->b = parse_rulefrag(p), p = walk(p);
while((*outp_++ = *p++)) return save(-1, p);
;
save(-1);
return 1;
} }
if(p == bank_a || p == bank_b || spacer(*(p - 1))) { if(p == bank_a || p == bank_b || spacer(*(p - 1))) {
for(i = 0; i < rules_len; i++) { for(i = 0; i < rules_len; i++) {
@ -191,11 +192,7 @@ rewrite(char *incoming)
else else
*outp_++ = cc; *outp_++ = cc;
} }
while((*outp_++ = *res++)) return save(i, res);
;
*outp_++ = 0;
save(i);
return 1;
} }
} }
} }