Store rules boundaries in pointer
This commit is contained in:
parent
9b2f60e460
commit
3f6e2b9624
11
src/modal.c
11
src/modal.c
|
@ -5,7 +5,7 @@ typedef struct {
|
||||||
} Rule;
|
} Rule;
|
||||||
|
|
||||||
static int rules_len, direction;
|
static int rules_len, direction;
|
||||||
static Rule rules[0x100];
|
static Rule rules[0x100], *rules_;
|
||||||
static char dict[0x8000], *dict_ = dict;
|
static char dict[0x8000], *dict_ = dict;
|
||||||
static char bank_a[0x4000], *prog_ = bank_a;
|
static char bank_a[0x4000], *prog_ = bank_a;
|
||||||
static char bank_b[0x4000], *outp_ = bank_b;
|
static char bank_b[0x4000], *outp_ = bank_b;
|
||||||
|
@ -138,6 +138,7 @@ add_rule(char *p)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
Rule *r = &rules[rules_len++];
|
Rule *r = &rules[rules_len++];
|
||||||
|
rules_++;
|
||||||
p += 2;
|
p += 2;
|
||||||
while((c = *p) && c <= ' ') p++;
|
while((c = *p) && c <= ' ') p++;
|
||||||
r->a = parse_rule(p), p = walk(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;
|
char c, last = 0, *p = direction ? bank_b : bank_a;
|
||||||
while((c = *p) && c <= ' ') p++;
|
while((c = *p) && c <= ' ') p++;
|
||||||
while((c = *p)) {
|
while((c = *p)) {
|
||||||
int i;
|
|
||||||
if(p[0] == '<' && p[1] == '>')
|
if(p[0] == '<' && p[1] == '>')
|
||||||
return add_rule(p);
|
return add_rule(p);
|
||||||
if(spacer(last)) {
|
if(spacer(last)) {
|
||||||
|
int i;
|
||||||
for(i = 0; i < rules_len; i++) {
|
for(i = 0; i < rules_len; i++) {
|
||||||
Rule *r = &rules[i];
|
Rule *r = &rules[i];
|
||||||
char *res = match_rule(p, r);
|
char *res = match_rule(p, r);
|
||||||
|
@ -182,10 +183,10 @@ rewrite(void)
|
||||||
static void
|
static void
|
||||||
print_rules(void)
|
print_rules(void)
|
||||||
{
|
{
|
||||||
int i;
|
Rule *r = rules;
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
for(i = 0; i < rules_len; i++)
|
while(r++ < rules_)
|
||||||
fprintf(stderr, "<> (%s) (%s)\n", rules[i].a, rules[i].b);
|
fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue