]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Better version of read_whole_line().
[wget] / src / init.c
index 9e11944551dbd18cc2ead4e2175672627eccea9f..b511c724859ddf3260482eb26deaaf5b45bc7c09 100644 (file)
@@ -1,5 +1,5 @@
 /* Reading/parsing the initialization file.
-   Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
 
 This file is part of Wget.
 
@@ -76,7 +76,6 @@ CMD_DECLARE (cmd_spec_dotstyle);
 CMD_DECLARE (cmd_spec_header);
 CMD_DECLARE (cmd_spec_htmlify);
 CMD_DECLARE (cmd_spec_mirror);
-CMD_DECLARE (cmd_spec_outputdocument);
 CMD_DECLARE (cmd_spec_recursive);
 CMD_DECLARE (cmd_spec_useragent);
 
@@ -96,8 +95,8 @@ static struct {
   { "background",      &opt.background,        cmd_boolean },
   { "backupconverted", &opt.backup_converted,  cmd_boolean },
   { "backups",         &opt.backups,           cmd_number },
-  { "bindaddress",     &opt.bind_address,      cmd_address },
   { "base",            &opt.base_href,         cmd_string },
+  { "bindaddress",     &opt.bind_address,      cmd_address },
   { "cache",           &opt.proxy_cache,       cmd_boolean },
   { "continue",                &opt.always_rest,       cmd_boolean },
   { "convertlinks",    &opt.convert_links,     cmd_boolean },
@@ -139,7 +138,7 @@ static struct {
   { "noparent",                &opt.no_parent,         cmd_boolean },
   { "noproxy",         &opt.no_proxy,          cmd_vector },
   { "numtries",                &opt.ntry,              cmd_number_inf },/* deprecated*/
-  { "outputdocument",  NULL,                   cmd_spec_outputdocument },
+  { "outputdocument",  &opt.output_document,   cmd_string },
   { "pagerequisites",  &opt.page_requisites,   cmd_boolean },
   { "passiveftp",      &opt.ftp_pasv,          cmd_lockable_boolean },
   { "passwd",          &opt.ftp_pass,          cmd_string },
@@ -175,7 +174,7 @@ static struct {
 static int
 comind (const char *com)
 {
-  int min = 0, max = ARRAY_SIZE (commands);
+  int min = 0, max = ARRAY_SIZE (commands) - 1;
 
   do
     {
@@ -337,10 +336,7 @@ run_wgetrc (const char *file)
     {
       char *com, *val;
       int status;
-      int length = strlen (line);
 
-      if (length && line[length - 1] == '\r')
-       line[length - 1] = '\0';
       /* Parse the line.  */
       status = parse_line (line, &com, &val);
       free (line);
@@ -412,12 +408,12 @@ parse_line (const char *line, char **com, char **val)
   const char *orig_comptr, *end;
   char *new_comptr;
 
-  /* Skip spaces.  */
-  while (*p == ' ' || *p == '\t')
+  /* Skip whitespace.  */
+  while (*p && ISSPACE (*p))
     ++p;
 
   /* Don't process empty lines.  */
-  if (!*p || *p == '\n' || *p == '#')
+  if (!*p || *p == '#')
     return -1;
 
   for (orig_comptr = p; ISALPHA (*p) || *p == '_' || *p == '-'; p++)
@@ -425,6 +421,8 @@ parse_line (const char *line, char **com, char **val)
   /* The next char should be space or '='.  */
   if (!ISSPACE (*p) && (*p != '='))
     return 0;
+  /* Here we cannot use strdupdelim() as we normally would because we
+     want to skip the `-' and `_' characters in the input string.  */
   *com = (char *)xmalloc (p - orig_comptr + 1);
   for (new_comptr = *com; orig_comptr < p; orig_comptr++)
     {
@@ -450,10 +448,12 @@ parse_line (const char *line, char **com, char **val)
     }
   /* Skip spaces after '='.  */
   for (++p; ISSPACE (*p); p++);
-  /* Get the ending position.  */
-  for (end = p; *end && *end != '\n'; end++);
-  /* Allocate *val, and copy from line.  */
-  *val = strdupdelim (p, end);
+  /* Get the ending position for VAL by starting with the end of the
+     line and skipping whitespace.  */
+  end = line + strlen (line) - 1;
+  while (end > p && ISSPACE (*end))
+    --end;
+  *val = strdupdelim (p, end + 1);
   return 1;
 }
 
@@ -915,15 +915,6 @@ cmd_spec_mirror (const char *com, const char *val, void *closure)
   return 1;
 }
 
-static int
-cmd_spec_outputdocument (const char *com, const char *val, void *closure)
-{
-  FREE_MAYBE (opt.output_document);
-  opt.output_document = xstrdup (val);
-  opt.ntry = 1;
-  return 1;
-}
-
 static int
 cmd_spec_recursive (const char *com, const char *val, void *closure)
 {