bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

remove some POSIXLY_CORRECT dependencies from coreutils


From: Paul Eggert
Subject: remove some POSIXLY_CORRECT dependencies from coreutils
Date: Wed, 09 Jun 2004 13:11:59 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

In a few cases, the default coreutils behavior conforms to POSIX, but
coreutils changes its behavior if POSIXLY_CORRECT is set.  Here is a
patch to remove these special cases; this lessens the effect of
POSIXLY_CORRECT on coreutils behavior.  This patch affects behavior
only when POSIXLY_CORRECT is set.

2004-06-09  Paul Eggert  <address@hidden>

        * NEWS: Remove special cases for POSIXLY_CORRECT when POSIX allows
        the GNU behavior.
        * doc/coreutils.texi (pr invocation, unlink invocation, false
        invocation, true invocation): Document this.
        * src/ls.c (decode_switches): Pay attention to TABSIZE even if
        POSIXLY_CORRECT is set.  POSIX reserves upper-case environment
        variables to the implementation, so it's OK for ls to depend on
        TABSIZE.
        * src/pr.c: Include "hard-locale.h".
        (main): When in a non-POSIX locale, ignore POSIXLY_CORRECT, since
        POSIX specifies the behavior only in the POSIX locale.
        * src/printf.c (print_esc): Support \x, \u, \U even if POSIXLY_CORRECT,
        since POSIX says the behavior is unspecified here.
        * src/tail.c (parse_obsolescent_option): Support multiple file operands
        even if POSIXLY_CORRECT, since POSIX does not require a diagnostic.
        * src/printf.c (main): Recognize --help, --version even if
        POSIXLY_CORRECT.  POSIX does not specify any options, but it
        does not prohibit options either, so "printf" is like "expr" here.
        * src/true.c (main): Likewise.
        * src/unlink.c (main): Likewise.
        * src/yes.c (main): Likewise.
        * tests/misc/printf: Adjust to the new semantics for \x if
        POSIXLY_CORRECT.

Index: NEWS
===================================================================
RCS file: /home/meyering/coreutils/cu/NEWS,v
retrieving revision 1.214
diff -p -u -r1.214 NEWS
--- NEWS        8 Jun 2004 13:23:42 -0000       1.214
+++ NEWS        9 Jun 2004 19:54:54 -0000
@@ -117,6 +117,15 @@ GNU coreutils NEWS                      
   echo -e '\xHH' now outputs a byte whose hexadecimal value is HH,
   for compatibility with bash.
 
+  In the following cases POSIX allows the default GNU behavior,
+  so when POSIXLY_CORRECT is set:
+
+    false, printf, true, unlink, and yes all support --help and --option.
+    ls supports TABSIZE.
+    pr no longer depends on LC_TIME for the date format in non-POSIX locales.
+    printf supports \u, \U, \x.
+    tail supports two or more files when using the obsolete option syntax.
+
 
 * Major changes in release 5.2.1 (2004-03-12) [stable]
 
Index: doc/coreutils.texi
===================================================================
RCS file: /home/meyering/coreutils/cu/doc/coreutils.texi,v
retrieving revision 1.187
diff -p -u -r1.187 coreutils.texi
--- doc/coreutils.texi  7 Jun 2004 08:21:07 -0000       1.187
+++ doc/coreutils.texi  9 Jun 2004 19:33:39 -0000
@@ -1952,10 +1952,11 @@ e.g., @option{--date-format="Monday morn
 
 @vindex POSIXLY_CORRECT
 @vindex LC_TIME
-If the @env{POSIXLY_CORRECT} environment variable is not set, the date
+Normally the date
 format defaults to @samp{%Y-%m-%d %H:%M} (for example, @samp{2001-12-04
-23:59}); otherwise, the format depends on the @env{LC_TIME} locale
-category, with the default being @samp{%b %e %H:%M %Y} (for example,
+23:59}); but if the @env{POSIXLY_CORRECT} environment variable is set
+and the @env{LC_TIME} locale category specifies the @acronym{POSIX}
+locale, the default is @samp{%b %e %H:%M %Y} (for example,
 @samp{Dec@ @ 4 23:59 2001}.
 
 @item address@hidden@var{in-tabwidth}]]
@@ -7768,12 +7769,9 @@ On some systems @code{unlink} can be use
 directory.  On others, it can be used that way only by a privileged user.
 In the GNU system @code{unlink} can never delete the name of a directory.
 
address@hidden POSIXLY_CORRECT
-By default, @command{unlink} honors the @option{--help} and @option{--version}
-options.  That makes it a little harder to remove files named
address@hidden and @option{--version}, so when the environment variable
address@hidden is set, @command{unlink} treats such a command line
-arguments not as an option, but as an operand.
+The @command{unlink} command honors the @option{--help} and
address@hidden options.  To remove a file whose name begins with
address@hidden, prefix the name with @samp{./}, e.g., @samp{unlink ./--help}.
 
 @exitstatus
 
