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>
This commit is contained in:
parent
fe73798135
commit
c541a8955d
154
coreutils/test.c
154
coreutils/test.c
@ -222,7 +222,7 @@ static const char *const TOKSTR[] = {
|
|||||||
#define unnest_msg_and_return(expr, ...) return expr
|
#define unnest_msg_and_return(expr, ...) return expr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum token_types {
|
enum {
|
||||||
UNOP,
|
UNOP,
|
||||||
BINOP,
|
BINOP,
|
||||||
BUNOP,
|
BUNOP,
|
||||||
@ -231,53 +231,96 @@ enum token_types {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct operator_t {
|
struct operator_t {
|
||||||
char op_text[4];
|
|
||||||
unsigned char op_num, op_type;
|
unsigned char op_num, op_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct operator_t ops[] = {
|
static const struct operator_t ops_table[] = {
|
||||||
{ "-r", FILRD , UNOP },
|
{ /* "-r" */ FILRD , UNOP },
|
||||||
{ "-w", FILWR , UNOP },
|
{ /* "-w" */ FILWR , UNOP },
|
||||||
{ "-x", FILEX , UNOP },
|
{ /* "-x" */ FILEX , UNOP },
|
||||||
{ "-e", FILEXIST, UNOP },
|
{ /* "-e" */ FILEXIST, UNOP },
|
||||||
{ "-f", FILREG , UNOP },
|
{ /* "-f" */ FILREG , UNOP },
|
||||||
{ "-d", FILDIR , UNOP },
|
{ /* "-d" */ FILDIR , UNOP },
|
||||||
{ "-c", FILCDEV , UNOP },
|
{ /* "-c" */ FILCDEV , UNOP },
|
||||||
{ "-b", FILBDEV , UNOP },
|
{ /* "-b" */ FILBDEV , UNOP },
|
||||||
{ "-p", FILFIFO , UNOP },
|
{ /* "-p" */ FILFIFO , UNOP },
|
||||||
{ "-u", FILSUID , UNOP },
|
{ /* "-u" */ FILSUID , UNOP },
|
||||||
{ "-g", FILSGID , UNOP },
|
{ /* "-g" */ FILSGID , UNOP },
|
||||||
{ "-k", FILSTCK , UNOP },
|
{ /* "-k" */ FILSTCK , UNOP },
|
||||||
{ "-s", FILGZ , UNOP },
|
{ /* "-s" */ FILGZ , UNOP },
|
||||||
{ "-t", FILTT , UNOP },
|
{ /* "-t" */ FILTT , UNOP },
|
||||||
{ "-z", STREZ , UNOP },
|
{ /* "-z" */ STREZ , UNOP },
|
||||||
{ "-n", STRNZ , UNOP },
|
{ /* "-n" */ STRNZ , UNOP },
|
||||||
{ "-h", FILSYM , UNOP }, /* for backwards compat */
|
{ /* "-h" */ FILSYM , UNOP }, /* for backwards compat */
|
||||||
|
|
||||||
{ "-O" , FILUID , UNOP },
|
{ /* "-O" */ FILUID , UNOP },
|
||||||
{ "-G" , FILGID , UNOP },
|
{ /* "-G" */ FILGID , UNOP },
|
||||||
{ "-L" , FILSYM , UNOP },
|
{ /* "-L" */ FILSYM , UNOP },
|
||||||
{ "-S" , FILSOCK, UNOP },
|
{ /* "-S" */ FILSOCK , UNOP },
|
||||||
{ "=" , STREQ , BINOP },
|
{ /* "=" */ STREQ , BINOP },
|
||||||
{ "==" , STREQ , BINOP },
|
{ /* "==" */ STREQ , BINOP },
|
||||||
{ "!=" , STRNE , BINOP },
|
{ /* "!=" */ STRNE , BINOP },
|
||||||
{ "<" , STRLT , BINOP },
|
{ /* "<" */ STRLT , BINOP },
|
||||||
{ ">" , STRGT , BINOP },
|
{ /* ">" */ STRGT , BINOP },
|
||||||
{ "-eq", INTEQ , BINOP },
|
{ /* "-eq"*/ INTEQ , BINOP },
|
||||||
{ "-ne", INTNE , BINOP },
|
{ /* "-ne"*/ INTNE , BINOP },
|
||||||
{ "-ge", INTGE , BINOP },
|
{ /* "-ge"*/ INTGE , BINOP },
|
||||||
{ "-gt", INTGT , BINOP },
|
{ /* "-gt"*/ INTGT , BINOP },
|
||||||
{ "-le", INTLE , BINOP },
|
{ /* "-le"*/ INTLE , BINOP },
|
||||||
{ "-lt", INTLT , BINOP },
|
{ /* "-lt"*/ INTLT , BINOP },
|
||||||
{ "-nt", FILNT , BINOP },
|
{ /* "-nt"*/ FILNT , BINOP },
|
||||||
{ "-ot", FILOT , BINOP },
|
{ /* "-ot"*/ FILOT , BINOP },
|
||||||
{ "-ef", FILEQ , BINOP },
|
{ /* "-ef"*/ FILEQ , BINOP },
|
||||||
{ "!" , UNOT , BUNOP },
|
{ /* "!" */ UNOT , BUNOP },
|
||||||
{ "-a" , BAND , BBINOP },
|
{ /* "-a" */ BAND , BBINOP },
|
||||||
{ "-o" , BOR , BBINOP },
|
{ /* "-o" */ BOR , BBINOP },
|
||||||
{ "(" , LPAREN , PAREN },
|
{ /* "(" */ LPAREN , PAREN },
|
||||||
{ ")" , RPAREN , PAREN },
|
{ /* ")" */ RPAREN , PAREN },
|
||||||
};
|
};
|
||||||
|
/* Please keep these two tables in sync */
|
||||||
|
static const char ops_texts[] ALIGN1 =
|
||||||
|
"-r" "\0"
|
||||||
|
"-w" "\0"
|
||||||
|
"-x" "\0"
|
||||||
|
"-e" "\0"
|
||||||
|
"-f" "\0"
|
||||||
|
"-d" "\0"
|
||||||
|
"-c" "\0"
|
||||||
|
"-b" "\0"
|
||||||
|
"-p" "\0"
|
||||||
|
"-u" "\0"
|
||||||
|
"-g" "\0"
|
||||||
|
"-k" "\0"
|
||||||
|
"-s" "\0"
|
||||||
|
"-t" "\0"
|
||||||
|
"-z" "\0"
|
||||||
|
"-n" "\0"
|
||||||
|
"-h" "\0"
|
||||||
|
|
||||||
|
"-O" "\0"
|
||||||
|
"-G" "\0"
|
||||||
|
"-L" "\0"
|
||||||
|
"-S" "\0"
|
||||||
|
"=" "\0"
|
||||||
|
"==" "\0"
|
||||||
|
"!=" "\0"
|
||||||
|
"<" "\0"
|
||||||
|
">" "\0"
|
||||||
|
"-eq" "\0"
|
||||||
|
"-ne" "\0"
|
||||||
|
"-ge" "\0"
|
||||||
|
"-gt" "\0"
|
||||||
|
"-le" "\0"
|
||||||
|
"-lt" "\0"
|
||||||
|
"-nt" "\0"
|
||||||
|
"-ot" "\0"
|
||||||
|
"-ef" "\0"
|
||||||
|
"!" "\0"
|
||||||
|
"-a" "\0"
|
||||||
|
"-o" "\0"
|
||||||
|
"(" "\0"
|
||||||
|
")" "\0"
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_FEATURE_TEST_64
|
#if ENABLE_FEATURE_TEST_64
|
||||||
@ -384,29 +427,22 @@ static int equalf(const char *f1, const char *f2)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static enum token check_operator(char *s)
|
static enum token check_operator(const char *s)
|
||||||
{
|
{
|
||||||
static const struct operator_t no_op = {
|
static const struct operator_t no_op = {
|
||||||
.op_num = -1,
|
.op_num = -1,
|
||||||
.op_type = -1
|
.op_type = -1
|
||||||
};
|
};
|
||||||
const struct operator_t *op;
|
int n;
|
||||||
|
|
||||||
last_operator = &no_op;
|
last_operator = &no_op;
|
||||||
if (s == NULL) {
|
if (s == NULL)
|
||||||
return EOI;
|
return EOI;
|
||||||
}
|
n = index_in_strings(ops_texts, s);
|
||||||
|
if (n < 0)
|
||||||
op = ops;
|
return OPERAND;
|
||||||
do {
|
last_operator = &ops_table[n];
|
||||||
if (strcmp(s, op->op_text) == 0) {
|
return ops_table[n].op_num;
|
||||||
last_operator = op;
|
|
||||||
return op->op_num;
|
|
||||||
}
|
|
||||||
op++;
|
|
||||||
} while (op < ops + ARRAY_SIZE(ops));
|
|
||||||
|
|
||||||
return OPERAND;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -422,7 +458,7 @@ static int binop(void)
|
|||||||
|
|
||||||
opnd2 = *++args;
|
opnd2 = *++args;
|
||||||
if (opnd2 == NULL)
|
if (opnd2 == NULL)
|
||||||
syntax(op->op_text, "argument expected");
|
syntax(args[-1], "argument expected");
|
||||||
|
|
||||||
if (is_int_op(op->op_num)) {
|
if (is_int_op(op->op_num)) {
|
||||||
val1 = getn(opnd1);
|
val1 = getn(opnd1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user