From 22312cf42545fa2ed1fcdfa527399aab56e5c321 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 10:01:09 -0700 Subject: [PATCH] * --- src/modal.c | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/modal.c b/src/modal.c index 40e72e3..96b23e5 100644 --- a/src/modal.c +++ b/src/modal.c @@ -1,18 +1,13 @@ #include -/* dict */ - -static char dict[0x8000], *next = dict; - -/* rule */ - typedef struct { - char *a; - char *b; + char *a, *b; } Rule; static int rules_len; static Rule rules[0x100]; +static char dict[0x8000], *next = dict; +static char program[0x1000], *prog_ = program; static char * addside(FILE *f) @@ -38,10 +33,6 @@ addrule(FILE *f) r->a = addside(f), r->b = addside(f); } -/* program */ - -static char program[0x1000], *prog_ = program; - static void addprogram(FILE *f) { @@ -61,23 +52,6 @@ tokenize(char *t, FILE *f) addprogram(f); } -static int -walk(FILE *f) -{ - char c, token[0x40], *tokptr; - tokptr = token; - while(f && fread(&c, 1, 1, f)) { - if(c < 0x21) - *tokptr++ = 0x00, tokenize(token, f), tokptr = token; - else if(tokptr - token < 0x3f) - *tokptr++ = c; - else - return printf("Token too long: %s\n", token); - } - *tokptr++ = 0x00, tokenize(token, f), tokptr = token; - return 1; -} - static void display() { @@ -93,9 +67,19 @@ static int eval(char *path) { FILE *f; + char c, token[0x40], *tokptr; if(!(f = fopen(path, "r"))) return !printf("Invalid file: %s\n", path); - walk(f); + tokptr = token; + while(f && fread(&c, 1, 1, f)) { + if(c < 0x21) + *tokptr++ = 0x00, tokenize(token, f), tokptr = token; + else if(tokptr - token < 0x3f) + *tokptr++ = c; + else + return printf("Token too long: %s\n", token); + } + *tokptr++ = 0x00, tokenize(token, f), tokptr = token; display(); fclose(f); return 1;