]> sjero.net Git - wget/blobdiff - src/ftp.c
[svn] Support human-readable file size printing.
[wget] / src / ftp.c
index 47face7192b9a6aa11b63ee68a8d3670b2b745b5..e138896c4dc4b40e83c2333bbbec871ba2b10a9e 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -220,6 +220,26 @@ ftp_do_port (int csock, int *local_sock)
 }
 #endif
 
+static void
+print_length (wgint size, wgint start, int authoritative)
+{
+  logprintf (LOG_VERBOSE, _("Length: %s"), with_thousand_seps (size));
+  if (size >= 1024)
+    logprintf (LOG_VERBOSE, " (%s)", human_readable (size));
+  if (start > 0)
+    {
+      if (start >= 1024)
+       logprintf (LOG_VERBOSE, _(", %s (%s) remaining"),
+                  with_thousand_seps (size - start),
+                  human_readable (size - start));
+      else
+       logprintf (LOG_VERBOSE, _(", %s remaining"),
+                  with_thousand_seps (size - start));
+    }
+  if (!authoritative)
+    logputs (LOG_VERBOSE, _(" (unauthoritative)\n"));
+}
+
 /* Retrieves a file with denoted parameters through opening an FTP
    connection to the server.  It always closes the data connection,
    and closes the control connection in case of error.  */
@@ -271,8 +291,7 @@ getftp (struct url *u, wgint *len, wgint restval, ccon *con)
       if (con->proxy)
        {
          /* If proxy is in use, log in as username@target-site. */
-         logname = xmalloc (strlen (user) + 1 + strlen (u->host) + 1);
-         sprintf (logname, "%s@%s", user, u->host);
+         logname = concat_strings (user, "@", u->host, (char *) 0);
        }
 
       /* Login to the server: */
@@ -994,20 +1013,11 @@ Error in server response, closing control connection.\n"));
 
   if (*len)
     {
-      logprintf (LOG_VERBOSE, _("Length: %s"), legible (*len));
-      if (restval)
-       logprintf (LOG_VERBOSE, _(" [%s to go]"), legible (*len - restval));
-      logputs (LOG_VERBOSE, "\n");
+      print_length (*len, restval, 1);
       expected_bytes = *len;   /* for get_contents/show_progress */
     }
   else if (expected_bytes)
-    {
-      logprintf (LOG_VERBOSE, _("Length: %s"), legible (expected_bytes));
-      if (restval)
-       logprintf (LOG_VERBOSE, _(" [%s to go]"),
-                  legible (expected_bytes - restval));
-      logputs (LOG_VERBOSE, _(" (unauthoritative)\n"));
-    }
+    print_length (expected_bytes, restval, 0);
 
   /* Get the contents of the document.  */
   flags = 0;
@@ -1114,7 +1124,7 @@ Error in server response, closing control connection.\n"));
          char *line;
          /* The lines are being read with read_whole_line because of
             no-buffering on opt.lfile.  */
-         while ((line = read_whole_line (fp)))
+         while ((line = read_whole_line (fp)) != NULL)
            {
              logprintf (LOG_ALWAYS, "%s\n", escnonprint (line));
              xfree (line);
@@ -1793,7 +1803,6 @@ ftp_retrieve_glob (struct url *u, ccon *con, int action)
          return RETRBADPATTERN;
        }
     }
-  res = RETROK;
   if (start)
     {
       /* Just get everything.  */
@@ -1843,7 +1852,6 @@ ftp_loop (struct url *u, int *dt, struct url *proxy)
   con.rs = ST_UNIX;
   con.id = NULL;
   con.proxy = proxy;
-  res = RETROK;                        /* in case it's not used */
 
   /* If the file name is empty, the user probably wants a directory
      index.  We'll provide one, properly HTML-ized.  Unless