Add a FreeBSD-specific -S flag which controls the maximum size of an argument

having replacements done in it via -I.
This commit is contained in:
Juli Mallett 2005-12-30 23:25:41 +00:00
parent 38e62c6999
commit ba084f6a80
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=153918
2 changed files with 34 additions and 10 deletions

View File

@ -50,6 +50,7 @@
.Oo
.Fl I Ar replstr
.Op Fl R Ar replacements
.Op Fl S Ar replsize
.Oc
.Op Fl J Ar replstr
.Op Fl L Ar number
@ -114,13 +115,20 @@ 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
beyond 255 bytes; this is implemented by concatenating as much of the argument
beyond
.Ar replsize
(or 255 if no
.Fl S
flag is specified)
bytes; this is implemented by concatenating as much of the argument
containing
.Ar replstr
as possible, to the constructed arguments to
.Ar utility ,
up to 255 bytes.
The 255 byte limit does not apply to arguments to
up to
.Ar replsize
bytes.
The size limit does not apply to arguments to
.Ar utility
which do not contain
.Ar replstr ,
@ -220,6 +228,13 @@ will do replacement in.
If
.Ar replacements
is negative, the number of arguments in which to replace is unbounded.
.It Fl S Ar replsize
Specify the amount of space (in bytes) that
.Fl I
can use for replacements.
The default for
.Ar replsize
is 255.
.It Fl s Ar size
Set the maximum number of bytes for the command line length provided to
.Ar utility .
@ -293,7 +308,7 @@ utility is expected to be
.St -p1003.2
compliant.
The
.Fl J , o , P
.Fl J , o , P, S
and
.Fl R
options are non-standard

View File

@ -80,7 +80,7 @@ static char **av, **bxp, **ep, **endxp, **xp;
static char *argp, *bbp, *ebp, *inpline, *p, *replstr;
static const char *eofstr;
static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
static int cnt, Iflag, jfound, Lflag, wasquoted, xflag;
static int cnt, Iflag, jfound, Lflag, Sflag, wasquoted, xflag;
static int curprocs, maxprocs;
static volatile int childerr;
@ -124,7 +124,7 @@ main(int argc, char *argv[])
nline -= strlen(*ep++) + 1 + sizeof(*ep);
}
maxprocs = 1;
while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:rtx")) != -1)
while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:S:s:rtx")) != -1)
switch(ch) {
case 'E':
eofstr = optarg;
@ -166,6 +166,11 @@ main(int argc, char *argv[])
case 'r':
/* GNU compatibility */
break;
case 'S':
Sflag = strtoul(optarg, &endptr, 10);
if (*endptr != '\0')
errx(1, "replsize must be a number");
break;
case 's':
nline = atoi(optarg);
break;
@ -187,8 +192,12 @@ main(int argc, char *argv[])
if (!Iflag && Rflag)
usage();
if (!Iflag && Sflag)
usage();
if (Iflag && !Rflag)
Rflag = 5;
if (Iflag && !Sflag)
Sflag = 255;
if (xflag && !nflag)
usage();
if (Iflag || Lflag)
@ -454,7 +463,7 @@ prerun(int argc, char *argv[])
while (--argc) {
*tmp = *avj++;
if (repls && strstr(*tmp, replstr) != NULL) {
strnsubst(tmp++, replstr, inpline, (size_t)255);
strnsubst(tmp++, replstr, inpline, (size_t)Sflag);
if (repls > 0)
repls--;
} else {
@ -609,8 +618,8 @@ static void
usage(void)
{
fprintf(stderr,
"usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]\n"
" [-L number] [-n number [-x]] [-P maxprocs] [-s size]\n"
" [utility [argument ...]]\n");
"usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements] [-S replsize]]\n"
" [-J replstr] [-L number] [-n number [-x]] [-P maxprocs]\n"
" [-s size] [utility [argument ...]]\n");
exit(1);
}