From a70b986d42c89def265a396f8cedd23c749be1f9 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Sat, 6 Jan 2024 14:59:49 -0800 Subject: fix all bug part 2 --- main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 7ffdccd..0b7ecd9 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ extern ht_t *WORD_TABLE; extern array_t *STACK; extern char *INBUF; extern parser_t *PARSER; +extern array_t *EVAL_STACK; void usage() { printf("Usage: stem [-hv] [file]\n"); @@ -15,7 +16,7 @@ void usage() { void version() { printf("Author: Preston Pan, MIT License 2023\n"); - printf("stem, version 1.0\n"); + printf("stem, version 1.1\n"); exit(0); } @@ -34,6 +35,11 @@ int main(int argc, char **argv) { } FILE *FP = fopen(argv[1], "rb"); + + if (!FP) { + usage(); + } + ssize_t bytes_read = getdelim(&INBUF, &len, '\0', FP); if (FP != NULL) { fflush(FP); @@ -43,7 +49,7 @@ int main(int argc, char **argv) { PARSER = init_parser(INBUF); STACK = init_array(10); WORD_TABLE = init_ht(500); - + EVAL_STACK = init_array(10); while (1) { v = parser_get_next(PARSER); if (v == NULL) @@ -56,5 +62,6 @@ int main(int argc, char **argv) { array_free(STACK); free(PARSER); free(INBUF); + array_free(EVAL_STACK); return 0; } -- cgit