It seems that done_on_match and exit_on_match flags don't work for invert.
This patch to fix it.

Norihiro
From 2fd4c98e2d3386ccea693616734813a2b3c95779 Mon Sep 17 00:00:00 2001
From: Norihiro Tanaka <[email protected]>
Date: Wed, 7 May 2014 17:55:45 +0900
Subject: [PATCH] grep: done on match for -L, -l or -q with invert

* src/grep.c (grepbuf, grep): Do it.
---
 src/grep.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index a661fc0..9db74d6 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1131,8 +1131,12 @@ grepbuf (char const *beg, char const *lim)
           prtext (p, b, &n);
           nlines += n;
           outleft -= n;
-          if (!outleft)
-            return nlines;
+          if (!outleft || done_on_match)
+            {
+              if (exit_on_match)
+                exit (EXIT_SUCCESS);
+              return nlines;
+            }
         }
       p = endp;
     }
@@ -1141,6 +1145,8 @@ grepbuf (char const *beg, char const *lim)
       prtext (p, lim, &n);
       nlines += n;
       outleft -= n;
+      if (exit_on_match)
+        exit (EXIT_SUCCESS);
     }
   return nlines;
 }
@@ -1219,8 +1225,7 @@ grep (int fd, struct stat const *st)
             nlines += grepbuf (beg, lim);
           if (pending)
             prpending (lim);
-          if ((!outleft && !pending)
-              || (nlines && done_on_match && !out_invert))
+          if ((!outleft && !pending) || (nlines && done_on_match))
             goto finish_grep;
         }
 
-- 
1.9.2

Reply via email to