tisp

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

commit 23d8b441a09ac855870b5e9f4310b3ef1d0f78af
parent 71930bd11825b7c2bb594985ed81733f3c4f5308
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Wed,  7 Oct 2020 14:26:28 -0700

Use comma operator to simplify error handling

Diffstat:
tib/io.c | 6++----
tib/os.c | 9++++-----
tisp.c | 18++++++------------
3 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/tib/io.c b/tib/io.c @@ -135,10 +135,8 @@ prim_open(Tsp st, Hash env, Val args) char *fname; struct Val v; Val ret; - if (!(ret = malloc(sizeof(struct Val)))) { - perror("; malloc"); - exit(1); - } + if (!(ret = malloc(sizeof(struct Val)))) + perror("; malloc"), exit(1); tsp_arg_min(args, "open", 1); if (!(args = tisp_eval_list(st, env, args))) return NULL; diff --git a/tib/os.c b/tib/os.c @@ -36,14 +36,13 @@ prim_cd(Tsp st, Hash env, Val args) return NULL; if (!(v->t & (TSP_STR|TSP_SYM))) tsp_warnf("strlen: expected string or symbol, received %s", type_str(v->t)); - if (chdir(v->v.s)) { - perror("; tisp: error: cd"); - return NULL; - } + if (chdir(v->v.s)) + return perror("; error: cd"), NULL; return st->none; } -/* print current working directory */ +/* TODO rename to cwd ? */ +/* return string of current working directory */ static Val prim_pwd(Tsp st, Hash env, Val args) { diff --git a/tisp.c b/tisp.c @@ -44,10 +44,8 @@ static void * ecalloc(size_t nmemb, size_t size) { void *p; - if (!(p = calloc(nmemb, size))) { - perror("; calloc"); - exit(1); - } + if (!(p = calloc(nmemb, size))) + perror("; calloc"), exit(1); return p; } @@ -55,20 +53,16 @@ static void * emalloc(size_t size) { void *p; - if (!(p = malloc(size))) { - perror("; malloc"); - exit(1); - } + if (!(p = malloc(size))) + perror("; malloc"), exit(1); return p; } static void * erealloc(void *p, size_t size) { - if (!(p = realloc(p, size))) { - perror("; realloc"); - exit(1); - } + if (!(p = realloc(p, size))) + perror("; realloc"), exit(1); return p; }