Clean up use of confirm() and mbort() so that the current operation

is always passed in (instead of depending upon the 'mname' global).
For confirm(), if the second argument is NULL print the "Continue with <cmd>"
prompt.  This fixes up the the display of interrupted prompts.
This commit is contained in:
lukem 2007-04-18 01:39:04 +00:00
parent 0549fd6148
commit 036f5d17ed
3 changed files with 39 additions and 33 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.120 2007/04/17 05:52:03 lukem Exp $ */ /* $NetBSD: cmds.c,v 1.121 2007/04/18 01:39:04 lukem Exp $ */
/*- /*-
* Copyright (c) 1996-2007 The NetBSD Foundation, Inc. * Copyright (c) 1996-2007 The NetBSD Foundation, Inc.
@ -103,7 +103,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else #else
__RCSID("$NetBSD: cmds.c,v 1.120 2007/04/17 05:52:03 lukem Exp $"); __RCSID("$NetBSD: cmds.c,v 1.121 2007/04/18 01:39:04 lukem Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -131,7 +131,7 @@ __RCSID("$NetBSD: cmds.c,v 1.120 2007/04/17 05:52:03 lukem Exp $");
#include "ftp_var.h" #include "ftp_var.h"
#include "version.h" #include "version.h"
struct types { static struct types {
char *t_name; char *t_name;
char *t_mode; char *t_mode;
int t_type; int t_type;
@ -145,30 +145,43 @@ struct types {
{ NULL } { NULL }
}; };
sigjmp_buf jabort; static sigjmp_buf jabort;
const char *mname;
static int confirm(const char *, const char *); static int confirm(const char *, const char *);
static void mintr(int);
static void mabort(const char *);
static const char *doprocess(char *, size_t, const char *, int, int, int); static const char *doprocess(char *, size_t, const char *, int, int, int);
static const char *domap(char *, size_t, const char *); static const char *domap(char *, size_t, const char *);
static const char *docase(char *, size_t, const char *); static const char *docase(char *, size_t, const char *);
static const char *dotrans(char *, size_t, const char *); static const char *dotrans(char *, size_t, const char *);
/*
* Confirm if "cmd" is to be performed upon "file".
* If "file" is NULL, generate a "Continue with" prompt instead.
*/
static int static int
confirm(const char *cmd, const char *file) confirm(const char *cmd, const char *file)
{ {
const char *errormsg; const char *errormsg;
char line[BUFSIZ]; char line[BUFSIZ];
const char *promptleft, *promptright;
if (!interactive || confirmrest) if (!interactive || confirmrest)
return (1); return (1);
if (file == NULL) {
promptleft = "Continue with";
promptright = cmd;
} else {
promptleft = cmd;
promptright = file;
}
while (1) { while (1) {
fprintf(ttyout, "%s %s [anpqy?]? ", cmd, file); fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright);
(void)fflush(ttyout); (void)fflush(ttyout);
if (getline(stdin, line, sizeof(line), &errormsg) < 0) { if (getline(stdin, line, sizeof(line), &errormsg) < 0) {
mflag = 0; mflag = 0;
fprintf(ttyout, "%s; %s aborted\n", errormsg, mname); fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd);
return (0); return (0);
} }
switch (tolower((unsigned char)*line)) { switch (tolower((unsigned char)*line)) {
@ -183,7 +196,7 @@ confirm(const char *cmd, const char *file)
break; break;
case 'q': case 'q':
mflag = 0; mflag = 0;
fprintf(ttyout, "%s aborted.\n", mname); fprintf(ttyout, "%s aborted.\n", cmd);
/* FALLTHROUGH */ /* FALLTHROUGH */
case 'n': case 'n':
return (0); return (0);
@ -458,11 +471,10 @@ mput(int argc, char *argv[])
code = -1; code = -1;
return; return;
} }
mname = argv[0];
mflag = 1; mflag = 1;
oldintr = xsignal(SIGINT, mintr); oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1)) if (sigsetjmp(jabort, 1))
mabort(); mabort(argv[0]);
if (proxy) { if (proxy) {
char *cp; char *cp;
@ -480,7 +492,7 @@ mput(int argc, char *argv[])
if (!mflag && fromatty) { if (!mflag && fromatty) {
ointer = interactive; ointer = interactive;
interactive = 1; interactive = 1;
if (confirm("Continue with", "mput")) { if (confirm(argv[0], NULL)) {
mflag++; mflag++;
} }
interactive = ointer; interactive = ointer;
@ -504,7 +516,7 @@ mput(int argc, char *argv[])
if (!mflag && fromatty) { if (!mflag && fromatty) {
ointer = interactive; ointer = interactive;
interactive = 1; interactive = 1;
if (confirm("Continue with", "mput")) { if (confirm(argv[0], NULL)) {
mflag++; mflag++;
} }
interactive = ointer; interactive = ointer;
@ -532,7 +544,7 @@ mput(int argc, char *argv[])
if (!mflag && fromatty) { if (!mflag && fromatty) {
ointer = interactive; ointer = interactive;
interactive = 1; interactive = 1;
if (confirm("Continue with", "mput")) { if (confirm(argv[0], NULL)) {
mflag++; mflag++;
} }
interactive = ointer; interactive = ointer;
@ -634,7 +646,7 @@ getit(int argc, char *argv[], int restartit, const char *mode)
} }
/* ARGSUSED */ /* ARGSUSED */
void static void
mintr(int signo) mintr(int signo)
{ {
@ -644,8 +656,8 @@ mintr(int signo)
siglongjmp(jabort, 1); siglongjmp(jabort, 1);
} }
void static void
mabort(void) mabort(const char *cmd)
{ {
int ointer, oconf; int ointer, oconf;
@ -654,7 +666,7 @@ mabort(void)
oconf = confirmrest; oconf = confirmrest;
interactive = 1; interactive = 1;
confirmrest = 0; confirmrest = 0;
if (confirm("Continue with", mname)) { if (confirm(cmd, NULL)) {
interactive = ointer; interactive = ointer;
confirmrest = oconf; confirmrest = oconf;
return; return;
@ -683,7 +695,6 @@ mget(int argc, char *argv[])
code = -1; code = -1;
return; return;
} }
mname = argv[0];
mflag = 1; mflag = 1;
restart_point = 0; restart_point = 0;
restartit = 0; restartit = 0;
@ -697,7 +708,7 @@ mget(int argc, char *argv[])
} }
oldintr = xsignal(SIGINT, mintr); oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1)) if (sigsetjmp(jabort, 1))
mabort(); mabort(argv[0]);
while ((cp = remglob(argv, proxy, NULL)) != NULL) { while ((cp = remglob(argv, proxy, NULL)) != NULL) {
char buf[MAXPATHLEN]; char buf[MAXPATHLEN];
if (*cp == '\0' || !connected) { if (*cp == '\0' || !connected) {
@ -728,7 +739,7 @@ mget(int argc, char *argv[])
if (!mflag && fromatty) { if (!mflag && fromatty) {
ointer = interactive; ointer = interactive;
interactive = 1; interactive = 1;
if (confirm("Continue with", "mget")) if (confirm(argv[0], NULL))
mflag++; mflag++;
interactive = ointer; interactive = ointer;
} }
@ -1216,11 +1227,10 @@ mdelete(int argc, char *argv[])
code = -1; code = -1;
return; return;
} }
mname = argv[0];
mflag = 1; mflag = 1;
oldintr = xsignal(SIGINT, mintr); oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1)) if (sigsetjmp(jabort, 1))
mabort(); mabort(argv[0]);
while ((cp = remglob(argv, 0, NULL)) != NULL) { while ((cp = remglob(argv, 0, NULL)) != NULL) {
if (*cp == '\0') { if (*cp == '\0') {
mflag = 0; mflag = 0;
@ -1232,7 +1242,7 @@ mdelete(int argc, char *argv[])
if (!mflag && fromatty) { if (!mflag && fromatty) {
ointer = interactive; ointer = interactive;
interactive = 1; interactive = 1;
if (confirm("Continue with", "mdelete")) { if (confirm(argv[0], NULL)) {
mflag++; mflag++;
} }
interactive = ointer; interactive = ointer;
@ -1336,7 +1346,6 @@ ls(int argc, char *argv[])
(void)strlcpy(locfile + 1, p, len - 1); (void)strlcpy(locfile + 1, p, len - 1);
freelocfile = 1; freelocfile = 1;
} else if ((strcmp(locfile, "-") != 0) && *locfile != '|') { } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
mname = argv[0];
if ((locfile = globulize(locfile)) == NULL || if ((locfile = globulize(locfile)) == NULL ||
!confirm("output to local-file:", locfile)) { !confirm("output to local-file:", locfile)) {
code = -1; code = -1;
@ -1373,7 +1382,6 @@ mls(int argc, char *argv[])
} }
odest = dest = argv[argc - 1]; odest = dest = argv[argc - 1];
argv[argc - 1] = NULL; argv[argc - 1] = NULL;
mname = argv[0];
if (strcmp(dest, "-") && *dest != '|') if (strcmp(dest, "-") && *dest != '|')
if (((dest = globulize(dest)) == NULL) || if (((dest = globulize(dest)) == NULL) ||
!confirm("output to local-file:", dest)) { !confirm("output to local-file:", dest)) {
@ -1384,7 +1392,7 @@ mls(int argc, char *argv[])
mflag = 1; mflag = 1;
oldintr = xsignal(SIGINT, mintr); oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1)) if (sigsetjmp(jabort, 1))
mabort(); mabort(argv[0]);
for (i = 1; mflag && i < argc-1 && connected; i++) { for (i = 1; mflag && i < argc-1 && connected; i++) {
mode = (i == 1) ? "w" : "a"; mode = (i == 1) ? "w" : "a";
recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode, recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
@ -1392,7 +1400,7 @@ mls(int argc, char *argv[])
if (!mflag && fromatty) { if (!mflag && fromatty) {
ointer = interactive; ointer = interactive;
interactive = 1; interactive = 1;
if (confirm("Continue with", argv[0])) { if (confirm(argv[0], NULL)) {
mflag++; mflag++;
} }
interactive = ointer; interactive = ointer;

View File

@ -1,7 +1,7 @@
/* $NetBSD: extern.h,v 1.70 2006/01/31 20:01:23 christos Exp $ */ /* $NetBSD: extern.h,v 1.71 2007/04/18 01:39:04 lukem Exp $ */
/*- /*-
* Copyright (c) 1996-2005 The NetBSD Foundation, Inc. * Copyright (c) 1996-2007 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
* *
* This code is derived from software contributed to The NetBSD Foundation * This code is derived from software contributed to The NetBSD Foundation
@ -160,13 +160,11 @@ void lostpeer(int);
void lpage(int, char **); void lpage(int, char **);
void lpwd(int, char **); void lpwd(int, char **);
void ls(int, char **); void ls(int, char **);
void mabort(void);
void macdef(int, char **); void macdef(int, char **);
void makeargv(void); void makeargv(void);
void makedir(int, char **); void makedir(int, char **);
void mdelete(int, char **); void mdelete(int, char **);
void mget(int, char **); void mget(int, char **);
void mintr(int);
void mls(int, char **); void mls(int, char **);
void mlst(int, char **); void mlst(int, char **);
void modtime(int, char **); void modtime(int, char **);

View File

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.62 2007/04/17 05:52:04 lukem Exp $ */ /* $NetBSD: version.h,v 1.63 2007/04/18 01:39:04 lukem Exp $ */
/*- /*-
* Copyright (c) 1999-2007 The NetBSD Foundation, Inc. * Copyright (c) 1999-2007 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
@ -40,5 +40,5 @@
#endif #endif
#ifndef FTP_VERSION #ifndef FTP_VERSION
#define FTP_VERSION "20070416" #define FTP_VERSION "20070418"
#endif #endif