Blame SOURCES/pcre-8.33-RC1-Fix-pcregrep-so-that-it-can-find-empty-lines.patch

1e2217
From 038a52f90a30d93c5688a882620bfd392f386076 Mon Sep 17 00:00:00 2001
1e2217
From: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
1e2217
Date: Fri, 10 May 2013 11:40:06 +0000
1e2217
Subject: [PATCH] Fix pcregrep so that it can find empty lines.
1e2217
1e2217
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1324 2f5784b3-3f2a-0410-8824-cb99058d5e15
1e2217
1e2217
Petr Pisar: Ported to 8.33-RC1.
1e2217
1e2217
diff --git a/RunGrepTest b/RunGrepTest
1e2217
index 94fd808..daaf8af 100755
1e2217
--- a/RunGrepTest
1e2217
+++ b/RunGrepTest
1e2217
@@ -486,6 +486,22 @@ echo "---------------------------- Test 101 ------------------------------" >>te
1e2217
 (cd $srcdir; $valgrind $pcregrep -o3 -Ho2 -o12 --only-matching=1 -o3 --colour=always --om-separator='|' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtry
1e2217
 echo "RC=$?" >>testtry
1e2217
 
1e2217
+echo "---------------------------- Test 102 -----------------------------" >>testtry
1e2217
+(cd $srcdir; $valgrind $pcregrep -n "^$" ./testdata/grepinput3) >>testtry 2>&1
1e2217
+echo "RC=$?" >>testtry
1e2217
+
1e2217
+echo "---------------------------- Test 103 -----------------------------" >>testtry
1e2217
+(cd $srcdir; $valgrind $pcregrep --only-matching "^$" ./testdata/grepinput3) >>testtry 2>&1
1e2217
+echo "RC=$?" >>testtry
1e2217
+
1e2217
+echo "---------------------------- Test 104 -----------------------------" >>testtry
1e2217
+(cd $srcdir; $valgrind $pcregrep -n --only-matching "^$" ./testdata/grepinput3) >>testtry 2>&1
1e2217
+echo "RC=$?" >>testtry
1e2217
+
1e2217
+echo "---------------------------- Test 105 -----------------------------" >>testtry
1e2217
+(cd $srcdir; $valgrind $pcregrep --colour=always "ipsum|" ./testdata/grepinput3) >>testtry 2>&1
1e2217
+echo "RC=$?" >>testtry
1e2217
+
1e2217
 
1e2217
 # Now compare the results.
1e2217
 
1e2217
diff --git a/pcregrep.c b/pcregrep.c
1e2217
index 2e0dc03..1d20733 100644
1e2217
--- a/pcregrep.c
1e2217
+++ b/pcregrep.c
1e2217
@@ -1378,6 +1378,7 @@ to find all possible matches.
1e2217
 Arguments:
1e2217
   matchptr     the start of the subject
1e2217
   length       the length of the subject to match
1e2217
+  options      options for pcre_exec 
1e2217
   startoffset  where to start matching
1e2217
   offsets      the offets vector to fill in
1e2217
   mrc          address of where to put the result of pcre_exec()
1e2217
@@ -1388,8 +1389,8 @@ Returns:      TRUE if there was a match
1e2217
 */
1e2217
 
1e2217
 static BOOL
1e2217
-match_patterns(char *matchptr, size_t length, int startoffset, int *offsets,
1e2217
-  int *mrc)
1e2217
+match_patterns(char *matchptr, size_t length, unsigned int options, 
1e2217
+  int startoffset, int *offsets, int *mrc)
1e2217
 {
1e2217
 int i;
1e2217
 size_t slen = length;
1e2217
@@ -1404,7 +1405,7 @@ if (slen > 200)
1e2217
 for (i = 1; p != NULL; p = p->next, i++)
1e2217
   {
1e2217
   *mrc = pcre_exec(p->compiled, p->hint, matchptr, (int)length,
1e2217
-    startoffset, PCRE_NOTEMPTY, offsets, OFFSET_SIZE);
1e2217
+    startoffset, options, offsets, OFFSET_SIZE);
1e2217
   if (*mrc >= 0) return TRUE;
1e2217
   if (*mrc == PCRE_ERROR_NOMATCH) continue;
1e2217
   fprintf(stderr, "pcregrep: pcre_exec() gave error %d while matching ", *mrc);
1e2217
@@ -1539,6 +1540,7 @@ while (ptr < endptr)
1e2217
   int endlinelength;
1e2217
   int mrc = 0;
1e2217
   int startoffset = 0;
1e2217
+  unsigned int options = 0; 
1e2217
   BOOL match;
1e2217
   char *matchptr = ptr;
1e2217
   char *t = ptr;
1e2217
@@ -1628,9 +1630,12 @@ while (ptr < endptr)
1e2217
 
1e2217
   /* Run through all the patterns until one matches or there is an error other
1e2217
   than NOMATCH. This code is in a subroutine so that it can be re-used for
1e2217
-  finding subsequent matches when colouring matched lines. */
1e2217
+  finding subsequent matches when colouring matched lines. After finding one 
1e2217
+  match, set PCRE_NOTEMPTY to disable any further matches of null strings in 
1e2217
+  this line. */
1e2217
 
1e2217
-  match = match_patterns(matchptr, length, startoffset, offsets, &mrc);
1e2217
+  match = match_patterns(matchptr, length, options, startoffset, offsets, &mrc);
1e2217
+  options = PCRE_NOTEMPTY;
1e2217
 
1e2217
   /* If it's a match or a not-match (as required), do what's wanted. */
1e2217
 
1e2217
@@ -1871,7 +1876,8 @@ while (ptr < endptr)
1e2217
           {
1e2217
           startoffset = offsets[1];
1e2217
           if (startoffset >= (int)linelength + endlinelength ||
1e2217
-              !match_patterns(matchptr, length, startoffset, offsets, &mrc))
1e2217
+              !match_patterns(matchptr, length, options, startoffset, offsets,
1e2217
+                &mrc))
1e2217
             break;
1e2217
           FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout);
1e2217
           fprintf(stdout, "%c[%sm", 0x1b, colour_string);
1e2217
diff --git a/testdata/grepoutput b/testdata/grepoutput
1e2217
index 733b9d6..cf04091 100644
1e2217
--- a/testdata/grepoutput
1e2217
+++ b/testdata/grepoutput
1e2217
@@ -705,3 +705,38 @@ RC=0
1e2217
 ./testdata/grepinput:?[1;31mzero?[00m|?[1;31ma?[00m
1e2217
 ./testdata/grepinput:?[1;31m.?[00m|?[1;31mzero?[00m|?[1;31mthe?[00m|?[1;31m.?[00m
1e2217
 RC=0
1e2217
+---------------------------- Test 102 -----------------------------
1e2217
+2:
1e2217
+5:
1e2217
+7:
1e2217
+9:
1e2217
+12:
1e2217
+14:
1e2217
+RC=0
1e2217
+---------------------------- Test 103 -----------------------------
1e2217
+RC=0
1e2217
+---------------------------- Test 104 -----------------------------
1e2217
+2:
1e2217
+5:
1e2217
+7:
1e2217
+9:
1e2217
+12:
1e2217
+14:
1e2217
+RC=0
1e2217
+---------------------------- Test 105 -----------------------------
1e2217
+?[1;31m?[00mtriple:	t1_txt	s1_tag	s_txt	p_tag	p_txt	o_tag	o_txt
1e2217
+?[1;31m?[00m
1e2217
+?[1;31m?[00mtriple:	t2_txt	s1_tag	s_txt	p_tag	p_txt	o_tag	
1e2217
+?[1;31m?[00mLorem ?[1;31mipsum?[00m dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
1e2217
+?[1;31m?[00m
1e2217
+?[1;31m?[00mtriple:	t3_txt	s2_tag	s_txt	p_tag	p_txt	o_tag	o_txt
1e2217
+?[1;31m?[00m
1e2217
+?[1;31m?[00mtriple:	t4_txt	s1_tag	s_txt	p_tag	p_txt	o_tag	o_txt
1e2217
+?[1;31m?[00m
1e2217
+?[1;31m?[00mtriple:	t5_txt	s1_tag	s_txt	p_tag	p_txt	o_tag	
1e2217
+?[1;31m?[00mo_txt
1e2217
+?[1;31m?[00m
1e2217
+?[1;31m?[00mtriple:	t6_txt	s2_tag	s_txt	p_tag	p_txt	o_tag	o_txt
1e2217
+?[1;31m?[00m
1e2217
+?[1;31m?[00mtriple:	t7_txt	s1_tag	s_txt	p_tag	p_txt	o_tag	o_txt
1e2217
+RC=0
1e2217
-- 
1e2217
1.8.1.4
1e2217