BC_STATUS_SUCCESS = 0,
BC_STATUS_FAILURE = 1,
BC_STATUS_PARSE_EMPTY_EXP = 2, // bc_parse_expr() uses this
+ BC_STATUS_EOF = 3, // bc_vm_stdin() uses this
} BcStatus;
#define BC_VEC_INVALID_IDX ((size_t) -1)
struct globals {
IF_FEATURE_BC_SIGNALS(smallint ttyin;)
IF_FEATURE_CLEAN_UP(smallint exiting;)
- smallint eof;
char sbgn;
char send;
static BcStatus bc_read_line(BcVec *vec, const char *prompt)
{
+ BcStatus s;
bool bad_chars;
if (G_posix) prompt = "";
+ s = BC_STATUS_SUCCESS;
do {
int c;
if (n <= 0) { // read errors or EOF, or ^D, or ^C
if (n == 0) // ^C
goto intr;
- G.eof = 1;
+ s = BC_STATUS_EOF;
break;
}
i = 0;
if (c == EOF) {
if (ferror(stdin))
quit(); // this emits error message
- G.eof = 1;
+ s = BC_STATUS_EOF;
// Note: EOF does not append '\n', therefore:
// printf 'print 123\n' | bc - works
// printf 'print 123' | bc - fails (syntax error)
bc_vec_pushZeroByte(vec);
- return BC_STATUS_SUCCESS;
+ return s;
}
static char* bc_read_file(const char *path)
// with a backslash to the parser. The reason for that is because the parser
// treats a backslash+newline combo as whitespace, per the bc spec. In that
// case, and for strings and comments, the parser will expect more stuff.
- s = BC_STATUS_SUCCESS;
- while (!G.eof && (s = bc_read_line(&buf, ">>> ")) == BC_STATUS_SUCCESS) {
+ while ((s = bc_read_line(&buf, ">>> ")) == BC_STATUS_SUCCESS) {
char *string = buf.v;
bc_vec_pop_all(&buffer);
}
+ if (s == BC_STATUS_EOF) // input EOF (^D) is not an error
+ s = BC_STATUS_SUCCESS;
if (str) {
s = bc_error("string end could not be found");