From 0d0fe504355a7b71f3529247067979a0a9ad2933 Mon Sep 17 00:00:00 2001 From: hniksic Date: Fri, 5 Dec 2003 19:01:31 -0800 Subject: [PATCH] [svn] New option --protocol-directories. --- NEWS | 3 +++ src/ChangeLog | 8 ++++++++ src/init.c | 1 + src/main.c | 24 +++++++++++++++--------- src/options.h | 1 + src/url.c | 26 +++++++++++++++++--------- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index d3ac88a1..f7244d75 100644 --- 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" diff --git a/src/ChangeLog b/src/ChangeLog index 24b86060..9e7cd444 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-12-06 Hrvoje Niksic + + * 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 * ftp.c (getftp): Ditto. diff --git a/src/init.c b/src/init.c index 8624f128..6ece81cd 100644 --- a/src/init.c +++ b/src/init.c @@ -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 }, diff --git a/src/main.c b/src/main.c index 29eb99d5..6391ebf2 100644 --- a/src/main.c +++ b/src/main.c @@ -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 diff --git a/src/options.h b/src/options.h index f5474865..34a85e71 100644 --- a/src/options.h +++ b/src/options.h @@ -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 */ diff --git a/src/url.c b/src/url.c index a625ff95..2bbf84be 100644 --- 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) -- 2.39.2