X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fmain.c;h=81277c35742b63c474937b00e43f528f68d814db;hp=5f40897a67d94ad91bd7bc079fc38b0cdf1f4172;hb=2f6aa1d7417df1dfc58597777686fbd77179b9fd;hpb=3e25a9817f47fbb8660cc6a3b2f3eea239526c6c diff --git a/src/main.c b/src/main.c index 5f40897a..81277c35 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ /* Command line parsing. Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, + Inc. This file is part of GNU Wget. @@ -32,9 +33,7 @@ as that of the covered work. */ #include #include -#ifdef HAVE_UNISTD_H -# include -#endif /* HAVE_UNISTD_H */ +#include #include #include #ifdef ENABLE_NLS @@ -55,6 +54,7 @@ as that of the covered work. */ #include "convert.h" #include "spider.h" #include "http.h" /* for save_cookies */ +#include "ptimer.h" #include #include @@ -164,6 +164,7 @@ static struct cmdline_option option_data[] = { IF_SSL ("certificate-type"), 0, OPT_VALUE, "certificatetype", -1 }, { IF_SSL ("check-certificate"), 0, OPT_BOOLEAN, "checkcertificate", -1 }, { "clobber", 0, OPT__CLOBBER, NULL, optional_argument }, + { "config", 0, OPT_VALUE, "chooseconfig", -1 }, { "connect-timeout", 0, OPT_VALUE, "connecttimeout", -1 }, { "continue", 'c', OPT_BOOLEAN, "continue", -1 }, { "convert-links", 'k', OPT_BOOLEAN, "convertlinks", -1 }, @@ -266,6 +267,7 @@ static struct cmdline_option option_data[] = { "timeout", 'T', OPT_VALUE, "timeout", -1 }, { "timestamping", 'N', OPT_BOOLEAN, "timestamping", -1 }, { "tries", 't', OPT_VALUE, "tries", -1 }, + { "unlink", 0, OPT_BOOLEAN, "unlink", -1 }, { "trust-server-names", 0, OPT_BOOLEAN, "trustservernames", -1 }, { "use-server-timestamps", 0, OPT_BOOLEAN, "useservertimestamps", -1 }, { "user", 0, OPT_VALUE, "user", -1 }, @@ -439,6 +441,8 @@ Logging and input file:\n"), N_("\ -B, --base=URL resolves HTML input-file links (-i -F)\n\ relative to URL.\n"), + N_("\ + --config=FILE Specify config file to use.\n"), "\n", N_("\ @@ -451,7 +455,7 @@ Download:\n"), -O, --output-document=FILE write documents to FILE.\n"), N_("\ -nc, --no-clobber skip downloads that would download to\n\ - existing files.\n"), + existing files (overwriting them).\n"), N_("\ -c, --continue resume getting a partially-downloaded file.\n"), N_("\ @@ -515,6 +519,8 @@ Download:\n"), --local-encoding=ENC use ENC as the local encoding for IRIs.\n"), N_("\ --remote-encoding=ENC use ENC as the default remote encoding.\n"), + N_("\ + --unlink remove file before clobber.\n"), "\n", N_("\ @@ -681,7 +687,8 @@ Recursive accept/reject:\n"), N_("\ -I, --include-directories=LIST list of allowed directories.\n"), N_("\ - --trust-server-names use the name specified by the redirection url last component.\n"), + --trust-server-names use the name specified by the redirection\n\ + url last component.\n"), N_("\ -X, --exclude-directories=LIST list of excluded directories.\n"), N_("\ @@ -868,11 +875,16 @@ main (int argc, char **argv) { char **url, **t; int i, ret, longindex; - int nurl, status; + int nurl; bool append_to_log = false; + total_downloaded_bytes = 0; + program_name = argv[0]; + struct ptimer *timer = ptimer_new (); + double start_time = ptimer_measure (timer); + i18n_initialize (); /* Construct the name of the executable, without the directory part. */ @@ -892,10 +904,46 @@ main (int argc, char **argv) windows_main ((char **) &exec_name); #endif - /* Set option defaults; read the system wgetrc and ~/.wgetrc. */ - initialize (); + /* Load the hard-coded defaults. */ + defaults (); init_switches (); + + /* This seperate getopt_long is needed to find the user config + and parse it before the other user options. */ + longindex = -1; + int retconf; + bool use_userconfig = false; + + while ((retconf = getopt_long (argc, argv, + short_options, long_options, &longindex)) != -1) + { + int confval; + bool userrc_ret = true; + struct cmdline_option *config_opt; + confval = long_options[longindex].val; + config_opt = &option_data[confval & ~BOOLEAN_NEG_MARKER]; + if (strcmp (config_opt->long_name, "config") == 0) + { + userrc_ret &= run_wgetrc (optarg); + use_userconfig = true; + } + if (!userrc_ret) + { + printf ("Exiting due to error in %s\n", optarg); + exit (2); + } + else + break; + } + + /* If the user did not specify a config, read the system wgetrc and ~/.wgetrc. */ + if (use_userconfig == false) + initialize (); + + opterr = 0; + optind = 0; + longindex = -1; while ((ret = getopt_long (argc, argv, short_options, long_options, &longindex)) != -1) @@ -958,7 +1006,7 @@ main (int argc, char **argv) short options for convenience and backward compatibility. */ char *p; - for (p = optarg; *p; p++) + for (p = optarg; p && *p; p++) switch (*p) { case 'v': @@ -1015,6 +1063,14 @@ main (int argc, char **argv) /* All user options have now been processed, so it's now safe to do interoption dependency checks. */ + if (opt.noclobber && opt.convert_links) + { + fprintf (stderr, + _("Both --no-clobber and --convert-links were specified," + "only --convert-links will be used.\n")); + opt.noclobber = false; + } + if (opt.reclevel == 0) opt.reclevel = INFINITE_RECURSION; /* see recur.h for commentary */ @@ -1267,7 +1323,6 @@ outputting to a regular file.\n")); signal (SIGWINCH, progress_handle_sigwinch); #endif - status = RETROK; /* initialize it, just-in-case */ /* Retrieve the URLs from argument list. */ for (t = url; *t; t++) { @@ -1287,7 +1342,6 @@ outputting to a regular file.\n")); char *error = url_error (*t, url_err); logprintf (LOG_NOTQUIET, "%s: %s.\n",*t, error); xfree (error); - status = URLERROR; } else { @@ -1300,14 +1354,14 @@ outputting to a regular file.\n")); if (url_scheme (*t) == SCHEME_FTP) opt.follow_ftp = 1; - status = retrieve_tree (url_parsed, NULL); + retrieve_tree (url_parsed, NULL); opt.follow_ftp = old_follow_ftp; } else { - status = retrieve_url (url_parsed, *t, &filename, &redirected_URL, - NULL, &dt, opt.recursive, iri, true); + retrieve_url (url_parsed, *t, &filename, &redirected_URL, NULL, + &dt, opt.recursive, iri, true); } if (opt.delete_after && file_exists_p(filename)) @@ -1328,7 +1382,7 @@ outputting to a regular file.\n")); if (opt.input_filename) { int count; - status = retrieve_from_file (opt.input_filename, opt.force_html, &count); + retrieve_from_file (opt.input_filename, opt.force_html, &count); if (!count) logprintf (LOG_NOTQUIET, _("No URLs found in %s.\n"), opt.input_filename); @@ -1345,13 +1399,23 @@ outputting to a regular file.\n")); && total_downloaded_bytes != 0) { + double end_time = ptimer_measure (timer); + ptimer_destroy (timer); + + char *wall_time = xstrdup (secs_to_human_time (end_time - start_time)); + char *download_time = xstrdup (secs_to_human_time (total_download_time)); logprintf (LOG_NOTQUIET, - _("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"), - datetime_str (time (NULL)), - numurls, - human_readable (total_downloaded_bytes), - secs_to_human_time (total_download_time), - retr_rate (total_downloaded_bytes, total_download_time)); + _("FINISHED --%s--\nTotal wall clock time: %s\n" + "Downloaded: %d files, %s in %s (%s)\n"), + datetime_str (time (NULL)), + wall_time, + numurls, + human_readable (total_downloaded_bytes), + download_time, + retr_rate (total_downloaded_bytes, total_download_time)); + xfree (wall_time); + xfree (download_time); + /* Print quota warning, if exceeded. */ if (opt.quota && total_downloaded_bytes > opt.quota) logprintf (LOG_NOTQUIET,