CMD_DECLARE (cmd_spec_timeout);
CMD_DECLARE (cmd_spec_useragent);
-/* List of recognized commands, each consisting of name, closure and function.
- When adding a new command, simply add it to the list, but be sure to keep the
- list sorted alphabetically, as findcmd() depends on it. Also, be sure to add
- any entries that allocate memory (e.g. cmd_string and cmd_vector guys) to the
+/* List of recognized commands, each consisting of name, closure and
+ function. When adding a new command, simply add it to the list,
+ but be sure to keep the list sorted alphabetically, as
+ command_by_name depends on it. Also, be sure to add any entries
+ that allocate memory (e.g. cmd_string and cmd_vector guys) to the
cleanup() function below. */
+
static struct {
char *name;
void *closure;
{ "ignoretags", &opt.ignore_tags, cmd_vector },
{ "includedirectories", &opt.includes, cmd_directory_vector },
{ "input", &opt.input_filename, cmd_file },
+#ifdef ENABLE_IPV6
+ { "inet4only", &opt.ipv4_only, cmd_boolean },
+ { "inet6only", &opt.ipv6_only, cmd_boolean },
+#endif
+ { "keepsessioncookies", &opt.keep_session_cookies, cmd_boolean },
{ "killlonger", &opt.kill_longer, cmd_boolean },
{ "limitrate", &opt.limit_rate, cmd_bytes },
{ "loadcookies", &opt.cookies_input, cmd_file },
{ "passwd", &opt.ftp_pass, cmd_string },
{ "postdata", &opt.post_data, cmd_string },
{ "postfile", &opt.post_file_name, cmd_file },
+ { "preservepermissions", &opt.preserve_perm, cmd_boolean },
{ "progress", &opt.progress_type, cmd_spec_progress },
{ "proxypasswd", &opt.proxy_passwd, cmd_string },
{ "proxyuser", &opt.proxy_user, cmd_string },
{ "waitretry", &opt.waitretry, cmd_time }
};
-/* Look up COM in the commands[] array and return its index. If COM
- is not found, -1 is returned. This function uses binary search. */
+/* Look up CMDNAME in the commands[] and return its position in the
+ array. If CMDNAME is not found, return -1. */
static int
-findcmd (const char *com)
+command_by_name (const char *cmdname)
{
+ /* Use binary search for speed. Wget has ~100 commands, which
+ guarantees a worst case performance of 7 string comparisons. */
int lo = 0, hi = countof (commands) - 1;
while (lo <= hi)
{
int mid = (lo + hi) >> 1;
- int cmp = strcasecmp (com, commands[mid].name);
+ int cmp = strcasecmp (cmdname, commands[mid].name);
if (cmp < 0)
hi = mid - 1;
else if (cmp > 0)
the command is valid. */
BOUNDED_TO_ALLOCA (cmdstart, cmdend, cmdcopy);
dehyphen (cmdcopy);
- ind = findcmd (cmdcopy);
+ ind = command_by_name (cmdcopy);
if (ind == -1)
return 0;
setval_internal (int comind, const char *com, const char *val)
{
assert (0 <= comind && comind < countof (commands));
+ DEBUGP (("Setting %s (%d) to %s\n", com, comind, val));
return ((*commands[comind].action) (com, val, commands[comind].closure));
}
void
setoptval (const char *com, const char *val)
{
- if (!setval_internal (findcmd (com), com, val))
+ assert (val != NULL);
+ if (!setval_internal (command_by_name (com), com, val))
exit (2);
}
cleanup_html_url ();
downloaded_files_free ();
host_cleanup ();
- cookie_jar_delete (wget_cookie_jar);
+ if (wget_cookie_jar)
+ cookie_jar_delete (wget_cookie_jar);
{
extern acc_t *netrc_list;