[Midnightbsd-cvs] src [8715] trunk/usr.bin/grep: make bsdgrep behave as gnugrep for -m
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Sep 25 18:23:06 EDT 2016
Revision: 8715
http://svnweb.midnightbsd.org/src/?rev=8715
Author: laffer1
Date: 2016-09-25 18:23:06 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
make bsdgrep behave as gnugrep for -m
Modified Paths:
--------------
trunk/usr.bin/grep/grep.c
trunk/usr.bin/grep/grep.h
trunk/usr.bin/grep/util.c
Modified: trunk/usr.bin/grep/grep.c
===================================================================
--- trunk/usr.bin/grep/grep.c 2016-09-25 22:22:33 UTC (rev 8714)
+++ trunk/usr.bin/grep/grep.c 2016-09-25 22:23:06 UTC (rev 8715)
@@ -107,6 +107,7 @@
bool lflag; /* -l: only show names of files with matches */
bool mflag; /* -m x: stop reading the files after x matches */
long long mcount; /* count for -m */
+long long mlimit; /* requested value for -m */
bool nflag; /* -n: show line numbers in front of matching lines */
bool oflag; /* -o: print only matching part */
bool qflag; /* -q: quiet mode (don't output anything) */
@@ -529,7 +530,7 @@
case 'm':
mflag = true;
errno = 0;
- mcount = strtoll(optarg, &ep, 10);
+ mlimit = mcount = strtoll(optarg, &ep, 10);
if (((errno == ERANGE) && (mcount == LLONG_MAX)) ||
((errno == EINVAL) && (mcount == 0)))
err(2, NULL);
Modified: trunk/usr.bin/grep/grep.h
===================================================================
--- trunk/usr.bin/grep/grep.h 2016-09-25 22:22:33 UTC (rev 8714)
+++ trunk/usr.bin/grep/grep.h 2016-09-25 22:23:06 UTC (rev 8715)
@@ -115,6 +115,7 @@
extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
extern unsigned long long Aflag, Bflag;
extern long long mcount;
+extern long long mlimit;
extern char *label;
extern const char *color;
extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
Modified: trunk/usr.bin/grep/util.c
===================================================================
--- trunk/usr.bin/grep/util.c 2016-09-25 22:22:33 UTC (rev 8714)
+++ trunk/usr.bin/grep/util.c 2016-09-25 22:23:06 UTC (rev 8715)
@@ -176,8 +176,7 @@
mode_t s;
int c, t;
- if (mflag && (mcount <= 0))
- return (0);
+ mcount = mlimit;
if (strcmp(fn, "-") == 0) {
fn = label != NULL ? label : getstr(1);
More information about the Midnightbsd-cvs
mailing list