From: Adam Dickmeiss Date: Wed, 15 Jan 2014 14:04:11 +0000 (+0100) Subject: zoomsh: do not use readline for stdin (no tty) YAZ-724 X-Git-Tag: v5.0.11~2 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=02b9296d9a65ff5b325cedbd4d9455ba2edd9365 zoomsh: do not use readline for stdin (no tty) YAZ-724 Just use fgets in that case. If the user hits Ctrl-D a new-line is also printed. --- diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 607a6ff..88536d1 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -9,6 +9,10 @@ #include #endif +#if HAVE_UNISTD_H +#include +#endif + #include #include #include @@ -806,34 +810,40 @@ static int shell(ZOOM_connection *c, ZOOM_resultset *r, char buf[100000]; char *cp; const char *bp = buf; + char *line_in = 0; #if HAVE_READLINE_READLINE_H - char* line_in; - line_in = readline("ZOOM>"); - if (!line_in) + if (isatty(0)) { - res = -1; - break; - } + line_in = readline("ZOOM>"); + if (!line_in) + { + putchar('\n'); + res = -1; + break; + } #if HAVE_READLINE_HISTORY_H - if (*line_in) - add_history(line_in); + if (*line_in) + add_history(line_in); #endif - if (strlen(line_in) > sizeof(buf)-1) - { - printf("Input line too long\n"); - res = 1; - break; + if (strlen(line_in) > sizeof(buf)-1) + { + printf("Input line too long\n"); + res = 1; + break; + } + strcpy(buf,line_in); + free(line_in); } - strcpy(buf,line_in); - free(line_in); -#else - printf("ZOOM>"); fflush(stdout); - if (!fgets(buf, sizeof(buf)-1, stdin)) +#endif + if (!line_in) /* no line buffer via readline or not enabled at all */ { - res = -1; - break; + printf("ZOOM>"); fflush(stdout); + if (!fgets(buf, sizeof(buf)-1, stdin)) + { + res = -1; + break; + } } -#endif if ((cp = strchr(buf, '\n'))) *cp = '\0'; res = cmd_parse(c, r, options, &bp);