bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch: non-empty matches following empty ones


From: Charles Levert
Subject: Patch: non-empty matches following empty ones
Date: Mon, 22 Aug 2005 11:12:20 -0400
User-agent: Mutt/1.4.1i

Two tests included, which previously would have failed.
A lot of this is just re-indentation within new conditional.

Ok to apply?



Index: grep/ChangeLog
===================================================================
RCS file: /cvsroot/grep/grep/ChangeLog,v
retrieving revision 1.270
diff -p -u -r1.270 ChangeLog
--- grep/ChangeLog      27 Jul 2005 02:44:53 -0000      1.270
+++ grep/ChangeLog      22 Aug 2005 14:59:37 -0000
@@ -1,3 +1,11 @@
+2005-08-22  Charles Levert  <address@hidden>
+
+       * src/grep.c (print_line_middle): In case of an empty match,
+         make minimal progress and continue instead of aborting process
+         of the remainder of the line, in case there's still an upcoming
+         non-empty match.
+       * tests/foad1.sh: Add two tests for this.
+
 2005-07-26  Charles Levert  <address@hidden>
 
        * tests/pcre.sh: New file.  Add test 1.
Index: grep/src/grep.c
===================================================================
RCS file: /cvsroot/grep/grep/src/grep.c,v
retrieving revision 1.112
diff -p -u -r1.112 grep.c
--- grep/src/grep.c     7 Jul 2005 05:32:30 -0000       1.112
+++ grep/src/grep.c     22 Aug 2005 14:35:04 -0000
@@ -753,6 +753,7 @@ print_line_middle (const char *beg, cons
 {
   size_t match_size;
   size_t match_offset;
+  const char *mid = NULL;
   char *buf;           /* XXX */
   const char *ibeg;    /* XXX */
 
@@ -784,21 +785,35 @@ print_line_middle (const char *beg, cons
 
       /* Avoid hanging on grep --color "" foo */
       if (match_size == 0)
-       break;
+       {
+         /* Make minimal progress; there may be further non-empty matches.  */
+         /* XXX - Could really advance by one whole multi-octet character.  */
+         match_size = 1;
+         if (!mid)
+           mid = beg;
+       }
+      else
+       {
-
-      if (only_matching)
-       print_line_head(b, lim, SEP_CHAR_MATCH);
-      else
-       {
-         PR_SGR_START(mlines_color);
-         fwrite (beg, sizeof (char), match_offset, stdout);
-       }
+         if (only_matching)
+           print_line_head(b, lim, SEP_CHAR_MATCH);
+         else
+           {
+             PR_SGR_START(mlines_color);
+             if (mid)
+               {
+                 fwrite (mid, sizeof (char), (beg - mid) + match_offset, 
stdout);
+                 mid = NULL;
+               }
+             else
+               fwrite (beg, sizeof (char), match_offset, stdout);
+           }
 
+         PR_SGR_START_IF(grep_color);
+         fwrite (b, sizeof (char), match_size, stdout);
+         PR_SGR_END_IF(grep_color);
+         if (only_matching)
+           fputs("\n", stdout);
-      PR_SGR_START_IF(grep_color);
-      fwrite (b, sizeof (char), match_size, stdout);
-      PR_SGR_END_IF(grep_color);
-      if (only_matching)
-       fputs("\n", stdout);
+       }
       beg = b + match_size;
       ibeg += match_offset + match_size;       /* XXX */
     }
@@ -808,6 +823,8 @@ print_line_middle (const char *beg, cons
 
   if (only_matching)
     beg = lim;
+  else if (mid)
+    beg = mid;
 
   return beg;
 }
Index: grep/tests/foad1.sh
===================================================================
RCS file: /cvsroot/grep/grep/tests/foad1.sh,v
retrieving revision 1.11
diff -p -u -r1.11 foad1.sh
--- grep/tests/foad1.sh 23 Jun 2005 00:55:58 -0000      1.11
+++ grep/tests/foad1.sh 22 Aug 2005 14:54:33 -0000
@@ -89,6 +89,10 @@ grep_test "4/444/" "4/444/" "4$"  -m1 -A
 grep_test "A/CX/B/C/" "A/B/C/" -wF -e A -e B -e C
 grep_test "LIN7C 55327/" "" -wF -e 5327 -e 5532
 
+# Test for non-empty matches following empty ones.
+grep_test 'xyz/' 'y/' -o 'y*'
+grep_test 'xyz/' "x${CB}y${CE}z/" --color=always 'y*'
+
 
 # The rest of this file is meant to be executed under this locale.
 LC_ALL=cs_CZ.UTF-8; export LC_ALL




reply via email to

[Prev in Thread] Current Thread [Next in Thread]