]> sjero.net Git - wget/blob - src/main.c
2d1276b8100ea5ef34f84d68e056a643c38b4992
[wget] / src / main.c
1 /* Command line parsing.
2    Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3
4 This file is part of Wget.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include <config.h>
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <ctype.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif /* HAVE_UNISTD_H */
28 #include <sys/types.h>
29 #ifdef HAVE_STRING_H
30 # include <string.h>
31 #else
32 # include <strings.h>
33 #endif /* HAVE_STRING_H */
34 #ifdef HAVE_SIGNAL_H
35 # include <signal.h>
36 #endif
37 #ifdef HAVE_NLS
38 #ifdef HAVE_LOCALE_H
39 # include <locale.h>
40 #endif /* HAVE_LOCALE_H */
41 #endif /* HAVE_NLS */
42
43 #define OPTIONS_DEFINED_HERE    /* for options.h */
44
45 #include "wget.h"
46 #include "utils.h"
47 #include "getopt.h"
48 #include "init.h"
49 #include "retr.h"
50 #include "recur.h"
51 #include "host.h"
52
53 #ifndef PATH_SEPARATOR
54 # define PATH_SEPARATOR '/'
55 #endif
56
57 extern char *version_string;
58
59 #ifndef errno
60 extern int errno;
61 #endif
62
63 struct options opt;
64
65 /* From log.c.  */
66 void log_init PARAMS ((const char *, int));
67 void log_close PARAMS ((void));
68 void redirect_output PARAMS ((const char *));
69
70 static RETSIGTYPE redirect_output_signal PARAMS ((int));
71
72 const char *exec_name;
73 \f
74 /* Initialize I18N.  The initialization amounts to invoking
75    setlocale(), bindtextdomain() and textdomain().
76    Does nothing if NLS is disabled or missing.  */
77 static void
78 i18n_initialize (void)
79 {
80   /* If HAVE_NLS is defined, assume the existence of the three
81      functions invoked here.  */
82 #ifdef HAVE_NLS
83   /* Set the current locale.  */
84   /* Here we use LC_MESSAGES instead of LC_ALL, for two reasons.
85      First, message catalogs are all of I18N Wget uses anyway.
86      Second, setting LC_ALL has a dangerous potential of messing
87      things up.  For example, when in a foreign locale, Solaris
88      strptime() fails to handle international dates correctly, which
89      makes http_atotm() malfunction.  */
90 #ifdef LC_MESSAGES
91   setlocale (LC_MESSAGES, "");
92 #else
93   setlocale (LC_ALL, "");
94 #endif
95   /* Set the text message domain.  */
96   bindtextdomain ("wget", LOCALEDIR);
97   textdomain ("wget");
98 #endif /* HAVE_NLS */
99 }
100 \f
101 /* Print the usage message.  */
102 static void
103 print_usage (void)
104 {
105   printf (_("Usage: %s [OPTION]... [URL]...\n"), exec_name);
106 }
107
108 /* Print the help message, describing all the available options.  If
109    you add an option, be sure to update this list.  */
110 static void
111 print_help (void)
112 {
113   printf (_("GNU Wget %s, a non-interactive network retriever.\n"),
114           version_string);
115   print_usage ();
116   /* Had to split this in parts, so the #@@#%# Ultrix compiler and cpp
117      don't bitch.  Also, it makes translation much easier.  */
118   printf ("%s%s%s%s%s%s%s%s%s%s", _("\
119 \n\
120 Mandatory arguments to long options are mandatory for short options too.\n\
121 \n"), _("\
122 Startup:\n\
123   -V,  --version           display the version of Wget and exit.\n\
124   -h,  --help              print this help.\n\
125   -b,  --background        go to background after startup.\n\
126   -e,  --execute=COMMAND   execute a `.wgetrc\' command.\n\
127 \n"), _("\
128 Logging and input file:\n\
129   -o,  --output-file=FILE     log messages to FILE.\n\
130   -a,  --append-output=FILE   append messages to FILE.\n\
131   -d,  --debug                print debug output.\n\
132   -q,  --quiet                quiet (no output).\n\
133   -v,  --verbose              be verbose (this is the default).\n\
134   -nv, --non-verbose          turn off verboseness, without being quiet.\n\
135   -i,  --input-file=FILE      read URL-s from file.\n\
136   -F,  --force-html           treat input file as HTML.\n\
137 \n"), _("\
138 Download:\n\
139   -t,  --tries=NUMBER           set number of retries to NUMBER (0 unlimits).\n\
140   -O   --output-document=FILE   write documents to FILE.\n\
141   -nc, --no-clobber             don\'t clobber existing files.\n\
142   -c,  --continue               restart getting an existing file.\n\
143        --dot-style=STYLE        set retrieval display style.\n\
144   -N,  --timestamping           don\'t retrieve files if older than local.\n\
145   -S,  --server-response        print server response.\n\
146        --spider                 don\'t download anything.\n\
147   -T,  --timeout=SECONDS        set the read timeout to SECONDS.\n\
148   -w,  --wait=SECONDS           wait SECONDS between retrievals.\n\
149        --waitretry=SECONDS      wait 0..max SECONDS between retries of a retrieval.\n\
150   -Y,  --proxy=on/off           turn proxy on or off.\n\
151   -Q,  --quota=NUMBER           set retrieval quota to NUMBER.\n\
152 \n"),  _("\
153 Directories:\n\
154   -nd  --no-directories            don\'t create directories.\n\
155   -x,  --force-directories         force creation of directories.\n\
156   -nH, --no-host-directories       don\'t create host directories.\n\
157   -P,  --directory-prefix=PREFIX   save files to PREFIX/...\n\
158        --cut-dirs=NUMBER           ignore NUMBER remote directory components.\n\
159 \n"), _("\
160 HTTP options:\n\
161        --http-user=USER      set http user to USER.\n\
162        --http-passwd=PASS    set http password to PASS.\n\
163   -C,  --cache=on/off        (dis)allow server-cached data (normally allowed).\n\
164        --ignore-length       ignore `Content-Length\' header field.\n\
165        --header=STRING       insert STRING among the headers.\n\
166        --proxy-user=USER     set USER as proxy username.\n\
167        --proxy-passwd=PASS   set PASS as proxy password.\n\
168   -s,  --save-headers        save the HTTP headers to file.\n\
169   -U,  --user-agent=AGENT    identify as AGENT instead of Wget/VERSION.\n\
170 \n"), _("\
171 FTP options:\n\
172        --retr-symlinks   retrieve FTP symbolic links.\n\
173   -g,  --glob=on/off     turn file name globbing on or off.\n\
174        --passive-ftp     use the \"passive\" transfer mode.\n\
175 \n"), _("\
176 Recursive retrieval:\n\
177   -r,  --recursive             recursive web-suck -- use with care!.\n\
178   -l,  --level=NUMBER          maximum recursion depth (0 to unlimit).\n\
179        --delete-after          delete downloaded files.\n\
180   -k,  --convert-links         convert non-relative links to relative.\n\
181   -K,  --backup-converted      before converting file X, back up as X.orig.\n\
182   -m,  --mirror                turn on options suitable for mirroring.\n\
183   -nr, --dont-remove-listing   don\'t remove `.listing\' files.\n\
184 \n"), _("\
185 Recursive accept/reject:\n\
186   -A,  --accept=LIST                comma-separated list of accepted extensions.\n\
187   -R,  --reject=LIST                comma-separated list of rejected extensions.\n\
188   -D,  --domains=LIST               comma-separated list of accepted domains.\n\
189        --exclude-domains=LIST       comma-separated list of rejected domains.\n\
190        --follow-ftp                 follow FTP links from HTML documents.\n\
191        --follow-tags=LIST           comma-separated list of followed HTML tags.\n\
192   -G,  --ignore-tags=LIST           comma-separated list of ignored HTML tags.\n\
193   -H,  --span-hosts                 go to foreign hosts when recursive.\n\
194   -L,  --relative                   follow relative links only.\n\
195   -I,  --include-directories=LIST   list of allowed directories.\n\
196   -X,  --exclude-directories=LIST   list of excluded directories.\n\
197   -nh, --no-host-lookup             don\'t DNS-lookup hosts.\n\
198   -np, --no-parent                  don\'t ascend to the parent directory.\n\
199 \n"), _("Mail bug reports and suggestions to <bug-wget@gnu.org>.\n"));
200 }
201 \f
202 int
203 main (int argc, char *const *argv)
204 {
205   char **url, **t;
206   int i, c, nurl, status, append_to_log;
207   int wr = 0;
208
209   static struct option long_options[] =
210   {
211     /* Options without arguments: */
212     { "background", no_argument, NULL, 'b' },
213     { "continue", no_argument, NULL, 'c' },
214     { "convert-links", no_argument, NULL, 'k' },
215     { "backup-converted", no_argument, NULL, 'K' },
216     { "debug", no_argument, NULL, 'd' },
217     { "dont-remove-listing", no_argument, NULL, 21 },
218     { "email-address", no_argument, NULL, 'E' }, /* undocumented (debug) */
219     { "follow-ftp", no_argument, NULL, 14 },
220     { "force-directories", no_argument, NULL, 'x' },
221     { "force-hier", no_argument, NULL, 'x' }, /* obsolete */
222     { "force-html", no_argument, NULL, 'F'},
223     { "help", no_argument, NULL, 'h' },
224     { "ignore-length", no_argument, NULL, 10 },
225     { "mirror", no_argument, NULL, 'm' },
226     { "no-clobber", no_argument, NULL, 13 },
227     { "no-directories", no_argument, NULL, 19 },
228     { "no-host-directories", no_argument, NULL, 20 },
229     { "no-host-lookup", no_argument, NULL, 22 },
230     { "no-parent", no_argument, NULL, 5 },
231     { "non-verbose", no_argument, NULL, 18 },
232     { "passive-ftp", no_argument, NULL, 11 },
233     { "quiet", no_argument, NULL, 'q' },
234     { "recursive", no_argument, NULL, 'r' },
235     { "relative", no_argument, NULL, 'L' },
236     { "retr-symlinks", no_argument, NULL, 9 },
237     { "save-headers", no_argument, NULL, 's' },
238     { "server-response", no_argument, NULL, 'S' },
239     { "span-hosts", no_argument, NULL, 'H' },
240     { "spider", no_argument, NULL, 4 },
241     { "timestamping", no_argument, NULL, 'N' },
242     { "verbose", no_argument, NULL, 'v' },
243     { "version", no_argument, NULL, 'V' },
244
245     /* Options accepting an argument: */
246     { "accept", required_argument, NULL, 'A' },
247     { "append-output", required_argument, NULL, 'a' },
248     { "backups", required_argument, NULL, 23 }, /* undocumented */
249     { "base", required_argument, NULL, 'B' },
250     { "cache", required_argument, NULL, 'C' },
251     { "cut-dirs", required_argument, NULL, 17 },
252     { "delete-after", no_argument, NULL, 8 },
253     { "directory-prefix", required_argument, NULL, 'P' },
254     { "domains", required_argument, NULL, 'D' },
255     { "dot-style", required_argument, NULL, 6 },
256     { "execute", required_argument, NULL, 'e' },
257     { "exclude-directories", required_argument, NULL, 'X' },
258     { "exclude-domains", required_argument, NULL, 12 },
259     { "follow-tags", required_argument, NULL, 25 },
260     { "glob", required_argument, NULL, 'g' },
261     { "header", required_argument, NULL, 3 },
262     { "htmlify", required_argument, NULL, 7 },
263     { "http-passwd", required_argument, NULL, 2 },
264     { "http-user", required_argument, NULL, 1 },
265     { "ignore-tags", required_argument, NULL, 'G' },
266     { "include-directories", required_argument, NULL, 'I' },
267     { "input-file", required_argument, NULL, 'i' },
268     { "level", required_argument, NULL, 'l' },
269     { "no", required_argument, NULL, 'n' },
270     { "output-document", required_argument, NULL, 'O' },
271     { "output-file", required_argument, NULL, 'o' },
272     { "proxy", required_argument, NULL, 'Y' },
273     { "proxy-passwd", required_argument, NULL, 16 },
274     { "proxy-user", required_argument, NULL, 15 },
275     { "quota", required_argument, NULL, 'Q' },
276     { "reject", required_argument, NULL, 'R' },
277     { "timeout", required_argument, NULL, 'T' },
278     { "tries", required_argument, NULL, 't' },
279     { "user-agent", required_argument, NULL, 'U' },
280     { "referer", required_argument, NULL, 129 }, /* undocumented */
281     { "use-proxy", required_argument, NULL, 'Y' },
282     { "wait", required_argument, NULL, 'w' },
283     { "waitretry", required_argument, NULL, 24 }, /* partially undocumented */
284     { 0, 0, 0, 0 }
285   };
286
287   i18n_initialize ();
288
289   append_to_log = 0;
290
291   /* Construct the name of the executable, without the directory part.  */
292   exec_name = strrchr (argv[0], PATH_SEPARATOR);
293   if (!exec_name)
294     exec_name = argv[0];
295   else
296     ++exec_name;
297
298 #ifdef WINDOWS
299   windows_main_junk (&argc, (char **) argv, (char **) &exec_name);
300 #endif
301
302   initialize ();
303
304   while ((c = getopt_long (argc, argv, "\
305 hVqvdkKsxmNWrHSLcFbEY:G:g:T:U:O:l:n:i:o:a:t:D:A:R:P:B:e:Q:X:I:w:",
306                            long_options, (int *)0)) != EOF)
307     {
308       switch (c)
309         {
310           /* Options without arguments: */
311         case 4:
312           setval ("spider", "on");
313           break;
314         case 5:
315           setval ("noparent", "on");
316           break;
317         case 8:
318           setval ("deleteafter", "on");
319           break;
320         case 9:
321           setval ("retrsymlinks", "on");
322           break;
323         case 10:
324           setval ("ignorelength", "on");
325           break;
326         case 11:
327           setval ("passiveftp", "on");
328           break;
329         case 13:
330           setval ("noclobber", "on");
331           break;
332         case 14:
333           setval ("followftp", "on");
334           break;
335         case 17:
336           setval ("cutdirs", optarg);
337           break;
338         case 18:
339           setval ("verbose", "off");
340           break;
341         case 19:
342           setval ("dirstruct", "off");
343           break;
344         case 20:
345           setval ("addhostdir", "off");
346           break;
347         case 21:
348           setval ("removelisting", "off");
349           break;
350         case 22:
351           setval ("simplehostcheck", "on");
352           break;
353         case 'b':
354           setval ("background", "on");
355           break;
356         case 'c':
357           setval ("continue", "on");
358           break;
359         case 'd':
360 #ifdef DEBUG
361           setval ("debug", "on");
362 #else  /* not DEBUG */
363           fprintf (stderr, _("%s: debug support not compiled in.\n"),
364                    exec_name);
365 #endif /* not DEBUG */
366           break;
367         case 'E':
368           /* For debugging purposes.  */
369           printf ("%s\n", ftp_getaddress ());
370           exit (0);
371           break;
372         case 'F':
373           setval ("forcehtml", "on");
374           break;
375         case 'H':
376           setval ("spanhosts", "on");
377           break;
378         case 'h':
379           print_help ();
380 #ifdef WINDOWS
381           ws_help (exec_name);
382 #endif
383           exit (0);
384           break;
385         case 'K':
386           setval ("backupconverted", "on");
387           break;
388         case 'k':
389           setval ("convertlinks", "on");
390           break;
391         case 'L':
392           setval ("relativeonly", "on");
393           break;
394         case 'm':
395           setval ("mirror", "on");
396           break;
397         case 'N':
398           setval ("timestamping", "on");
399           break;
400         case 'S':
401           setval ("serverresponse", "on");
402           break;
403         case 's':
404           setval ("saveheaders", "on");
405           break;
406         case 'q':
407           setval ("quiet", "on");
408           break;
409         case 'r':
410           setval ("recursive", "on");
411           break;
412         case 'V':
413           printf ("GNU Wget %s\n\n", version_string);
414           printf ("%s", _("\
415 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.\n\
416 This program is distributed in the hope that it will be useful,\n\
417 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
418 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
419 GNU General Public License for more details.\n"));
420           printf (_("\nWritten by Hrvoje Niksic <hniksic@srce.hr>.\n"));
421           exit (0);
422           break;
423         case 'v':
424           setval ("verbose", "on");
425           break;
426         case 'x':
427           setval ("dirstruct", "on");
428           break;
429
430           /* Options accepting an argument: */
431         case 1:
432           setval ("httpuser", optarg);
433           break;
434         case 2:
435           setval ("httppasswd", optarg);
436           break;
437         case 3:
438           setval ("header", optarg);
439           break;
440         case 6:
441           setval ("dotstyle", optarg);
442           break;
443         case 7:
444           setval ("htmlify", optarg);
445           break;
446         case 12:
447           setval ("excludedomains", optarg);
448           break;
449         case 15:
450           setval ("proxyuser", optarg);
451           break;
452         case 16:
453           setval ("proxypasswd", optarg);
454           break;
455         case 23:
456           setval ("backups", optarg);
457           break;
458         case 24:
459           setval ("waitretry", optarg);
460           wr = 1;
461           break;
462         case 25:
463           setval ("followtags", optarg);
464           break;
465         case 129:
466           setval ("referer", optarg);
467           break;
468         case 'A':
469           setval ("accept", optarg);
470           break;
471         case 'a':
472           setval ("logfile", optarg);
473           append_to_log = 1;
474           break;
475         case 'B':
476           setval ("base", optarg);
477           break;
478         case 'C':
479           setval ("cache", optarg);
480           break;
481         case 'D':
482           setval ("domains", optarg);
483           break;
484         case 'e':
485           {
486             char *com, *val;
487             if (parse_line (optarg, &com, &val))
488               {
489                 if (!setval (com, val))
490                   exit (1);
491               }
492             else
493               {
494                 fprintf (stderr, _("%s: %s: invalid command\n"), exec_name,
495                          optarg);
496                 exit (1);
497               }
498             free (com);
499             free (val);
500           }
501           break;
502         case 'G':
503           setval ("ignoretags", optarg);
504           break;
505         case 'g':
506           setval ("glob", optarg);
507           break;
508         case 'I':
509           setval ("includedirectories", optarg);
510           break;
511         case 'i':
512           setval ("input", optarg);
513           break;
514         case 'l':
515           setval ("reclevel", optarg);
516           break;
517         case 'n':
518           {
519             /* #### The n? options are utter crock!  */
520             char *p;
521
522             for (p = optarg; *p; p++)
523               switch (*p)
524                 {
525                 case 'v':
526                   setval ("verbose", "off");
527                   break;
528                 case 'h':
529                   setval ("simplehostcheck", "on");
530                   break;
531                 case 'H':
532                   setval ("addhostdir", "off");
533                   break;
534                 case 'd':
535                   setval ("dirstruct", "off");
536                   break;
537                 case 'c':
538                   setval ("noclobber", "on");
539                   break;
540                 case 'r':
541                   setval ("removelisting", "off");
542                   break;
543                 case 'p':
544                   setval ("noparent", "on");
545                   break;
546                 default:
547                   printf (_("%s: illegal option -- `-n%c'\n"), exec_name, *p);
548                   print_usage ();
549                   printf ("\n");
550                   printf (_("Try `%s --help\' for more options.\n"), exec_name);
551                   exit (1);
552                 }
553             break;
554           }
555         case 'O':
556           setval ("outputdocument", optarg);
557           break;
558         case 'o':
559           setval ("logfile", optarg);
560           break;
561         case 'P':
562           setval ("dirprefix", optarg);
563           break;
564         case 'Q':
565           setval ("quota", optarg);
566           break;
567         case 'R':
568           setval ("reject", optarg);
569           break;
570         case 'T':
571           setval ("timeout", optarg);
572           break;
573         case 't':
574           setval ("tries", optarg);
575           break;
576         case 'U':
577           setval ("useragent", optarg);
578           break;
579         case 'w':
580           setval ("wait", optarg);
581           break;
582         case 'X':
583           setval ("excludedirectories", optarg);
584           break;
585         case 'Y':
586           setval ("useproxy", optarg);
587           break;
588
589         case '?':
590           print_usage ();
591           printf ("\n");
592           printf (_("Try `%s --help' for more options.\n"), exec_name);
593           exit (0);
594           break;
595         }
596     }
597   if (opt.verbose == -1)
598     opt.verbose = !opt.quiet;
599
600   /* Retain compatibility with previous scripts.
601      if wait has been set, but waitretry has not, give it the wait value.
602      A simple check on the values is not enough, I could have set
603      wait to n>0 and waitretry to 0 - HEH */
604   if (opt.wait && !wr)
605     {
606       char  opt_wait_str[256];  /* bigger than needed buf to prevent overflow */
607
608       sprintf(opt_wait_str, "%ld", opt.wait);
609       setval ("waitretry", opt_wait_str);
610     }
611     
612   /* Sanity checks.  */
613   if (opt.verbose && opt.quiet)
614     {
615       printf (_("Can't be verbose and quiet at the same time.\n"));
616       print_usage ();
617       exit (1);
618     }
619   if (opt.timestamping && opt.noclobber)
620     {
621       printf (_("\
622 Can't timestamp and not clobber old files at the same time.\n"));
623       print_usage ();
624       exit (1);
625     }
626   nurl = argc - optind;
627   if (!nurl && !opt.input_filename)
628     {
629       /* No URL specified.  */
630       printf (_("%s: missing URL\n"), exec_name);
631       print_usage ();
632       printf ("\n");
633       /* #### Something nicer should be printed here -- similar to the
634          pre-1.5 `--help' page.  */
635       printf (_("Try `%s --help' for more options.\n"), exec_name);
636       exit (1);
637     }
638
639   if (opt.background)
640     fork_to_background ();
641
642   /* Allocate basic pointer.  */
643   url = ALLOCA_ARRAY (char *, nurl + 1);
644   /* Fill in the arguments.  */
645   for (i = 0; i < nurl; i++, optind++)
646     {
647       char *irix4_cc_needs_this;
648       STRDUP_ALLOCA (irix4_cc_needs_this, argv[optind]);
649       url[i] = irix4_cc_needs_this;
650     }
651   url[i] = NULL;
652
653   /* Change the title of console window on Windows.  #### I think this
654      statement should belong to retrieve_url().  --hniksic.  */
655 #ifdef WINDOWS
656   ws_changetitle (*url, nurl);
657 #endif
658
659   /* Initialize logging.  */
660   log_init (opt.lfilename, append_to_log);
661
662   DEBUGP (("DEBUG output created by Wget %s on %s.\n\n", version_string,
663            OS_TYPE));
664   /* Open the output filename if necessary.  */
665   if (opt.output_document)
666     {
667       if (HYPHENP (opt.output_document))
668         opt.dfp = stdout;
669       else
670         {
671           opt.dfp = fopen (opt.output_document, "wb");
672           if (opt.dfp == NULL)
673             {
674               perror (opt.output_document);
675               exit (1);
676             }
677         }
678     }
679
680 #ifdef WINDOWS
681   ws_startup ();
682 #endif
683
684   /* Setup the signal handler to redirect output when hangup is
685      received.  */
686 #ifdef HAVE_SIGNAL
687   if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
688     signal(SIGHUP, redirect_output_signal);
689   /* ...and do the same for SIGUSR1.  */
690   signal (SIGUSR1, redirect_output_signal);
691   /* Writing to a closed socket normally signals SIGPIPE, and the
692      process exits.  What we want is to ignore SIGPIPE and just check
693      for the return value of write().  */
694   signal (SIGPIPE, SIG_IGN);
695 #endif /* HAVE_SIGNAL */
696
697   status = RETROK;              /* initialize it, just-in-case */
698   recursive_reset ();
699   /* Retrieve the URLs from argument list.  */
700   for (t = url; *t; t++)
701     {
702       char *filename, *new_file;
703       int dt;
704
705       status = retrieve_url (*t, &filename, &new_file, NULL, &dt);
706       if (opt.recursive && status == RETROK && (dt & TEXTHTML))
707         status = recursive_retrieve (filename, new_file ? new_file : *t);
708       FREE_MAYBE (new_file);
709       FREE_MAYBE (filename);
710     }
711
712   /* And then from the input file, if any.  */
713   if (opt.input_filename)
714     {
715       int count;
716       status = retrieve_from_file (opt.input_filename, opt.force_html, &count);
717       if (!count)
718         logprintf (LOG_NOTQUIET, _("No URLs found in %s.\n"),
719                    opt.input_filename);
720     }
721   /* Print the downloaded sum.  */
722   if (opt.recursive
723       || nurl > 1
724       || (opt.input_filename && opt.downloaded != 0))
725     {
726       logprintf (LOG_NOTQUIET,
727                  _("\nFINISHED --%s--\nDownloaded: %s bytes in %d files\n"),
728                  time_str (NULL), legible (opt.downloaded), opt.numurls);
729       /* Print quota warning, if exceeded.  */
730       if (opt.quota && opt.downloaded > opt.quota)
731         logprintf (LOG_NOTQUIET,
732                    _("Download quota (%s bytes) EXCEEDED!\n"),
733                    legible (opt.quota));
734     }
735   if (opt.convert_links)
736     {
737       convert_all_links ();
738     }
739   log_close ();
740   cleanup ();
741   if (status == RETROK)
742     return 0;
743   else
744     return 1;
745 }
746 \f
747 /* Hangup signal handler.  When wget receives SIGHUP or SIGUSR1, it
748    will proceed operation as usual, trying to write into a log file.
749    If that is impossible, the output will be turned off.  */
750
751 #ifdef HAVE_SIGNAL
752 static RETSIGTYPE
753 redirect_output_signal (int sig)
754 {
755   char tmp[100];
756   signal (sig, redirect_output_signal);
757   /* Please note that the double `%' in `%%s' is intentional, because
758      redirect_output passes tmp through printf.  */
759   sprintf (tmp, _("%s received, redirecting output to `%%s'.\n"),
760            (sig == SIGHUP ? "SIGHUP" :
761             (sig == SIGUSR1 ? "SIGUSR1" :
762              "WTF?!")));
763   redirect_output (tmp);
764 }
765 #endif /* HAVE_SIGNAL */