diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-30 18:37:08 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-30 18:37:08 +0100 |
commit | bd1de181ad9a3486ad35e71272fe2cf21d63916c (patch) | |
tree | 0a20790787deb5f6a47cc5010058985183fccdb3 | |
parent | 6879a7ae4393e4a94490e297dbe8b836c6c7dd15 (diff) | |
download | busybox-w32-bd1de181ad9a3486ad35e71272fe2cf21d63916c.tar.gz busybox-w32-bd1de181ad9a3486ad35e71272fe2cf21d63916c.tar.bz2 busybox-w32-bd1de181ad9a3486ad35e71272fe2cf21d63916c.zip |
dc: make "dc -1.23 ..." work
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@googlemail.com>
-rw-r--r-- | miscutils/dc.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c index 3656cddc6..7348ed349 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c | |||
@@ -191,24 +191,21 @@ static void stack_machine(const char *argument) | |||
191 | double d; | 191 | double d; |
192 | const struct op *o = operators; | 192 | const struct op *o = operators; |
193 | 193 | ||
194 | if (argument == 0) | ||
195 | return; | ||
196 | |||
197 | d = strtod(argument, &endPointer); | 194 | d = strtod(argument, &endPointer); |
198 | 195 | ||
199 | if (endPointer != argument) { | 196 | if (endPointer != argument && *endPointer == '\0') { |
200 | push(d); | 197 | push(d); |
201 | return; | 198 | return; |
202 | } | 199 | } |
203 | 200 | ||
204 | while (o->name[0]) { | 201 | while (o->function) { |
205 | if (strcmp(o->name, argument) == 0) { | 202 | if (strcmp(o->name, argument) == 0) { |
206 | o->function(); | 203 | o->function(); |
207 | return; | 204 | return; |
208 | } | 205 | } |
209 | o++; | 206 | o++; |
210 | } | 207 | } |
211 | bb_error_msg_and_die("%s: syntax error", argument); | 208 | bb_error_msg_and_die("syntax error at '%s'", argument); |
212 | } | 209 | } |
213 | 210 | ||
214 | /* return pointer to next token in buffer and set *buffer to one char | 211 | /* 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) | |||
239 | cursor = line; | 236 | cursor = line; |
240 | while (1) { | 237 | while (1) { |
241 | token = get_token(&cursor); | 238 | token = get_token(&cursor); |
242 | if (!token) break; | 239 | if (!token) |
240 | break; | ||
243 | *cursor++ = '\0'; | 241 | *cursor++ = '\0'; |
244 | stack_machine(token); | 242 | stack_machine(token); |
245 | } | 243 | } |
246 | free(line); | 244 | free(line); |
247 | } | 245 | } |
248 | } else { | 246 | } else { |
249 | if (argv[0][0] == '-') | 247 | // why? it breaks "dc -2 2 * p" |
250 | bb_show_usage(); | 248 | //if (argv[0][0] == '-') |
249 | // bb_show_usage(); | ||
251 | do { | 250 | do { |
252 | stack_machine(*argv); | 251 | stack_machine(*argv); |
253 | } while (*++argv); | 252 | } while (*++argv); |