diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-01-18 13:30:13 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-01-18 13:30:13 +0100 |
commit | 9daf33fc5245abebdda145f95e1ad3a175241f18 (patch) | |
tree | 78d35989380e9328110bce0757e22a5db66722be /miscutils/dc.c | |
parent | 7c4b13e0190a645f4083741c7803e51984cf71cb (diff) | |
download | busybox-w32-9daf33fc5245abebdda145f95e1ad3a175241f18.tar.gz busybox-w32-9daf33fc5245abebdda145f95e1ad3a175241f18.tar.bz2 busybox-w32-9daf33fc5245abebdda145f95e1ad3a175241f18.zip |
dc: code shrink
function old new delta
stack_machine 103 101 -2
operators 176 168 -8
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/dc.c')
-rw-r--r-- | miscutils/dc.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c index 6903761e4..6bcfbe249 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c | |||
@@ -11,11 +11,11 @@ | |||
11 | //usage: | 11 | //usage: |
12 | //usage:#define dc_full_usage "\n\n" | 12 | //usage:#define dc_full_usage "\n\n" |
13 | //usage: "Tiny RPN calculator. Operations:\n" | 13 | //usage: "Tiny RPN calculator. Operations:\n" |
14 | //usage: "+, add, -, sub, *, mul, /, div, %, mod, "IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, eor,\n" | 14 | //usage: "+, add, -, sub, *, mul, /, div, %, mod, "IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, xor,\n" |
15 | //usage: "p - print top of the stack (without popping),\n" | 15 | //usage: "p - print top of the stack (without popping),\n" |
16 | //usage: "f - print entire stack,\n" | 16 | //usage: "f - print entire stack,\n" |
17 | //usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" | 17 | //usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" |
18 | //usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 * 2 2 + / p' -> 16" | 18 | //usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16" |
19 | //usage: | 19 | //usage: |
20 | //usage:#define dc_example_usage | 20 | //usage:#define dc_example_usage |
21 | //usage: "$ dc 2 2 + p\n" | 21 | //usage: "$ dc 2 2 + p\n" |
@@ -219,29 +219,29 @@ static const struct op operators[] = { | |||
219 | {"p", print_no_pop}, | 219 | {"p", print_no_pop}, |
220 | {"f", print_stack_no_pop}, | 220 | {"f", print_stack_no_pop}, |
221 | {"o", set_output_base}, | 221 | {"o", set_output_base}, |
222 | { "", NULL } | ||
223 | }; | 222 | }; |
224 | 223 | ||
225 | static void stack_machine(const char *argument) | 224 | static void stack_machine(const char *argument) |
226 | { | 225 | { |
227 | char *endPointer; | 226 | char *end; |
228 | double d; | 227 | double d; |
229 | const struct op *o = operators; | 228 | const struct op *o; |
230 | 229 | ||
231 | d = strtod(argument, &endPointer); | 230 | d = strtod(argument, &end); |
232 | 231 | if (end != argument && *end == '\0') { | |
233 | if (endPointer != argument && *endPointer == '\0') { | ||
234 | push(d); | 232 | push(d); |
235 | return; | 233 | return; |
236 | } | 234 | } |
237 | 235 | ||
238 | while (o->function) { | 236 | o = operators; |
237 | do { | ||
239 | if (strcmp(o->name, argument) == 0) { | 238 | if (strcmp(o->name, argument) == 0) { |
240 | o->function(); | 239 | o->function(); |
241 | return; | 240 | return; |
242 | } | 241 | } |
243 | o++; | 242 | o++; |
244 | } | 243 | } while (o != operators + ARRAY_SIZE(operators)); |
244 | |||
245 | bb_error_msg_and_die("syntax error at '%s'", argument); | 245 | bb_error_msg_and_die("syntax error at '%s'", argument); |
246 | } | 246 | } |
247 | 247 | ||