]> err.no Git - moreutils/commitdiff
parallel: -i will now replace {} inside parameters, before the {} had to be a separat...
authorJoey Hess <joey@kitenet.net>
Tue, 6 Jul 2010 19:06:51 +0000 (15:06 -0400)
committerJoey Hess <joey@kitenet.net>
Tue, 6 Jul 2010 19:06:51 +0000 (15:06 -0400)
debian/changelog
parallel.c

index 588deb70c2d9391ed8e1aeeca5e84861809d7409..3969922192013dc53766f20d8b3dee41644102c3 100644 (file)
@@ -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 <joeyh@debian.org>  Fri, 18 Jun 2010 13:06:47 -0400
 
index 81a4184b01e0b858d1334a65c1c98e51af20e615..d283b96101fbc89ef214436bab316cf1092536f9 100644 (file)
@@ -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);