X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=miscutils%2Fdc.c;h=8d7a92a2802f5c871f40a4cb65bafd22667d9abe;hb=95b520110dc1ee6ee670817fdd6312a8565cf34c;hp=5bf3bc984684171c9f95f6b19819d2ecb3f2ba3a;hpb=1ca41775bbdc07cf67be79aebc566754c9c02855;p=oweals%2Fbusybox.git diff --git a/miscutils/dc.c b/miscutils/dc.c index 5bf3bc984..8d7a92a28 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -1,39 +1,28 @@ /* vi: set sw=4 ts=4: */ -#include "internal.h" #include #include #include +#include #include #include +#include "busybox.h" /* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */ -static const char dc_usage[] = "dc expression ...\n" -#ifndef BB_FEATURE_TRIVIAL_HELP - "\nThis is a Tiny RPN calculator that understands the\n" - "following operations: +, -, /, *, and, or, not, eor.\n" - "i.e. 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16\n" -#endif - ; - static double stack[100]; static unsigned int pointer; static void push(double a) { - if (pointer >= (sizeof(stack) / sizeof(*stack))) { - fprintf(stderr, "dc: stack overflow\n"); - exit(-1); - } else - stack[pointer++] = a; + if (pointer >= (sizeof(stack) / sizeof(*stack))) + error_msg_and_die("stack overflow"); + stack[pointer++] = a; } static double pop() { - if (pointer == 0) { - fprintf(stderr, "dc: stack underflow\n"); - exit(-1); - } + if (pointer == 0) + error_msg_and_die("stack underflow"); return stack[--pointer]; } @@ -132,8 +121,7 @@ static void stack_machine(const char *argument) } o++; } - fprintf(stderr, "dc: %s: syntax error.\n", argument); - exit(-1); + error_msg_and_die("%s: syntax error.", argument); } /* return pointer to next token in buffer and set *buffer to one char @@ -182,7 +170,7 @@ int dc_main(int argc, char **argv) } } else { if (*argv[1]=='-') - usage(dc_usage); + show_usage(); while (argc >= 2) { stack_machine(argv[1]); argv++; @@ -190,5 +178,5 @@ int dc_main(int argc, char **argv) } } stack_machine(0); - return( TRUE); + return EXIT_SUCCESS; }