]> sjero.net Git - wget/blobdiff - src/main.c
[svn] Move extern declarations to .h files.
[wget] / src / main.c
index 797472cd3008096d48f9f9018aee4f407fcdaefb..9bf80465dc3b75274d16f296c5e9968e8f220cb6 100644 (file)
@@ -51,6 +51,7 @@ so, delete this exception statement from your version.  */
 #include "url.h"
 #include "progress.h"          /* for progress_handle_sigwinch */
 #include "convert.h"
+#include "http.h"              /* for save_cookies */
 
 /* On GNU system this will include system-wide getopt.h. */
 #include "getopt.h"
@@ -61,11 +62,8 @@ so, delete this exception statement from your version.  */
 
 struct options opt;
 
-extern SUM_SIZE_INT total_downloaded_bytes;
 extern char *version_string;
 
-extern struct cookie_jar *wget_cookie_jar;
-
 static void redirect_output_signal (int);
 
 const char *exec_name;
@@ -80,20 +78,7 @@ i18n_initialize (void)
   /* HAVE_NLS implies existence of functions invoked here.  */
 #ifdef HAVE_NLS
   /* Set the current locale.  */
-  /* Where possible, sets only LC_MESSAGES and LC_CTYPE.  Other
-     categories, such as numeric, time, or collation, break code that
-     parses data received from the network and relies on C-locale
-     behavior of libc functions.  For example, Solaris strptime fails
-     to recognize English month names in non-English locales, which
-     breaks http_atotm.  Some implementations of fnmatch perform
-     unwanted case folding in non-C locales.  ctype macros, while they
-     were used, provided another example against LC_ALL.  */
-#if defined(LC_MESSAGES) && defined(LC_CTYPE)
-  setlocale (LC_MESSAGES, "");
-  setlocale (LC_CTYPE, "");    /* safe because we use safe-ctype */
-#else
   setlocale (LC_ALL, "");
-#endif
   /* Set the text message domain.  */
   bindtextdomain ("wget", LOCALEDIR);
   textdomain ("wget");
@@ -137,7 +122,7 @@ struct cmdline_option {
   int argtype;                 /* for non-standard options */
 };
 
-struct cmdline_option option_data[] =
+static struct cmdline_option option_data[] =
   {
     { "accept", 'A', OPT_VALUE, "accept", -1 },
     { "append-output", 'a', OPT__APPEND_OUTPUT, NULL, required_argument },
@@ -638,6 +623,40 @@ Recursive accept/reject:\n"),
   exit (0);
 }
 
+/* Return a human-readable printed representation of INTERVAL,
+   measured in seconds.  */
+
+static char *
+secs_to_human_time (double interval)
+{
+  static char buf[32];
+  int secs = (int) (interval + 0.5);
+  int hours, mins, days;
+
+  days = secs / 86400, secs %= 86400;
+  hours = secs / 3600, secs %= 3600;
+  mins = secs / 60, secs %= 60;
+
+  if (days)
+    sprintf (buf, "%dd %dh %dm %ds", days, hours, mins, secs);
+  else if (hours)
+    sprintf (buf, "%dh %dm %ds", hours, mins, secs);
+  else if (mins)
+    sprintf (buf, "%dm %ds", mins, secs);
+  else if (interval >= 10)
+    sprintf (buf, "%ds", secs);
+  else
+    /* For very quick downloads show more exact timing information. */
+    sprintf (buf, "%.*fs",
+            interval < 0.001 ? 0 : /* 0s instead of 0.000s */
+            interval < 0.01 ? 3 :  /* 0.00x */
+            interval < 0.1 ? 2 :   /* 0.0x */
+            1,                     /* 0.x, 1.x, ..., 9.x */
+            interval);
+
+  return buf;
+}
+
 static void
 print_version (void)
 {
@@ -876,9 +895,6 @@ Can't timestamp and not clobber old files at the same time.\n"));
   /* Open the output filename if necessary.  */
   if (opt.output_document)
     {
-      extern FILE *output_stream;
-      extern bool output_stream_regular;
-
       if (HYPHENP (opt.output_document))
        output_stream = stdout;
       else
@@ -960,10 +976,12 @@ Can't timestamp and not clobber old files at the same time.\n"));
       || (opt.input_filename && total_downloaded_bytes != 0))
     {
       logprintf (LOG_NOTQUIET,
-                _("\nFINISHED --%s--\nDownloaded: %s in %d files\n"),
+                _("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"),
                 time_str (NULL),
+                opt.numurls,
                 human_readable (total_downloaded_bytes),
-                opt.numurls);
+                secs_to_human_time (total_download_time / 1000),
+                retr_rate (total_downloaded_bytes, total_download_time));
       /* Print quota warning, if exceeded.  */
       if (opt.quota && total_downloaded_bytes > opt.quota)
        logprintf (LOG_NOTQUIET,