Code

tests: consolidate CR removal/addition functions
[git.git] / grep.c
diff --git a/grep.c b/grep.c
index 03ffcd4042e95b521e2aed03ecf2ae6d65fef41c..8e1f7de7717da95e8954491f5205547f2091aa35 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -29,20 +29,14 @@ void append_grep_pattern(struct grep_opt *opt, const char *pat,
        p->next = NULL;
 }
 
-static int is_fixed(const char *s)
-{
-       while (*s && !is_regex_special(*s))
-               s++;
-       return !*s;
-}
-
 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))
+       if (opt->fixed)
                p->fixed = 1;
        if (opt->regflags & REG_ICASE)
                p->fixed = 0;
@@ -262,9 +256,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 +326,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);
 
@@ -639,7 +639,7 @@ static int look_ahead(struct grep_opt *opt,
                regmatch_t m;
 
                if (p->fixed)
-                       hit = !fixmatch(p->pattern, bol, &m);
+                       hit = !fixmatch(p->pattern, bol, p->ignore_case, &m);
                else
                        hit = !regexec(&p->regexp, bol, 1, &m, 0);
                if (!hit || m.rm_so < 0 || m.rm_eo < 0)