bc: simplify bc_program_print()
function old new delta bc_program_print 730 713 -17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
b696d9ec20
commit
44d79d866d
@ -5737,15 +5737,14 @@ static BcStatus bc_program_print(char inst, size_t idx)
|
|||||||
{
|
{
|
||||||
BcStatus s = BC_STATUS_SUCCESS;
|
BcStatus s = BC_STATUS_SUCCESS;
|
||||||
BcResult *r;
|
BcResult *r;
|
||||||
size_t len, i;
|
BcNum *num;
|
||||||
char *str;
|
|
||||||
BcNum *num = NULL;
|
|
||||||
bool pop = inst != BC_INST_PRINT;
|
bool pop = inst != BC_INST_PRINT;
|
||||||
|
|
||||||
if (!BC_PROG_STACK(&G.prog.results, idx + 1))
|
if (!BC_PROG_STACK(&G.prog.results, idx + 1))
|
||||||
return bc_error_stack_has_too_few_elements();
|
return bc_error_stack_has_too_few_elements();
|
||||||
|
|
||||||
r = bc_vec_item_rev(&G.prog.results, idx);
|
r = bc_vec_item_rev(&G.prog.results, idx);
|
||||||
|
num = NULL; // is this NULL necessary?
|
||||||
s = bc_program_num(r, &num, false);
|
s = bc_program_num(r, &num, false);
|
||||||
if (s) return s;
|
if (s) return s;
|
||||||
|
|
||||||
@ -5754,16 +5753,18 @@ static BcStatus bc_program_print(char inst, size_t idx)
|
|||||||
if (!s) bc_num_copy(&G.prog.last, num);
|
if (!s) bc_num_copy(&G.prog.last, num);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
char *str;
|
||||||
|
|
||||||
idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx;
|
idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx;
|
||||||
str = *bc_program_str(idx);
|
str = *bc_program_str(idx);
|
||||||
|
|
||||||
if (inst == BC_INST_PRINT_STR) {
|
if (inst == BC_INST_PRINT_STR) {
|
||||||
for (i = 0, len = strlen(str); i < len; ++i) {
|
for (;;) {
|
||||||
char c = str[i];
|
char c = *str++;
|
||||||
|
if (c == '\0') break;
|
||||||
bb_putchar(c);
|
bb_putchar(c);
|
||||||
if (c == '\n') G.prog.nchars = SIZE_MAX;
|
|
||||||
++G.prog.nchars;
|
++G.prog.nchars;
|
||||||
|
if (c == '\n') G.prog.nchars = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user