aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-12 16:35:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-12 16:35:24 +0100
commitcef85c2442886eabfc0d023af86843ba90fbe081 (patch)
treec99f7c787f3fbb36cc92f54daefd77d7176f3a10
parent0b8a7723c7351533826283c07b37cf2daa77ecf8 (diff)
downloadbusybox-w32-cef85c2442886eabfc0d023af86843ba90fbe081.tar.gz
busybox-w32-cef85c2442886eabfc0d023af86843ba90fbe081.tar.bz2
busybox-w32-cef85c2442886eabfc0d023af86843ba90fbe081.zip
find: significantly improve hext text. +116 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c105
1 files changed, 56 insertions, 49 deletions
diff --git a/findutils/find.c b/findutils/find.c
index f85381b47..e8747f93b 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -112,11 +112,11 @@
112//config: This option allows find to restrict searches to a single filesystem. 112//config: This option allows find to restrict searches to a single filesystem.
113//config: 113//config:
114//config:config FEATURE_FIND_MAXDEPTH 114//config:config FEATURE_FIND_MAXDEPTH
115//config: bool "Enable -maxdepth N" 115//config: bool "Enable -mindepth N and -maxdepth N"
116//config: default y 116//config: default y
117//config: depends on FIND 117//config: depends on FIND
118//config: help 118//config: help
119//config: This option enables -maxdepth N option. 119//config: This option enables -mindepth N and -maxdepth N option.
120//config: 120//config:
121//config:config FEATURE_FIND_NEWER 121//config:config FEATURE_FIND_NEWER
122//config: bool "Enable -newer: compare file modification times" 122//config: bool "Enable -newer: compare file modification times"
@@ -124,7 +124,7 @@
124//config: depends on FIND 124//config: depends on FIND
125//config: help 125//config: help
126//config: Support the 'find -newer' option for finding any files which have 126//config: Support the 'find -newer' option for finding any files which have
127//config: a modified time that is more recent than the specified FILE. 127//config: modification time that is more recent than the specified FILE.
128//config: 128//config:
129//config:config FEATURE_FIND_INUM 129//config:config FEATURE_FIND_INUM
130//config: bool "Enable -inum: inode number matching" 130//config: bool "Enable -inum: inode number matching"
@@ -684,7 +684,6 @@ static action*** parse_params(char **argv)
684#endif 684#endif
685 PARM_print , 685 PARM_print ,
686 IF_FEATURE_FIND_PRINT0( PARM_print0 ,) 686 IF_FEATURE_FIND_PRINT0( PARM_print0 ,)
687 IF_FEATURE_FIND_DEPTH( PARM_depth ,)
688 IF_FEATURE_FIND_PRUNE( PARM_prune ,) 687 IF_FEATURE_FIND_PRUNE( PARM_prune ,)
689 IF_FEATURE_FIND_DELETE( PARM_delete ,) 688 IF_FEATURE_FIND_DELETE( PARM_delete ,)
690 IF_FEATURE_FIND_EXEC( PARM_exec ,) 689 IF_FEATURE_FIND_EXEC( PARM_exec ,)
@@ -718,7 +717,6 @@ static action*** parse_params(char **argv)
718#endif 717#endif
719 "-print\0" 718 "-print\0"
720 IF_FEATURE_FIND_PRINT0( "-print0\0" ) 719 IF_FEATURE_FIND_PRINT0( "-print0\0" )
721 IF_FEATURE_FIND_DEPTH( "-depth\0" )
722 IF_FEATURE_FIND_PRUNE( "-prune\0" ) 720 IF_FEATURE_FIND_PRUNE( "-prune\0" )
723 IF_FEATURE_FIND_DELETE( "-delete\0" ) 721 IF_FEATURE_FIND_DELETE( "-delete\0" )
724 IF_FEATURE_FIND_EXEC( "-exec\0" ) 722 IF_FEATURE_FIND_EXEC( "-exec\0" )
@@ -739,7 +737,7 @@ static action*** parse_params(char **argv)
739 IF_FEATURE_FIND_SIZE( "-size\0" ) 737 IF_FEATURE_FIND_SIZE( "-size\0" )
740 IF_FEATURE_FIND_CONTEXT("-context\0") 738 IF_FEATURE_FIND_CONTEXT("-context\0")
741 IF_FEATURE_FIND_LINKS( "-links\0" ) 739 IF_FEATURE_FIND_LINKS( "-links\0" )
742 ; 740 ;
743 741
744 action*** appp; 742 action*** appp;
745 unsigned cur_group = 0; 743 unsigned cur_group = 0;
@@ -828,11 +826,6 @@ static action*** parse_params(char **argv)
828 (void) ALLOC_ACTION(print0); 826 (void) ALLOC_ACTION(print0);
829 } 827 }
830#endif 828#endif
831#if ENABLE_FEATURE_FIND_DEPTH
832 else if (parm == PARM_depth) {
833 G.recurse_flags |= ACTION_DEPTHFIRST;
834 }
835#endif
836#if ENABLE_FEATURE_FIND_PRUNE 829#if ENABLE_FEATURE_FIND_PRUNE
837 else if (parm == PARM_prune) { 830 else if (parm == PARM_prune) {
838 IF_FEATURE_FIND_NOT( invert_flag = 0; ) 831 IF_FEATURE_FIND_NOT( invert_flag = 0; )
@@ -859,9 +852,9 @@ static action*** parse_params(char **argv)
859 if (!*argv) /* did not see ';' or '+' until end */ 852 if (!*argv) /* did not see ';' or '+' until end */
860 bb_error_msg_and_die(bb_msg_requires_arg, "-exec"); 853 bb_error_msg_and_die(bb_msg_requires_arg, "-exec");
861 // find -exec echo Foo ">{}<" ";" 854 // find -exec echo Foo ">{}<" ";"
862 // executes "echo Foo <filename>", 855 // executes "echo Foo >FILENAME<",
863 // find -exec echo Foo ">{}<" "+" 856 // find -exec echo Foo ">{}<" "+"
864 // executes "echo Foo <filename1> <filename2> <filename3>...". 857 // executes "echo Foo FILENAME1 FILENAME2 FILENAME3...".
865 // TODO (so far we treat "+" just like ";") 858 // TODO (so far we treat "+" just like ";")
866 if ((argv[0][0] == ';' || argv[0][0] == '+') 859 if ((argv[0][0] == ';' || argv[0][0] == '+')
867 && argv[0][1] == '\0' 860 && argv[0][1] == '\0'
@@ -1051,34 +1044,46 @@ static action*** parse_params(char **argv)
1051} 1044}
1052 1045
1053//usage:#define find_trivial_usage 1046//usage:#define find_trivial_usage
1054//usage: "[PATH]... [EXPRESSION]" 1047//usage: "[OPTIONS] [PATH]... [ACTION]..."
1055//usage:#define find_full_usage "\n\n" 1048//usage:#define find_full_usage "\n\n"
1056//usage: "Search for files. The default PATH is the current directory,\n" 1049//usage: "Search for files and perform actions on them.\n"
1057//usage: "default EXPRESSION is '-print'\n" 1050//usage: "First failed action stops processing of current file.\n"
1058//usage: "\nEXPRESSION may consist of:" 1051//usage: "Defaults: PATH is current directory, action is '-print'\n"
1052//usage: "\nOptions:"
1059//usage: "\n -follow Follow symlinks" 1053//usage: "\n -follow Follow symlinks"
1060//usage: IF_FEATURE_FIND_XDEV( 1054//usage: IF_FEATURE_FIND_XDEV(
1061//usage: "\n -xdev Don't descend directories on other filesystems" 1055//usage: "\n -xdev Don't descend directories on other filesystems"
1062//usage: ) 1056//usage: )
1063//usage: IF_FEATURE_FIND_MAXDEPTH( 1057//usage: IF_FEATURE_FIND_MAXDEPTH(
1064//usage: "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" 1058//usage: "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies"
1065//usage: "\n tests/actions to command line arguments only" 1059//usage: "\n actions to command line arguments only"
1066//usage: )
1067//usage: "\n -mindepth N Don't act on first N levels" 1060//usage: "\n -mindepth N Don't act on first N levels"
1068//usage: "\n -name PATTERN File name (w/o directory name) matches PATTERN" 1061//usage: )
1062//usage: IF_FEATURE_FIND_DEPTH(
1063//usage: "\n -depth Act on directory *after* traversing it"
1064//usage: )
1065//usage: "\n"
1066//usage: IF_FEATURE_FIND_PAREN(
1067//usage: "\n ( ACTIONS ) Group actions for -o / -a"
1068//usage: )
1069//usage: "\n ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2"
1070//usage: "\n ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2"
1071//usage: "\n Note: -a has higher priority than -o"
1072//usage: "\nActions:"
1073//usage: "\n -name PATTERN Match file name (w/o directory name) to PATTERN"
1069//usage: "\n -iname PATTERN Case insensitive -name" 1074//usage: "\n -iname PATTERN Case insensitive -name"
1070//usage: IF_FEATURE_FIND_PATH( 1075//usage: IF_FEATURE_FIND_PATH(
1071//usage: "\n -path PATTERN Path matches PATTERN" 1076//usage: "\n -path PATTERN Match path to PATTERN"
1072//usage: ) 1077//usage: )
1073//usage: IF_FEATURE_FIND_REGEX( 1078//usage: IF_FEATURE_FIND_REGEX(
1074//usage: "\n -regex PATTERN Path matches regex PATTERN" 1079//usage: "\n -regex PATTERN Match path to regex PATTERN"
1075//usage: ) 1080//usage: )
1076//usage: IF_FEATURE_FIND_TYPE( 1081//usage: IF_FEATURE_FIND_TYPE(
1077//usage: "\n -type X File type is X (X is one of: f,d,l,b,c,...)" 1082//usage: "\n -type X File type is X (one of: f,d,l,b,c,...)"
1078//usage: ) 1083//usage: )
1079//usage: IF_FEATURE_FIND_PERM( 1084//usage: IF_FEATURE_FIND_PERM(
1080//usage: "\n -perm NNN Permissions match any of (+NNN), all of (-NNN)," 1085//usage: "\n -perm MASK At least one mask bit (+MASK), all bits (-MASK),"
1081//usage: "\n or exactly NNN" 1086//usage: "\n or exactly MASK bits are set in mode bits"
1082//usage: ) 1087//usage: )
1083//usage: IF_FEATURE_FIND_MTIME( 1088//usage: IF_FEATURE_FIND_MTIME(
1084//usage: "\n -mtime DAYS Modified time is greater than (+N), less than (-N)," 1089//usage: "\n -mtime DAYS Modified time is greater than (+N), less than (-N),"
@@ -1100,9 +1105,6 @@ static action*** parse_params(char **argv)
1100//usage: IF_FEATURE_FIND_GROUP( 1105//usage: IF_FEATURE_FIND_GROUP(
1101//usage: "\n -group NAME File belongs to group NAME (numeric group ID allowed)" 1106//usage: "\n -group NAME File belongs to group NAME (numeric group ID allowed)"
1102//usage: ) 1107//usage: )
1103//usage: IF_FEATURE_FIND_DEPTH(
1104//usage: "\n -depth Process directory name after traversing it"
1105//usage: )
1106//usage: IF_FEATURE_FIND_SIZE( 1108//usage: IF_FEATURE_FIND_SIZE(
1107//usage: "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))" 1109//usage: "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))"
1108//usage: "\n +/-N: file size is bigger/smaller than N" 1110//usage: "\n +/-N: file size is bigger/smaller than N"
@@ -1111,26 +1113,23 @@ static action*** parse_params(char **argv)
1111//usage: "\n -links N Number of links is greater than (+N), less than (-N)," 1113//usage: "\n -links N Number of links is greater than (+N), less than (-N),"
1112//usage: "\n or exactly N" 1114//usage: "\n or exactly N"
1113//usage: ) 1115//usage: )
1114//usage: "\n -print Print (default and assumed)"
1115//usage: IF_FEATURE_FIND_PRINT0(
1116//usage: "\n -print0 Delimit output with null characters rather than"
1117//usage: "\n newlines"
1118//usage: )
1119//usage: IF_FEATURE_FIND_CONTEXT( 1116//usage: IF_FEATURE_FIND_CONTEXT(
1120//usage: "\n -context File has specified security context" 1117//usage: "\n -context CTX File has specified security context"
1121//usage: ) 1118//usage: )
1122//usage: IF_FEATURE_FIND_EXEC( 1119//usage: "\n If none of the following actions is specified, -print is assumed"
1123//usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by the" 1120//usage: "\n -print Print file name"
1124//usage: "\n matching files" 1121//usage: IF_FEATURE_FIND_PRINT0(
1122//usage: "\n -print0 Print file name, NUL terminated"
1125//usage: ) 1123//usage: )
1126//usage: IF_FEATURE_FIND_PRUNE( 1124//usage: IF_FEATURE_FIND_PRUNE(
1127//usage: "\n -prune Stop traversing current subtree" 1125//usage: "\n -prune If current file is directory, don't descend into it"
1128//usage: ) 1126//usage: )
1129//usage: IF_FEATURE_FIND_DELETE( 1127//usage: IF_FEATURE_FIND_EXEC(
1130//usage: "\n -delete Delete files, turns on -depth option" 1128//usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by"
1129//usage: "\n file name. Fails if CMD exits with nonzero"
1131//usage: ) 1130//usage: )
1132//usage: IF_FEATURE_FIND_PAREN( 1131//usage: IF_FEATURE_FIND_DELETE(
1133//usage: "\n (EXPR) Group an expression" 1132//usage: "\n -delete Delete current file/directory. Turns on -depth option"
1134//usage: ) 1133//usage: )
1135//usage: 1134//usage:
1136//usage:#define find_example_usage 1135//usage:#define find_example_usage
@@ -1141,14 +1140,16 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1141int find_main(int argc UNUSED_PARAM, char **argv) 1140int find_main(int argc UNUSED_PARAM, char **argv)
1142{ 1141{
1143 static const char options[] ALIGN1 = 1142 static const char options[] ALIGN1 =
1144 "-follow\0" 1143 "-follow\0"
1145IF_FEATURE_FIND_XDEV( "-xdev\0" ) 1144IF_FEATURE_FIND_XDEV( "-xdev\0" )
1146IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0") 1145IF_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0")
1147 ; 1146IF_FEATURE_FIND_DEPTH( "-depth\0" )
1147 ;
1148 enum { 1148 enum {
1149 OPT_FOLLOW, 1149 OPT_FOLLOW,
1150IF_FEATURE_FIND_XDEV( OPT_XDEV ,) 1150IF_FEATURE_FIND_XDEV( OPT_XDEV ,)
1151IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,) 1151IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
1152IF_FEATURE_FIND_DEPTH( OPT_DEPTH ,)
1152 }; 1153 };
1153 1154
1154 char *arg; 1155 char *arg;
@@ -1181,12 +1182,12 @@ IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
1181/* All options always return true. They always take effect 1182/* All options always return true. They always take effect
1182 * rather than being processed only when their place in the 1183 * rather than being processed only when their place in the
1183 * expression is reached. 1184 * expression is reached.
1184 * We implement: -follow, -xdev, -maxdepth 1185 * We implement: -follow, -xdev, -mindepth, -maxdepth, -depth
1185 */ 1186 */
1186 /* Process options, and replace then with -a */ 1187 /* Process options, and replace then with -a */
1187 /* (-a will be ignored by recursive parser later) */ 1188 /* (-a will be ignored by recursive parser later) */
1188 argp = &argv[firstopt]; 1189 argp = &argv[firstopt];
1189 while ((arg = argp[0])) { 1190 while ((arg = argp[0]) != NULL) {
1190 int opt = index_in_strings(options, arg); 1191 int opt = index_in_strings(options, arg);
1191 if (opt == OPT_FOLLOW) { 1192 if (opt == OPT_FOLLOW) {
1192 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK; 1193 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
@@ -1216,8 +1217,14 @@ IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
1216 bb_show_usage(); 1217 bb_show_usage();
1217 minmaxdepth[opt - OPT_MINDEPTH] = xatoi_positive(argp[1]); 1218 minmaxdepth[opt - OPT_MINDEPTH] = xatoi_positive(argp[1]);
1218 argp[0] = (char*)"-a"; 1219 argp[0] = (char*)"-a";
1219 argp[1] = (char*)"-a";
1220 argp++; 1220 argp++;
1221 argp[0] = (char*)"-a";
1222 }
1223#endif
1224#if ENABLE_FEATURE_FIND_DEPTH
1225 if (opt == OPT_DEPTH) {
1226 G.recurse_flags |= ACTION_DEPTHFIRST;
1227 argp[0] = (char*)"-a";
1221 } 1228 }
1222#endif 1229#endif
1223 argp++; 1230 argp++;