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>
This commit is contained in:
@@ -402,34 +402,6 @@ struct globals {
|
||||
G.recurse_flags = ACTION_RECURSE; \
|
||||
} while (0)
|
||||
|
||||
#if ENABLE_FEATURE_FIND_EXEC
|
||||
static unsigned count_subst(const char *str)
|
||||
{
|
||||
unsigned count = 0;
|
||||
while ((str = strstr(str, "{}")) != NULL) {
|
||||
count++;
|
||||
str++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
static char* subst(const char *src, unsigned count, const char* filename)
|
||||
{
|
||||
char *buf, *dst, *end;
|
||||
size_t flen = strlen(filename);
|
||||
/* we replace each '{}' with filename: growth by strlen-2 */
|
||||
buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
|
||||
while ((end = strstr(src, "{}")) != NULL) {
|
||||
dst = mempcpy(dst, src, end - src);
|
||||
dst = mempcpy(dst, filename, flen);
|
||||
src = end + 2;
|
||||
}
|
||||
strcpy(dst, src);
|
||||
return buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return values of ACTFs ('action functions') are a bit mask:
|
||||
* bit 1=1: prune (use SKIP constant for setting it)
|
||||
* bit 0=1: matched successfully (TRUE)
|
||||
@@ -613,7 +585,7 @@ ACTF(exec)
|
||||
char *argv[ap->exec_argc + 1];
|
||||
#endif
|
||||
for (i = 0; i < ap->exec_argc; i++)
|
||||
argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName);
|
||||
argv[i] = xmalloc_substitute_string(ap->exec_argv[i], ap->subst_count[i], "{}", fileName);
|
||||
argv[i] = NULL; /* terminate the list */
|
||||
|
||||
rc = spawn_and_wait(argv);
|
||||
@@ -1091,7 +1063,7 @@ static action*** parse_params(char **argv)
|
||||
ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
|
||||
i = ap->exec_argc;
|
||||
while (i--)
|
||||
ap->subst_count[i] = count_subst(ap->exec_argv[i]);
|
||||
ap->subst_count[i] = count_strstr(ap->exec_argv[i], "{}");
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_FIND_PAREN
|
||||
|
||||
Reference in New Issue
Block a user