On 9/17/20 3:03 PM, Jim Meyering wrote:
The alternative is to change that "B" to a "b", which should be fine,
now that it's only emitted to stderr.

Makes sense.

NEWS should be updated accordingly - but when I looked into doing that I came up with the attached more-elaborate patch, which changes this new diagnostic and two other unusual-format diagnostics, so that they use the same "grep: FILENAME: MESSAGE" form that grep uses everywhere else. Whaddya think?
>From 28c5ff1eee695d3cfa9e72a9f07ac9380bdc4ada Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Thu, 17 Sep 2020 19:54:14 -0700
Subject: [PATCH] grep: be more consistent about diagnostic format

* NEWS: Mention this.
* bootstrap.conf (gnulib_modules): Remove 'quote'.
* src/grep.c: Do not include quote.h.
(grep, grepdirent, grepdesc): Put the three unusual diagnostics
into the same "grep: FOO: message" form that grep uses elsewhere.
* tests/binary-file-matches, tests/in-eq-out-infloop:
Adjust tests to match new diagnostic format.
---
 NEWS                      | 12 +++++++++---
 bootstrap.conf            |  1 -
 src/grep.c                |  9 +++------
 tests/binary-file-matches |  2 +-
 tests/in-eq-out-infloop   |  4 ++--
 5 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/NEWS b/NEWS
index fd08663..79b9db0 100644
--- a/NEWS
+++ b/NEWS
@@ -4,14 +4,20 @@ GNU grep NEWS                                    -*- outline -*-
 
 ** Changes in behavior
 
-  The "Binary file FOO matches" message is now sent to standard error
-  and FOO is now quoted, to avoid confusion with ordinary output and
-  when file names contain spaces and the like.  For example, commands
+  The message that a binary file matches is now sent to standard error
+  and the message has been reworded from "Binary file FOO matches" to
+  "grep: FOO: binary file matches", to avoid confusion with ordinary
+  output or when file names contain spaces and the like, and to be
+  more consistent with other diagnostics.  For example, commands
   like 'grep PATTERN FILE | wc' no longer add 1 to the count of
   matching text lines due to the presence of the message.  Like other
   stderr messages, the message is now omitted if the --no-messages
   (-s) option is given.
 
+  Two other stderr messages now use the typical form too.  They are
+  now "grep: FOO: warning: recursive directory loop" and "grep: FOO:
+  input file is also the output".
+
   The --files-without-match (-L) option has reverted to its behavior
   in grep 3.1 and earlier.  That is, grep -L again succeeds when a
   line is selected, not when a file is listed.  The behavior in grep
diff --git a/bootstrap.conf b/bootstrap.conf
index 4268623..54c0359 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -72,7 +72,6 @@ obstack
 openat-safer
 perl
 propername
-quote
 rawmemchr
 readme-release
 realloc-gnu
diff --git a/src/grep.c b/src/grep.c
index 614f203..ba6b15d 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -45,7 +45,6 @@
 #include "hash.h"
 #include "intprops.h"
 #include "propername.h"
-#include "quote.h"
 #include "safe-read.h"
 #include "search.h"
 #include "c-strcase.h"
@@ -1644,7 +1643,7 @@ grep (int fd, struct stat const *st, bool *ineof)
   if (binary_files == BINARY_BINARY_FILES && ! (out_quiet | suppress_errors)
       && (encoding_error_output
           || (0 <= nlines_first_null && nlines_first_null < nlines)))
-    error (0, 0, _("binary file %s matches"), quote (input_filename ()));
+    error (0, 0, _("%s: binary file matches"), input_filename ());
   return nlines;
 }
 
@@ -1682,8 +1681,7 @@ grepdirent (FTS *fts, FTSENT *ent, bool command_line)
 
     case FTS_DC:
       if (!suppress_errors)
-        error (0, 0, _("warning: %s: %s"), filename,
-               _("recursive directory loop"));
+        error (0, 0, _("%s: warning: recursive directory loop"), filename);
       return true;
 
     case FTS_DNR:
@@ -1903,8 +1901,7 @@ grepdesc (int desc, bool command_line)
       && S_ISREG (st.st_mode) && SAME_INODE (st, out_stat))
     {
       if (! suppress_errors)
-        error (0, 0, _("input file %s is also the output"),
-               quote (input_filename ()));
+        error (0, 0, _("%s: input file is also the output"), input_filename ());
       errseen = true;
       goto closeout;
     }
diff --git a/tests/binary-file-matches b/tests/binary-file-matches
index 75c23bc..da18f9d 100755
--- a/tests/binary-file-matches
+++ b/tests/binary-file-matches
@@ -11,7 +11,7 @@
 
 fail=0
 
-echo "grep: binary file '(standard input)' matches" > exp \
+echo "grep: (standard input): binary file matches" > exp \
   || framework_failure_
 
 printf 'a\0' | grep a > out 2> err || fail=1
diff --git a/tests/in-eq-out-infloop b/tests/in-eq-out-infloop
index c6d5968..11ba904 100755
--- a/tests/in-eq-out-infloop
+++ b/tests/in-eq-out-infloop
@@ -17,13 +17,13 @@ echo "$v" > out || framework_failure_
 for arg in out - ''; do
   # Accommodate both 'out' and '(standard input)', as well as
   # the multi-byte quoting we see on OS/X-based systems.
-  echo grep: input file ... is also the output > err.exp || framework_failure_
+  echo grep: ...: input file is also the output > err.exp || framework_failure_
 
   # Require an exit status of 2.
   # grep-2.8 and earlier would infloop with $arg = out.
   # grep-2.10 and earlier would infloop with $arg = - or $arg = ''.
   timeout 10 grep 0 $arg < out >> out 2> err; st=$?; test $st = 2 || fail=1
-  sed 's/file .* is/file ... is/' err > k && mv k err
+  sed 's/grep: .*: /grep: ...: /' err > k && mv k err
   # Normalize the diagnostic prefix from e.g., "/mnt/dir/grep: " to "grep: "
   sed 's/^[^:]*: /grep: /' err > k && mv k err
   compare err.exp err || fail=1
-- 
2.17.1

Reply via email to