[git commit master] dc: make "dc -1.23 ..." work

Denys Vlasenko vda.linux at googlemail.com
Wed Dec 30 17:37:08 UTC 2009


commit: http://git.busybox.net/busybox/commit/?id=bd1de181ad9a3486ad35e71272fe2cf21d63916c
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
stack_machine                                         97     103      +6
dc_main                                              121     110     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 9/-58)             Total: -49 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/dc.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/miscutils/dc.c b/miscutils/dc.c
index 3656cdd..7348ed3 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -191,24 +191,21 @@ static void stack_machine(const char *argument)
 	double d;
 	const struct op *o = operators;
 
-	if (argument == 0)
-		return;
-
 	d = strtod(argument, &endPointer);
 
-	if (endPointer != argument) {
+	if (endPointer != argument && *endPointer == '\0') {
 		push(d);
 		return;
 	}
 
-	while (o->name[0]) {
+	while (o->function) {
 		if (strcmp(o->name, argument) == 0) {
 			o->function();
 			return;
 		}
 		o++;
 	}
-	bb_error_msg_and_die("%s: syntax error", argument);
+	bb_error_msg_and_die("syntax error at '%s'", argument);
 }
 
 /* return pointer to next token in buffer and set *buffer to one char
@@ -239,15 +236,17 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
 			cursor = line;
 			while (1) {
 				token = get_token(&cursor);
-				if (!token) break;
+				if (!token)
+					break;
 				*cursor++ = '\0';
 				stack_machine(token);
 			}
 			free(line);
 		}
 	} else {
-		if (argv[0][0] == '-')
-			bb_show_usage();
+		// why? it breaks "dc -2 2 * p"
+		//if (argv[0][0] == '-')
+		//	bb_show_usage();
 		do {
 			stack_machine(*argv);
 		} while (*++argv);
-- 
1.6.3.3



More information about the busybox-cvs mailing list