Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Jun 2000 15:30:04 -0700 (PDT)
From:      Ben Smithurst <ben@scientia.demon.co.uk>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/18941: Adding -{min,max}depth options to find(1)
Message-ID:  <200006022230.PAA18179@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

The following reply was made to PR bin/18941; it has been noted by GNATS.

From: Ben Smithurst <ben@scientia.demon.co.uk>
To: Bill Fumerola <billf@chc-chimes.com>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/18941: Adding -{min,max}depth options to find(1)
Date: Fri, 2 Jun 2000 21:53:04 +0100

 --4SFOXa2GPu3tIq4H
 Content-Type: text/plain; charset=us-ascii
 
 Bill Fumerola wrote:
 
 > On Thu, Jun 01, 2000 at 05:33:03PM +0100, Ben Smithurst wrote:
 > 
 >> ok.  Should the #ifndef lint around it all stay?
 > 
 > yes
 
 ok, here's an updated diff.
 
 -- 
 Ben Smithurst / ben@scientia.demon.co.uk / PGP: 0x99392F7D
 
 --4SFOXa2GPu3tIq4H
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="find.diff"
 
 Index: Makefile
 ===================================================================
 RCS file: /usr/cvs/src/usr.bin/find/Makefile,v
 retrieving revision 1.8
 diff -u -r1.8 Makefile
 --- Makefile	2000/02/05 18:42:34	1.8
 +++ Makefile	2000/06/01 16:36:09
 @@ -1,6 +1,7 @@
  #	@(#)Makefile	8.1 (Berkeley) 6/6/93
  # $FreeBSD: src/usr.bin/find/Makefile,v 1.8 2000/02/05 18:42:34 joe Exp $
  
 +CFLAGS+=	-Wall
  PROG=	find
  SRCS=	find.c function.c ls.c main.c misc.c operator.c option.c setflags.c
  .PATH:	${.CURDIR}/../../lib/libc/gen
 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/30 02:03:36
 @@ -80,9 +80,12 @@
  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));
  PLAN	*c_or __P((void));
  
 -extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs;
 +extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs,
 +    mindepth, maxdepth;
 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.c
 ===================================================================
 RCS file: /usr/cvs/src/usr.bin/find/find.c,v
 retrieving revision 1.7
 diff -u -r1.7 find.c
 --- find.c	1998/11/29 11:34:30	1.7
 +++ find.c	2000/06/01 16:33:29
 @@ -35,7 +35,12 @@
   */
  
  #ifndef lint
 +#if 0
  static char sccsid[] = "@(#)find.c	8.5 (Berkeley) 8/5/94";
 +#else
 +static const char rcsid[] =
 +	"$FreeBSD$";
 +#endif
  #endif /* not lint */
  
  #include <sys/types.h>
 @@ -206,12 +211,21 @@
  			continue;
  		}
  
 +		if (mindepth != -1 && entry->fts_level < mindepth)
 +			continue;
 +
  		/*
  		 * Call all the functions in the execution plan until one is
  		 * false or all have been executed.  This is where we do all
  		 * the work specified by the user on the command line.
  		 */
  		for (p = plan; p && (p->eval)(p, entry); p = p->next);
 +
 +		if (maxdepth != -1 && entry->fts_level >= maxdepth) {
 +			if (fts_set(tree, entry, FTS_SKIP))
 +				err(1, "%s", entry->fts_path);
 +			continue;
 +		}
  	}
  	if (errno)
  		err(1, "fts_read");
 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/06/01 16:33:45
 @@ -35,8 +35,12 @@
   */
  
  #ifndef lint
 +#if 0
  static char sccsid[] = "@(#)function.c	8.10 (Berkeley) 5/4/95";
 -static char rcsid[] = "$FreeBSD: src/usr.bin/find/function.c,v 1.22 2000/02/05 18:42:34 joe Exp $";
 +#else
 +static const char rcsid[] =
 +	"$FreeBSD: src/usr.bin/find/function.c,v 1.22 2000/02/05 18:42:34 joe Exp $";
 +#endif
  #endif /* not lint */
  
  #include <sys/param.h>
 @@ -717,6 +721,68 @@
  }
  
  /*
 + * -maxdepth n functions --
 + *
 + *	Does the same as -prune if the level of the current file is greater
 + *	than the specified maximum depth.
 + *
 + *	Note that -maxdepth and -mindepth are handled specially in
 + *	find_execute() so their f_* functions here do nothing.
 + */
 +int
 +f_maxdepth(plan, entry)
 +	PLAN *plan;
 +	FTSENT *entry;
 +{
 +	return (1);
 +}
 +
 +PLAN *
 +c_maxdepth(arg)
 +	char *arg;
 +{
 +	PLAN *new;
 +
 +	if (*arg == '-')
 +		/* all other errors handled by find_parsenum() */
 +		errx(1, "-maxdepth: %s: value must be positive", arg);
 +
 +	new = palloc(N_MAXDEPTH, f_maxdepth);
 +	maxdepth = find_parsenum(new, "-maxdepth", arg, NULL);
 +	return (new);
 +
 +}
 +
 +/*
 + * -mindepth n functions --
 + *
 + *	True if the current file is at or deeper than the specified minimum
 + *	depth.
 + */
 +int
 +f_mindepth(plan, entry)
 +	PLAN *plan;
 +	FTSENT *entry;
 +{
 +	return (1);
 +}
 +
 +PLAN *
 +c_mindepth(arg)
 +	char *arg;
 +{
 +	PLAN *new;
 +
 +	if (*arg == '-')
 +		/* all other errors handled by find_parsenum() */
 +		errx(1, "-maxdepth: %s: value must be positive", arg);
 +
 +	new = palloc(N_MINDEPTH, f_mindepth);
 +	mindepth = find_parsenum(new, "-mindepth", arg, NULL);
 +	return (new);
 +}
 +
 +/*
   * -mtime n functions --
   *
   *	True if the difference between the file modification time and the
 @@ -1005,9 +1071,6 @@
  #endif
  	return new;
  }
 -  
 -  /*
 -
  
  /*
   * -print functions --
 Index: ls.c
 ===================================================================
 RCS file: /usr/cvs/src/usr.bin/find/ls.c,v
 retrieving revision 1.5
 diff -u -r1.5 ls.c
 --- ls.c	1998/07/06 21:01:14	1.5
 +++ ls.c	2000/06/01 16:34:27
 @@ -32,7 +32,12 @@
   */
  
  #ifndef lint
 +#if 0
  static char sccsid[] = "@(#)ls.c	8.1 (Berkeley) 6/6/93";
 +#else
 +static const char rcsid[] =
 +	"$FreeBSD$";
 +#endif
  #endif /* not lint */
  
  #include <sys/param.h>
 Index: main.c
 ===================================================================
 RCS file: /usr/cvs/src/usr.bin/find/main.c,v
 retrieving revision 1.9
 diff -u -r1.9 main.c
 --- main.c	1998/11/29 11:34:30	1.9
 +++ main.c	2000/06/01 16:34:36
 @@ -41,7 +41,12 @@
  #endif /* not lint */
  
  #ifndef lint
 +#if 0
  static char sccsid[] = "@(#)main.c	8.4 (Berkeley) 5/4/95";
 +#else
 +static const char rcsid[] =
 +	"$FreeBSD$";
 +#endif
  #endif /* not lint */
  
  #include <sys/types.h>
 @@ -67,6 +72,7 @@
  int isoutput;			/* user specified output operator */
  int issort;         		/* do hierarchies in lexicographical order */
  int isxargs;			/* don't permit xargs delimiting chars */
 +int mindepth = -1, maxdepth = -1; /* minimum and maximum depth */
  
  static void usage __P((void));
  
 Index: misc.c
 ===================================================================
 RCS file: /usr/cvs/src/usr.bin/find/misc.c,v
 retrieving revision 1.2
 diff -u -r1.2 misc.c
 --- misc.c	1995/05/30 06:30:13	1.2
 +++ misc.c	2000/06/01 16:34:46
 @@ -35,7 +35,12 @@
   */
  
  #ifndef lint
 +#if 0
  static char sccsid[] = "@(#)misc.c	8.2 (Berkeley) 4/1/94";
 +#else
 +static const char rcsid[] =
 +	"$FreeBSD$";
 +#endif
  #endif /* not lint */
  
  #include <sys/types.h>
 Index: operator.c
 ===================================================================
 RCS file: /usr/cvs/src/usr.bin/find/operator.c,v
 retrieving revision 1.5
 diff -u -r1.5 operator.c
 --- operator.c	1998/11/29 12:17:09	1.5
 +++ operator.c	2000/06/01 16:34:57
 @@ -35,7 +35,12 @@
   */
  
  #ifndef lint
 +#if 0
  static char sccsid[] = "@(#)operator.c	8.1 (Berkeley) 6/6/93";
 +#else
 +static const char rcsid[] =
 +	"$FreeBSD$";
 +#endif
  #endif /* not lint */
  
  #include <sys/types.h>
 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/30 02:18:28
 @@ -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 },
 
 --4SFOXa2GPu3tIq4H--
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006022230.PAA18179>