summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-01-18 12:30:13 (GMT)
committer Denys Vlasenko <vda.linux@googlemail.com>2013-01-18 12:30:13 (GMT)
commit9daf33fc5245abebdda145f95e1ad3a175241f18 (patch)
tree78d35989380e9328110bce0757e22a5db66722be
parent7c4b13e0190a645f4083741c7803e51984cf71cb (diff)
downloadbusybox-9daf33fc5245abebdda145f95e1ad3a175241f18.tar.gz
busybox-9daf33fc5245abebdda145f95e1ad3a175241f18.tar.bz2
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>
-rw-r--r--miscutils/dc.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c
index 6903761..6bcfbe2 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -11,11 +11,11 @@
//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, eor,\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 * 2 2 + / p' -> 16"
+//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"
@@ -219,29 +219,29 @@ static const struct op operators[] = {
{"p", print_no_pop},
{"f", print_stack_no_pop},
{"o", set_output_base},
- { "", NULL }
};
static void stack_machine(const char *argument)
{
- char *endPointer;
+ char *end;
double d;
- const struct op *o = operators;
+ const struct op *o;
- d = strtod(argument, &endPointer);
-
- if (endPointer != argument && *endPointer == '\0') {
+ d = strtod(argument, &end);
+ if (end != argument && *end == '\0') {
push(d);
return;
}
- while (o->function) {
+ o = operators;
+ do {
if (strcmp(o->name, argument) == 0) {
o->function();
return;
}
o++;
- }
+ } while (o != operators + ARRAY_SIZE(operators));
+
bb_error_msg_and_die("syntax error at '%s'", argument);
}