From d168e7e1c8a3d521854dbde3e888a2b6a92191fe Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 21:44:54 +0900 Subject: [PATCH] catch read error in repl --- tools/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/main.c b/tools/main.c index a50f2cf6..0d648d20 100644 --- a/tools/main.c +++ b/tools/main.c @@ -56,6 +56,7 @@ repl(pic_state *pic) char *prompt; struct pic_proc *proc; pic_value v, exprs; + jmp_buf jmp; int ai; #if PIC_ENABLE_READLINE @@ -102,6 +103,17 @@ repl(pic_state *pic) goto overflow; strcat(code, line); + if (setjmp(jmp) == 0) { + pic->jmp = &jmp; + } + else { + /* error occured */ + printf("%s\n", pic_errmsg(pic)); + code[0] = '\0'; + pic->err = NULL; + goto next; + } + /* read */ exprs = pic_read_cstr(pic, code); if (pic_undef_p(exprs)) { /* wait for more input */