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