1 /* Command line parsing.
2 Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Wget.
7 GNU Wget is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GNU Wget is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Wget; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 In addition, as a special exception, the Free Software Foundation
22 gives permission to link the code of its release of Wget with the
23 OpenSSL project's "OpenSSL" library (or with modified versions of it
24 that use the same license as the "OpenSSL" library), and distribute
25 the linked executables. You must obey the GNU General Public License
26 in all respects for all of the code used other than "OpenSSL". If you
27 modify this file, you may extend this exception to your version of the
28 file, but you are not obligated to do so. If you do not wish to do
29 so, delete this exception statement from your version. */
37 #endif /* HAVE_UNISTD_H */
38 #include <sys/types.h>
43 #endif /* HAVE_STRING_H */
50 #endif /* HAVE_LOCALE_H */
62 #include "progress.h" /* for progress_handle_sigwinch */
66 # include "gen_sslfunc.h"
69 /* On GNU system this will include system-wide getopt.h. */
72 #ifndef PATH_SEPARATOR
73 # define PATH_SEPARATOR '/'
76 extern char *version_string;
84 extern struct cookie_jar *wget_cookie_jar;
87 void log_init PARAMS ((const char *, int));
88 void log_close PARAMS ((void));
89 void log_request_redirect_output PARAMS ((const char *));
91 static RETSIGTYPE redirect_output_signal PARAMS ((int));
93 const char *exec_name;
95 /* Initialize I18N. The initialization amounts to invoking
96 setlocale(), bindtextdomain() and textdomain().
97 Does nothing if NLS is disabled or missing. */
99 i18n_initialize (void)
101 /* If HAVE_NLS is defined, assume the existence of the three
102 functions invoked here. */
104 /* Set the current locale. */
105 /* Here we use LC_MESSAGES instead of LC_ALL, for two reasons.
106 First, message catalogs are all of I18N Wget uses anyway.
107 Second, setting LC_ALL has a dangerous potential of messing
108 things up. For example, when in a foreign locale, Solaris
109 strptime() fails to handle international dates correctly, which
110 makes http_atotm() malfunction. */
112 setlocale (LC_MESSAGES, "");
113 setlocale (LC_CTYPE, "");
115 setlocale (LC_ALL, "");
117 /* Set the text message domain. */
118 bindtextdomain ("wget", LOCALEDIR);
120 #endif /* HAVE_NLS */
123 /* Print the usage message. */
127 printf (_("Usage: %s [OPTION]... [URL]...\n"), exec_name);
130 /* Print the help message, describing all the available options. If
131 you add an option, be sure to update this list. */
135 printf (_("GNU Wget %s, a non-interactive network retriever.\n"),
138 /* Had to split this in parts, so the #@@#%# Ultrix compiler and cpp
139 don't bitch. Also, it makes translation much easier. */
142 Mandatory arguments to long options are mandatory for short options too.\n\
146 -V, --version display the version of Wget and exit.\n\
147 -h, --help print this help.\n\
148 -b, --background go to background after startup.\n\
149 -e, --execute=COMMAND execute a `.wgetrc\'-style command.\n\
152 Logging and input file:\n\
153 -o, --output-file=FILE log messages to FILE.\n\
154 -a, --append-output=FILE append messages to FILE.\n\
155 -d, --debug print debug output.\n\
156 -q, --quiet quiet (no output).\n\
157 -v, --verbose be verbose (this is the default).\n\
158 -nv, --non-verbose turn off verboseness, without being quiet.\n\
159 -i, --input-file=FILE download URLs found in FILE.\n\
160 -F, --force-html treat input file as HTML.\n\
161 -B, --base=URL prepends URL to relative links in -F -i file.\n\
165 -t, --tries=NUMBER set number of retries to NUMBER (0 unlimits).\n\
166 --retry-connrefused retry even if connection is refused.\n\
167 -O --output-document=FILE write documents to FILE.\n\
168 -nc, --no-clobber don\'t clobber existing files or use .# suffixes.\n\
169 -c, --continue resume getting a partially-downloaded file.\n\
170 --progress=TYPE select progress gauge type.\n\
171 -N, --timestamping don\'t re-retrieve files unless newer than local.\n\
172 -S, --server-response print server response.\n\
173 --spider don\'t download anything.\n\
174 -T, --timeout=SECONDS set all timeout values to SECONDS.\n\
175 --dns-timeout=SECS set the DNS lookup timeout to SECS.\n\
176 --connect-timeout=SECS set the connect timeout to SECS.\n\
177 --read-timeout=SECS set the read timeout to SECS.\n\
178 -w, --wait=SECONDS wait SECONDS between retrievals.\n\
179 --waitretry=SECONDS wait 1...SECONDS between retries of a retrieval.\n\
180 --random-wait wait from 0...2*WAIT secs between retrievals.\n\
181 -Y, --proxy=on/off turn proxy on or off.\n\
182 -Q, --quota=NUMBER set retrieval quota to NUMBER.\n\
183 --bind-address=ADDRESS bind to ADDRESS (hostname or IP) on local host.\n\
184 --limit-rate=RATE limit download rate to RATE.\n\
185 --dns-cache=off disable caching DNS lookups.\n\
186 --restrict-file-names=OS restrict chars in file names to ones OS allows.\n\
190 -nd, --no-directories don\'t create directories.\n\
191 -x, --force-directories force creation of directories.\n\
192 -nH, --no-host-directories don\'t create host directories.\n\
193 -P, --directory-prefix=PREFIX save files to PREFIX/...\n\
194 --cut-dirs=NUMBER ignore NUMBER remote directory components.\n\
198 --http-user=USER set http user to USER.\n\
199 --http-passwd=PASS set http password to PASS.\n\
200 -C, --cache=on/off (dis)allow server-cached data (normally allowed).\n\
201 -E, --html-extension save all text/html documents with .html extension.\n\
202 --ignore-length ignore `Content-Length\' header field.\n\
203 --header=STRING insert STRING among the headers.\n\
204 --proxy-user=USER set USER as proxy username.\n\
205 --proxy-passwd=PASS set PASS as proxy password.\n\
206 --referer=URL include `Referer: URL\' header in HTTP request.\n\
207 -s, --save-headers save the HTTP headers to file.\n\
208 -U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION.\n\
209 --no-http-keep-alive disable HTTP keep-alive (persistent connections).\n\
210 --cookies=off don't use cookies.\n\
211 --load-cookies=FILE load cookies from FILE before session.\n\
212 --save-cookies=FILE save cookies to FILE after session.\n\
213 --post-data=STRING use the POST method; send STRING as the data.\n\
214 --post-file=FILE use the POST method; send contents of FILE.\n\
218 HTTPS (SSL) options:\n\
219 --sslcertfile=FILE optional client certificate.\n\
220 --sslcertkey=KEYFILE optional keyfile for this certificate.\n\
221 --egd-file=FILE file name of the EGD socket.\n\
222 --sslcadir=DIR dir where hash list of CA's are stured.\n\
223 --sslcafile=FILE file with bundle of CA's\n\
224 --sslcerttype=0/1 Client-Cert type 0=PEM (default) / 1=ASN1 (DER)\n\
225 --sslcheckcert=0/1 Check the server cert agenst given CA\n\
226 --sslprotocol=0-3 choose SSL protocol; 0=automatic,\n\
227 1=SSLv2 2=SSLv3 3=TLSv1\n\
232 -nr, --dont-remove-listing don\'t remove `.listing\' files.\n\
233 -g, --glob=on/off turn file name globbing on or off.\n\
234 --passive-ftp use the \"passive\" transfer mode.\n\
235 --retr-symlinks when recursing, get linked-to files (not dirs).\n\
238 Recursive retrieval:\n\
239 -r, --recursive recursive download.\n\
240 -l, --level=NUMBER maximum recursion depth (inf or 0 for infinite).\n\
241 --delete-after delete files locally after downloading them.\n\
242 -k, --convert-links convert non-relative links to relative.\n\
243 -K, --backup-converted before converting file X, back up as X.orig.\n\
244 -m, --mirror shortcut option equivalent to -r -N -l inf -nr.\n\
245 -p, --page-requisites get all images, etc. needed to display HTML page.\n\
246 --strict-comments turn on strict (SGML) handling of HTML comments.\n\
249 Recursive accept/reject:\n\
250 -A, --accept=LIST comma-separated list of accepted extensions.\n\
251 -R, --reject=LIST comma-separated list of rejected extensions.\n\
252 -D, --domains=LIST comma-separated list of accepted domains.\n\
253 --exclude-domains=LIST comma-separated list of rejected domains.\n\
254 --follow-ftp follow FTP links from HTML documents.\n\
255 --follow-tags=LIST comma-separated list of followed HTML tags.\n\
256 -G, --ignore-tags=LIST comma-separated list of ignored HTML tags.\n\
257 -H, --span-hosts go to foreign hosts when recursive.\n\
258 -L, --relative follow relative links only.\n\
259 -I, --include-directories=LIST list of allowed directories.\n\
260 -X, --exclude-directories=LIST list of excluded directories.\n\
261 -np, --no-parent don\'t ascend to the parent directory.\n\
263 fputs (_("Mail bug reports and suggestions to <bug-wget@gnu.org>.\n"),
268 main (int argc, char *const *argv)
271 int i, c, nurl, status, append_to_log;
273 static struct option long_options[] =
275 /* Options without arguments: */
276 { "background", no_argument, NULL, 'b' },
277 { "backup-converted", no_argument, NULL, 'K' },
278 { "continue", no_argument, NULL, 'c' },
279 { "convert-links", no_argument, NULL, 'k' },
280 { "debug", no_argument, NULL, 'd' },
281 { "delete-after", no_argument, NULL, 136 },
282 { "dont-remove-listing", no_argument, NULL, 149 },
283 { "follow-ftp", no_argument, NULL, 142 },
284 { "force-directories", no_argument, NULL, 'x' },
285 { "force-hier", no_argument, NULL, 'x' }, /* obsolete */
286 { "force-html", no_argument, NULL, 'F'},
287 { "help", no_argument, NULL, 'h' },
288 { "html-extension", no_argument, NULL, 'E' },
289 { "ignore-length", no_argument, NULL, 138 },
290 { "mirror", no_argument, NULL, 'm' },
291 { "no-clobber", no_argument, NULL, 141 },
292 { "no-directories", no_argument, NULL, 147 },
293 { "no-host-directories", no_argument, NULL, 148 },
294 { "no-host-lookup", no_argument, NULL, 150 },
295 { "no-http-keep-alive", no_argument, NULL, 156 },
296 { "no-parent", no_argument, NULL, 133 },
297 { "non-verbose", no_argument, NULL, 146 },
298 { "passive-ftp", no_argument, NULL, 139 },
299 { "page-requisites", no_argument, NULL, 'p' },
300 { "quiet", no_argument, NULL, 'q' },
301 { "random-wait", no_argument, NULL, 165 },
302 { "recursive", no_argument, NULL, 'r' },
303 { "relative", no_argument, NULL, 'L' },
304 { "retr-symlinks", no_argument, NULL, 137 },
305 { "retry-connrefused", no_argument, NULL, 174 },
306 { "save-headers", no_argument, NULL, 's' },
307 { "server-response", no_argument, NULL, 'S' },
308 { "span-hosts", no_argument, NULL, 'H' },
309 { "spider", no_argument, NULL, 132 },
310 { "strict-comments", no_argument, NULL, 177 },
311 { "timestamping", no_argument, NULL, 'N' },
312 { "verbose", no_argument, NULL, 'v' },
313 { "version", no_argument, NULL, 'V' },
315 /* Options accepting an argument: */
316 { "accept", required_argument, NULL, 'A' },
317 { "append-output", required_argument, NULL, 'a' },
318 { "backups", required_argument, NULL, 151 }, /* undocumented */
319 { "base", required_argument, NULL, 'B' },
320 { "bind-address", required_argument, NULL, 155 },
321 { "cache", required_argument, NULL, 'C' },
322 { "connect-timeout", required_argument, NULL, 180 },
323 { "cookies", required_argument, NULL, 160 },
324 { "cut-dirs", required_argument, NULL, 145 },
325 { "dns-timeout", required_argument, NULL, 178 },
326 { "directory-prefix", required_argument, NULL, 'P' },
327 { "dns-cache", required_argument, NULL, 175 },
328 { "domains", required_argument, NULL, 'D' },
329 { "dot-style", required_argument, NULL, 134 },
330 { "execute", required_argument, NULL, 'e' },
331 { "exclude-directories", required_argument, NULL, 'X' },
332 { "exclude-domains", required_argument, NULL, 140 },
333 { "follow-tags", required_argument, NULL, 153 },
334 { "glob", required_argument, NULL, 'g' },
335 { "header", required_argument, NULL, 131 },
336 { "htmlify", required_argument, NULL, 135 },
337 { "http-passwd", required_argument, NULL, 130 },
338 { "http-user", required_argument, NULL, 129 },
339 { "ignore-tags", required_argument, NULL, 'G' },
340 { "include-directories", required_argument, NULL, 'I' },
341 { "input-file", required_argument, NULL, 'i' },
342 { "level", required_argument, NULL, 'l' },
343 { "limit-rate", required_argument, NULL, 164 },
344 { "load-cookies", required_argument, NULL, 161 },
345 { "no", required_argument, NULL, 'n' },
346 { "output-document", required_argument, NULL, 'O' },
347 { "output-file", required_argument, NULL, 'o' },
348 { "post-data", required_argument, NULL, 167 },
349 { "post-file", required_argument, NULL, 168 },
350 { "progress", required_argument, NULL, 163 },
351 { "proxy", required_argument, NULL, 'Y' },
352 { "proxy-passwd", required_argument, NULL, 144 },
353 { "proxy-user", required_argument, NULL, 143 },
354 { "quota", required_argument, NULL, 'Q' },
355 { "read-timeout", required_argument, NULL, 179 },
356 { "reject", required_argument, NULL, 'R' },
357 { "restrict-file-names", required_argument, NULL, 176 },
358 { "save-cookies", required_argument, NULL, 162 },
359 { "timeout", required_argument, NULL, 'T' },
360 { "tries", required_argument, NULL, 't' },
361 { "user-agent", required_argument, NULL, 'U' },
362 { "referer", required_argument, NULL, 157 },
363 { "use-proxy", required_argument, NULL, 'Y' },
365 { "sslcertfile", required_argument, NULL, 158 },
366 { "sslcertkey", required_argument, NULL, 159 },
367 { "egd-file", required_argument, NULL, 166 },
368 { "sslcadir", required_argument, NULL, 169},
369 { "sslcafile", required_argument, NULL, 170},
370 { "sslcerttype", required_argument, NULL, 171},
371 { "sslcheckcert", required_argument, NULL, 172},
372 { "sslprotocol", required_argument, NULL, 173},
373 #endif /* HAVE_SSL */
374 { "wait", required_argument, NULL, 'w' },
375 { "waitretry", required_argument, NULL, 152 },
383 /* Construct the name of the executable, without the directory part. */
384 exec_name = strrchr (argv[0], PATH_SEPARATOR);
391 windows_main_junk (&argc, (char **) argv, (char **) &exec_name);
394 initialize (); /* sets option defaults; reads the system wgetrc and .wgetrc */
396 /* [Is the order of the option letters significant? If not, they should be
397 alphabetized, like the long_options. The only thing I know for sure is
398 that the options with required arguments must be followed by a ':'.
399 -- Dan Harkless <wget@harkless.org>] */
400 while ((c = getopt_long (argc, argv, "\
401 hpVqvdkKsxmNWrHSLcFbEY:G:g:T:U:O:l:n:i:o:a:t:D:A:R:P:B:e:Q:X:I:w:C:",
402 long_options, (int *)0)) != EOF)
406 /* Options without arguments: */
408 setoptval ("spider", "on");
411 setoptval ("noparent", "on");
414 setoptval ("deleteafter", "on");
417 setoptval ("retrsymlinks", "on");
420 setoptval ("ignorelength", "on");
423 setoptval ("passiveftp", "on");
426 setoptval ("noclobber", "on");
429 setoptval ("followftp", "on");
432 setoptval ("cutdirs", optarg);
435 setoptval ("verbose", "off");
438 setoptval ("dirstruct", "off");
441 setoptval ("addhostdir", "off");
444 setoptval ("removelisting", "off");
447 setoptval ("bindaddress", optarg);
450 setoptval ("httpkeepalive", "off");
453 setoptval ("randomwait", "on");
456 setoptval ("background", "on");
459 setoptval ("continue", "on");
463 setoptval ("debug", "on");
464 #else /* not DEBUG */
465 fprintf (stderr, _("%s: debug support not compiled in.\n"),
467 #endif /* not DEBUG */
470 setoptval ("htmlextension", "on");
473 setoptval ("forcehtml", "on");
476 setoptval ("spanhosts", "on");
486 setoptval ("backupconverted", "on");
489 setoptval ("convertlinks", "on");
492 setoptval ("relativeonly", "on");
495 setoptval ("mirror", "on");
498 setoptval ("timestamping", "on");
501 setoptval ("pagerequisites", "on");
504 setoptval ("serverresponse", "on");
507 setoptval ("saveheaders", "on");
510 setoptval ("quiet", "on");
513 setoptval ("recursive", "on");
516 printf ("GNU Wget %s\n\n", version_string);
518 Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.\n"));
520 This program is distributed in the hope that it will be useful,\n\
521 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
522 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
523 GNU General Public License for more details.\n"));
524 printf (_("\nOriginally written by Hrvoje Niksic <hniksic@arsdigita.com>.\n"));
528 setoptval ("verbose", "on");
531 setoptval ("dirstruct", "on");
534 setoptval ("retryconnrefused", "on");
537 setoptval ("strictcomments", "on");
540 /* Options accepting an argument: */
542 setoptval ("httpuser", optarg);
545 setoptval ("httppasswd", optarg);
548 setoptval ("header", optarg);
551 setoptval ("dotstyle", optarg);
554 setoptval ("htmlify", optarg);
557 setoptval ("excludedomains", optarg);
560 setoptval ("proxyuser", optarg);
563 setoptval ("proxypasswd", optarg);
566 setoptval ("backups", optarg);
569 setoptval ("waitretry", optarg);
572 setoptval ("followtags", optarg);
575 setoptval ("cookies", optarg);
578 setoptval ("loadcookies", optarg);
581 setoptval ("savecookies", optarg);
584 setoptval ("progress", optarg);
587 setoptval ("limitrate", optarg);
590 setoptval ("referer", optarg);
594 setoptval ("sslcertfile", optarg);
597 setoptval ("sslcertkey", optarg);
600 setoptval ("egdfile", optarg);
603 setoptval ("sslcadir", optarg);
606 setoptval ("sslcafile", optarg);
609 setoptval ("sslcerttype", optarg);
612 setoptval ("sslcheckcert", optarg);
615 setoptval ("sslprotocol", optarg);
617 #endif /* HAVE_SSL */
619 setoptval ("postdata", optarg);
622 setoptval ("postfile", optarg);
625 setoptval ("dnscache", optarg);
628 setoptval ("restrictfilenames", optarg);
631 setoptval ("dnstimeout", optarg);
634 setoptval ("readtimeout", optarg);
637 setoptval ("connecttimeout", optarg);
640 setoptval ("accept", optarg);
643 setoptval ("logfile", optarg);
647 setoptval ("base", optarg);
650 setoptval ("cache", optarg);
653 setoptval ("domains", optarg);
656 run_command (optarg);
659 setoptval ("ignoretags", optarg);
662 setoptval ("glob", optarg);
665 setoptval ("includedirectories", optarg);
668 setoptval ("input", optarg);
671 setoptval ("reclevel", optarg);
675 /* #### What we really want here is --no-foo. */
678 for (p = optarg; *p; p++)
682 setoptval ("verbose", "off");
685 setoptval ("addhostdir", "off");
688 setoptval ("dirstruct", "off");
691 setoptval ("noclobber", "on");
694 setoptval ("removelisting", "off");
697 setoptval ("noparent", "on");
700 setoptval ("httpkeepalive", "off");
703 printf (_("%s: illegal option -- `-n%c'\n"), exec_name, *p);
706 printf (_("Try `%s --help\' for more options.\n"), exec_name);
712 setoptval ("outputdocument", optarg);
715 setoptval ("logfile", optarg);
718 setoptval ("dirprefix", optarg);
721 setoptval ("quota", optarg);
724 setoptval ("reject", optarg);
727 setoptval ("timeout", optarg);
730 setoptval ("tries", optarg);
733 setoptval ("useragent", optarg);
736 setoptval ("wait", optarg);
739 setoptval ("excludedirectories", optarg);
742 setoptval ("useproxy", optarg);
748 printf (_("Try `%s --help' for more options.\n"), exec_name);
754 /* All user options have now been processed, so it's now safe to do
755 interoption dependency checks. */
757 if (opt.reclevel == 0)
758 opt.reclevel = INFINITE_RECURSION; /* see wget.h for commentary on this */
760 if (opt.page_requisites && !opt.recursive)
762 opt.recursive = TRUE;
764 if (!opt.no_dirstruct)
765 opt.dirstruct = TRUE; /* usually handled by cmd_spec_recursive() */
768 if (opt.verbose == -1)
769 opt.verbose = !opt.quiet;
772 if (opt.verbose && opt.quiet)
774 printf (_("Can't be verbose and quiet at the same time.\n"));
778 if (opt.timestamping && opt.noclobber)
781 Can't timestamp and not clobber old files at the same time.\n"));
785 nurl = argc - optind;
786 if (!nurl && !opt.input_filename)
788 /* No URL specified. */
789 printf (_("%s: missing URL\n"), exec_name);
792 /* #### Something nicer should be printed here -- similar to the
793 pre-1.5 `--help' page. */
794 printf (_("Try `%s --help' for more options.\n"), exec_name);
799 fork_to_background ();
801 /* Initialize progress. Have to do this after the options are
802 processed so we know where the log file is. */
804 set_progress_implementation (opt.progress_type);
806 /* Allocate basic pointer. */
807 url = ALLOCA_ARRAY (char *, nurl + 1);
808 /* Fill in the arguments. */
809 for (i = 0; i < nurl; i++, optind++)
811 char *rewritten = rewrite_shorthand_url (argv[optind]);
815 url[i] = xstrdup (argv[optind]);
819 /* Change the title of console window on Windows. #### I think this
820 statement should belong to retrieve_url(). --hniksic. */
822 ws_changetitle (*url, nurl);
825 /* Initialize logging. */
826 log_init (opt.lfilename, append_to_log);
828 DEBUGP (("DEBUG output created by Wget %s on %s.\n\n", version_string,
831 /* Open the output filename if necessary. */
832 if (opt.output_document)
834 if (HYPHENP (opt.output_document))
839 opt.dfp = fopen (opt.output_document, opt.always_rest ? "ab" : "wb");
842 perror (opt.output_document);
845 if (fstat (fileno (opt.dfp), &st) == 0 && S_ISREG (st.st_mode))
846 opt.od_known_regular = 1;
854 /* Setup the signal handler to redirect output when hangup is
857 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
858 signal(SIGHUP, redirect_output_signal);
859 /* ...and do the same for SIGUSR1. */
860 signal (SIGUSR1, redirect_output_signal);
861 /* Writing to a closed socket normally signals SIGPIPE, and the
862 process exits. What we want is to ignore SIGPIPE and just check
863 for the return value of write(). */
864 signal (SIGPIPE, SIG_IGN);
866 signal (SIGWINCH, progress_handle_sigwinch);
868 #endif /* HAVE_SIGNAL */
871 /* Must call this before resolving any URLs because it has the power
872 to disable `https'. */
876 status = RETROK; /* initialize it, just-in-case */
877 /* Retrieve the URLs from argument list. */
878 for (t = url; *t; t++)
880 char *filename = NULL, *redirected_URL = NULL;
883 if (opt.recursive && url_scheme (*t) != SCHEME_FTP)
884 status = retrieve_tree (*t);
886 status = retrieve_url (*t, &filename, &redirected_URL, NULL, &dt);
888 if (opt.delete_after && file_exists_p(filename))
890 DEBUGP (("Removing file due to --delete-after in main():\n"));
891 logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);
892 if (unlink (filename))
893 logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
896 FREE_MAYBE (redirected_URL);
897 FREE_MAYBE (filename);
900 /* And then from the input file, if any. */
901 if (opt.input_filename)
904 status = retrieve_from_file (opt.input_filename, opt.force_html, &count);
906 logprintf (LOG_NOTQUIET, _("No URLs found in %s.\n"),
909 /* Print the downloaded sum. */
912 || (opt.input_filename && opt.downloaded != 0))
914 logprintf (LOG_NOTQUIET,
915 _("\nFINISHED --%s--\nDownloaded: %s bytes in %d files\n"),
917 (opt.downloaded_overflow ?
918 "<overflow>" : legible_very_long (opt.downloaded)),
920 /* Print quota warning, if exceeded. */
921 if (downloaded_exceeds_quota ())
922 logprintf (LOG_NOTQUIET,
923 _("Download quota (%s bytes) EXCEEDED!\n"),
924 legible (opt.quota));
927 if (opt.cookies_output && wget_cookie_jar)
928 cookie_jar_save (wget_cookie_jar, opt.cookies_output);
930 if (opt.convert_links && !opt.delete_after)
932 convert_all_links ();
936 for (i = 0; i < nurl; i++)
941 print_malloc_debug_stats ();
943 if (status == RETROK)
950 /* Hangup signal handler. When wget receives SIGHUP or SIGUSR1, it
951 will proceed operation as usual, trying to write into a log file.
952 If that is impossible, the output will be turned off.
954 #### It is unsafe to do call libc functions from a signal handler.
955 What we should do is, set a global variable, and have the code in
959 redirect_output_signal (int sig)
961 char *signal_name = (sig == SIGHUP ? "SIGHUP" :
962 (sig == SIGUSR1 ? "SIGUSR1" :
964 log_request_redirect_output (signal_name);
965 progress_schedule_redirect ();
966 signal (sig, redirect_output_signal);
968 #endif /* HAVE_SIGNAL */