[Pcre-svn] [585] code/trunk: Fix pcregrep bug when --colour …

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [585] code/trunk: Fix pcregrep bug when --colour was used with -v.
Revision: 585
          http://vcs.pcre.org/viewvc?view=rev&revision=585
Author:   ph10
Date:     2011-01-12 17:21:11 +0000 (Wed, 12 Jan 2011)


Log Message:
-----------
Fix pcregrep bug when --colour was used with -v.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/RunGrepTest
    code/trunk/pcregrep.c
    code/trunk/testdata/grepoutput


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2011-01-12 11:41:55 UTC (rev 584)
+++ code/trunk/ChangeLog    2011-01-12 17:21:11 UTC (rev 585)
@@ -11,6 +11,11 @@
     --match-limit and --recursion-limit options (added for 8.11). In
     particular, this made one of the standard tests crash. (The integer value 
     went into the wrong half of a long int.)
+    
+3.  If the --colour option was given to pcregrep with -v (invert match), it
+    did strange things, either producing crazy output, or crashing. It should,
+    of course, ignore a request for colour when reporting lines that do not 
+    match. 



Version 8.11 10-Dec-2010

Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest    2011-01-12 11:41:55 UTC (rev 584)
+++ code/trunk/RunGrepTest    2011-01-12 17:21:11 UTC (rev 585)
@@ -10,19 +10,24 @@


pcregrep=`pwd`/pcregrep

-echo " "
-echo "Testing pcregrep"
-$pcregrep -V
-
 valgrind=
 while [ $# -gt 0 ] ; do
   case $1 in
     valgrind) valgrind="valgrind -q --leak-check=no";;
-    *) echo "Unknown argument $1"; exit 1;;
+    *) echo "RunGrepTest: Unknown argument $1"; exit 1;;
   esac
   shift
 done


+echo " "
+if [ "$valgrind" = "" ] ; then
+ echo "Testing pcregrep"
+else
+ echo "Testing pcregrep using valgrind"
+fi
+
+$pcregrep -V
+
cf="diff -ub"

# Set up a suitable "diff" command for comparison. Some systems have a diff
@@ -327,6 +332,10 @@
(cd $srcdir; $valgrind $pcregrep --only-matching=2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtry
echo "RC=$?" >>testtry

+echo "---------------------------- Test 69 -----------------------------" >>testtry
+(cd $srcdir; $valgrind $pcregrep -vn --colour=always pattern ./testdata/grepinputx) >>testtry
+echo "RC=$?" >>testtry
+
# Now compare the results.

$cf $srcdir/testdata/grepoutput testtry

Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c    2011-01-12 11:41:55 UTC (rev 584)
+++ code/trunk/pcregrep.c    2011-01-12 17:21:11 UTC (rev 585)
@@ -1355,9 +1355,9 @@
 #endif


       /* We have to split the line(s) up if colouring, and search for further
-      matches. */
+      matches, but not of course if the line is a non-match. */


-      if (do_colour)
+      if (do_colour && !invert)
         {
         int last_offset = 0;
         FWRITE(ptr, 1, offsets[0], stdout);


Modified: code/trunk/testdata/grepoutput
===================================================================
--- code/trunk/testdata/grepoutput    2011-01-12 11:41:55 UTC (rev 584)
+++ code/trunk/testdata/grepoutput    2011-01-12 17:21:11 UTC (rev 585)
@@ -538,3 +538,46 @@
 ---------------------------- Test 68 ------------------------------
 pear
 RC=0
+---------------------------- Test 69 -----------------------------
+1:This is a second file of input for the pcregrep tests.
+2:
+4:
+5:Pattern
+6:That time it was on a line by itself.
+7:
+8:To pat or not to pat, that is the question.
+9:
+10:complete pair
+11:of lines
+12:
+13:That was a complete pair
+14:of lines all by themselves.
+15:
+16:complete pair
+17:of lines
+18:
+19:And there they were again, to check line numbers.
+20:
+21:one
+22:two
+23:three
+24:four
+25:five
+26:six
+27:seven
+28:eight
+29:nine
+30:ten
+31:eleven
+32:twelve
+33:thirteen
+34:fourteen
+35:fifteen
+36:sixteen
+37:seventeen
+38:eighteen
+39:nineteen
+40:twenty
+41:
+43:This is the last line of this file.
+RC=0