X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fmain.c;h=8b9c11057b01091755732d381f351303b24126d1;hp=d4fea4f3619e81fc11e4291b4689fed39cdb729e;hb=50e12521d63b8b42370a07d9c9971f56ca6dc58a;hpb=fafd83c097b578be8581726cc5b52bc10bdc9238 diff --git a/src/main.c b/src/main.c index d4fea4f3..8b9c1105 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /* Command line parsing. Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Wget. @@ -80,6 +80,9 @@ static void redirect_output_signal (int); #endif const char *exec_name; + +/* Number of successfully downloaded URLs */ +int numurls = 0; #ifndef TESTING /* Initialize I18N/L10N. That amounts to invoking setlocale, and @@ -199,10 +202,12 @@ static struct cmdline_option option_data[] = { "inet6-only", '6', OPT_BOOLEAN, "inet6only", -1 }, #endif { "input-file", 'i', OPT_VALUE, "input", -1 }, + { "iri", 0, OPT_BOOLEAN, "iri", -1 }, { "keep-session-cookies", 0, OPT_BOOLEAN, "keepsessioncookies", -1 }, { "level", 'l', OPT_VALUE, "reclevel", -1 }, { "limit-rate", 0, OPT_VALUE, "limitrate", -1 }, { "load-cookies", 0, OPT_VALUE, "loadcookies", -1 }, + { "locale", 0, OPT_VALUE, "locale", -1 }, { "max-redirect", 0, OPT_VALUE, "maxredirect", -1 }, { "mirror", 'm', OPT_BOOLEAN, "mirror", -1 }, { "no", 'n', OPT__NO, NULL, required_argument }, @@ -236,6 +241,7 @@ static struct cmdline_option option_data[] = { "referer", 0, OPT_VALUE, "referer", -1 }, { "reject", 'R', OPT_VALUE, "reject", -1 }, { "relative", 'L', OPT_BOOLEAN, "relativeonly", -1 }, + { "remote-encoding", 0, OPT_VALUE, "remoteencoding", -1}, { "remove-listing", 0, OPT_BOOLEAN, "removelisting", -1 }, { "restrict-file-names", 0, OPT_BOOLEAN, "restrictfilenames", -1 }, { "retr-symlinks", 0, OPT_BOOLEAN, "retrsymlinks", -1 }, @@ -706,16 +712,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 +731,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 +739,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 +748,8 @@ format_and_print_line (const char *prefix, char *line, } printf ("\n"); + + xfree (line_dup); } static void @@ -803,23 +807,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 @@ -1082,6 +1080,27 @@ for details.\n\n")); exit (1); } +#ifdef ENABLE_IRI + if (opt.enable_iri) + { + if (opt.locale && !check_encoding_name (opt.locale)) + opt.locale = NULL; + + if (!opt.locale) + opt.locale = find_locale (); + + if (opt.encoding_remote && !check_encoding_name (opt.encoding_remote)) + opt.encoding_remote = NULL; + } +#else + if (opt.enable_iri || opt.locale || opt.encoding_remote) + { + /* sXXXav : be more specific... */ + printf(_("This version does not have support for IRIs\n")); + exit(1); + } +#endif + if (opt.ask_passwd) { opt.passwd = prompt_for_password (); @@ -1129,7 +1148,7 @@ for details.\n\n")); { #ifdef WINDOWS FILE *result; - result = freopen (NULL, "wb", stdout); + result = freopen ("CONOUT$", "wb", stdout); if (result == NULL) { logputs (LOG_NOTQUIET, _("\ @@ -1183,34 +1202,55 @@ 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; + /* Need to do a new struct iri every time, because + * retrieve_url may modify it in some circumstances, + * currently. */ + struct iri *iri = iri_new (); + struct url *url_parsed = url_parse (*t, &url_err, iri, true); + + set_uri_encoding (iri, opt.locale, true); - 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, NULL); - 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, iri); + } - 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); + iri_free (iri); } /* And then from the input file, if any. */ @@ -1239,7 +1279,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));