aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-08-31 19:17:42 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-08-31 19:17:42 +0200
commita61ff51b49478345bdfc05d88b4d9df372faa6b9 (patch)
treeeebe8fec4820e87a89a5a12eb86ce0fbb630ba4e
parentee06264a29c81a2d309c9919222d61ff92aa7b7c (diff)
downloadbusybox-w32-a61ff51b49478345bdfc05d88b4d9df372faa6b9.tar.gz
busybox-w32-a61ff51b49478345bdfc05d88b4d9df372faa6b9.tar.bz2
busybox-w32-a61ff51b49478345bdfc05d88b4d9df372faa6b9.zip
find: add rudimentary support for -exec {} +
function old new delta parse_params 1421 1414 -7 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--findutils/find.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/findutils/find.c b/findutils/find.c
index f9e1ccab6..dd00f37ea 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -748,13 +748,13 @@ static action*** parse_params(char **argv)
748 748
749 /* This is the only place in busybox where we use nested function. 749 /* This is the only place in busybox where we use nested function.
750 * So far more standard alternatives were bigger. */ 750 * So far more standard alternatives were bigger. */
751 /* Suppress a warning "func without a prototype" */ 751 /* Auto decl suppresses "func without a prototype" warning: */
752 auto action* alloc_action(int sizeof_struct, action_fp f); 752 auto action* alloc_action(int sizeof_struct, action_fp f);
753 action* alloc_action(int sizeof_struct, action_fp f) 753 action* alloc_action(int sizeof_struct, action_fp f)
754 { 754 {
755 action *ap; 755 action *ap;
756 appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp)); 756 appp[cur_group] = xrealloc(appp[cur_group], (cur_action+2) * sizeof(*appp));
757 appp[cur_group][cur_action++] = ap = xmalloc(sizeof_struct); 757 appp[cur_group][cur_action++] = ap = xzalloc(sizeof_struct);
758 appp[cur_group][cur_action] = NULL; 758 appp[cur_group][cur_action] = NULL;
759 ap->f = f; 759 ap->f = f;
760 IF_FEATURE_FIND_NOT( ap->invert = invert_flag; ) 760 IF_FEATURE_FIND_NOT( ap->invert = invert_flag; )
@@ -854,16 +854,20 @@ static action*** parse_params(char **argv)
854 IF_FEATURE_FIND_NOT( invert_flag = 0; ) 854 IF_FEATURE_FIND_NOT( invert_flag = 0; )
855 ap = ALLOC_ACTION(exec); 855 ap = ALLOC_ACTION(exec);
856 ap->exec_argv = ++argv; /* first arg after -exec */ 856 ap->exec_argv = ++argv; /* first arg after -exec */
857 ap->exec_argc = 0; 857 /*ap->exec_argc = 0; - ALLOC_ACTION did it */
858 while (1) { 858 while (1) {
859 if (!*argv) /* did not see ';' or '+' until end */ 859 if (!*argv) /* did not see ';' or '+' until end */
860 bb_error_msg_and_die(bb_msg_requires_arg, "-exec"); 860 bb_error_msg_and_die(bb_msg_requires_arg, "-exec");
861 if (LONE_CHAR(argv[0], ';')) 861 // find -exec echo Foo ">{}<" ";"
862 // executes "echo Foo <filename>",
863 // find -exec echo Foo ">{}<" "+"
864 // executes "echo Foo <filename1> <filename2> <filename3>...".
865 // TODO (so far we treat "+" just like ";")
866 if ((argv[0][0] == ';' || argv[0][0] == '+')
867 && argv[0][1] == '\0'
868 ) {
862 break; 869 break;
863 //TODO: implement {} + (like xargs) 870 }
864 // See:
865 // find findutils/ -exec echo ">"{}"<" \;
866 // find findutils/ -exec echo ">"{}"<" +
867 argv++; 871 argv++;
868 ap->exec_argc++; 872 ap->exec_argc++;
869 } 873 }
@@ -936,7 +940,7 @@ static action*** parse_params(char **argv)
936 ap = ALLOC_ACTION(perm); 940 ap = ALLOC_ACTION(perm);
937 ap->perm_char = arg1[0]; 941 ap->perm_char = arg1[0];
938 arg1 = plus_minus_num(arg1); 942 arg1 = plus_minus_num(arg1);
939 ap->perm_mask = 0; 943 /*ap->perm_mask = 0; - ALLOC_ACTION did it */
940 if (!bb_parse_mode(arg1, &ap->perm_mask)) 944 if (!bb_parse_mode(arg1, &ap->perm_mask))
941 bb_error_msg_and_die("invalid mode '%s'", arg1); 945 bb_error_msg_and_die("invalid mode '%s'", arg1);
942 } 946 }
@@ -1022,7 +1026,7 @@ static action*** parse_params(char **argv)
1022 else if (parm == PARM_context) { 1026 else if (parm == PARM_context) {
1023 action_context *ap; 1027 action_context *ap;
1024 ap = ALLOC_ACTION(context); 1028 ap = ALLOC_ACTION(context);
1025 ap->context = NULL; 1029 /*ap->context = NULL; - ALLOC_ACTION did it */
1026 /* SELinux headers erroneously declare non-const parameter */ 1030 /* SELinux headers erroneously declare non-const parameter */
1027 if (selinux_raw_to_trans_context((char*)arg1, &ap->context)) 1031 if (selinux_raw_to_trans_context((char*)arg1, &ap->context))
1028 bb_simple_perror_msg(arg1); 1032 bb_simple_perror_msg(arg1);