commit b066e9c6dba1bbf164b41cdc975bdcc68a8a3c87
parent ff95a1d47af0763dbe7dd13bd26f89b7099227a8
Author: Ed van Bruggen <edvb@uw.edu>
Date: Sun, 16 Jun 2019 17:57:43 -0700
Support reading files
Diffstat:
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tibs/io.c b/tibs/io.c
@@ -42,8 +42,17 @@ prim_print(Env env, Val args)
static Val
prim_read(Env env, Val args)
{
- char *file;
- if (!(file = tisp_read_file(NULL)))
+ Val v;
+ char *file, *fname = NULL;
+ if (list_len(args) > 1)
+ tsp_warnf("read: expected 0 or 1 argument, received %d", list_len(args));
+ if (list_len(args) == 1) {
+ if (!(v = tisp_eval(env, car(args))))
+ return NULL;
+ tsp_arg_type(v, "read", STRING);
+ fname = v->v.s;
+ }
+ if (!(file = tisp_read_file(fname)))
return env->nil;
return mk_str(env, file);
}