aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-07-06 20:35:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-07-06 20:35:35 +0200
commitabe22cd17b182153bc883e7d9e3cb04eb2c449ff (patch)
treee80e7c8303596af1ad304e2a3bdcd5fce99c2a57
parent4a85d56c4cda90d0c175f29eb320375d14ead507 (diff)
downloadbusybox-w32-abe22cd17b182153bc883e7d9e3cb04eb2c449ff.tar.gz
busybox-w32-abe22cd17b182153bc883e7d9e3cb04eb2c449ff.tar.bz2
busybox-w32-abe22cd17b182153bc883e7d9e3cb04eb2c449ff.zip
find: implement -quit
function old new delta packed_usage 32816 32846 +30 find_main 446 464 +18 func_quit - 13 +13 parse_params 1495 1505 +10 static.params 210 216 +6 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/0 up/down: 77/0) Total: 77 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 07321c81a..72732615b 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -182,6 +182,13 @@
182//config: If the file is a directory, don't descend into it. Useful for 182//config: If the file is a directory, don't descend into it. Useful for
183//config: exclusion .svn and CVS directories. 183//config: exclusion .svn and CVS directories.
184//config: 184//config:
185//config:config FEATURE_FIND_QUIT
186//config: bool "Enable -quit: exit"
187//config: default y
188//config: depends on FIND
189//config: help
190//config: If this action is reached, 'find' exits.
191//config:
185//config:config FEATURE_FIND_DELETE 192//config:config FEATURE_FIND_DELETE
186//config: bool "Enable -delete: delete files/dirs" 193//config: bool "Enable -delete: delete files/dirs"
187//config: default y 194//config: default y
@@ -318,6 +325,9 @@
318//usage: IF_FEATURE_FIND_DELETE( 325//usage: IF_FEATURE_FIND_DELETE(
319//usage: "\n -delete Delete current file/directory. Turns on -depth option" 326//usage: "\n -delete Delete current file/directory. Turns on -depth option"
320//usage: ) 327//usage: )
328//usage: IF_FEATURE_FIND_QUIT(
329//usage: "\n -quit Exit"
330//usage: )
321//usage: 331//usage:
322//usage:#define find_example_usage 332//usage:#define find_example_usage
323//usage: "$ find / -name passwd\n" 333//usage: "$ find / -name passwd\n"
@@ -375,6 +385,7 @@ IF_FEATURE_FIND_SIZE( ACTS(size, char size_char; off_t size;))
375IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;)) 385IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;))
376IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;)) 386IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
377IF_FEATURE_FIND_PRUNE( ACTS(prune)) 387IF_FEATURE_FIND_PRUNE( ACTS(prune))
388IF_FEATURE_FIND_QUIT( ACTS(quit))
378IF_FEATURE_FIND_DELETE( ACTS(delete)) 389IF_FEATURE_FIND_DELETE( ACTS(delete))
379IF_FEATURE_FIND_EXEC( ACTS(exec, 390IF_FEATURE_FIND_EXEC( ACTS(exec,
380 char **exec_argv; /* -exec ARGS */ 391 char **exec_argv; /* -exec ARGS */
@@ -402,6 +413,7 @@ struct globals {
402 action ***actions; 413 action ***actions;
403 smallint need_print; 414 smallint need_print;
404 smallint xdev_on; 415 smallint xdev_on;
416 smalluint exitstatus;
405 recurse_flags_t recurse_flags; 417 recurse_flags_t recurse_flags;
406 IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;) 418 IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;)
407} FIX_ALIASING; 419} FIX_ALIASING;
@@ -774,6 +786,12 @@ ACTF(prune)
774 return SKIP + TRUE; 786 return SKIP + TRUE;
775} 787}
776#endif 788#endif
789#if ENABLE_FEATURE_FIND_QUIT
790ACTF(quit)
791{
792 exit(G.exitstatus);
793}
794#endif
777#if ENABLE_FEATURE_FIND_DELETE 795#if ENABLE_FEATURE_FIND_DELETE
778ACTF(delete) 796ACTF(delete)
779{ 797{
@@ -954,6 +972,7 @@ static action*** parse_params(char **argv)
954 PARM_print , 972 PARM_print ,
955 IF_FEATURE_FIND_PRINT0( PARM_print0 ,) 973 IF_FEATURE_FIND_PRINT0( PARM_print0 ,)
956 IF_FEATURE_FIND_PRUNE( PARM_prune ,) 974 IF_FEATURE_FIND_PRUNE( PARM_prune ,)
975 IF_FEATURE_FIND_QUIT( PARM_quit ,)
957 IF_FEATURE_FIND_DELETE( PARM_delete ,) 976 IF_FEATURE_FIND_DELETE( PARM_delete ,)
958 IF_FEATURE_FIND_EXEC( PARM_exec ,) 977 IF_FEATURE_FIND_EXEC( PARM_exec ,)
959 IF_FEATURE_FIND_PAREN( PARM_char_brace,) 978 IF_FEATURE_FIND_PAREN( PARM_char_brace,)
@@ -997,6 +1016,7 @@ static action*** parse_params(char **argv)
997 "-print\0" 1016 "-print\0"
998 IF_FEATURE_FIND_PRINT0( "-print0\0" ) 1017 IF_FEATURE_FIND_PRINT0( "-print0\0" )
999 IF_FEATURE_FIND_PRUNE( "-prune\0" ) 1018 IF_FEATURE_FIND_PRUNE( "-prune\0" )
1019 IF_FEATURE_FIND_QUIT( "-quit\0" )
1000 IF_FEATURE_FIND_DELETE( "-delete\0" ) 1020 IF_FEATURE_FIND_DELETE( "-delete\0" )
1001 IF_FEATURE_FIND_EXEC( "-exec\0" ) 1021 IF_FEATURE_FIND_EXEC( "-exec\0" )
1002 IF_FEATURE_FIND_PAREN( "(\0" ) 1022 IF_FEATURE_FIND_PAREN( "(\0" )
@@ -1152,6 +1172,12 @@ static action*** parse_params(char **argv)
1152 (void) ALLOC_ACTION(prune); 1172 (void) ALLOC_ACTION(prune);
1153 } 1173 }
1154#endif 1174#endif
1175#if ENABLE_FEATURE_FIND_QUIT
1176 else if (parm == PARM_quit) {
1177 dbg("%d", __LINE__);
1178 (void) ALLOC_ACTION(quit);
1179 }
1180#endif
1155#if ENABLE_FEATURE_FIND_DELETE 1181#if ENABLE_FEATURE_FIND_DELETE
1156 else if (parm == PARM_delete) { 1182 else if (parm == PARM_delete) {
1157 dbg("%d", __LINE__); 1183 dbg("%d", __LINE__);
@@ -1401,7 +1427,7 @@ static action*** parse_params(char **argv)
1401int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1427int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1402int find_main(int argc UNUSED_PARAM, char **argv) 1428int find_main(int argc UNUSED_PARAM, char **argv)
1403{ 1429{
1404 int i, firstopt, status = EXIT_SUCCESS; 1430 int i, firstopt;
1405 char **past_HLP, *saved; 1431 char **past_HLP, *saved;
1406 1432
1407 INIT_G(); 1433 INIT_G();
@@ -1475,10 +1501,10 @@ int find_main(int argc UNUSED_PARAM, char **argv)
1475 NULL, /* user data */ 1501 NULL, /* user data */
1476 0) /* depth */ 1502 0) /* depth */
1477 ) { 1503 ) {
1478 status |= EXIT_FAILURE; 1504 G.exitstatus |= EXIT_FAILURE;
1479 } 1505 }
1480 } 1506 }
1481 1507
1482 IF_FEATURE_FIND_EXEC_PLUS(status |= flush_exec_plus();) 1508 IF_FEATURE_FIND_EXEC_PLUS(G.exitstatus |= flush_exec_plus();)
1483 return status; 1509 return G.exitstatus;
1484} 1510}