]> sjero.net Git - wget/commitdiff
[svn] New option --protocol-directories.
authorhniksic <devnull@localhost>
Sat, 6 Dec 2003 03:01:31 +0000 (19:01 -0800)
committerhniksic <devnull@localhost>
Sat, 6 Dec 2003 03:01:31 +0000 (19:01 -0800)
NEWS
src/ChangeLog
src/init.c
src/main.c
src/options.h
src/url.c

diff --git a/NEWS b/NEWS
index d3ac88a11742f3a1a672121e3b4540e82fbd74dd..f7244d75895faf2221d61f10741c455beaf81a68 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,9 @@ which might not be what the user wants.  The new option
 `--preserve-permissions' and the corresponding `.wgetrc' variable can
 be used to revert to the old behavior.
 
+** The new option `--protocol-directories' instructs Wget to also use
+the protocol name as a directory component of local file names.
+
 ** Many options that previously unconditionally set or unset various
 flags are now boolean options that can be invoked as either `--OPTION'
 or `--no-OPTION'.  Options that required an argument "on" or "off"
index 24b86060503a1cca39050f2b8b1d93649cab6ce6..9e7cd444e6cd1be74305909a4d92529eb8e640c4 100644 (file)
@@ -1,3 +1,11 @@
+2003-12-06  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * url.c (url_file_name): Respect the setting of
+       opt.protocol_directories.
+
+       * main.c (main): Only check for ret=='?' when longindex is unset.
+       (option_data): New option --protocol-directories.
+
 2003-12-06  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * ftp.c (getftp): Ditto.
index 8624f128e17f987ef5a22e65e37f33532c733418..6ece81cd80f5e44a8c5118a2a720ba48ed529f04 100644 (file)
@@ -181,6 +181,7 @@ static struct {
   { "postfile",                &opt.post_file_name,    cmd_file },
   { "preservepermissions", &opt.preserve_perm, cmd_boolean },
   { "progress",                &opt.progress_type,     cmd_spec_progress },
+  { "protocoldirectories", &opt.protocol_directories, cmd_boolean },
   { "proxypasswd",     &opt.proxy_passwd,      cmd_string },
   { "proxyuser",       &opt.proxy_user,        cmd_string },
   { "quiet",           &opt.quiet,             cmd_boolean },
index 29eb99d51dec2856a9e884008e887f270d129e95..6391ebf2cbd34ad3483d1c87d5b7ff774ac84f3c 100644 (file)
@@ -216,6 +216,7 @@ struct cmdline_option option_data[] =
     { "post-file", 0, OPT_VALUE, "postfile", -1 },
     { "preserve-permissions", 0, OPT_BOOLEAN, "preservepermissions", -1 },
     { "progress", 0, OPT_VALUE, "progress", -1 },
+    { "protocol-directories", 0, OPT_BOOLEAN, "protocoldirectories", -1 },
     { "proxy", 'Y', OPT_BOOLEAN, "useproxy", -1 },
     { "proxy-passwd", 0, OPT_VALUE, "proxypasswd", -1 },
     { "proxy-user", 0, OPT_VALUE, "proxyuser", -1 },
@@ -475,6 +476,8 @@ Directories:\n"),
   -x,  --force-directories        force creation of directories.\n"),
     N_("\
   -nH, --no-host-directories      don't create host directories.\n"),
+    N_("\
+       --protocol-directories     use protocol name in directories.\n"),
     N_("\
   -P,  --directory-prefix=PREFIX  save files to PREFIX/...\n"),
     N_("\
@@ -671,18 +674,21 @@ main (int argc, char *const *argv)
     {
       int val;
       struct cmdline_option *opt;
-      if (ret == '?')
-       {
-         print_usage ();
-         printf ("\n");
-         printf (_("Try `%s --help' for more options.\n"), exec_name);
-         exit (2);
-       }
 
       /* If LONGINDEX is unchanged, it means RET is referring a short
-        option.  Look it up in the mapping table.  */
+        option.  */
       if (longindex == -1)
-       longindex = optmap[ret - 32];
+       {
+         if (ret == '?')
+           {
+             print_usage ();
+             printf ("\n");
+             printf (_("Try `%s --help' for more options.\n"), exec_name);
+             exit (2);
+           }
+         /* Find the short option character in the mapping.  */
+         longindex = optmap[ret - 32];
+       }
       val = long_options[longindex].val;
 
       /* Use the retrieved value to locate the option in the
index f5474865f74566744720c51961a720cc1457d678..34a85e718fdde70dacb1998ef17ecb6d0e113b66 100644 (file)
@@ -53,6 +53,7 @@ struct options
   int no_dirstruct;            /* Do we hate dirstruct? */
   int cut_dirs;                        /* Number of directory components to cut. */
   int add_hostdir;             /* Do we add hostname directory? */
+  int protocol_directories;    /* Whether to prepend "http"/"ftp" to dirs. */
   int noclobber;               /* Disables clobbering of existing
                                   data. */
   char *dir_prefix;            /* The top of directory tree */
index a625ff9543822ef607f12cbd0affd911e64ba7fb..2bbf84be5b20f4c1f0a673d690deee10d8ffaeb9 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -54,7 +54,8 @@ extern int errno;
 
 struct scheme_data
 {
-  char *leading_string;
+  const char *name;
+  const char *leading_string;
   int default_port;
   int enabled;
 };
@@ -62,14 +63,14 @@ struct scheme_data
 /* Supported schemes: */
 static struct scheme_data supported_schemes[] =
 {
-  { "http://",  DEFAULT_HTTP_PORT,  1 },
+  { "http",    "http://",  DEFAULT_HTTP_PORT,  1 },
 #ifdef HAVE_SSL
-  { "https://", DEFAULT_HTTPS_PORT, 1 },
+  { "https",   "https://", DEFAULT_HTTPS_PORT, 1 },
 #endif
-  { "ftp://",   DEFAULT_FTP_PORT,   1 },
+  { "ftp",     "ftp://",   DEFAULT_FTP_PORT,   1 },
 
   /* SCHEME_INVALID */
-  { NULL,       -1,                 0 }
+  { NULL,      NULL,       -1,                 0 }
 };
 
 /* Forward declarations: */
@@ -1578,6 +1579,12 @@ url_file_name (const struct url *u)
      directory structure.  */
   if (opt.dirstruct)
     {
+      if (opt.protocol_directories)
+       {
+         if (fnres.tail)
+           append_char ('/', &fnres);
+         append_string (supported_schemes[u->scheme].name, &fnres);
+       }
       if (opt.add_hostdir)
        {
          if (fnres.tail)
@@ -1963,10 +1970,10 @@ url_string (const struct url *url, int hide_password)
   char *quoted_user = NULL, *quoted_passwd = NULL;
 
   int scheme_port  = supported_schemes[url->scheme].default_port;
-  char *scheme_str = supported_schemes[url->scheme].leading_string;
+  const char *scheme_str = supported_schemes[url->scheme].leading_string;
   int fplen = full_path_length (url);
 
-  int brackets_around_host = 0;
+  int brackets_around_host;
 
   assert (scheme_str != NULL);
 
@@ -1983,8 +1990,9 @@ url_string (const struct url *url, int hide_password)
        }
     }
 
-  if (strchr (url->host, ':'))
-    brackets_around_host = 1;
+  /* Numeric IPv6 addresses can contain ':' and need to be quoted with
+     brackets.  */
+  brackets_around_host = strchr (url->host, ':') != NULL;
 
   size = (strlen (scheme_str)
          + strlen (url->host)