aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-12 22:41:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-12 22:41:57 +0200
commitc541a8955d20080c7a5e0c13e15bef8740eb3565 (patch)
treec999820b14c39b6c4d9bb9671439fdfab2af8390
parentfe73798135d30561f9985278ecc46d41c8ff492e (diff)
downloadbusybox-w32-c541a8955d20080c7a5e0c13e15bef8740eb3565.tar.gz
busybox-w32-c541a8955d20080c7a5e0c13e15bef8740eb3565.tar.bz2
busybox-w32-c541a8955d20080c7a5e0c13e15bef8740eb3565.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.c156
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
225enum token_types { 225enum {
226 UNOP, 226 UNOP,
227 BINOP, 227 BINOP,
228 BUNOP, 228 BUNOP,
@@ -231,53 +231,96 @@ enum token_types {
231}; 231};
232 232
233struct operator_t { 233struct 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
238static const struct operator_t ops[] = { 237static 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 */
281static 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
387static enum token check_operator(char *s) 430static 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);