Reviewed by: Warner Losh <imp@village.org>
Submitted by: Marc Slemko <marcs@znep.com> Obtained from: OpenBSD Add -0 for reading the results of find -0.
This commit is contained in:
parent
b11ecdd6d0
commit
d919888163
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=19318
@ -43,6 +43,7 @@
|
||||
.Nd "construct argument list(s) and execute utility"
|
||||
.Sh SYNOPSIS
|
||||
.Nm xargs
|
||||
.Op Fl 0
|
||||
.Op Fl t
|
||||
.Oo Op Fl x
|
||||
.Fl n Ar number
|
||||
@ -79,6 +80,16 @@ Any single character, including newlines, may be escaped by a backslash.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl 0
|
||||
Changes
|
||||
.Nm xargs
|
||||
to expect NUL
|
||||
(``\\0'')
|
||||
characters as seperators, instead of spaces and newlines.
|
||||
This is expected to be used in concert with the
|
||||
.Fl print0
|
||||
function in
|
||||
.Nm find .
|
||||
.It Fl n Ar number
|
||||
Set the maximum number of arguments taken from standard input for each
|
||||
invocation of the utility.
|
||||
|
@ -55,6 +55,7 @@ static char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93";
|
||||
#include "pathnames.h"
|
||||
|
||||
int tflag, rval;
|
||||
int zflag;
|
||||
|
||||
void err __P((const char *, ...));
|
||||
void run __P((char **));
|
||||
@ -89,7 +90,7 @@ main(argc, argv, env)
|
||||
nline -= strlen(*ep++) + 1 + sizeof(*ep);
|
||||
}
|
||||
nflag = xflag = 0;
|
||||
while ((ch = getopt(argc, argv, "n:s:tx")) != EOF)
|
||||
while ((ch = getopt(argc, argv, "0n:s:tx")) != EOF)
|
||||
switch(ch) {
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
@ -105,6 +106,9 @@ main(argc, argv, env)
|
||||
case 'x':
|
||||
xflag = 1;
|
||||
break;
|
||||
case '0':
|
||||
zflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
@ -178,10 +182,17 @@ main(argc, argv, env)
|
||||
case ' ':
|
||||
case '\t':
|
||||
/* Quotes escape tabs and spaces. */
|
||||
if (insingle || indouble)
|
||||
if (insingle || indouble || zflag)
|
||||
goto addch;
|
||||
goto arg2;
|
||||
case '\0':
|
||||
if (zflag)
|
||||
goto arg2;
|
||||
goto addch;
|
||||
case '\n':
|
||||
if (zflag)
|
||||
goto addch;
|
||||
|
||||
/* Empty lines are skipped. */
|
||||
if (argp == p)
|
||||
continue;
|
||||
@ -212,16 +223,18 @@ arg2: *p = '\0';
|
||||
argp = p;
|
||||
break;
|
||||
case '\'':
|
||||
if (indouble)
|
||||
if (indouble || zflag)
|
||||
goto addch;
|
||||
insingle = !insingle;
|
||||
break;
|
||||
case '"':
|
||||
if (insingle)
|
||||
if (insingle || zflag)
|
||||
goto addch;
|
||||
indouble = !indouble;
|
||||
break;
|
||||
case '\\':
|
||||
if (zflag)
|
||||
goto addch;
|
||||
/* Backslash escapes anything, is escaped by quotes. */
|
||||
if (!insingle && !indouble && (ch = getchar()) == EOF)
|
||||
err("backslash at EOF");
|
||||
@ -295,7 +308,7 @@ void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: xargs [-t] [-n number [-x]] [-s size] [utility [argument ...]]\n");
|
||||
"usage: xargs [-0] [-t] [-n number [-x]] [-s size] [utility [argument ...]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user