From: Denys Vlasenko Date: Mon, 14 Nov 2016 04:09:48 +0000 (+0100) Subject: Make grep/egrep/fgrep independently selectable X-Git-Tag: 1_26_0~68 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1924e99ad3513990f317c4295c35d5861521555a;p=oweals%2Fbusybox.git Make grep/egrep/fgrep independently selectable Signed-off-by: Denys Vlasenko --- diff --git a/findutils/grep.c b/findutils/grep.c index 1fa605f6f..547e3d576 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -18,45 +18,41 @@ * (C) 2006 Jac Goudsmit added -o option */ -//applet:IF_GREP(APPLET(grep, BB_DIR_BIN, BB_SUID_DROP)) -//applet:IF_FEATURE_GREP_EGREP_ALIAS(APPLET_ODDNAME(egrep, grep, BB_DIR_BIN, BB_SUID_DROP, egrep)) -//applet:IF_FEATURE_GREP_FGREP_ALIAS(APPLET_ODDNAME(fgrep, grep, BB_DIR_BIN, BB_SUID_DROP, fgrep)) - -//kbuild:lib-$(CONFIG_GREP) += grep.o - //config:config GREP //config: bool "grep" //config: default y //config: help //config: grep is used to search files for a specified pattern. //config: -//config:config FEATURE_GREP_EGREP_ALIAS -//config: bool "Enable extended regular expressions (egrep & grep -E)" +//config:config EGREP +//config: bool "egrep" //config: default y -//config: depends on GREP //config: help -//config: Enabled support for extended regular expressions. Extended -//config: regular expressions allow for alternation (foo|bar), grouping, -//config: and various repetition operators. +//config: Alias to "grep -E" //config: -//config:config FEATURE_GREP_FGREP_ALIAS -//config: bool "Alias fgrep to grep -F" +//config:config FGREP +//config: bool "fgrep" //config: default y -//config: depends on GREP //config: help -//config: fgrep sees the search pattern as a normal string rather than -//config: regular expressions. -//config: grep -F always works, this just creates the fgrep alias. +//config: Alias to "grep -F" //config: //config:config FEATURE_GREP_CONTEXT //config: bool "Enable before and after context flags (-A, -B and -C)" //config: default y -//config: depends on GREP +//config: depends on GREP || EGREP //config: help //config: Print the specified number of leading (-B) and/or trailing (-A) //config: context surrounding our matching lines. //config: Print the specified number of context lines (-C). +//applet:IF_GREP(APPLET(grep, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_EGREP(APPLET_ODDNAME(egrep, grep, BB_DIR_BIN, BB_SUID_DROP, egrep)) +//applet:IF_FGREP(APPLET_ODDNAME(fgrep, grep, BB_DIR_BIN, BB_SUID_DROP, fgrep)) + +//kbuild:lib-$(CONFIG_GREP) += grep.o +//kbuild:lib-$(CONFIG_EGREP) += grep.o +//kbuild:lib-$(CONFIG_FGREP) += grep.o + #include "libbb.h" #include "common_bufsiz.h" #include "xregex.h" @@ -64,9 +60,7 @@ /* options */ //usage:#define grep_trivial_usage -//usage: "[-HhnlLoqvsriw" -//usage: "F" -//usage: IF_FEATURE_GREP_EGREP_ALIAS("E") +//usage: "[-HhnlLoqvsriwFE" //usage: IF_EXTRA_COMPAT("z") //usage: "] [-m N] " //usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ") @@ -88,9 +82,7 @@ //usage: "\n -w Match whole words only" //usage: "\n -x Match whole lines only" //usage: "\n -F PATTERN is a literal (not regexp)" -//usage: IF_FEATURE_GREP_EGREP_ALIAS( //usage: "\n -E PATTERN is an extended regexp" -//usage: ) //usage: IF_EXTRA_COMPAT( //usage: "\n -z Input is NUL terminated" //usage: ) @@ -117,7 +109,7 @@ #define OPTSTR_GREP \ "lnqvscFiHhe:*f:*Lorm:+wx" \ IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \ - IF_FEATURE_GREP_EGREP_ALIAS("E") \ + "E" \ IF_EXTRA_COMPAT("z") \ "aI" /* ignored: -a "assume all files to be text" */ @@ -144,7 +136,7 @@ enum { IF_FEATURE_GREP_CONTEXT( OPTBIT_A ,) /* -A NUM: after-match context */ IF_FEATURE_GREP_CONTEXT( OPTBIT_B ,) /* -B NUM: before-match context */ IF_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */ - IF_FEATURE_GREP_EGREP_ALIAS(OPTBIT_E ,) /* extended regexp */ + OPTBIT_E, /* extended regexp */ IF_EXTRA_COMPAT( OPTBIT_z ,) /* input is NUL terminated */ OPT_l = 1 << OPTBIT_l, OPT_n = 1 << OPTBIT_n, @@ -167,7 +159,7 @@ enum { OPT_A = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_A)) + 0, OPT_B = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_B)) + 0, OPT_C = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0, - OPT_E = IF_FEATURE_GREP_EGREP_ALIAS((1 << OPTBIT_E)) + 0, + OPT_E = 1 << OPTBIT_E, OPT_z = IF_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0, }; @@ -744,7 +736,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) } } - if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f') + if (ENABLE_FGREP && applet_name[0] == 'f') option_mask32 |= OPT_F; #if !ENABLE_EXTRA_COMPAT @@ -752,8 +744,8 @@ int grep_main(int argc UNUSED_PARAM, char **argv) reflags = REG_NOSUB; #endif - if (ENABLE_FEATURE_GREP_EGREP_ALIAS - && (applet_name[0] == 'e' || (option_mask32 & OPT_E)) + if ((ENABLE_EGREP && applet_name[0] == 'e') + || (option_mask32 & OPT_E) ) { reflags |= REG_EXTENDED; } diff --git a/testsuite/grep.tests b/testsuite/grep.tests index f6d9f2105..ed4ba455e 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests @@ -96,7 +96,7 @@ testing "grep -x -F (partial match 1)" "grep -x -F foo input ; echo \$?" \ testing "grep -x -F (partial match 2)" "grep -x -F foo input ; echo \$?" \ "1\n" "bar foo\n" "" -optional FEATURE_GREP_EGREP_ALIAS +optional EGREP testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \ "b\ar\nfoo\nbaz" testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n"