--- retr.c	Sun May 27 22:35:09 2001
+++ retr.c.new	Wed Jun  6 16:49:37 2001
@@ -148,10 +148,76 @@
 }
 
 static void
-print_percentage (long bytes, long expected)
+print_percentage (long bytes, long expected, enum spflags flags)
 {
-  int percentage = (int)(100.0 * bytes / expected);
-  logprintf (LOG_VERBOSE, "%3d%%", percentage);
+  static struct wget_timer *pp_timer;
+  static unsigned long oldTime, oldBytes, oldExpected;
+  unsigned long curTime, deltaTime;
+  static unsigned long speed, estimate;
+  int percentage;
+  char buf[100];
+  char* pc;
+
+  if( flags == SP_INIT ) {
+    pp_timer = wtimer_new();
+    oldTime = wtimer_elapsed (pp_timer);
+    oldBytes = bytes;
+    oldExpected = expected;
+    return;
+  }
+
+  curTime = wtimer_elapsed (pp_timer);
+
+  if( flags == SP_FINISH ) {
+    wtimer_delete(pp_timer);
+    }
+
+  if( curTime > oldTime) {
+    deltaTime = curTime - oldTime;
+    oldTime = curTime;
+    }
+  else {
+    deltaTime = 0;
+    }
+
+
+  if( deltaTime != 0) {
+    estimate = (unsigned long)(((expected-bytes)*(((float)deltaTime)/1000)) / (bytes-oldBytes));
+    speed    = (unsigned long)((bytes-oldBytes) / (((float)deltaTime)/1000));
+    oldBytes = bytes;
+  }
+  percentage = (int)(100.0 * bytes / expected);
+
+  pc = buf;
+  *pc = 0;
+  if( percentage > 99)
+    pc += sprintf( pc, "100%%" );
+  else
+    pc += sprintf( pc, " %2d%%", percentage );
+
+  if ( deltaTime == 0 ) { /* we are too fast :) -- print percentage only */
+    logprintf( LOG_VERBOSE, "%s", buf );
+    return;
+    }
+
+  pc += sprintf( pc, "%4ld:%02ld ", estimate / 60, estimate % 60 );
+
+  if ( speed < 1000 )
+    pc += sprintf( pc, "%4ldB", speed );
+  else if ( speed < 1000*10 )
+    pc += sprintf( pc, "%4.2fK", speed / 1000.0 );
+  else if ( speed < 1000*100 )
+    pc += sprintf( pc, "%4.1fK", speed / 1000.0 );
+  else if ( speed < 1000*1000 )
+    pc += sprintf( pc, "%4.0fK", speed / 1000.0 );
+  else if ( speed < 1000*1000*10 )
+    pc += sprintf( pc, "%4.2fM", speed / (1000.0*1000.0) );
+  else if ( speed < 1000*1000*100 )
+    pc += sprintf( pc, "%4.1fM", speed / (1000.0*1000.0) );
+  else
+    pc += sprintf( pc, "%4.0fM", speed / (1000.0*1000.0) );
+
+  logprintf( LOG_VERBOSE, "%s", buf );
 }
 
 /* Show the dotted progress report of file loading.  Called with
@@ -191,11 +257,7 @@
       logputs (LOG_VERBOSE, tmpstr);
       if (expected)
 	print_percentage (nrow * line_bytes + ndot * opt.dot_bytes + offs,
-			  expected);
-      logprintf (LOG_VERBOSE, " @%s",
-		 rate (ndot * opt.dot_bytes
-		       + offs - (initial_skip % line_bytes),
-		       time_offset, 1));
+			  expected, flags);
       logputs (LOG_VERBOSE, "\n\n");
       return 0;
     }
@@ -230,6 +292,7 @@
 	    }
 	}
       logprintf (LOG_VERBOSE, "\n%5ldK", nrow * line_bytes / 1024);
+      print_percentage (nrow * line_bytes + res, expected, flags);
     }
   /* Offset gets incremented by current value.  */
   offs += res;
@@ -250,10 +313,7 @@
 	  ndot = 0;
 	  ++nrow;
 	  if (expected)
-	    print_percentage (nrow * line_bytes, expected);
-	  logprintf (LOG_VERBOSE, " @%s",
-		     rate (line_bytes - (initial_skip % line_bytes),
-			   time_offset, 1));
+	    print_percentage (nrow * line_bytes, expected, flags);
 	  initial_skip = 0;
 	  logprintf (LOG_VERBOSE, "\n%5ldK", nrow * line_bytes / 1024);
 	}
