Revision: 336
http://www.exim.org/viewvc/pcre2?view=rev&revision=336
Author: ph10
Date: 2015-08-05 18:35:36 +0100 (Wed, 05 Aug 2015)
Log Message:
-----------
Make -q override -l and -q in pcre2grep for compatibility with other greps.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/RunGrepTest
code/trunk/src/pcre2grep.c
code/trunk/testdata/grepoutput
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2015-08-05 09:04:01 UTC (rev 335)
+++ code/trunk/ChangeLog 2015-08-05 17:35:36 UTC (rev 336)
@@ -105,7 +105,10 @@
27. Fixed an issue when \p{Any} inside an xclass did not read the current
character.
+28. If pcre2grep was given the -q option with -c or -l, or when handling a
+binary file, it incorrectly wrote output to stdout.
+
Version 10.20 30-June-2015
--------------------------
Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest 2015-08-05 09:04:01 UTC (rev 335)
+++ code/trunk/RunGrepTest 2015-08-05 17:35:36 UTC (rev 336)
@@ -530,6 +530,14 @@
(cd $srcdir; $valgrind $pcre2grep --line-offsets '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1
echo "RC=$?" >>testtrygrep
+echo "---------------------------- Test 108 ------------------------------" >>testtrygrep
+(cd $srcdir; $valgrind $pcre2grep -lq PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
+echo "RC=$?" >>testtrygrep
+
+echo "---------------------------- Test 109 -----------------------------" >>testtrygrep
+(cd $srcdir; $valgrind $pcre2grep -cq lazy ./testdata/grepinput*) >>testtrygrep
+echo "RC=$?" >>testtrygrep
+
# Now compare the results.
$cf $srcdir/testdata/grepoutput testtrygrep
Modified: code/trunk/src/pcre2grep.c
===================================================================
--- code/trunk/src/pcre2grep.c 2015-08-05 09:04:01 UTC (rev 335)
+++ code/trunk/src/pcre2grep.c 2015-08-05 17:35:36 UTC (rev 336)
@@ -1691,9 +1691,13 @@
if (filenames == FN_NOMATCH_ONLY) return 1;
+ /* If all we want is a yes/no answer, we can return immediately. */
+
+ if (quiet) return 0;
+
/* Just count if just counting is wanted. */
- if (count_only) count++;
+ else if (count_only) count++;
/* When handling a binary file and binary-files==binary, the "binary"
variable will be set true (it's false in all other cases). In this
@@ -1705,8 +1709,8 @@
return 0;
}
- /* If all we want is a file name, there is no need to scan any more lines
- in the file. */
+ /* Likewise, if all we want is a file name, there is no need to scan any
+ more lines in the file. */
else if (filenames == FN_MATCH_ONLY)
{
@@ -1714,10 +1718,6 @@
return 0;
}
- /* Likewise, if all we want is a yes/no answer. */
-
- else if (quiet) return 0;
-
/* The --only-matching option prints just the substring that matched,
and/or one or more captured portions of it, as long as these strings are
not empty. The --file-offsets and --line-offsets options output offsets for
@@ -2069,7 +2069,7 @@
/* Print the match count if wanted */
-if (count_only)
+if (count_only && !quiet)
{
if (count > 0 || !omit_zero_count)
{
Modified: code/trunk/testdata/grepoutput
===================================================================
(Binary files differ)