diff options
author | Martynas Venckus <martynas@cvs.openbsd.org> | 2009-04-26 21:26:04 +0000 |
---|---|---|
committer | Martynas Venckus <martynas@cvs.openbsd.org> | 2009-04-26 21:26:04 +0000 |
commit | ea0f72a852d6dc33748c7116ad2ce277735bf5cd (patch) | |
tree | 27a28c4d83277cba194461fec24aef8bb851cef7 /usr.bin | |
parent | 2ea65187c3a8c7cfbfabdf522738e51739427fb8 (diff) |
figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ftp/extern.h | 5 | ||||
-rw-r--r-- | usr.bin/ftp/fetch.c | 12 | ||||
-rw-r--r-- | usr.bin/ftp/ftp.1 | 9 | ||||
-rw-r--r-- | usr.bin/ftp/ftp.c | 12 | ||||
-rw-r--r-- | usr.bin/ftp/main.c | 12 | ||||
-rw-r--r-- | usr.bin/ftp/util.c | 24 |
6 files changed, 36 insertions, 38 deletions
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index 2070844ebf4..7891c696512 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.36 2009/04/13 01:47:04 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.37 2009/04/26 21:26:03 martynas Exp $ */ /* $NetBSD: extern.h,v 1.17 1997/08/18 10:20:19 lukem Exp $ */ /* @@ -124,7 +124,7 @@ void mput(int, char **); char *onoff(int); void newer(int, char **); void page(int, char **); -void progressmeter(int); +void progressmeter(int, const char *); char *prompt(void); void proxabort(int); void proxtrans(const char *, const char *, const char *); @@ -210,7 +210,6 @@ 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/fetch.c b/usr.bin/ftp/fetch.c index 9adf95e806c..be1c4edab17 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.83 2008/10/16 23:15:53 martynas Exp $ */ +/* $OpenBSD: fetch.c,v 1.84 2009/04/26 21:26:03 martynas Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -31,7 +31,7 @@ */ #if !defined(lint) && !defined(SMALL) -static const char rcsid[] = "$OpenBSD: fetch.c,v 1.83 2008/10/16 23:15:53 martynas Exp $"; +static const char rcsid[] = "$OpenBSD: fetch.c,v 1.84 2009/04/26 21:26:03 martynas Exp $"; #endif /* not lint and not SMALL */ /* @@ -304,7 +304,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) bytes = 0; hashbytes = mark; - progressmeter(-1); + progressmeter(-1, path); if ((buf = malloc(4096)) == NULL) errx(1, "Can't allocate memory for transfer buffer"); @@ -339,7 +339,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile) warn("Reading from file"); goto cleanup_url_get; } - progressmeter(1); + progressmeter(1, NULL); if (verbose) fputs("Successfully retrieved file.\n", ttyout); (void)signal(SIGINT, oldintr); @@ -690,7 +690,7 @@ again: bytes = 0; hashbytes = mark; - progressmeter(-1); + progressmeter(-1, path); free(buf); @@ -728,7 +728,7 @@ again: warn("Reading from socket"); goto cleanup_url_get; } - progressmeter(1); + progressmeter(1, NULL); if ( #ifndef SMALL !resume && diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1 index dc71deefd5d..c8b3106089a 100644 --- a/usr.bin/ftp/ftp.1 +++ b/usr.bin/ftp/ftp.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ftp.1,v 1.75 2009/04/13 01:47:04 deraadt Exp $ +.\" $OpenBSD: ftp.1,v 1.76 2009/04/26 21:26:03 martynas 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: April 13 2009 $ +.Dd $Mdocdate: April 26 2009 $ .Dt FTP 1 .Os .Sh NAME @@ -42,7 +42,6 @@ .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 @@ -210,10 +209,6 @@ 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/ftp.c b/usr.bin/ftp/ftp.c index a1c19bc2a5b..a809f64fdeb 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftp.c,v 1.74 2009/04/25 12:22:19 martynas Exp $ */ +/* $OpenBSD: ftp.c,v 1.75 2009/04/26 21:26:03 martynas Exp $ */ /* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */ /* @@ -60,7 +60,7 @@ */ #if !defined(lint) && !defined(SMALL) -static const char rcsid[] = "$OpenBSD: ftp.c,v 1.74 2009/04/25 12:22:19 martynas Exp $"; +static const char rcsid[] = "$OpenBSD: ftp.c,v 1.75 2009/04/26 21:26:03 martynas Exp $"; #endif /* not lint and not SMALL */ #include <sys/types.h> @@ -708,7 +708,7 @@ sendrequest(const char *cmd, const char *local, const char *remote, dout = dataconn(lmode); if (dout == NULL) goto abort; - progressmeter(-1); + progressmeter(-1, remote); may_reset_noop_timeout(); oldintp = signal(SIGPIPE, SIG_IGN); switch (curtype) { @@ -789,7 +789,7 @@ sendrequest(const char *cmd, const char *local, const char *remote, } break; } - progressmeter(1); + progressmeter(1, NULL); progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); @@ -1024,7 +1024,7 @@ recvrequest(const char *cmd, const char * volatile local, const char *remote, progress = 0; preserve = 0; } - progressmeter(-1); + progressmeter(-1, remote); may_reset_noop_timeout(); switch (curtype) { @@ -1166,7 +1166,7 @@ break2: warnx("local: %s: %s", local, strerror(serrno)); break; } - progressmeter(1); + progressmeter(1, NULL); progress = oprogress; preserve = opreserve; if (closefunc != NULL) diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index a0d1674c8f1..a5f62c29362 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.72 2009/04/13 01:47:04 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.73 2009/04/26 21:26:03 martynas 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.72 2009/04/13 01:47:04 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: main.c,v 1.73 2009/04/26 21:26:03 martynas 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:tT:vV")) != -1) { + while ((ch = getopt(argc, argv, "46AaCc:dEegik:mno:pP:r:tvV")) != -1) { switch (ch) { case '4': family = PF_INET; @@ -281,10 +281,6 @@ main(volatile int argc, char *argv[]) trace = 1; break; - case 'T': - title = strdup(optarg); - break; - case 'v': verbose = 1; break; @@ -775,7 +771,7 @@ usage(void) "d" #endif /* !SMALL */ "EegimnptVv] [-k seconds] [-P port] [-r seconds]\n" - " [-T title] [host [port]]\n" + " [host [port]]\n" " %s " #ifndef SMALL "[-C] " diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index 1edf343ff9b..491056a002e 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.58 2009/04/26 10:30:07 sthen Exp $ */ +/* $OpenBSD: util.c,v 1.59 2009/04/26 21:26:03 martynas 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.58 2009/04/26 10:30:07 sthen Exp $"; +static const char rcsid[] = "$OpenBSD: util.c,v 1.59 2009/04/26 21:26:03 martynas Exp $"; #endif /* not lint and not SMALL */ /* @@ -733,7 +733,7 @@ updateprogressmeter(int signo) /* update progressmeter if foreground process or in -m mode */ if (foregroundproc() || progress == -1) - progressmeter(0); + progressmeter(0, NULL); errno = save_errno; } @@ -749,10 +749,8 @@ updateprogressmeter(int signo) */ static struct timeval start; -char *title; - void -progressmeter(int flag) +progressmeter(int flag, const char *filename) { /* * List of order of magnitude prefixes. @@ -762,6 +760,7 @@ progressmeter(int flag) static struct timeval lastupdate; static off_t lastsize; + static char *title = NULL; struct timeval now, td, wait; off_t cursize, abbrevsize; double elapsed; @@ -784,7 +783,12 @@ progressmeter(int flag) ratio = 100; ratio = MAX(ratio, 0); ratio = MIN(ratio, 100); - if (title) { + if (!verbose && flag == -1) { + filename = basename(filename); + if (filename != NULL) + title = strdup(filename); + } + if (!verbose && title != NULL) { int l = strlen(title); char *dotdot = ""; @@ -798,7 +802,7 @@ progressmeter(int flag) snprintf(buf, sizeof(buf), "\r%-*.*s%s %3d%% ", l, l, title, dotdot, ratio); overhead += l + 1; - } else + } else snprintf(buf, sizeof(buf), "\r%3d%% ", ratio); barlength = ttywidth - overhead; @@ -879,6 +883,10 @@ progressmeter(int flag) } else if (flag == 1) { alarmtimer(0); (void)putc('\n', ttyout); + if (title != NULL) { + free(title); + title = NULL; + } } fflush(ttyout); } |