X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzoomsh.c;h=88536d1407c14c891993aebb41d7b215bf619c0b;hb=609ad9573e7ea6450727297bdd36080cf38a9032;hp=fde447e4c6fc12822033114bcb4ae2ec8528b59f;hpb=5242cb5a8634bfa38b9333ff7f903e718ac6e292;p=yaz-moved-to-github.git diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index fde447e..88536d1 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2012 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ /** \file zoomsh.c @@ -9,6 +9,10 @@ #include #endif +#if HAVE_UNISTD_H +#include +#endif + #include #include #include @@ -752,7 +756,7 @@ static int cmd_parse(ZOOM_connection *c, ZOOM_resultset *r, cmd_len = next_token(buf, &cmd_str); if (cmd_len < 0) - return -1; + return 0; if (is_command("quit", cmd_str, cmd_len)) return -1; else if (is_command("set", cmd_str, cmd_len)) @@ -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);