3e2d96ac | 08-Feb-2021 |
Kyle Evans <kevans@FreeBSD.org> |
grep: fix -A handling in conjunction with -m match limitation
The basic issue here is that grep, when given -m 1, would stop all line processing once it hit the match count and exit immediately. Th
grep: fix -A handling in conjunction with -m match limitation
The basic issue here is that grep, when given -m 1, would stop all line processing once it hit the match count and exit immediately. The problem with exiting immediately is that -A processing only happens when subsequent lines are processed and do not match.
The fix here is relatively easy; when bsdgrep matches a line, it resets the 'tail' of the matching context to the value supplied to -A and dumps anything that's been queued up for -B. After the current line has been printed and tail is reset, we check our mcount and do what's needed. Therefore, at the time that we decide we're doing nothing, we know that 'tail' of the context is correct and we can simply continue on if there's still more to pick up.
With this change, we still bail out immediately if there's been no -A flag. If -A was supplied, we signal that we should continue on. However, subsequent lines will not even bothere to try and process the line. We have reached the match count, so even if the next line would match then we must process it if it hadn't. Thus, the loop in procfile() can short-circuit and just process the line as a non-match until procmatches() indicates that it's safe to stop.
A test has been added to reflect both that we should be picking up the next line and that the next line should be considered a non-match even if it should have been.
PR: 253350 MFC-after: 3 days
show more ...
|
6d635d3b | 20-May-2017 |
Ed Maste <emaste@FreeBSD.org> |
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: 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.
Submitted by: Kyle Evans <kevans91@ksu.edu> Reviewed by: cem Differential Revision: https://reviews.freebsd.org/D10580
show more ...
|
f701bdc5 | 15-May-2017 |
Ed Maste <emaste@FreeBSD.org> |
bsdgrep: add more tests for different binary flags
The existing 'binary' test in netbsd-tests/ does a basic check of the default treatment for binary behavior, but not much more than that. Given som
bsdgrep: add more tests for different binary flags
The existing 'binary' test in netbsd-tests/ does a basic check of the default treatment for binary behavior, but not much more than that. Given some opportunity for breakage recently that did not trigger any failures, add some tests to cover the three different binary file behaviors (a, -I, -U) and their --binary-files= equivalent values.
Submitted by: Kyle Evans <kevans91@ksu.edu> Reviewed by: cem, ngie Differential Revision: https://reviews.freebsd.org/D10620
show more ...
|