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