summaryrefslogtreecommitdiffstats
path: root/usr.bin/xargs
diff options
context:
space:
mode:
authorjmz <jmz@FreeBSD.org>1999-05-23 15:58:22 +0000
committerjmz <jmz@FreeBSD.org>1999-05-23 15:58:22 +0000
commit6a83da626f3be7608a613cb444387330662e6d59 (patch)
treebea65ce1241b343859f3b02f3f6f8d4ea652f5c7 /usr.bin/xargs
parent9f3c1a9bd4a8ed16279e1c4449ba190591d56de7 (diff)
downloadFreeBSD-src-6a83da626f3be7608a613cb444387330662e6d59.zip
FreeBSD-src-6a83da626f3be7608a613cb444387330662e6d59.tar.gz
xargs was spliting the input in a very different way from everyone else,
and was also a bit inconsistent: leading blanks, or any double blanks generated empty arguments, but a trailing blank did not. PR: bin/2630, bin/10914 Submitted by: Arne Henrik Juul <arnej@imf.unit.no>
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r--usr.bin/xargs/xargs.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c
index ec7eea3..41bf75a 100644
--- a/usr.bin/xargs/xargs.c
+++ b/usr.bin/xargs/xargs.c
@@ -45,7 +45,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: xargs.c,v 1.6 1998/06/17 12:58:43 jkoshy Exp $";
+ "$Id: xargs.c,v 1.7 1998/10/13 14:52:32 des Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -70,7 +70,7 @@ main(argc, argv, env)
{
register int ch;
register char *p, *bbp, *ebp, **bxp, **exp, **xp;
- int cnt, indouble, insingle, nargs, nflag, nline, xflag;
+ int cnt, indouble, insingle, nargs, nflag, nline, xflag, wasquoted;
char **av, *argp, **ep = env;
long arg_max;
@@ -95,7 +95,7 @@ main(argc, argv, env)
/* 1 byte for each '\0' */
nline -= strlen(*ep++) + 1 + sizeof(*ep);
}
- nflag = xflag = 0;
+ nflag = xflag = wasquoted = 0;
while ((ch = getopt(argc, argv, "0n:s:tx")) != -1)
switch(ch) {
case 'n':
@@ -177,13 +177,6 @@ main(argc, argv, env)
/* No arguments since last exec. */
if (p == bbp)
exit(rval);
-
- /* Nothing since end of last argument. */
- if (argp == p) {
- *xp = NULL;
- run(av);
- exit(rval);
- }
goto arg1;
case ' ':
case '\t':
@@ -199,24 +192,24 @@ main(argc, argv, env)
if (zflag)
goto addch;
- /* Empty lines are skipped. */
- if (argp == p)
- continue;
-
/* Quotes do not escape newlines. */
arg1: if (insingle || indouble)
errx(1, "unterminated quote");
-arg2: *p = '\0';
- *xp++ = argp;
+arg2:
+ /* Do not make empty args unless they are quoted */
+ if (argp != p || wasquoted) {
+ *p++ = '\0';
+ *xp++ = argp;
+ }
/*
* If max'd out on args or buffer, or reached EOF,
* run the command. If xflag and max'd out on buffer
* but not on args, object.
*/
- if (xp == exp || p == ebp || ch == EOF) {
- if (xflag && xp != exp && p == ebp)
+ if (xp == exp || p > ebp || ch == EOF) {
+ if (xflag && xp != exp && p > ebp)
errx(1, "insufficient space for arguments");
*xp = NULL;
run(av);
@@ -224,19 +217,21 @@ arg2: *p = '\0';
exit(rval);
p = bbp;
xp = bxp;
- } else
- ++p;
+ }
argp = p;
+ wasquoted = 0;
break;
case '\'':
if (indouble || zflag)
goto addch;
insingle = !insingle;
+ wasquoted = 1;
break;
case '"':
if (insingle || zflag)
goto addch;
indouble = !indouble;
+ wasquoted = 1;
break;
case '\\':
if (zflag)
OpenPOWER on IntegriCloud