aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index a4033a40b..2cbe7ea91 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -404,7 +404,7 @@ static int grep_file(FILE *file)
404#endif 404#endif
405 ) { 405 ) {
406 if (option_mask32 & OPT_x) { 406 if (option_mask32 & OPT_x) {
407 found = (gl->matched_range.rm_so == 0 407 found |= (gl->matched_range.rm_so == 0
408 && match_at[gl->matched_range.rm_eo] == '\0'); 408 && match_at[gl->matched_range.rm_eo] == '\0');
409 } else 409 } else
410 if (!(option_mask32 & OPT_w)) { 410 if (!(option_mask32 & OPT_w)) {
@@ -443,15 +443,23 @@ static int grep_file(FILE *file)
443 } 443 }
444 } 444 }
445 } 445 }
446 /* If it's non-inverted search, we can stop 446 /* If it's a non-inverted search, we can stop
447 * at first match */ 447 * at first match and report it.
448 if (found && !invert_search) 448 * If it's an inverted search, we can move on
449 goto do_found; 449 * to the next line of input, ignoring the
450 * rest of the patterns.
451 */
452 if (found) {
453 //if (invert_search)
454 // goto do_not_found;
455 //goto do_found;
456 break; // this accomplishes both
457 }
450 pattern_ptr = pattern_ptr->link; 458 pattern_ptr = pattern_ptr->link;
451 } /* while (pattern_ptr) */ 459 } /* while (pattern_ptr) */
452 460
453 if (found ^ invert_search) { 461 if (found ^ invert_search) {
454 do_found: 462 //do_found:
455 /* keep track of matches */ 463 /* keep track of matches */
456 nmatches++; 464 nmatches++;
457 465
@@ -552,6 +560,7 @@ static int grep_file(FILE *file)
552 } 560 }
553#if ENABLE_FEATURE_GREP_CONTEXT 561#if ENABLE_FEATURE_GREP_CONTEXT
554 else { /* no match */ 562 else { /* no match */
563 //do_not_found:
555 /* if we need to print some context lines after the last match, do so */ 564 /* if we need to print some context lines after the last match, do so */
556 if (print_n_lines_after) { 565 if (print_n_lines_after) {
557 print_line(line, strlen(line), linenum, '-'); 566 print_line(line, strlen(line), linenum, '-');