aboutsummaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-31 18:48:10 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-31 18:48:59 +0100
commit2747f6195b94db6c1adf2eae243df5c0a01d39f2 (patch)
tree8417a84f9ecba6d54de8acfec74afcfa0bfd094c /miscutils/bc.c
parentaad76968cd5934ee17f36cd8e817e86ae952b533 (diff)
downloadbusybox-2747f6195b94db6c1adf2eae243df5c0a01d39f2.tar.gz
bc: fold xc_lex_more_input() into peek_inbuf()
function old new delta peek_inbuf 69 56 -13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r--miscutils/bc.c31
1 files changed, 9 insertions, 22 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index de6f9aab8..72c23542c 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2727,20 +2727,6 @@ static BC_STATUS zxc_num_parse(BcNum *n, const char *val, unsigned base_t)
}
#define zxc_num_parse(...) (zxc_num_parse(__VA_ARGS__) COMMA_SUCCESS)
-static bool xc_lex_more_input(void)
-{
- BcParse *p = &G.prs;
-
- bc_vec_pop_all(&G.input_buffer);
-
- xc_read_line(&G.input_buffer, G.prs.lex_input_fp);
-
- p->lex_inbuf = G.input_buffer.v;
-// bb_error_msg("G.input_buffer.len:%d '%s'", G.input_buffer.len, G.input_buffer.v);
-
- return G.input_buffer.len > 1;
-}
-
// p->lex_inbuf points to the current string to be parsed.
// if p->lex_inbuf points to '\0', it's either EOF or it points after
// last processed line's terminating '\n' (and more reading needs to be done
@@ -2774,10 +2760,13 @@ static bool xc_lex_more_input(void)
// end" - ...prints "str#\<newline>end"
static char peek_inbuf(void)
{
- if (*G.prs.lex_inbuf == '\0') {
- if (G.prs.lex_input_fp)
- if (!xc_lex_more_input())
- G.prs.lex_input_fp = NULL;
+ if (*G.prs.lex_inbuf == '\0'
+ && G.prs.lex_input_fp
+ ) {
+ xc_read_line(&G.input_buffer, G.prs.lex_input_fp);
+ G.prs.lex_inbuf = G.input_buffer.v;
+ if (G.input_buffer.len <= 1) // on EOF, len is 1 (NUL byte)
+ G.prs.lex_input_fp = NULL;
}
return *G.prs.lex_inbuf;
}
@@ -2796,7 +2785,7 @@ static void xc_lex_lineComment(void)
// Try: echo -n '#foo' | bc
p->lex = XC_LEX_WHITESPACE;
- // We depend here on input being done in whole lines:
+ // Not peek_inbuf(): we depend on input being done in whole lines:
// '\0' which isn't the EOF can only be seen after '\n'.
while ((c = *p->lex_inbuf) != '\n' && c != '\0')
p->lex_inbuf++;
@@ -5281,17 +5270,15 @@ static BC_STATUS zxc_program_read(void)
IF_DC(s = zdc_parse_exprs_until_eof());
}
if (s) goto exec_err;
-
if (G.prs.lex != XC_LEX_NLINE && G.prs.lex != XC_LEX_EOF) {
s = bc_error("bad read() expression");
goto exec_err;
}
+ xc_parse_push(XC_INST_RET);
ip.func = BC_PROG_READ;
ip.inst_idx = 0;
IF_BC(ip.results_len_before_call = G.prog.results.len;)
-
- xc_parse_push(XC_INST_RET);
bc_vec_push(&G.prog.exestack, &ip);
exec_err: