From owner-svn-src-head@freebsd.org Fri May 5 17:35:06 2017 Return-Path: Delivered-To: svn-src-head@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 7A687D5F0CB; Fri, 5 May 2017 17:35:06 +0000 (UTC) (envelope-from emaste@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 5590F1A9E; Fri, 5 May 2017 17:35:06 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v45HZ5Nx073407; Fri, 5 May 2017 17:35:05 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v45HZ5W0073405; Fri, 5 May 2017 17:35:05 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201705051735.v45HZ5W0073405@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Fri, 5 May 2017 17:35:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r317842 - in head: contrib/netbsd-tests/usr.bin/grep 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.23 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: Fri, 05 May 2017 17:35:06 -0000 Author: emaste Date: Fri May 5 17:35:05 2017 New Revision: 317842 URL: https://svnweb.freebsd.org/changeset/base/317842 Log: bsdgrep: don't ouptut matches with -c, -l, -L Refactoring done in r317703 broke -c, -l, and -L flags implying suppression of match printing. Fortunately this is just a matter of not doing any printing of the resulting matches and context printing was not broken in this refactoring. Add some regression tests since this area may still see further refactoring, include different context flags as well even though they were not broken in this case. PR: 219077 Submitted by: Kyle kevans91@ksu.edu Reported by: markj Reviewed by: cem, ngie Differential Revision: https://reviews.freebsd.org/D10607 Modified: head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh head/usr.bin/grep/util.c Modified: head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh ============================================================================== --- head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh Fri May 5 17:28:49 2017 (r317841) +++ head/contrib/netbsd-tests/usr.bin/grep/t_grep.sh Fri May 5 17:35:05 2017 (r317842) @@ -494,6 +494,34 @@ wv_combo_break_body() atf_check -s exit:1 grep -v -w "x" test1 atf_check -s exit:1 grep -v -w "x" test2 } + +atf_test_case grep_nomatch_flags +grep_nomatch_flags_head() +{ + atf_set "descr" "Check for no match (-c, -l, -L, -q) flags not producing line matches or context (PR 219077)" +} + +grep_nomatch_flags_body() +{ + printf "A\nB\nC\n" > test1 + + atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1 + atf_check -o inline:"1\n" grep -c -B 1 -e "B" test1 + atf_check -o inline:"1\n" grep -c -A 1 -e "B" test1 + atf_check -o inline:"1\n" grep -c -C 1 -e "B" test1 + + atf_check -o inline:"test1\n" grep -l -e "B" test1 + atf_check -o inline:"test1\n" grep -l -B 1 -e "B" test1 + atf_check -o inline:"test1\n" grep -l -A 1 -e "B" test1 + atf_check -o inline:"test1\n" grep -l -C 1 -e "B" test1 + + atf_check -s exit:1 -o inline:"test1\n" grep -L -e "D" test1 + + atf_check -o empty grep -q -e "B" test1 + atf_check -o empty grep -q -B 1 -e "B" test1 + atf_check -o empty grep -q -A 1 -e "B" test1 + atf_check -o empty grep -q -C 1 -e "B" test1 +} # End FreeBSD atf_init_test_cases() @@ -527,5 +555,6 @@ atf_init_test_cases() atf_add_test_case fgrep_sanity atf_add_test_case egrep_sanity atf_add_test_case grep_sanity + atf_add_test_case grep_nomatch_flags # End FreeBSD } Modified: head/usr.bin/grep/util.c ============================================================================== --- head/usr.bin/grep/util.c Fri May 5 17:28:49 2017 (r317841) +++ head/usr.bin/grep/util.c Fri May 5 17:35:05 2017 (r317842) @@ -201,7 +201,7 @@ procfile(const char *fn) struct str *ln; mode_t s; int c, last_outed, t, tail; - bool doctx, same_file; + bool doctx, printmatch, same_file; if (strcmp(fn, "-") == 0) { fn = label != NULL ? label : getstr(1); @@ -237,12 +237,14 @@ procfile(const char *fn) last_outed = 0; same_file = false; doctx = false; - if ((!pc.binary || binbehave != BINFILE_BIN) && !cflag && !qflag && - !lflag && !Lflag && (Aflag != 0 || Bflag != 0)) + printmatch = true; + if ((pc.binary && binbehave == BINFILE_BIN) || cflag || qflag || + lflag || Lflag) + printmatch = false; + if (printmatch && (Aflag != 0 || Bflag != 0)) doctx = true; mcount = mlimit; - for (c = 0; c == 0 || !(lflag || qflag); ) { /* Reset match count for every line processed */ pc.matchidx = 0; @@ -283,7 +285,7 @@ procfile(const char *fn) tail = Aflag; } /* Print the matching line, but only if not quiet/binary */ - if (t == 0 && !qflag && !pc.binary) { + if (t == 0 && printmatch) { printline(&pc, ':'); first_match = false; same_file = true;