grep: add -R
No binary (build failed)
—
(log yok)
| @@ -60,7 +60,7 @@ | |
| /* options */ | |
| //usage:#define grep_trivial_usage | |
| - | //usage: "[-HhnlLoqvsriwFE" |
| + | //usage: "[-HhnlLoqvsrRiwFE" |
| //usage: IF_EXTRA_COMPAT("z") | |
| //usage: "] [-m N] " | |
| //usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ") | |
| @@ -78,6 +78,7 @@ | |
| //usage: "\n -v Select non-matching lines" | |
| //usage: "\n -s Suppress open and read errors" | |
| //usage: "\n -r Recurse" | |
| + | //usage: "\n -R Recurse and dereference symlinks" |
| //usage: "\n -i Ignore case" | |
| //usage: "\n -w Match whole words only" | |
| //usage: "\n -x Match whole lines only" | |
| @@ -108,7 +109,7 @@ | |
| /* -e,-f are lists; -m,-A,-B,-C have numeric param */ | |
| #define OPTSTR_GREP \ | |
| - | "lnqvscFiHhe:*f:*Lorm:+wx" \ |
| + | "lnqvscFiHhe:*f:*LorRm:+wx" \ |
| IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \ | |
| "E" \ | |
| IF_EXTRA_COMPAT("z") \ | |
| @@ -131,6 +132,7 @@ enum { | |
| OPTBIT_L, /* list unmatched file names only */ | |
| OPTBIT_o, /* show only matching parts of lines */ | |
| OPTBIT_r, /* recurse dirs */ | |
| + | OPTBIT_R, /* recurse dirs and symlinks to dirs */ |
| OPTBIT_m, /* -m MAX_MATCHES */ | |
| OPTBIT_w, /* -w whole word match */ | |
| OPTBIT_x, /* -x whole line match */ | |
| @@ -154,6 +156,7 @@ enum { | |
| OPT_L = 1 << OPTBIT_L, | |
| OPT_o = 1 << OPTBIT_o, | |
| OPT_r = 1 << OPTBIT_r, | |
| + | OPT_R = 1 << OPTBIT_R, |
| OPT_m = 1 << OPTBIT_m, | |
| OPT_w = 1 << OPTBIT_w, | |
| OPT_x = 1 << OPTBIT_x, | |
| @@ -687,6 +690,7 @@ static int grep_dir(const char *dir) | |
| int matched = 0; | |
| recursive_action(dir, | |
| /* recurse=yes */ ACTION_RECURSE | | |
| + | /* followLinks=always */ ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0) | |
| /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 | | |
| /* depthFirst=yes */ ACTION_DEPTHFIRST, | |
| /* fileAction= */ file_action_grep, | |
| @@ -827,7 +831,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) | |
| if (!cur_file || LONE_DASH(cur_file)) { | |
| cur_file = "(standard input)"; | |
| } else { | |
| - | if (option_mask32 & OPT_r) { |
| + | if (option_mask32 & (OPT_r|OPT_R)) { |
| struct stat st; | |
| if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) { | |
| if (!(option_mask32 & OPT_h)) | |