Inlined load

This commit is contained in:
Devine Lu Linvega 2024-04-07 10:58:39 -07:00
parent 2250f9231e
commit 98748fb44d
1 changed files with 9 additions and 16 deletions

View File

@ -213,12 +213,17 @@ print_rules(void)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
static int int
load(char *path) main(int argc, char **argv)
{ {
FILE *f;
char c, *w = bank_a; char c, *w = bank_a;
FILE *f = fopen(path, "r"); if(argc < 2)
if(!f) return 0; return !printf("usage: modal [-v] source.modal\n");
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
return !printf("Modal - Modal Interpreter, 4 Apr 2024.\n");
if(!(f = fopen(argv[1], "r")))
return !printf("Invalid Modal file: %s.\n", argv[1]);
while(fread(&c, 1, 1, f)) { while(fread(&c, 1, 1, f)) {
if(prog_ > bank_a) { if(prog_ > bank_a) {
if(c == ')' && *(w - 1) == ' ') w--; if(c == ')' && *(w - 1) == ' ') w--;
@ -231,18 +236,6 @@ load(char *path)
} }
*w++ = 0; *w++ = 0;
fclose(f); fclose(f);
return 1;
}
int
main(int argc, char **argv)
{
if(argc < 2)
return !printf("usage: modal [-v] source.modal\n");
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
return !printf("Modal - Modal Interpreter, 4 Apr 2024.\n");
if(!load(argv[1]))
return !printf("Invalid Modal file: %s.\n", argv[1]);
queue = 2; queue = 2;
while(rewrite(argv[queue])) while(rewrite(argv[queue]))
; ;