tisp

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

commit b13a59fb6ab6f57c269e0ac2aceb8202dfbac01c
parent 2e4800a32eca935b04d10aa4a4d4165f6352fb96
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 23 Aug 2018 23:23:49 -0700

Remove util.c dependency in tisp.c

Diffstat:
tisp.c | 49++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/tisp.c b/tisp.c @@ -21,18 +21,65 @@ #include <ctype.h> #include <dlfcn.h> #include <limits.h> +#include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "tisp.h" -#include "util.h" + +#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) /* functions */ static Hash hash_extend(Hash ht, Val args, Val vals); static void hash_merge(Hash ht, Hash ht2); +static void +die(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } else { + fputc('\n', stderr); + } + + exit(1); +} + +static void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + if (!(p = calloc(nmemb, size))) + die("calloc:"); + return p; +} + +static void * +emalloc(size_t size) +{ + void *p; + if (!(p = malloc(size))) + die("malloc:"); + return p; +} + +static void * +erealloc(void *p, size_t size) +{ + if (!(p = realloc(p, size))) + die("realloc:"); + return p; +} + void skip_spaces(Str str) {