diff -NBur ../../orig/findutils-4.1.7/find/defs.h findutils-4.1.7/find/defs.h --- ../../orig/findutils-4.1.7/find/defs.h 2001-05-20 22:39:37.000000000 +0200 +++ findutils-4.1.7/find/defs.h 2002-11-12 15:21:46.000000000 +0100 @@ -348,6 +348,7 @@ boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); +boolean pred_isort PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); @@ -368,6 +369,7 @@ boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); +boolean pred_sort PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); @@ -404,6 +406,8 @@ extern time_t cur_day_start; extern boolean full_days; extern boolean no_leaf_check; +extern boolean dir_sort; +extern boolean dir_isort; extern boolean stay_on_filesystem; extern boolean stop_at_current_level; extern boolean have_stat; diff -NBur ../../orig/findutils-4.1.7/find/find.1 findutils-4.1.7/find/find.1 --- ../../orig/findutils-4.1.7/find/find.1 2001-05-20 22:39:37.000000000 +0200 +++ findutils-4.1.7/find/find.1 2002-11-12 15:21:46.000000000 +0100 @@ -52,6 +52,10 @@ Print a summary of the command-line usage of .B find and exit. +.IP \-isort +Do a case insensitive sorting of directories before further processing. +That will result in a isorted output of +.B find. .IP "\-maxdepth \fIlevels\fR" Descend at most \fIlevels\fR (a non-negative integer) levels of directories below the command line arguments. `\-maxdepth 0' means @@ -79,6 +83,10 @@ in the directory are non-directories (`leaf' files in the directory tree). If only the files' names need to be examined, there is no need to stat them; this gives a significant increase in search speed. +.IP \-sort +Do a sorting of directories before further processing. +That will result in a sorted output of +.B find. .IP "\-version, \-\-version" Print the \fBfind\fR version number and exit. .IP \-xdev diff -NBur ../../orig/findutils-4.1.7/find/find.c findutils-4.1.7/find/find.c --- ../../orig/findutils-4.1.7/find/find.c 2001-05-20 22:39:37.000000000 +0200 +++ findutils-4.1.7/find/find.c 2002-11-12 15:24:17.000000000 +0100 @@ -101,6 +101,12 @@ are non-directories. */ boolean no_leaf_check; +/* If true, do a case insensitive sorting of filenames on the fly. */ +boolean dir_isort; + +/* If true, do a case sensitive sorting of filenames on the fly. */ +boolean dir_sort; + /* If true, don't cross filesystem boundaries. */ boolean stay_on_filesystem; @@ -136,6 +142,9 @@ /* Pointer to the function used to stat files. */ int (*xstat) (); +/* Function to do the comparison in qsort. */ +int strpcmp(); + /* Status value to return to system. */ int exit_status; @@ -175,6 +184,8 @@ full_days = false; no_leaf_check = false; stay_on_filesystem = false; + dir_isort = false; + dir_sort = false; exit_status = 0; dereference = false; #ifdef DEBUG_STAT @@ -280,6 +291,11 @@ if ((*xstat) (".", &starting_stat_buf) != 0) error (1, errno, _("cannot get current directory")); + /* Sort top directories, if requested by a sort option. */ + if (dir_sort || dir_isort) { + for (i = 1; i < argc && strchr ("-!(),", argv[i][0]) == NULL; i++); /* Do nothing*/ + if (--i > 1) qsort (&argv[1],i,sizeof(char *),strpcmp); +} /* If no paths are given, default to ".". */ for (i = 1; i < argc && strchr ("-!(),", argv[i][0]) == NULL; i++) process_top_path (argv[i]); @@ -499,11 +515,13 @@ else { register char *namep; /* Current point in `name_space'. */ + char ** namep_list; /* List of namep pointers for sorting. */ char *cur_path; /* Full path of each file to process. */ char *cur_name; /* Base name of each file to process. */ unsigned cur_path_size; /* Bytes allocated for `cur_path'. */ register unsigned file_len; /* Length of each path to process. */ register unsigned pathname_len; /* PATHLEN plus trailing '/'. */ + register unsigned i,n_items; /* Temporary counters. */ if (pathname[pathlen - 1] == '/') pathname_len = pathlen + 1; /* For '\0'; already have '/'. */ @@ -526,8 +544,21 @@ stat_buf.st_ino != dir_ids[dir_curr].ino) error (1, 0, _("%s changed during execution of %s"), starting_dir, program_name); - for (namep = name_space; *namep; namep += file_len - pathname_len + 1) + /* Introduce pointer array namep_list in case sorting is requested. */ + for (namep = name_space, n_items = 0; *namep; namep += strlen (namep) + 1) + n_items++; + if (n_items) { + namep_list = (char **) xmalloc(sizeof(char *)*n_items); + for (namep = name_space, i = 0; *namep; namep += strlen(namep) + 1) + namep_list[i++] = namep; + if (n_items > 1 && (dir_sort || dir_isort)) + qsort(namep_list,n_items,sizeof(char *),strpcmp); + } + { + for (i = 0; i < n_items; i++) + { + namep = namep_list[i]; /* Append this directory entry's name to the path being searched. */ file_len = pathname_len + strlen (namep); if (file_len > cur_path_size) @@ -561,8 +592,10 @@ process_path (cur_path, cur_name, false, pathname); curdepth--; } + } /* end loop on cnt */ + if (n_items) free (namep_list); - if (strcmp (name, ".")) + if (strcmp (name, ".")) { /* We could go back and do the next command-line arg instead, maybe using longjmp. */ @@ -630,3 +663,11 @@ } return (true); } + +int strpcmp(const char **a, const char **b) +{ +if (dir_sort) + return strcmp(*(char **)a, *(char **)b); +else + return strcasecmp(*(char **)a, *(char **)b); +} diff -NBur ../../orig/findutils-4.1.7/find/parser.c findutils-4.1.7/find/parser.c --- ../../orig/findutils-4.1.7/find/parser.c 2001-05-20 22:39:37.000000000 +0200 +++ findutils-4.1.7/find/parser.c 2002-11-12 15:21:46.000000000 +0100 @@ -80,6 +80,7 @@ static boolean parse_inum PARAMS((char *argv[], int *arg_ptr)); static boolean parse_ipath PARAMS((char *argv[], int *arg_ptr)); static boolean parse_iregex PARAMS((char *argv[], int *arg_ptr)); +static boolean parse_isort PARAMS((char *argv[], int *arg_ptr)); static boolean parse_links PARAMS((char *argv[], int *arg_ptr)); static boolean parse_lname PARAMS((char *argv[], int *arg_ptr)); static boolean parse_ls PARAMS((char *argv[], int *arg_ptr)); @@ -105,6 +106,7 @@ static boolean parse_regex PARAMS((char *argv[], int *arg_ptr)); static boolean insert_regex PARAMS((char *argv[], int *arg_ptr, boolean ignore_case)); static boolean parse_size PARAMS((char *argv[], int *arg_ptr)); +static boolean parse_sort PARAMS((char *argv[], int *arg_ptr)); static boolean parse_true PARAMS((char *argv[], int *arg_ptr)); static boolean parse_type PARAMS((char *argv[], int *arg_ptr)); static boolean parse_uid PARAMS((char *argv[], int *arg_ptr)); @@ -179,6 +181,7 @@ {"inum", parse_inum}, /* GNU, Unix */ {"ipath", parse_ipath}, /* GNU */ {"iregex", parse_iregex}, /* GNU */ + {"isort", parse_isort}, {"links", parse_links}, {"lname", parse_lname}, /* GNU */ {"ls", parse_ls}, /* GNU, Unix */ @@ -206,6 +209,7 @@ {"prune", parse_prune}, {"regex", parse_regex}, /* GNU */ {"size", parse_size}, + {"sort", parse_sort}, {"true", parse_true}, /* GNU */ {"type", parse_type}, {"uid", parse_uid}, /* GNU */ @@ -559,8 +563,8 @@ ( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2\n")); puts (_("\ EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2\n\ -options (always true): -daystart -depth -follow --help\n\ - -maxdepth LEVELS -mindepth LEVELS -mount -noleaf --version -xdev\n\ +options (always true): -daystart -depth -follow --help -isort\n\ + -maxdepth LEVELS -mindepth LEVELS -mount -noleaf -sort --version -xdev\n\ tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N\n")); puts (_("\ -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME\n\ @@ -631,6 +635,13 @@ } static boolean +parse_isort (char **argv,int *arg_ptr) +{ + dir_isort = true; + return (true); +} + +static boolean parse_links (char **argv, int *arg_ptr) { return (insert_num (argv, arg_ptr, pred_links)); @@ -1114,6 +1125,13 @@ } static boolean +parse_sort (char **argv, int *arg_ptr) +{ + dir_sort = true; + return (true); +} + +static boolean parse_true (char **argv, int *arg_ptr) { struct predicate *our_pred; diff -NBur ../../orig/findutils-4.1.7/locate/frcode.c findutils-4.1.7/locate/frcode.c --- ../../orig/findutils-4.1.7/locate/frcode.c 2000-04-12 11:43:28.000000000 +0200 +++ findutils-4.1.7/locate/frcode.c 2002-11-12 15:21:46.000000000 +0100 @@ -21,9 +21,7 @@ see ";login:", March 1983, p. 8. The input is a sorted list of NUL-terminated strings. - (FIXME newline-terminated, until we figure out how to sort - NUL-terminated strings.) - + The output entries are in the same order as the input; each entry consists of an offset-differential count byte (the additional number of characters of prefix of the preceding entry to @@ -126,12 +124,8 @@ fwrite (LOCATEDB_MAGIC, sizeof (LOCATEDB_MAGIC), 1, stdout); - /* FIXME temporary: change the \n to \0 when we figure out how to sort - null-terminated strings. */ - while ((line_len = getline (&path, &pathsize, stdin)) > 0) + while ((line_len = getdelim (&path, &pathsize, '\0', stdin)) > 0) { - path[line_len - 1] = '\0'; /* FIXME temporary: nuke the newline. */ - count = prefix_length (oldpath, path); diffcount = count - oldcount; oldcount = count; diff -NBur ../../orig/findutils-4.1.7/locate/updatedb.sh findutils-4.1.7/locate/updatedb.sh --- ../../orig/findutils-4.1.7/locate/updatedb.sh 2001-05-20 22:39:37.000000000 +0200 +++ findutils-4.1.7/locate/updatedb.sh 2002-11-12 15:21:46.000000000 +0100 @@ -106,36 +106,36 @@ # Make and code the file list. # Sort case insensitively for users' convenience. +# If you want to sort case sensitively replace the find option -isort by -sort rm -f $LOCATE_DB.n trap 'rm -f $LOCATE_DB.n; exit' 1 15 if test $old = no; then -# FIXME figure out how to sort null-terminated strings, and use -print0. { if test -n "$SEARCHPATHS"; then if [ "$LOCALUSER" != "" ]; then su $LOCALUSER -c \ "$find $SEARCHPATHS \ \\( $prunefs_exp \ - -type d -regex '$PRUNEREGEX' \\) -prune -o -print" + -type d -regex '$PRUNEREGEX' \\) -prune -o -print0 -isort" else $find $SEARCHPATHS \ \( $prunefs_exp \ - -type d -regex "$PRUNEREGEX" \) -prune -o -print + -type d -regex "$PRUNEREGEX" \) -prune -o -print0 -isort fi fi if test -n "$NETPATHS"; then if [ "`whoami`" = root ]; then su $NETUSER -c \ - "$find $NETPATHS \\( -type d -regex '$PRUNEREGEX' -prune \\) -o -print" + "$find $NETPATHS \\( -type d -regex '$PRUNEREGEX' -prune \\) -o -print0 -isort" else - $find $NETPATHS \( -type d -regex "$PRUNEREGEX" -prune \) -o -print + $find $NETPATHS \( -type d -regex "$PRUNEREGEX" -prune \) -o -print0 -isort fi fi -} | sort -f | $frcode > $LOCATE_DB.n +} 2> /dev/null | $frcode > $LOCATE_DB.n # To avoid breaking locate while this script is running, put the # results in a temp file, then rename it atomically. @@ -166,29 +166,31 @@ # Alphabetize subdirectories before file entries using tr. James says: # "to get everything in monotonic collating sequence, to avoid some # breakage i'll have to think about." +# If you want to sort case sensitively replace the find option -isort by -sort + { if test -n "$SEARCHPATHS"; then if [ "$LOCALUSER" != "" ]; then su $LOCALUSER -c \ "$find $SEARCHPATHS \ \( $prunefs_exp \ - -type d -regex '$PRUNEREGEX' \) -prune -o -print" + -type d -regex '$PRUNEREGEX' \) -prune -o -print -isort" else $find $SEARCHPATHS \ \( $prunefs_exp \ - -type d -regex "$PRUNEREGEX" \) -prune -o -print + -type d -regex "$PRUNEREGEX" \) -prune -o -print -isort fi fi if test -n "$NETPATHS"; then if [ "`whoami`" = root ]; then su $NETUSER -c \ - "$find $NETPATHS \\( -type d -regex '$PRUNEREGEX' -prune \\) -o -print" + "$find $NETPATHS \\( -type d -regex '$PRUNEREGEX' -prune \\) -o -print -isort" else - $find $NETPATHS \( -type d -regex "$PRUNEREGEX" -prune \) -o -print + $find $NETPATHS \( -type d -regex "$PRUNEREGEX" -prune \) -o -print -isort fi fi -} | tr / '\001' | sort -f | tr '\001' / > $filelist +} > $filelist # Compute the (at most 128) most common bigrams in the file list. $bigram < $filelist | sort | uniq -c | sort -nr |