aboutsummaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-02-27 11:17:06 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-02-27 11:17:06 +0100
commit6f068904dc142657bb596f91196f9113f1838cbe (patch)
treeac02741b3c8b74bf3a078aeb13ef7ff1c5e1e23f /findutils/find.c
parent6885e49ba596239a0b0d3631fd72fc2692fbb65c (diff)
downloadbusybox-w32-6f068904dc142657bb596f91196f9113f1838cbe.tar.gz
busybox-w32-6f068904dc142657bb596f91196f9113f1838cbe.tar.bz2
busybox-w32-6f068904dc142657bb596f91196f9113f1838cbe.zip
xargs: add support for -I and -i. Closes 493
function old new delta process_stdin_with_replace - 195 +195 xmalloc_substitute_string - 145 +145 xargs_main 808 884 +76 count_strstr - 45 +45 packed_usage 29580 29571 -9 parse_params 1445 1416 -29 func_exec 285 138 -147 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 1/3 up/down: 461/-185) Total: 276 bytes text data bss dec hex filename 922156 932 17692 940780 e5aec busybox_old 922440 932 17692 941064 e5c08 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c32
1 files changed, 2 insertions, 30 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 044f010b0..6d34f4d68 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -402,34 +402,6 @@ struct globals {
402 G.recurse_flags = ACTION_RECURSE; \ 402 G.recurse_flags = ACTION_RECURSE; \
403} while (0) 403} while (0)
404 404
405#if ENABLE_FEATURE_FIND_EXEC
406static unsigned count_subst(const char *str)
407{
408 unsigned count = 0;
409 while ((str = strstr(str, "{}")) != NULL) {
410 count++;
411 str++;
412 }
413 return count;
414}
415
416
417static char* subst(const char *src, unsigned count, const char* filename)
418{
419 char *buf, *dst, *end;
420 size_t flen = strlen(filename);
421 /* we replace each '{}' with filename: growth by strlen-2 */
422 buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
423 while ((end = strstr(src, "{}")) != NULL) {
424 dst = mempcpy(dst, src, end - src);
425 dst = mempcpy(dst, filename, flen);
426 src = end + 2;
427 }
428 strcpy(dst, src);
429 return buf;
430}
431#endif
432
433/* Return values of ACTFs ('action functions') are a bit mask: 405/* Return values of ACTFs ('action functions') are a bit mask:
434 * bit 1=1: prune (use SKIP constant for setting it) 406 * bit 1=1: prune (use SKIP constant for setting it)
435 * bit 0=1: matched successfully (TRUE) 407 * bit 0=1: matched successfully (TRUE)
@@ -613,7 +585,7 @@ ACTF(exec)
613 char *argv[ap->exec_argc + 1]; 585 char *argv[ap->exec_argc + 1];
614#endif 586#endif
615 for (i = 0; i < ap->exec_argc; i++) 587 for (i = 0; i < ap->exec_argc; i++)
616 argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName); 588 argv[i] = xmalloc_substitute_string(ap->exec_argv[i], ap->subst_count[i], "{}", fileName);
617 argv[i] = NULL; /* terminate the list */ 589 argv[i] = NULL; /* terminate the list */
618 590
619 rc = spawn_and_wait(argv); 591 rc = spawn_and_wait(argv);
@@ -1091,7 +1063,7 @@ static action*** parse_params(char **argv)
1091 ap->subst_count = xmalloc(ap->exec_argc * sizeof(int)); 1063 ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
1092 i = ap->exec_argc; 1064 i = ap->exec_argc;
1093 while (i--) 1065 while (i--)
1094 ap->subst_count[i] = count_subst(ap->exec_argv[i]); 1066 ap->subst_count[i] = count_strstr(ap->exec_argv[i], "{}");
1095 } 1067 }
1096#endif 1068#endif
1097#if ENABLE_FEATURE_FIND_PAREN 1069#if ENABLE_FEATURE_FIND_PAREN