grep-commit
[Top][All Lists]
Advanced

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

Changes to grep/src/grep.c


From: Charles Levert
Subject: Changes to grep/src/grep.c
Date: Wed, 24 Aug 2005 03:28:30 -0400

Index: grep/src/grep.c
diff -u grep/src/grep.c:1.112 grep/src/grep.c:1.113
--- grep/src/grep.c:1.112       Thu Jul  7 05:32:30 2005
+++ grep/src/grep.c     Wed Aug 24 07:28:29 2005
@@ -753,6 +753,7 @@
 {
   size_t match_size;
   size_t match_offset;
+  const char *mid = NULL;
   char *buf;           /* XXX */
   const char *ibeg;    /* XXX */
 
@@ -784,21 +785,35 @@
 
       /* Avoid hanging on grep --color "" foo */
       if (match_size == 0)
-       break;
-
-      if (only_matching)
-       print_line_head(b, lim, SEP_CHAR_MATCH);
+       {
+         /* 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
        {
-         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 @@
 
   if (only_matching)
     beg = lim;
+  else if (mid)
+    beg = mid;
 
   return beg;
 }




reply via email to

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