@@ -9106,11 +9104,7 @@ pipeline.
 @dfn{failure}.  It can be used as a place holder in shell scripts
 where an unsuccessful command is needed.
 
address@hidden POSIXLY_CORRECT
-By default, @command{false} honors the @option{--help} and @option{--version}
-options.  However, that is contrary to @acronym{POSIX}, so when the environment
-variable @env{POSIXLY_CORRECT} is set, @command{false} ignores @emph{all}
-command line arguments, including @option{--help} and @option{--version}.
address@hidden honors the @option{--help} and @option{--version} options.
 
 This version of @command{false} is implemented as a C program, and is thus
 more secure and faster than a shell script implementation, and may safely
@@ -9138,11 +9132,7 @@ In most modern shells, @command{true} is
 you use @samp{true} in a script, you're probably using the built-in
 command, not the one documented here.
 
address@hidden POSIXLY_CORRECT
-By default, @command{true} honors the @option{--help} and @option{--version}
-options.  However, that is contrary to @acronym{POSIX}, so when the environment
-variable @env{POSIXLY_CORRECT} is set, @command{true} ignores @emph{all}
-command line arguments, including @option{--help} and @option{--version}.
address@hidden honors the @option{--help} and @option{--version} options.
 
 Note, however, that it is possible to cause @command{true}
 to exit with nonzero status: when invoked in address@hidden mode,
Index: src/ls.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/ls.c,v
retrieving revision 1.356
diff -p -u -r1.356 ls.c
--- src/ls.c    1 Jun 2004 13:36:20 -0000       1.356
+++ src/ls.c    9 Jun 2004 18:59:38 -0000
@@ -1416,12 +1416,10 @@ decode_switches (int argc, char **argv)
   }
 #endif
 
