]> sjero.net Git - wget/commitdiff
[svn] Display percentage in title bar.
authorhniksic <devnull@localhost>
Tue, 30 Sep 2003 21:24:36 +0000 (14:24 -0700)
committerhniksic <devnull@localhost>
Tue, 30 Sep 2003 21:24:36 +0000 (14:24 -0700)
By Gisle Vanem.

src/ChangeLog
src/mswindows.c
src/mswindows.h
src/retr.c

index 1bd854b8618959d729fcabbcc8def53966701c10..482e033f57b09828acee557c54c09033cac4f2ca 100644 (file)
@@ -1,3 +1,12 @@
+2003-09-26  Gisle Vanem  <giva@bgnett.no>
+       * 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 <Aaron.Hawley@uvm.edu>
 
        * ftp.c (getftp): --spider option should now work with FTP
index a3a186a8e97fd0bf97cce5d23d8fb1d65428f4ed..d1a2a543b55cbe14b08f2d8d415f6a317109c37c 100644 (file)
@@ -37,6 +37,7 @@ so, delete this exception statement from your version.  */
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
+#include <math.h>
 
 #ifdef HACK_BCC_UTIME_BUG
 # include <io.h>
@@ -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;
index b7d9c9492d5ca7998f3811e041466e8df540efb1..2f25fc22871891c56d86b97842c68154745548ff 100644 (file)
@@ -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 **);
index 3d8357fc252532eadea167d60bb6284872276194..9378f60bdee2f8b30845141a89bb7b9ccd7297f3 100644 (file)
@@ -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;