From 06574409465598d5e28d4f675a915830dd2c9d57 Mon Sep 17 00:00:00 2001 From: Charles Levert Date: Tue, 21 Jun 2005 05:18:44 +0000 Subject: * src/grep.c (main): Add a test to check if -o/--only-matching and context lines are both specified and if so, set both context specifications (before and after) to zero then print an explicit warning to stderr explaining what was done and why (as opposed to drastically aborting the process in error). Patch #3768. Other code needs this zero setting to work correctly without having to repeatedly test for this conflictual condition. --- ChangeLog | 8 ++++++++ src/grep.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index c3ced5d2..436d3e34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,14 @@ right after a line boundary. This will be used later to fix --byte-offset's broken behavior. Patch #3769. + * src/grep.c (main): Add a test to check if -o/--only-matching + and context lines are both specified and if so, set both context + specifications (before and after) to zero then print an explicit + warning to stderr explaining what was done and why (as opposed + to drastically aborting the process in error). Patch #3768. + Other code needs this zero setting to work correctly without + having to repeatedly test for this conflictual condition. + 2005-06-20 Charles Levert * src/grep.c: Extensively document the SGR/EL-to-Right issue. diff --git a/src/grep.c b/src/grep.c index e5152bc1..c4ee5bc8 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1799,6 +1799,14 @@ main (int argc, char **argv) out_after = default_context; if (out_before < 0) out_before = default_context; + if (only_matching && (out_after > 0 || out_before > 0)) + { + fprintf(stderr, + _("%s: Any context line specification " + "is ignored with -o/--only-matching.\n"), + program_name); + out_after = out_before = 0; + } if (color_option) { -- cgit v1.2.1