aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-07-11 12:22:31 -0700
committerRob Landley <rob@landley.net>2019-07-12 12:18:45 -0500
commit5194d4ad66ad130cb730e0b192ba1e2b5181184d (patch)
treee435db7dfed5b1503dc852bbf566852c61651e7f /toys/posix
parentdff94300f9bd0f3e6e33a22d480ea11380ddd039 (diff)
downloadtoybox-5194d4ad66ad130cb730e0b192ba1e2b5181184d.tar.gz
grep: add -R as well as -r.
On BSD these are actually the same, and there's a -S that you need in addition. So strictly this is a behavior change for Android (which is going from BSD grep to toybox grep), but it's a behavior preserving change for the AOSP build (which is going from GNU grep to toybox grep), and the latter actually has a checked-in use of -R where the former doesn't.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/grep.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 30a98190..b92294ed 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -10,7 +10,7 @@
* echo hello | grep -f </dev/null
*
-USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
+USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
USE_EGREP(OLDTOY(egrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
USE_FGREP(OLDTOY(fgrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
@@ -29,6 +29,7 @@ config GREP
file search:
-r Recurse into subdirectories (defaults FILE to ".")
+ -R Recurse into subdirectories and symlinks to directories
-M Match filename pattern (--include)
-S Skip filename pattern (--exclude)
--exclude-dir=PATTERN Skip directory pattern
@@ -425,7 +426,7 @@ static int do_grep_r(struct dirtree *new)
if (S_ISDIR(new->st.st_mode)) {
for (al = TT.exclude_dir; al; al = al->next)
if (!fnmatch(al->arg, new->name, 0)) return 0;
- return DIRTREE_RECURSE;
+ return DIRTREE_RECURSE|(FLAG(R)?DIRTREE_SYMFOLLOW:0);
}
if (TT.S || TT.M) {
for (al = TT.S; al; al = al->next)
@@ -464,6 +465,8 @@ void grep_main(void)
TT.grey = "\033[0m";
} else TT.purple = TT.cyan = TT.red = TT.green = TT.grey = "";
+ if (FLAG(R)) toys.optflags |= FLAG_r;
+
// Grep exits with 2 for errors
toys.exitval = 2;