1
1
/* Command line parsing.
2
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3
2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
2
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
5
6
This file is part of GNU Wget.
76
85
extern char *system_getrc;
77
86
extern char *link_string;
78
87
/* defined in build_info.c */
79
extern char *compiled_features[];
88
extern const char *compiled_features[];
80
89
/* Used for --version output in print_version */
81
90
#define MAX_CHARS_PER_LINE 72
82
91
#define TABULATION 4
164
173
{ IF_SSL ("certificate-type"), 0, OPT_VALUE, "certificatetype", -1 },
165
174
{ IF_SSL ("check-certificate"), 0, OPT_BOOLEAN, "checkcertificate", -1 },
166
175
{ "clobber", 0, OPT__CLOBBER, NULL, optional_argument },
176
{ "config", 0, OPT_VALUE, "chooseconfig", -1 },
167
177
{ "connect-timeout", 0, OPT_VALUE, "connecttimeout", -1 },
168
178
{ "continue", 'c', OPT_BOOLEAN, "continue", -1 },
169
179
{ "convert-links", 'k', OPT_BOOLEAN, "convertlinks", -1 },
266
276
{ "timeout", 'T', OPT_VALUE, "timeout", -1 },
267
277
{ "timestamping", 'N', OPT_BOOLEAN, "timestamping", -1 },
268
278
{ "tries", 't', OPT_VALUE, "tries", -1 },
279
{ "unlink", 0, OPT_BOOLEAN, "unlink", -1 },
269
280
{ "trust-server-names", 0, OPT_BOOLEAN, "trustservernames", -1 },
281
{ "use-server-timestamps", 0, OPT_BOOLEAN, "useservertimestamps", -1 },
270
282
{ "user", 0, OPT_VALUE, "user", -1 },
271
283
{ "user-agent", 'U', OPT_VALUE, "useragent", -1 },
272
284
{ "verbose", 'v', OPT_BOOLEAN, "verbose", -1 },
383
395
/* Print the usage message. */
397
print_usage (int error)
387
printf (_("Usage: %s [OPTION]... [URL]...\n"), exec_name);
399
fprintf (error ? stderr : stdout, _("Usage: %s [OPTION]... [URL]...\n"),
390
403
/* Print the help message, describing all the available options. If
449
464
-O, --output-document=FILE write documents to FILE.\n"),
451
466
-nc, --no-clobber skip downloads that would download to\n\
467
existing files (overwriting them).\n"),
454
469
-c, --continue resume getting a partially-downloaded file.\n"),
458
473
-N, --timestamping don't re-retrieve files unless newer than\n\
476
--no-use-server-timestamps don't set the local file's timestamp by\n\
477
the one on the server.\n"),
461
479
-S, --server-response print server response.\n"),
463
481
--spider don't download anything.\n"),
475
493
--waitretry=SECONDS wait 1..SECONDS between retries of a retrieval.\n"),
477
--random-wait wait from 0...2*WAIT secs between retrievals.\n"),
495
--random-wait wait from 0.5*WAIT...1.5*WAIT secs between retrievals.\n"),
479
497
--no-proxy explicitly turn off proxy.\n"),
510
528
--local-encoding=ENC use ENC as the local encoding for IRIs.\n"),
512
530
--remote-encoding=ENC use ENC as the default remote encoding.\n"),
532
--unlink remove file before clobber.\n"),
585
605
HTTPS (SSL/TLS) options:\n"),
588
607
--secure-protocol=PR choose secure protocol, one of auto, SSLv2,\n\
589
608
SSLv3, and TLSv1.\n"),
592
--secure-protocol=PR choose secure protocol, one of auto,\n\
593
SSLv3, and TLSv1.\n"),
596
610
--no-check-certificate don't validate the server's certificate.\n"),
683
697
-I, --include-directories=LIST list of allowed directories.\n"),
685
--trust-server-names use the name specified by the redirection url last component.\n"),
699
--trust-server-names use the name specified by the redirection\n\
700
url last component.\n"),
687
702
-X, --exclude-directories=LIST list of excluded directories.\n"),
697
712
printf (_("GNU Wget %s, a non-interactive network retriever.\n"),
701
716
for (i = 0; i < countof (help); i++)
702
717
fputs (_(help[i]), stdout);
734
749
prompt_for_password (void)
737
printf (_("Password for user %s: "), quote (opt.user));
752
fprintf (stderr, _("Password for user %s: "), quote (opt.user));
739
printf (_("Password: "));
754
fprintf (stderr, _("Password: "));
740
755
return getpass("");
790
805
const char *locale_title = _("Locale: ");
791
806
const char *compile_title = _("Compile: ");
792
807
const char *link_title = _("Link: ");
794
808
char *env_wgetrc, *user_wgetrc;
798
printf (_("GNU Wget %s built on VMS %s %s.\n\n"),
799
version_string, vms_arch(), vms_vers());
800
#else /* def __VMS */
801
811
printf (_("GNU Wget %s built on %s.\n\n"), version_string, OS_TYPE);
802
#endif /* def __VMS */
803
/* compiled_features is a char*[]. We limit the characters per
804
line to MAX_CHARS_PER_LINE and prefix each line with a constant
805
number of spaces for proper alignment. */
806
813
for (i = 0; compiled_features[i] != NULL; )
808
815
int line_length = MAX_CHARS_PER_LINE;
840
848
MAX_CHARS_PER_LINE);
841
849
#endif /* def ENABLE_NLS */
843
format_and_print_line (compile_title,
851
if (compilation_string != NULL)
852
format_and_print_line (compile_title,
847
format_and_print_line (link_title,
856
if (link_string != NULL)
857
format_and_print_line (link_title,
852
862
/* TRANSLATORS: When available, an actual copyright character
862
872
names such as this one. See en_US.po for reference. */
863
873
fputs (_("\nOriginally written by Hrvoje Niksic <hniksic@xemacs.org>.\n"),
865
fputs (_("Currently maintained by Micah Cowan <micah@cowan.name>.\n"),
867
875
fputs (_("Please send bug reports and questions to <bug-wget@gnu.org>.\n"),
878
886
int i, ret, longindex;
880
888
bool append_to_log = false;
890
total_downloaded_bytes = 0;
882
892
program_name = argv[0];
894
struct ptimer *timer = ptimer_new ();
895
double start_time = ptimer_measure (timer);
884
897
i18n_initialize ();
886
899
/* Construct the name of the executable, without the directory part. */
901
/* On VMS, lose the "dev:[dir]" prefix and the ".EXE;nnn" suffix. */
902
exec_name = vms_basename (argv[0]);
903
#else /* def __VMS */
887
904
exec_name = strrchr (argv[0], PATH_SEPARATOR);
889
906
exec_name = argv[0];
909
#endif /* def __VMS [else] */
894
912
/* Drop extension (typically .EXE) from executable filename. */
895
913
windows_main ((char **) &exec_name);
898
/* Set option defaults; read the system wgetrc and ~/.wgetrc. */
916
/* Load the hard-coded defaults. */
901
919
init_switches ();
921
/* This seperate getopt_long is needed to find the user config
922
and parse it before the other user options. */
925
bool use_userconfig = false;
927
while ((retconf = getopt_long (argc, argv,
928
short_options, long_options, &longindex)) != -1)
931
bool userrc_ret = true;
932
struct cmdline_option *config_opt;
933
confval = long_options[longindex].val;
934
config_opt = &option_data[confval & ~BOOLEAN_NEG_MARKER];
935
if (strcmp (config_opt->long_name, "config") == 0)
937
userrc_ret &= run_wgetrc (optarg);
938
use_userconfig = true;
942
printf ("Exiting due to error in %s\n", optarg);
949
/* If the user did not specify a config, read the system wgetrc and ~/.wgetrc. */
950
if (use_userconfig == false)
903
957
while ((ret = getopt_long (argc, argv,
904
958
short_options, long_options, &longindex)) != -1)
980
1034
setoptval ("noparent", "1", opt->long_name);
983
printf (_("%s: illegal option -- `-n%c'\n"), exec_name, *p);
986
printf (_("Try `%s --help' for more options.\n"), exec_name);
1037
fprintf (stderr, _("%s: illegal option -- `-n%c'\n"),
1040
fprintf (stderr, "\n");
1041
fprintf (stderr, _("Try `%s --help' for more options.\n"),
1016
1072
/* All user options have now been processed, so it's now safe to do
1017
1073
interoption dependency checks. */
1075
if (opt.noclobber && opt.convert_links)
1078
_("Both --no-clobber and --convert-links were specified,"
1079
"only --convert-links will be used.\n"));
1080
opt.noclobber = false;
1019
1083
if (opt.reclevel == 0)
1020
1084
opt.reclevel = INFINITE_RECURSION; /* see recur.h for commentary */
1038
1102
/* Sanity checks. */
1039
1103
if (opt.verbose && opt.quiet)
1041
printf (_("Can't be verbose and quiet at the same time.\n"));
1105
fprintf (stderr, _("Can't be verbose and quiet at the same time.\n"));
1045
1109
if (opt.timestamping && opt.noclobber)
1111
fprintf (stderr, _("\
1048
1112
Can't timestamp and not clobber old files at the same time.\n"));
1052
1116
#ifdef ENABLE_IPV6
1053
1117
if (opt.ipv4_only && opt.ipv6_only)
1055
printf (_("Cannot specify both --inet4-only and --inet6-only.\n"));
1120
_("Cannot specify both --inet4-only and --inet6-only.\n"));
1066
1131
Cannot specify both -k and -O if multiple URLs are given, or in combination\n\
1067
with -p or -r. See the manual for details.\n\n"), stdout);
1132
with -p or -r. See the manual for details.\n\n"), stderr);
1071
1136
if (opt.page_requisites
1085
1150
if (opt.noclobber && file_exists_p(opt.output_document))
1087
1152
/* Check if output file exists; if it does, exit. */
1088
logprintf (LOG_VERBOSE, _("File `%s' already there; not retrieving.\n"), opt.output_document);
1153
logprintf (LOG_VERBOSE,
1154
_("File `%s' already there; not retrieving.\n"),
1155
opt.output_document);
1093
1160
if (opt.ask_passwd && opt.passwd)
1095
printf (_("Cannot specify both --ask-password and --password.\n"));
1163
_("Cannot specify both --ask-password and --password.\n"));
1100
1168
if (!nurl && !opt.input_filename)
1102
1170
/* No URL specified. */
1103
printf (_("%s: missing URL\n"), exec_name);
1171
fprintf (stderr, _("%s: missing URL\n"), exec_name);
1106
1174
/* #### Something nicer should be printed here -- similar to the
1107
1175
pre-1.5 `--help' page. */
1108
printf (_("Try `%s --help' for more options.\n"), exec_name);
1176
fprintf (stderr, _("Try `%s --help' for more options.\n"), exec_name);
1122
1190
opt.encoding_remote = NULL;
1193
memset (&dummy_iri, 0, sizeof (dummy_iri));
1125
1194
if (opt.enable_iri || opt.locale || opt.encoding_remote)
1127
1196
/* sXXXav : be more specific... */
1128
printf(_("This version does not have support for IRIs\n"));
1197
fprintf (stderr, _("This version does not have support for IRIs\n"));
1185
1254
if (HYPHENP (opt.output_document))
1189
result = freopen ("CONOUT$", "wb", stdout);
1192
logputs (LOG_NOTQUIET, _("\
1193
WARNING: Can't reopen standard output in binary mode;\n\
1194
downloaded file may contain inappropriate line endings.\n"));
1257
_setmode (_fileno (stdout), _O_BINARY);
1197
1259
output_stream = stdout;
1221
1283
if (fstat (fileno (output_stream), &st) == 0 && S_ISREG (st.st_mode))
1222
1284
output_stream_regular = true;
1286
if (!output_stream_regular && opt.convert_links)
1288
fprintf (stderr, _("-k can be used together with -O only if \
1289
outputting to a regular file.\n"));
1228
1297
any), otherwise according to the current default device.
1230
1299
if (output_stream == NULL)
1232
set_ods5_dest( "SYS$DISK");
1300
set_ods5_dest( "SYS$DISK");
1234
1301
else if (output_stream != stdout)
1236
set_ods5_dest( opt.output_document);
1302
set_ods5_dest( opt.output_document);
1238
1303
#endif /* def __VMS */
1281
1345
char *error = url_error (*t, url_err);
1282
1346
logprintf (LOG_NOTQUIET, "%s: %s.\n",*t, error);
1348
inform_exit_status (URLERROR);
1294
1358
if (url_scheme (*t) == SCHEME_FTP)
1295
1359
opt.follow_ftp = 1;
1297
status = retrieve_tree (url_parsed, NULL);
1361
retrieve_tree (url_parsed, NULL);
1299
1363
opt.follow_ftp = old_follow_ftp;
1303
status = retrieve_url (url_parsed, *t, &filename, &redirected_URL,
1304
NULL, &dt, opt.recursive, iri, true);
1367
retrieve_url (url_parsed, *t, &filename, &redirected_URL, NULL,
1368
&dt, opt.recursive, iri, true);
1307
1371
if (opt.delete_after && file_exists_p(filename))
1322
1386
if (opt.input_filename)
1325
1390
status = retrieve_from_file (opt.input_filename, opt.force_html, &count);
1391
inform_exit_status (status);
1327
1393
logprintf (LOG_NOTQUIET, _("No URLs found in %s.\n"),
1328
1394
opt.input_filename);
1342
1406
total_downloaded_bytes != 0)
1408
double end_time = ptimer_measure (timer);
1409
ptimer_destroy (timer);
1411
char *wall_time = xstrdup (secs_to_human_time (end_time - start_time));
1412
char *download_time = xstrdup (secs_to_human_time (total_download_time));
1344
1413
logprintf (LOG_NOTQUIET,
1345
_("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"),
1346
datetime_str (time (NULL)),
1348
human_readable (total_downloaded_bytes),
1349
secs_to_human_time (total_download_time),
1350
retr_rate (total_downloaded_bytes, total_download_time));
1414
_("FINISHED --%s--\nTotal wall clock time: %s\n"
1415
"Downloaded: %d files, %s in %s (%s)\n"),
1416
datetime_str (time (NULL)),
1419
human_readable (total_downloaded_bytes),
1421
retr_rate (total_downloaded_bytes, total_download_time));
1423
xfree (download_time);
1351
1425
/* Print quota warning, if exceeded. */
1352
1426
if (opt.quota && total_downloaded_bytes > opt.quota)
1353
1427
logprintf (LOG_NOTQUIET,