From owner-svn-src-head@FreeBSD.ORG Thu Dec 20 17:38:15 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 94DD2AED; Thu, 20 Dec 2012 17:38:15 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 5FA588FC12; Thu, 20 Dec 2012 17:38:15 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBKHcFcS090729; Thu, 20 Dec 2012 17:38:15 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBKHcEGZ090726; Thu, 20 Dec 2012 17:38:14 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201212201738.qBKHcEGZ090726@svn.freebsd.org> From: Eitan Adler Date: Thu, 20 Dec 2012 17:38:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244493 - head/usr.bin/grep X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Dec 2012 17:38:15 -0000 Author: eadler Date: Thu Dec 20 17:38:14 2012 New Revision: 244493 URL: http://svnweb.freebsd.org/changeset/base/244493 Log: Make bsdgrep behave as gnugrep and as documented: -m should only stop reading the specific file, not any file. Tested by: frogs (irc) Reviewed by: gabor Approved by: cperciva (implicit) MFC after: 1 week Modified: head/usr.bin/grep/grep.c head/usr.bin/grep/grep.h head/usr.bin/grep/util.c Modified: head/usr.bin/grep/grep.c ============================================================================== --- head/usr.bin/grep/grep.c Thu Dec 20 17:23:40 2012 (r244492) +++ head/usr.bin/grep/grep.c Thu Dec 20 17:38:14 2012 (r244493) @@ -108,6 +108,7 @@ bool iflag; /* -i: ignore case */ 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) */ @@ -524,7 +525,7 @@ main(int argc, char *argv[]) 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: head/usr.bin/grep/grep.h ============================================================================== --- head/usr.bin/grep/grep.h Thu Dec 20 17:23:40 2012 (r244492) +++ head/usr.bin/grep/grep.h Thu Dec 20 17:38:14 2012 (r244493) @@ -115,6 +115,7 @@ extern bool Eflag, Fflag, Gflag, Hflag, 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: head/usr.bin/grep/util.c ============================================================================== --- head/usr.bin/grep/util.c Thu Dec 20 17:23:40 2012 (r244492) +++ head/usr.bin/grep/util.c Thu Dec 20 17:38:14 2012 (r244493) @@ -176,8 +176,7 @@ procfile(const char *fn) mode_t s; int c, t; - if (mflag && (mcount <= 0)) - return (0); + mcount = mlimit; if (strcmp(fn, "-") == 0) { fn = label != NULL ? label : getstr(1);