diff options
author | Jim Meyering <jim@meyering.net> | 2003-07-23 07:11:14 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-07-23 07:11:14 +0000 |
commit | b4fa822482de9eaa4b5d429881de9d145d802f5e (patch) | |
tree | a5accc3e742495209c3c4b5877c924f223687f91 /src | |
parent | e2da85e0b731442c8ad383702929bcd31cd1b2e8 (diff) | |
download | coreutils-b4fa822482de9eaa4b5d429881de9d145d802f5e.tar.xz |
Don't include headers already included by system.h:
Don't include limits.h or error.h.
Diffstat (limited to 'src')
-rw-r--r-- | src/test.c | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/test.c b/src/test.c index 7a106c311..6c9eaf0ff 100644 --- a/src/test.c +++ b/src/test.c @@ -40,7 +40,6 @@ #include "error.h" #include "euidaccess.h" -#include <limits.h> #ifndef _POSIX_VERSION # include <sys/param.h> #endif /* _POSIX_VERSION */ @@ -54,15 +53,6 @@ char *program_name; # include <sys/file.h> #endif /* !_POSIX_VERSION */ -#include <errno.h> -#ifndef errno -extern int errno; -#endif - -#if !defined (member) -# define member(c, s) ((c) ? (strchr ((s), (c)) ? 1 : 0) : 0) -#endif /* !member */ - extern gid_t getegid (); extern uid_t geteuid (); @@ -101,7 +91,7 @@ static int pos; /* The offset of the current argument in ARGV. */ static int argc; /* The number of arguments present in ARGV. */ static char **argv; /* The argument list. */ -static int unop (int op); +static int test_unop (char const *s); static int binop (char *s); static int unary_operator (void); static int binary_operator (void); @@ -312,31 +302,31 @@ term (void) if (pos >= argc) beyond (); - /* Deal with leading "not"'s. */ - if ('!' == argv[pos][0] && '\000' == argv[pos][1]) + /* Deal with leading `not's. */ + if (argv[pos][0] == '!' && argv[pos][1] == '\0') { - value = FALSE; - while (pos < argc && '!' == argv[pos][0] && '\000' == argv[pos][1]) + value = 0; + while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0') { advance (1); - value ^= (TRUE); + value = 1 - value; } - return (value ^ (term ())); + return (value ? !term() : term()); } /* A paren-bracketed argument. */ - if (argv[pos][0] == '(' && !argv[pos][1]) + if (argv[pos][0] == '(' && argv[pos][1] == '\0') { advance (1); value = expr (); - if (!argv[pos]) + if (argv[pos] == 0) test_syntax_error (_("')' expected\n"), NULL); else if (argv[pos][0] != ')' || argv[pos][1]) test_syntax_error (_("')' expected, found %s\n"), argv[pos]); advance (0); - return (TRUE == (value)); + return (value); } /* are there enough arguments left that this could be dyadic? */ @@ -345,9 +335,9 @@ term (void) value = binary_operator (); /* Might be a switch type argument */ - else if ('-' == argv[pos][0] && argv[pos][1] && 0 == argv[pos][2]) + else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0') { - if (unop (argv[pos][1])) + if (test_unop (argv[pos])) value = unary_operator (); else test_syntax_error (_("%s: unary operator expected\n"), argv[pos]); @@ -857,9 +847,22 @@ binop (char *s) /* Return nonzero if OP is one of the test command's unary operators. */ static int -unop (int op) +test_unop (char const *op) { - return (member (op, "abcdefgkLhprsStuwxOGnz")); + if (op[0] != '-') + return (0); + + switch (op[1]) + { + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'k': case 'n': + case 'o': case 'p': case 'r': case 's': case 't': + case 'u': case 'w': case 'x': case 'z': + case 'G': case 'L': case 'O': case 'S': case 'N': + return (1); + } + + return (0); } static int @@ -882,7 +885,7 @@ two_arguments (void) && argv[pos][1] != '\0' && argv[pos][2] == '\0') { - if (unop (argv[pos][1])) + if (test_unop (argv[pos])) value = unary_operator (); else test_syntax_error (_("%s: unary operator expected\n"), argv[pos]); |