From owner-freebsd-questions Fri Apr 28 13:52:35 2000 Delivered-To: freebsd-questions@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id 080D837B939 for ; Fri, 28 Apr 2000 13:52:19 -0700 (PDT) (envelope-from ben@scientia.demon.co.uk) Received: from strontium.scientia.demon.co.uk ([192.168.91.36] ident=exim) by scientia.demon.co.uk with esmtp (Exim 3.12 #1) id 12lHFD-0005rB-00; Fri, 28 Apr 2000 21:20:11 +0100 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.12 #7) id 12lHFC-0007h8-00; Fri, 28 Apr 2000 21:20:10 +0100 Date: Fri, 28 Apr 2000 21:20:10 +0100 From: Ben Smithurst To: Shawn Barnhart Cc: questions@FreeBSD.ORG Subject: Re: 'find' command -- maxdepth option? Message-ID: <20000428212010.C17098@strontium.scientia.demon.co.uk> References: <04f101bfb116$e4baafa0$b8209fc0@marlowe> <20000428155325.A86507@strontium.scientia.demon.co.uk> <054301bfb13e$07f775d0$b8209fc0@marlowe> <20000428203156.B17098@strontium.scientia.demon.co.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0ntfKIWw70PvrIHh" X-Mailer: Mutt 1.0i In-Reply-To: <20000428203156.B17098@strontium.scientia.demon.co.uk> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --0ntfKIWw70PvrIHh Content-Type: text/plain; charset=us-ascii Ben Smithurst wrote: > Shawn Barnhart wrote: > >> It seems to work close enough, although it's added complexity. I guess I >> wish there was a -maxdepth option, or a port for gnu findutils. Gnu find >> seems superior to freebsd's find. > > OK, I was bored. :-) Try this patch. It seems to work, so might send-pr it > to get this feature added. Turns out this patch is broken. It prints out the right files, but it still descends further than it should. I guess that needs fixing before I send-pr it. ... hack hack hack ... Try this one instead, perhaps I'll send-pr this one. :-) It also has -mindepth. -- Ben Smithurst / ben@scientia.demon.co.uk / PGP: 0x99392F7D --0ntfKIWw70PvrIHh Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="find.diff" Index: extern.h =================================================================== RCS file: /usr/cvs/src/usr.bin/find/extern.h,v retrieving revision 1.9 diff -u -r1.9 extern.h --- extern.h 1999/12/19 15:43:18 1.9 +++ extern.h 2000/04/28 19:42:08 @@ -80,6 +80,8 @@ PLAN *c_xdev __P((void)); PLAN *c_openparen __P((void)); PLAN *c_closeparen __P((void)); +PLAN *c_maxdepth __P((char *)); +PLAN *c_mindepth __P((char *)); PLAN *c_mmin __P((char *)); PLAN *c_mtime __P((char *)); PLAN *c_not __P((void)); Index: find.1 =================================================================== RCS file: /usr/cvs/src/usr.bin/find/find.1,v retrieving revision 1.23 diff -u -r1.23 find.1 --- find.1 2000/03/01 10:48:32 1.23 +++ find.1 2000/04/28 19:48:12 @@ -245,6 +245,12 @@ If the file is a symbolic link, the pathname of the linked\-to file will be displayed preceded by ``\->''. The format is identical to that produced by ``ls \-dgils''. +.It Ic -maxdepth Ar n +True if the depth of the current file into the tree is less than or equal to +.Ar n . +.It Ic -mindepth Ar n +True if the depth of the current file into the tree is greater than or equal to +.Ar n . .It Ic -mmin Ar n True if the difference between the file last modification time and the time .Nm find Index: find.h =================================================================== RCS file: /usr/cvs/src/usr.bin/find/find.h,v retrieving revision 1.6 diff -u -r1.6 find.h --- find.h 1999/12/19 15:43:18 1.6 +++ find.h 2000/04/28 19:44:31 @@ -46,7 +46,7 @@ N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV, - N_PRINT0, N_DELETE + N_PRINT0, N_DELETE, N_MAXDEPTH, N_MINDEPTH }; /* node definition */ Index: function.c =================================================================== RCS file: /usr/cvs/src/usr.bin/find/function.c,v retrieving revision 1.22 diff -u -r1.22 function.c --- function.c 2000/02/05 18:42:34 1.22 +++ function.c 2000/04/28 20:14:17 @@ -717,6 +717,55 @@ } /* + * -{max,min}depth n functions -- + * + * True if the current depth is mindepth <= n <= maxdepth. + */ +int +f_maxdepth(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern FTS *tree; + + if (entry->fts_level >= plan->t_data && fts_set(tree, entry, FTS_SKIP)) + err(1, "%s", entry->fts_path); + return (1); +} + +PLAN * +c_maxdepth(arg) + char *arg; +{ + PLAN *new; + + new = palloc(N_MAXDEPTH, f_maxdepth); + new->t_data = find_parsenum(new, "-maxdepth", arg, NULL); + return (new); + +} + +int +f_mindepth(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + + return (entry->fts_level >= plan->t_data); +} + +PLAN * +c_mindepth(arg) + char *arg; +{ + PLAN *new; + + new = palloc(N_MINDEPTH, f_mindepth); + new->t_data = find_parsenum(new, "-mindepth", arg, NULL); + return (new); +} + +/* * -mtime n functions -- * * True if the difference between the file modification time and the Index: option.c =================================================================== RCS file: /usr/cvs/src/usr.bin/find/option.c,v retrieving revision 1.9 diff -u -r1.9 option.c --- option.c 1999/12/19 15:43:19 1.9 +++ option.c 2000/04/28 19:41:56 @@ -84,6 +84,8 @@ { "-inum", N_INUM, c_inum, O_ARGV }, { "-links", N_LINKS, c_links, O_ARGV }, { "-ls", N_LS, c_ls, O_ZERO }, + { "-maxdepth", N_MAXDEPTH, c_maxdepth, O_ARGV }, + { "-mindepth", N_MINDEPTH, c_mindepth, O_ARGV }, { "-mmin", N_MMIN, c_mmin, O_ARGV }, { "-mtime", N_MTIME, c_mtime, O_ARGV }, { "-name", N_NAME, c_name, O_ARGV }, --0ntfKIWw70PvrIHh-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message