Implement XCU5 prompt mode (-p).

This commit is contained in:
kleink 1999-12-22 14:41:00 +00:00
parent 4ce1b28f8c
commit 1a2a0445fa
2 changed files with 68 additions and 18 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: xargs.1,v 1.9 1999/01/12 00:07:20 lukem Exp $
.\" $NetBSD: xargs.1,v 1.10 1999/12/22 14:41:00 kleink Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -37,7 +37,7 @@
.\"
.\" @(#)xargs.1 8.1 (Berkeley) 6/6/93
.\"
.Dd January 12, 1999
.Dd December 21, 1999
.Dt XARGS 1
.Os
.Sh NAME
@ -46,6 +46,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl 0
.Op Fl p
.Op Fl t
.Oo Op Fl x
.Fl n Ar number
@ -107,6 +108,16 @@ arguments remaining for the last invocation of
The current default value for
.Ar number
is 5000.
.It Fl p
Prompt mode: immediately before each command execution the user is prompted
whether to execute the command instance. If an affirmative response is read
from
.Pa /dev/tty
the command will be executed; otherwise this particular invocation will be
skipped.
This option implies the
.Fl t
option.
.It Fl s Ar size
Set the maximum number of bytes for the command line length provided to
.Ar utility .
@ -148,6 +159,11 @@ 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 FILES
.Bl -tag -width /dev/tty -compact
.It Pa /dev/tty
used to read responses in prompt mode
.El
.Sh DIAGNOSTICS
.Nm
exits with one of the following values:

View File

@ -1,4 +1,4 @@
/* $NetBSD: xargs.c,v 1.11 1998/12/20 15:06:53 christos Exp $ */
/* $NetBSD: xargs.c,v 1.12 1999/12/22 14:41:01 kleink Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -46,27 +46,32 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: xargs.c,v 1.11 1998/12/20 15:06:53 christos Exp $");
__RCSID("$NetBSD: xargs.c,v 1.12 1999/12/22 14:41:01 kleink Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <langinfo.h>
#include <limits.h>
#include <locale.h>
#include <paths.h>
#include <regex.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <locale.h>
#include <signal.h>
#include <err.h>
#include "pathnames.h"
int tflag, zflag, rval;
static int pflag, tflag, zflag, rval;
static FILE *promptfile;
static regex_t yesexpr;
void run __P((char **));
int main __P((int, char **));
void usage __P((void));
static void run __P((char **));
int main __P((int, char **));
static void usage __P((void));
int
main(argc, argv)
@ -96,7 +101,7 @@ main(argc, argv)
nargs = 5000;
nline = ARG_MAX - 4 * 1024;
nflag = xflag = 0;
while ((ch = getopt(argc, argv, "0n:s:tx")) != -1)
while ((ch = getopt(argc, argv, "0n:ps:tx")) != -1)
switch(ch) {
case '0':
zflag = 1;
@ -106,6 +111,9 @@ main(argc, argv)
if ((nargs = atoi(optarg)) <= 0)
errx(1, "illegal argument count");
break;
case 'p':
pflag = tflag = 1;
break;
case 's':
nline = atoi(optarg);
break;
@ -171,6 +179,20 @@ main(argc, argv)
err(1, "malloc");
ebp = (argp = p = bbp) + nline - 1;
if (pflag) {
int error;
if ((promptfile = fopen(_PATH_TTY, "r")) == NULL)
err(1, "prompt mode: cannot open input");
if ((error = regcomp(&yesexpr, nl_langinfo(YESEXPR), REG_NOSUB))
!= 0) {
char msg[NL_TEXTMAX];
(void)regerror(error, NULL, msg, sizeof (msg));
err(1, "cannot compile yesexpr: %s", msg);
}
}
for (insingle = indouble = 0;;)
switch(ch = getchar()) {
case EOF:
@ -269,7 +291,7 @@ addch: if (p < ebp) {
/* NOTREACHED */
}
void
static void
run(argv)
char **argv;
{
@ -282,8 +304,20 @@ run(argv)
(void)fprintf(stderr, "%s", *argv);
for (p = argv + 1; *p; ++p)
(void)fprintf(stderr, " %s", *p);
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
if (pflag) {
char buf[LINE_MAX + 1];
(void)fprintf(stderr, "?...");
fflush(stderr);
if (fgets(buf, sizeof (buf), promptfile) == NULL) {
rval = 1;
return;
}
if (regexec(&yesexpr, buf, 0, NULL, 0) != 0)
return;
} else {
(void)fprintf(stderr, "\n");
}
}
noinvoke = 0;
switch(pid = vfork()) {
@ -331,10 +365,10 @@ run(argv)
}
}
void
static void
usage()
{
(void)fprintf(stderr,
"usage: xargs [-0t] [-n number [-x]] [-s size] [utility [argument ...]]\n");
"usage: xargs [-0pt] [-n number [-x]] [-s size] [utility [argument ...]]\n");
exit(1);
}