]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC r318574: bsdgrep: Correct per-line line metadata printing
authorkevans <kevans@FreeBSD.org>
Thu, 17 Aug 2017 04:30:31 +0000 (04:30 +0000)
committerkevans <kevans@FreeBSD.org>
Thu, 17 Aug 2017 04:30:31 +0000 (04:30 +0000)
commitf72c265f72c7bd726e998cb0bbafccf79a64ec11
tree909b3d3402a2834ffb5c1c81875c63393c2fd63b
parent49a5aa9d0aecb47b9456d5141c14fba723f7eb74
MFC r318574: bsdgrep: Correct per-line line metadata printing

Metadata printing with -b, -H, or -n flags suffered from a few flaws:

1) -b/offset printing was broken when used in conjunction with -o

2) With -o, bsdgrep did not print metadata for every match/line, just
   the first match of a line

3) There were no tests for this

Address these issues by outputting this data per-match if the -o flag is
specified, and prior to outputting any matches if -o but not --color,
since --color alone will not generate a new line of output for every
iteration over the matches.

To correct -b output, fudge the line offset as we're printing matches.

While here, make sure we're using grep_printline in -A context.  Context
printing should *never* look at the parsing context, just the line.

The tests included do not pass with gnugrep in base due to it exhibiting
similar quirky behavior that bsdgrep previously exhibited.

Approved by: emaste (mentor, blanket MFC)
contrib/netbsd-tests/usr.bin/grep/t_grep.sh
usr.bin/grep/grep.h
usr.bin/grep/queue.c
usr.bin/grep/util.c