]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Applied Dennis Smit's --preserve-permissions patch.
[wget] / src / init.c
index 7f666f9e6dc3accb7e1ab718c58a08b7d4a175d4..abafecddd00d97e4fe42c2a6c8c4b2f8921d7c25 100644 (file)
@@ -106,11 +106,13 @@ CMD_DECLARE (cmd_spec_restrict_file_names);
 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;
@@ -165,6 +167,7 @@ static struct {
   { "ignoretags",      &opt.ignore_tags,       cmd_vector },
   { "includedirectories", &opt.includes,       cmd_directory_vector },
   { "input",           &opt.input_filename,    cmd_file },
+  { "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 },
@@ -182,6 +185,7 @@ static struct {
   { "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 },
@@ -224,18 +228,20 @@ static struct {
   { "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)
@@ -536,7 +542,7 @@ parse_line (const char *line, char **com, char **val, int *comind)
      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;
 
@@ -554,6 +560,7 @@ static int
 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));
 }
 
@@ -570,7 +577,8 @@ setval_internal (int comind, const char *com, const char *val)
 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);
 }
 
@@ -1319,7 +1327,8 @@ cleanup (void)
   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;