~ubuntu-branches/ubuntu/trusty/wget/trusty-updates

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2009-12-12 08:15:59 UTC
  • mfrom: (2.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091212081559-mvccl4kzdqb138y3
Tags: 1.12-1.1ubuntu1
* Merge from debian testing, remaining changes:
  - Add wget-udeb to ship wget.gnu as alternative to busybox wget
    implementation.
* Keep build dependencies in main:
  - debian/control: remove info2man build-dep
  - debian/patches/00list: disable wget-infopod_generated_manpage.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Command line parsing.
2
2
   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3
 
   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4
4
 
5
5
This file is part of GNU Wget.
6
6
 
28
28
shall include the source code for the parts of OpenSSL used as well
29
29
as that of the covered work.  */
30
30
 
31
 
#include <config.h>
 
31
#include "wget.h"
32
32
 
33
33
#include <stdio.h>
34
34
#include <stdlib.h>
37
37
#endif /* HAVE_UNISTD_H */
38
38
#include <string.h>
39
39
#include <signal.h>
40
 
#ifdef HAVE_NLS
 
40
#ifdef ENABLE_NLS
41
41
# include <locale.h>
42
42
#endif
43
43
#include <assert.h>
44
44
#include <errno.h>
45
45
#include <time.h>
46
46
 
47
 
#include "wget.h"
 
47
#include "exits.h"
48
48
#include "utils.h"
49
49
#include "init.h"
50
50
#include "retr.h"
56
56
#include "spider.h"
57
57
#include "http.h"               /* for save_cookies */
58
58
 
59
 
/* On GNU system this will include system-wide getopt.h. */
60
 
#include "getopt.h"
 
59
#include <getopt.h>
 
60
#include <getpass.h>
 
61
#include <quote.h>
 
62
 
 
63
#ifdef __VMS
 
64
#include "vms.h"
 
65
#endif /* __VMS */
61
66
 
62
67
#ifndef PATH_SEPARATOR
63
68
# define PATH_SEPARATOR '/'
65
70
 
66
71
struct options opt;
67
72
 
 
73
/* defined in version.c */
68
74
extern char *version_string;
 
75
extern char *compilation_string;
 
76
extern char *system_getrc;
 
77
extern char *link_string;
 
78
/* defined in build_info.c */
 
79
extern char *compiled_features[];
 
80
/* Used for --version output in print_version */
 
81
#define MAX_CHARS_PER_LINE      72
 
82
#define TABULATION              4
69
83
 
70
84
#if defined(SIGHUP) || defined(SIGUSR1)
71
85
static void redirect_output_signal (int);
72
86
#endif
73
87
 
74
88
const char *exec_name;
 
89
 
 
90
/* Number of successfully downloaded URLs */
 
91
int numurls = 0;
75
92
 
76
93
#ifndef TESTING
77
94
/* Initialize I18N/L10N.  That amounts to invoking setlocale, and
81
98
static void
82
99
i18n_initialize (void)
83
100
{
84
 
  /* HAVE_NLS implies existence of functions invoked here.  */
85
 
#ifdef HAVE_NLS
 
101
  /* ENABLE_NLS implies existence of functions invoked here.  */
 
102
#ifdef ENABLE_NLS
86
103
  /* Set the current locale.  */
87
104
  setlocale (LC_ALL, "");
88
105
  /* Set the text message domain.  */
89
106
  bindtextdomain ("wget", LOCALEDIR);
90
107
  textdomain ("wget");
91
 
#endif /* HAVE_NLS */
 
108
#endif /* ENABLE_NLS */
92
109
}
93
110
 
94
111
/* Definition of command-line options. */
131
148
static struct cmdline_option option_data[] =
132
149
  {
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 },
 
192
#ifdef __VMS
 
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 },
190
213
#endif
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 },
247
273
    { "version", 'V', OPT_FUNCALL, (void *) print_version, no_argument },
248
274
    { "wait", 'w', OPT_VALUE, "wait", -1 },
249
275
    { "waitretry", 0, OPT_VALUE, "waitretry", -1 },
250
 
#ifdef MSDOS
 
276
#ifdef USE_WATT32
251
277
    { "wdebug", 0, OPT_BOOLEAN, "wdebug", -1 },
