Re: test -t FD vs. [FD]

2003-07-06 Thread Jim Meyering
Paul Eggert [EMAIL PROTECTED] wrote:
 [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.

Thank you!
I've applied that patch.


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


Re: test -t FD vs. [FD]

2003-06-30 Thread Paul Eggert
[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 -  1.9
+++ README  1 Jul 2003 03:37:22 -
@@ -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 -   1.16
+++ man/Makefile.am 1 Jul 2003 03:37:22 -
@@ -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 -  1.24
+++ src/Makefile.am 1 Jul 2003 03:41:59 -
@@ -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 -  1.86
+++ src/test.c  1 Jul 2003 03:42:03 -
@@ -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)
 {
-  /* 

Re: test -t FD vs. [FD]

2003-06-20 Thread Paul Eggert
Dan Jacobson [EMAIL PROTECTED] writes:

 $ man test
-t [FD]
   file descriptor FD (stdout by default) is opened on a terminal
 I.e. argument optional
 
 $ help test
 -t FD  True if FD is opened on a terminal.
 Not so optional with bash then.
 
 You guys should unify them.

POSIX long ago decided that FD is not optional with test -t.  GNU
'test' conforms to POSIX in this respect.  This means GNU 'test' is
incompatible with ancient Unix 'test', but that's life in the big
city.  The original specification had an ambiguous grammar, and POSIX
removed the ambiguity by making FD required.

Reference:
http://www.opengroup.org/onlinepubs/007904975/utilities/test.html


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


test -t FD vs. [FD]

2003-06-18 Thread Dan Jacobson
[remove emacs group when following up]

 Why does (shell-command test -ttty) get so far to tell me 'not a
 tty'!?

Paul With a single argument, test only tells you whether that arguments is
Paul empty.  You want test -t 0 (or 1 or 2).

$ man test
   -t [FD]
  file descriptor FD (stdout by default) is opened on a terminal
I.e. argument optional

$ help test
-t FD  True if FD is opened on a terminal.
Not so optional with bash then.

You guys should unify them.
 Wait, (shell-command /usr/bin/test -ttty) doesn't get that
 far, good.

Paul Looks like /usr/bin/test is buggy.


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


Re: test -t FD vs. [FD]

2003-06-18 Thread Paul Jarc
Dan Jacobson [EMAIL PROTECTED] wrote:
 Paul With a single argument, test only tells you whether that arguments is
 Paul empty.  You want test -t 0 (or 1 or 2).

 $ man test
-t [FD]
   file descriptor FD (stdout by default) is opened on a terminal
 I.e. argument optional

Making it optional is historical, but violates SUSv3.  (test --help
and test --version also violate SUSv3.)


paul


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