From owner-svn-src-stable-11@freebsd.org Wed Aug 16 01:03:05 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 86C23DDA8B7; Wed, 16 Aug 2017 01:03:05 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 61CA867E3E; Wed, 16 Aug 2017 01:03:05 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7G134O9046028; Wed, 16 Aug 2017 01:03:04 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7G134AS046027; Wed, 16 Aug 2017 01:03:04 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201708160103.v7G134AS046027@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 16 Aug 2017 01:03:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r322562 - stable/11/usr.bin/grep X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/usr.bin/grep X-SVN-Commit-Revision: 322562 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Aug 2017 01:03:05 -0000 Author: kevans Date: Wed Aug 16 01:03:04 2017 New Revision: 322562 URL: https://svnweb.freebsd.org/changeset/base/322562 Log: MFC r317051: bsdgrep: remove output separators between overlapping segments Make bsdgrep more sensitive to context overlaps. If it's printing context that either overlaps or is immediately adjacent to another bit of context, don't print a separator. - Non-overlapping segments no longer have two separators between them - Overlapping segments no longer have separators between them with overlapping sections repeated Approved by: emaste (mentor, blanket MFC) Modified: stable/11/usr.bin/grep/util.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/grep/util.c ============================================================================== --- stable/11/usr.bin/grep/util.c Wed Aug 16 00:55:56 2017 (r322561) +++ stable/11/usr.bin/grep/util.c Wed Aug 16 01:03:04 2017 (r322562) @@ -55,6 +55,9 @@ __FBSDID("$FreeBSD$"); static int linesqueued; static int procline(struct str *l, int); +static int lasta; +static bool ctxover; + bool file_matching(const char *fname) { @@ -204,8 +207,10 @@ procfile(const char *fn) strcpy(ln.file, fn); ln.line_no = 0; ln.len = 0; + ctxover = false; linesqueued = 0; tail = 0; + lasta = 0; ln.off = -1; for (c = 0; c == 0 || !(lflag || qflag); ) { @@ -227,10 +232,24 @@ procfile(const char *fn) free(f); return (0); } - /* Process the file line-by-line */ + + /* Process the file line-by-line, enqueue non-matching lines */ if ((t = procline(&ln, f->binary)) == 0 && Bflag > 0) { - enqueue(&ln); - linesqueued++; + /* Except don't enqueue lines that appear in -A ctx */ + if (ln.line_no == 0 || lasta != ln.line_no) { + /* queue is maxed to Bflag number of lines */ + enqueue(&ln); + linesqueued++; + ctxover = false; + } else { + /* + * Indicate to procline() that we have ctx + * overlap and make sure queue is empty. + */ + if (!ctxover) + clearqueue(); + ctxover = true; + } } c += t; if (mflag && mcount <= 0) @@ -385,17 +404,19 @@ procline(struct str *l, int nottext) /* Dealing with the context */ if ((tail || c) && !cflag && !qflag && !lflag && !Lflag) { if (c) { - if (!first && !prev && !tail && Aflag) + if (!first && !prev && !tail && (Bflag || Aflag) && + !ctxover) printf("--\n"); tail = Aflag; if (Bflag > 0) { - if (!first && !prev) - printf("--\n"); printqueue(); + ctxover = false; } linesqueued = 0; printline(l, ':', matches, m); } else { + /* Print -A lines following matches */ + lasta = l->line_no; printline(l, '-', matches, m); tail--; }