aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/bc.c
diff options
context:
space:
mode:
Diffstat (limited to 'toys/pending/bc.c')
-rw-r--r--toys/pending/bc.c32
1 files changed, 5 insertions, 27 deletions
diff --git a/toys/pending/bc.c b/toys/pending/bc.c
index 5d0e98e9..bb5d86cb 100644
--- a/toys/pending/bc.c
+++ b/toys/pending/bc.c
@@ -536,7 +536,6 @@ BcStatus bc_lex_token(BcLex *l);
BcStatus bc_parse_parse(BcParse *p);
BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next);
-void bc_parse_noElse(BcParse *p);
#define BC_PROG_ONE_CAP (1)
@@ -678,7 +677,7 @@ char *bc_err_msgs[] = {
"negative number",
"non integer number",
- "overflow",
+ "overflow; %s",
"divide by zero",
"could not open file: %s",
@@ -1722,7 +1721,6 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *c, size_t scale) {
return BC_STATUS_SUCCESS;
}
if (!a->len) {
- if (b->neg) return bc_vm_err(BC_ERROR_MATH_DIVIDE_BY_ZERO);
bc_num_setToZero(c, scale);
return BC_STATUS_SUCCESS;
}
@@ -3594,8 +3592,6 @@ static BcStatus bc_parse_endBody(BcParse *p, int brace) {
new_else = (p->l.t == BC_LEX_KEY_ELSE);
if (new_else) s = bc_parse_else(p);
- else if (!has_brace && (!BC_PARSE_IF_END(p) || brace))
- bc_parse_noElse(p);
}
if (brace && has_brace) brace = 0;
@@ -3605,15 +3601,6 @@ static BcStatus bc_parse_endBody(BcParse *p, int brace) {
if (!s && p->flags.len == 1 && brace)
s = bc_parse_err(p, BC_ERROR_PARSE_TOKEN);
- else if (brace && BC_PARSE_BRACE(p)) {
- uint16_t flags = BC_PARSE_TOP_FLAG(p);
- if (!(flags & (BC_PARSE_FLAG_FUNC_INNER | BC_PARSE_FLAG_LOOP_INNER)) &&
- !(flags & (BC_PARSE_FLAG_IF | BC_PARSE_FLAG_ELSE)) &&
- !(flags & (BC_PARSE_FLAG_IF_END)))
- {
- bc_vec_pop(&p->flags);
- }
- }
return s;
}
@@ -3624,7 +3611,7 @@ static void bc_parse_startBody(BcParse *p, uint16_t flags) {
bc_vec_push(&p->flags, &flags);
}
-void bc_parse_noElse(BcParse *p) {
+static void bc_parse_noElse(BcParse *p) {
uint16_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
*flag_ptr = (*flag_ptr & ~(BC_PARSE_FLAG_IF_END));
bc_parse_setLabel(p);
@@ -3983,10 +3970,8 @@ static BcStatus bc_parse_body(BcParse *p, int brace) {
if (p->l.t == BC_LEX_NLINE) s = bc_lex_next(&p->l);
}
else {
- size_t len = p->flags.len;
s = bc_parse_stmt(p);
- if (!s && !brace && !BC_PARSE_BODY(p) && len <= p->flags.len)
- s = bc_parse_endBody(p, 0);
+ if (!s && !brace && !BC_PARSE_BODY(p)) s = bc_parse_endBody(p, 0);
}
return s;
@@ -4805,9 +4790,8 @@ static void bc_program_printString(char *str)
if ((idx = stridx("ab\\efnqrt", c = str[i+1])) >= 0) {
if (c == 'n') TT.nchars = SIZE_MAX;
c = "\a\b\\\\\f\n\"\r\t"[idx];
+ i++;
}
- else putchar('\\');
- i++;
}
putchar(c);
@@ -5683,7 +5667,6 @@ static void bc_vm_clean()
static BcStatus bc_vm_process(char *text, int is_stdin) {
BcStatus s;
- uint16_t *flags;
s = bc_parse_text(&BC_VM->prs, text);
if (s) goto err;
@@ -5693,11 +5676,6 @@ static BcStatus bc_vm_process(char *text, int is_stdin) {
if (s) goto err;
}
- flags = BC_PARSE_TOP_FLAG_PTR(&BC_VM->prs);
-
- if (!is_stdin && BC_VM->prs.flags.len == 1 && *flags == BC_PARSE_FLAG_IF_END)
- bc_parse_noElse(&BC_VM->prs);
-
if (BC_PARSE_NO_EXEC(&BC_VM->prs)) goto err;
s = bc_program_exec(&BC_VM->prog);
@@ -5853,7 +5831,7 @@ void bc_main(void)
int i;
for (i = 0; !s && i < toys.optc; ++i) s = bc_vm_file(toys.optargs[i]);
- if (!s) s = bc_vm_stdin();
+ if (!s || s != BC_STATUS_QUIT) s = bc_vm_stdin();
}
if (CFG_TOYBOX_FREE) {