diff options
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/bc.c | 43 | ||||
| -rw-r--r-- | miscutils/dc.c | 51 |
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 @@ | |||
| 94 | //config: Also note that, like the FreeBSD dc, extended registers are not | 94 | //config: Also note that, like the FreeBSD dc, extended registers are not |
| 95 | //config: allowed unless the "-x" option is given. | 95 | //config: allowed unless the "-x" option is given. |
| 96 | //config: | 96 | //config: |
| 97 | //config:config FEATURE_DC_SMALL | ||
| 98 | //config: bool "Minimal dc implementation (4.2 kb), not using bc code base" | ||
| 99 | //config: depends on DC && !BC | ||
| 100 | //config: default y | ||
| 101 | //config: | ||
| 102 | //config:config FEATURE_DC_LIBM | ||
| 103 | //config: bool "Enable power and exp functions (requires libm)" | ||
| 104 | //config: default y | ||
| 105 | //config: depends on FEATURE_DC_SMALL | ||
| 106 | //config: help | ||
| 107 | //config: Enable power and exp functions. | ||
| 108 | //config: NOTE: This will require libm to be present for linking. | ||
| 109 | //config: | ||
| 97 | //config:config FEATURE_BC_SIGNALS | 110 | //config:config FEATURE_BC_SIGNALS |
| 98 | //config: bool "Enable bc/dc signal handling" | 111 | //config: bool "Enable bc/dc signal handling" |
| 99 | //config: default y | 112 | //config: default y |
| 100 | //config: depends on BC || DC | 113 | //config: depends on (BC || DC) && !FEATURE_DC_SMALL |
| 101 | //config: help | 114 | //config: help |
| 102 | //config: Enable signal handling for bc and dc. | 115 | //config: Enable signal handling for bc and dc. |
| 103 | //config: | 116 | //config: |
| 104 | //config:config FEATURE_BC_LONG_OPTIONS | 117 | //config:config FEATURE_BC_LONG_OPTIONS |
| 105 | //config: bool "Enable bc/dc long options" | 118 | //config: bool "Enable bc/dc long options" |
| 106 | //config: default y | 119 | //config: default y |
| 107 | //config: depends on BC || DC | 120 | //config: depends on (BC || DC) && !FEATURE_DC_SMALL |
| 108 | //config: help | 121 | //config: help |
| 109 | //config: Enable long options for bc and dc. | 122 | //config: Enable long options for bc and dc. |
| 110 | 123 | ||
| @@ -143,16 +156,16 @@ | |||
| 143 | //usage:#define dc_trivial_usage | 156 | //usage:#define dc_trivial_usage |
| 144 | //usage: "EXPRESSION..." | 157 | //usage: "EXPRESSION..." |
| 145 | //usage: | 158 | //usage: |
| 146 | //usage:#define dc_full_usage "\n\n" | 159 | //usage:#define dc_full_usage "\n" |
| 147 | //usage: "Tiny RPN calculator. Operations:\n" | 160 | //usage: "\nTiny RPN calculator. Operations:" |
| 148 | //usage: "+, add, -, sub, *, mul, /, div, %, mod, ^, exp, ~, divmod, |, " | 161 | //usage: "\n+, add, -, sub, *, mul, /, div, %, mod, ^, exp, ~, divmod, |, " |
| 149 | //usage: "modular exponentiation,\n" | 162 | //usage: "modular exponentiation," |
| 150 | //usage: "p - print top of the stack (without popping),\n" | 163 | //usage: "\np - print top of the stack (without popping)," |
| 151 | //usage: "f - print entire stack,\n" | 164 | //usage: "\nf - print entire stack," |
| 152 | //usage: "k - pop the value and set the precision.\n" | 165 | //usage: "\nk - pop the value and set the precision." |
| 153 | //usage: "i - pop the value and set input radix.\n" | 166 | //usage: "\ni - pop the value and set input radix." |
| 154 | //usage: "o - pop the value and set output radix.\n" | 167 | //usage: "\no - pop the value and set output radix." |
| 155 | //usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16" | 168 | //usage: "\nExamples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16" |
| 156 | //usage: | 169 | //usage: |
| 157 | //usage:#define dc_example_usage | 170 | //usage:#define dc_example_usage |
| 158 | //usage: "$ dc 2 2 + p\n" | 171 | //usage: "$ dc 2 2 + p\n" |
| @@ -169,6 +182,10 @@ | |||
| 169 | #include "libbb.h" | 182 | #include "libbb.h" |
| 170 | #include "common_bufsiz.h" | 183 | #include "common_bufsiz.h" |
| 171 | 184 | ||
| 185 | #if ENABLE_FEATURE_DC_SMALL | ||
| 186 | # include "dc.c" | ||
| 187 | #else | ||
| 188 | |||
| 172 | typedef enum BcStatus { | 189 | typedef enum BcStatus { |
| 173 | BC_STATUS_SUCCESS = 0, | 190 | BC_STATUS_SUCCESS = 0, |
| 174 | BC_STATUS_FAILURE = 1, | 191 | BC_STATUS_FAILURE = 1, |
| @@ -7490,3 +7507,5 @@ int dc_main(int argc UNUSED_PARAM, char **argv) | |||
| 7490 | return bc_vm_run(argv, "DC_LINE_LENGTH"); | 7507 | return bc_vm_run(argv, "DC_LINE_LENGTH"); |
| 7491 | } | 7508 | } |
| 7492 | #endif | 7509 | #endif |
| 7510 | |||
| 7511 | #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 @@ | |||
| 1 | #if 0 //TODO: use if bc is not selected | ||
| 2 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 3 | /* | 2 | /* |
| 4 | * 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. |
| 5 | */ | 4 | */ |
| 6 | //config:config DC | 5 | |
| 7 | //config: bool "dc (4.2 kb)" | 6 | /* config/applet/usage bits are in bc.c */ |
| 8 | //config: default y | 7 | |
| 9 | //config: help | 8 | //#include "libbb.h" |
| 10 | //config: Dc is a reverse-polish desk calculator which supports unlimited | 9 | //#include "common_bufsiz.h" |
| 11 | //config: precision arithmetic. | ||
| 12 | //config: | ||
| 13 | //config:config FEATURE_DC_LIBM | ||
| 14 | //config: bool "Enable power and exp functions (requires libm)" | ||
| 15 | //config: default y | ||
| 16 | //config: depends on DC | ||
| 17 | //config: help | ||
| 18 | //config: Enable power and exp functions. | ||
| 19 | //config: NOTE: This will require libm to be present for linking. | ||
| 20 | |||
| 21 | //applet:IF_DC(APPLET(dc, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
| 22 | |||
| 23 | //kbuild:lib-$(CONFIG_DC) += dc.o | ||
| 24 | |||
| 25 | //usage:#define dc_trivial_usage | ||
| 26 | //usage: "EXPRESSION..." | ||
| 27 | //usage: | ||
| 28 | //usage:#define dc_full_usage "\n\n" | ||
| 29 | //usage: "Tiny RPN calculator. Operations:\n" | ||
| 30 | //usage: "+, add, -, sub, *, mul, /, div, %, mod, "IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, xor,\n" | ||
| 31 | //usage: "p - print top of the stack (without popping),\n" | ||
| 32 | //usage: "f - print entire stack,\n" | ||
| 33 | //usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" | ||
| 34 | //usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16" | ||
| 35 | //usage: | ||
| 36 | //usage:#define dc_example_usage | ||
| 37 | //usage: "$ dc 2 2 + p\n" | ||
| 38 | //usage: "4\n" | ||
| 39 | //usage: "$ dc 8 8 \\* 2 2 + / p\n" | ||
| 40 | //usage: "16\n" | ||
| 41 | //usage: "$ dc 0 1 and p\n" | ||
| 42 | //usage: "0\n" | ||
| 43 | //usage: "$ dc 0 1 or p\n" | ||
| 44 | //usage: "1\n" | ||
| 45 | //usage: "$ echo 72 9 div 8 mul p | dc\n" | ||
| 46 | //usage: "64\n" | ||
| 47 | |||
| 48 | #include "libbb.h" | ||
| 49 | #include "common_bufsiz.h" | ||
| 50 | #include <math.h> | 10 | #include <math.h> |
| 51 | 11 | ||
| 52 | #if 0 | 12 | #if 0 |
| @@ -303,4 +263,3 @@ int dc_main(int argc UNUSED_PARAM, char **argv) | |||
| 303 | } | 263 | } |
| 304 | return EXIT_SUCCESS; | 264 | return EXIT_SUCCESS; |
| 305 | } | 265 | } |
| 306 | #endif | ||
