]> www.ginac.de Git - ginac.git/commitdiff
[PATCH] Make ginsh evaluate line-by-line in non-interactive mode.
authorVitaly Magerya <vmagerya@gmail.com>
Wed, 21 Jun 2023 18:48:36 +0000 (20:48 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Wed, 21 Jun 2023 18:48:36 +0000 (20:48 +0200)
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.

ginsh/ginsh_lexer.lpp

index 8692b1ac4fea6a7e1a80d0445939b5c9c6e6e7b9..5169ecef82865567ab8097f91f277a667e6a422f 100644 (file)
@@ -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;
 }