Extend our -R extension which sets the number of arguments in which -I will
replace to support magic values less than zero, which mean to just go nuts and expand as many as we want. MFC after: 2 weeks
This commit is contained in:
parent
08f16c7ae4
commit
3c67516766
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=111581
@ -211,6 +211,9 @@ No commands are executed if the process is not attached to a terminal.
|
||||
Specify the maximum number of arguments that
|
||||
.Fl I
|
||||
will do replacement in.
|
||||
If
|
||||
.Ar replacements
|
||||
is negative, the number of arguments in which to replace is unbounded.
|
||||
.It Fl s Ar size
|
||||
Set the maximum number of bytes for the command line length provided to
|
||||
.Ar utility .
|
||||
|
@ -96,6 +96,7 @@ main(int argc, char *argv[])
|
||||
long arg_max;
|
||||
int ch, Jflag, nargs, nflag, nline;
|
||||
size_t linelen;
|
||||
char *endptr;
|
||||
|
||||
inpline = replstr = NULL;
|
||||
ep = environ;
|
||||
@ -158,8 +159,9 @@ main(int argc, char *argv[])
|
||||
pflag = 1;
|
||||
break;
|
||||
case 'R':
|
||||
if ((Rflag = atoi(optarg)) <= 0)
|
||||
errx(1, "illegal number of replacements");
|
||||
Rflag = strtol(optarg, &endptr, 10);
|
||||
if (*endptr != '\0')
|
||||
errx(1, "replacements must be a number");
|
||||
break;
|
||||
case 's':
|
||||
nline = atoi(optarg);
|
||||
@ -444,7 +446,8 @@ prerun(int argc, char *argv[])
|
||||
*tmp = *avj++;
|
||||
if (repls && strstr(*tmp, replstr) != NULL) {
|
||||
strnsubst(tmp++, replstr, inpline, (size_t)255);
|
||||
repls--;
|
||||
if (repls > 0)
|
||||
repls--;
|
||||
} else {
|
||||
if ((*tmp = strdup(*tmp)) == NULL)
|
||||
errx(1, "strdup failed");
|
||||
|
Loading…
Reference in New Issue
Block a user