252
278
#endif
253
279
  };
293
319
init_switches (void)
294
320
{
295
321
  char *p = short_options;
296
 
  int i, o = 0;
 
322
  size_t i, o = 0;
297
323
  for (i = 0; i < countof (option_data); i++)
298
324
    {
299
325
      struct cmdline_option *opt = &option_data[i];
393
419
    N_("\
394
420
  -d,  --debug               print lots of debugging information.\n"),
395
421
#endif
396
 
#ifdef MSDOS
 
422
#ifdef USE_WATT32
397
423
    N_("\
398
424
       --wdebug              print Watt-32 debug output.\n"),
399
425
#endif
404
430
    N_("\
405
431
  -nv, --no-verbose          turn off verboseness, without being quiet.\n"),
406
432
    N_("\
407
 
  -i,  --input-file=FILE     download URLs found in FILE.\n"),
 
433
  -i,  --input-file=FILE     download URLs found in local or external FILE.\n"),
408
434
    N_("\
409
435
  -F,  --force-html          treat input file as HTML.\n"),
410
436
    N_("\
411
 
  -B,  --base=URL            prepends URL to relative links in -F -i file.\n"),
 
437
  -B,  --base=URL            resolves HTML input-file links (-i -F)\n\
 
438
                             relative to URL.\n"),
412
439
    "\n",
413
440
 
414
441
    N_("\
474
501
       --user=USER               set both ftp and http user to USER.\n"),
475
502
    N_("\
476
503
       --password=PASS           set both ftp and http password to PASS.\n"),
 
504
    N_("\
 
505
       --ask-password            prompt for passwords.\n"),
 
506
    N_("\
 
507
       --no-iri                  turn off IRI support.\n"),
 
508
    N_("\
 
509
       --local-encoding=ENC      use ENC as the local encoding for IRIs.\n"),
 
510
    N_("\
 
511
       --remote-encoding=ENC     use ENC as the default remote encoding.\n"),
477
512
    "\n",
478
513
 
479
514
    N_("\
500
535
       --http-password=PASS    set http password to PASS.\n"),
501
536
    N_("\
502
537
       --no-cache              disallow server-cached data.\n"),
 
538
    N_ ("\
 
539
       --default-page=NAME     Change the default page name (normally\n\
 
540
                               this is `index.html'.).\n"),
503
541
    N_("\
504
 
  -E,  --html-extension        save HTML documents with `.html' extension.\n"),
 
542
  -E,  --adjust-extension      save HTML/CSS documents with proper extensions.\n"),
505
543
    N_("\
506
544
       --ignore-length         ignore `Content-Length' header field.\n"),
507
545
    N_("\
536
574
       --content-disposition   honor the Content-Disposition header when\n\
537
575
                               choosing local file names (EXPERIMENTAL).\n"),
538
576
    N_("\
539
 
       --auth-no-challenge     Send Basic HTTP authentication information\n\
 
577
       --auth-no-challenge     send Basic HTTP authentication information\n\
540
578
                               without first waiting for the server's\n\
541
579
                               challenge.\n"),
542
580
    "\n",
570
608
 
571
609
    N_("\
572
610
FTP options:\n"),
 
611
#ifdef __VMS
 
612
    N_("\
 
613
       --ftp-stmlf             Use Stream_LF format for all binary FTP files.\n"),
 
614
#endif /* def __VMS */
573
615
    N_("\
574
616
       --ftp-user=USER         set ftp user to USER.\n"),
575
617
    N_("\
582
624
       --no-passive-ftp        disable the \"passive\" transfer mode.\n"),
583
625
    N_("\
584
626
       --retr-symlinks         when recursing, get linked-to files (not dir).\n"),
585
 
    N_("\
586
 
       --preserve-permissions  preserve remote file permissions.\n"),
587
627
    "\n",
588
628
 
589
629
    N_("\
595
635
    N_("\
596
636
       --delete-after       delete files locally after downloading them.\n"),
597
637
    N_("\
598
 
  -k,  --convert-links      make links in downloaded HTML point to local files.\n"),
 
638
  -k,  --convert-links      make links in downloaded HTML or CSS point to\n\
 
639
                            local files.\n"),
 
640
#ifdef __VMS
 
641
    N_("\
 
642
  -K,  --backup-converted   before converting file X, back up as X_orig.\n"),
 
643
#else /* def __VMS */
599
644
    N_("\
600
645
  -K,  --backup-converted   before converting file X, back up as X.orig.\n"),
 
646
#endif /* def __VMS [else] */
601
647
    N_("\
602
648
  -m,  --mirror             shortcut for -N -r -l inf --no-remove-listing.\n"),
603
649
    N_("\
637
683
    N_("Mail bug reports and suggestions to <bug-wget@gnu.org>.\n")
638
684
  };
639
685
 
640
 
  int i;
 
686
  size_t i;
641
687
 
642
688
  printf (_("GNU Wget %s, a non-interactive network retriever.\n"),
643
689
          version_string);
675
721
  return buf;
676
722
}
677
723
 
 
724
static char *
 
725
prompt_for_password (void)
 
726
{
 
727
  if (opt.user)
 
728
    printf (_("Password for user %s: "), quote (opt.user));
 
729
  else
 
730
    printf (_("Password: "));
 
731
  return getpass("");
 
732
}
 
733
 
 
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
 
737
   lines.*/
 
738
static void
 
739
format_and_print_line (const char *prefix, const char *line,
 
740
                       int line_length)
 
741
{
 
742
  int remaining_chars;
 
743
  char *line_dup, *token;
 
744
 
 
745
  assert (prefix != NULL);
 
746
  assert (line != NULL);
 
747
 
 
748
  line_dup = xstrdup (line);
 
749
 
 
750
  if (line_length <= 0)
 
751
    line_length = MAX_CHARS_PER_LINE - TABULATION;
 
752
 
 
753
  printf ("%s", prefix);
 
754
  remaining_chars = line_length;
 
755
  /* We break on spaces. */
 
756
  token = strtok (line_dup, " ");
 
757
  while (token != NULL)
 
758
    {
 
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))
 
763
        {
 
764
          printf ("\n%*c", TABULATION, ' ');
 
765
          remaining_chars = line_length - TABULATION;
 
766
        }
 
767
      printf ("%s ", token);
 
768
      remaining_chars -= strlen (token) + 1;  /* account for " " */
 
769
      token = strtok (NULL, " ");
 
770
    }
 
771
 
 
772
  printf ("\n");
 
773
 
 
774
  xfree (line_dup);
 
775
}
 
776
 
678
777
static void
679
778
print_version (void)
680
779
{
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: ");
 
784
  char *line;
 
785
  char *env_wgetrc, *user_wgetrc;
 
786
  int i;
 
787
 
 
788
#ifdef __VMS
 
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; )
 
798
    {
 
799
      int line_length = MAX_CHARS_PER_LINE;
 
800
      while ((line_length > 0) && (compiled_features[i] != NULL))
 
801
        {
 
802
          printf ("%s ", compiled_features[i]);
 
803
          line_length -= strlen (compiled_features[i]) + 2;
 
804
          i++;
 
805
        }
 
806
      printf ("\n");
 
807
    }
 
808
  printf ("\n");
 
809
  /* Handle the case when $WGETRC is unset and $HOME/.wgetrc is
 
810
     absent. */
 
811
  printf ("%s\n", wgetrc_title);
 
812
  env_wgetrc = wgetrc_env_file_name ();
 
813
  if (env_wgetrc && *env_wgetrc)
 
814
    {
 
815
      printf (_("    %s (env)\n"), env_wgetrc);
 
816
      xfree (env_wgetrc);
 
817
    }
 
818
  user_wgetrc = wgetrc_user_file_name ();
 
819
  if (user_wgetrc)
 
820
    {
 
821
      printf (_("    %s (user)\n"), user_wgetrc);
 
822
      xfree (user_wgetrc);
 
823
    }
 
824
#ifdef SYSTEM_WGETRC
 
825
  printf (_("    %s (system)\n"), SYSTEM_WGETRC);
 
826
#endif
 
827
 
 
828
#ifdef ENABLE_NLS
 
829
  format_and_print_line (locale_title,
 
830
                        LOCALEDIR,
 
831
                        MAX_CHARS_PER_LINE);
 
832
#endif /* def ENABLE_NLS */
 
833
 
 
834
  format_and_print_line (compile_title,
 
835
                         compilation_string,
 
836
                         MAX_CHARS_PER_LINE);
 
837
 
 
838
  format_and_print_line (link_title,
 
839
                         link_string,
 
840
                         MAX_CHARS_PER_LINE);
 
841
 
 
842
  printf ("\n");
 
843
  /* TRANSLATORS: When available, an actual copyright character
 
844
     (cirle-c) should be used in preference to "(C)". */
682
845
  fputs (_("\
683
 
Copyright (C) 2008 Free Software Foundation, Inc.\n"), stdout);
 
846
Copyright (C) 2009 Free Software Foundation, Inc.\n"), stdout);
684
847
  fputs (_("\
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"),
690
855
         stdout);
691
856
  fputs (_("Currently maintained by Micah Cowan <micah@cowan.name>.\n"),
692
857
         stdout);
 
858
  fputs (_("Please send bug reports and questions to <bug-wget@gnu.org>.\n"),
 
859
         stdout);
693
860
  exit (0);
694
861
}
695
 
 
 
862
 
 
863
char *program_name; /* Needed by lib/error.c. */
696
864
 
697
865
int
698
 
main (int argc, char *const *argv)
 
866
main (int argc, char **argv)
699
867
{
700
868
  char **url, **t;
701
869
  int i, ret, longindex;
702
870
  int nurl, status;
703
871
  bool append_to_log = false;
704
872
 
 
873
  program_name = argv[0];
 
874
 
705
875
  i18n_initialize ();
706
876
 
707
877
  /* Construct the name of the executable, without the directory part.  */
817
987
               before passing the value to setoptval.  */
818
988
            bool flag = true;
819
989
            if (optarg)
820
 
              flag = (*optarg == '1' || TOLOWER (*optarg) == 'y'
821
 
                      || (TOLOWER (optarg[0]) == 'o'
822
 
                          && TOLOWER (optarg[1]) == 'n'));
 
990
              flag = (*optarg == '1' || c_tolower (*optarg) == 'y'
 
991
                      || (c_tolower (optarg[0]) == 'o'
 
992
                          && c_tolower (optarg[1]) == 'n'));
823
993
            setoptval (opt->type == OPT__PARENT ? "noparent" : "noclobber",
824
994
                       flag ? "0" : "1", opt->long_name);
825
995
            break;
838
1008
     interoption dependency checks. */
839
1009
 
840
1010
  if (opt.reclevel == 0)
841
 
    opt.reclevel = INFINITE_RECURSION; /* see recur.h for commentary on this */
 
1011
      opt.reclevel = INFINITE_RECURSION; /* see recur.h for commentary */
 
1012
 
 
1013
  if (opt.spider || opt.delete_after)
 
1014
      opt.no_dirstruct = true;
842
1015
 
843
1016
  if (opt.page_requisites && !opt.recursive)
844
1017
    {
877
1050
#endif
878
1051
  if (opt.output_document)
879
1052
    {
880
 
      if (opt.convert_links 
 
1053
      if (opt.convert_links
881
1054
          && (nurl > 1 || opt.page_requisites || opt.recursive))
882
1055
        {
883
1056
          fputs (_("\
900
1073
for details.\n\n"));
901
1074
          opt.timestamping = false;
902
1075
        }
903
 
      if (opt.noclobber && file_exists_p(opt.output_document)) 
904
 
           { 
 
1076
      if (opt.noclobber && file_exists_p(opt.output_document))
 
1077
           {
905
1078
              /* Check if output file exists; if it does, exit. */
906
1079
              logprintf (LOG_VERBOSE, _("File `%s' already there; not retrieving.\n"), opt.output_document);
907
1080
              exit(1);
908
 
           }  
 
1081
           }
 
1082
    }
 
1083
 
 
1084
  if (opt.ask_passwd && opt.passwd)
 
1085
    {
 
1086
      printf (_("Cannot specify both --ask-password and --password.\n"));
 
1087
      print_usage ();
 
1088
      exit (1);
909
1089
    }
910
1090
 
911
1091
  if (!nurl && !opt.input_filename)
920
1100
      exit (1);
921
1101
    }
922
1102
 
923
 
#ifdef MSDOS
 
1103
#ifdef ENABLE_IRI
 
1104
  if (opt.enable_iri)
 
1105
    {
 
1106
      if (opt.locale && !check_encoding_name (opt.locale))
 
1107
        opt.locale = NULL;
 
1108
 
 
1109
      if (!opt.locale)
 
1110
        opt.locale = find_locale ();
 
1111
 
 
1112
      if (opt.encoding_remote && !check_encoding_name (opt.encoding_remote))
 
1113
        opt.encoding_remote = NULL;
 
1114
    }
 
1115
#else
 
1116
  if (opt.enable_iri || opt.locale || opt.encoding_remote)
 
1117
    {
 
1118
      /* sXXXav : be more specific... */
 
1119
      printf(_("This version does not have support for IRIs\n"));
 
1120
      exit(1);
 
1121
    }
 
1122
#endif
 
1123
 
 
1124
  if (opt.ask_passwd)
 
1125
    {
 
1126
      opt.passwd = prompt_for_password ();
 
1127
 
 
1128
      if (opt.passwd == NULL || opt.passwd[0] == '\0')
 
1129
        exit (1);
 
1130
    }
 
1131
 
 
1132
#ifdef USE_WATT32
924
1133
  if (opt.wdebug)
925
1134
     dbug_init();
926
1135
  sock_init();
949
1158
  /* Initialize logging.  */
950
1159
  log_init (opt.lfilename, append_to_log);
951
1160
 
952
 
  DEBUGP (("DEBUG output created by Wget %s on %s.\n\n", version_string,
953
 
           OS_TYPE));
 
1161
  DEBUGP (("DEBUG output created by Wget %s on %s.\n\n",
 
1162
           version_string, OS_TYPE));
954
1163
 
955
1164
  /* Open the output filename if necessary.  */
 
1165
 
 
1166
/* 2005-04-17 SMS.
 
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
 
1172
   server.)
 
1173
*/
956
1174
  if (opt.output_document)
957
1175
    {
958
1176
      if (HYPHENP (opt.output_document))
959
 
        output_stream = stdout;
 
1177
        {
 
1178
#ifdef WINDOWS
 
1179
          FILE *result;
 
1180
          result = freopen ("CONOUT$", "wb", stdout);
 
1181
          if (result == NULL)
 
1182
            {
 
1183
              logputs (LOG_NOTQUIET, _("\
 
1184
WARNING: Can't reopen standard output in binary mode;\n\
 
1185
         downloaded file may contain inappropriate line endings.\n"));
 
1186
            }
 
1187
#endif
 
1188
          output_stream = stdout;
 
1189
        }
960
1190
      else
961
1191
        {
962
1192
          struct_fstat st;
 
1193
 
 
1194
#ifdef __VMS
 
1195
/* Common fopen() optional arguments:
 
1196
   sequential access only, access callback function.
 
1197
*/
 
1198
# define FOPEN_OPT_ARGS , "fop=sqo", "acc", acc_cb, &open_id
 
1199
          int open_id = 7;
 
1200
#else /* def __VMS */
 
1201
# define FOPEN_OPT_ARGS
 
1202
#endif /* def __VMS [else] */
 
1203
 
963
1204
          output_stream = fopen (opt.output_document,
964
 
                                 opt.always_rest ? "ab" : "wb");
 
1205
                                 opt.always_rest ? "ab" : "wb"
 
1206
                                 FOPEN_OPT_ARGS);
965
1207
          if (output_stream == NULL)
966
1208
            {
967
1209
              perror (opt.output_document);
972
1214
        }
973
1215
    }
974
1216
 
 
1217
#ifdef __VMS
 
1218
  /* Set global ODS5 flag according to the specified destination (if
 
1219
     any), otherwise according to the current default device.
 
1220
  */
 
1221
  if (output_stream == NULL)
 
1222
    {
 
1223
      set_ods5_dest( "SYS$DISK");
 
1224
    }
 
1225
  else if (output_stream != stdout)
 
1226
    {
 
1227
      set_ods5_dest( opt.output_document);
 
1228
    }
 
1229
#endif /* def __VMS */
 
1230
 
975
1231
#ifdef WINDOWS
976
1232
  ws_startup ();
977
1233
#endif
1001
1257
  for (t = url; *t; t++)
1002
1258
    {
1003
1259
      char *filename = NULL, *redirected_URL = NULL;
1004
 
      int dt;
1005
 
 
1006
 
      if ((opt.recursive || opt.page_requisites)
1007
 
          && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (*t)))
 
1260
      int dt, url_err;
 
1261
      /* Need to do a new struct iri every time, because
 
1262
       * retrieve_url may modify it in some circumstances,
 
1263
       * currently. */
 
1264
      struct iri *iri = iri_new ();
 
1265
      struct url *url_parsed;
 
1266
 
 
1267
      set_uri_encoding (iri, opt.locale, true);
 
1268
      url_parsed = url_parse (*t, &url_err, iri, true);
 
1269
 
 
1270
      if (!url_parsed)
1008
1271
        {
1009
 
          int old_follow_ftp = opt.follow_ftp;
1010
 
 
1011
 
          /* Turn opt.follow_ftp on in case of recursive FTP retrieval */
1012
 
          if (url_scheme (*t) == SCHEME_FTP) 
1013
 
            opt.follow_ftp = 1;
1014
 
          
1015
 
          status = retrieve_tree (*t);
1016
 
 
1017
 
          opt.follow_ftp = old_follow_ftp;
 
1272
          char *error = url_error (*t, url_err);
 
1273
          logprintf (LOG_NOTQUIET, "%s: %s.\n",*t, error);
 
1274
          xfree (error);
 
1275
          status = URLERROR;
1018
1276
        }
1019
1277
      else
1020
 
        status = retrieve_url (*t, &filename, &redirected_URL, NULL, &dt, opt.recursive);
1021
 
 
1022
 
      if (opt.delete_after && file_exists_p(filename))
1023
1278
        {
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)))
 
1281
            {
 
1282
              int old_follow_ftp = opt.follow_ftp;
 
1283
 
 
1284
              /* Turn opt.follow_ftp on in case of recursive FTP retrieval */
 
1285
              if (url_scheme (*t) == SCHEME_FTP)
 
1286
                opt.follow_ftp = 1;
 
1287
 
 
1288
              status = retrieve_tree (url_parsed, NULL);
 
1289
 
 
1290
              opt.follow_ftp = old_follow_ftp;
 
1291
            }
 
1292
          else
 
1293
          {
 
1294
            status = retrieve_url (url_parsed, *t, &filename, &redirected_URL,
 
1295
                                   NULL, &dt, opt.recursive, iri, true);
 
1296
          }
 
1297
 
 
1298
          if (opt.delete_after && file_exists_p(filename))
 
1299
            {
 
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));
 
1304
            }
 
1305
          xfree_null (redirected_URL);
 
1306
          xfree_null (filename);
 
1307
          url_free (url_parsed);
1028
1308
        }
1029
 
 
1030
 
      xfree_null (redirected_URL);
1031
 
      xfree_null (filename);
 
1309
      iri_free (iri);
1032
1310
    }
1033
1311
 
1034
1312
  /* And then from the input file, if any.  */
1046
1324
    {
1047
1325
      print_broken_links();
1048
1326
    }
1049
 
  
 
1327
 
1050
1328
  /* Print the downloaded sum.  */
1051
1329
  if ((opt.recursive || opt.page_requisites
1052
1330
       || nurl > 1
1057
1335
      logprintf (LOG_NOTQUIET,
1058
1336
                 _("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"),
1059
1337
                 datetime_str (time (NULL)),
1060
 
                 opt.numurls,
 
1338
                 numurls,
1061
1339
                 human_readable (total_downloaded_bytes),
1062
1340
                 secs_to_human_time (total_download_time),
1063
1341
                 retr_rate (total_downloaded_bytes, total_download_time));
1079
1357
    xfree (url[i]);
1080
1358
  cleanup ();
1081
1359
 
1082
 
#ifdef DEBUG_MALLOC
1083
 
  print_malloc_debug_stats ();
1084
 
#endif
1085
 
  if (status == RETROK)
1086
 
    return 0;
1087
 
  else
1088
 
    return 1;
 
1360
  return get_exit_status ();
1089
1361
}
1090
1362
#endif /* TESTING */
1091
1363