diff --git a/eval.c b/eval.c index 00845b28..4588a1a4 100644 --- a/eval.c +++ b/eval.c @@ -778,7 +778,15 @@ int main (int argc, char **argv) { for (i=1; i < argc && argv[i][0] == '-'; i++) { switch (argv[i][1]) { case 'e': + case 'p': + obj = sexp_read_from_string(argv[i+1]); + res = eval_in_stack(obj, e, stack, 0); + if (argv[i][1] == 'p') { + sexp_write(res, cur_output_port); + sexp_write_char('\n', cur_output_port); + } quit=1; + i++; break; default: errx(1, "unknown option: %s", argv[i]); diff --git a/sexp.c b/sexp.c index 16c060c5..eb180664 100644 --- a/sexp.c +++ b/sexp.c @@ -753,6 +753,15 @@ sexp sexp_read (sexp in) { return res; } +sexp sexp_read_from_string(char *str) { + sexp s = sexp_make_string(str); + sexp in = sexp_make_input_string_port(s); + sexp res = sexp_read(in); + sexp_free(s); + sexp_free(in); + return res; +} + void sexp_init() { if (! sexp_initialized_p) { sexp_initialized_p = 1; diff --git a/sexp.h b/sexp.h index 729110fb..fed7ae22 100644 --- a/sexp.h +++ b/sexp.h @@ -232,6 +232,7 @@ char* sexp_read_symbol(sexp in, int init); sexp sexp_read_number(sexp in, int base); sexp sexp_read_raw(sexp in); sexp sexp_read(sexp in); +sexp sexp_read_from_string(char *str); sexp sexp_make_input_port(FILE* in); sexp sexp_make_output_port(FILE* out); sexp sexp_make_input_string_port(sexp str);