diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2018-11-01 21:46:50 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2019-05-28 20:49:54 -0400 |
commit | fda29616c7af6b6e2a79c596cc01123a2d68ee02 (patch) | |
tree | 04aa6baac9ae4c1cf1afdc33c896bfa9ca97fda4 /parse.c | |
parent | 1cc323eb88242bc7be7177ba4cb037a58c754763 (diff) | |
download | bfs-fda29616c7af6b6e2a79c596cc01123a2d68ee02.tar.xz |
Implement a depth-first mode (-dfs)
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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; } |