aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-06 11:31:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-06 11:31:14 +0100
commit9ca9ef2d5b4eea4ee79784b226c556ab8b0818de (patch)
treeae1bf5858ed9fc51ed1be42728ba515e9cafe19a /miscutils
parenta68a87cd60c2cb0c0e9170317901d8f70923926a (diff)
downloadbusybox-9ca9ef2d5b4eea4ee79784b226c556ab8b0818de.tar.gz
dc: re-enable "tiny dc" implementation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c43
-rw-r--r--miscutils/dc.c51
2 files changed, 36 insertions, 58 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 71945ff4a..26044afbc 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -94,17 +94,30 @@
//config: Also note that, like the FreeBSD dc, extended registers are not
//config: allowed unless the "-x" option is given.
//config:
+//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:
+//config:config FEATURE_DC_LIBM
+//config: bool "Enable power and exp functions (requires libm)"
+//config: default y
+//config: depends on FEATURE_DC_SMALL
+//config: help
+//config: Enable power and exp functions.
+//config: NOTE: This will require libm to be present for linking.
+//config:
//config:config FEATURE_BC_SIGNALS
//config: bool "Enable bc/dc signal handling"
//config: default y
-//config: depends on BC || DC
+//config: depends on (BC || DC) && !FEATURE_DC_SMALL
//config: help
//config: Enable signal handling for bc and dc.
//config:
//config:config FEATURE_BC_LONG_OPTIONS
//config: bool "Enable bc/dc long options"
//config: default y
-//config: depends on BC || DC
+//config: depends on (BC || DC) && !FEATURE_DC_SMALL
//config: help
//config: Enable long options for bc and dc.
@@ -143,16 +156,16 @@
//usage:#define dc_trivial_usage
//usage: "EXPRESSION..."
//usage:
-//usage:#define dc_full_usage "\n\n"
-//usage: "Tiny RPN calculator. Operations:\n"
-//usage: "+, add, -, sub, *, mul, /, div, %, mod, ^, exp, ~, divmod, |, "
-//usage: "modular exponentiation,\n"
-//usage: "p - print top of the stack (without popping),\n"
-//usage: "f - print entire stack,\n"
-//usage: "k - pop the value and set the precision.\n"
-//usage: "i - pop the value and set input radix.\n"
-//usage: "o - pop the value and set output radix.\n"
-//usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16"
+//usage:#define dc_full_usage "\n"
+//usage: "\nTiny RPN calculator. Operations:"
+//usage: "\n+, add, -, sub, *, mul, /, div, %, mod, ^, exp, ~, divmod, |, "
+//usage: "modular exponentiation,"
+//usage: "\np - print top of the stack (without popping),"
+//usage: "\nf - print entire stack,"
+//usage: "\nk - pop the value and set the precision."
+//usage: "\ni - pop the value and set input radix."
+//usage: "\no - pop the value and set output radix."
+//usage: "\nExamples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16"
//usage:
//usage:#define dc_example_usage
//usage: "$ dc 2 2 + p\n"
@@ -169,6 +182,10 @@
#include "libbb.h"
#include "common_bufsiz.h"
+#if ENABLE_FEATURE_DC_SMALL
+# include "dc.c"
+#else
+
typedef enum BcStatus {
BC_STATUS_SUCCESS = 0,
BC_STATUS_FAILURE = 1,
@@ -7490,3 +7507,5 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
return bc_vm_run(argv, "DC_LINE_LENGTH");
}
#endif
+
+#endif // not DC_SMALL
diff --git a/miscutils/dc.c b/miscutils/dc.c
index d58f97e91..22890147d 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -1,52 +1,12 @@
-#if 0 //TODO: use if bc is not selected
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
- //config:config DC
- //config: bool "dc (4.2 kb)"
- //config: default y
- //config: help
- //config: Dc is a reverse-polish desk calculator which supports unlimited
- //config: precision arithmetic.
- //config:
- //config:config FEATURE_DC_LIBM
- //config: bool "Enable power and exp functions (requires libm)"
- //config: default y
- //config: depends on DC
- //config: help
- //config: Enable power and exp functions.
- //config: NOTE: This will require libm to be present for linking.
-
- //applet:IF_DC(APPLET(dc, BB_DIR_USR_BIN, BB_SUID_DROP))
-
- //kbuild:lib-$(CONFIG_DC) += dc.o
-
- //usage:#define dc_trivial_usage
- //usage: "EXPRESSION..."
- //usage:
- //usage:#define dc_full_usage "\n\n"
- //usage: "Tiny RPN calculator. Operations:\n"
- //usage: "+, add, -, sub, *, mul, /, div, %, mod, "IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, xor,\n"
- //usage: "p - print top of the stack (without popping),\n"
- //usage: "f - print entire stack,\n"
- //usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n"
- //usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16"
- //usage:
- //usage:#define dc_example_usage
- //usage: "$ dc 2 2 + p\n"
- //usage: "4\n"
- //usage: "$ dc 8 8 \\* 2 2 + / p\n"
- //usage: "16\n"
- //usage: "$ dc 0 1 and p\n"
- //usage: "0\n"
- //usage: "$ dc 0 1 or p\n"
- //usage: "1\n"
- //usage: "$ echo 72 9 div 8 mul p | dc\n"
- //usage: "64\n"
-
-#include "libbb.h"
-#include "common_bufsiz.h"
+
+/* config/applet/usage bits are in bc.c */
+
+//#include "libbb.h"
+//#include "common_bufsiz.h"
#include <math.h>
#if 0
@@ -303,4 +263,3 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
}
return EXIT_SUCCESS;
}
-#endif