summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-12-18 18:35:33 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-12-18 18:35:33 -0500
commit8fad779ae21b1052268af0befa930c75d1dd780b (patch)
tree59fe107f78d9b53f0e6d3ac59e326105a2d06230 /parse.c
parente319411a3f2f4e82f3519cc1a1f45e7153a5e2af (diff)
downloadbfs-8fad779ae21b1052268af0befa930c75d1dd780b.tar.xz
Implement BSD find's -depth N
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index 8d865e8..1af73cb 100644
--- a/parse.c
+++ b/parse.c
@@ -832,6 +832,23 @@ static struct expr *parse_depth(struct parser_state *state, int arg1, int arg2)
}
/**
+ * Parse -depth [N].
+ */
+static struct expr *parse_depth_n(struct parser_state *state, int arg1, int arg2) {
+ const char *arg = state->argv[1];
+ if (arg) {
+ while (*arg == '-' || *arg == '+') {
+ ++arg;
+ }
+ if (*arg >= '0' && *arg <= '9') {
+ return parse_test_icmp(state, eval_depth);
+ }
+ }
+
+ return parse_depth(state, arg1, arg2);
+}
+
+/**
* Parse -{min,max}depth N.
*/
static struct expr *parse_depth_limit(struct parser_state *state, int is_min, int arg2) {
@@ -1800,7 +1817,7 @@ static const struct table_entry parse_table[] = {
{"d", false, parse_depth},
{"daystart", false, parse_daystart},
{"delete", false, parse_delete},
- {"depth", false, parse_depth},
+ {"depth", false, parse_depth_n},
{"empty", false, parse_empty},
{"exec", false, parse_exec, 0},
{"execdir", false, parse_exec, EXEC_CHDIR},