From owner-freebsd-questions Fri Apr 28 13:52:50 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 B741D37B64A for ; Fri, 28 Apr 2000 13:52:34 -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 12lGUX-0005qO-00; Fri, 28 Apr 2000 20:31:57 +0100 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.12 #7) id 12lGUW-000IkO-00; Fri, 28 Apr 2000 20:31:56 +0100 Date: Fri, 28 Apr 2000 20:31:56 +0100 From: Ben Smithurst To: Shawn Barnhart Cc: questions@FreeBSD.ORG Subject: Re: 'find' command -- maxdepth option? Message-ID: <20000428203156.B17098@strontium.scientia.demon.co.uk> References: <04f101bfb116$e4baafa0$b8209fc0@marlowe> <20000428155325.A86507@strontium.scientia.demon.co.uk> <054301bfb13e$07f775d0$b8209fc0@marlowe> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="+HP7ph2BbKc20aGI" X-Mailer: Mutt 1.0i In-Reply-To: <054301bfb13e$07f775d0$b8209fc0@marlowe> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --+HP7ph2BbKc20aGI Content-Type: text/plain; charset=us-ascii 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. -- Ben Smithurst / ben@scientia.demon.co.uk / PGP: 0x99392F7D --+HP7ph2BbKc20aGI 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:28:44 @@ -80,6 +80,7 @@ PLAN *c_xdev __P((void)); PLAN *c_openparen __P((void)); PLAN *c_closeparen __P((void)); +PLAN *c_maxdepth __P((char *)); PLAN *c_mmin __P((char *)); PLAN *c_mtime __P((char *)); PLAN *c_not __P((void)); 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:27: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 }; /* 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 19:29:25 @@ -717,6 +717,33 @@ } /* + * -maxdepth n functions -- + * + * True if the current depth is <= maxdepth. + */ +int +f_maxdepth(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + + /* using COMPARE() macro makes no sense for -maxdepth */ + return (entry->fts_level <= plan->t_data); +} + +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); + +} + +/* * -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:28:17 @@ -84,6 +84,7 @@ { "-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 }, { "-mmin", N_MMIN, c_mmin, O_ARGV }, { "-mtime", N_MTIME, c_mtime, O_ARGV }, { "-name", N_NAME, c_name, O_ARGV }, --+HP7ph2BbKc20aGI-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message