Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/ftp a few user interface and cosmetic tweaks:
details: https://anonhg.NetBSD.org/src/rev/0e172d0ef109
branches: trunk
changeset: 477137:0e172d0ef109
user: lukem <lukem%NetBSD.org@localhost>
date: Tue Oct 12 06:04:59 1999 +0000
description:
a few user interface and cosmetic tweaks:
* confirm(): move from util.c to cmds.c. display mnemonic string in its prompt.
add support for `q' (terminate current xfer), `?' (show help list)
* in various signal handlers, output a linefeed only if fromatty.
* if fgets(stdin) returned NULL (i.e, EOF), clearerr(stdin) because you don't
want future fgets to fail. this is not done for the fgets() in the main
command loop, since ftp will quit at that point.
* unless ftp is invoked with -a, don't retain the anonftp setting between
hosts (`ftp somehost:' sets anonftp, but you don't want that to `stick'
if you close that connection and open a new one).
diffstat:
usr.bin/ftp/cmds.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++----
usr.bin/ftp/extern.h | 3 +-
usr.bin/ftp/fetch.c | 20 +++++++++----
usr.bin/ftp/ftp.1 | 18 +++++++++--
usr.bin/ftp/ftp.c | 13 +++++---
usr.bin/ftp/main.c | 14 ++++++--
usr.bin/ftp/util.c | 40 +++++----------------------
7 files changed, 124 insertions(+), 59 deletions(-)
diffs (truncated from 425 to 300 lines):
diff -r f6deb1ddd13b -r 0e172d0ef109 usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c Tue Oct 12 04:53:45 1999 +0000
+++ b/usr.bin/ftp/cmds.c Tue Oct 12 06:04:59 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cmds.c,v 1.73 1999/10/10 22:33:54 lukem Exp $ */
+/* $NetBSD: cmds.c,v 1.74 1999/10/12 06:04:59 lukem Exp $ */
/*-
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -107,7 +107,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: cmds.c,v 1.73 1999/10/10 22:33:54 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.74 1999/10/12 06:04:59 lukem Exp $");
#endif
#endif /* not lint */
@@ -134,9 +134,6 @@
#include "ftp_var.h"
-sigjmp_buf jabort;
-char *mname;
-
struct types {
char *t_name;
char *t_mode;
@@ -151,6 +148,63 @@
{ NULL }
};
+sigjmp_buf jabort;
+char *mname;
+
+static int confirm __P((const char *, const char *));
+
+static int
+confirm(cmd, file)
+ const char *cmd, *file;
+{
+ char line[BUFSIZ];
+
+ if (!interactive || confirmrest)
+ return (1);
+ while (1) {
+ fprintf(ttyout, "%s %s [anpqy?]? ", cmd, file);
+ (void)fflush(ttyout);
+ if (fgets(line, sizeof(line), stdin) == NULL) {
+ mflag = 0;
+ fprintf(ttyout, "\nEOF received; %s aborted\n", mname);
+ clearerr(stdin);
+ return (0);
+ }
+ switch (tolower(*line)) {
+ case 'a':
+ confirmrest = 1;
+ fprintf(ttyout,
+ "Prompting off for duration of %s.\n", cmd);
+ break;
+ case 'n':
+ return (0);
+ case 'p':
+ interactive = 0;
+ fputs("Interactive mode: off.\n", ttyout);
+ break;
+ case 'q':
+ mflag = 0;
+ fprintf(ttyout, "%s aborted\n", mname);
+ return (0);
+ case 'y':
+ default:
+ return (1);
+ case '?':
+ fprintf(ttyout,
+ " confirmation options:\n"
+ "\ta answer `yes' for the duration of %s\n"
+ "\tn answer `no' for this file\n"
+ "\tp turn off `prompt' mode\n"
+ "\tq stop the current %s\n"
+ "\ty answer `yes' for this file\n"
+ "\t? this help list\n",
+ cmd, cmd);
+ break;
+ }
+ }
+ /* NOTREACHED */
+}
+
/*
* Set transfer type.
*/
@@ -570,7 +624,8 @@
{
alarmtimer(0);
- write(fileno(ttyout), "\n", 1);
+ if (fromatty)
+ write(fileno(ttyout), "\n", 1);
siglongjmp(jabort, 1);
}
@@ -1375,6 +1430,7 @@
if (fgets(acct, sizeof(acct) - 1, stdin) == NULL) {
fprintf(ttyout,
"\nEOF received; login aborted.\n");
+ clearerr(stdin);
code = -1;
return;
}
@@ -1632,6 +1688,13 @@
}
cout = NULL;
connected = 0;
+ /*
+ * determine if anonftp was specifically set with -a
+ * (1), or implicitly set by auto_fetch() (2). in the
+ * latter case, disable after the current xfer
+ */
+ if (anonftp == 2)
+ anonftp = 0;
data = -1;
epsv4bad = 0;
if (!proxy) {
diff -r f6deb1ddd13b -r 0e172d0ef109 usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h Tue Oct 12 04:53:45 1999 +0000
+++ b/usr.bin/ftp/extern.h Tue Oct 12 06:04:59 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.45 1999/10/09 12:48:12 lukem Exp $ */
+/* $NetBSD: extern.h,v 1.46 1999/10/12 06:04:59 lukem Exp $ */
/*-
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -124,7 +124,6 @@
unsigned char complete __P((EditLine *, int));
void controlediting __P((void));
#endif /* !NO_EDITCOMPLETE */
-int confirm __P((const char *, const char *));
FILE *dataconn __P((const char *));
void delete __P((int, char **));
void disconnect __P((int, char **));
diff -r f6deb1ddd13b -r 0e172d0ef109 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c Tue Oct 12 04:53:45 1999 +0000
+++ b/usr.bin/ftp/fetch.c Tue Oct 12 06:04:59 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.89 1999/10/10 22:33:55 lukem Exp $ */
+/* $NetBSD: fetch.c,v 1.90 1999/10/12 06:05:00 lukem Exp $ */
/*-
* Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.89 1999/10/10 22:33:55 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.90 1999/10/12 06:05:00 lukem Exp $");
#endif /* not lint */
/*
@@ -162,8 +162,10 @@
else {
fprintf(ttyout, "Username for `%s': ", realm);
(void)fflush(ttyout);
- if (fgets(user, sizeof(user) - 1, stdin) == NULL)
+ if (fgets(user, sizeof(user) - 1, stdin) == NULL) {
+ clearerr(stdin);
goto cleanup_auth_url;
+ }
user[strlen(user) - 1] = '\0';
}
if (gpass != NULL)
@@ -996,9 +998,14 @@
fprintf(ttyout,
"Authorization failed. Retry (y/n)? ");
- if (fgets(reply, sizeof(reply), stdin) != NULL
- && tolower(reply[0]) != 'y')
+ if (fgets(reply, sizeof(reply), stdin)
+ == NULL) {
+ clearerr(stdin);
goto cleanup_fetch_url;
+ } else {
+ if (tolower(reply[0]) != 'y')
+ goto cleanup_fetch_url;
+ }
auser = NULL;
apass = NULL;
}
@@ -1637,7 +1644,8 @@
if (strchr(argv[argpos], ':') == NULL)
break;
redirect_loop = 0;
- anonftp = 1; /* Handle "automatic" transfers. */
+ if (!anonftp)
+ anonftp = 2; /* Handle "automatic" transfers. */
rval = go_fetch(argv[argpos]);
if (outfile != NULL && strcmp(outfile, "-") != 0
&& outfile[0] != '|')
diff -r f6deb1ddd13b -r 0e172d0ef109 usr.bin/ftp/ftp.1
--- a/usr.bin/ftp/ftp.1 Tue Oct 12 04:53:45 1999 +0000
+++ b/usr.bin/ftp/ftp.1 Tue Oct 12 06:04:59 1999 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: ftp.1,v 1.53 1999/10/05 13:05:40 lukem Exp $
+.\" $NetBSD: ftp.1,v 1.54 1999/10/12 06:05:00 lukem Exp $
.\"
.\" Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -68,7 +68,7 @@
.\"
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
.\"
-.Dd October 5, 1999
+.Dd October 12, 1999
.Dt FTP 1
.Os
.Sh NAME
@@ -900,14 +900,16 @@
.Pp
When prompting is on, the following commands are available at a prompt:
.Bl -tag -width 2n -offset indent
-.It Ic n
-Do not transfer the file.
.It Ic a
Answer
.Sq yes
to the current file, and automatically answer
.Sq yes
to any remaining files for the current command.
+.It Ic n
+Answer
+.Sq no ,
+and do not transfer the file.
.It Ic p
Answer
.Sq yes
@@ -915,6 +917,14 @@
(as is
.Dq prompt off
had been given).
+.It Ic q
+Terminate the current operation.
+.It Ic y
+Answer
+.Sq yes ,
+and transfer the file.
+.It Ic ?
+Display a help message.
.El
.Pp
Any other reponse will answer
diff -r f6deb1ddd13b -r 0e172d0ef109 usr.bin/ftp/ftp.c
--- a/usr.bin/ftp/ftp.c Tue Oct 12 04:53:45 1999 +0000
+++ b/usr.bin/ftp/ftp.c Tue Oct 12 06:04:59 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp.c,v 1.83 1999/10/10 22:33:55 lukem Exp $ */
+/* $NetBSD: ftp.c,v 1.84 1999/10/12 06:05:01 lukem Exp $ */
/*-
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@@ -103,7 +103,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-__RCSID("$NetBSD: ftp.c,v 1.83 1999/10/10 22:33:55 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.84 1999/10/12 06:05:01 lukem Exp $");
#endif
#endif /* not lint */
@@ -391,7 +391,8 @@
int oerrno = errno;
alarmtimer(0);
- write(fileno(ttyout), "\n", 1);
+ if (fromatty)
+ write(fileno(ttyout), "\n", 1);
abrtflag++;
if (ptflag)
siglongjmp(ptabort, 1);
@@ -405,7 +406,8 @@
int oerrno = errno;
alarmtimer(0);
- write(fileno(ttyout), "\n", 1);
+ if (fromatty)
+ write(fileno(ttyout), "\n", 1);
timeoutflag++;
if (ptflag)
siglongjmp(ptabort, 1);
@@ -1883,7 +1885,8 @@
{
alarmtimer(0);
- write(fileno(ttyout), "\n", 1);
+ if (fromatty)
+ write(fileno(ttyout), "\n", 1);
ptabflg++;
mflag = 0;
abrtflag = 0;
diff -r f6deb1ddd13b -r 0e172d0ef109 usr.bin/ftp/main.c
--- a/usr.bin/ftp/main.c Tue Oct 12 04:53:45 1999 +0000
Home |
Main Index |
Thread Index |
Old Index