diff --git a/src/modal.c b/src/modal.c index b05b764..128fa88 100644 --- a/src/modal.c +++ b/src/modal.c @@ -55,16 +55,15 @@ static void save(void) { int i, end = outp_ - outp; - for(i = 0; i < end; i++) prog[i] = outp[i]; - prog[i] = 0; - prog_ = prog; - outp_ = outp; + for(i = 0; i <= end; i++) prog[i] = outp[i]; + prog_ = prog, outp_ = outp; printf(".. %s\n", prog); } static int rewrite(void) { + int success = 0; char c, *p = prog; while((c = *p)) { int i, found = 0; @@ -78,7 +77,7 @@ rewrite(void) writereg(*b++); else *outp_++ = cc; - found = 1; + found = success = 1; p = res; } } @@ -88,8 +87,9 @@ rewrite(void) } } *outp_++ = 0; - save(); - return 1; + if(success) + save(); + return success; } static void @@ -165,7 +165,7 @@ main(int argc, char **argv) parse(argv[1]); print_rules(); printf(".. %s\n", prog); - rewrite(); - rewrite(); + while(rewrite()) + ; return 0; } \ No newline at end of file