]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Allow decimal values for --timeout, --wait, and --waitretry.
[wget] / src / init.c
index bce2427aaf71cd8e4fe17565607fda5d33bdd1c7..321e2d42b22afe1826e8aaf996a6533b8ebf67a5 100644 (file)
@@ -189,7 +189,7 @@ static struct {
   { "reject",          &opt.rejects,           cmd_vector },
   { "relativeonly",    &opt.relative_only,     cmd_boolean },
   { "removelisting",   &opt.remove_listing,    cmd_boolean },
-  { "restrictfilenames", &opt.restrict_file_names, cmd_spec_restrict_file_names },
+  { "restrictfilenames", NULL,                 cmd_spec_restrict_file_names },
   { "retrsymlinks",    &opt.retr_symlinks,     cmd_boolean },
   { "retryconnrefused",        &opt.retry_connrefused, cmd_boolean },
   { "robots",          &opt.use_robots,        cmd_boolean },
@@ -207,6 +207,7 @@ static struct {
   { "sslcheckcert",    &opt.sslcheckcert,      cmd_number },
   { "sslprotocol",     &opt.sslprotocol,       cmd_number },
 #endif /* HAVE_SSL */
+  { "strictcomments",  &opt.strict_comments,   cmd_boolean },
   { "timeout",         &opt.timeout,           cmd_time },
   { "timestamping",    &opt.timestamping,      cmd_boolean },
   { "tries",           &opt.ntry,              cmd_number_inf },
@@ -223,7 +224,7 @@ static struct {
 static int
 comind (const char *com)
 {
-  int lo = 0, hi = ARRAY_SIZE (commands) - 1;
+  int lo = 0, hi = countof (commands) - 1;
 
   while (lo <= hi)
     {
@@ -255,7 +256,6 @@ defaults (void)
   opt.cookies = 1;
 
   opt.verbose = -1;
-  opt.dir_prefix = xstrdup (".");
   opt.ntry = 20;
   opt.reclevel = 5;
   opt.add_hostdir = 1;
@@ -286,10 +286,11 @@ defaults (void)
 
   /* The default for file name restriction defaults to the OS type. */
 #if !defined(WINDOWS) && !defined(__CYGWIN__)
-  opt.restrict_file_names = restrict_shell;
+  opt.restrict_files_os = restrict_unix;
 #else
-  opt.restrict_file_names = restrict_windows;
+  opt.restrict_files_os = restrict_windows;
 #endif
+  opt.restrict_files_ctrl = 1;
 }
 \f
 /* Return the user's home directory (strdup-ed), or NULL if none is
@@ -666,6 +667,12 @@ cmd_string (const char *com, const char *val, void *closure)
   return 1;
 }
 
+#ifndef WINDOWS
+# define ISSEP(c) ((c) == '/')
+#else
+# define ISSEP(c) ((c) == '/' || (c) == '\\')
+#endif
+
 /* Like the above, but handles tilde-expansion when reading a user's
    `.wgetrc'.  In that case, and if VAL begins with `~', the tilde
    gets expanded to the user's home directory.  */
@@ -678,11 +685,7 @@ cmd_file (const char *com, const char *val, void *closure)
 
   /* #### If VAL is empty, perhaps should set *CLOSURE to NULL.  */
 
-  if (!enable_tilde_expansion || !(*val == '~' && (*(val + 1) == '/'
-#ifdef WINDOWS
-         || *(val + 1) == '\\'
-#endif
-         )))
+  if (!enable_tilde_expansion || !(*val == '~' && ISSEP (val[1])))
     {
     noexpand:
       *pstring = xstrdup (val);
@@ -696,21 +699,12 @@ cmd_file (const char *com, const char *val, void *closure)
        goto noexpand;
 
       homelen = strlen (home);
-      while (homelen && (home[homelen - 1] == '/'
-#ifdef WINDOWS
-           || home[homelen - 1] == '\\'
-#endif
-           ))
+      while (homelen && ISSEP (home[homelen - 1]))
        home[--homelen] = '\0';
 
       /* Skip the leading "~/". */
-#ifdef WINDOWS
-      for (++val; *val == '/' || *val == '\\'; val++)
-       ;
-#else
-      for (++val; *val == '/'; val++)
+      for (++val; ISSEP (*val); val++)
        ;
-#endif
 
       result = xmalloc (homelen + 1 + strlen (val) + 1);
       memcpy (result, home, homelen);
@@ -719,6 +713,7 @@ cmd_file (const char *com, const char *val, void *closure)
 
       *pstring = result;
     }
+
 #ifdef WINDOWS
   /* Convert "\" to "/". */
   {
@@ -861,51 +856,89 @@ cmd_bytes (const char *com, const char *val, void *closure)
   return 1;
 }
 
-/* Store the value of VAL to *OUT, allowing suffixes for minutes and
-   hours.  */
+/* Store the value of VAL to *OUT.  The value is a time period, by
+   default expressed in seconds.  */
+
 static int
 cmd_time (const char *com, const char *val, void *closure)
 {
-  long result = 0;
-  const char *p = val;
+  double result, mult, divider;
+  int seen_dot, seen_digit;
 
-  /* Search for digits and construct result.  */
-  for (; *p && ISDIGIT (*p); p++)
-    result = (10 * result) + (*p - '0');
-  /* If no digits were found, or more than one character is following
-     them, bail out.  */
-  if (p == val || (*p != '\0' && *(p + 1) != '\0'))
+  const char *p;
+  const char *end = val + strlen (val);
+
+  /* Skip trailing whitespace.  */
+  while (end > val && ISSPACE (end[-1]))
+    --end;
+
+  if (val == end)
     {
-      printf (_("%s: Invalid specification `%s'\n"), com, val);
+    err:
+      fprintf (stderr, _("%s: Invalid time specification `%s'\n"), com, val);
       return 0;
     }
-  /* Search for a suffix.  */
-  switch (TOLOWER (*p))
+
+  switch (TOLOWER (end[-1]))
     {
-    case '\0':
-      /* None */
+    case 's':
+      --end, mult = 1;         /* seconds */
       break;
     case 'm':
-      /* Minutes */
-      result *= 60;
+      --end, mult = 60;                /* minutes */
       break;
     case 'h':
-      /* Seconds */
-      result *= 3600;
+      --end, mult = 3600;      /* hours */
       break;
     case 'd':
-      /* Days (overflow on 16bit machines) */
-      result *= 86400L;
+      --end, mult = 86400;     /* days */
       break;
     case 'w':
-      /* Weeks :-) */
-      result *= 604800L;
+      --end, mult = 604800;    /* weeks */
       break;
     default:
-      printf (_("%s: Invalid specification `%s'\n"), com, val);
-      return 0;
+      /* Not a recognized suffix: treat it as part of number, and
+        assume seconds. */
+      mult = 1;
+    }
+
+  /* Skip leading and trailing whitespace. */
+  while (val < end && ISSPACE (*val))
+    ++val;
+  while (val > end && ISSPACE (end[-1]))
+    --end;
+  if (val == end)
+    goto err;
+
+  /* Poor man's strtod: */
+  result = 0;
+  seen_dot = seen_digit = 0;
+  divider = 1;
+
+  p = val;
+  while (p < end)
+    {
+      char ch = *p++;
+      if (ISDIGIT (ch))
+       {
+         if (!seen_dot)
+           result = (10 * result) + (ch - '0');
+         else
+           result += (ch - '0') / (divider *= 10);
+         seen_digit = 1;
+       }
+      else if (ch == '.')
+       {
+         if (!seen_dot)
+           seen_dot = 1;
+         else
+           goto err;
+       }
     }
-  *(long *)closure = result;
+  if (!seen_digit)
+    goto err;
+  result *= mult;
+  *(double *)closure = result;
   return 1;
 }
 \f
@@ -1020,20 +1053,41 @@ cmd_spec_recursive (const char *com, const char *val, void *closure)
 static int
 cmd_spec_restrict_file_names (const char *com, const char *val, void *closure)
 {
-  /* The currently accepted values are `none', `unix', and
-     `windows'.  */
-  if (0 == strcasecmp (val, "none"))
-    opt.restrict_file_names = restrict_none;
-  else if (0 == strcasecmp (val, "unix"))
-    opt.restrict_file_names = restrict_shell;
-  else if (0 == strcasecmp (val, "windows"))
-    opt.restrict_file_names = restrict_windows;
+  int restrict_os = opt.restrict_files_os;
+  int restrict_ctrl = opt.restrict_files_ctrl;
+
+  const char *end = strchr (val, ',');
+  if (!end)
+    end = val + strlen (val);
+
+#define VAL_IS(string_literal) BOUNDED_EQUAL (val, end, string_literal)
+
+  if (VAL_IS ("unix"))
+    restrict_os = restrict_unix;
+  else if (VAL_IS ("windows"))
+    restrict_os = restrict_windows;
+  else if (VAL_IS ("nocontrol"))
+    restrict_ctrl = 0;
   else
     {
+    err:
       fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
               exec_name, com, val);
       return 0;
     }
+
+#undef VAL_IS
+
+  if (*end)
+    {
+      if (!strcmp (end + 1, "nocontrol"))
+       restrict_ctrl = 0;
+      else
+       goto err;
+    }
+
+  opt.restrict_files_os = restrict_os;
+  opt.restrict_files_ctrl = restrict_ctrl;
   return 1;
 }
 
@@ -1070,8 +1124,6 @@ myatoi (const char *s)
     return res;
 }
 
-#define ISODIGIT(x) ((x) >= '0' && (x) <= '7')
-
 static int
 check_user_specified_header (const char *s)
 {
@@ -1125,7 +1177,7 @@ cleanup (void)
     free_netrc (netrc_list);
   }
   FREE_MAYBE (opt.lfilename);
-  xfree (opt.dir_prefix);
+  FREE_MAYBE (opt.dir_prefix);
   FREE_MAYBE (opt.input_filename);
   FREE_MAYBE (opt.output_document);
   free_vec (opt.accepts);