Add -s (sort) option, which causes entries in each directory sorted.

Similar to FreeBSD's.
This commit is contained in:
itohy 2000-03-10 11:46:04 +00:00
parent 6096ea59cd
commit 6baa6f27af
3 changed files with 27 additions and 14 deletions

View File

@ -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;

View File

@ -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
@ -146,6 +148,13 @@ find_formplan(argv)
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 */
/*
@ -162,7 +171,7 @@ find_execute(plan, paths)
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; ) {

View File

@ -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;