From a0642cc62efd41b2e28a2fca7ca9d965e5854582 Mon Sep 17 00:00:00 2001 From: hniksic Date: Wed, 25 Feb 2004 15:45:24 -0800 Subject: [PATCH] [svn] Revamped MS console logic. Submitted by David Fritz. --- src/ChangeLog | 14 ++++++++++++++ src/ftp.c | 2 +- src/http.c | 2 +- src/main.c | 6 ------ src/mswindows.c | 48 +++++++++++++++++++++++++++++------------------- src/mswindows.h | 2 +- 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index e7d55956..17c101ab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2004-02-23 David Fritz + + * http.c (http_loop): Ditto. + + * ftp.c (ftp_loop_internal): Update call to ws_changetitle(). + + * main.c (main): Don't bother calling ws_changetitle(). + + * mswindows.h (ws_changetitle): Update prototype. + + * mswindows.c (ws_changetitle): Remove second argument. Use + xfree_null(). + (ws_percenttitle): Only update title when percentage has changed. + 2004-02-23 David Fritz * mswindows.h: Ditto. diff --git a/src/ftp.c b/src/ftp.c index e4c3b621..7ad73fb0 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -1203,7 +1203,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con) logprintf (LOG_VERBOSE, "--%s-- %s\n %s => `%s'\n", tms, hurl, tmp, locf); #ifdef WINDOWS - ws_changetitle (hurl, 1); + ws_changetitle (hurl); #endif xfree (hurl); } diff --git a/src/http.c b/src/http.c index 86324f08..dec5f026 100644 --- a/src/http.c +++ b/src/http.c @@ -1912,7 +1912,7 @@ File `%s' already there, will not retrieve.\n"), *hstat.local_file); logprintf (LOG_VERBOSE, "--%s-- %s\n %s => `%s'\n", tms, hurl, tmp, locf); #ifdef WINDOWS - ws_changetitle (hurl, 1); + ws_changetitle (hurl); #endif xfree (hurl); } diff --git a/src/main.c b/src/main.c index 884d9c89..3175e70a 100644 --- a/src/main.c +++ b/src/main.c @@ -852,12 +852,6 @@ Can't timestamp and not clobber old files at the same time.\n")); } url[i] = NULL; - /* Change the title of console window on Windows. #### I think this - statement should belong to retrieve_url(). --hniksic. */ -#ifdef WINDOWS - ws_changetitle (*url, nurl); -#endif - /* Initialize logging. */ log_init (opt.lfilename, append_to_log); diff --git a/src/mswindows.c b/src/mswindows.c index b33291a1..0406bb35 100644 --- a/src/mswindows.c +++ b/src/mswindows.c @@ -165,33 +165,43 @@ ws_handler (DWORD dwEvent) static char *title_buf = NULL; static char *curr_url = NULL; -static int num_urls = 0; +static int old_percentage = -1; +/* Updates the console title with the URL of the current file being + transferred. */ void -ws_changetitle (const char *url, int nurl) +ws_changetitle (const char *url) { - if (!nurl) - return; - - num_urls = nurl; - if (title_buf) - xfree(title_buf); - if (curr_url) - xfree(curr_url); + xfree_null (title_buf); + xfree_null (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); + curr_url = xstrdup (url); + old_percentage = -1; + sprintf (title_buf, "Wget %s", curr_url); + SetConsoleTitle (title_buf); } +/* Updates the console title with the percentage of the current file + transferred. */ void -ws_percenttitle (double percent) +ws_percenttitle (double percentage_float) { - if (num_urls == 1 && title_buf && curr_url && fabs(percent) <= 100.0) - { - sprintf (title_buf, "Wget [%.0f%%] %s", percent, curr_url); - SetConsoleTitle (title_buf); - } + int percentage = (int) percentage_float; + + /* Only update the title when the percentage has changed. */ + if (percentage == old_percentage) + return; + + old_percentage = percentage; + + if (percentage > 100) + return; + + assert (title_buf != NULL); + assert (curr_url != NULL); + + sprintf (title_buf, "Wget [%d%%] %s", percentage, curr_url); + SetConsoleTitle (title_buf); } /* Returns a pointer to the fully qualified name of the directory that diff --git a/src/mswindows.h b/src/mswindows.h index 431e9d70..e66fa314 100644 --- a/src/mswindows.h +++ b/src/mswindows.h @@ -157,7 +157,7 @@ int usleep (unsigned long); #endif void ws_startup (void); -void ws_changetitle (const char*, int); +void ws_changetitle (const char *); void ws_percenttitle (double); char *ws_mypath (void); void windows_main_junk (int *, char **, char **); -- 2.39.2