diff options
-rw-r--r-- | bfs.h | 1 | ||||
-rw-r--r-- | eval.c | 7 | ||||
-rw-r--r-- | parse.c | 19 | ||||
-rwxr-xr-x | tests.sh | 32 | ||||
-rw-r--r-- | tests/test_0112.out | 6 | ||||
-rw-r--r-- | tests/test_0113.out | 3 | ||||
-rw-r--r-- | tests/test_0114.out | 10 | ||||
-rw-r--r-- | tests/test_0115.out | 6 | ||||
-rw-r--r-- | tests/test_0116.out | 3 | ||||
-rw-r--r-- | tests/test_0117.out | 10 |
10 files changed, 95 insertions, 2 deletions
@@ -285,6 +285,7 @@ bool eval_used(const struct expr *expr, struct eval_state *state); bool eval_gid(const struct expr *expr, struct eval_state *state); bool eval_uid(const struct expr *expr, struct eval_state *state); +bool eval_depth(const struct expr *expr, struct eval_state *state); bool eval_empty(const struct expr *expr, struct eval_state *state); bool eval_hidden(const struct expr *expr, struct eval_state *state); bool eval_inum(const struct expr *expr, struct eval_state *state); @@ -474,6 +474,13 @@ out: } /** + * -depth N test. + */ +bool eval_depth(const struct expr *expr, struct eval_state *state) { + return do_cmp(expr, state->ftwbuf->depth); +} + +/** * -empty test. */ bool eval_empty(const struct expr *expr, struct eval_state *state) { @@ -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}, @@ -705,9 +705,39 @@ function test_0111() { bfs_diff weirdnames -nohidden } +function test_0112() { + [ "$BSD" ] || return 0 + bfs_diff basic -depth 2 +} + +function test_0113() { + [ "$BSD" ] || return 0 + bfs_diff basic -depth +2 +} + +function test_0114() { + [ "$BSD" ] || return 0 + bfs_diff basic -depth -2 +} + +function test_0115() { + [ "$BSD" ] || return 0 + bfs_diff basic -depth -depth 2 +} + +function test_0116() { + [ "$BSD" ] || return 0 + bfs_diff basic -depth -depth +2 +} + +function test_0117() { + [ "$BSD" ] || return 0 + bfs_diff basic -depth -depth -2 +} + result=0 -for i in {1..111}; do +for i in {1..117}; do test="test_$(printf '%04d' $i)" if [ -t 1 ]; then diff --git a/tests/test_0112.out b/tests/test_0112.out new file mode 100644 index 0000000..3bfc1d3 --- /dev/null +++ b/tests/test_0112.out @@ -0,0 +1,6 @@ +basic/c/d +basic/e/f +basic/g/h +basic/j/foo +basic/k/foo +basic/l/foo diff --git a/tests/test_0113.out b/tests/test_0113.out new file mode 100644 index 0000000..847995d --- /dev/null +++ b/tests/test_0113.out @@ -0,0 +1,3 @@ +basic/k/foo/bar +basic/l/foo/bar +basic/l/foo/bar/baz diff --git a/tests/test_0114.out b/tests/test_0114.out new file mode 100644 index 0000000..7575ae4 --- /dev/null +++ b/tests/test_0114.out @@ -0,0 +1,10 @@ +basic +basic/a +basic/b +basic/c +basic/e +basic/g +basic/i +basic/j +basic/k +basic/l diff --git a/tests/test_0115.out b/tests/test_0115.out new file mode 100644 index 0000000..3bfc1d3 --- /dev/null +++ b/tests/test_0115.out @@ -0,0 +1,6 @@ +basic/c/d +basic/e/f +basic/g/h +basic/j/foo +basic/k/foo +basic/l/foo diff --git a/tests/test_0116.out b/tests/test_0116.out new file mode 100644 index 0000000..847995d --- /dev/null +++ b/tests/test_0116.out @@ -0,0 +1,3 @@ +basic/k/foo/bar +basic/l/foo/bar +basic/l/foo/bar/baz diff --git a/tests/test_0117.out b/tests/test_0117.out new file mode 100644 index 0000000..7575ae4 --- /dev/null +++ b/tests/test_0117.out @@ -0,0 +1,10 @@ +basic +basic/a +basic/b +basic/c +basic/e +basic/g +basic/i +basic/j +basic/k +basic/l |