aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-09-19 21:29:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-09-19 21:29:21 +0000
commitc110b7d61f33169d8aee348801fe32c86fef4c55 (patch)
tree4783d61ec4aa57638e87a1a40ace140a3d4ff187
parent72fa70af4c0c46fe2b02d3df27c24ff4d14eb505 (diff)
downloadbusybox-w32-c110b7d61f33169d8aee348801fe32c86fef4c55.tar.gz
busybox-w32-c110b7d61f33169d8aee348801fe32c86fef4c55.tar.bz2
busybox-w32-c110b7d61f33169d8aee348801fe32c86fef4c55.zip
grep: fix EXTRA_COMPAT grep to honor -E and -i
-rw-r--r--findutils/grep.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index f2ed01e74..e0f01c9c2 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,8 +549,10 @@ 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))
@@ -541,8 +560,18 @@ int grep_main(int argc, char **argv)
541 reflags |= REG_EXTENDED; 560 reflags |= REG_EXTENDED;
542 } 561 }
543 562
544 if (option_mask32 & OPT_i) 563 if (option_mask32 & OPT_i) {
564#if !ENABLE_EXTRA_COMPAT
545 reflags |= REG_ICASE; 565 reflags |= REG_ICASE;
566#else
567 int i;
568 case_fold = xmalloc(256);
569 for (i = 0; i < 256; i++)
570 case_fold[i] = (unsigned char)i;
571 for (i = 'a'; i <= 'z'; i++)
572 case_fold[i] = (unsigned char)(i - ('a' - 'A'));
573#endif
574 }
546 575
547 argv += optind; 576 argv += optind;
548 argc -= optind; 577 argc -= optind;