X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=dc.c;h=d462100a21166e42c939915de6b0f761a1ed5253;hb=46f44d24fcc25a5d6e13e0453485881bdf147e91;hp=31a5471c30e1752721a99e87c60c6fd39ad2ebf0;hpb=7ac06a3ff12b800af7b5e5e97377695a628a8856;p=oweals%2Fbusybox.git diff --git a/dc.c b/dc.c index 31a5471c3..d462100a2 100644 --- a/dc.c +++ b/dc.c @@ -1,5 +1,5 @@ /* vi: set sw=4 ts=4: */ -#include "internal.h" +#include "busybox.h" #include #include #include @@ -8,32 +8,20 @@ /* 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\n"); + 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\n"); return stack[--pointer]; } @@ -132,8 +120,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.\n", argument); } /* return pointer to next token in buffer and set *buffer to one char @@ -170,7 +157,7 @@ int dc_main(int argc, char **argv) char *line = NULL; char *cursor = NULL; char *token = NULL; - while ((line = cstring_lineFromFile(stdin))) { + while ((line = get_line_from_file(stdin))) { cursor = line; len = number_of_tokens(line); for (i = 0; i < len; i++) { @@ -190,5 +177,5 @@ int dc_main(int argc, char **argv) } } stack_machine(0); - return( TRUE); + return EXIT_SUCCESS; }