diff options
author | jmallett <jmallett@FreeBSD.org> | 2005-12-30 23:25:41 +0000 |
---|---|---|
committer | jmallett <jmallett@FreeBSD.org> | 2005-12-30 23:25:41 +0000 |
commit | 1ac616cdd4d9854e7304dc1af29769327ff6bb0c (patch) | |
tree | 42559a95cb42730437e667bb488b83db67b8542d | |
parent | 7618c13881f3aa701a1e45a69ca08b919426dba9 (diff) | |
download | FreeBSD-src-1ac616cdd4d9854e7304dc1af29769327ff6bb0c.zip FreeBSD-src-1ac616cdd4d9854e7304dc1af29769327ff6bb0c.tar.gz |
Add a FreeBSD-specific -S flag which controls the maximum size of an argument
having replacements done in it via -I.
-rw-r--r-- | usr.bin/xargs/xargs.1 | 23 | ||||
-rw-r--r-- | usr.bin/xargs/xargs.c | 21 |
2 files changed, 34 insertions, 10 deletions
diff --git a/usr.bin/xargs/xargs.1 b/usr.bin/xargs/xargs.1 index 928a112..b8fe2c8 100644 --- a/usr.bin/xargs/xargs.1 +++ b/usr.bin/xargs/xargs.1 @@ -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 diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index 5a97ed3..b4a8b83 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -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); } |