From: Vitaly Magerya Date: Wed, 21 Jun 2023 18:48:36 +0000 (+0200) Subject: [PATCH] Make ginsh evaluate line-by-line in non-interactive mode. X-Git-Tag: release_1-8-7~4 X-Git-Url: https://ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=4bc2092e2f15a6422774c34c7f8fa4079be67d08 [PATCH] Make ginsh evaluate line-by-line in non-interactive mode. When used interactively ginsh consumes the input line-by-line, so if a complete expression is entered it is enough to end the line to get an evaluated result. In the non-interative mode (i.e. if the input is not a tty) the input is consumed in blocks, making it impossible to use ginsh as a subprocess. This patch makes the non-interactive mode reuse the same line parsing logic as the interactive mode (without readline), but skips printing the "> " prompt, preserving the backward compatibility. --- diff --git a/ginsh/ginsh_lexer.lpp b/ginsh/ginsh_lexer.lpp index 8692b1ac..5169ecef 100644 --- a/ginsh/ginsh_lexer.lpp +++ b/ginsh/ginsh_lexer.lpp @@ -203,8 +203,16 @@ static int ginsh_input(char *buf, int max_size) YY_FATAL_ERROR("input in flex scanner failed"); result = n; #endif - } else if (((result = fread(buf, 1, max_size, yyin)) == 0) && ferror(yyin)) - YY_FATAL_ERROR("input in flex scanner failed"); + } else { + int c = '*', n; + for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; ++n) + buf[n] = (char)c; + if (c == '\n') + buf[n++] = (char)c; + if (c == EOF && ferror(yyin)) + YY_FATAL_ERROR("input in flex scanner failed"); + result = n; + } return result; }