From 451ddf3cf9f685d8470f06bec7b90a97e7859374 Mon Sep 17 00:00:00 2001 From: hniksic Date: Tue, 30 Sep 2003 14:24:36 -0700 Subject: [PATCH] [svn] Display percentage in title bar. By Gisle Vanem. --- src/ChangeLog | 9 +++++++++ src/mswindows.c | 41 +++++++++++++++++++++++++++++------------ src/mswindows.h | 7 ++----- src/retr.c | 6 +++++- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1bd854b8..482e033f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2003-09-26 Gisle Vanem + * src/mswindows.c: Added ws_percenttitle() showing progress in the + window titlebar. Called from retr.c. Secured ws_mypath(). + + * windows/config.h.ms: alloca() prototype not needed. Removed + "#undef ENABLE_NLS"; should be in Makefile IMHO. Moved + WGET_USE_STDARG from mswindows.h to config.ms.h because of #ifdef + in log.c. (MSVC's vararg.h and stdarg.h are incompatible). + 2003-09-29 Aaron Hawley * ftp.c (getftp): --spider option should now work with FTP diff --git a/src/mswindows.c b/src/mswindows.c index a3a186a8..d1a2a543 100644 --- a/src/mswindows.c +++ b/src/mswindows.c @@ -37,6 +37,7 @@ so, delete this exception statement from your version. */ #include #include #include +#include #ifdef HACK_BCC_UTIME_BUG # include @@ -176,22 +177,41 @@ ws_handler (DWORD dwEvent) return TRUE; } +static char *title_buf = NULL; +static char *curr_url = NULL; +static int num_urls = 0; + void -ws_changetitle (char *url, int nurl) +ws_changetitle (const char *url, int nurl) { - char *title_buf; if (!nurl) return; - title_buf = (char *)alloca (strlen (url) + 20); - sprintf (title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ..."); - SetConsoleTitle (title_buf); + num_urls = nurl; + if (title_buf) + xfree(title_buf); + if (curr_url) + xfree(curr_url); + title_buf = (char *)xmalloc (strlen (url) + 20); + curr_url = xstrdup(url); + sprintf(title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ..."); + SetConsoleTitle(title_buf); +} + +void +ws_percenttitle (double percent) +{ + if (num_urls == 1 && title_buf && curr_url && fabs(percent) <= 100.0) + { + sprintf (title_buf, "Wget [%.1f%%] %s", percent, curr_url); + SetConsoleTitle (title_buf); + } } char * ws_mypath (void) { - static char *wspathsave; + static char *wspathsave = NULL; char buffer[MAX_PATH]; char *ptr; @@ -200,14 +220,11 @@ ws_mypath (void) return wspathsave; } - GetModuleFileName (NULL, buffer, MAX_PATH); - - ptr = strrchr (buffer, '\\'); - if (ptr) + if (GetModuleFileName (NULL, buffer, MAX_PATH) && + (ptr = strrchr (buffer, PATH_SEPARATOR)) != NULL) { *(ptr + 1) = '\0'; - wspathsave = (char*) xmalloc (strlen (buffer) + 1); - strcpy (wspathsave, buffer); + wspathsave = xstrdup (buffer); } else wspathsave = NULL; diff --git a/src/mswindows.h b/src/mswindows.h index b7d9c949..2f25fc22 100644 --- a/src/mswindows.h +++ b/src/mswindows.h @@ -65,10 +65,6 @@ so, delete this exception statement from your version. */ #endif #endif -/* Use ANSI-style stdargs regardless of whether the compiler bothers - to define __STDC__. (Many don't when extensions are enabled.) */ -#define WGET_USE_STDARG - #define REALCLOSE(x) closesocket (x) /* read & write don't work with sockets on Windows 95. */ @@ -135,7 +131,8 @@ int usleep (unsigned long); #endif void ws_startup (void); -void ws_changetitle (char*, int); +void ws_changetitle (const char*, int); +void ws_percenttitle (double); char *ws_mypath (void); void ws_help (const char *); void windows_main_junk (int *, char **, char **); diff --git a/src/retr.c b/src/retr.c index 3d8357fc..9378f60b 100644 --- a/src/retr.c +++ b/src/retr.c @@ -236,9 +236,13 @@ get_contents (int fd, FILE *fp, long *len, long restval, long expected, if (opt.limit_rate) limit_bandwidth (res, &dltime, timer); + *len += res; if (progress) progress_update (progress, res, dltime); - *len += res; +#ifdef WINDOWS + if (use_expected && expected > 0) + ws_percenttitle (100.0 * (double)(*len) / (double)expected); +#endif } if (res < -1) res = -1; -- 2.39.2