summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bfs.16
-rw-r--r--eval.c12
-rw-r--r--eval.h1
-rw-r--r--parse.c28
-rwxr-xr-xtests.sh5
-rw-r--r--tests/test_nohidden_depth.out19
6 files changed, 48 insertions, 23 deletions
diff --git a/bfs.1 b/bfs.1
index f308961..1b5ac0d 100644
--- a/bfs.1
+++ b/bfs.1
@@ -271,6 +271,9 @@ Don't descend into other mount points (same as
.B \-xdev
for now, but will skip mount points entirely in the future).
.TP
+.B \-nohidden
+Exclude hidden files and directories.
+.TP
.B \-noleaf
Ignored; for compatibility with GNU find.
.TP
@@ -609,9 +612,6 @@ List files like
.B ls
.IR \-dils .
.TP
-.B \-nohidden
-Filter out hidden files and directories.
-.TP
.B \-print
Print the path to the found file.
.TP
diff --git a/eval.c b/eval.c
index 41e0377..ed1ab55 100644
--- a/eval.c
+++ b/eval.c
@@ -449,18 +449,6 @@ bool eval_hidden(const struct expr *expr, struct eval_state *state) {
}
/**
- * -nohidden action.
- */
-bool eval_nohidden(const struct expr *expr, struct eval_state *state) {
- if (eval_hidden(expr, state)) {
- eval_prune(expr, state);
- return false;
- } else {
- return true;
- }
-}
-
-/**
* -inum test.
*/
bool eval_inum(const struct expr *expr, struct eval_state *state) {
diff --git a/eval.h b/eval.h
index 7038bb9..b31c0d5 100644
--- a/eval.h
+++ b/eval.h
@@ -63,7 +63,6 @@ bool eval_regex(const struct expr *expr, struct eval_state *state);
bool eval_delete(const struct expr *expr, struct eval_state *state);
bool eval_exec(const struct expr *expr, struct eval_state *state);
bool eval_exit(const struct expr *expr, struct eval_state *state);
-bool eval_nohidden(const struct expr *expr, struct eval_state *state);
bool eval_fls(const struct expr *expr, struct eval_state *state);
bool eval_fprint(const struct expr *expr, struct eval_state *state);
bool eval_fprint0(const struct expr *expr, struct eval_state *state);
diff --git a/parse.c b/parse.c
index 23aefba..7bde6d0 100644
--- a/parse.c
+++ b/parse.c
@@ -61,6 +61,7 @@
// Strings printed by -D tree for "fake" expressions
static char *fake_and_arg = "-a";
static char *fake_false_arg = "-false";
+static char *fake_hidden_arg = "-hidden";
static char *fake_or_arg = "-o";
static char *fake_print_arg = "-print";
static char *fake_true_arg = "-true";
@@ -754,7 +755,7 @@ static struct expr *parse_unary_test(struct parser_state *state, eval_fn *eval)
* Parse a single action.
*/
static struct expr *parse_action(struct parser_state *state, eval_fn *eval, size_t argc) {
- if (eval != eval_nohidden && eval != eval_prune && eval != eval_quit) {
+ if (eval != eval_prune && eval != eval_quit) {
state->implicit_print = false;
}
@@ -1733,8 +1734,22 @@ static struct expr *parse_nogroup(struct parser_state *state, int arg1, int arg2
* Parse -nohidden.
*/
static struct expr *parse_nohidden(struct parser_state *state, int arg1, int arg2) {
- state->prune_arg = state->argv[0];
- return parse_nullary_action(state, eval_nohidden);
+ struct expr *hidden = new_expr(eval_hidden, 1, &fake_hidden_arg);
+ if (!hidden) {
+ return NULL;
+ }
+
+ hidden->probability = 0.01;
+ hidden->pure = true;
+
+ struct cmdline *cmdline = state->cmdline;
+ cmdline->exclude = new_binary_expr(eval_or, cmdline->exclude, hidden, &fake_or_arg);
+ if (!cmdline->exclude) {
+ return NULL;
+ }
+
+ parser_advance(state, T_OPTION, 1);
+ return &expr_true;
}
/**
@@ -2680,6 +2695,8 @@ static struct expr *parse_help(struct parser_state *state, int arg1, int arg2) {
cfprintf(cout, " ${blu}-mount${rs}\n");
cfprintf(cout, " Don't descend into other mount points (same as ${blu}-xdev${rs} for now, but will\n");
cfprintf(cout, " skip mount points entirely in the future)\n");
+ cfprintf(cout, " ${blu}-nohidden${rs}\n");
+ cfprintf(cout, " Exclude hidden files\n");
cfprintf(cout, " ${blu}-noleaf${rs}\n");
cfprintf(cout, " Ignored; for compatibility with GNU find\n");
cfprintf(cout, " ${blu}-regextype${rs} ${bld}TYPE${rs}\n");
@@ -2732,8 +2749,7 @@ static struct expr *parse_help(struct parser_state *state, int arg1, int arg2) {
cfprintf(cout, " ${blu}-user${rs} ${bld}NAME${rs}\n");
cfprintf(cout, " Find files owned by the group/user ${bld}NAME${rs}\n");
cfprintf(cout, " ${blu}-hidden${rs}\n");
- cfprintf(cout, " ${blu}-nohidden${rs}\n");
- cfprintf(cout, " Find hidden files, or filter them out\n");
+ cfprintf(cout, " Find hidden files\n");
#ifdef FNM_CASEFOLD
cfprintf(cout, " ${blu}-ilname${rs} ${bld}GLOB${rs}\n");
cfprintf(cout, " ${blu}-iname${rs} ${bld}GLOB${rs}\n");
@@ -2815,8 +2831,6 @@ static struct expr *parse_help(struct parser_state *state, int arg1, int arg2) {
" output\n");
cfprintf(cout, " ${blu}-ls${rs}\n");
cfprintf(cout, " List files like ${ex}ls${rs} ${bld}-dils${rs}\n");
- cfprintf(cout, " ${blu}-nohidden${rs}\n");
- cfprintf(cout, " Filter out hidden files and directories\n");
cfprintf(cout, " ${blu}-print${rs}\n");
cfprintf(cout, " Print the path to the found file\n");
cfprintf(cout, " ${blu}-print0${rs}\n");
diff --git a/tests.sh b/tests.sh
index c428c65..77a5da1 100755
--- a/tests.sh
+++ b/tests.sh
@@ -646,6 +646,7 @@ bfs_tests=(
test_hidden
test_nohidden
+ test_nohidden_depth
test_perm_symbolic_trailing_comma
test_perm_symbolic_double_comma
@@ -1783,6 +1784,10 @@ function test_nohidden() {
bfs_diff weirdnames -nohidden
}
+function test_nohidden_depth() {
+ bfs_diff weirdnames -depth -nohidden
+}
+
function test_depth_n() {
bfs_diff basic -depth 2
}
diff --git a/tests/test_nohidden_depth.out b/tests/test_nohidden_depth.out
new file mode 100644
index 0000000..d2a9690
--- /dev/null
+++ b/tests/test_nohidden_depth.out
@@ -0,0 +1,19 @@
+weirdnames
+weirdnames/
+weirdnames/!
+weirdnames/!-
+weirdnames/(
+weirdnames/(-
+weirdnames/)
+weirdnames/,
+weirdnames/-
+weirdnames/\
+weirdnames/ /j
+weirdnames/!-/e
+weirdnames/!/d
+weirdnames/(-/c
+weirdnames/(/b
+weirdnames/)/g
+weirdnames/,/f
+weirdnames/-/a
+weirdnames/\/i