Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xargs Implement XCU5 prompt mode (-p).
details: https://anonhg.NetBSD.org/src/rev/1e80f488b2ac
branches: trunk
changeset: 479821:1e80f488b2ac
user: kleink <kleink%NetBSD.org@localhost>
date: Wed Dec 22 14:41:00 1999 +0000
description:
Implement XCU5 prompt mode (-p).
diffstat:
usr.bin/xargs/xargs.1 | 20 +++++++++++++-
usr.bin/xargs/xargs.c | 66 ++++++++++++++++++++++++++++++++++++++------------
2 files changed, 68 insertions(+), 18 deletions(-)
diffs (191 lines):
diff -r aed18fea8ab3 -r 1e80f488b2ac usr.bin/xargs/xargs.1
--- a/usr.bin/xargs/xargs.1 Wed Dec 22 14:39:18 1999 +0000
+++ b/usr.bin/xargs/xargs.1 Wed Dec 22 14:41:00 1999 +0000
@@ -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 @@
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 @@
.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:
diff -r aed18fea8ab3 -r 1e80f488b2ac usr.bin/xargs/xargs.c
--- a/usr.bin/xargs/xargs.c Wed Dec 22 14:39:18 1999 +0000
+++ b/usr.bin/xargs/xargs.c Wed Dec 22 14:41:00 1999 +0000
@@ -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 @@
#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 @@
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 @@
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 @@
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 @@
/* NOTREACHED */
}
-void
+static void
run(argv)
char **argv;
{
@@ -282,8 +304,20 @@
(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 @@
}
}
-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);
}
Home |
Main Index |
Thread Index |
Old Index