bug-coreutils
[Top][All Lists]
Advanced

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

fix for "tr xy -z" bug mentioned by Glenn Fowler


From: Paul Eggert
Subject: fix for "tr xy -z" bug mentioned by Glenn Fowler
Date: Wed, 08 Sep 2004 18:21:19 -0700

I installed this patch to fix the bug recently mentioned by Glenn
Fowler, and also to document the argument-reordering properties of GNU
coreutils a bit better.

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

        * NEWS: Document that "tr xy -z" now works as per POSIX.
        Sort the descriptions of the changes by program name.
        * doc/coreutils.texi (Common options): Some programs don't reorder
        options.
        (tr invocation, echo invocation, printf invocation, test invocation,
        expr invocation, basename invocation, chroot invocation,
        nice invocation, nohup invocation, seq invocation):
        This program doesn't reorder options.
        (tr invocation): Mention --help, --version, --.
        (echo invocation): Mention that -- isn't special.
        (test invocation): Mention that the expression is optional,
        and that test ! EXPR is like ! test EXPR.
        (expr invocation): Mention --help, --version.
        * src/tr.c (main): Don't reorder options.
        * tests/tr/Test.pm (fowler-1): New test case.

Index: NEWS
===================================================================
RCS file: /home/eggert/coreutils/cu/NEWS,v
retrieving revision 1.232
diff -p -u -r1.232 NEWS
--- NEWS        7 Sep 2004 06:22:13 -0000       1.232
+++ NEWS        9 Sep 2004 00:27:11 -0000
@@ -4,13 +4,6 @@ GNU coreutils NEWS                      
 
 ** Bug fixes
 
-  rm (without -f) no longer hangs when attempting to remove a symlink
-  to a file on an off-line NFS-mounted partition.
-
-  cut's --output-delimiter=D option works with abutting byte ranges.
-
-  rm no longer gets a failed assertion under some unusual conditions.
-
   Several fixes to chgrp and chown for compatibility with POSIX and BSD:
 
     Do not affect symbolic links by default.
@@ -39,24 +32,26 @@ GNU coreutils NEWS                      
     recursively-encountered symbolic link cannot be updated because
     the file system does not support it.
 
-  md5sum and sha1sum now report an error when given so many input
-  lines that their line counter overflows, instead of silently
-  reporting incorrect results.
+  cut's --output-delimiter=D option works with abutting byte ranges.
 
-  rm no longer requires read access to the current directory.
+  echo now conforms to POSIX better.  It supports the \0ooo syntax for
+  octal escapes, and \c now terminates printing immediately.  If
+  POSIXLY_CORRECT is set and the first argument is not "-n", echo now
+  outputs all option-like arguments instead of treating them as options.
 
-  "sort -o -" now writes to a file named "-" instead of to standard
-  output; POSIX requires this.
+  expand and unexpand now conform to POSIX better.  They check for
+  blanks (which can include characters other than space and tab in
+  non-POSIX locales) instead of spaces and tabs.  Unexpand now
+  preserves some blanks instead of converting them to tabs or spaces.
 
-  tail -f no longer mishandles pipes and fifos.  With no operands,
-  tail now ignores -f if standard input is a pipe, as POSIX requires.
+  "ln x d/" now reports an error if d/x is a directory and x a file,
+  instead of incorrectly creating a link to d/x/x.
 
