Make -q override -l and -q in pcre2grep for compatibility with other greps.

This commit is contained in:
Philip.Hazel 2015-08-05 17:35:36 +00:00
parent 4003ae5911
commit 537f8b1a3d
4 changed files with 23 additions and 8 deletions

View File

@ -105,6 +105,9 @@ fuzzer.
27. Fixed an issue when \p{Any} inside an xclass did not read the current 27. Fixed an issue when \p{Any} inside an xclass did not read the current
character. 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 Version 10.20 30-June-2015
-------------------------- --------------------------

View File

@ -530,6 +530,14 @@ echo "aaaaa" >>testtemp1grep
(cd $srcdir; $valgrind $pcre2grep --line-offsets '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1 (cd $srcdir; $valgrind $pcre2grep --line-offsets '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1
echo "RC=$?" >>testtrygrep 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. # Now compare the results.
$cf $srcdir/testdata/grepoutput testtrygrep $cf $srcdir/testdata/grepoutput testtrygrep

View File

@ -1691,9 +1691,13 @@ while (ptr < endptr)
if (filenames == FN_NOMATCH_ONLY) return 1; 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. */ /* 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" /* 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 variable will be set true (it's false in all other cases). In this
@ -1705,8 +1709,8 @@ while (ptr < endptr)
return 0; return 0;
} }
/* If all we want is a file name, there is no need to scan any more lines /* Likewise, if all we want is a file name, there is no need to scan any
in the file. */ more lines in the file. */
else if (filenames == FN_MATCH_ONLY) else if (filenames == FN_MATCH_ONLY)
{ {
@ -1714,10 +1718,6 @@ while (ptr < endptr)
return 0; 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, /* 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 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 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 */ /* Print the match count if wanted */
if (count_only) if (count_only && !quiet)
{ {
if (count > 0 || !omit_zero_count) if (count > 0 || !omit_zero_count)
{ {

4
testdata/grepoutput vendored
View File

@ -751,3 +751,7 @@ RC=0
2:3,1 2:3,1
2:4,1 2:4,1
RC=0 RC=0
---------------------------- Test 108 ------------------------------
RC=0
---------------------------- Test 109 -----------------------------
RC=0