}
// This is not a "z" function: can also return BC_STATUS_EOF
+// Can return success (0) or BC_STATUS_EOF.
+// Exits with error message if read error is detected.
static BcStatus bc_read_line(BcVec *vec)
{
BcStatus s;
G.prog.file = NULL;
s = bc_read_line(&buf);
- if (s) goto io_err;
+ //if (s) goto io_err; - wrong, nonzero return means EOF, not error
common_parse_init(&parse, BC_PROG_READ);
bc_lex_file(&parse.l);
bc_vec_push(&G.prog.stack, &ip);
exec_err:
- G.prog.file = sv_file;
bc_parse_free(&parse);
-io_err:
+//io_err:
+ G.prog.file = sv_file;
bc_vec_free(&buf);
return s;
}
{
BcStatus s;
BcVec buf, buffer;
- size_t len, i, str = 0;
- bool comment = false;
+ size_t str;
+ bool comment;
G.prog.file = NULL;
bc_lex_file(&G.prs.l);
// 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.
+ comment = false;
+ str = 0;
while ((s = bc_read_line(&buf)) == BC_STATUS_SUCCESS) {
-
+ size_t len;
char *string = buf.v;
len = buf.len - 1;
-
if (len == 1) {
if (str && buf.v[0] == G.send)
str -= 1;
str += 1;
}
else if (len > 1 || comment) {
-
+ size_t i;
for (i = 0; i < len; ++i) {
-
bool notend = len > i + 1;
char c = string[i];