diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-29 18:50:56 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-29 18:52:19 +0100 |
commit | 29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7 (patch) | |
tree | 6a77b0d0c204d1180bdd92087911cfe5ef1b59f0 /miscutils | |
parent | cba45d9b6586ff57c021911885930e6a415aa2c4 (diff) | |
download | busybox-29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7.tar.gz |
bc,dc: make BC_LINE_LENGTH/DC_LINE_LENGTH more compatible with GNU
function old new delta
xc_vm_init 640 682 +42
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/bc.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 59e18a8c1..6d54f968a 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -231,7 +231,7 @@ typedef struct BcNum { #define BC_NUM_MAX_IBASE 36 // larger value might speed up BIGNUM calculations a bit: #define BC_NUM_DEF_SIZE 16 -#define BC_NUM_PRINT_WIDTH 69 +#define BC_NUM_PRINT_WIDTH 70 #define BC_NUM_KARATSUBA_LEN 32 @@ -7372,11 +7372,29 @@ static unsigned xc_vm_envLen(const char *var) lenv = getenv(var); len = BC_NUM_PRINT_WIDTH; - if (!lenv) return len; + if (lenv) { + len = bb_strtou(lenv, NULL, 10); + if (len == 0 || len > INT_MAX) + len = INT_MAX; + if (errno) + len = BC_NUM_PRINT_WIDTH; + } - len = bb_strtou(lenv, NULL, 10) - 1; - if (errno || len < 2 || len >= INT_MAX) - len = BC_NUM_PRINT_WIDTH; + // dc (GNU bc 1.07.1) 1.4.1 seems to use width + // 1 char wider than bc from the same package. + // Both default width, and xC_LINE_LENGTH=N are wider: + // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints: + // |1234\ | + // |56 | + // "echo '123456' | BC_LINE_LENGTH=5 bc" prints: + // |123\ | + // |456 | + // Do the same, but it might be a bug in GNU package + if (IS_BC) + len--; + + if (len < 2) + len = IS_BC ? BC_NUM_PRINT_WIDTH - 1 : BC_NUM_PRINT_WIDTH; return len; } @@ -7467,16 +7485,6 @@ int dc_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - // TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use width - // 1 char wider than bc from the same package. - // Both default width, and xC_LINE_LENGTH=N are wider: - // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints: - // |1234\ | - // |56 | - // "echo '123456' | BC_LINE_LENGTH=5 bc" prints: - // |123\ | - // |456 | - // Do the same, or it's a bug? xc_vm_init("DC_LINE_LENGTH"); // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs |