tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 4892c6efba8257742ee25271b9e3493927a27e83
parent c2747457ab8d62e36ae74cd178b75e6fba1c3e45
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Tue, 26 Nov 2019 21:00:27 -0800

Check for NULL from tisp_eval in main

Diffstat:
main.c | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c @@ -18,7 +18,7 @@ main(int argc, char *argv[]) { int i; struct Str str = { NULL }; - Val v; + Val v = NULL; Env env = tisp_env_init(64); #ifndef TIB_DYNAMIC @@ -30,10 +30,12 @@ main(int argc, char *argv[]) tisp_env_lib(env, libs_tsp); #endif + /* TODO reduce redunecy by setting argv[i][0] = '-' ? */ if (argc == 1) - tisp_print(stdout, tisp_eval_list(env, tisp_parse_file(env, NULL))); + if ((v = tisp_eval_list(env, tisp_parse_file(env, NULL)))) + tisp_print(stdout, v); - for (i = 1; i < argc; i++) { + for (i = 1; i < argc; i++, v = NULL) { if (argv[i][0] == '-') { if (argv[i][1] == 'c') { /* run next argument as tisp command */ if (!(str.d = argv[++i])) { @@ -41,7 +43,7 @@ main(int argc, char *argv[]) exit(2); } if ((v = tisp_read(env, &str))) - tisp_print(stdout, tisp_eval(env, v)); + v = tisp_eval(env, v); } else if (argv[i][1] == 'v') { /* version and copyright info */ fprintf(stderr, "tisp v%s (c) 2017-2019 Ed van Bruggen\n", VERSION); exit(0); @@ -49,11 +51,12 @@ main(int argc, char *argv[]) fputs("usage: tisp [-hv] [FILE ...]\n", stderr); exit(argv[i][1] == 'h' ? 0 : 1); } else { /* single hypen read from stdin */ - tisp_print(stdout, tisp_eval_list(env, tisp_parse_file(env, NULL))); + v = tisp_eval_list(env, tisp_parse_file(env, NULL)); } } else { /* otherwise read as file */ - tisp_print(stdout, tisp_eval_list(env, tisp_parse_file(env, argv[i]))); + v = tisp_eval_list(env, tisp_parse_file(env, argv[i])); } + if (v) tisp_print(stdout, v); } puts("");