-  For some types of errors (e.g., read-only file system, I/O error)
-  when first encountering a directory, `rm -r' would mistakenly fail
-  to remove files under that directory.
+  ls no longer segfaults on systems for which SIZE_MAX != (size_t) -1.
 
-  If d/x is a directory and x a file, "ln x d/" now reports an error
-  instead of incorrectly creating a link to d/x/x.
+  md5sum and sha1sum now report an error when given so many input
+  lines that their line counter overflows, instead of silently
+  reporting incorrect results.
 
   Fixes for "nice":
 
@@ -71,25 +66,6 @@ GNU coreutils NEWS                      
     It now consistently adjusts out-of-range nice values to the
     closest values in range; formerly it sometimes reported an error.
 
-  ptx now diagnoses invalid values for its --width=N (-w)
-  and --gap-size=N (-g) options.
-
-  tee now exits when it gets a SIGPIPE signal, as POSIX requires.
-  To get tee's old behavior, use the shell command "(trap '' PIPE; tee)".
-  Also, "tee -" now writes to standard output instead of to a file named "-".
-
-  ls no longer segfaults on systems for which SIZE_MAX != (size_t) -1
-
-  echo now conforms to POSIX better.  It supports the \0ooo syntax for
-  octal escapes, and \c now terminates printing immediately.  If
-  POSIXLY_CORRECT is set and the first argument is not "-n", echo now
-  outputs all option-like arguments instead of treating them as options.
-
-  expand and unexpand now conform to POSIX better.  They check for
-  blanks (which can include characters other than space and tab in
-  non-POSIX locales) instead of spaces and tabs.  Unexpand now
-  preserves some blanks instead of converting them to tabs or spaces.
-
   printf has several changes:
 
     It now uses 'intmax_t' (not 'long int') to format integers, so it
@@ -103,8 +79,34 @@ GNU coreutils NEWS                      
     like %#d, instead of relying on undefined behavior in the underlying
     printf function.
 
+  ptx now diagnoses invalid values for its --width=N (-w)
+  and --gap-size=N (-g) options.
+
+  rm (without -f) no longer hangs when attempting to remove a symlink
+  to a file on an off-line NFS-mounted partition.
+
+  rm no longer gets a failed assertion under some unusual conditions.
+
+  rm no longer requires read access to the current directory.
+
+  "rm -r" would mistakenly fail to remove files under a directory
+  for some types of errors (e.g., read-only file system, I/O error)
+  when first encountering the directory.
+
+  "sort -o -" now writes to a file named "-" instead of to standard
+  output; POSIX requires this.
+
+  "tail -f" no longer mishandles pipes and fifos.  With no operands,
+  tail now ignores -f if standard input is a pipe, as POSIX requires.
+
+  tee now exits when it gets a SIGPIPE signal, as POSIX requires.
+  To get tee's old behavior, use the shell command "(trap '' PIPE; tee)".
+  Also, "tee -" now writes to standard output instead of to a file named "-".
+
   "touch -- MMDDhhmm[yy] file" is now equivalent to
   "touch MMDDhhmm[yy] file" even when conforming to pre-2001 POSIX.
+
+  tr no longer mishandles a second operand with leading "-".
 
   who now prints user names in full instead of truncating them after 8 bytes.
 
Index: doc/coreutils.texi
===================================================================
RCS file: /home/eggert/coreutils/cu/doc/coreutils.texi,v
retrieving revision 1.206
diff -p -u -r1.206 coreutils.texi
--- doc/coreutils.texi  8 Sep 2004 19:29:18 -0000       1.206
+++ doc/coreutils.texi  9 Sep 2004 00:19:03 -0000
@@ -600,6 +600,13 @@ as if all the options appear before any 
 @env{POSIXLY_CORRECT} environment variable is set, options must appear
 before operands, unless otherwise specified for a particular command.
 
+A few programs can usefully have trailing operands with leading
address@hidden  With such a program, options must precede operands even if
address@hidden is not set, and this fact is noted in the
+program description.  For example, the @command{env} command's options
+must appear before its operands, since in some cases the operands
+specify a command that itself contains options.
+
 Some of these programs recognize the @option{--help} and @option{--version}
 options only when one of them is the sole command line argument.
 
@@ -4749,6 +4756,9 @@ This distinction will matter only when s
 and this is possible only in locales using multibyte encodings when
 the input contains encoding errors.
 
+The program accepts the @option{--help} and @option{--version}
+options.  @xref{Common options}.  Options must precede operands.
+
 @exitstatus
 
 @menu
@@ -5060,6 +5070,12 @@ of characters:
 tr -d axM-
 @end example
 
+Or you can use @samp{--} to terminate option processing:
+
address@hidden
+tr -d -- -axM
address@hidden example
+
 More generally, use the character class notation @code{[=c=]}
 with @samp{-} (or any other character) in place of the @samp{c}:
 
@@ -9052,6 +9068,9 @@ echo address@hidden@dots{} address@hidden
 @end example
 
 The program accepts the following options.  Also see @ref{Common options}.
+Options must precede operands, and the normally-special argument
address@hidden has no special meaning and is treated like any other
address@hidden
 
 @table @samp
 @item -n
@@ -9217,6 +9236,7 @@ use of @samp{\u} and @samp{\U} will give
 
 The only options are a lone @option{--help} or
 @option{--version}.  @xref{Common options}.
+Options must precede operands.
 
 The Unicode character syntaxes are useful for writing strings in a locale
 independent way.  For example, a string containing the Euro currency symbol
@@ -9378,14 +9398,22 @@ not have the desired effect.  Since @sam
 @var{expr} ]} have the same meaning, only the former form is discussed
 below.
 
+Synopses:
+
address@hidden
+test address@hidden
+[ address@hidden ]
address@hidden example
+
 @cindex conflicts with shell built-ins
 @cindex built-in shell commands, conflicts with
 Because most shells have a built-in command by the same name, using the
 unadorned command name in a script or interactively may get you
 different functionality than that described here.
 
-Besides the options below, a single argument is also allowed:
address@hidden returns true if the argument is not null.  The argument
+If @var{expression} is omitted, @command{test} returns false.
+If @var{expression} is a single argument,
address@hidden returns false if the argument is null and true otherwise.  The 
argument
 can be any string, including strings like @samp{-d}, @samp{-1},
 @samp{--}, @samp{--help}, and @samp{--version} that most other
 programs would treat as options.  To get help and version information,
@@ -9712,6 +9740,9 @@ may be used for grouping in the usual ma
 parentheses and many operators to avoid the shell evaluating them,
 however.
 
+The only options are @option{--help} and @option{--version}.  @xref{Common
+options}.  Options must precede operands.
+
 @cindex exit status of @command{expr}
 Exit status:
 
@@ -10028,7 +10059,7 @@ it is removed from @var{name} as well.  
 result on standard output.
 
 The only options are @option{--help} and @option{--version}.  @xref{Common
-options}.
+options}.  Options must precede operands.
 
 @exitstatus
 
@@ -11961,7 +11992,7 @@ specified, the default is the value of t
 variable or @command{/bin/sh} if not set, invoked with the @option{-i} option.
 
 The only options are @option{--help} and @option{--version}.  @xref{Common
-options}.
+options}.  Options must precede operands.
 
 Here are a few tips to help avoid common problems in using chroot.
 To start with a simple example, make @var{command} refer to a statically
@@ -12035,6 +12066,7 @@ specifications, the resulting environmen
 specifying a command name of @command{printenv}.
 
 The program accepts the following options.  Also see @ref{Common options}.
+Options must precede operands.
 
 @table @samp
 
@@ -12104,6 +12136,7 @@ unadorned command name in a script or in
 different functionality than that described here.
 
 The program accepts the following option.  Also see @ref{Common options}.
+Options must precede operands.
 
 @table @samp
 @item -n @var{adjustment}
@@ -12222,7 +12255,7 @@ scheduling priority of @var{command}; us
 e.g., @samp{nohup nice @var{command}}.
 
 The only options are @option{--help} and @option{--version}.  @xref{Common
-options}.
+options}.  Options must precede operands.
 
 @cindex exit status of @command{nohup}
 Exit status:
@@ -12691,6 +12724,7 @@ Floating-point numbers
 may be specified (using a period before any fractional digits).
 
 The program accepts the following options.  Also see @ref{Common options}.
+Options must precede operands.
 
 @table @samp
 @item -f @var{format}
Index: src/tr.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/tr.c,v
retrieving revision 1.137
diff -p -u -r1.137 tr.c
--- src/tr.c    30 Jul 2004 21:08:48 -0000      1.137
+++ src/tr.c    8 Sep 2004 17:56:55 -0000
@@ -1681,7 +1681,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((c = getopt_long (argc, argv, "cCdst", long_options, NULL)) != -1)
+  while ((c = getopt_long (argc, argv, "+cCdst", long_options, NULL)) != -1)
     {
       switch (c)
        {
Index: tests/tr/Test.pm
===================================================================
RCS file: /home/eggert/coreutils/cu/tests/tr/Test.pm,v
retrieving revision 1.11
diff -p -u -r1.11 Test.pm
--- tests/tr/Test.pm    2 Jun 2004 08:50:42 -0000       1.11
+++ tests/tr/Test.pm    8 Sep 2004 17:51:21 -0000
@@ -112,6 +112,9 @@ my @tv = (
 ['repeat-compl', '-c ' . q|'[a*65536]\n' '[b*]'|, 'abcd', 'abbb', 0],
 ['repeat-Compl', '-C ' . q|'[a*65536]\n' '[b*]'|, 'abcd', 'abbb', 0],
 
+# From Glenn Fowler.
+['fowler-1', q|ah -H|, 'aha', '-H-', 0],
+
 );
 
 sub test_vector




reply via email to

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