131
148
static struct cmdline_option option_data[] =
133
150
{ "accept", 'A', OPT_VALUE, "accept", -1 },
151
{ "adjust-extension", 'E', OPT_BOOLEAN, "adjustextension", -1 },
134
152
{ "append-output", 'a', OPT__APPEND_OUTPUT, NULL, required_argument },
153
{ "ask-password", 0, OPT_BOOLEAN, "askpassword", -1 },
135
154
{ "auth-no-challenge", 0, OPT_BOOLEAN, "authnochallenge", -1 },
136
155
{ "background", 'b', OPT_BOOLEAN, "background", -1 },
137
156
{ "backup-converted", 'K', OPT_BOOLEAN, "backupconverted", -1 },
152
171
{ "cookies", 0, OPT_BOOLEAN, "cookies", -1 },
153
172
{ "cut-dirs", 0, OPT_VALUE, "cutdirs", -1 },
154
173
{ WHEN_DEBUG ("debug"), 'd', OPT_BOOLEAN, "debug", -1 },
174
{ "default-page", 0, OPT_VALUE, "defaultpage", -1 },
155
175
{ "delete-after", 0, OPT_BOOLEAN, "deleteafter", -1 },
156
176
{ "directories", 0, OPT_BOOLEAN, "dirstruct", -1 },
157
177
{ "directory-prefix", 'P', OPT_VALUE, "dirprefix", -1 },
159
179
{ "dns-timeout", 0, OPT_VALUE, "dnstimeout", -1 },
160
180
{ "domains", 'D', OPT_VALUE, "domains", -1 },
161
181
{ "dont-remove-listing", 0, OPT__DONT_REMOVE_LISTING, NULL, no_argument },
162
{ "dot-style", 0, OPT_VALUE, "dotstyle", -1 },
182
{ "dot-style", 0, OPT_VALUE, "dotstyle", -1 }, /* deprecated */
163
183
{ "egd-file", 0, OPT_VALUE, "egdfile", -1 },
164
184
{ "exclude-directories", 'X', OPT_VALUE, "excludedirectories", -1 },
165
185
{ "exclude-domains", 0, OPT_VALUE, "excludedomains", -1 },
169
189
{ "force-directories", 'x', OPT_BOOLEAN, "dirstruct", -1 },
170
190
{ "force-html", 'F', OPT_BOOLEAN, "forcehtml", -1 },
171
191
{ "ftp-password", 0, OPT_VALUE, "ftppassword", -1 },
193
{ "ftp-stmlf", 0, OPT_BOOLEAN, "ftpstmlf", -1 },
194
#endif /* def __VMS */
172
195
{ "ftp-user", 0, OPT_VALUE, "ftpuser", -1 },
173
196
{ "glob", 0, OPT_BOOLEAN, "glob", -1 },
174
197
{ "header", 0, OPT_VALUE, "header", -1 },
175
198
{ "help", 'h', OPT_FUNCALL, (void *)print_help, no_argument },
176
199
{ "host-directories", 0, OPT_BOOLEAN, "addhostdir", -1 },
177
{ "html-extension", 'E', OPT_BOOLEAN, "htmlextension", -1 },
200
{ "html-extension", 'E', OPT_BOOLEAN, "adjustextension", -1 }, /* deprecated */
178
201
{ "htmlify", 0, OPT_BOOLEAN, "htmlify", -1 },
179
202
{ "http-keep-alive", 0, OPT_BOOLEAN, "httpkeepalive", -1 },
180
203
{ "http-passwd", 0, OPT_VALUE, "httppassword", -1 }, /* deprecated */
189
212
{ "inet6-only", '6', OPT_BOOLEAN, "inet6only", -1 },
191
214
{ "input-file", 'i', OPT_VALUE, "input", -1 },
215
{ "iri", 0, OPT_BOOLEAN, "iri", -1 },
192
216
{ "keep-session-cookies", 0, OPT_BOOLEAN, "keepsessioncookies", -1 },
193
217
{ "level", 'l', OPT_VALUE, "reclevel", -1 },
194
218
{ "limit-rate", 0, OPT_VALUE, "limitrate", -1 },
195
219
{ "load-cookies", 0, OPT_VALUE, "loadcookies", -1 },
220
{ "local-encoding", 0, OPT_VALUE, "localencoding", -1 },
196
221
{ "max-redirect", 0, OPT_VALUE, "maxredirect", -1 },
197
222
{ "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
198
223
{ "no", 'n', OPT__NO, NULL, required_argument },
207
232
{ "post-data", 0, OPT_VALUE, "postdata", -1 },
208
233
{ "post-file", 0, OPT_VALUE, "postfile", -1 },
209
234
{ "prefer-family", 0, OPT_VALUE, "preferfamily", -1 },
210
{ "preserve-permissions", 0, OPT_BOOLEAN, "preservepermissions", -1 },
235
{ "preserve-permissions", 0, OPT_BOOLEAN, "preservepermissions", -1 }, /* deprecated */
211
236
{ IF_SSL ("private-key"), 0, OPT_VALUE, "privatekey", -1 },
212
237
{ IF_SSL ("private-key-type"), 0, OPT_VALUE, "privatekeytype", -1 },
213
238
{ "progress", 0, OPT_VALUE, "progress", -1 },
226
251
{ "referer", 0, OPT_VALUE, "referer", -1 },
227
252
{ "reject", 'R', OPT_VALUE, "reject", -1 },
228
253
{ "relative", 'L', OPT_BOOLEAN, "relativeonly", -1 },
254
{ "remote-encoding", 0, OPT_VALUE, "remoteencoding", -1 },
229
255
{ "remove-listing", 0, OPT_BOOLEAN, "removelisting", -1 },
230
256
{ "restrict-file-names", 0, OPT_BOOLEAN, "restrictfilenames", -1 },
231
257
{ "retr-symlinks", 0, OPT_BOOLEAN, "retrsymlinks", -1 },
725
prompt_for_password (void)
728
printf (_("Password for user %s: "), quote (opt.user));
730
printf (_("Password: "));
734
/* Function that prints the line argument while limiting it
735
to at most line_length. prefix is printed on the first line
736
and an appropriate number of spaces are added on subsequent
739
format_and_print_line (const char *prefix, const char *line,
743
char *line_dup, *token;
745
assert (prefix != NULL);
746
assert (line != NULL);
748
line_dup = xstrdup (line);
750
if (line_length <= 0)
751
line_length = MAX_CHARS_PER_LINE - TABULATION;
753
printf ("%s", prefix);
754
remaining_chars = line_length;
755
/* We break on spaces. */
756
token = strtok (line_dup, " ");
757
while (token != NULL)
759
/* If however a token is much larger than the maximum
760
line length, all bets are off and we simply print the
761
token on the next line. */
762
if (remaining_chars <= strlen (token))
764
printf ("\n%*c", TABULATION, ' ');
765
remaining_chars = line_length - TABULATION;
767
printf ("%s ", token);
768
remaining_chars -= strlen (token) + 1; /* account for " " */
769
token = strtok (NULL, " ");
679
778
print_version (void)
681
printf ("GNU Wget %s\n\n", version_string);
780
const char *wgetrc_title = _("Wgetrc: ");
781
const char *locale_title = _("Locale: ");
782
const char *compile_title = _("Compile: ");
783
const char *link_title = _("Link: ");
785
char *env_wgetrc, *user_wgetrc;
789
printf (_("GNU Wget %s built on VMS %s %s.\n\n"),
790
version_string, vms_arch(), vms_vers());
791
#else /* def __VMS */
792
printf (_("GNU Wget %s built on %s.\n\n"), version_string, OS_TYPE);
793
#endif /* def __VMS */
794
/* compiled_features is a char*[]. We limit the characters per
795
line to MAX_CHARS_PER_LINE and prefix each line with a constant
796
number of spaces for proper alignment. */
797
for (i = 0; compiled_features[i] != NULL; )
799
int line_length = MAX_CHARS_PER_LINE;
800
while ((line_length > 0) && (compiled_features[i] != NULL))
802
printf ("%s ", compiled_features[i]);
803
line_length -= strlen (compiled_features[i]) + 2;
809
/* Handle the case when $WGETRC is unset and $HOME/.wgetrc is
811
printf ("%s\n", wgetrc_title);
812
env_wgetrc = wgetrc_env_file_name ();
813
if (env_wgetrc && *env_wgetrc)
815
printf (_(" %s (env)\n"), env_wgetrc);
818
user_wgetrc = wgetrc_user_file_name ();
821
printf (_(" %s (user)\n"), user_wgetrc);
825
printf (_(" %s (system)\n"), SYSTEM_WGETRC);
829
format_and_print_line (locale_title,
832
#endif /* def ENABLE_NLS */
834
format_and_print_line (compile_title,
838
format_and_print_line (link_title,
843
/* TRANSLATORS: When available, an actual copyright character
844
(cirle-c) should be used in preference to "(C)". */
683
Copyright (C) 2008 Free Software Foundation, Inc.\n"), stdout);
846
Copyright (C) 2009 Free Software Foundation, Inc.\n"), stdout);
685
848
License GPLv3+: GNU GPL version 3 or later\n\
686
849
<http://www.gnu.org/licenses/gpl.html>.\n\
687
850
This is free software: you are free to change and redistribute it.\n\
688
851
There is NO WARRANTY, to the extent permitted by law.\n"), stdout);
852
/* TRANSLATORS: When available, please use the proper diacritics for
853
names such as this one. See en_US.po for reference. */
689
854
fputs (_("\nOriginally written by Hrvoje Niksic <hniksic@xemacs.org>.\n"),
691
856
fputs (_("Currently maintained by Micah Cowan <micah@cowan.name>.\n"),
858
fputs (_("Please send bug reports and questions to <bug-wget@gnu.org>.\n"),
863
char *program_name; /* Needed by lib/error.c. */
698
main (int argc, char *const *argv)
866
main (int argc, char **argv)
701
869
int i, ret, longindex;
702
870
int nurl, status;
703
871
bool append_to_log = false;
873
program_name = argv[0];
705
875
i18n_initialize ();
707
877
/* Construct the name of the executable, without the directory part. */
949
1158
/* Initialize logging. */
950
1159
log_init (opt.lfilename, append_to_log);
952
DEBUGP (("DEBUG output created by Wget %s on %s.\n\n", version_string,
1161
DEBUGP (("DEBUG output created by Wget %s on %s.\n\n",
1162
version_string, OS_TYPE));
955
1164
/* Open the output filename if necessary. */
1167
Note that having the output_stream ("-O") file opened here for an FTP
1168
URL rather than in getftp() (ftp.c) (and the http equivalent) rather
1169
limits the ability in VMS to open the file differently for ASCII
1170
versus binary FTP there. (Of course, doing it here allows a open
1171
failure to be detected immediately, without first connecting to the
956
1174
if (opt.output_document)
958
1176
if (HYPHENP (opt.output_document))
959
output_stream = stdout;
1180
result = freopen ("CONOUT$", "wb", stdout);
1183
logputs (LOG_NOTQUIET, _("\
1184
WARNING: Can't reopen standard output in binary mode;\n\
1185
downloaded file may contain inappropriate line endings.\n"));
1188
output_stream = stdout;
962
1192
struct_fstat st;
1195
/* Common fopen() optional arguments:
1196
sequential access only, access callback function.
1198
# define FOPEN_OPT_ARGS , "fop=sqo", "acc", acc_cb, &open_id
1200
#else /* def __VMS */
1201
# define FOPEN_OPT_ARGS
1202
#endif /* def __VMS [else] */
963
1204
output_stream = fopen (opt.output_document,
964
opt.always_rest ? "ab" : "wb");
1205
opt.always_rest ? "ab" : "wb"
965
1207
if (output_stream == NULL)
967
1209
perror (opt.output_document);
1001
1257
for (t = url; *t; t++)
1003
1259
char *filename = NULL, *redirected_URL = NULL;
1006
if ((opt.recursive || opt.page_requisites)
1007
&& (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (*t)))
1261
/* Need to do a new struct iri every time, because
1262
* retrieve_url may modify it in some circumstances,
1264
struct iri *iri = iri_new ();
1265
struct url *url_parsed;
1267
set_uri_encoding (iri, opt.locale, true);
1268
url_parsed = url_parse (*t, &url_err, iri, true);
1009
int old_follow_ftp = opt.follow_ftp;
1011
/* Turn opt.follow_ftp on in case of recursive FTP retrieval */
1012
if (url_scheme (*t) == SCHEME_FTP)
1015
status = retrieve_tree (*t);
1017
opt.follow_ftp = old_follow_ftp;
1272
char *error = url_error (*t, url_err);
1273
logprintf (LOG_NOTQUIET, "%s: %s.\n",*t, error);
1020
status = retrieve_url (*t, &filename, &redirected_URL, NULL, &dt, opt.recursive);
1022
if (opt.delete_after && file_exists_p(filename))
1024
DEBUGP (("Removing file due to --delete-after in main():\n"));
1025
logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);
1026
if (unlink (filename))
1027
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
1279
if ((opt.recursive || opt.page_requisites)
1280
&& (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (url_parsed)))
1282
int old_follow_ftp = opt.follow_ftp;
1284
/* Turn opt.follow_ftp on in case of recursive FTP retrieval */
1285
if (url_scheme (*t) == SCHEME_FTP)
1288
status = retrieve_tree (url_parsed, NULL);
1290
opt.follow_ftp = old_follow_ftp;
1294
status = retrieve_url (url_parsed, *t, &filename, &redirected_URL,
1295
NULL, &dt, opt.recursive, iri, true);
1298
if (opt.delete_after && file_exists_p(filename))
1300
DEBUGP (("Removing file due to --delete-after in main():\n"));
1301
logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);
1302
if (unlink (filename))
1303
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
1305
xfree_null (redirected_URL);
1306
xfree_null (filename);
1307
url_free (url_parsed);
1030
xfree_null (redirected_URL);
1031
xfree_null (filename);
1034
1312
/* And then from the input file, if any. */