summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-05-22 13:17:02 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-05-22 13:17:02 -0400
commit8ea44cab76a20f1c5ac473b1651611bea0ee9e6b (patch)
treecd2d47aef86e6ce8fa0fd49a3baa6a5709aba8ae /parse.c
parenta36577183430607196e88c2b951f2dc71a06dbaf (diff)
downloadbfs-8ea44cab76a20f1c5ac473b1651611bea0ee9e6b.tar.xz
Implement -{exec,ok}{,dir}.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c56
1 files changed, 51 insertions, 5 deletions
diff --git a/parse.c b/parse.c
index 53d42eb..d51c43e 100644
--- a/parse.c
+++ b/parse.c
@@ -281,15 +281,15 @@ bad:
static const char *parse_icmp(const struct parser_state *state, const char *str, struct expr *expr, enum intflags flags) {
switch (str[0]) {
case '-':
- expr->cmp = CMP_LESS;
+ expr->cmpflag = CMP_LESS;
++str;
break;
case '+':
- expr->cmp = CMP_GREATER;
+ expr->cmpflag = CMP_GREATER;
++str;
break;
default:
- expr->cmp = CMP_EXACT;
+ expr->cmpflag = CMP_EXACT;
break;
}
@@ -571,6 +571,40 @@ static struct expr *parse_depth(struct parser_state *state, int *depth) {
}
/**
+ * Parse -exec[dir]/-ok[dir].
+ */
+static struct expr *parse_exec(struct parser_state *state, enum execflags flags) {
+ size_t i = 1;
+ const char *arg;
+ while ((arg = state->args[i++])) {
+ if (strcmp(arg, ";") == 0) {
+ break;
+ } else if (strcmp(arg, "+") == 0) {
+ flags |= EXEC_MULTI;
+ break;
+ }
+ }
+
+ if (!arg) {
+ pretty_error(state->cmdline->stderr_colors,
+ "error: %s: Expected ';' or '+'.\n", state->args[0]);
+ return NULL;
+ }
+
+ if (flags & EXEC_MULTI) {
+ pretty_error(state->cmdline->stderr_colors,
+ "error: %s ... {} + is not supported yet\n", state->args[0]);
+ return NULL;
+ }
+
+ struct expr *expr = parse_action(state, eval_exec, i);
+ if (expr) {
+ expr->execflags = flags;
+ }
+ return expr;
+}
+
+/**
* Parse -group.
*/
static struct expr *parse_group(struct parser_state *state) {
@@ -599,7 +633,7 @@ static struct expr *parse_group(struct parser_state *state) {
goto error;
}
- expr->cmp = CMP_EXACT;
+ expr->cmpflag = CMP_EXACT;
return expr;
error:
@@ -640,7 +674,7 @@ static struct expr *parse_user(struct parser_state *state) {
goto error;
}
- expr->cmp = CMP_EXACT;
+ expr->cmpflag = CMP_EXACT;
return expr;
error:
@@ -1028,6 +1062,10 @@ static struct expr *parse_literal(struct parser_state *state) {
case 'e':
if (strcmp(arg, "-empty") == 0) {
return parse_nullary_test(state, eval_empty);
+ } else if (strcmp(arg, "-exec") == 0) {
+ return parse_exec(state, 0);
+ } else if (strcmp(arg, "-execdir") == 0) {
+ return parse_exec(state, EXEC_CHDIR);
} else if (strcmp(arg, "-executable") == 0) {
return parse_access(state, X_OK);
}
@@ -1115,6 +1153,14 @@ static struct expr *parse_literal(struct parser_state *state) {
}
break;
+ case 'o':
+ if (strcmp(arg, "-ok") == 0) {
+ return parse_exec(state, EXEC_CONFIRM);
+ } else if (strcmp(arg, "-okdir") == 0) {
+ return parse_exec(state, EXEC_CONFIRM | EXEC_CHDIR);
+ }
+ break;
+
case 'p':
if (strcmp(arg, "-path") == 0) {
return parse_path(state, false);