]> sjero.net Git - wget/blobdiff - src/main.c
removed some more calls
[wget] / src / main.c
index d4fea4f3619e81fc11e4291b4689fed39cdb729e..7388291899abc3eff8ec3b46c5e562d00d34c8cb 100644 (file)
@@ -80,6 +80,9 @@ static void redirect_output_signal (int);
 #endif
 
 const char *exec_name;
+
+/* Number of successfully downloaded URLs */
+int numurls = 0;
 \f
 #ifndef TESTING
 /* Initialize I18N/L10N.  That amounts to invoking setlocale, and
@@ -706,16 +709,18 @@ prompt_for_password (void)
    and an appropriate number of spaces are added on subsequent
    lines.*/
 static void
-format_and_print_line (const char *prefix, char *line,
+format_and_print_line (const char *prefix, const char *line,
                        int line_length) 
 {
   int leading_spaces;
   int remaining_chars;
-  char *token;
+  char *line_dup, *token;
   
   assert (prefix != NULL);
   assert (line != NULL);
 
+  line_dup = xstrdup (line);
+
   if (line_length <= 0)
     line_length = max_chars_per_line;
 
@@ -723,7 +728,7 @@ format_and_print_line (const char *prefix, char *line,
   printf ("%s", prefix);
   remaining_chars = line_length - leading_spaces;
   /* We break on spaces. */
-  token = strtok (line, " ");
+  token = strtok (line_dup, " ");
   while (token != NULL) 
     {
       /* If however a token is much larger than the maximum
@@ -731,13 +736,7 @@ format_and_print_line (const char *prefix, char *line,
          token on the next line. */
       if (remaining_chars <= strlen (token)) 
         {
-          int j;
-          printf ("\n");
-          j = 0;
-          for (j = 0; j < leading_spaces; j++) 
-            {
-              printf (" ");
-            }
+          printf ("\n%*c", leading_spaces, ' ');
           remaining_chars = line_length - leading_spaces;
         }
       printf ("%s ", token);
@@ -746,6 +745,8 @@ format_and_print_line (const char *prefix, char *line,
     }
 
   printf ("\n");
+
+  xfree (line_dup);
 }
 
 static void
@@ -803,23 +804,17 @@ print_version (void)
   putchar ('\n');
 #endif
 
-  line = xstrdup (LOCALEDIR);
   format_and_print_line (locale_title,
-                        line
+                        LOCALEDIR
                         max_chars_per_line);
-  xfree (line);
   
-  line = xstrdup (compilation_string);
   format_and_print_line (compile_title,
-                        line,
+                        compilation_string,
                         max_chars_per_line);
-  xfree (line);
 
-  line = xstrdup (link_string);
   format_and_print_line (link_title,
-                        line,
+                        link_string,
                         max_chars_per_line);
-  xfree (line);
 
   printf ("\n");
   /* TRANSLATORS: When available, an actual copyright character
@@ -1183,34 +1178,45 @@ WARNING: Can't reopen standard output in binary mode;\n\
   for (t = url; *t; t++)
     {
       char *filename = NULL, *redirected_URL = NULL;
-      int dt;
+      int dt, url_err;
+      struct url *url_parsed = url_parse (*t, &url_err);
 
-      if ((opt.recursive || opt.page_requisites)
-          && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (*t)))
+      if (!url_parsed)
         {
-          int old_follow_ftp = opt.follow_ftp;
+          char *error = url_error (*t, url_err);
+          logprintf (LOG_NOTQUIET, "%s: %s.\n",*t, error);
+          xfree (error);
+          status = URLERROR;
+        }
+      else
+        {
+          if ((opt.recursive || opt.page_requisites)
+              && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (url_parsed)))
+            {
+              int old_follow_ftp = opt.follow_ftp;
 
-          /* Turn opt.follow_ftp on in case of recursive FTP retrieval */
-          if (url_scheme (*t) == SCHEME_FTP) 
-            opt.follow_ftp = 1;
+              /* Turn opt.follow_ftp on in case of recursive FTP retrieval */
+              if (url_scheme (*t) == SCHEME_FTP) 
+                opt.follow_ftp = 1;
           
-          status = retrieve_tree (*t);
+              status = retrieve_tree (url_parsed);
 
-          opt.follow_ftp = old_follow_ftp;
-        }
-      else
-        status = retrieve_url (*t, &filename, &redirected_URL, NULL, &dt, opt.recursive);
+              opt.follow_ftp = old_follow_ftp;
+            }
+          else
+            status = retrieve_url (url_parsed, *t, &filename, &redirected_URL, NULL, &dt, opt.recursive);
 
-      if (opt.delete_after && file_exists_p(filename))
-        {
-          DEBUGP (("Removing file due to --delete-after in main():\n"));
-          logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);
-          if (unlink (filename))
-            logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
+          if (opt.delete_after && file_exists_p(filename))
+            {
+              DEBUGP (("Removing file due to --delete-after in main():\n"));
+              logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);
+              if (unlink (filename))
+                logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
+            }
+          xfree_null (redirected_URL);
+          xfree_null (filename);
+          url_free (url_parsed);
         }
-
-      xfree_null (redirected_URL);
-      xfree_null (filename);
     }
 
   /* And then from the input file, if any.  */
@@ -1239,7 +1245,7 @@ WARNING: Can't reopen standard output in binary mode;\n\
       logprintf (LOG_NOTQUIET,
                  _("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"),
                  datetime_str (time (NULL)),
-                 opt.numurls,
+                 numurls,
                  human_readable (total_downloaded_bytes),
                  secs_to_human_time (total_download_time),
                  retr_rate (total_downloaded_bytes, total_download_time));