]> sjero.net Git - wget/commitdiff
[svn] Revamped MS console logic. Submitted by David Fritz.
authorhniksic <devnull@localhost>
Wed, 25 Feb 2004 23:45:24 +0000 (15:45 -0800)
committerhniksic <devnull@localhost>
Wed, 25 Feb 2004 23:45:24 +0000 (15:45 -0800)
src/ChangeLog
src/ftp.c
src/http.c
src/main.c
src/mswindows.c
src/mswindows.h

index e7d55956d8cc4e56d939c805891af6ab0a384237..17c101ab05af9cf5e0e9314797d29d4b41377a4a 100644 (file)
@@ -1,3 +1,17 @@
+2004-02-23  David Fritz  <zeroxdf@att.net>
+
+       * 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  <zeroxdf@att.net>
 
        * mswindows.h: Ditto.
index e4c3b621be6c7fae1dbe22281554edccaaca946a..7ad73fb04d2541dd0cd6b3abcbb7166c52917fb7 100644 (file)
--- 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);
        }
index 86324f08c878a53c885c40bcda6bd80475660e4d..dec5f0267b220d8987878f6b0dd59d0e8c535f68 100644 (file)
@@ -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);
        }
index 884d9c89797100e73763016ade0463a758421bbc..3175e70a704ada89e14a941d73bbb294fe233594 100644 (file)
@@ -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);
 
index b33291a1fd46c9222b18347872b1e5c79150c94e..0406bb355f786ddf1e4d15bfbb7816deca41964c 100644 (file)
@@ -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
index 431e9d70fe87c04c80a5d9456cf05ff821f55a5e..e66fa3145748e38d58d53e3091974a9907deb76c 100644 (file)
@@ -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 **);