summaryrefslogtreecommitdiff
path: root/src/test.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-06 06:12:20 +0000
committerJim Meyering <jim@meyering.net>2003-07-06 06:12:20 +0000
commit05731b47170a04cb54be605b037ffd712fdd8a3f (patch)
treeb24f92ce5aa2ec98205c33f3401839cd2713d80c /src/test.c
parent138fd919b8039c219fd5bca4f99bcfe65d3e69e0 (diff)
downloadcoreutils-05731b47170a04cb54be605b037ffd712fdd8a3f.tar.xz
Add support for a "[" that conforms to the GNU coding standards,
i.e., that does not depend on its name. (LBRACKET): Define to 0 if not defined. (main): Use LBRACKET rather than argv[0]. ---------- (one_argument): Do not check for -t if POSIXLY_CORRECT. (main): Do not recognize --help or --version if POSIXLY_CORRECT, when invoked as "test". Handle "[ ]" correctly. Do not bother testing that margv[margc] is non-null.
Diffstat (limited to 'src/test.c')
-rw-r--r--src/test.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/test.c b/src/test.c
index 631b4af1b..1fec21f8d 100644
--- a/src/test.c
+++ b/src/test.c
@@ -32,6 +32,10 @@
#define TEST_STANDALONE 1
+#ifndef LBRACKET
+# define LBRACKET 0
+#endif
+
#include "system.h"
#include "error.h"
#include "euidaccess.h"
@@ -859,7 +863,7 @@ unop (int op)
static int
one_argument (const char *s)
{
- if (STREQ (s, "-t"))
+ if (! getenv ("POSIXLY_CORRECT") && STREQ (s, "-t"))
return (TRUE == (isatty (1)));
return strlen (s) != 0;
@@ -1082,32 +1086,26 @@ main (int margc, char **margv)
atexit (close_stdout);
#endif /* TEST_STANDALONE */
- argv = margv;
+ /* Recognize --help or --version unless POSIXLY_CORRECT is set. */
+ if (! getenv ("POSIXLY_CORRECT"))
+ parse_long_options (margc, margv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+ AUTHORS, usage);
- if (margv[0] && strcmp (margv[0], "[") == 0)
+ if (LBRACKET)
{
- /* Don't recognize --help or --version if POSIXLY_CORRECT is set. */
- if (getenv ("POSIXLY_CORRECT") == NULL)
- parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
- AUTHORS, usage);
-
--margc;
- if (margc < 2)
- test_exit (SHELL_BOOLEAN (FALSE));
-
- if (margv[margc] && strcmp (margv[margc], "]") != 0)
+ if (margc < 1 || strcmp (margv[margc], "]") != 0)
test_syntax_error (_("missing `]'\n"), NULL);
}
+ argv = margv;
argc = margc;
pos = 1;
if (pos >= argc)
test_exit (SHELL_BOOLEAN (FALSE));
- parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
- AUTHORS, usage);
value = posixtest ();
if (pos != argc)