From 3f6e2b96241aa25854b6518356578ea1520b6f7a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 8 Apr 2024 11:16:42 -0700 Subject: [PATCH] Store rules boundaries in pointer --- src/modal.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modal.c b/src/modal.c index 22a71f1..ee1e872 100644 --- a/src/modal.c +++ b/src/modal.c @@ -5,7 +5,7 @@ typedef struct { } Rule; static int rules_len, direction; -static Rule rules[0x100]; +static Rule rules[0x100], *rules_; static char dict[0x8000], *dict_ = dict; static char bank_a[0x4000], *prog_ = bank_a; static char bank_b[0x4000], *outp_ = bank_b; @@ -138,6 +138,7 @@ add_rule(char *p) { char c; Rule *r = &rules[rules_len++]; + rules_++; p += 2; while((c = *p) && c <= ' ') p++; r->a = parse_rule(p), p = walk(p); @@ -152,10 +153,10 @@ rewrite(void) char c, last = 0, *p = direction ? bank_b : bank_a; while((c = *p) && c <= ' ') p++; while((c = *p)) { - int i; if(p[0] == '<' && p[1] == '>') return add_rule(p); if(spacer(last)) { + int i; for(i = 0; i < rules_len; i++) { Rule *r = &rules[i]; char *res = match_rule(p, r); @@ -182,10 +183,10 @@ rewrite(void) static void print_rules(void) { - int i; + Rule *r = rules; fprintf(stderr, "\n"); - for(i = 0; i < rules_len; i++) - fprintf(stderr, "<> (%s) (%s)\n", rules[i].a, rules[i].b); + while(r++ < rules_) + fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b); fprintf(stderr, "\n"); }