summaryrefslogtreecommitdiffstats
path: root/usr.bin/find/function.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/find/function.c')
-rw-r--r--usr.bin/find/function.c54
1 files changed, 47 insertions, 7 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 72bf8aa..c0fb6e0 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include "find.h"
@@ -462,11 +463,9 @@ c_delete(OPTION *option, char ***argvp __unused)
/*
- * -depth functions --
+ * always_true --
*
- * Always true, causes descent of the directory hierarchy to be done
- * so that all entries in a directory are acted on before the directory
- * itself.
+ * Always true, used for -maxdepth, -mindepth, -xdev and -follow
*/
int
f_always_true(PLAN *plan __unused, FTSENT *entry __unused)
@@ -474,12 +473,53 @@ f_always_true(PLAN *plan __unused, FTSENT *entry __unused)
return 1;
}
+/*
+ * -depth functions --
+ *
+ * With argument: True if the file is at level n.
+ * Without argument: Always true, causes descent of the directory hierarchy
+ * to be done so that all entries in a directory are acted on before the
+ * directory itself.
+ */
+int
+f_depth(PLAN *plan, FTSENT *entry)
+{
+ if (plan->flags & F_DEPTH)
+ COMPARE(entry->fts_level, plan->d_data);
+ else
+ return 1;
+}
+
PLAN *
-c_depth(OPTION *option, char ***argvp __unused)
+c_depth(OPTION *option, char ***argvp)
{
- isdepth = 1;
+ PLAN *new;
+ char *str;
- return palloc(option);
+ new = palloc(option);
+
+ str = **argvp;
+ if (str && !(new->flags & F_DEPTH)) {
+ /* skip leading + or - */
+ if (*str == '+' || *str == '-')
+ str++;
+ /* skip sign */
+ if (*str == '+' || *str == '-')
+ str++;
+ if (isdigit(*str))
+ new->flags |= F_DEPTH;
+ }
+
+ if (new->flags & F_DEPTH) { /* -depth n */
+ char *ndepth;
+
+ ndepth = nextarg(option, argvp);
+ new->d_data = find_parsenum(new, option->name, ndepth, NULL);
+ } else { /* -d */
+ isdepth = 1;
+ }
+
+ return new;
}
/*
OpenPOWER on IntegriCloud