Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id conventions. Changed to use err(),errx(),warn(),warnx().
This commit is contained in:
parent
e1436b104d
commit
5bbd8ba446
@ -1,5 +1,5 @@
|
||||
# from: @(#)Makefile 5.1 (Berkeley) 5/11/90
|
||||
# $Id: Makefile,v 1.2 1993/07/30 22:14:23 mycroft Exp $
|
||||
# $NetBSD: Makefile,v 1.3 1994/11/14 06:51:37 jtc Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= xargs
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
/* $NetBSD: pathnames.h,v 1.3 1994/11/14 06:51:38 jtc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -30,8 +32,14 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
<<<<<<< pathnames.h
|
||||
* from: @(#)pathnames.h 5.1 (Berkeley) 4/17/90
|
||||
* $Id: pathnames.h,v 1.2 1993/08/01 18:01:01 mycroft Exp $
|
||||
* $Id: pathnames.h,v 1.3 1994/11/14 06:51:38 jtc Exp $
|
||||
||||||| 1.1.1.2
|
||||
* @(#)pathnames.h 5.1 (Berkeley) 4/17/90
|
||||
=======
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 6/6/93
|
||||
>>>>>>> /var/tmp/T4001951
|
||||
*/
|
||||
|
||||
#define _PATH_ECHO "/bin/echo"
|
||||
|
@ -1,5 +1,7 @@
|
||||
.\" Copyright (c) 1990 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" $NetBSD: xargs.1,v 1.6 1994/11/14 06:51:40 jtc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" John B. Roll Jr. and the Institute of Electrical and Electronics
|
||||
@ -33,34 +35,30 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)xargs.1 5.5 (Berkeley) 6/27/91
|
||||
.\" $Id: xargs.1,v 1.5 1994/01/11 18:49:39 jtc Exp $
|
||||
.\" @(#)xargs.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd June 27, 1991
|
||||
.Dd June 6, 1993
|
||||
.Dt XARGS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm xargs
|
||||
.Nd construct argument list(s) and execute utility.
|
||||
.Nd "construct argument list(s) and execute utility"
|
||||
.Sh SYNOPSIS
|
||||
.Nm xargs
|
||||
.Nm xargs
|
||||
.Op Fl t
|
||||
.Oo
|
||||
.Op Fl x
|
||||
.Oo Op Fl x
|
||||
.Fl n Ar number
|
||||
.Oc
|
||||
.Op Fl s Ar size
|
||||
.Oo
|
||||
.Ar utility
|
||||
.Op Ar argument Ar ...
|
||||
.Oc
|
||||
.Op Ar utility Op Ar arguments ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm xargs
|
||||
utility reads space, tab, newline and end-of-file delimited arguments
|
||||
from the standard input and executes the specified
|
||||
.Ar utility
|
||||
with them as arguments.
|
||||
with them as
|
||||
arguments.
|
||||
.Pp
|
||||
The utility and any arguments specified on the command line are given
|
||||
to the
|
||||
@ -71,8 +69,10 @@ The
|
||||
.Ar utility
|
||||
is repeatedly executed until standard input is exhausted.
|
||||
.Pp
|
||||
Spaces, tabs and newlines may be embedded in arguments using single
|
||||
or double quotes or backslashes.
|
||||
Spaces, tabs and newlines may be embedded in arguments using single
|
||||
(``\ '\ '')
|
||||
.Ek
|
||||
or double (``"'') quotes or backslashes (``\e'').
|
||||
Single quotes escape all non-single quote characters, excluding newlines,
|
||||
up to the matching single quote.
|
||||
Double quotes escape all non-double quote characters, excluding newlines,
|
||||
@ -104,11 +104,13 @@ Set the maximum number of bytes for the command line length provided to
|
||||
.Ar utility .
|
||||
The sum of the length of the utility name and the arguments passed to
|
||||
.Ar utility
|
||||
(including NULL terminators) will be less than or equal to this number.
|
||||
(including
|
||||
.Dv NULL
|
||||
terminators) will be less than or equal to this number.
|
||||
The current default value for
|
||||
.Ar size
|
||||
is
|
||||
.Dv ARG_MAX
|
||||
is
|
||||
.Dv ARG_MAX
|
||||
- 2048.
|
||||
.It Fl t
|
||||
Echo the command to be executed to standard error immediately before it
|
||||
@ -130,6 +132,14 @@ is used.
|
||||
Undefined behavior may occur if
|
||||
.Ar utility
|
||||
reads from the standard input.
|
||||
.Pp
|
||||
The
|
||||
.Nm xargs
|
||||
utility exits immediately (without processing any further input) if a
|
||||
command line cannot be assembled,
|
||||
.Ar utility
|
||||
cannot be invoked, an invocation of the utility is terminated by a signal
|
||||
or an invocation of the utility exits with a value of 255.
|
||||
.Sh DIAGNOSTICS
|
||||
.Nm xargs
|
||||
exits with one of the following values:
|
||||
@ -161,12 +171,13 @@ could not be found.
|
||||
.It 1
|
||||
Some other error occurred.
|
||||
.El
|
||||
.Sh "SEE ALSO"
|
||||
.Sh SEE ALSO
|
||||
.Xr echo 1 ,
|
||||
.Xr find 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm xargs
|
||||
is expected to be
|
||||
utility is expected to be
|
||||
.St -p1003.2
|
||||
compliant.
|
||||
.Sh HISTORY
|
||||
|
@ -1,6 +1,8 @@
|
||||
/* $NetBSD: xargs.c,v 1.7 1994/11/14 06:51:41 jtc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* John B. Roll Jr.
|
||||
@ -35,14 +37,16 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1990, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)xargs.c 5.11 (Berkeley) 6/19/91";*/
|
||||
static char rcsid[] = "$Id: xargs.c,v 1.6 1993/12/31 19:33:53 jtc Exp $";
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static char rcsid[] = "$NetBSD: xargs.c,v 1.7 1994/11/14 06:51:41 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -54,20 +58,19 @@ static char rcsid[] = "$Id: xargs.c,v 1.6 1993/12/31 19:33:53 jtc Exp $";
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <err.h>
|
||||
#include "pathnames.h"
|
||||
|
||||
int exit_status = 0;
|
||||
int tflag;
|
||||
void err __P((const char *, ...));
|
||||
void run(), usage();
|
||||
int tflag, rval;
|
||||
|
||||
void run __P((char **));
|
||||
void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
register int ch;
|
||||
register char *p, *bbp, *ebp, **bxp, **exp, **xp;
|
||||
int cnt, indouble, insingle, nargs, nflag, nline, xflag;
|
||||
@ -96,7 +99,7 @@ main(argc, argv)
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
if ((nargs = atoi(optarg)) <= 0)
|
||||
err("illegal argument count");
|
||||
errx(1, "illegal argument count");
|
||||
break;
|
||||
case 's':
|
||||
nline = atoi(optarg);
|
||||
@ -124,7 +127,7 @@ main(argc, argv)
|
||||
*/
|
||||
if (!(av = bxp =
|
||||
malloc((u_int)(1 + argc + nargs + 1) * sizeof(char **))))
|
||||
err("%s", strerror(errno));
|
||||
err(1, NULL);
|
||||
|
||||
/*
|
||||
* Use the user's name for the utility as argv[0], just like the
|
||||
@ -157,10 +160,10 @@ main(argc, argv)
|
||||
*/
|
||||
nline -= cnt;
|
||||
if (nline <= 0)
|
||||
err("insufficient space for command");
|
||||
errx(1, "insufficient space for command");
|
||||
|
||||
if (!(bbp = malloc((u_int)nline + 1)))
|
||||
err("%s", strerror(errno));
|
||||
err(1, NULL);
|
||||
ebp = (argp = p = bbp) + nline - 1;
|
||||
|
||||
for (insingle = indouble = 0;;)
|
||||
@ -168,13 +171,13 @@ main(argc, argv)
|
||||
case EOF:
|
||||
/* No arguments since last exec. */
|
||||
if (p == bbp)
|
||||
exit(exit_status);
|
||||
exit(rval);
|
||||
|
||||
/* Nothing since end of last argument. */
|
||||
if (argp == p) {
|
||||
*xp = NULL;
|
||||
run(av);
|
||||
exit(exit_status);
|
||||
exit(rval);
|
||||
}
|
||||
goto arg1;
|
||||
case ' ':
|
||||
@ -190,7 +193,7 @@ main(argc, argv)
|
||||
|
||||
/* Quotes do not escape newlines. */
|
||||
arg1: if (insingle || indouble)
|
||||
err("unterminated quote");
|
||||
errx(1, "unterminated quote");
|
||||
|
||||
arg2: *p = '\0';
|
||||
*xp++ = argp;
|
||||
@ -202,11 +205,11 @@ arg2: *p = '\0';
|
||||
*/
|
||||
if (xp == exp || p == ebp || ch == EOF) {
|
||||
if (xflag && xp != exp && p == ebp)
|
||||
err("insufficient space for arguments");
|
||||
errx(1, "insufficient space for arguments");
|
||||
*xp = NULL;
|
||||
run(av);
|
||||
if (ch == EOF)
|
||||
exit(exit_status);
|
||||
exit(rval);
|
||||
p = bbp;
|
||||
xp = bxp;
|
||||
} else
|
||||
@ -226,7 +229,7 @@ arg2: *p = '\0';
|
||||
case '\\':
|
||||
/* Backslash escapes anything, is escaped by quotes. */
|
||||
if (!insingle && !indouble && (ch = getchar()) == EOF)
|
||||
err("backslash at EOF");
|
||||
errx(1, "backslash at EOF");
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
addch: if (p < ebp) {
|
||||
@ -236,10 +239,10 @@ addch: if (p < ebp) {
|
||||
|
||||
/* If only one argument, not enough buffer space. */
|
||||
if (bxp == xp)
|
||||
err("insufficient space for argument");
|
||||
errx(1, "insufficient space for argument");
|
||||
/* Didn't hit argument limit, so if xflag object. */
|
||||
if (xflag)
|
||||
err("insufficient space for arguments");
|
||||
errx(1, "insufficient space for arguments");
|
||||
|
||||
*xp = NULL;
|
||||
run(av);
|
||||
@ -257,9 +260,9 @@ void
|
||||
run(argv)
|
||||
char **argv;
|
||||
{
|
||||
volatile int noinvoke;
|
||||
register char **p;
|
||||
pid_t pid;
|
||||
volatile int noinvoke;
|
||||
int status;
|
||||
|
||||
if (tflag) {
|
||||
@ -272,17 +275,16 @@ run(argv)
|
||||
noinvoke = 0;
|
||||
switch(pid = vfork()) {
|
||||
case -1:
|
||||
err("vfork: %s", strerror(errno));
|
||||
err(1, "vfork");
|
||||
case 0:
|
||||
execvp(argv[0], argv);
|
||||
noinvoke = (errno == ENOENT) ? 127 : 126;
|
||||
(void)fprintf(stderr,
|
||||
"xargs: %s: %s.\n", argv[0], strerror(errno));
|
||||
warn("%s", argv[0]);;
|
||||
_exit(1);
|
||||
}
|
||||
pid = waitpid(pid, &status, 0);
|
||||
if (pid == -1)
|
||||
err("waitpid: %s", strerror(errno));
|
||||
err(1, "waitpid");
|
||||
|
||||
/*
|
||||
* If we couldn't invoke the utility or the utility didn't exit
|
||||
@ -299,19 +301,13 @@ run(argv)
|
||||
*/
|
||||
if (WIFEXITED(status)) {
|
||||
if (WEXITSTATUS (status) == 255) {
|
||||
fprintf (stderr, "xargs: %s exited with status 255\n",
|
||||
argv[0]);
|
||||
warnx ("%s exited with status 255", argv[0]);
|
||||
exit(124);
|
||||
} else if (WEXITSTATUS (status) != 0) {
|
||||
exit_status = 123;
|
||||
rval = 123;
|
||||
}
|
||||
} else if (WIFSTOPPED (status)) {
|
||||
fprintf (stderr, "xargs: %s terminated by signal %d\n",
|
||||
argv[0], WSTOPSIG (status));
|
||||
exit(125);
|
||||
} else if (WIFSIGNALED (status)) {
|
||||
fprintf (stderr, "xargs: %s terminated by signal %d\n",
|
||||
argv[0], WTERMSIG (status));
|
||||
warnx ("%s terminated by signal %d", argv[0], WTERMSIG(status));
|
||||
exit(125);
|
||||
}
|
||||
}
|
||||
@ -320,35 +316,6 @@ void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: xargs [-t] [[-x] -n number] [-s size] [utility [argument ...]]\n");
|
||||
"usage: xargs [-t] [-n number [-x]] [-s size] [utility [argument ...]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if __STDC__
|
||||
err(const char *fmt, ...)
|
||||
#else
|
||||
err(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
(void)fprintf(stderr, "xargs: ");
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
(void)fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user