aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-06 14:59:49 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-06 14:59:49 -0800
commita70b986d42c89def265a396f8cedd23c749be1f9 (patch)
tree72b88443b5ce0c1af914dc3b34906fbbde032dec /main.c
parent77afa3abf898c0535f9d2c96f6c6fc6939932c60 (diff)
fix all bug part 2
Diffstat (limited to 'main.c')
-rw-r--r--main.c11
1 files changed, 9 insertions, 2 deletions
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;
}