summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-03-06 13:40:24 -0500
committerTavian Barnes <tavianator@tavianator.com>2021-03-06 13:40:24 -0500
commit863b70d198f62f28581162473a521208dd67879e (patch)
tree9506283742eef1951ecaa897f4584b3941499a51 /parse.c
parent8f201b2380aef3a566316343e7e71c6fc995cf41 (diff)
downloadbfs-863b70d198f62f28581162473a521208dd67879e.tar.xz
Implement -flags, from FreeBSD find
This is the last BSD-specific primary I'm aware of. Fixes #14.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index 08899eb..fd4585c 100644
--- a/parse.c
+++ b/parse.c
@@ -1160,6 +1160,60 @@ static struct expr *parse_f(struct parser_state *state, int arg1, int arg2) {
}
/**
+ * Parse -flags FLAGS.
+ */
+static struct expr *parse_flags(struct parser_state *state, int arg1, int arg2) {
+#if __APPLE__ || __FreeBSD__
+ struct expr *expr = parse_unary_test(state, eval_flags);
+ if (!expr) {
+ return NULL;
+ }
+
+ // strtofflags() takes a non-const char *
+ char *copy = strdup(expr->sdata);
+ if (!copy) {
+ parse_perror(state, "strdup()");
+ goto err;
+ }
+
+ char *flags = copy;
+ switch (flags[0]) {
+ case '-':
+ expr->mode_cmp = MODE_ALL;
+ ++flags;
+ break;
+ case '+':
+ expr->mode_cmp = MODE_ANY;
+ ++flags;
+ break;
+ default:
+ expr->mode_cmp = MODE_EXACT;
+ break;
+ }
+
+ unsigned long set, clear;
+ if (strtofflags(&flags, &set, &clear) != 0) {
+ parse_error(state, "${blu}%s${rs}: Invalid flags ${bld}%s${rs}.\n", expr->argv[0], flags);
+ goto err;
+ }
+
+ expr->set_flags = set;
+ expr->clear_flags = clear;
+
+ free(copy);
+ return expr;
+
+err:
+ free(copy);
+ free_expr(expr);
+ return NULL;
+#else // !(__APPLE__ || __FreeBSD)
+ parse_error(state, "${blu}%s${rs} is missing platform support.\n", state->argv[0]);
+ return NULL;
+#endif
+}
+
+/**
* Parse -fls FILE.
*/
static struct expr *parse_fls(struct parser_state *state, int arg1, int arg2) {
@@ -2888,6 +2942,7 @@ static const struct table_entry parse_table[] = {
{"-exit", T_ACTION, parse_exit},
{"-f", T_FLAG, parse_f},
{"-false", T_TEST, parse_const, false},
+ {"-flags", T_TEST, parse_flags},
{"-fls", T_ACTION, parse_fls},
{"-follow", T_OPTION, parse_follow, BFTW_FOLLOW_ALL, true},
{"-fprint", T_ACTION, parse_fprint},