summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-11-01 21:46:50 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-05-28 20:49:54 -0400
commitfda29616c7af6b6e2a79c596cc01123a2d68ee02 (patch)
tree04aa6baac9ae4c1cf1afdc33c896bfa9ca97fda4 /parse.c
parent1cc323eb88242bc7be7177ba4cb037a58c754763 (diff)
downloadbfs-fda29616c7af6b6e2a79c596cc01123a2d68ee02.tar.xz
Implement a depth-first mode (-dfs)
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index 7ca50ae..7d98ffe 100644
--- a/parse.c
+++ b/parse.c
@@ -2150,6 +2150,15 @@ static struct expr *parse_samefile(struct parser_state *state, int arg1, int arg
}
/**
+ * Parse -bfs, -dfs.
+ */
+static struct expr *parse_search_strategy(struct parser_state *state, int strategy, int arg2) {
+ struct cmdline *cmdline = state->cmdline;
+ cmdline->strategy = strategy;
+ return parse_nullary_flag(state);
+}
+
+/**
* Parse -size N[cwbkMGTP]?.
*/
static struct expr *parse_size(struct parser_state *state, int arg1, int arg2) {
@@ -2623,6 +2632,7 @@ static const struct table_entry parse_table[] = {
{"-and"},
{"-anewer", false, parse_newer, BFS_STAT_ATIME},
{"-atime", false, parse_time, BFS_STAT_ATIME, DAYS},
+ {"-bfs", false, parse_search_strategy, BFTW_BFS},
{"-capable", false, parse_capable},
{"-cmin", false, parse_time, BFS_STAT_CTIME, MINUTES},
{"-cnewer", false, parse_newer, BFS_STAT_CTIME},
@@ -2632,6 +2642,7 @@ static const struct table_entry parse_table[] = {
{"-daystart", false, parse_daystart},
{"-delete", false, parse_delete},
{"-depth", false, parse_depth_n},
+ {"-dfs", false, parse_search_strategy, BFTW_DFS},
{"-empty", false, parse_empty},
{"-exec", false, parse_exec, 0},
{"-execdir", false, parse_exec, BFS_EXEC_CHDIR},
@@ -3031,6 +3042,15 @@ void dump_cmdline(const struct cmdline *cmdline, bool verbose) {
cfprintf(cerr, "${ex}%s${rs} ", cmdline->argv[0]);
+ switch (cmdline->strategy) {
+ case BFTW_BFS:
+ cfprintf(cerr, "${cyn}-bfs${rs} ");
+ break;
+ case BFTW_DFS:
+ cfprintf(cerr, "${cyn}-dfs${rs} ");
+ break;
+ }
+
if (cmdline->flags & BFTW_LOGICAL) {
cfprintf(cerr, "${cyn}-L${rs} ");
} else if (cmdline->flags & BFTW_COMFOLLOW) {
@@ -3152,6 +3172,7 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) {
cmdline->mindepth = 0;
cmdline->maxdepth = INT_MAX;
cmdline->flags = BFTW_RECOVER;
+ cmdline->strategy = BFTW_BFS;
cmdline->optlevel = 3;
cmdline->debug = 0;
cmdline->xargs_safe = false;
@@ -3215,6 +3236,11 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) {
.prune_arg = NULL,
};
+ if (strcmp(xbasename(state.command), "find") == 0) {
+ // Operate depth-first when invoked as "find"
+ cmdline->strategy = BFTW_DFS;
+ }
+
if (parse_gettime(&state.now) != 0) {
goto fail;
}