summaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
Diffstat (limited to 'findutils')
-rw-r--r--findutils/grep.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index f2ed01e74..9d38ef912 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -87,7 +87,11 @@ enum {
87 87
88struct globals { 88struct globals {
89 int max_matches; 89 int max_matches;
90#if !ENABLE_EXTRA_COMPAT
90 int reflags; 91 int reflags;
92#else
93 RE_TRANSLATE_TYPE case_fold; /* RE_TRANSLATE_TYPE is [[un]signed] char* */
94#endif
91 smalluint invert_search; 95 smalluint invert_search;
92 smalluint print_filename; 96 smalluint print_filename;
93 smalluint open_errors; 97 smalluint open_errors;
@@ -110,7 +114,19 @@ struct globals {
110 }; \ 114 }; \
111} while (0) 115} while (0)
112#define max_matches (G.max_matches ) 116#define max_matches (G.max_matches )
117#if !ENABLE_EXTRA_COMPAT
113#define reflags (G.reflags ) 118#define reflags (G.reflags )
119#else
120#define case_fold (G.case_fold )
121/* http://www.delorie.com/gnu/docs/regex/regex_46.html */
122#define reflags re_syntax_options
123#undef REG_NOSUB
124#undef REG_EXTENDED
125#undef REG_ICASE
126#define REG_NOSUB bug:is:here /* should not be used */
127#define REG_EXTENDED RE_SYNTAX_EGREP
128#define REG_ICASE bug:is:here /* should not be used */
129#endif
114#define invert_search (G.invert_search ) 130#define invert_search (G.invert_search )
115#define print_filename (G.print_filename ) 131#define print_filename (G.print_filename )
116#define open_errors (G.open_errors ) 132#define open_errors (G.open_errors )
@@ -240,6 +256,7 @@ static int grep_file(FILE *file)
240 xregcomp(&gl->compiled_regex, gl->pattern, reflags); 256 xregcomp(&gl->compiled_regex, gl->pattern, reflags);
241#else 257#else
242 memset(&gl->compiled_regex, 0, sizeof(gl->compiled_regex)); 258 memset(&gl->compiled_regex, 0, sizeof(gl->compiled_regex));
259 gl->compiled_regex.translate = case_fold; /* for -i */
243 if (re_compile_pattern(gl->pattern, strlen(gl->pattern), &gl->compiled_regex)) 260 if (re_compile_pattern(gl->pattern, strlen(gl->pattern), &gl->compiled_regex))
244 bb_error_msg_and_die("bad regex '%s'", gl->pattern); 261 bb_error_msg_and_die("bad regex '%s'", gl->pattern);
245#endif 262#endif
@@ -532,17 +549,34 @@ int grep_main(int argc, char **argv)
532 if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f') 549 if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f')
533 option_mask32 |= OPT_F; 550 option_mask32 |= OPT_F;
534 551
552#if !ENABLE_EXTRA_COMPAT
535 if (!(option_mask32 & (OPT_o | OPT_w))) 553 if (!(option_mask32 & (OPT_o | OPT_w)))
536 reflags = REG_NOSUB; 554 reflags = REG_NOSUB;
555#endif
537 556
538 if (ENABLE_FEATURE_GREP_EGREP_ALIAS 557 if (ENABLE_FEATURE_GREP_EGREP_ALIAS
539 && (applet_name[0] == 'e' || (option_mask32 & OPT_E)) 558 && (applet_name[0] == 'e' || (option_mask32 & OPT_E))
540 ) { 559 ) {
541 reflags |= REG_EXTENDED; 560 reflags |= REG_EXTENDED;
542 } 561 }
562#if ENABLE_EXTRA_COMPAT
563 else {
564 reflags = RE_SYNTAX_GREP;
565 }
566#endif
543 567
544 if (option_mask32 & OPT_i) 568 if (option_mask32 & OPT_i) {
569#if !ENABLE_EXTRA_COMPAT
545 reflags |= REG_ICASE; 570 reflags |= REG_ICASE;
571#else
572 int i;
573 case_fold = xmalloc(256);
574 for (i = 0; i < 256; i++)
575 case_fold[i] = (unsigned char)i;
576 for (i = 'a'; i <= 'z'; i++)
577 case_fold[i] = (unsigned char)(i - ('a' - 'A'));
578#endif
579 }
546 580
547 argv += optind; 581 argv += optind;
548 argc -= optind; 582 argc -= optind;