Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 2 | /* |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 6 | #include "libbb.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 7 | #include <math.h> |
| 8 | |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 9 | //usage:#define dc_trivial_usage |
Denys Vlasenko | 506d3a9 | 2010-07-29 04:06:07 +0200 | [diff] [blame] | 10 | //usage: "EXPRESSION..." |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 11 | //usage: |
| 12 | //usage:#define dc_full_usage "\n\n" |
| 13 | //usage: "Tiny RPN calculator. Operations:\n" |
| 14 | //usage: "+, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor,\n" |
| 15 | //usage: "p - print top of the stack (without popping),\n" |
Denys Vlasenko | 506d3a9 | 2010-07-29 04:06:07 +0200 | [diff] [blame] | 16 | //usage: "f - print entire stack,\n" |
| 17 | //usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" |
| 18 | //usage: "Examples: 'dc 2 2 add' -> 4, 'dc 8 8 * 2 2 + /' -> 16" |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 19 | //usage: |
| 20 | //usage:#define dc_example_usage |
| 21 | //usage: "$ dc 2 2 + p\n" |
| 22 | //usage: "4\n" |
| 23 | //usage: "$ dc 8 8 \\* 2 2 + / p\n" |
| 24 | //usage: "16\n" |
| 25 | //usage: "$ dc 0 1 and p\n" |
| 26 | //usage: "0\n" |
| 27 | //usage: "$ dc 0 1 or p\n" |
| 28 | //usage: "1\n" |
| 29 | //usage: "$ echo 72 9 div 8 mul p | dc\n" |
| 30 | //usage: "64\n" |
| 31 | |
| 32 | #if 0 |
| 33 | typedef unsigned data_t; |
| 34 | #define DATA_FMT "" |
| 35 | #elif 0 |
| 36 | typedef unsigned long data_t; |
| 37 | #define DATA_FMT "l" |
| 38 | #else |
| 39 | typedef unsigned long long data_t; |
| 40 | #define DATA_FMT "ll" |
| 41 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 42 | |
Denis Vlasenko | 5b27fbe | 2007-03-24 14:06:51 +0000 | [diff] [blame] | 43 | |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 44 | struct globals { |
| 45 | unsigned pointer; |
| 46 | unsigned base; |
| 47 | double stack[1]; |
Denys Vlasenko | 98a4c7c | 2010-02-04 15:00:15 +0100 | [diff] [blame] | 48 | } FIX_ALIASING; |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 49 | enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) }; |
| 50 | #define G (*(struct globals*)&bb_common_bufsiz1) |
| 51 | #define pointer (G.pointer ) |
| 52 | #define base (G.base ) |
| 53 | #define stack (G.stack ) |
Denis Vlasenko | d8850f2 | 2008-12-30 10:40:05 +0000 | [diff] [blame] | 54 | #define INIT_G() do { \ |
| 55 | base = 10; \ |
| 56 | } while (0) |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 57 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 58 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 59 | static void push(double a) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 60 | { |
Denis Vlasenko | 5b27fbe | 2007-03-24 14:06:51 +0000 | [diff] [blame] | 61 | if (pointer >= STACK_SIZE) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 62 | bb_error_msg_and_die("stack overflow"); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 63 | stack[pointer++] = a; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 66 | static double pop(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 67 | { |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 68 | if (pointer == 0) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 69 | bb_error_msg_and_die("stack underflow"); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 70 | return stack[--pointer]; |
| 71 | } |
| 72 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 73 | static void add(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 74 | { |
| 75 | push(pop() + pop()); |
| 76 | } |
| 77 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 78 | static void sub(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 79 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 80 | double subtrahend = pop(); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 81 | |
| 82 | push(pop() - subtrahend); |
| 83 | } |
| 84 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 85 | static void mul(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 86 | { |
| 87 | push(pop() * pop()); |
| 88 | } |
| 89 | |
Denis Vlasenko | 0783230 | 2008-10-20 08:43:10 +0000 | [diff] [blame] | 90 | #if ENABLE_FEATURE_DC_LIBM |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 91 | static void power(void) |
| 92 | { |
| 93 | double topower = pop(); |
| 94 | |
| 95 | push(pow(pop(), topower)); |
| 96 | } |
Denis Vlasenko | 0783230 | 2008-10-20 08:43:10 +0000 | [diff] [blame] | 97 | #endif |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 98 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 99 | static void divide(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 100 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 101 | double divisor = pop(); |
| 102 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 103 | push(pop() / divisor); |
| 104 | } |
| 105 | |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 106 | static void mod(void) |
| 107 | { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 108 | data_t d = pop(); |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 109 | |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 110 | push((data_t) pop() % d); |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 113 | static void and(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 114 | { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 115 | push((data_t) pop() & (data_t) pop()); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 118 | static void or(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 119 | { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 120 | push((data_t) pop() | (data_t) pop()); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 123 | static void eor(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 124 | { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 125 | push((data_t) pop() ^ (data_t) pop()); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 128 | static void not(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 129 | { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 130 | push(~(data_t) pop()); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Glenn L McGrath | 6d07432 | 2002-12-12 10:31:53 +0000 | [diff] [blame] | 133 | static void set_output_base(void) |
| 134 | { |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 135 | static const char bases[] ALIGN1 = { 2, 8, 10, 16, 0 }; |
| 136 | unsigned b = (unsigned)pop(); |
| 137 | |
| 138 | base = *strchrnul(bases, b); |
| 139 | if (base == 0) { |
| 140 | bb_error_msg("error, base %u is not supported", b); |
Denis Vlasenko | 5b27fbe | 2007-03-24 14:06:51 +0000 | [diff] [blame] | 141 | base = 10; |
Glenn L McGrath | 6d07432 | 2002-12-12 10:31:53 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | static void print_base(double print) |
| 146 | { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 147 | data_t x, i; |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 148 | |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 149 | x = (data_t) print; |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 150 | if (base == 10) { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 151 | if (x == print) /* exactly representable as unsigned integer */ |
| 152 | printf("%"DATA_FMT"u\n", x); |
| 153 | else |
| 154 | printf("%g\n", print); |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 158 | switch (base) { |
| 159 | case 16: |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 160 | printf("%"DATA_FMT"x\n", x); |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 161 | break; |
| 162 | case 8: |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 163 | printf("%"DATA_FMT"o\n", x); |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 164 | break; |
| 165 | default: /* base 2 */ |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 166 | i = MAXINT(data_t) - (MAXINT(data_t) >> 1); |
| 167 | /* i is 100000...00000 */ |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 168 | do { |
Denys Vlasenko | 7a07b0e | 2010-07-29 04:00:27 +0200 | [diff] [blame] | 169 | if (x & i) |
| 170 | break; |
Denis Vlasenko | 6b38e18 | 2008-10-30 23:25:50 +0000 | [diff] [blame] | 171 | i >>= 1; |
| 172 | } while (i > 1); |
| 173 | do { |
| 174 | bb_putchar('1' - !(x & i)); |
| 175 | i >>= 1; |
| 176 | } while (i); |
| 177 | bb_putchar('\n'); |
| 178 | } |
Glenn L McGrath | 6d07432 | 2002-12-12 10:31:53 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static void print_stack_no_pop(void) |
| 182 | { |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 183 | unsigned i = pointer; |
Glenn L McGrath | 6d07432 | 2002-12-12 10:31:53 +0000 | [diff] [blame] | 184 | while (i) |
| 185 | print_base(stack[--i]); |
| 186 | } |
| 187 | |
| 188 | static void print_no_pop(void) |
| 189 | { |
| 190 | print_base(stack[pointer-1]); |
| 191 | } |
| 192 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 193 | struct op { |
Denis Vlasenko | 5b27fbe | 2007-03-24 14:06:51 +0000 | [diff] [blame] | 194 | const char name[4]; |
Aaron Lehmann | 2dd2d7a | 2001-12-06 03:29:37 +0000 | [diff] [blame] | 195 | void (*function) (void); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 198 | static const struct op operators[] = { |
John Beppu | c035254 | 2000-06-21 18:00:46 +0000 | [diff] [blame] | 199 | {"+", add}, |
| 200 | {"add", add}, |
| 201 | {"-", sub}, |
| 202 | {"sub", sub}, |
| 203 | {"*", mul}, |
| 204 | {"mul", mul}, |
| 205 | {"/", divide}, |
| 206 | {"div", divide}, |
Denis Vlasenko | 0783230 | 2008-10-20 08:43:10 +0000 | [diff] [blame] | 207 | #if ENABLE_FEATURE_DC_LIBM |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 208 | {"**", power}, |
| 209 | {"exp", power}, |
| 210 | {"pow", power}, |
Denis Vlasenko | 0783230 | 2008-10-20 08:43:10 +0000 | [diff] [blame] | 211 | #endif |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 212 | {"%", mod}, |
| 213 | {"mod", mod}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 214 | {"and", and}, |
John Beppu | c035254 | 2000-06-21 18:00:46 +0000 | [diff] [blame] | 215 | {"or", or}, |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 216 | {"not", not}, |
| 217 | {"eor", eor}, |
Eric Andersen | a928774 | 2003-10-22 11:24:39 +0000 | [diff] [blame] | 218 | {"xor", eor}, |
Glenn L McGrath | 6d07432 | 2002-12-12 10:31:53 +0000 | [diff] [blame] | 219 | {"p", print_no_pop}, |
| 220 | {"f", print_stack_no_pop}, |
| 221 | {"o", set_output_base}, |
Denys Vlasenko | 043b1e5 | 2009-09-06 12:47:55 +0200 | [diff] [blame] | 222 | { "", NULL } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 225 | static void stack_machine(const char *argument) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 226 | { |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 227 | char *endPointer; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 228 | double d; |
| 229 | const struct op *o = operators; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 230 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 231 | d = strtod(argument, &endPointer); |
| 232 | |
Denys Vlasenko | bd1de18 | 2009-12-30 18:37:08 +0100 | [diff] [blame] | 233 | if (endPointer != argument && *endPointer == '\0') { |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 234 | push(d); |
| 235 | return; |
| 236 | } |
| 237 | |
Denys Vlasenko | bd1de18 | 2009-12-30 18:37:08 +0100 | [diff] [blame] | 238 | while (o->function) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 239 | if (strcmp(o->name, argument) == 0) { |
Denis Vlasenko | 5b27fbe | 2007-03-24 14:06:51 +0000 | [diff] [blame] | 240 | o->function(); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 241 | return; |
| 242 | } |
| 243 | o++; |
| 244 | } |
Denys Vlasenko | bd1de18 | 2009-12-30 18:37:08 +0100 | [diff] [blame] | 245 | bb_error_msg_and_die("syntax error at '%s'", argument); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 246 | } |
| 247 | |
John Beppu | 5db60a7 | 2000-06-12 22:59:12 +0000 | [diff] [blame] | 248 | /* return pointer to next token in buffer and set *buffer to one char |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 249 | * past the end of the above mentioned token |
John Beppu | 5db60a7 | 2000-06-12 22:59:12 +0000 | [diff] [blame] | 250 | */ |
| 251 | static char *get_token(char **buffer) |
| 252 | { |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 253 | char *current = skip_whitespace(*buffer); |
| 254 | if (*current != '\0') { |
| 255 | *buffer = skip_non_whitespace(current); |
| 256 | return current; |
John Beppu | 5db60a7 | 2000-06-12 22:59:12 +0000 | [diff] [blame] | 257 | } |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 258 | return NULL; |
John Beppu | 5db60a7 | 2000-06-12 22:59:12 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 261 | int dc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 262 | int dc_main(int argc UNUSED_PARAM, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 263 | { |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 264 | INIT_G(); |
| 265 | |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 266 | argv++; |
| 267 | if (!argv[0]) { |
| 268 | /* take stuff from stdin if no args are given */ |
| 269 | char *line; |
| 270 | char *cursor; |
| 271 | char *token; |
Denis Vlasenko | 8ee649a | 2008-03-26 20:04:27 +0000 | [diff] [blame] | 272 | while ((line = xmalloc_fgetline(stdin)) != NULL) { |
John Beppu | 5db60a7 | 2000-06-12 22:59:12 +0000 | [diff] [blame] | 273 | cursor = line; |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 274 | while (1) { |
John Beppu | 5db60a7 | 2000-06-12 22:59:12 +0000 | [diff] [blame] | 275 | token = get_token(&cursor); |
Denys Vlasenko | bd1de18 | 2009-12-30 18:37:08 +0100 | [diff] [blame] | 276 | if (!token) |
| 277 | break; |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 278 | *cursor++ = '\0'; |
John Beppu | 5db60a7 | 2000-06-12 22:59:12 +0000 | [diff] [blame] | 279 | stack_machine(token); |
| 280 | } |
| 281 | free(line); |
| 282 | } |
| 283 | } else { |
Denys Vlasenko | bd1de18 | 2009-12-30 18:37:08 +0100 | [diff] [blame] | 284 | // why? it breaks "dc -2 2 * p" |
| 285 | //if (argv[0][0] == '-') |
| 286 | // bb_show_usage(); |
Denis Vlasenko | b44c790 | 2008-03-17 09:29:43 +0000 | [diff] [blame] | 287 | do { |
| 288 | stack_machine(*argv); |
| 289 | } while (*++argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 290 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 291 | return EXIT_SUCCESS; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 292 | } |