Subject: bug#37907: --no-ignore-case option

From: [email-masked]
Date: Thu, 24 Oct 2019 14:40:26 -0600

Hi Karl.

See the attached patch.  Less than 10 minutes' work. :-)

Grep guys - I'm pretty sure I've signed papwerwork for grep. Feel free
to incorporate this patch.

I chose '-g' since that letter was unused. It has no mnemonic value.

Thanks,

Arnold

Karl Berry <[email-masked]> wrote:

> I suggest adding --no-ignore-case to clear the case-insensitivity -i
> search. I, and surely many others, have an alias or script that runs
> grep with -i by default, along with other options (since GREP_OPTIONS
> was killed). It would be highly convenient to be able to add
> --no-ignore-case on the fly to the rare-in-my-experience invocations
> where case sensitivity is desired.
>
> (Also, just in principle, it seems like any boolean option should be
> switchable by successive options. But I won't go that far.)
>
> Besides, since I'm not sending a patch (sorry), my expectation is that
> there will never be enough time to implement random minor suggestions
> like this, so it doesn't matter :).
>
> Thanks,
> Karl
diff --git a/doc/grep.in.1 b/doc/grep.in.1
index a2cbf5c..733647e 100644
--- a/doc/grep.in.1
+++ b/doc/grep.in.1
@@ -254,6 +254,12 @@ Ignore case distinctions in patterns and input data,
 so that characters that differ only in case
 match each other.
 .TP
+.BR \-g ", " \-\^\-no\-ignore\-case
+Don't ignore case distinctions in patterns and input data.
+This option is useful for passing to shell scripts that already use
+.BR \-i ,
+in order to cancel its effects.
+.TP
 .BR \-v ", " \-\^\-invert\-match
 Invert the sense of matching, to select non-matching lines.
 .TP
diff --git a/doc/grep.texi b/doc/grep.texi
index f5edc72..a004639 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -215,6 +215,14 @@ SHARP S) even though lowercasing the latter yields the former.
 @option{-y} is an obsolete synonym that is provided for compatibility.
 (@option{-i} is specified by POSIX.)
 
+@item -g
+@itemx --no-ignore-case
+@opindex -g
+@opindex --no-ignore-case
+Don't ignore case distinctions in patterns and input data.
+This option is useful for passing to shell scripts that already use
+@option{-i}, in order to cancel its effects.
+
 @item -v
 @itemx --invert-match
 @opindex -v
diff --git a/src/grep.c b/src/grep.c
index 6f35f26..379d9e1 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -411,7 +411,7 @@ static struct exclude *excluded_patterns[2];
 static struct exclude *excluded_directory_patterns[2];
 /* Short options.  */
 static char const short_options[] =
-"0123456789A:B:C:D:EFGHIPTUVX:abcd:e:f:hiLlm:noqRrsuvwxyZz";
+"0123456789A:B:C:D:EFGHIPTUVX:abcd:e:f:ghiLlm:noqRrsuvwxyZz";
 
 /* Non-boolean long options that have no corresponding short equivalents.  */
 enum
@@ -455,6 +455,7 @@ static struct option const long_options[] =
   {"help", no_argument, &show_help, 1},
   {"include", required_argument, NULL, INCLUDE_OPTION},
   {"ignore-case", no_argument, NULL, 'i'},
+  {"no-ignore-case", no_argument, NULL, 'g'},
   {"initial-tab", no_argument, NULL, 'T'},
   {"label", required_argument, NULL, LABEL_OPTION},
   {"line-buffered", no_argument, NULL, LINE_BUFFERED_OPTION},
@@ -2616,6 +2617,10 @@ main (int argc, char **argv)
         match_icase = true;
         break;
 
+      case 'g':
+        match_icase = false;
+        break;
+
       case 'L':
         /* Like -l, except list files that don't contain matches.
            Inspired by the same option in Hume's gre. */