From 8395589d15961cedc136a0cf945bd5ae93b5c7c6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 13 Jul 2016 19:57:43 -0400 Subject: Implement -f PATH from BSD find. --- RELEASES.md | 1 + parse.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 83007c8..e76518e 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -27,6 +27,7 @@ - Implement `-D rates` - Implement `-fprint` - Implement `-fprint0` +- Implement BSD's `-f` 0.79 diff --git a/parse.c b/parse.c index 8e01435..e5bfacb 100644 --- a/parse.c +++ b/parse.c @@ -786,6 +786,27 @@ static struct expr *parse_exec(struct parser_state *state, enum exec_flags flags return expr; } +/** + * Parse -f PATH. + */ +static struct expr *parse_f(struct parser_state *state) { + parser_advance(state, T_FLAG, 1); + + const char *path = state->argv[0]; + if (!path) { + pretty_error(state->cmdline->stderr_colors, + "error: -f requires a path.\n"); + return NULL; + } + + if (!parse_root(state, path)) { + return NULL; + } + + parser_advance(state, T_PATH, 1); + return &expr_true; +} + /** * Open a file for an expression. */ @@ -1307,7 +1328,9 @@ static struct expr *parse_literal(struct parser_state *state) { break; case 'f': - if (strcmp(arg, "-false") == 0) { + if (strcmp(arg, "-f") == 0) { + return parse_f(state); + } else if (strcmp(arg, "-false") == 0) { parser_advance(state, T_TEST, 1); return &expr_false; } else if (strcmp(arg, "-follow") == 0) { @@ -1857,6 +1880,10 @@ void dump_cmdline(const struct cmdline *cmdline, bool verbose) { } for (struct root *root = cmdline->roots; root; root = root->next) { + char c = root->path[0]; + if (c == '-' || c == '(' || c == ')' || c == '!' || c == ',') { + fputs("-f ", stderr); + } fprintf(stderr, "%s ", root->path); } -- cgit v1.2.3