This commit is contained in:
parent
e109696e7c
commit
22312cf425
44
src/modal.c
44
src/modal.c
|
@ -1,18 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/* 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;
|
||||
|
|
Loading…
Reference in New Issue