summaryrefslogtreecommitdiffstats
path: root/usr.bin/xargs
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2002-05-02 02:42:34 +0000
committerjmallett <jmallett@FreeBSD.org>2002-05-02 02:42:34 +0000
commit96a12743eb9e02581876e3fdd9fc785e1eebfbcd (patch)
tree9a8df1d9686ad508823645a78c35a3a772f2d729 /usr.bin/xargs
parentc1bf294b84bd9846c5be9259703c4be92300f3b4 (diff)
downloadFreeBSD-src-96a12743eb9e02581876e3fdd9fc785e1eebfbcd.zip
FreeBSD-src-96a12743eb9e02581876e3fdd9fc785e1eebfbcd.tar.gz
Make -J a proper flag internal to the code (rather than just check for
use of replstr and lack of Iflag), and add -R, which when given with -I controls the number of arguments on which replacement will be done. Some people happen to think it's idiotic to limit to 5 arguments, so let the user override it if they like.
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r--usr.bin/xargs/xargs.115
-rw-r--r--usr.bin/xargs/xargs.c25
2 files changed, 30 insertions, 10 deletions
diff --git a/usr.bin/xargs/xargs.1 b/usr.bin/xargs/xargs.1
index debda8e..23a7798 100644
--- a/usr.bin/xargs/xargs.1
+++ b/usr.bin/xargs/xargs.1
@@ -47,7 +47,10 @@
.Nm
.Op Fl 0pt
.Op Fl E Ar eofstr
-.Op Fl I Ar replstr
+.Oo
+.Fl I Ar replstr
+.Op Fl R Ar replacements
+.Oc
.Op Fl J Ar replstr
.Op Fl L Ar number
.Oo
@@ -104,7 +107,11 @@ Execute
.Ar utility
for each input line, replacing one or more occurences of
.Ar replstr
-in up to 5 arguments to
+in up to
+.Ar replacements
+(or 5 if no
+.Op R
+flag is specified) arguments to
.Ar utility
with the entire line of input.
The resulting arguments after replacement is done will not be allowed to grow
@@ -191,6 +198,10 @@ A response of
.Ql y
causes the command to be executed, any other response causes it to be
skipped.
+.It Fl R Ar replacements
+This option specifies the maximum number of arguments that
+.Op I
+will do replacement in.
.It Fl s Ar size
Set the maximum number of bytes for the command line length provided to
.Ar utility .
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c
index ae18ea8..c5c50d3 100644
--- a/usr.bin/xargs/xargs.c
+++ b/usr.bin/xargs/xargs.c
@@ -76,8 +76,8 @@ int
main(int argc, char **argv)
{
long arg_max;
- int ch, cnt, count, Iflag, indouble, insingle, jfound, lflag;
- int nargs, nflag, nline, wasquoted, foundeof, xflag;
+ int ch, cnt, count, Iflag, indouble, insingle, Jflag, jfound, lflag;
+ int nargs, nflag, nline, Rflag, wasquoted, foundeof, xflag;
size_t linelen;
const char *eofstr;
char **av, **avj, **bxp, **ep, **exp, **xp;
@@ -86,7 +86,8 @@ main(int argc, char **argv)
ep = environ;
inpline = replstr = NULL;
eofstr = "";
- cnt = count = Iflag = jfound = lflag = nflag = xflag = wasquoted = 0;
+ cnt = count = Iflag = Jflag = jfound = lflag = nflag = Rflag = xflag =
+ wasquoted = 0;
/*
* POSIX.2 limits the exec line length to ARG_MAX - 2K. Running that
@@ -109,7 +110,7 @@ main(int argc, char **argv)
/* 1 byte for each '\0' */
nline -= strlen(*ep++) + 1 + sizeof(*ep);
}
- while ((ch = getopt(argc, argv, "0E:I:J:L:n:ps:tx")) != -1)
+ while ((ch = getopt(argc, argv, "0E:I:J:L:n:pR:s:tx")) != -1)
switch(ch) {
case 'E':
eofstr = optarg;
@@ -117,9 +118,11 @@ main(int argc, char **argv)
case 'I':
Iflag = 1;
lflag = 1;
+ Rflag = 5;
replstr = optarg;
break;
case 'J':
+ Jflag = 1;
replstr = optarg;
break;
case 'L':
@@ -133,6 +136,12 @@ main(int argc, char **argv)
case 'p':
pflag = 1;
break;
+ case 'R':
+ if (!Iflag)
+ usage();
+ if ((Rflag = atoi(optarg)) <= 0)
+ errx(1, "illegal number of replacements");
+ break;
case 's':
nline = atoi(optarg);
break;
@@ -177,7 +186,7 @@ main(int argc, char **argv)
cnt = strlen((*bxp++ = echo));
else {
do {
- if (!Iflag && replstr && strcmp(*argv, replstr) == 0) {
+ if (Jflag && strcmp(*argv, replstr) == 0) {
jfound = 1;
argv++;
for (avj = argv; *avj; avj++)
@@ -289,7 +298,7 @@ arg2:
if (tmp == NULL)
err(1, "malloc");
tmp2 = tmp;
- repls = 5;
+ repls = Rflag;
for (avj = av, iter = argc; iter; avj++, iter--) {
*tmp = *avj;
if (avj != av && repls > 0 &&
@@ -424,7 +433,7 @@ static void
usage(void)
{
fprintf(stderr,
-"usage: xargs [-0pt] [-E eofstr] [-I replstr] [-J replstr] [-L number]\n"
-" [-n number [-x] [-s size] [utility [argument ...]]\n");
+"usage: xargs [-0pt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]\n"
+" [-L number] [-n number [-x] [-s size] [utility [argument ...]]\n");
exit(1);
}
OpenPOWER on IntegriCloud