summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-07-13 19:57:43 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-07-13 19:58:40 -0400
commit8395589d15961cedc136a0cf945bd5ae93b5c7c6 (patch)
tree0f1d77fe420f160f4ed603b3bfc063775e47fbac /parse.c
parentd0119ee5efa56c32f956027f58673a6b3da7ac46 (diff)
downloadbfs-8395589d15961cedc136a0cf945bd5ae93b5c7c6.tar.xz
Implement -f PATH from BSD find.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index 8e01435..e5bfacb 100644
--- a/parse.c
+++ b/parse.c
@@ -787,6 +787,27 @@ static struct expr *parse_exec(struct parser_state *state, enum exec_flags flags
}
/**
+ * 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.
*/
static int expr_open(struct parser_state *state, struct expr *expr, const char *path) {
@@ -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);
}