From owner-svn-src-user@FreeBSD.ORG Sun Sep 11 21:17:55 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4D9D106564A; Sun, 11 Sep 2011 21:17:55 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BC1828FC0C; Sun, 11 Sep 2011 21:17:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p8BLHtxG096313; Sun, 11 Sep 2011 21:17:55 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p8BLHtOt096309; Sun, 11 Sep 2011 21:17:55 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201109112117.p8BLHtOt096309@svn.freebsd.org> From: Gabor Kovesdan Date: Sun, 11 Sep 2011 21:17:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225493 - user/gabor/grep/trunk X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Sep 2011 21:17:56 -0000 Author: gabor Date: Sun Sep 11 21:17:55 2011 New Revision: 225493 URL: http://svn.freebsd.org/changeset/base/225493 Log: - Partly fix context after maximum count of matches. GNU grep does not include further matching lines in the context so the behavior is still not totally the same. Reported by: aakuusta@gmail.com Modified: user/gabor/grep/trunk/grep.c user/gabor/grep/trunk/grep.h user/gabor/grep/trunk/util.c Modified: user/gabor/grep/trunk/grep.c ============================================================================== --- user/gabor/grep/trunk/grep.c Sun Sep 11 20:38:33 2011 (r225492) +++ user/gabor/grep/trunk/grep.c Sun Sep 11 21:17:55 2011 (r225493) @@ -106,7 +106,7 @@ bool hflag; /* -h: don't print filenam 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 */ -unsigned long long mcount; /* count for -m */ +long long mcount; /* count 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) */ @@ -521,8 +521,8 @@ main(int argc, char *argv[]) case 'm': mflag = true; errno = 0; - mcount = strtoull(optarg, &ep, 10); - if (((errno == ERANGE) && (mcount == ULLONG_MAX)) || + mcount = strtoll(optarg, &ep, 10); + if (((errno == ERANGE) && (mcount == LLONG_MAX)) || ((errno == EINVAL) && (mcount == 0))) err(2, NULL); else if (ep[0] != '\0') { Modified: user/gabor/grep/trunk/grep.h ============================================================================== --- user/gabor/grep/trunk/grep.h Sun Sep 11 20:38:33 2011 (r225492) +++ user/gabor/grep/trunk/grep.h Sun Sep 11 21:17:55 2011 (r225493) @@ -113,7 +113,8 @@ extern bool Eflag, Fflag, Gflag, Hflag, bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag, qflag, sflag, vflag, wflag, xflag; extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag; -extern unsigned long long Aflag, Bflag, mcount; +extern unsigned long long Aflag, Bflag; +extern long long mcount; extern char *label; extern const char *color; extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave; Modified: user/gabor/grep/trunk/util.c ============================================================================== --- user/gabor/grep/trunk/util.c Sun Sep 11 20:38:33 2011 (r225492) +++ user/gabor/grep/trunk/util.c Sun Sep 11 21:17:55 2011 (r225493) @@ -233,13 +233,8 @@ procfile(const char *fn) linesqueued++; } c += t; - - /* Count the matches if we have a match limit */ - if (mflag) { - mcount -= t; - if (mcount <= 0) - break; - } + if (mflag && mcount < 0) + break; } if (Bflag > 0) clearqueue(); @@ -348,6 +343,11 @@ procline(struct str *l, int nottext) break; /* No matches */ } + + /* Count the matches if we have a match limit */ + if (mflag) + mcount -= c; + if (c && binbehave == BINFILE_BIN && nottext) return (c); /* Binary file */