summaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
authorDenys Vlasenko2016-11-14 05:09:48 +0100
committerDenys Vlasenko2016-11-14 05:09:48 +0100
commit1924e99ad3513990f317c4295c35d5861521555a (patch)
tree65b1f39bfa87682cd71c88dc892d811bf6a98749 /findutils/grep.c
parent97e9a72c71d0238c9f241612ce4af923c16954c7 (diff)
downloadbusybox-1924e99ad3513990f317c4295c35d5861521555a.zip
busybox-1924e99ad3513990f317c4295c35d5861521555a.tar.gz
Make grep/egrep/fgrep independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c52
1 files changed, 22 insertions, 30 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 1fa605f..547e3d5 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;
}