zgrep: fix "binary file matches" mislabeling
commit9d3248751178939713a39115cf68ec8a11506cc9
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 5 Apr 2022 22:16:33 +0000 (5 15:16 -0700)
committerJim Meyering <meyering@fb.com>
Thu, 7 Apr 2022 16:28:24 +0000 (7 09:28 -0700)
tree08cfc5cbb2a4d97046118a0507afe4518e721fa3
parent5e1fc8b92c1af9382365aef0f9130341ee1d2c76
zgrep: fix "binary file matches" mislabeling

Problem reported by Jim Avera (Bug#31280).
This became more of an issue when GNU grep 3.5 (2020) started sending
"binary file matches" diagnostics to stderr instead of to stdout.
* tests/Makefile.am (TESTS): Add zgrep-binary.
* tests/zgrep-binary: New test.
* zgrep.in (args): New var, to accumulate args separately
from grep command, so we can prepend args if need be.
Most uses of 'grep' changed to use 'args' instead, or also.
(with_filename): Set to 1 if more than one file and -h not given;
this simplifies later code.
(gnuish_grep): New var; evaluates to true if grep supports
-H and --label options, as is true for GNU and FreeBSD grep.
Append -H to 'grep' if outputting file names with GNUish grep,
and use --label with GNUish grep unless reading from stdin,
as that’s safer and more efficient than relabeling with 'sed'.
NEWS
tests/Makefile.am
tests/zgrep-binary [new file with mode: 0755]
zgrep.in