bsdgrep: Clean up procmatches a little bit
This commit is contained in:
parent
81c634e8d5
commit
5ea3fdc775
@ -218,8 +218,10 @@ procmatches(struct mprintc *mc, struct parsec *pc, bool matched)
|
||||
{
|
||||
|
||||
/* Deal with any -B context or context separators */
|
||||
if (matched && mc->doctx) {
|
||||
if (!first_match && (!mc->same_file || mc->last_outed > 0))
|
||||
if (matched) {
|
||||
if (mc->doctx) {
|
||||
if (!first_match &&
|
||||
(!mc->same_file || mc->last_outed > 0))
|
||||
printf("--\n");
|
||||
if (Bflag > 0)
|
||||
printqueue();
|
||||
@ -227,7 +229,7 @@ procmatches(struct mprintc *mc, struct parsec *pc, bool matched)
|
||||
}
|
||||
|
||||
/* Print the matching line, but only if not quiet/binary */
|
||||
if (matched && mc->printmatch) {
|
||||
if (mc->printmatch) {
|
||||
printline(pc, ':');
|
||||
while (pc->matchidx >= MAX_MATCHES) {
|
||||
/* Reset matchidx and try again */
|
||||
@ -242,8 +244,15 @@ procmatches(struct mprintc *mc, struct parsec *pc, bool matched)
|
||||
mc->last_outed = 0;
|
||||
}
|
||||
|
||||
if (!matched && mc->doctx) {
|
||||
/* Deal with any -A context */
|
||||
/* Count the matches if we have a match limit */
|
||||
if (mflag) {
|
||||
/* XXX TODO: Decrement by number of matched lines */
|
||||
mcount -= 1;
|
||||
if (mflag && mcount <= 0)
|
||||
return (false);
|
||||
}
|
||||
} else if (mc->doctx) {
|
||||
/* Not matching, deal with any -A context as needed */
|
||||
if (mc->tail > 0) {
|
||||
grep_printline(&pc->ln, '-');
|
||||
mc->tail--;
|
||||
@ -262,14 +271,6 @@ procmatches(struct mprintc *mc, struct parsec *pc, bool matched)
|
||||
}
|
||||
}
|
||||
|
||||
/* Count the matches if we have a match limit */
|
||||
if (matched && mflag) {
|
||||
/* XXX TODO: Decrement by number of matched lines */
|
||||
mcount -= 1;
|
||||
if (mflag && mcount <= 0)
|
||||
return (false);
|
||||
}
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user