Store rules boundaries in pointer

This commit is contained in:
Devine Lu Linvega 2024-04-08 11:16:42 -07:00
parent 9b2f60e460
commit 3f6e2b9624
1 changed files with 6 additions and 5 deletions

View File

@ -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");
}