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. --- parse.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'parse.c') 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