summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2015-08-05 17:35:36 +0000
committerph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2015-08-05 17:35:36 +0000
commita5ad98662b9a175651f445a26f71cbef1a818a7e (patch)
treea1f286d9f69883f3f37c59822aa30a09cb96bcaa
parentc7aac899c3f05257dafba2d0809e618255618c87 (diff)
downloadpcre2-a5ad98662b9a175651f445a26f71cbef1a818a7e.tar.gz
Make -q override -l and -q in pcre2grep for compatibility with other greps.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@336 6239d852-aaf2-0410-a92c-79f79f948069
-rw-r--r--ChangeLog3
-rwxr-xr-xRunGrepTest8
-rw-r--r--src/pcre2grep.c16
-rw-r--r--testdata/grepoutput4
4 files changed, 23 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 6c2548a..078aca3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -105,6 +105,9 @@ fuzzer.
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
--------------------------
diff --git a/RunGrepTest b/RunGrepTest
index f7db29e..79bf5a3 100755
--- a/RunGrepTest
+++ b/RunGrepTest
@@ -530,6 +530,14 @@ echo "aaaaa" >>testtemp1grep
(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
diff --git a/src/pcre2grep.c b/src/pcre2grep.c
index d5a5d6d..9216245 100644
--- a/src/pcre2grep.c
+++ b/src/pcre2grep.c
@@ -1691,9 +1691,13 @@ while (ptr < endptr)
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 @@ while (ptr < endptr)
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 @@ while (ptr < endptr)
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 @@ if (filenames == FN_NOMATCH_ONLY)
/* Print the match count if wanted */
-if (count_only)
+if (count_only && !quiet)
{
if (count > 0 || !omit_zero_count)
{
diff --git a/testdata/grepoutput b/testdata/grepoutput
index 883bad7..3f6704c 100644
--- a/testdata/grepoutput
+++ b/testdata/grepoutput
@@ -751,3 +751,7 @@ RC=0
2:3,1
2:4,1
RC=0
+---------------------------- Test 108 ------------------------------
+RC=0
+---------------------------- Test 109 -----------------------------
+RC=0