- implement updateremotepwd(); update the global variable `remotepwd'

to contain the remote working directory.
- add `set prompt', a user configurable prompt. (defaults to `ftp> ').
  the following escape characters a la tcsh(1) are supported: %/, %m,
  %M, and %n.
- add global var `username'; used by prompt code
- fix a couple of minor memory leaks
- bump version
This commit is contained in:
lukem 1999-11-11 02:53:02 +00:00
parent ac3150a13d
commit 14fbd5079e
7 changed files with 179 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.78 1999/11/09 22:03:49 lukem Exp $ */
/* $NetBSD: cmds.c,v 1.79 1999/11/11 02:53:02 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.78 1999/11/09 22:03:49 lukem Exp $");
__RCSID("$NetBSD: cmds.c,v 1.79 1999/11/11 02:53:02 lukem Exp $");
#endif
#endif /* not lint */
@ -1142,8 +1142,10 @@ cd(argc, argv)
ttyout);
r = command("XCWD %s", argv[1]);
}
if (r == COMPLETE)
if (r == COMPLETE) {
dirchange = 1;
updateremotepwd();
}
}
/*
@ -2352,8 +2354,10 @@ cdup(argc, argv)
ttyout);
r = command("XCUP");
}
if (r == COMPLETE)
if (r == COMPLETE) {
dirchange = 1;
updateremotepwd();
}
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmdtab.c,v 1.32 1999/10/24 12:31:37 lukem Exp $ */
/* $NetBSD: cmdtab.c,v 1.33 1999/11/11 02:53:03 lukem Exp $ */
/*-
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@ -74,7 +74,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: cmdtab.c,v 1.32 1999/10/24 12:31:37 lukem Exp $");
__RCSID("$NetBSD: cmdtab.c,v 1.33 1999/11/11 02:53:03 lukem Exp $");
#endif
#endif /* not lint */
@ -280,5 +280,6 @@ struct option optiontab[] = {
{ "http_proxy", NULL },
{ "no_proxy", NULL },
{ "pager", NULL },
{ "prompt", NULL },
{ 0 },
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.48 1999/10/24 12:31:38 lukem Exp $ */
/* $NetBSD: extern.h,v 1.49 1999/11/11 02:53:03 lukem Exp $ */
/*-
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@ -242,6 +242,7 @@ int strsuftoi __P((const char *));
void syst __P((int, char **));
int togglevar __P((int, char **, int *, const char *));
void unsetoption __P((int, char **));
void updateremotepwd __P((void));
void usage __P((void));
void user __P((int, char **));
int xconnect __P((int, const struct sockaddr *, int));

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ftp.1,v 1.57 1999/11/10 07:34:41 lukem Exp $
.\" $NetBSD: ftp.1,v 1.58 1999/11/11 02:53:03 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 November 10, 1999
.Dd November 11, 1999
.Dt FTP 1
.Os
.Sh NAME
@ -1202,6 +1202,13 @@ Defaults to
.It pager
Defaults to
.Ev $PAGER .
.It prompt
Prompt to display when requesting input.
Defaults to
.Sq "ftp> ".
Refer to
.Sx COMMAND LINE PROMPT
below for more information.
.El
.It Ic size Ar remote-file
Return size of
@ -1788,6 +1795,37 @@ To use this, bind a key to the
command
.Ic ftp-complete .
By default, this is bound to the TAB key.
.Sh COMMAND LINE PROMPT
By default,
.Nm
displays a command line prompt of
.Sq "ftp> "
to the user.
This can be changed with the
.Ic "set prompt"
command.
.Pp
The following formatting sequences are replaced by the given
information:
.Bl -tag -width "%% " -offset indent
.It %/
The current remote working directory.
.It %M
The remote host name.
.It %m
The remote host name, up to the first
.Sq \&. .
.It %n
The remote user name.
.It %%
A single
.Sq % .
.El
.Pp
If a sequence depends upon information only available during a
connection, then
.Sq -
will be used if the connection isn't valid.
.Sh ENVIRONMENT
.Nm
uses the following environment variables.
@ -1896,12 +1934,13 @@ command appeared in
Various features such as command line editing, context sensitive
command and file completion, dynamic progress bar, automatic
fetching of files and URLs, modification time preservation,
transfer rate throttling, and other enhancements over the standard
transfer rate throttling, configurable command line prompt,
and other enhancements over the standard
.Bx
.Nm
were implemented in
.Nx 1.3
(and later releases)
and later releases
by Luke Mewburn <lukem@netbsd.org>.
.Pp
IPv6 support was added by the WIDE/KAME project.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp_var.h,v 1.46 1999/11/09 22:03:50 lukem Exp $ */
/* $NetBSD: ftp_var.h,v 1.47 1999/11/11 02:53:03 lukem Exp $ */
/*-
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@ -108,7 +108,7 @@
#define FTP_PRODUCT "NetBSD-ftp"
#endif
#ifndef FTP_VERSION
#define FTP_VERSION "19991110"
#define FTP_VERSION "19991111"
#endif
#ifdef SMALL
@ -186,6 +186,7 @@ struct option {
#endif
#define DEFAULTPAGER "more" /* default pager if $PAGER isn't set */
#define DEFAULTPROMPT "ftp> " /* default prompt if `set prompt' is empty */
#define TMPFILE "ftpXXXXXXXXXX"
@ -272,8 +273,10 @@ GLOBAL off_t restart_point; /* offset to restart transfer */
GLOBAL char *hostname; /* name of host connected to */
GLOBAL int unix_server; /* server is unix, can use binary for ascii */
GLOBAL int unix_proxy; /* proxy is unix, can use binary for ascii */
GLOBAL char remotepwd[MAXPATHLEN]; /* remote dir */
GLOBAL char *username; /* name of user logged in as. (dynamic) */
GLOBAL char *ftpport; /* port number to use for FTP connections */
GLOBAL char *ftpport; /* port number to use for FTP connections */
GLOBAL char *httpport; /* port number to use for HTTP connections */
GLOBAL char *gateport; /* port number to use for gateftp connections */
@ -304,8 +307,8 @@ GLOBAL char macbuf[4096];
GLOBAL char home[MAXPATHLEN]; /* home directory (for lcd) */
GLOBAL char reply_string[BUFSIZ]; /* first line of previous reply */
GLOBAL FILE *cin;
GLOBAL FILE *cout;
GLOBAL FILE *cin;
GLOBAL FILE *cout;
GLOBAL int data;
extern struct cmd cmdtab[];

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.65 1999/10/24 12:31:41 lukem Exp $ */
/* $NetBSD: main.c,v 1.66 1999/11/11 02:53:03 lukem Exp $ */
/*-
* Copyright (c) 1996-1999 The NetBSD Foundation, Inc.
@ -108,7 +108,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: main.c,v 1.65 1999/10/24 12:31:41 lukem Exp $");
__RCSID("$NetBSD: main.c,v 1.66 1999/11/11 02:53:03 lukem Exp $");
#endif
#endif /* not lint */
@ -413,10 +413,13 @@ main(argc, argv)
(void)strlcat(anonpass, "@", len);
setupoption("anonpass", getenv("FTPANONPASS"), anonpass);
setupoption("ftp_proxy", getenv(FTP_PROXY), xstrdup(""));
setupoption("http_proxy", getenv(HTTP_PROXY), xstrdup(""));
setupoption("no_proxy", getenv(NO_PROXY), xstrdup(""));
setupoption("pager", getenv("PAGER"), xstrdup(DEFAULTPAGER));
setupoption("ftp_proxy", getenv(FTP_PROXY), "");
setupoption("http_proxy", getenv(HTTP_PROXY), "");
setupoption("no_proxy", getenv(NO_PROXY), "");
setupoption("pager", getenv("PAGER"), DEFAULTPAGER);
setupoption("prompt", DEFAULTPROMPT, NULL);
free(anonpass);
setttywidth(0);
#ifdef SIGINFO
@ -481,7 +484,64 @@ main(argc, argv)
char *
prompt()
{
return ("ftp> ");
static char **prompt;
static char buf[MAXPATHLEN];
char *p, *p2;
int i;
if (prompt == NULL) {
struct option *o;
o = getoption("prompt");
if (o == NULL)
errx(1, "no such option `prompt'");
prompt = &(o->value);
}
#define ADDBUF(x) do { \
if (i >= sizeof(buf) - 1) \
goto endbuf; \
buf[i++] = (x); \
} while (0)
p = *prompt ? *prompt : DEFAULTPROMPT;
for (i = 0; *p; p++) {
if (*p == '%') {
p++;
switch (*p) {
case '%':
ADDBUF('%');
break;
case '/':
for (p2 = connected ? remotepwd : "/";
*p2; p2++)
ADDBUF(*p2);
break;
case 'M':
for (p2 = connected ? hostname : "-";
*p2; p2++)
ADDBUF(*p2);
break;
case 'm':
for (p2 = connected ? hostname : "-";
*p2 && *p2 != '.'; p2++)
ADDBUF(*p2);
break;
case 'n':
for (p2 = connected ? username : "-";
*p2 && *p2 != '.'; p2++)
ADDBUF(*p2);
break;
default:
/* XXX: ignore for now. maybe barf ? */
break;
}
} else
ADDBUF(*p);
}
endbuf:
buf[i] = '\0';
return (buf);
}
/*
@ -867,15 +927,13 @@ char *
getoptionvalue(name)
const char *name;
{
const char *p;
struct option *c;
if (name == NULL)
errx(1, "getoptionvalue() invoked with NULL name");
for (c = optiontab; (p = c->name) != NULL; c++) {
if (strcasecmp(p, name) == 0)
return (c->value);
}
c = getoption(name);
if (c != NULL)
return (c->value);
errx(1, "getoptionvalue() invoked with unknown option `%s'", name);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.80 1999/11/09 07:26:50 lukem Exp $ */
/* $NetBSD: util.c,v 1.81 1999/11/11 02:53:03 lukem Exp $ */
/*-
* Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.80 1999/11/09 07:26:50 lukem Exp $");
__RCSID("$NetBSD: util.c,v 1.81 1999/11/11 02:53:03 lukem Exp $");
#endif /* not lint */
/*
@ -224,6 +224,7 @@ setpeer(argc, argv)
"Remember to set tenex mode when transferring binary files from this machine.\n",
ttyout);
}
updateremotepwd();
verbose = overbose;
}
}
@ -251,6 +252,8 @@ cleanuppeer()
anonftp = 0;
data = -1;
epsv4bad = 0;
if (username)
free(username);
if (!proxy)
macnum = 0;
}
@ -406,6 +409,7 @@ ftp_login(host, user, pass)
goto cleanup_ftp_login;
}
rval = 1;
username = xstrdup(user);
if (proxy)
goto cleanup_ftp_login;
@ -658,6 +662,45 @@ remotemodtime(file, noisy)
return (rtime);
}
/*
* update global `remotepwd', which contains the state of the remote cwd
*/
void
updateremotepwd()
{
int overbose, ocode, i;
char *cp;
overbose = verbose;
ocode = code;
if (debug == 0)
verbose = -1;
if (command("PWD") != COMPLETE)
goto badremotepwd;
cp = strchr(reply_string, ' ');
if (cp == NULL || cp[0] == '\0' || cp[1] != '"')
goto badremotepwd;
cp += 2;
for (i = 0; *cp && i < sizeof(remotepwd) - 1; i++, cp++) {
if (cp[0] == '"') {
if (cp[1] == '"')
cp++;
else
break;
}
remotepwd[i] = *cp;
}
remotepwd[i] = '\0';
if (debug)
fprintf(ttyout, "got remotepwd as `%s'\n", remotepwd);
goto cleanupremotepwd;
badremotepwd:
remotepwd[0]='\0';
cleanupremotepwd:
verbose = overbose;
code = ocode;
}
#ifndef NO_PROGRESS
/*