aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-12-29 18:50:56 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-12-29 18:52:19 +0100
commit29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7 (patch)
tree6a77b0d0c204d1180bdd92087911cfe5ef1b59f0 /miscutils
parentcba45d9b6586ff57c021911885930e6a415aa2c4 (diff)
downloadbusybox-w32-29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7.tar.gz
busybox-w32-29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7.tar.bz2
busybox-w32-29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7.zip
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.c38
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 {
231#define BC_NUM_MAX_IBASE 36 231#define BC_NUM_MAX_IBASE 36
232// larger value might speed up BIGNUM calculations a bit: 232// larger value might speed up BIGNUM calculations a bit:
233#define BC_NUM_DEF_SIZE 16 233#define BC_NUM_DEF_SIZE 16
234#define BC_NUM_PRINT_WIDTH 69 234#define BC_NUM_PRINT_WIDTH 70
235 235
236#define BC_NUM_KARATSUBA_LEN 32 236#define BC_NUM_KARATSUBA_LEN 32
237 237
@@ -7372,11 +7372,29 @@ static unsigned xc_vm_envLen(const char *var)
7372 7372
7373 lenv = getenv(var); 7373 lenv = getenv(var);
7374 len = BC_NUM_PRINT_WIDTH; 7374 len = BC_NUM_PRINT_WIDTH;
7375 if (!lenv) return len; 7375 if (lenv) {
7376 len = bb_strtou(lenv, NULL, 10);
7377 if (len == 0 || len > INT_MAX)
7378 len = INT_MAX;
7379 if (errno)
7380 len = BC_NUM_PRINT_WIDTH;
7381 }
7376 7382
7377 len = bb_strtou(lenv, NULL, 10) - 1; 7383 // dc (GNU bc 1.07.1) 1.4.1 seems to use width
7378 if (errno || len < 2 || len >= INT_MAX) 7384 // 1 char wider than bc from the same package.
7379 len = BC_NUM_PRINT_WIDTH; 7385 // Both default width, and xC_LINE_LENGTH=N are wider:
7386 // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints:
7387 // |1234\ |
7388 // |56 |
7389 // "echo '123456' | BC_LINE_LENGTH=5 bc" prints:
7390 // |123\ |
7391 // |456 |
7392 // Do the same, but it might be a bug in GNU package
7393 if (IS_BC)
7394 len--;
7395
7396 if (len < 2)
7397 len = IS_BC ? BC_NUM_PRINT_WIDTH - 1 : BC_NUM_PRINT_WIDTH;
7380 7398
7381 return len; 7399 return len;
7382} 7400}
@@ -7467,16 +7485,6 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
7467 7485
7468 INIT_G(); 7486 INIT_G();
7469 7487
7470 // TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use width
7471 // 1 char wider than bc from the same package.
7472 // Both default width, and xC_LINE_LENGTH=N are wider:
7473 // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints:
7474 // |1234\ |
7475 // |56 |
7476 // "echo '123456' | BC_LINE_LENGTH=5 bc" prints:
7477 // |123\ |
7478 // |456 |
7479 // Do the same, or it's a bug?
7480 xc_vm_init("DC_LINE_LENGTH"); 7488 xc_vm_init("DC_LINE_LENGTH");
7481 7489
7482 // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs 7490 // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs