]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Improve error message so it names the more useful values first.
[wget] / src / init.c
index f4dfdd9ab7d4130fddcbb572bb3d03233c8a4bbe..b0e2c592462ba2466283390ab12ab916d6e45980 100644 (file)
@@ -105,7 +105,7 @@ CMD_DECLARE (cmd_spec_useragent);
    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
+   that allocate memory (e.g. cmd_string and cmd_vector) to the
    cleanup() function below. */
 
 static struct {
@@ -159,10 +159,10 @@ static struct {
   { "forcehtml",       &opt.force_html,        cmd_boolean },
   { "ftppasswd",       &opt.ftp_passwd,        cmd_string }, /* deprecated */
   { "ftppassword",     &opt.ftp_passwd,        cmd_string },
-  { "ftpuser",         &opt.ftp_user,          cmd_string },
   { "ftpproxy",                &opt.ftp_proxy,         cmd_string },
+  { "ftpuser",         &opt.ftp_user,          cmd_string },
   { "glob",            &opt.ftp_glob,          cmd_boolean },
-  { "header",          &opt.user_headers,      cmd_spec_header },
+  { "header",          NULL,                   cmd_spec_header },
   { "htmlextension",   &opt.html_extension,    cmd_boolean },
   { "htmlify",         NULL,                   cmd_spec_htmlify },
   { "httpkeepalive",   &opt.http_keep_alive,   cmd_boolean },
@@ -612,7 +612,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));
+  DEBUGP (("Setting %s (%s) to %s\n", com, commands[comind].name, val));
   return ((*commands[comind].action) (com, val, commands[comind].place));
 }
 
@@ -627,10 +627,16 @@ setval_internal (int comind, const char *com, const char *val)
    to accept COMIND directly.  */
 
 void
-setoptval (const char *com, const char *val)
+setoptval (const char *com, const char *val, const char *optname)
 {
+  /* Prepend "--" to OPTNAME. */
+  char *dd_optname = (char *) alloca (2 + strlen (optname) + 1);
+  dd_optname[0] = '-';
+  dd_optname[1] = '-';
+  strcpy (dd_optname + 2, optname);
+
   assert (val != NULL);
-  if (!setval_internal (command_by_name (com), com, val))
+  if (!setval_internal (command_by_name (com), dd_optname, val))
     exit (2);
 }
 
@@ -643,16 +649,15 @@ run_command (const char *opt)
 {
   char *com, *val;
   int comind;
-  int status = parse_line (opt, &com, &val, &comind);
-  if (status == 1)
+  switch (parse_line (opt, &com, &val, &comind))
     {
+    case line_ok:
       if (!setval_internal (comind, com, val))
        exit (2);
       xfree (com);
       xfree (val);
-    }
-  else if (status == 0)
-    {
+      break;
+    default:
       fprintf (stderr, _("%s: Invalid --execute command `%s'\n"),
               exec_name, opt);
       exit (2);
@@ -742,7 +747,7 @@ cmd_lockable_boolean (const char *com, const char *val, void *place)
   else
     {
       fprintf (stderr,
-              _("%s: %s: Invalid boolean `%s', use always, on, off, or never.\n"),
+              _("%s: %s: Invalid boolean `%s'; use on, off, always, or never.\n"),
               exec_name, com, val);
       return 0;
     }
@@ -1113,15 +1118,24 @@ cmd_spec_dirstruct (const char *com, const char *val, void *place_ignored)
 }
 
 static int
-cmd_spec_header (const char *com, const char *val, void *place)
+cmd_spec_header (const char *com, const char *val, void *place_ignored)
 {
+  /* Empty value means reset the list of headers. */
+  if (*val == '\0')
+    {
+      free_vec (opt.user_headers);
+      opt.user_headers = NULL;
+      return 1;
+    }
+
   if (!check_user_specified_header (val))
     {
       fprintf (stderr, _("%s: %s: Invalid header `%s'.\n"),
               exec_name, com, val);
       return 0;
     }
-  return cmd_vector (com, val, place);
+  opt.user_headers = vec_append (opt.user_headers, val);
+  return 1;
 }
 
 static int
@@ -1286,9 +1300,8 @@ cmd_spec_timeout (const char *com, const char *val, void *place_ignored)
 static int
 cmd_spec_useragent (const char *com, const char *val, void *place_ignored)
 {
-  /* Just check for empty string and newline, so we don't throw total
-     junk to the server.  */
-  if (!*val || strchr (val, '\n'))
+  /* Disallow embedded newlines.  */
+  if (strchr (val, '\n'))
     {
       fprintf (stderr, _("%s: %s: Invalid value `%s'.\n"),
               exec_name, com, val);
@@ -1490,7 +1503,6 @@ cleanup (void)
   free_vec (opt.follow_tags);
   free_vec (opt.ignore_tags);
   xfree_null (opt.progress_type);
-  xfree (opt.ftp_acc);
   xfree_null (opt.ftp_user);
   xfree_null (opt.ftp_passwd);
   xfree_null (opt.ftp_proxy);
@@ -1505,6 +1517,10 @@ cleanup (void)
 # ifdef HAVE_SSL
   xfree_null (opt.cert_file);
   xfree_null (opt.private_key);
+  xfree_null (opt.ca_directory);
+  xfree_null (opt.ca_cert);
+  xfree_null (opt.random_file);
+  xfree_null (opt.egd_file);
 # endif
   xfree_null (opt.bind_address);
   xfree_null (opt.cookies_input);