summaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
authorDenys Vlasenko2018-12-08 19:34:35 +0100
committerDenys Vlasenko2018-12-08 19:34:35 +0100
commit6e7c65fca0cb176592000b249f612e037a1dc7fc (patch)
treefc787d64478f4478e1420f30a4999fd7bdf9cd19 /miscutils/bc.c
parentd0bc5fdfea72ffac3102c76760f3e55a40a430ea (diff)
downloadbusybox-6e7c65fca0cb176592000b249f612e037a1dc7fc.zip
busybox-6e7c65fca0cb176592000b249f612e037a1dc7fc.tar.gz
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>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r--miscutils/bc.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e543b2b..cd38bfa 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2,9 +2,6 @@
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
* Copyright (c) 2018 Gavin D. Howard and contributors.
- *
- * ** Automatically generated from https://github.com/gavinhoward/bc **
- * ** Do not edit unless you know what you are doing. **
*/
//config:config BC
//config: bool "bc (45 kb; 49 kb when combined with dc)"
@@ -97,7 +94,7 @@
//config:config FEATURE_DC_SMALL
//config: bool "Minimal dc implementation (4.2 kb), not using bc code base"
//config: depends on DC && !BC
-//config: default y
+//config: default n
//config:
//config:config FEATURE_DC_LIBM
//config: bool "Enable power and exp functions (requires libm)"
@@ -155,11 +152,11 @@
//usage: "obase = A\n"
//usage:
//usage:#define dc_trivial_usage
-//usage: "[-eSCRIPT]... [-fFILE]... [FILE]..."
+//usage: IF_NOT_FEATURE_DC_SMALL("[-x] ")"[-eSCRIPT]... [-fFILE]... [FILE]..."
//usage:
//usage:#define dc_full_usage "\n"
//usage: "\nTiny RPN calculator. Operations:"
-//usage: "\n+, -, *, /, %, ~, ^, |,"
+//usage: "\n+, -, *, /, %, ~, ^," IF_NOT_FEATURE_DC_SMALL(" |,")
//usage: "\np - print top of the stack (without popping)"
//usage: "\nf - print entire stack"
//usage: "\nk - pop the value and set the precision"
@@ -1267,13 +1264,11 @@ static int push_input_byte(BcVec *vec, char c)
return 0;
}
-static BcStatus bc_read_line(BcVec *vec, const char *prompt)
+static BcStatus bc_read_line(BcVec *vec)
{
BcStatus s;
bool bad_chars;
- if (G_posix) prompt = "";
-
s = BC_STATUS_SUCCESS;
do {
int c;
@@ -1296,7 +1291,7 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt)
if (G_ttyin) {
int n, i;
# define line_buf bb_common_bufsiz1
- n = read_line_input(G.line_input_state, prompt, line_buf, COMMON_BUFSIZE);
+ n = read_line_input(G.line_input_state, "", line_buf, COMMON_BUFSIZE);
if (n <= 0) { // read errors or EOF, or ^D, or ^C
if (n == 0) // ^C
goto intr;
@@ -1314,8 +1309,6 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt)
# endif
#endif
{
- if (G_ttyin)
- fputs(prompt, stderr);
IF_FEATURE_BC_SIGNALS(errno = 0;)
do {
c = fgetc(stdin);
@@ -5563,7 +5556,7 @@ static BcStatus bc_program_read(void)
sv_file = G.prog.file;
G.prog.file = NULL;
- s = bc_read_line(&buf, "read> ");
+ s = bc_read_line(&buf);
if (s) goto io_err;
common_parse_init(&parse, BC_PROG_READ);
@@ -6976,8 +6969,6 @@ static void bc_vm_info(void)
{
printf("%s "BB_VER"\n"
"Copyright (c) 2018 Gavin D. Howard and contributors\n"
- "Report bugs at: https://github.com/gavinhoward/bc\n"
- "This is free software with ABSOLUTELY NO WARRANTY\n"
, applet_name);
}
@@ -7002,7 +6993,6 @@ static void bc_args(char **argv)
if (getenv("POSIXLY_CORRECT"))
option_mask32 |= BC_FLAG_S;
-///should be in bc_vm_run() instead??
if (opts & BC_FLAG_V) {
bc_vm_info();
exit(0);
@@ -7130,7 +7120,7 @@ static BcStatus bc_vm_stdin(void)
// with a backslash to the parser. The reason for that is because the parser
// treats a backslash+newline combo as whitespace, per the bc spec. In that
// case, and for strings and comments, the parser will expect more stuff.
- while ((s = bc_read_line(&buf, ">>> ")) == BC_STATUS_SUCCESS) {
+ while ((s = bc_read_line(&buf)) == BC_STATUS_SUCCESS) {
char *string = buf.v;
@@ -7602,8 +7592,18 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
INIT_G();
G.sbgn = '[';
G.send = ']';
- // TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use default width
- // 1 char narrower than bc from the same package. Do the same?
+ /*
+ * 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?
+ */
bc_vm_init("DC_LINE_LENGTH");
// Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs