aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/find/function.c
diff options
context:
space:
mode:
authorOliver Eikemeier <eik@FreeBSD.org>2004-05-28 17:17:15 +0000
committerOliver Eikemeier <eik@FreeBSD.org>2004-05-28 17:17:15 +0000
commit1c8329632ead4c55efc169bdd247330eaa0b50d8 (patch)
treede2701bbe39f57e4860326018916a82714254cdb /usr.bin/find/function.c
parente3aa81b84d547e81938b7953edfbdbc30e976b4f (diff)
downloadsrc-1c8329632ead4c55efc169bdd247330eaa0b50d8.tar.gz
src-1c8329632ead4c55efc169bdd247330eaa0b50d8.zip
Notes
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 72bf8aae6f65..c0fb6e007599 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;
}
/*