Date: Sat, 14 Nov 1998 20:50:02 +0100 From: Wolfram Schneider <wosch@panke.de.freebsd.org> To: current@FreeBSD.ORG Subject: sort option for find Message-ID: <19981114205002.A27346@panke.de.freebsd.org>
next in thread | raw e-mail | index | archive | help
--azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii I want add a sort option to find(1). The sort option make it possible to build the locate database without large (usually 20-100MB) temp files. `find -s /dir' is a little bit slower than `find /dir | sort'. I don't think users care if locate.updated runs 5% longer if they save disk space and error mails. -s The -s option cause find to traverse the file hierarchies in lex- icographical order. The output will be sorted too. --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="d.find" Index: find.1 =================================================================== RCS file: /a/ncvs/src/usr.bin/find/find.1,v retrieving revision 1.15 diff -u -r1.15 find.1 --- find.1 1998/05/15 11:22:36 1.15 +++ find.1 1998/11/14 19:27:39 @@ -44,7 +44,7 @@ .Sh SYNOPSIS .Nm find .Op Fl H | Fl L | Fl P -.Op Fl Xdx +.Op Fl Xdsx .Op Fl f Ar file .Op Ar file ... .Ar expression @@ -121,6 +121,13 @@ to traverse. File hierarchies may also be specified as the operands immediately following the options. +.It Fl s +The +.Fl s +option cause +.Nm find +to traverse the file hierarchies in lexicographical order. The +output will be sorted too. .It Fl x The .Fl x Index: find.c =================================================================== RCS file: /a/ncvs/src/usr.bin/find/find.c,v retrieving revision 1.4 diff -u -r1.4 find.c --- find.c 1997/03/11 13:48:23 1.4 +++ find.c 1998/11/14 18:43:09 @@ -50,6 +50,8 @@ #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 @@ -140,6 +142,19 @@ } FTS *tree; /* pointer to top of FTS hierarchy */ +extern int sflag; + +/* + * 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 -- @@ -155,7 +170,8 @@ PLAN *p; int rval; - if ((tree = fts_open(paths, ftsoptions, (int (*)())NULL)) == NULL) + if ((tree = fts_open(paths, ftsoptions, + (sflag ? find_compare : NULL) )) == NULL) err(1, "ftsopen"); for (rval = 0; (entry = fts_read(tree)) != NULL;) { Index: main.c =================================================================== RCS file: /a/ncvs/src/usr.bin/find/main.c,v retrieving revision 1.6 diff -u -r1.6 main.c --- main.c 1997/05/19 18:16:29 1.6 +++ main.c 1998/11/14 18:23:19 @@ -66,6 +66,7 @@ int isdepth; /* do directories on post-order visit */ int isoutput; /* user specified output operator */ int isxargs; /* don't permit xargs delimiting chars */ +int sflag; /* travel the file hierarchy lexicographical order */ static void usage __P((void)); @@ -84,7 +85,7 @@ p = start = argv; Hflag = Lflag = 0; ftsoptions = FTS_NOSTAT | FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "HLPXdf:x")) != -1) + while ((ch = getopt(argc, argv, "HLPXdf:sx")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -105,6 +106,9 @@ break; case 'f': *p++ = optarg; + break; + case 's': + sflag = 1; break; case 'x': ftsoptions |= FTS_XDEV; --azLHFNyN32YCQGCU-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19981114205002.A27346>