diff -ur findutils-4.2.27.old/lib/buildcmd.c findutils-4.2.27/lib/buildcmd.c --- findutils-4.2.27.old/lib/buildcmd.c 2005-11-23 18:24:02.000000000 +0100 +++ findutils-4.2.27/lib/buildcmd.c 2006-02-20 10:26:03.000000000 +0100 @@ -120,6 +120,7 @@ char *p; int bytes_left = ctl->arg_max - 1; /* Bytes left on the command line. */ int need_prefix; + static int done_replacing = 0; /* XXX: on systems lacking an upper limit for exec args, ctl->arg_max * may have been set to LONG_MAX (see bc_get_arg_max()). Hence @@ -134,7 +135,11 @@ do { size_t len; /* Length in ARG before `replace_pat'. */ - char *s = mbstrstr (arg, ctl->replace_pat); + char *s; + if (!done_replacing) + s = mbstrstr (arg, ctl->replace_pat); + else + s = NULL; /* Pretend we didn't find anything. */ if (s) { need_prefix = 1; @@ -163,6 +168,8 @@ arg += ctl->rplen; arglen -= ctl->rplen; p += lblen; + if (ctl->repl_only_once == 1) + done_replacing = 1; } } while (*arg); @@ -386,6 +393,7 @@ ctl->exec_callback = cb_exec_noop; ctl->lines_per_exec = 0; ctl->args_per_exec = 0; + ctl->repl_only_once = 0; } void diff -ur findutils-4.2.27.old/lib/buildcmd.h findutils-4.2.27/lib/buildcmd.h --- findutils-4.2.27.old/lib/buildcmd.h 2005-11-23 18:36:50.000000000 +0100 +++ findutils-4.2.27/lib/buildcmd.h 2006-02-20 10:23:31.000000000 +0100 @@ -91,6 +91,9 @@ /* The maximum number of arguments to use per command line. */ long args_per_exec; + + /* Wether to replace only the first match. */ + int repl_only_once; /* false */ }; diff -ur findutils-4.2.27.old/xargs/xargs.c findutils-4.2.27/xargs/xargs.c --- findutils-4.2.27.old/xargs/xargs.c 2005-12-04 03:51:36.000000000 +0100 +++ findutils-4.2.27/xargs/xargs.c 2006-02-20 10:22:49.000000000 +0100 @@ -247,6 +247,7 @@ {"delimiter", required_argument, NULL, 'd'}, {"eof", optional_argument, NULL, 'e'}, {"replace", optional_argument, NULL, 'I'}, + {"replace-first", optional_argument, NULL, 'J'}, {"max-lines", optional_argument, NULL, 'l'}, {"max-args", required_argument, NULL, 'n'}, {"interactive", no_argument, NULL, 'p'}, @@ -480,7 +481,7 @@ - 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) @@ -507,6 +508,8 @@ usage (stdout); return 0; + case 'J': /* FreeBSD */ + bc_ctl.repl_only_once = 1; case 'I': /* POSIX */ case 'i': /* deprecated */ if (optarg)