diff --git a/src/modal.c b/src/modal.c index ff74cc4..e04ae04 100644 --- a/src/modal.c +++ b/src/modal.c @@ -4,7 +4,7 @@ typedef struct { char *a, *b; } Rule; -static int rules_len; +static int rules_len, direction = 0; static Rule rules[0x100]; static char dict[0x8000], *dict_ = dict; static char bank_a[0x1000], *prog_ = bank_a; @@ -89,11 +89,11 @@ bind(char r) static void save(int rule) { - int i, end = outp_ - bank_b; - /* todo: change pointer instead of copying memory */ - for(i = 0; i <= end; i++) bank_a[i] = bank_b[i]; - prog_ = bank_a, outp_ = bank_b; - printf("%02d %s\n", rule, bank_a); + if((direction = !direction)) + prog_ = bank_b, outp_ = bank_a; + else + prog_ = bank_a, outp_ = bank_b; + printf("%02d %s\n", rule, direction ? bank_b : bank_a); } static char * @@ -138,7 +138,7 @@ addrule(char *s) static int rewrite(void) { - char c, *p = bank_a; + char c, *p = direction ? bank_b : bank_a; while((c = *p)) { int i; if(p[0] == '<' && p[1] == '>')