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: Thu, 10 Nov 2005 14:57:55 -0500

Index: grep/src/grep.c
diff -u grep/src/grep.c:1.116 grep/src/grep.c:1.117
--- grep/src/grep.c:1.116       Thu Nov 10 01:19:03 2005
+++ grep/src/grep.c     Thu Nov 10 19:57:54 2005
@@ -761,6 +761,7 @@
 {
   size_t match_size;
   size_t match_offset;
+  const char *cur = beg;
   const char *mid = NULL;
   char *buf;           /* XXX */
   const char *ibeg;    /* XXX */
@@ -781,9 +782,9 @@
       ibeg = beg;
     }
 
-  while (   lim > beg
-        && (   (match_offset = execute(ibeg, lim - beg, &match_size, 1))
-            != (size_t) -1))
+  while (   lim > cur
+        && ((match_offset = execute(ibeg, lim - beg, &match_size,
+                                    ibeg + (cur - beg))) != (size_t) -1))
     {
       char const *b = beg + match_offset;
 
@@ -798,7 +799,7 @@
          /* XXX - Could really advance by one whole multi-octet character.  */
          match_size = 1;
          if (!mid)
-           mid = beg;
+           mid = cur;
        }
       else
        {
@@ -809,11 +810,10 @@
              PR_SGR_START(mlines_color);
              if (mid)
                {
-                 fwrite (mid, sizeof (char), (beg - mid) + match_offset, 
stdout);
+                 cur = mid;
                  mid = NULL;
                }
-             else
-               fwrite (beg, sizeof (char), match_offset, stdout);
+             fwrite (cur, sizeof (char), b - cur, stdout);
            }
 
          PR_SGR_START_IF(grep_color);
@@ -822,19 +822,18 @@
          if (only_matching)
            fputs("\n", stdout);
        }
-      beg = b + match_size;
-      ibeg += match_offset + match_size;       /* XXX */
+      cur = b + match_size;
     }
 
   if (buf)
     free(buf); /* XXX */
 
   if (only_matching)
-    beg = lim;
+    cur = lim;
   else if (mid)
-    beg = mid;
+    cur = mid;
 
-  return beg;
+  return cur;
 }
 
 static const char *
@@ -904,7 +903,8 @@
       size_t match_size;
       --pending;
       if (outleft
-         || ((execute(lastout, nl + 1 - lastout, &match_size, 0) == (size_t) 
-1)
+         || ((execute(lastout, nl + 1 - lastout,
+                      &match_size, NULL) == (size_t) -1)
              == !out_invert))
        prline (lastout, nl + 1, SEP_CHAR_CONTEXT);
       else
@@ -994,7 +994,8 @@
 
   nlines = 0;
   p = beg;
-  while ((match_offset = execute(p, lim - p, &match_size, 0)) != (size_t) -1)
+  while ((match_offset = execute(p, lim - p, &match_size,
+                                NULL)) != (size_t) -1)
     {
       char const *b = p + match_offset;
       char const *endp = b + match_size;




reply via email to

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