iris

small scheme interpreter
git clone git://git.2f30.org/iris.git
Log | Files | Refs | LICENSE

commit 36440fedf7a1810050ee29c45dcf772cdeda6d27
parent c68887a9d589fcbd27ac1c1aa1270785246cba73
Author: sin <sin@2f30.org>
Date:   Fri May  9 17:17:05 +0100

Handle gracefully non-interactive input

echo '()' | ./iris etc.

Diffstat:
repl.c | 16+++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/repl.c b/repl.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include "lexer.h" #include "debug.h" #include "util.h" @@ -25,18 +26,23 @@ main(void) { char *buf = NULL; size_t sz = 0; + int interactive = isatty(fileno(stdin)); - puts("Welcome to iris, use ^C to quit"); + if (interactive == 1) + puts("Welcome to iris, use ^C to quit"); do { - printf("> "); - fflush(stdout); + if (interactive == 1) { + printf("> "); + fflush(stdout); + } if (afgets(&buf, &sz, stdin)) lexertest(buf); if (ferror(stdin)) { fprintf(stderr, "input error\n"); return EXIT_FAILURE; } - } while (1); - /* not reachable */ + fflush(stdout); + } while (interactive == 1); + free(buf); return 0; }