* (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"
/* 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] ")
//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: )
#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" */
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,
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,
};
}
}
- 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
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;
}