aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Leppanen <tomi.leppanen@jolla.com>2019-11-25 17:59:52 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-11-27 17:11:09 +0100
commit1b76ffaae400f266fe5aea0d5900a7e2ab9d7aa8 (patch)
tree3d1cd284687332353a67e839ebbcb2741bb14f99
parent008413754ba588e6168c3d15280181fb2c331770 (diff)
downloadbusybox-w32-1b76ffaae400f266fe5aea0d5900a7e2ab9d7aa8.tar.gz
busybox-w32-1b76ffaae400f266fe5aea0d5900a7e2ab9d7aa8.tar.bz2
busybox-w32-1b76ffaae400f266fe5aea0d5900a7e2ab9d7aa8.zip
grep: add -R
This adds -R option to grep similar to GNU grep. It is the same as -r but also dereferences symbolic links to directories. function old new delta grep_main 834 850 +16 packed_usage 33362 33368 +6 grep_file 1440 1441 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 23/0) Total: 23 bytes Signed-off-by: Tomi Leppanen <tomi.leppanen@jolla.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/grep.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 2cbe7ea91..5b8644c36 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -60,7 +60,7 @@
60 60
61/* options */ 61/* options */
62//usage:#define grep_trivial_usage 62//usage:#define grep_trivial_usage
63//usage: "[-HhnlLoqvsriwFE" 63//usage: "[-HhnlLoqvsrRiwFE"
64//usage: IF_EXTRA_COMPAT("z") 64//usage: IF_EXTRA_COMPAT("z")
65//usage: "] [-m N] " 65//usage: "] [-m N] "
66//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ") 66//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
@@ -78,6 +78,7 @@
78//usage: "\n -v Select non-matching lines" 78//usage: "\n -v Select non-matching lines"
79//usage: "\n -s Suppress open and read errors" 79//usage: "\n -s Suppress open and read errors"
80//usage: "\n -r Recurse" 80//usage: "\n -r Recurse"
81//usage: "\n -R Recurse and dereference symlinks"
81//usage: "\n -i Ignore case" 82//usage: "\n -i Ignore case"
82//usage: "\n -w Match whole words only" 83//usage: "\n -w Match whole words only"
83//usage: "\n -x Match whole lines only" 84//usage: "\n -x Match whole lines only"
@@ -108,7 +109,7 @@
108 109
109/* -e,-f are lists; -m,-A,-B,-C have numeric param */ 110/* -e,-f are lists; -m,-A,-B,-C have numeric param */
110#define OPTSTR_GREP \ 111#define OPTSTR_GREP \
111 "lnqvscFiHhe:*f:*Lorm:+wx" \ 112 "lnqvscFiHhe:*f:*LorRm:+wx" \
112 IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \ 113 IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
113 "E" \ 114 "E" \
114 IF_EXTRA_COMPAT("z") \ 115 IF_EXTRA_COMPAT("z") \
@@ -131,6 +132,7 @@ enum {
131 OPTBIT_L, /* list unmatched file names only */ 132 OPTBIT_L, /* list unmatched file names only */
132 OPTBIT_o, /* show only matching parts of lines */ 133 OPTBIT_o, /* show only matching parts of lines */
133 OPTBIT_r, /* recurse dirs */ 134 OPTBIT_r, /* recurse dirs */
135 OPTBIT_R, /* recurse dirs and symlinks to dirs */
134 OPTBIT_m, /* -m MAX_MATCHES */ 136 OPTBIT_m, /* -m MAX_MATCHES */
135 OPTBIT_w, /* -w whole word match */ 137 OPTBIT_w, /* -w whole word match */
136 OPTBIT_x, /* -x whole line match */ 138 OPTBIT_x, /* -x whole line match */
@@ -154,6 +156,7 @@ enum {
154 OPT_L = 1 << OPTBIT_L, 156 OPT_L = 1 << OPTBIT_L,
155 OPT_o = 1 << OPTBIT_o, 157 OPT_o = 1 << OPTBIT_o,
156 OPT_r = 1 << OPTBIT_r, 158 OPT_r = 1 << OPTBIT_r,
159 OPT_R = 1 << OPTBIT_R,
157 OPT_m = 1 << OPTBIT_m, 160 OPT_m = 1 << OPTBIT_m,
158 OPT_w = 1 << OPTBIT_w, 161 OPT_w = 1 << OPTBIT_w,
159 OPT_x = 1 << OPTBIT_x, 162 OPT_x = 1 << OPTBIT_x,
@@ -687,6 +690,7 @@ static int grep_dir(const char *dir)
687 int matched = 0; 690 int matched = 0;
688 recursive_action(dir, 691 recursive_action(dir,
689 /* recurse=yes */ ACTION_RECURSE | 692 /* recurse=yes */ ACTION_RECURSE |
693 /* followLinks=always */ ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0) |
690 /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 | 694 /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
691 /* depthFirst=yes */ ACTION_DEPTHFIRST, 695 /* depthFirst=yes */ ACTION_DEPTHFIRST,
692 /* fileAction= */ file_action_grep, 696 /* fileAction= */ file_action_grep,
@@ -827,7 +831,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
827 if (!cur_file || LONE_DASH(cur_file)) { 831 if (!cur_file || LONE_DASH(cur_file)) {
828 cur_file = "(standard input)"; 832 cur_file = "(standard input)";
829 } else { 833 } else {
830 if (option_mask32 & OPT_r) { 834 if (option_mask32 & (OPT_r|OPT_R)) {
831 struct stat st; 835 struct stat st;
832 if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) { 836 if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) {
833 if (!(option_mask32 & OPT_h)) 837 if (!(option_mask32 & OPT_h))