=== modified file 'lib/buildcmd.c' --- lib/buildcmd.c 2011-06-25 13:58:56 +0000 +++ lib/buildcmd.c 2011-06-25 15:41:42 +0000 @@ -545,6 +545,7 @@ assert (ctl->max_arg_count > 0); ctl->rplen = 0u; ctl->replace_pat = NULL; + ctl->replace_single_pat = NULL; ctl->initial_argc = 0; ctl->exec_callback = cb_exec_noop; ctl->lines_per_exec = 0; === modified file 'lib/buildcmd.h' --- lib/buildcmd.h 2011-06-25 13:58:56 +0000 +++ lib/buildcmd.h 2011-06-25 15:41:42 +0000 @@ -89,6 +89,13 @@ initial args. */ char *replace_pat; + /* Like `replace_pat', but: + - Replaces only the single argument that matches exactly with `replace_pat' + (no substring matching). + - Replaces this argument with the whole input, broken into multiple + arguments when it contains spaces or newlines. */ + char *replace_single_pat; + /* Number of initial arguments given on the command line. */ int initial_argc; /* 0 */ === modified file 'xargs/xargs.c' --- xargs/xargs.c 2011-06-25 13:58:56 +0000 +++ xargs/xargs.c 2011-06-25 15:41:42 +0000 @@ -179,6 +179,7 @@ {"delimiter", required_argument, NULL, 'd'}, {"eof", optional_argument, NULL, 'e'}, {"replace", optional_argument, NULL, 'I'}, + {"replace-single", optional_argument, NULL, 'J'}, {"max-lines", optional_argument, NULL, 'l'}, {"max-args", required_argument, NULL, 'n'}, {"interactive", no_argument, NULL, 'p'}, @@ -473,7 +474,7 @@ bc_use_sensible_arg_max (&bc_ctl); } - while ((optc = getopt_long (argc, argv, "+0a:E:e::i::I:l::L:n:prs:txP:d:", + while ((optc = getopt_long (argc, argv, "+0a:E:e::i::I:J:l::L:n:prs:txP:d:", longopts, (int *) 0)) != -1) { switch (optc) @@ -500,12 +501,23 @@ usage (stdout); return 0; + case 'J': /* FreeBSD */ case 'I': /* POSIX */ case 'i': /* deprecated */ - if (optarg) - bc_ctl.replace_pat = optarg; + if (optc == 'J') + { + if (optarg) + bc_ctl.replace_single_pat = optarg; + else + bc_ctl.replace_single_pat = "{}"; + } else - bc_ctl.replace_pat = "{}"; + { + if (optarg) + bc_ctl.replace_pat = optarg; + else + bc_ctl.replace_pat = "{}"; + } /* -i excludes -n -l. */ bc_ctl.args_per_exec = 0; bc_ctl.lines_per_exec = 0; @@ -683,10 +695,21 @@ if (!bc_ctl.replace_pat) { for (; optind < argc; optind++) - bc_push_arg (&bc_ctl, &bc_state, - argv[optind], strlen (argv[optind]) + 1, - NULL, 0, - initial_args); + { + if (bc_ctl.replace_single_pat && !strcmp (argv[optind], bc_ctl.replace_single_pat)) + { + while ((*read_line) () != -1); + bc_ctl.replace_single_pat = NULL; + } + else + { + bc_push_arg (&bc_ctl, &bc_state, + argv[optind], strlen (argv[optind]) + 1, + NULL, 0, + initial_args); + } + } + initial_args = false; bc_ctl.initial_argc = bc_state.cmd_argc; bc_state.cmd_initial_argv_chars = bc_state.cmd_argv_chars;