From: Joey Hess Date: Tue, 6 Jul 2010 19:06:51 +0000 (-0400) Subject: parallel: -i will now replace {} inside parameters, before the {} had to be a separat... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5af8181d2bb7e08e08fcab7a0d5910acb7a8522;p=moreutils parallel: -i will now replace {} inside parameters, before the {} had to be a separate parameter. --- diff --git a/debian/changelog b/debian/changelog index 588deb7..3969922 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,8 @@ moreutils (0.40) UNRELEASED; urgency=low * lckdo: Now deprecated, since util-linux's flock(1) can do the same thing. + * parallel: -i will now replace {} inside parameters, before the {} had + to be a separate parameter. -- Joey Hess Fri, 18 Jun 2010 13:06:47 -0400 diff --git a/parallel.c b/parallel.c index 81a4184..d283b96 100644 --- a/parallel.c +++ b/parallel.c @@ -52,20 +52,25 @@ void exec_child(char **command, char **arguments, int replace_cb, int nargs) { char **argv; int argc = 0; int i; + char *s; while (command[argc] != 0) { argc++; } - if (replace_cb == 0) + if (! replace_cb) argc++; argv = calloc(sizeof(char*), argc + nargs); for (i = 0; i < argc; i++) { + while (replace_cb && (s=strstr(command[i], "{}"))) { + char *buf=malloc(strlen(command[i]) + strlen(arguments[0])); + s[0]='\0'; + sprintf(buf, "%s%s%s", command[i], arguments[0], s+2); + command[i]=buf; + } argv[i] = command[i]; - if (replace_cb && (strcmp(argv[i], "{}") == 0)) - argv[i] = arguments[0]; } - if (replace_cb == 0) + if (! replace_cb) memcpy(argv + i - 1, arguments, nargs * sizeof(char *)); execvp(argv[0], argv); exit(1);