version 1.1, 1995/10/18 08:47:00 |
version 1.2, 1996/06/11 06:48:06 |
|
|
#include "pathnames.h" |
#include "pathnames.h" |
|
|
int tflag, rval; |
int tflag, rval; |
|
int zflag; |
|
|
void run __P((char **)); |
void run __P((char **)); |
void usage __P((void)); |
void usage __P((void)); |
|
|
nargs = 5000; |
nargs = 5000; |
nline = ARG_MAX - 4 * 1024; |
nline = ARG_MAX - 4 * 1024; |
nflag = xflag = 0; |
nflag = xflag = 0; |
while ((ch = getopt(argc, argv, "n:s:tx")) != EOF) |
while ((ch = getopt(argc, argv, "0n:s:tx")) != EOF) |
switch(ch) { |
switch(ch) { |
case 'n': |
case 'n': |
nflag = 1; |
nflag = 1; |
|
|
case 'x': |
case 'x': |
xflag = 1; |
xflag = 1; |
break; |
break; |
|
case '0': |
|
zflag = 1; |
|
break; |
case '?': |
case '?': |
default: |
default: |
usage(); |
usage(); |
|
|
case ' ': |
case ' ': |
case '\t': |
case '\t': |
/* Quotes escape tabs and spaces. */ |
/* Quotes escape tabs and spaces. */ |
if (insingle || indouble) |
if (insingle || indouble || zflag) |
goto addch; |
goto addch; |
goto arg2; |
goto arg2; |
|
case '\0': |
|
if (zflag) |
|
goto arg2; |
|
goto addch; |
case '\n': |
case '\n': |
|
if (zflag) |
|
goto addch; |
|
|
/* Empty lines are skipped. */ |
/* Empty lines are skipped. */ |
if (argp == p) |
if (argp == p) |
continue; |
continue; |
|
|
argp = p; |
argp = p; |
break; |
break; |
case '\'': |
case '\'': |
if (indouble) |
if (indouble || zflag) |
goto addch; |
goto addch; |
insingle = !insingle; |
insingle = !insingle; |
break; |
break; |
case '"': |
case '"': |
if (insingle) |
if (insingle || zflag) |
goto addch; |
goto addch; |
indouble = !indouble; |
indouble = !indouble; |
break; |
break; |
case '\\': |
case '\\': |
|
if (zflag) |
|
goto addch; |
/* Backslash escapes anything, is escaped by quotes. */ |
/* Backslash escapes anything, is escaped by quotes. */ |
if (!insingle && !indouble && (ch = getchar()) == EOF) |
if (!insingle && !indouble && (ch = getchar()) == EOF) |
errx(1, "backslash at EOF"); |
errx(1, "backslash at EOF"); |
|
|
usage() |
usage() |
{ |
{ |
(void)fprintf(stderr, |
(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); |
exit(1); |
} |
} |