aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-10 12:33:40 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-10 12:33:40 +0100
commit44d79d866dc4c9bb0c3bba47612feae78365a046 (patch)
treefff8e644c1274455187b2ee8c99969db26525baf
parentb696d9ec2044a1fd7906c1b2a2a747aff7c3f79f (diff)
downloadbusybox-w32-44d79d866dc4c9bb0c3bba47612feae78365a046.tar.gz
busybox-w32-44d79d866dc4c9bb0c3bba47612feae78365a046.tar.bz2
busybox-w32-44d79d866dc4c9bb0c3bba47612feae78365a046.zip
bc: simplify bc_program_print()
function old new delta bc_program_print 730 713 -17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 33abe9366..1879581e3 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -5737,15 +5737,14 @@ static BcStatus bc_program_print(char inst, size_t idx)
5737{ 5737{
5738 BcStatus s = BC_STATUS_SUCCESS; 5738 BcStatus s = BC_STATUS_SUCCESS;
5739 BcResult *r; 5739 BcResult *r;
5740 size_t len, i; 5740 BcNum *num;
5741 char *str;
5742 BcNum *num = NULL;
5743 bool pop = inst != BC_INST_PRINT; 5741 bool pop = inst != BC_INST_PRINT;
5744 5742
5745 if (!BC_PROG_STACK(&G.prog.results, idx + 1)) 5743 if (!BC_PROG_STACK(&G.prog.results, idx + 1))
5746 return bc_error_stack_has_too_few_elements(); 5744 return bc_error_stack_has_too_few_elements();
5747 5745
5748 r = bc_vec_item_rev(&G.prog.results, idx); 5746 r = bc_vec_item_rev(&G.prog.results, idx);
5747 num = NULL; // is this NULL necessary?
5749 s = bc_program_num(r, &num, false); 5748 s = bc_program_num(r, &num, false);
5750 if (s) return s; 5749 if (s) return s;
5751 5750
@@ -5754,16 +5753,18 @@ static BcStatus bc_program_print(char inst, size_t idx)
5754 if (!s) bc_num_copy(&G.prog.last, num); 5753 if (!s) bc_num_copy(&G.prog.last, num);
5755 } 5754 }
5756 else { 5755 else {
5756 char *str;
5757 5757
5758 idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx; 5758 idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx;
5759 str = *bc_program_str(idx); 5759 str = *bc_program_str(idx);
5760 5760
5761 if (inst == BC_INST_PRINT_STR) { 5761 if (inst == BC_INST_PRINT_STR) {
5762 for (i = 0, len = strlen(str); i < len; ++i) { 5762 for (;;) {
5763 char c = str[i]; 5763 char c = *str++;
5764 if (c == '\0') break;
5764 bb_putchar(c); 5765 bb_putchar(c);
5765 if (c == '\n') G.prog.nchars = SIZE_MAX;
5766 ++G.prog.nchars; 5766 ++G.prog.nchars;
5767 if (c == '\n') G.prog.nchars = 0;
5767 } 5768 }
5768 } 5769 }
5769 else { 5770 else {