-  /* Using the TABSIZE environment variable is not POSIX-approved.
-     Ignore it when POSIXLY_CORRECT is set.  */
   {
-    char const *p;
+    char const *p = getenv ("TABSIZE");
     tabsize = 8;
-    if (!getenv ("POSIXLY_CORRECT") && (p = getenv ("TABSIZE")))
+    if (p)
       {
        unsigned long int tmp_ulong;
        if (xstrtoul (p, NULL, 0, &tmp_ulong, NULL) == LONGINT_OK
Index: src/pr.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/pr.c,v
retrieving revision 1.118
diff -p -u -r1.118 pr.c
--- src/pr.c    22 Jan 2004 19:49:47 -0000      1.118
+++ src/pr.c    9 Jun 2004 19:03:33 -0000
@@ -316,6 +316,7 @@
 #include <sys/types.h>
 #include "system.h"
 #include "error.h"
+#include "hard-locale.h"
 #include "mbswidth.h"
 #include "posixver.h"
 #include "xstrtol.h"
@@ -1074,8 +1075,8 @@ main (int argc, char **argv)
     }
 
   if (! date_format)
-    date_format = (getenv ("POSIXLY_CORRECT")
-                  ? dcgettext (NULL, "%b %e %H:%M %Y", LC_TIME)
+    date_format = (getenv ("POSIXLY_CORRECT") && !hard_locale (LC_TIME)
+                  ? "%b %e %H:%M %Y"
                   : "%Y-%m-%d %H:%M");
 
   /* Now we can set a reasonable initial value: */
Index: src/printf.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/printf.c,v
retrieving revision 1.88
diff -p -u -r1.88 printf.c
--- src/printf.c        13 May 2004 07:26:46 -0000      1.88
+++ src/printf.c        9 Jun 2004 19:09:28 -0000
@@ -241,7 +241,7 @@ print_esc (const char *escstart, bool oc
   int esc_value = 0;           /* Value of \nnn escape. */
   int esc_length;              /* Length of \nnn escape. */
 
-  if (!posixly_correct && *p == 'x')
+  if (*p == 'x')
     {
       /* A hexadecimal \xhh escape sequence must have 1 or 2 hex. digits.  */
       for (esc_length = 0, ++p;
@@ -265,7 +265,7 @@ print_esc (const char *escstart, bool oc
     }
   else if (*p && strchr ("\"\\abcfnrtv", *p))
     print_esc_char (*p++);
-  else if (!posixly_correct && (*p == 'u' || *p == 'U'))
+  else if (*p == 'u' || *p == 'U')
     {
       char esc_char = *p;
       unsigned int uni_value;
@@ -557,11 +557,10 @@ main (int argc, char **argv)
 
   exit_status = 0;
 
-  /* Don't recognize --help or --version if POSIXLY_CORRECT is set.  */
   posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
-  if (!posixly_correct)
-    parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
-                       usage, AUTHORS, (char const *) NULL);
+
+  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+                     usage, AUTHORS, (char const *) NULL);
 
   /* The above handles --help and --version.
      Since there is no other invocation of getopt, handle `--' here.  */
Index: src/tail.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/tail.c,v
retrieving revision 1.222
diff -p -u -r1.222 tail.c
--- src/tail.c  6 May 2004 14:50:17 -0000       1.222
+++ src/tail.c  9 Jun 2004 19:19:57 -0000
@@ -1462,28 +1462,6 @@ parse_obsolescent_option (int argc, cons
 
   if (!*fail)
     {
-      if (argc > 3)
-       {
-         /* When POSIXLY_CORRECT is set, enforce the `at most one
-            file argument' requirement.  */
-         if (getenv ("POSIXLY_CORRECT"))
-           {
-             error (0, 0, _("\
-too many arguments;  When using tail's obsolescent option syntax (%s)\n\
-there may be no more than one file argument.  Use the equivalent -n or -c\n\
-option instead."), argv[1]);
-             *fail = 1;
-             return 1;
-           }
-
-#if DISABLED  /* FIXME: enable or remove this warning.  */
-         error (0, 0, _("\
-Warning: it is not portable to use two or more file arguments with\n\
-tail's obsolescent option syntax (%s).  Use the equivalent -n or -c\n\
-option instead."), argv[1]);
-#endif
-       }
-
       if (! obsolete_usage)
        {
          error (0, 0, _("`%s' option is obsolete; use `%s-%c %.*s'"),
Index: src/true.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/true.c,v
retrieving revision 1.19
diff -p -u -r1.19 true.c
--- src/true.c  5 Nov 2003 03:43:30 -0000       1.19
+++ src/true.c  9 Jun 2004 19:22:50 -0000
@@ -56,8 +56,8 @@ main (int argc, char **argv)
   atexit (close_stdout);
 
   /* Recognize --help or --version only if it's the only command-line
-     argument and if POSIXLY_CORRECT is not set.  */
-  if (argc == 2 && getenv ("POSIXLY_CORRECT") == NULL)
+     argument.  */
+  if (argc == 2)
     {
       if (STREQ (argv[1], "--help"))
        usage (EXIT_SUCCESS);
Index: src/unlink.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/unlink.c,v
retrieving revision 1.11
diff -p -u -r1.11 unlink.c
--- src/unlink.c        21 Jan 2004 23:47:48 -0000      1.11
+++ src/unlink.c        9 Jun 2004 19:25:21 -0000
@@ -71,10 +71,8 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  /* 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,
-                       usage, AUTHORS, (char const *) NULL);
+  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+                     usage, AUTHORS, (char const *) NULL);
 
   /* The above handles --help and --version.
      Since there is no other invocation of getopt, handle `--' here.  */
Index: src/yes.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/yes.c,v
retrieving revision 1.53
diff -p -u -r1.53 yes.c
--- src/yes.c   21 Jan 2004 23:50:38 -0000      1.53
+++ src/yes.c   9 Jun 2004 19:25:54 -0000
@@ -71,10 +71,8 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  /* 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,
-                       usage, AUTHORS, (char const *) NULL);
+  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+                     usage, AUTHORS, (char const *) NULL);
 
   if (argc == 1)
     {
Index: tests/misc/printf
===================================================================
RCS file: /home/meyering/coreutils/cu/tests/misc/printf,v
retrieving revision 1.6
diff -p -u -r1.6 printf
--- tests/misc/printf   21 Apr 2003 16:46:56 -0000      1.6
+++ tests/misc/printf   9 Jun 2004 19:44:00 -0000
@@ -38,9 +38,14 @@ rm -f out exp
 # Until coreutils-4.5.10, this would elicit a segfault.
 $prog '1 %*sy\n' -3 x >  out || fail=1
 
+# Until coreutils 5.2.2, this would succeed.
+if POSIXLY_CORRECT=1 $prog '2 \x' >/dev/null 2>&1; then
+  fail=1
+else
+  echo '2 failed, as expected' >> out
+fi
+
 # Until coreutils-4.5.12, these would fail.
-POSIXLY_CORRECT=1 \
-$prog '2 \x'          >> out || fail=1; echo >> out
 $prog '3 \x40\n'      >> out || fail=1
 POSIXLY_CORRECT=1 \
 $prog '4 \x40\n'      >> out || fail=1
@@ -60,9 +65,9 @@ $prog '8 %b %b %b %b\n' '\1y' '\01y' '\0
 
 cat <<\EOF > exp
 1 x  y
-2 \x
+2 failed, as expected
 3 @
-4 \x40
+4 @
 5 +234
 6 !
 7 =y =y =y *2y




reply via email to

[Prev in Thread] Current Thread [Next in Thread]