/* 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] ")
//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"
/* -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") \
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 */
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,
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,
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))