diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-12 22:38:26 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-12 22:38:26 +0200 |
commit | 5b807cd5acd1f27b3e7aa36aac2728be27c5907c (patch) | |
tree | 721cbf12f7e7029b2b415e0618ff403db306bc5e | |
parent | d7686c8c2c849c775007c5de19901ab6b38bd039 (diff) | |
download | busybox-w32-5b807cd5acd1f27b3e7aa36aac2728be27c5907c.tar.gz busybox-w32-5b807cd5acd1f27b3e7aa36aac2728be27c5907c.tar.bz2 busybox-w32-5b807cd5acd1f27b3e7aa36aac2728be27c5907c.zip |
test: use index_in_strings
function old new delta
ops_texts - 124 +124
ops_table - 80 +80
display_process_list 1447 1448 +1
binop 525 523 -2
static.no_op 6 2 -4
check_operator 71 63 -8
ops 240 - -240
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/3 up/down: 205/-254) Total: -49 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/test.c | 156 |
1 files changed, 96 insertions, 60 deletions
diff --git a/coreutils/test.c b/coreutils/test.c index c430f2210..5864c7f32 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
@@ -222,7 +222,7 @@ static const char *const TOKSTR[] = { | |||
222 | #define unnest_msg_and_return(expr, ...) return expr | 222 | #define unnest_msg_and_return(expr, ...) return expr |
223 | #endif | 223 | #endif |
224 | 224 | ||
225 | enum token_types { | 225 | enum { |
226 | UNOP, | 226 | UNOP, |
227 | BINOP, | 227 | BINOP, |
228 | BUNOP, | 228 | BUNOP, |
@@ -231,53 +231,96 @@ enum token_types { | |||
231 | }; | 231 | }; |
232 | 232 | ||
233 | struct operator_t { | 233 | struct operator_t { |
234 | char op_text[4]; | ||
235 | unsigned char op_num, op_type; | 234 | unsigned char op_num, op_type; |
236 | }; | 235 | }; |
237 | 236 | ||
238 | static const struct operator_t ops[] = { | 237 | static const struct operator_t ops_table[] = { |
239 | { "-r", FILRD , UNOP }, | 238 | { /* "-r" */ FILRD , UNOP }, |
240 | { "-w", FILWR , UNOP }, | 239 | { /* "-w" */ FILWR , UNOP }, |
241 | { "-x", FILEX , UNOP }, | 240 | { /* "-x" */ FILEX , UNOP }, |
242 | { "-e", FILEXIST, UNOP }, | 241 | { /* "-e" */ FILEXIST, UNOP }, |
243 | { "-f", FILREG , UNOP }, | 242 | { /* "-f" */ FILREG , UNOP }, |
244 | { "-d", FILDIR , UNOP }, | 243 | { /* "-d" */ FILDIR , UNOP }, |
245 | { "-c", FILCDEV , UNOP }, | 244 | { /* "-c" */ FILCDEV , UNOP }, |
246 | { "-b", FILBDEV , UNOP }, | 245 | { /* "-b" */ FILBDEV , UNOP }, |
247 | { "-p", FILFIFO , UNOP }, | 246 | { /* "-p" */ FILFIFO , UNOP }, |
248 | { "-u", FILSUID , UNOP }, | 247 | { /* "-u" */ FILSUID , UNOP }, |
249 | { "-g", FILSGID , UNOP }, | 248 | { /* "-g" */ FILSGID , UNOP }, |
250 | { "-k", FILSTCK , UNOP }, | 249 | { /* "-k" */ FILSTCK , UNOP }, |
251 | { "-s", FILGZ , UNOP }, | 250 | { /* "-s" */ FILGZ , UNOP }, |
252 | { "-t", FILTT , UNOP }, | 251 | { /* "-t" */ FILTT , UNOP }, |
253 | { "-z", STREZ , UNOP }, | 252 | { /* "-z" */ STREZ , UNOP }, |
254 | { "-n", STRNZ , UNOP }, | 253 | { /* "-n" */ STRNZ , UNOP }, |
255 | { "-h", FILSYM , UNOP }, /* for backwards compat */ | 254 | { /* "-h" */ FILSYM , UNOP }, /* for backwards compat */ |
256 | 255 | ||
257 | { "-O" , FILUID , UNOP }, | 256 | { /* "-O" */ FILUID , UNOP }, |
258 | { "-G" , FILGID , UNOP }, | 257 | { /* "-G" */ FILGID , UNOP }, |
259 | { "-L" , FILSYM , UNOP }, | 258 | { /* "-L" */ FILSYM , UNOP }, |
260 | { "-S" , FILSOCK, UNOP }, | 259 | { /* "-S" */ FILSOCK , UNOP }, |
261 | { "=" , STREQ , BINOP }, | 260 | { /* "=" */ STREQ , BINOP }, |
262 | { "==" , STREQ , BINOP }, | 261 | { /* "==" */ STREQ , BINOP }, |
263 | { "!=" , STRNE , BINOP }, | 262 | { /* "!=" */ STRNE , BINOP }, |
264 | { "<" , STRLT , BINOP }, | 263 | { /* "<" */ STRLT , BINOP }, |
265 | { ">" , STRGT , BINOP }, | 264 | { /* ">" */ STRGT , BINOP }, |
266 | { "-eq", INTEQ , BINOP }, | 265 | { /* "-eq"*/ INTEQ , BINOP }, |
267 | { "-ne", INTNE , BINOP }, | 266 | { /* "-ne"*/ INTNE , BINOP }, |
268 | { "-ge", INTGE , BINOP }, | 267 | { /* "-ge"*/ INTGE , BINOP }, |
269 | { "-gt", INTGT , BINOP }, | 268 | { /* "-gt"*/ INTGT , BINOP }, |
270 | { "-le", INTLE , BINOP }, | 269 | { /* "-le"*/ INTLE , BINOP }, |
271 | { "-lt", INTLT , BINOP }, | 270 | { /* "-lt"*/ INTLT , BINOP }, |
272 | { "-nt", FILNT , BINOP }, | 271 | { /* "-nt"*/ FILNT , BINOP }, |
273 | { "-ot", FILOT , BINOP }, | 272 | { /* "-ot"*/ FILOT , BINOP }, |
274 | { "-ef", FILEQ , BINOP }, | 273 | { /* "-ef"*/ FILEQ , BINOP }, |
275 | { "!" , UNOT , BUNOP }, | 274 | { /* "!" */ UNOT , BUNOP }, |
276 | { "-a" , BAND , BBINOP }, | 275 | { /* "-a" */ BAND , BBINOP }, |
277 | { "-o" , BOR , BBINOP }, | 276 | { /* "-o" */ BOR , BBINOP }, |
278 | { "(" , LPAREN , PAREN }, | 277 | { /* "(" */ LPAREN , PAREN }, |
279 | { ")" , RPAREN , PAREN }, | 278 | { /* ")" */ RPAREN , PAREN }, |
280 | }; | 279 | }; |
280 | /* Please keep these two tables in sync */ | ||
281 | static const char ops_texts[] ALIGN1 = | ||
282 | "-r" "\0" | ||
283 | "-w" "\0" | ||
284 | "-x" "\0" | ||
285 | "-e" "\0" | ||
286 | "-f" "\0" | ||
287 | "-d" "\0" | ||
288 | "-c" "\0" | ||
289 | "-b" "\0" | ||
290 | "-p" "\0" | ||
291 | "-u" "\0" | ||
292 | "-g" "\0" | ||
293 | "-k" "\0" | ||
294 | "-s" "\0" | ||
295 | "-t" "\0" | ||
296 | "-z" "\0" | ||
297 | "-n" "\0" | ||
298 | "-h" "\0" | ||
299 | |||
300 | "-O" "\0" | ||
301 | "-G" "\0" | ||
302 | "-L" "\0" | ||
303 | "-S" "\0" | ||
304 | "=" "\0" | ||
305 | "==" "\0" | ||
306 | "!=" "\0" | ||
307 | "<" "\0" | ||
308 | ">" "\0" | ||
309 | "-eq" "\0" | ||
310 | "-ne" "\0" | ||
311 | "-ge" "\0" | ||
312 | "-gt" "\0" | ||
313 | "-le" "\0" | ||
314 | "-lt" "\0" | ||
315 | "-nt" "\0" | ||
316 | "-ot" "\0" | ||
317 | "-ef" "\0" | ||
318 | "!" "\0" | ||
319 | "-a" "\0" | ||
320 | "-o" "\0" | ||
321 | "(" "\0" | ||
322 | ")" "\0" | ||
323 | ; | ||
281 | 324 | ||
282 | 325 | ||
283 | #if ENABLE_FEATURE_TEST_64 | 326 | #if ENABLE_FEATURE_TEST_64 |
@@ -384,29 +427,22 @@ static int equalf(const char *f1, const char *f2) | |||
384 | */ | 427 | */ |
385 | 428 | ||
386 | 429 | ||
387 | static enum token check_operator(char *s) | 430 | static enum token check_operator(const char *s) |
388 | { | 431 | { |
389 | static const struct operator_t no_op = { | 432 | static const struct operator_t no_op = { |
390 | .op_num = -1, | 433 | .op_num = -1, |
391 | .op_type = -1 | 434 | .op_type = -1 |
392 | }; | 435 | }; |
393 | const struct operator_t *op; | 436 | int n; |
394 | 437 | ||
395 | last_operator = &no_op; | 438 | last_operator = &no_op; |
396 | if (s == NULL) { | 439 | if (s == NULL) |
397 | return EOI; | 440 | return EOI; |
398 | } | 441 | n = index_in_strings(ops_texts, s); |
399 | 442 | if (n < 0) | |
400 | op = ops; | 443 | return OPERAND; |
401 | do { | 444 | last_operator = &ops_table[n]; |
402 | if (strcmp(s, op->op_text) == 0) { | 445 | return ops_table[n].op_num; |
403 | last_operator = op; | ||
404 | return op->op_num; | ||
405 | } | ||
406 | op++; | ||
407 | } while (op < ops + ARRAY_SIZE(ops)); | ||
408 | |||
409 | return OPERAND; | ||
410 | } | 446 | } |
411 | 447 | ||
412 | 448 | ||
@@ -422,7 +458,7 @@ static int binop(void) | |||
422 | 458 | ||
423 | opnd2 = *++args; | 459 | opnd2 = *++args; |
424 | if (opnd2 == NULL) | 460 | if (opnd2 == NULL) |
425 | syntax(op->op_text, "argument expected"); | 461 | syntax(args[-1], "argument expected"); |
426 | 462 | ||
427 | if (is_int_op(op->op_num)) { | 463 | if (is_int_op(op->op_num)) { |
428 | val1 = getn(opnd1); | 464 | val1 = getn(opnd1); |