[EMAIL PROTECTED] (Paul Jarc) writes:

> Paul Eggert <[EMAIL PROTECTED]> wrote:
> > POSIX long ago decided that FD is not optional with test -t.  GNU
> > 'test' conforms to POSIX in this respect.
> 
> bash's does, but coreutils' doesn't.

Good point.  I looked at coreutils/src/test.c and noticed some other
incompatibilities with POSIX and with the GNU coding standards.  Here
is a patch to fix them.  Even with this patch, coreutils "test"
disagrees with Bash "test" on some cases but that is a subject for a
different email.

2003-06-30  Paul Eggert  <[EMAIL PROTECTED]>

        Add support for a "[" that conforms to the GNU coding standards,
        i.e., that does not depend on its name.
        * src/lbracket.c: New file.
        * README: Add "[".
        * man/Makefile.am (programs): Ignore "[", since it doesn't have
        a separate man page.
        * src/Makefile.am (bin_PROGRAMS): Add "[".
        (__SOURCES): New var.
        * src/test.c (LBRACKET): Define to 0 if not defined.
        (main): Use LBRACKET rather than argv[0].

        * src/test.c (one_argument): Do not check for -t if POSIXLY_CORRECT.

        * src/test.c (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.

--- /dev/null   Tue Mar 18 13:55:57 2003
+++ src/lbracket.c      Mon Jun 30 16:08:27 2003
@@ -0,0 +1,2 @@
+#define LBRACKET 1
+#include "test.c"
Index: README
===================================================================
RCS file: /cvsroot/coreutils/coreutils/README,v
retrieving revision 1.9
diff -p -u -r1.9 README
--- README      16 Jun 2003 10:51:29 -0000      1.9
+++ README      1 Jul 2003 03:37:22 -0000
@@ -7,7 +7,7 @@ arbitrary limits.
 
 The programs that can be built with this package are:
 
-  basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd
+  [ basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd
   df dir dircolors dirname du echo env expand expr factor false fmt fold
   ginstall groups head hostid hostname id join kill link ln logname ls
   md5sum mkdir mkfifo mknod mv nice nl nohup od paste pathchk pinky pr
Index: man/Makefile.am
===================================================================
RCS file: /cvsroot/coreutils/coreutils/man/Makefile.am,v
retrieving revision 1.16
diff -p -u -r1.16 Makefile.am
--- man/Makefile.am     4 Jun 2003 12:22:06 -0000       1.16
+++ man/Makefile.am     1 Jul 2003 03:37:22 -0000
@@ -148,7 +148,7 @@ check-x-vs-1:
 programs =                                                             \
   echo 'spy:;@echo $$(all_programs)'                                   \
     | MAKEFLAGS= $(MAKE) -s -C $(srcdir)/../src -f Makefile -f - spy   \
-    | fmt -1 | sort -u
+    | fmt -1 | sort -u | grep -v '\['
 
 .PHONY: check-programs-vs-x
 check-programs-vs-x:
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/coreutils/coreutils/src/Makefile.am,v
retrieving revision 1.24
diff -p -u -r1.24 Makefile.am
--- src/Makefile.am     10 Apr 2003 19:11:07 -0000      1.24
+++ src/Makefile.am     1 Jul 2003 03:41:59 -0000
@@ -4,7 +4,7 @@ EXTRA_PROGRAMS = chroot df hostid nice p
 EXTRA_SCRIPTS = nohup
 
 bin_SCRIPTS = groups $(OPTIONAL_BIN_ZCRIPTS)
-bin_PROGRAMS = chgrp chown chmod cp dd dircolors du \
+bin_PROGRAMS = [ chgrp chown chmod cp dd dircolors du \
   ginstall link ln dir vdir ls mkdir \
   mkfifo mknod mv readlink rm rmdir shred stat sync touch unlink \
   cat cksum comm csplit cut expand fmt fold head join md5sum \
@@ -129,6 +129,9 @@ uninstall-local:
 
 transform = s/ginstall/install/; @program_transform_name@
 ginstall_SOURCES = install.c copy.c cp-hash.c
+
+# This is for the '[' program.  Automake transliterates '[' to '_'.
+__SOURCES = lbracket.c
 
 cp_SOURCES = cp.c copy.c cp-hash.c
 dir_SOURCES = ls.c ls-dir.c
Index: src/test.c
===================================================================
RCS file: /cvsroot/coreutils/coreutils/src/test.c,v
retrieving revision 1.86
diff -p -u -r1.86 test.c
--- src/test.c  17 Jun 2003 18:13:24 -0000      1.86
+++ src/test.c  1 Jul 2003 03:42:03 -0000
@@ -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)


_______________________________________________
Bug-coreutils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to