bin/66667: [PATCH] find(1): new primary `-level n'
Oliver Eikemeier
eik at FreeBSD.org
Sat May 15 07:40:21 PDT 2004
>Number: 66667
>Category: bin
>Synopsis: [PATCH] find(1): new primary `-level n'
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sat May 15 07:40:19 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator: Oliver Eikemeier
>Release: FreeBSD 4.10-STABLE i386
>Organization:
Fillmore Labs - http://www.fillmore-labs.com/
>Environment:
System: FreeBSD 4.10-STABLE
>Description:
Proposal of a new primary `-level n' for find(1), that is true iff the current file
is n levels deep in the tree. The usual +/- modifiers apply to n, with `-level +-1'
essentially being a noop. Useful to find or prune files at a known depth, without
affecting files with similar characteristics at different depths.
>How-To-Repeat:
An example to list all port directories without Tools (ok, this example lists
some additional files, like packages, distfiles and CVS, but you get the idea):
find /usr/ports -level 1 -name Tools -prune -o -level 2 -type d -print
an rough equivalent using the previous syntax is:
find /usr/ports -mindepth 2 -maxdepth 2 -regex '.*/Tools/[^/]*' -prune -o -type d -print
Basically, this it what I was trying to do before posting PR 66613.
>Fix:
The patch applies to -CURRENT and -STABLE
--- find-level.patch begins here ---
Index: extern.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/find/extern.h,v
retrieving revision 1.20
diff -u -r1.20 extern.h
--- extern.h 3 Apr 2004 17:10:04 -0000 1.20
+++ extern.h 15 May 2004 13:47:45 -0000
@@ -65,6 +65,7 @@
#endif
creat_f c_group;
creat_f c_inum;
+creat_f c_level;
creat_f c_links;
creat_f c_ls;
creat_f c_mXXdepth;
@@ -94,6 +95,7 @@
exec_f f_fstype;
exec_f f_group;
exec_f f_inum;
+exec_f f_level;
exec_f f_links;
exec_f f_ls;
exec_f f_name;
Index: find.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/find/find.1,v
retrieving revision 1.60
diff -u -r1.60 find.1
--- find.1 14 May 2004 12:58:13 -0000 1.60
+++ find.1 15 May 2004 13:47:45 -0000
@@ -408,6 +408,10 @@
Like
.Ic -regex ,
but the match is case insensitive.
+.It Ic -level Ar n
+True if the depth of the file relative to the starting point of the traversal
+is
+.Ar n .
.It Ic -links Ar n
True if the file has
.Ar n
Index: find.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/find/find.h,v
retrieving revision 1.16
diff -u -r1.16 find.h
--- find.h 2 Jun 2002 12:57:41 -0000 1.16
+++ find.h 15 May 2004 14:02:04 -0000
@@ -85,6 +85,7 @@
u_long _f_flags;
u_long _f_notflags;
} fl;
+ short _v_data; /* level depth (-1 to N) */
nlink_t _l_data; /* link count */
off_t _o_data; /* file size */
time_t _t_data; /* time value */
@@ -120,6 +121,7 @@
#define p_data p_un._p_data
#define t_data p_un._t_data
#define u_data p_un._u_data
+#define v_data p_un._v_data
#define re_data p_un._re_data
#define e_argv p_un.ex._e_argv
#define e_orig p_un.ex._e_orig
Index: function.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/find/function.c,v
retrieving revision 1.49
diff -u -r1.49 function.c
--- function.c 3 Apr 2004 17:10:04 -0000 1.49
+++ function.c 15 May 2004 13:47:45 -0000
@@ -943,6 +943,34 @@
}
/*
+ * -level n functions --
+ *
+ * True if the file is at level n in the search tree.
+ */
+int
+f_level(plan, entry)
+ PLAN *plan;
+ FTSENT *entry;
+{
+ COMPARE(entry->fts_level, plan->v_data);
+}
+
+PLAN *
+c_level(option, argvp)
+ OPTION *option;
+ char ***argvp;
+{
+ char *nlevel;
+ PLAN *new;
+
+ nlevel = nextarg(option, argvp);
+
+ new = palloc(option);
+ new->v_data = find_parsenum(new, option->name, nlevel, NULL);
+ return new;
+}
+
+/*
* -links n functions --
*
* True if the file has n links.
Index: option.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/find/option.c,v
retrieving revision 1.21
diff -u -r1.21 option.c
--- option.c 3 Apr 2004 17:10:04 -0000 1.21
+++ option.c 15 May 2004 13:47:45 -0000
@@ -91,6 +91,7 @@
{ "-inum", c_inum, f_inum, 0 },
{ "-ipath", c_name, f_path, F_IGNCASE },
{ "-iregex", c_regex, f_regex, F_IGNCASE },
+ { "-level", c_level, f_level, 0 },
{ "-links", c_links, f_links, 0 },
{ "-ls", c_ls, f_ls, 0 },
{ "-maxdepth", c_mXXdepth, f_always_true, F_MAXDEPTH },
--- find-level.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list