From d13a028d3d91883f7904f1da506602a7585990de Mon Sep 17 00:00:00 2001 From: wosch Date: Sun, 29 Nov 1998 00:54:21 +0000 Subject: Added a sort option to find(1). The sort option make it possible to build the locate database without large (usually 20-100MB) temp files. --- usr.bin/find/find.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'usr.bin/find/find.c') diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c index 8afadf8b..c63362a 100644 --- a/usr.bin/find/find.c +++ b/usr.bin/find/find.c @@ -50,6 +50,8 @@ static char sccsid[] = "@(#)find.c 8.5 (Berkeley) 8/5/94"; #include "find.h" +static int find_compare(const FTSENT **s1, const FTSENT **s2); + /* * find_formplan -- * process the command line and create a "plan" corresponding to the @@ -142,6 +144,18 @@ find_formplan(argv) FTS *tree; /* pointer to top of FTS hierarchy */ /* + * find_compare -- + * A function which be used in fts_open() to order the + * traversal of the hierarchy. + * This function give you a lexicographical sorted output. + */ +static int find_compare(s1, s2) + const FTSENT **s1, **s2; +{ + return strcoll( (*s1)->fts_name, (*s2)->fts_name ); +} + +/* * find_execute -- * take a search plan and an array of search paths and executes the plan * over all FTSENT's returned for the given search paths. @@ -155,7 +169,8 @@ find_execute(plan, paths) PLAN *p; int rval; - if ((tree = fts_open(paths, ftsoptions, (int (*)())NULL)) == NULL) + if ((tree = fts_open(paths, ftsoptions, + (issort ? find_compare : NULL) )) == NULL) err(1, "ftsopen"); for (rval = 0; (entry = fts_read(tree)) != NULL;) { -- cgit v1.1