diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/builtins.c | 3 | ||||
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | src/stem.c | 4 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/builtins.c b/src/builtins.c index eb4b521..5c42516 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -8,6 +8,7 @@ #include <string.h> #include <unistd.h> +/* macros taken from stackoverflow */ #define MAX 1000 #define JUSTDO(a) \ if (!(a)) { \ @@ -18,7 +19,6 @@ extern array_t *STACK; extern array_t *EVAL_STACK; extern ht_t *WORD_TABLE; -extern char *INBUF; extern parser_t *PARSER; extern ht_t *FLIT; @@ -28,6 +28,7 @@ extern ht_t *OBJ_TABLE; * (for quotes), split (split array, string, word into two), del (deleting * entries from quotes, strings, words) */ +/* taken from stackoverflow */ char *get_line(FILE *f) { int len = MAX; char buf[MAX], *e = NULL, *ret; @@ -7,9 +7,7 @@ #include <unistd.h> extern ht_t *WORD_TABLE; - extern array_t *STACK; -extern char *INBUF; extern parser_t *PARSER; extern array_t *EVAL_STACK; extern ht_t *OBJ_TABLE; @@ -29,7 +27,9 @@ void version() { int main(int argc, char **argv) { value_t *v; size_t len; + char *buf; + /* Parsing arguments */ if (argc < 2) { usage(); } @@ -40,16 +40,18 @@ int main(int argc, char **argv) { version(); } + /* Read code from file */ FILE *FP = fopen(argv[1], "rb"); if (!FP) { usage(); } - ssize_t bytes_read = getdelim(&INBUF, &len, '\0', FP); + ssize_t bytes_read = getdelim(&buf, &len, '\0', FP); fclose(FP); - PARSER = parser_pp(INBUF); + /* Set up global variables */ + PARSER = parser_pp(buf); STACK = init_array(10); WORD_TABLE = init_ht(500); EVAL_STACK = init_array(10); @@ -58,6 +60,7 @@ int main(int argc, char **argv) { add_funcs(); + /* parse and eval loop */ while (1) { v = parser_get_next(PARSER); if (v == NULL) @@ -65,6 +68,7 @@ int main(int argc, char **argv) { eval(v); } + /* Free all global variables */ free(PARSER->source); ht_free(WORD_TABLE, value_free); ht_free(FLIT, func_free); @@ -7,10 +7,10 @@ #include <stem.h> #include <string.h> +/* Global variables defined */ array_t *STACK; array_t *EVAL_STACK; ht_t *WORD_TABLE; -char *INBUF; parser_t *PARSER; ht_t *FLIT; @@ -165,7 +165,7 @@ parser_t *parser_pp(char *s) { parser_t *p = init_parser(s); string_t *rstr = init_string(NULL); while (p->c != '\0') { - if (p->c == '#') { + if (p->c == '#') { /* Comment character is # in stem */ while (p->c != '\n' && p->c != '\0') { parser_move(p); } |