summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Levert <charles_levert@gna.org>2005-06-21 05:18:44 +0000
committerCharles Levert <charles_levert@gna.org>2005-06-21 05:18:44 +0000
commit06574409465598d5e28d4f675a915830dd2c9d57 (patch)
treefeabfc2568333895bf64549d3f8563f8987228ea
parent6efca6e7e7e973ac8941c8694cb956efc9764164 (diff)
downloadgrep-06574409465598d5e28d4f675a915830dd2c9d57.tar.gz
* 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.
-rw-r--r--ChangeLog8
-rw-r--r--src/grep.c8
2 files changed, 16 insertions, 0 deletions
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 <charles_levert@gna.org>
* 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)
{