modal/src/modal.c

41 lines
732 B
C
Raw Normal View History

2024-04-04 12:04:27 -04:00
#include <stdio.h>
static int
walk(FILE *f)
{
char c, token[0x40], *cptr = token;
while(f && fread(&c, 1, 1, f)) {
if(c < 0x21) {
*cptr++ = 0x00;
printf("> %s\n", token);
cptr = token;
} else if(cptr - token < 0x3f)
*cptr++ = c;
else
return printf("Token too long: %s\n", token);
}
*cptr++ = 0;
return 1;
}
static int
eval(char *path)
{
FILE *f;
if(!(f = fopen(path, "r")))
return !printf("Invalid file: %s\n", path);
walk(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, 3 Apr 2024.\n");
return !eval(argv[1]);
}