HomeFreeBSD

MFC r318574: bsdgrep: Correct per-line line metadata printing

Description

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
  1. With -o, bsdgrep did not print metadata for every match/line, just the first match of a line
  1. 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)

Details

Provenance
kevansAuthored on
Parents
rS322609: MFC r318571: bsdgrep: emit more than MAX_LINE_MATCHES per line
Branches
Unknown
Tags
Unknown