mirror of
https://github.com/sheumann/hush.git
synced 2025-01-18 07:31:34 +00:00
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>
This commit is contained in:
parent
6879a7ae43
commit
bd1de181ad
@ -191,24 +191,21 @@ static void stack_machine(const char *argument)
|
|||||||
double d;
|
double d;
|
||||||
const struct op *o = operators;
|
const struct op *o = operators;
|
||||||
|
|
||||||
if (argument == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
d = strtod(argument, &endPointer);
|
d = strtod(argument, &endPointer);
|
||||||
|
|
||||||
if (endPointer != argument) {
|
if (endPointer != argument && *endPointer == '\0') {
|
||||||
push(d);
|
push(d);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (o->name[0]) {
|
while (o->function) {
|
||||||
if (strcmp(o->name, argument) == 0) {
|
if (strcmp(o->name, argument) == 0) {
|
||||||
o->function();
|
o->function();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
o++;
|
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
|
/* 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;
|
cursor = line;
|
||||||
while (1) {
|
while (1) {
|
||||||
token = get_token(&cursor);
|
token = get_token(&cursor);
|
||||||
if (!token) break;
|
if (!token)
|
||||||
|
break;
|
||||||
*cursor++ = '\0';
|
*cursor++ = '\0';
|
||||||
stack_machine(token);
|
stack_machine(token);
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (argv[0][0] == '-')
|
// why? it breaks "dc -2 2 * p"
|
||||||
bb_show_usage();
|
//if (argv[0][0] == '-')
|
||||||
|
// bb_show_usage();
|
||||||
do {
|
do {
|
||||||
stack_machine(*argv);
|
stack_machine(*argv);
|
||||||
} while (*++argv);
|
} while (*++argv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user