]> sjero.net Git - wget/blobdiff - src/progress.c
[svn] Use new macros xnew, xnew0, xnew_array, and xnew0_array in various places.
[wget] / src / progress.c
index c79be386e69bf4d45023990c17c1692b817742e7..99bdd5b616881d06078eeb5de6768e6cb6f945c3 100644 (file)
@@ -206,10 +206,7 @@ struct dot_progress {
 static void *
 dot_create (long initial, long total)
 {
-  struct dot_progress *dp = xmalloc (sizeof (struct dot_progress));
-
-  memset (dp, 0, sizeof (*dp));
-
+  struct dot_progress *dp = xnew0 (struct dot_progress);
   dp->initial_length = initial;
   dp->total_length   = total;
 
@@ -477,9 +474,7 @@ static void display_image PARAMS ((char *));
 static void *
 bar_create (long initial, long total)
 {
-  struct bar_progress *bp = xmalloc (sizeof (struct bar_progress));
-
-  memset (bp, 0, sizeof (*bp));
+  struct bar_progress *bp = xnew0 (struct bar_progress);
 
   /* In theory, our callers should take care of this pathological
      case, but it can sometimes happen. */
@@ -688,7 +683,7 @@ create_image (struct bar_progress *bp, double dl_total_time)
   else
     APPEND_LITERAL ("    ");
 
-  /* The progress bar: "[====>      ]" or "[--==>      ]". */
+  /* The progress bar: "[====>      ]" or "[++==>      ]". */
   if (progress_size && bp->total_length > 0)
     {
       /* Size of the initial portion. */
@@ -706,10 +701,10 @@ create_image (struct bar_progress *bp, double dl_total_time)
       *p++ = '[';
       begin = p;
 
-      /* Print the initial portion of the download with '-' chars, the
+      /* Print the initial portion of the download with '+' chars, the
         rest with '=' and one '>'.  */
       for (i = 0; i < insz; i++)
-       *p++ = '-';
+       *p++ = '+';
       dlsz -= insz;
       if (dlsz > 0)
        {
@@ -758,10 +753,12 @@ create_image (struct bar_progress *bp, double dl_total_time)
     {
       static char *short_units[] = { "B/s", "K/s", "M/s", "G/s" };
       int units = 0;
-      long bytes = hist->total_bytes + bp->recent_bytes;
-      double tm = hist->total_time + dl_total_time - bp->recent_start;
-      double dlrate = calc_rate (bytes, tm, &units);
-      sprintf (p, " %7.2f%s", dlrate, short_units[units]);
+      /* Calculate the download speed using the history ring and
+        recent data that hasn't made it to the ring yet.  */
+      long dlquant = hist->total_bytes + bp->recent_bytes;
+      double dltime = hist->total_time + (dl_total_time - bp->recent_start);
+      double dlspeed = calc_rate (dlquant, dltime, &units);
+      sprintf (p, " %7.2f%s", dlspeed, short_units[units]);
       p += strlen (p);
     }
   else
@@ -778,8 +775,9 @@ create_image (struct bar_progress *bp, double dl_total_time)
       /* Don't change the value of ETA more than approximately once
         per second; doing so would cause flashing without providing
         any value to the user. */
-      if (dl_total_time - bp->last_eta_time < 900
-         && bp->last_eta_value != 0)
+      if (bp->total_length != size
+         && bp->last_eta_value != 0
+         && dl_total_time - bp->last_eta_time < 900)
        eta = bp->last_eta_value;
       else
        {