aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-08 19:34:35 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-08 19:34:35 +0100
commit6e7c65fca0cb176592000b249f612e037a1dc7fc (patch)
treefc787d64478f4478e1420f30a4999fd7bdf9cd19
parentd0bc5fdfea72ffac3102c76760f3e55a40a430ea (diff)
downloadbusybox-w32-6e7c65fca0cb176592000b249f612e037a1dc7fc.tar.gz
busybox-w32-6e7c65fca0cb176592000b249f612e037a1dc7fc.tar.bz2
busybox-w32-6e7c65fca0cb176592000b249f612e037a1dc7fc.zip
bc: trim banner, use empty interactive prompts (GNU bc compat)
function old new delta bc_vm_run 689 684 -5 bc_program_read 355 350 -5 bc_read_line 307 285 -22 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-32) Total: -32 bytes text data bss dec hex filename 985409 485 7296 993190 f27a6 busybox_old 985265 485 7296 993046 f2716 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e543b2b93..cd38bfa42 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2,9 +2,6 @@
2/* 2/*
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
4 * Copyright (c) 2018 Gavin D. Howard and contributors. 4 * Copyright (c) 2018 Gavin D. Howard and contributors.
5 *
6 * ** Automatically generated from https://github.com/gavinhoward/bc **
7 * ** Do not edit unless you know what you are doing. **
8 */ 5 */
9//config:config BC 6//config:config BC
10//config: bool "bc (45 kb; 49 kb when combined with dc)" 7//config: bool "bc (45 kb; 49 kb when combined with dc)"
@@ -97,7 +94,7 @@
97//config:config FEATURE_DC_SMALL 94//config:config FEATURE_DC_SMALL
98//config: bool "Minimal dc implementation (4.2 kb), not using bc code base" 95//config: bool "Minimal dc implementation (4.2 kb), not using bc code base"
99//config: depends on DC && !BC 96//config: depends on DC && !BC
100//config: default y 97//config: default n
101//config: 98//config:
102//config:config FEATURE_DC_LIBM 99//config:config FEATURE_DC_LIBM
103//config: bool "Enable power and exp functions (requires libm)" 100//config: bool "Enable power and exp functions (requires libm)"
@@ -155,11 +152,11 @@
155//usage: "obase = A\n" 152//usage: "obase = A\n"
156//usage: 153//usage:
157//usage:#define dc_trivial_usage 154//usage:#define dc_trivial_usage
158//usage: "[-eSCRIPT]... [-fFILE]... [FILE]..." 155//usage: IF_NOT_FEATURE_DC_SMALL("[-x] ")"[-eSCRIPT]... [-fFILE]... [FILE]..."
159//usage: 156//usage:
160//usage:#define dc_full_usage "\n" 157//usage:#define dc_full_usage "\n"
161//usage: "\nTiny RPN calculator. Operations:" 158//usage: "\nTiny RPN calculator. Operations:"
162//usage: "\n+, -, *, /, %, ~, ^, |," 159//usage: "\n+, -, *, /, %, ~, ^," IF_NOT_FEATURE_DC_SMALL(" |,")
163//usage: "\np - print top of the stack (without popping)" 160//usage: "\np - print top of the stack (without popping)"
164//usage: "\nf - print entire stack" 161//usage: "\nf - print entire stack"
165//usage: "\nk - pop the value and set the precision" 162//usage: "\nk - pop the value and set the precision"
@@ -1267,13 +1264,11 @@ static int push_input_byte(BcVec *vec, char c)
1267 return 0; 1264 return 0;
1268} 1265}
1269 1266
1270static BcStatus bc_read_line(BcVec *vec, const char *prompt) 1267static BcStatus bc_read_line(BcVec *vec)
1271{ 1268{
1272 BcStatus s; 1269 BcStatus s;
1273 bool bad_chars; 1270 bool bad_chars;
1274 1271
1275 if (G_posix) prompt = "";
1276
1277 s = BC_STATUS_SUCCESS; 1272 s = BC_STATUS_SUCCESS;
1278 do { 1273 do {
1279 int c; 1274 int c;
@@ -1296,7 +1291,7 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt)
1296 if (G_ttyin) { 1291 if (G_ttyin) {
1297 int n, i; 1292 int n, i;
1298# define line_buf bb_common_bufsiz1 1293# define line_buf bb_common_bufsiz1
1299 n = read_line_input(G.line_input_state, prompt, line_buf, COMMON_BUFSIZE); 1294 n = read_line_input(G.line_input_state, "", line_buf, COMMON_BUFSIZE);
1300 if (n <= 0) { // read errors or EOF, or ^D, or ^C 1295 if (n <= 0) { // read errors or EOF, or ^D, or ^C
1301 if (n == 0) // ^C 1296 if (n == 0) // ^C
1302 goto intr; 1297 goto intr;
@@ -1314,8 +1309,6 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt)
1314# endif 1309# endif
1315#endif 1310#endif
1316 { 1311 {
1317 if (G_ttyin)
1318 fputs(prompt, stderr);
1319 IF_FEATURE_BC_SIGNALS(errno = 0;) 1312 IF_FEATURE_BC_SIGNALS(errno = 0;)
1320 do { 1313 do {
1321 c = fgetc(stdin); 1314 c = fgetc(stdin);
@@ -5563,7 +5556,7 @@ static BcStatus bc_program_read(void)
5563 sv_file = G.prog.file; 5556 sv_file = G.prog.file;
5564 G.prog.file = NULL; 5557 G.prog.file = NULL;
5565 5558
5566 s = bc_read_line(&buf, "read> "); 5559 s = bc_read_line(&buf);
5567 if (s) goto io_err; 5560 if (s) goto io_err;
5568 5561
5569 common_parse_init(&parse, BC_PROG_READ); 5562 common_parse_init(&parse, BC_PROG_READ);
@@ -6976,8 +6969,6 @@ static void bc_vm_info(void)
6976{ 6969{
6977 printf("%s "BB_VER"\n" 6970 printf("%s "BB_VER"\n"
6978 "Copyright (c) 2018 Gavin D. Howard and contributors\n" 6971 "Copyright (c) 2018 Gavin D. Howard and contributors\n"
6979 "Report bugs at: https://github.com/gavinhoward/bc\n"
6980 "This is free software with ABSOLUTELY NO WARRANTY\n"
6981 , applet_name); 6972 , applet_name);
6982} 6973}
6983 6974
@@ -7002,7 +6993,6 @@ static void bc_args(char **argv)
7002 if (getenv("POSIXLY_CORRECT")) 6993 if (getenv("POSIXLY_CORRECT"))
7003 option_mask32 |= BC_FLAG_S; 6994 option_mask32 |= BC_FLAG_S;
7004 6995
7005///should be in bc_vm_run() instead??
7006 if (opts & BC_FLAG_V) { 6996 if (opts & BC_FLAG_V) {
7007 bc_vm_info(); 6997 bc_vm_info();
7008 exit(0); 6998 exit(0);
@@ -7130,7 +7120,7 @@ static BcStatus bc_vm_stdin(void)
7130 // with a backslash to the parser. The reason for that is because the parser 7120 // with a backslash to the parser. The reason for that is because the parser
7131 // treats a backslash+newline combo as whitespace, per the bc spec. In that 7121 // treats a backslash+newline combo as whitespace, per the bc spec. In that
7132 // case, and for strings and comments, the parser will expect more stuff. 7122 // case, and for strings and comments, the parser will expect more stuff.
7133 while ((s = bc_read_line(&buf, ">>> ")) == BC_STATUS_SUCCESS) { 7123 while ((s = bc_read_line(&buf)) == BC_STATUS_SUCCESS) {
7134 7124
7135 char *string = buf.v; 7125 char *string = buf.v;
7136 7126
@@ -7602,8 +7592,18 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
7602 INIT_G(); 7592 INIT_G();
7603 G.sbgn = '['; 7593 G.sbgn = '[';
7604 G.send = ']'; 7594 G.send = ']';
7605 // TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use default width 7595 /*
7606 // 1 char narrower than bc from the same package. Do the same? 7596 * TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use width
7597 * 1 char wider than bc from the same package.
7598 * Both default width, and xC_LINE_LENGTH=N are wider:
7599 * "DC_LINE_LENGTH=5 dc -e'123456 p'" prints:
7600 * 1234\
7601 * 56
7602 * "echo '123456' | BC_LINE_LENGTH=5 bc" prints:
7603 * 123\
7604 * 456
7605 * Do the same, or it's a bug?
7606 */
7607 bc_vm_init("DC_LINE_LENGTH"); 7607 bc_vm_init("DC_LINE_LENGTH");
7608 7608
7609 // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs 7609 // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs