summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-04-13 01:47:05 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-04-13 01:47:05 +0000
commit1c8656b703ee969f669cd45dd46d701a19974bd8 (patch)
tree081f7b496aa7866b8f639f10ea297b29ccf67c35
parent56e8c1a9fb12d49886b506fbfb9a78a5f831b3ec (diff)
add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc
-rw-r--r--usr.bin/ftp/extern.h3
-rw-r--r--usr.bin/ftp/ftp.19
-rw-r--r--usr.bin/ftp/main.c14
-rw-r--r--usr.bin/ftp/util.c27
4 files changed, 40 insertions, 13 deletions
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h
index 5afc88706ce..2070844ebf4 100644
--- a/usr.bin/ftp/extern.h
+++ b/usr.bin/ftp/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.35 2008/07/08 21:07:57 martynas Exp $ */
+/* $OpenBSD: extern.h,v 1.36 2009/04/13 01:47:04 deraadt Exp $ */
/* $NetBSD: extern.h,v 1.17 1997/08/18 10:20:19 lukem Exp $ */
/*
@@ -210,6 +210,7 @@ extern struct cmd cmdtab[];
extern FILE *cout;
extern int data;
extern char *home;
+extern char *title;
extern jmp_buf jabort;
extern int family;
extern int proxy;
diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1
index 7ee7bdbf699..dc71deefd5d 100644
--- a/usr.bin/ftp/ftp.1
+++ b/usr.bin/ftp/ftp.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ftp.1,v 1.74 2008/09/08 19:31:16 martynas Exp $
+.\" $OpenBSD: ftp.1,v 1.75 2009/04/13 01:47:04 deraadt Exp $
.\" $NetBSD: ftp.1,v 1.22 1997/08/18 10:20:22 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
.\"
-.Dd $Mdocdate: September 8 2008 $
+.Dd $Mdocdate: April 13 2009 $
.Dt FTP 1
.Os
.Sh NAME
@@ -42,6 +42,7 @@
.Op Fl k Ar seconds
.Op Fl P Ar port
.Op Fl r Ar seconds
+.Op Fl T Ar title
.Op Ar host Op Ar port
.Nm ftp
.Op Fl C
@@ -209,6 +210,10 @@ if the server does not support passive connections.
.It Fl r Ar seconds
Retry to connect if failed, pausing for number of
.Ar seconds .
+.It Fl T Ar title
+Set a filename
+.Ar title
+which will appear in the transfer progress bar.
.It Fl t
Enables packet tracing.
.It Fl V
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index cdde0670620..a0d1674c8f1 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.71 2008/08/22 08:52:35 sobrado Exp $ */
+/* $OpenBSD: main.c,v 1.72 2009/04/13 01:47:04 deraadt Exp $ */
/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */
/*
@@ -66,7 +66,7 @@ static const char copyright[] =
#endif /* not lint */
#if !defined(lint) && !defined(SMALL)
-static const char rcsid[] = "$OpenBSD: main.c,v 1.71 2008/08/22 08:52:35 sobrado Exp $";
+static const char rcsid[] = "$OpenBSD: main.c,v 1.72 2009/04/13 01:47:04 deraadt Exp $";
#endif /* not lint and not SMALL */
/*
@@ -182,7 +182,7 @@ main(volatile int argc, char *argv[])
cookiefile = getenv("http_cookies");
#endif /* !SMALL */
- while ((ch = getopt(argc, argv, "46AaCc:dEegik:mno:pP:r:tvV")) != -1) {
+ while ((ch = getopt(argc, argv, "46AaCc:dEegik:mno:pP:r:tT:vV")) != -1) {
switch (ch) {
case '4':
family = PF_INET;
@@ -281,6 +281,10 @@ main(volatile int argc, char *argv[])
trace = 1;
break;
+ case 'T':
+ title = strdup(optarg);
+ break;
+
case 'v':
verbose = 1;
break;
@@ -770,8 +774,8 @@ usage(void)
#ifndef SMALL
"d"
#endif /* !SMALL */
- "EegimnptVv] [-k seconds] "
- "[-P port] [-r seconds] [host [port]]\n"
+ "EegimnptVv] [-k seconds] [-P port] [-r seconds]\n"
+ " [-T title] [host [port]]\n"
" %s "
#ifndef SMALL
"[-C] "
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 2025c4a5e4b..63288d9c930 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.56 2009/01/27 22:04:36 martynas Exp $ */
+/* $OpenBSD: util.c,v 1.57 2009/04/13 01:47:04 deraadt Exp $ */
/* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */
/*-
@@ -64,7 +64,7 @@
*/
#if !defined(lint) && !defined(SMALL)
-static const char rcsid[] = "$OpenBSD: util.c,v 1.56 2009/01/27 22:04:36 martynas Exp $";
+static const char rcsid[] = "$OpenBSD: util.c,v 1.57 2009/04/13 01:47:04 deraadt Exp $";
#endif /* not lint and not SMALL */
/*
@@ -749,6 +749,8 @@ updateprogressmeter(int signo)
*/
static struct timeval start;
+char *title;
+
void
progressmeter(int flag)
{
@@ -763,7 +765,7 @@ progressmeter(int flag)
struct timeval now, td, wait;
off_t cursize, abbrevsize;
double elapsed;
- int ratio, barlength, i, remaining;
+ int ratio, barlength, i, remaining, overhead = 30;
char buf[512];
if (flag == -1) {
@@ -782,9 +784,24 @@ progressmeter(int flag)
ratio = 100;
ratio = MAX(ratio, 0);
ratio = MIN(ratio, 100);
- snprintf(buf, sizeof(buf), "\r%3d%% ", ratio);
+ if (title) {
+ int l = strlen(title);
+ char *dotdot = "";
+
+ if (l < 12)
+ l = 12;
+ else if (l > 25) {
+ l = 22;
+ dotdot = "...";
+ overhead += 3;
+ }
+ snprintf(buf, sizeof(buf), "\r%-*.*s%s %3d%% ", l, l, title,
+ dotdot, ratio);
+ overhead += l + 1;
+ } else
+ snprintf(buf, sizeof(buf), "\r%3d%% ", ratio);
- barlength = ttywidth - 30;
+ barlength = ttywidth - overhead;
if (barlength > 0) {
i = barlength * ratio / 100;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),