]> sjero.net Git - wget/blobdiff - src/progress.c
[svn] Implemented breadth-first retrieval.
[wget] / src / progress.c
index 1e278598432b9888511c2720629f0bdaa621d2ef..e167b7bfc41843c4288c9caf0f937fe2615e0fab 100644 (file)
@@ -27,6 +27,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 # include <strings.h>
 #endif /* HAVE_STRING_H */
 #include <assert.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
 
 #include "wget.h"
 #include "progress.h"
@@ -411,7 +414,8 @@ bar_update (void *progress, long howmuch)
   long dltime = wtimer_elapsed (bp->timer);
 
   bp->count += howmuch;
-  if (bp->count + bp->initial_length > bp->total_length)
+  if (bp->total_length > 0
+      && bp->count + bp->initial_length > bp->total_length)
     /* We could be downloading more than total_length, e.g. when the
        server sends an incorrect Content-Length header.  In that case,
        adjust bp->total_length to the new reality, so that the code in
@@ -439,8 +443,15 @@ static void
 bar_finish (void *progress)
 {
   struct bar_progress *bp = progress;
+  long elapsed = wtimer_elapsed (bp->timer);
+
+  if (elapsed == 0)
+    /* If the download was faster than the granularity of the timer,
+       fake some output so that we don't get the ugly "----.--" rate
+       at the download finish.  */
+    elapsed = 1;
 
-  create_image (bp, wtimer_elapsed (bp->timer));
+  create_image (bp, elapsed);
   display_image (bp->buffer);
 
   logputs (LOG_VERBOSE, "\n\n");
@@ -462,14 +473,14 @@ create_image (struct bar_progress *bp, long dltime)
      Calculate its geometry:
 
      "xxx% "         - percentage                - 5 chars
-     "| ... | "      - progress bar decorations  - 3 chars
+     "| ... |"       - progress bar decorations  - 2 chars
      "1012.56 K/s "  - dl rate                   - 12 chars
      "nnnn "         - downloaded bytes          - 11 chars
      "ETA: xx:xx:xx" - ETA                       - 13 chars
 
      "=====>..."     - progress bar content      - the rest
   */
-  int progress_len = screen_width - (5 + 3 + 12 + 11 + 13);
+  int progress_len = screen_width - (5 + 2 + 12 + 11 + 13);
 
   if (progress_len < 7)
     progress_len = 0;
@@ -522,12 +533,12 @@ create_image (struct bar_progress *bp, long dltime)
     }
   else
     {
-      strcpy (p, "----.-- K/s ");
+      strcpy (p, "  --.-- K/s ");
       p += 12;
     }
 
   /* "12376 " */
-  sprintf (p, _("%ld "), size);
+  sprintf (p, "%ld ", size);
   p += strlen (p);
 
   /* "ETA: xx:xx:xx" */
@@ -592,20 +603,25 @@ display_image (char *buf)
 }
 
 static void
-bar_set_params (const char *ignored)
+bar_set_params (const char *params)
 {
   int sw;
 
-  if (opt.lfilename
+  if ((opt.lfilename
 #ifdef HAVE_ISATTY
-      || !isatty (fileno (stderr))
+       || !isatty (fileno (stderr))
 #else
-      1
+       1
 #endif
-      )
+       )
+      && !(params != NULL
+          && 0 == strcmp (params, "force")))
     {
-      /* We're not printing to a TTY.  Revert to the fallback
-        display. */
+      /* We're not printing to a TTY, so revert to the fallback
+        display.  #### We're recursively calling
+        set_progress_implementation here, which is slightly kludgy.
+        It would be nicer if that function could resolve this problem
+        itself.  */
       set_progress_implementation (NULL);
       return;
     }