Add -s (sort) option, which causes entries in each directory sorted.
Similar to FreeBSD's.
This commit is contained in:
parent
6096ea59cd
commit
6baa6f27af
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: extern.h,v 1.12 1999/07/20 01:28:41 cgd Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.13 2000/03/10 11:46:04 itohy Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
|
@ -87,4 +87,4 @@ PLAN *c_not __P((char ***, int));
|
|||
PLAN *c_or __P((char ***, int));
|
||||
PLAN *c_null __P((char ***, int));
|
||||
|
||||
extern int ftsoptions, isdeprecated, isdepth, isoutput, isxargs;
|
||||
extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: find.c,v 1.11 1998/02/21 22:47:20 christos Exp $ */
|
||||
/* $NetBSD: find.c,v 1.12 2000/03/10 11:46:04 itohy Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "from: @(#)find.c 8.5 (Berkeley) 8/5/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: find.c,v 1.11 1998/02/21 22:47:20 christos Exp $");
|
||||
__RCSID("$NetBSD: find.c,v 1.12 2000/03/10 11:46:04 itohy Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -57,6 +57,8 @@ __RCSID("$NetBSD: find.c,v 1.11 1998/02/21 22:47:20 christos Exp $");
|
|||
|
||||
#include "find.h"
|
||||
|
||||
static int ftscompare __P((const FTSENT **, const FTSENT **));
|
||||
|
||||
/*
|
||||
* find_formplan --
|
||||
* process the command line and create a "plan" corresponding to the
|
||||
|
@ -94,7 +96,7 @@ find_formplan(argv)
|
|||
tail = new;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* if the user didn't specify one of -print, -ok or -exec, then -print
|
||||
* is assumed so we bracket the current expression with parens, if
|
||||
|
@ -116,7 +118,7 @@ find_formplan(argv)
|
|||
tail = new;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* the command line has been completely processed into a search plan
|
||||
* except for the (, ), !, and -o operators. Rearrange the plan so
|
||||
|
@ -145,7 +147,14 @@ find_formplan(argv)
|
|||
plan = or_squish(plan); /* -o's */
|
||||
return (plan);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ftscompare(e1, e2)
|
||||
const FTSENT **e1, **e2;
|
||||
{
|
||||
return strcmp((*e1)->fts_name, (*e2)->fts_name);
|
||||
}
|
||||
|
||||
FTS *tree; /* pointer to top of FTS hierarchy */
|
||||
|
||||
/*
|
||||
|
@ -161,8 +170,8 @@ find_execute(plan, paths)
|
|||
register FTSENT *entry;
|
||||
PLAN *p;
|
||||
int rval;
|
||||
|
||||
if (!(tree = fts_open(paths, ftsoptions, NULL)))
|
||||
|
||||
if (!(tree = fts_open(paths, ftsoptions, issort ? ftscompare : NULL)))
|
||||
err(1, "ftsopen");
|
||||
|
||||
for (rval = 0; (entry = fts_read(tree)) != NULL; ) {
|
||||
|
@ -195,7 +204,7 @@ find_execute(plan, paths)
|
|||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Call all the functions in the execution plan until one is
|
||||
* false or all have been executed. This is where we do all
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: main.c,v 1.11 1999/04/29 02:23:58 simonb Exp $ */
|
||||
/* $NetBSD: main.c,v 1.12 2000/03/10 11:46:04 itohy Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
|
@ -43,7 +43,7 @@ static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
|
|||
#else
|
||||
__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
__RCSID("$NetBSD: main.c,v 1.11 1999/04/29 02:23:58 simonb Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.12 2000/03/10 11:46:04 itohy Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -67,6 +67,7 @@ int ftsoptions; /* options for the ftsopen(3) call */
|
|||
int isdeprecated; /* using deprecated syntax */
|
||||
int isdepth; /* do directories on post-order visit */
|
||||
int isoutput; /* user specified output operator */
|
||||
int issort; /* sort directory entries */
|
||||
int isxargs; /* don't permit xargs delimiting chars */
|
||||
|
||||
int main __P((int, char **));
|
||||
|
@ -86,7 +87,7 @@ main(argc, argv)
|
|||
p = start = alloca(argc * sizeof (char *));
|
||||
|
||||
ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
|
||||
while ((ch = getopt(argc, argv, "HLPXdf:hx")) != EOF)
|
||||
while ((ch = getopt(argc, argv, "HLPXdf:hsx")) != EOF)
|
||||
switch(ch) {
|
||||
case 'H':
|
||||
ftsoptions |= FTS_COMFOLLOW;
|
||||
|
@ -115,6 +116,9 @@ main(argc, argv)
|
|||
ftsoptions &= ~FTS_PHYSICAL;
|
||||
ftsoptions |= FTS_LOGICAL;
|
||||
break;
|
||||
case 's':
|
||||
issort = 1;
|
||||
break;
|
||||
case 'x':
|
||||
ftsoptions |= FTS_XDEV;
|
||||
break;
|
||||
|
@ -123,7 +127,7 @@ main(argc, argv)
|
|||
break;
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue