Make grep/egrep/fgrep independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
97e9a72c71
commit
1924e99ad3
@ -18,45 +18,41 @@
|
|||||||
* (C) 2006 Jac Goudsmit added -o option
|
* (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:config GREP
|
||||||
//config: bool "grep"
|
//config: bool "grep"
|
||||||
//config: default y
|
//config: default y
|
||||||
//config: help
|
//config: help
|
||||||
//config: grep is used to search files for a specified pattern.
|
//config: grep is used to search files for a specified pattern.
|
||||||
//config:
|
//config:
|
||||||
//config:config FEATURE_GREP_EGREP_ALIAS
|
//config:config EGREP
|
||||||
//config: bool "Enable extended regular expressions (egrep & grep -E)"
|
//config: bool "egrep"
|
||||||
//config: default y
|
//config: default y
|
||||||
//config: depends on GREP
|
|
||||||
//config: help
|
//config: help
|
||||||
//config: Enabled support for extended regular expressions. Extended
|
//config: Alias to "grep -E"
|
||||||
//config: regular expressions allow for alternation (foo|bar), grouping,
|
|
||||||
//config: and various repetition operators.
|
|
||||||
//config:
|
//config:
|
||||||
//config:config FEATURE_GREP_FGREP_ALIAS
|
//config:config FGREP
|
||||||
//config: bool "Alias fgrep to grep -F"
|
//config: bool "fgrep"
|
||||||
//config: default y
|
//config: default y
|
||||||
//config: depends on GREP
|
|
||||||
//config: help
|
//config: help
|
||||||
//config: fgrep sees the search pattern as a normal string rather than
|
//config: Alias to "grep -F"
|
||||||
//config: regular expressions.
|
|
||||||
//config: grep -F always works, this just creates the fgrep alias.
|
|
||||||
//config:
|
//config:
|
||||||
//config:config FEATURE_GREP_CONTEXT
|
//config:config FEATURE_GREP_CONTEXT
|
||||||
//config: bool "Enable before and after context flags (-A, -B and -C)"
|
//config: bool "Enable before and after context flags (-A, -B and -C)"
|
||||||
//config: default y
|
//config: default y
|
||||||
//config: depends on GREP
|
//config: depends on GREP || EGREP
|
||||||
//config: help
|
//config: help
|
||||||
//config: Print the specified number of leading (-B) and/or trailing (-A)
|
//config: Print the specified number of leading (-B) and/or trailing (-A)
|
||||||
//config: context surrounding our matching lines.
|
//config: context surrounding our matching lines.
|
||||||
//config: Print the specified number of context lines (-C).
|
//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 "libbb.h"
|
||||||
#include "common_bufsiz.h"
|
#include "common_bufsiz.h"
|
||||||
#include "xregex.h"
|
#include "xregex.h"
|
||||||
@ -64,9 +60,7 @@
|
|||||||
|
|
||||||
/* options */
|
/* options */
|
||||||
//usage:#define grep_trivial_usage
|
//usage:#define grep_trivial_usage
|
||||||
//usage: "[-HhnlLoqvsriw"
|
//usage: "[-HhnlLoqvsriwFE"
|
||||||
//usage: "F"
|
|
||||||
//usage: IF_FEATURE_GREP_EGREP_ALIAS("E")
|
|
||||||
//usage: IF_EXTRA_COMPAT("z")
|
//usage: IF_EXTRA_COMPAT("z")
|
||||||
//usage: "] [-m N] "
|
//usage: "] [-m N] "
|
||||||
//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
|
//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
|
||||||
@ -88,9 +82,7 @@
|
|||||||
//usage: "\n -w Match whole words only"
|
//usage: "\n -w Match whole words only"
|
||||||
//usage: "\n -x Match whole lines only"
|
//usage: "\n -x Match whole lines only"
|
||||||
//usage: "\n -F PATTERN is a literal (not regexp)"
|
//usage: "\n -F PATTERN is a literal (not regexp)"
|
||||||
//usage: IF_FEATURE_GREP_EGREP_ALIAS(
|
|
||||||
//usage: "\n -E PATTERN is an extended regexp"
|
//usage: "\n -E PATTERN is an extended regexp"
|
||||||
//usage: )
|
|
||||||
//usage: IF_EXTRA_COMPAT(
|
//usage: IF_EXTRA_COMPAT(
|
||||||
//usage: "\n -z Input is NUL terminated"
|
//usage: "\n -z Input is NUL terminated"
|
||||||
//usage: )
|
//usage: )
|
||||||
@ -117,7 +109,7 @@
|
|||||||
#define OPTSTR_GREP \
|
#define OPTSTR_GREP \
|
||||||
"lnqvscFiHhe:*f:*Lorm:+wx" \
|
"lnqvscFiHhe:*f:*Lorm:+wx" \
|
||||||
IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
|
IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
|
||||||
IF_FEATURE_GREP_EGREP_ALIAS("E") \
|
"E" \
|
||||||
IF_EXTRA_COMPAT("z") \
|
IF_EXTRA_COMPAT("z") \
|
||||||
"aI"
|
"aI"
|
||||||
/* ignored: -a "assume all files to be text" */
|
/* 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_A ,) /* -A NUM: after-match context */
|
||||||
IF_FEATURE_GREP_CONTEXT( OPTBIT_B ,) /* -B NUM: before-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_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 */
|
IF_EXTRA_COMPAT( OPTBIT_z ,) /* input is NUL terminated */
|
||||||
OPT_l = 1 << OPTBIT_l,
|
OPT_l = 1 << OPTBIT_l,
|
||||||
OPT_n = 1 << OPTBIT_n,
|
OPT_n = 1 << OPTBIT_n,
|
||||||
@ -167,7 +159,7 @@ enum {
|
|||||||
OPT_A = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_A)) + 0,
|
OPT_A = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_A)) + 0,
|
||||||
OPT_B = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_B)) + 0,
|
OPT_B = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_B)) + 0,
|
||||||
OPT_C = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 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,
|
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;
|
option_mask32 |= OPT_F;
|
||||||
|
|
||||||
#if !ENABLE_EXTRA_COMPAT
|
#if !ENABLE_EXTRA_COMPAT
|
||||||
@ -752,8 +744,8 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
reflags = REG_NOSUB;
|
reflags = REG_NOSUB;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ENABLE_FEATURE_GREP_EGREP_ALIAS
|
if ((ENABLE_EGREP && applet_name[0] == 'e')
|
||||||
&& (applet_name[0] == 'e' || (option_mask32 & OPT_E))
|
|| (option_mask32 & OPT_E)
|
||||||
) {
|
) {
|
||||||
reflags |= REG_EXTENDED;
|
reflags |= REG_EXTENDED;
|
||||||
}
|
}
|
||||||
|
@ -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 \$?" \
|
testing "grep -x -F (partial match 2)" "grep -x -F foo input ; echo \$?" \
|
||||||
"1\n" "bar foo\n" ""
|
"1\n" "bar foo\n" ""
|
||||||
|
|
||||||
optional FEATURE_GREP_EGREP_ALIAS
|
optional EGREP
|
||||||
testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \
|
testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \
|
||||||
"b\ar\nfoo\nbaz"
|
"b\ar\nfoo\nbaz"
|
||||||
testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n"
|
testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user