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