diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-31 18:48:10 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-31 18:48:59 +0100 |
commit | 2747f6195b94db6c1adf2eae243df5c0a01d39f2 (patch) | |
tree | 8417a84f9ecba6d54de8acfec74afcfa0bfd094c | |
parent | aad76968cd5934ee17f36cd8e817e86ae952b533 (diff) | |
download | busybox-w32-2747f6195b94db6c1adf2eae243df5c0a01d39f2.tar.gz busybox-w32-2747f6195b94db6c1adf2eae243df5c0a01d39f2.tar.bz2 busybox-w32-2747f6195b94db6c1adf2eae243df5c0a01d39f2.zip |
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>
-rw-r--r-- | miscutils/bc.c | 31 |
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) | |||
2727 | } | 2727 | } |
2728 | #define zxc_num_parse(...) (zxc_num_parse(__VA_ARGS__) COMMA_SUCCESS) | 2728 | #define zxc_num_parse(...) (zxc_num_parse(__VA_ARGS__) COMMA_SUCCESS) |
2729 | 2729 | ||
2730 | static bool xc_lex_more_input(void) | ||
2731 | { | ||
2732 | BcParse *p = &G.prs; | ||
2733 | |||
2734 | bc_vec_pop_all(&G.input_buffer); | ||
2735 | |||
2736 | xc_read_line(&G.input_buffer, G.prs.lex_input_fp); | ||
2737 | |||
2738 | p->lex_inbuf = G.input_buffer.v; | ||
2739 | // bb_error_msg("G.input_buffer.len:%d '%s'", G.input_buffer.len, G.input_buffer.v); | ||
2740 | |||
2741 | return G.input_buffer.len > 1; | ||
2742 | } | ||
2743 | |||
2744 | // p->lex_inbuf points to the current string to be parsed. | 2730 | // p->lex_inbuf points to the current string to be parsed. |
2745 | // if p->lex_inbuf points to '\0', it's either EOF or it points after | 2731 | // if p->lex_inbuf points to '\0', it's either EOF or it points after |
2746 | // last processed line's terminating '\n' (and more reading needs to be done | 2732 | // last processed line's terminating '\n' (and more reading needs to be done |
@@ -2774,10 +2760,13 @@ static bool xc_lex_more_input(void) | |||
2774 | // end" - ...prints "str#\<newline>end" | 2760 | // end" - ...prints "str#\<newline>end" |
2775 | static char peek_inbuf(void) | 2761 | static char peek_inbuf(void) |
2776 | { | 2762 | { |
2777 | if (*G.prs.lex_inbuf == '\0') { | 2763 | if (*G.prs.lex_inbuf == '\0' |
2778 | if (G.prs.lex_input_fp) | 2764 | && G.prs.lex_input_fp |
2779 | if (!xc_lex_more_input()) | 2765 | ) { |
2780 | G.prs.lex_input_fp = NULL; | 2766 | xc_read_line(&G.input_buffer, G.prs.lex_input_fp); |
2767 | G.prs.lex_inbuf = G.input_buffer.v; | ||
2768 | if (G.input_buffer.len <= 1) // on EOF, len is 1 (NUL byte) | ||
2769 | G.prs.lex_input_fp = NULL; | ||
2781 | } | 2770 | } |
2782 | return *G.prs.lex_inbuf; | 2771 | return *G.prs.lex_inbuf; |
2783 | } | 2772 | } |
@@ -2796,7 +2785,7 @@ static void xc_lex_lineComment(void) | |||
2796 | // Try: echo -n '#foo' | bc | 2785 | // Try: echo -n '#foo' | bc |
2797 | p->lex = XC_LEX_WHITESPACE; | 2786 | p->lex = XC_LEX_WHITESPACE; |
2798 | 2787 | ||
2799 | // We depend here on input being done in whole lines: | 2788 | // Not peek_inbuf(): we depend on input being done in whole lines: |
2800 | // '\0' which isn't the EOF can only be seen after '\n'. | 2789 | // '\0' which isn't the EOF can only be seen after '\n'. |
2801 | while ((c = *p->lex_inbuf) != '\n' && c != '\0') | 2790 | while ((c = *p->lex_inbuf) != '\n' && c != '\0') |
2802 | p->lex_inbuf++; | 2791 | p->lex_inbuf++; |
@@ -5281,17 +5270,15 @@ static BC_STATUS zxc_program_read(void) | |||
5281 | IF_DC(s = zdc_parse_exprs_until_eof()); | 5270 | IF_DC(s = zdc_parse_exprs_until_eof()); |
5282 | } | 5271 | } |
5283 | if (s) goto exec_err; | 5272 | if (s) goto exec_err; |
5284 | |||
5285 | if (G.prs.lex != XC_LEX_NLINE && G.prs.lex != XC_LEX_EOF) { | 5273 | if (G.prs.lex != XC_LEX_NLINE && G.prs.lex != XC_LEX_EOF) { |
5286 | s = bc_error("bad read() expression"); | 5274 | s = bc_error("bad read() expression"); |
5287 | goto exec_err; | 5275 | goto exec_err; |
5288 | } | 5276 | } |
5277 | xc_parse_push(XC_INST_RET); | ||
5289 | 5278 | ||
5290 | ip.func = BC_PROG_READ; | 5279 | ip.func = BC_PROG_READ; |
5291 | ip.inst_idx = 0; | 5280 | ip.inst_idx = 0; |
5292 | IF_BC(ip.results_len_before_call = G.prog.results.len;) | 5281 | IF_BC(ip.results_len_before_call = G.prog.results.len;) |
5293 | |||
5294 | xc_parse_push(XC_INST_RET); | ||
5295 | bc_vec_push(&G.prog.exestack, &ip); | 5282 | bc_vec_push(&G.prog.exestack, &ip); |
5296 | 5283 | ||
5297 | exec_err: | 5284 | exec_err: |