help.autocorrect: do not run a command if the command given is junk
[gitweb.git] / grep.c
diff --git a/grep.c b/grep.c
index c47785a2f0df79fd5ee8bc77a165fb0be3811091..bdadf2c0ccfafc18011beee3bc05754860392523 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -41,6 +41,7 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
        int err;
 
        p->word_regexp = opt->word_regexp;
+       p->ignore_case = opt->ignore_case;
 
        if (opt->fixed || is_fixed(p->pattern))
                p->fixed = 1;
@@ -262,9 +263,15 @@ static void show_name(struct grep_opt *opt, const char *name)
        printf("%s%c", name, opt->null_following_name ? '\0' : '\n');
 }
 
-static int fixmatch(const char *pattern, char *line, regmatch_t *match)
+
+static int fixmatch(const char *pattern, char *line, int ignore_case, regmatch_t *match)
 {
-       char *hit = strstr(line, pattern);
+       char *hit;
+       if (ignore_case)
+               hit = strcasestr(line, pattern);
+       else
+               hit = strstr(line, pattern);
+
        if (!hit) {
                match->rm_so = match->rm_eo = -1;
                return REG_NOMATCH;
@@ -326,7 +333,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
 
  again:
        if (p->fixed)
-               hit = !fixmatch(p->pattern, bol, pmatch);
+               hit = !fixmatch(p->pattern, bol, p->ignore_case, pmatch);
        else
                hit = !regexec(&p->regexp, bol, 1, pmatch, eflags);
 
@@ -491,18 +498,14 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
 {
        int rest = eol - bol;
 
-       if (opt->pre_context || opt->post_context || opt->funcname) {
+       if (opt->pre_context || opt->post_context) {
                if (opt->last_shown == 0) {
                        if (opt->show_hunk_mark)
-                               fputs(opt->funcname ? "==\n" : "--\n", stdout);
+                               fputs("--\n", stdout);
                        else
                                opt->show_hunk_mark = 1;
-               } else if (lno > opt->last_shown + 1) {
-                       if (opt->pre_context || opt->post_context)
-                               fputs((sign == '=') ? "==\n" : "--\n", stdout);
-                       else if (sign == '=')
-                               fputs("==\n", stdout);
-               }
+               } else if (lno > opt->last_shown + 1)
+                       fputs("--\n", stdout);
        }
        opt->last_shown = lno;