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.
This commit is contained in:
Paul Eggert 2020-09-17 19:54:14 -07:00 committed by Jim Meyering
parent 0e862a91cc
commit b9f3943910
5 changed files with 15 additions and 13 deletions

12
NEWS
View File

@ -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

View File

@ -72,7 +72,6 @@ obstack
openat-safer
perl
propername
quote
rawmemchr
readme-release
realloc-gnu

View File

@ -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;
}

View File

@ -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

View File

@ -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