aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/grep.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-08-12 03:16:29 -0500
committerRob Landley <rob@landley.net>2013-08-12 03:16:29 -0500
commit030970bd70e14849b0f2598bfa0982402fc7e2e7 (patch)
tree6c9dc6c4c42c3bb254f47e493a06c285e1ff9a9d /toys/pending/grep.c
parent31f07104445bc0c0cbc942d86ee9d31d08c344d8 (diff)
downloadtoybox-030970bd70e14849b0f2598bfa0982402fc7e2e7.tar.gz
grep: -om counts matching lines, not matching parts of lines.
Diffstat (limited to 'toys/pending/grep.c')
-rw-r--r--toys/pending/grep.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/toys/pending/grep.c b/toys/pending/grep.c
index 215c6d24..9c282ea7 100644
--- a/toys/pending/grep.c
+++ b/toys/pending/grep.c
@@ -67,6 +67,7 @@ static void do_grep(int fd, char *name)
regmatch_t matches[3];
size_t unused;
long len;
+ int mmatch = 0;
lcount++;
if (0 > (len = getline(&line, &unused, file))) break;
@@ -121,7 +122,7 @@ static void do_grep(int fd, char *name)
matches[which].rm_so = 0;
} else if (rc) break;
- mcount++;
+ mmatch++;
if (toys.optflags & FLAG_q) {
toys.exitval = 0;
xexit();
@@ -152,6 +153,7 @@ static void do_grep(int fd, char *name)
free(line);
+ if (mmatch) mcount++;
if ((toys.optflags & FLAG_m) && mcount >= TT.m) break;
}