@@ -356,18 +356,6 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,
356
356
die ("%s'%s': %s" , where , p -> pattern , error );
357
357
}
358
358
359
- static int is_fixed (const char * s , size_t len )
360
- {
361
- size_t i ;
362
-
363
- for (i = 0 ; i < len ; i ++ ) {
364
- if (is_regex_special (s [i ]))
365
- return 0 ;
366
- }
367
-
368
- return 1 ;
369
- }
370
-
371
359
#ifdef USE_LIBPCRE1
372
360
static void compile_pcre1_regexp (struct grep_pat * p , const struct grep_opt * opt )
373
361
{
@@ -643,38 +631,12 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
643
631
644
632
p -> word_regexp = opt -> word_regexp ;
645
633
p -> ignore_case = opt -> ignore_case ;
634
+ p -> fixed = opt -> fixed ;
646
635
647
636
if (memchr (p -> pattern , 0 , p -> patternlen ) && !opt -> pcre2 )
648
637
die (_ ("given pattern contains NULL byte (via -f <file>). This is only supported with -P under PCRE v2" ));
649
638
650
- /*
651
- * Even when -F (fixed) asks us to do a non-regexp search, we
652
- * may not be able to correctly case-fold when -i
653
- * (ignore-case) is asked (in which case, we'll synthesize a
654
- * regexp to match the pattern that matches regexp special
655
- * characters literally, while ignoring case differences). On
656
- * the other hand, even without -F, if the pattern does not
657
- * have any regexp special characters and there is no need for
658
- * case-folding search, we can internally turn it into a
659
- * simple string match using kws. p->fixed tells us if we
660
- * want to use kws.
661
- */
662
- if (opt -> fixed || is_fixed (p -> pattern , p -> patternlen ))
663
- p -> fixed = !p -> ignore_case || !has_non_ascii (p -> pattern );
664
-
665
- if (p -> fixed ) {
666
- p -> kws = kwsalloc (p -> ignore_case ? tolower_trans_tbl : NULL );
667
- kwsincr (p -> kws , p -> pattern , p -> patternlen );
668
- kwsprep (p -> kws );
669
- return ;
670
- }
671
-
672
639
if (opt -> fixed ) {
673
- /*
674
- * We come here when the pattern has the non-ascii
675
- * characters we cannot case-fold, and asked to
676
- * ignore-case.
677
- */
678
640
compile_fixed_regexp (p , opt );
679
641
return ;
680
642
}
@@ -1042,9 +1004,7 @@ void free_grep_patterns(struct grep_opt *opt)
1042
1004
case GREP_PATTERN : /* atom */
1043
1005
case GREP_PATTERN_HEAD :
1044
1006
case GREP_PATTERN_BODY :
1045
- if (p -> kws )
1046
- kwsfree (p -> kws );
1047
- else if (p -> pcre1_regexp )
1007
+ if (p -> pcre1_regexp )
1048
1008
free_pcre1_regexp (p );
1049
1009
else if (p -> pcre2_pattern )
1050
1010
free_pcre2_pattern (p );
@@ -1104,29 +1064,12 @@ static void show_name(struct grep_opt *opt, const char *name)
1104
1064
opt -> output (opt , opt -> null_following_name ? "\0" : "\n" , 1 );
1105
1065
}
1106
1066
1107
- static int fixmatch (struct grep_pat * p , char * line , char * eol ,
1108
- regmatch_t * match )
1109
- {
1110
- struct kwsmatch kwsm ;
1111
- size_t offset = kwsexec (p -> kws , line , eol - line , & kwsm );
1112
- if (offset == -1 ) {
1113
- match -> rm_so = match -> rm_eo = -1 ;
1114
- return REG_NOMATCH ;
1115
- } else {
1116
- match -> rm_so = offset ;
1117
- match -> rm_eo = match -> rm_so + kwsm .size [0 ];
1118
- return 0 ;
1119
- }
1120
- }
1121
-
1122
1067
static int patmatch (struct grep_pat * p , char * line , char * eol ,
1123
1068
regmatch_t * match , int eflags )
1124
1069
{
1125
1070
int hit ;
1126
1071
1127
- if (p -> fixed )
1128
- hit = !fixmatch (p , line , eol , match );
1129
- else if (p -> pcre1_regexp )
1072
+ if (p -> pcre1_regexp )
1130
1073
hit = !pcre1match (p , line , eol , match , eflags );
1131
1074
else if (p -> pcre2_pattern )
1132
1075
hit = !pcre2match (p , line , eol , match , eflags );
0 commit comments