]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Remove warnings under Borland C.
[wget] / src / init.c
index c0f260ed4c5c7aba282b589336c607b261819128..9cb2e9c7cca79925be1488e9ec3728b73508efab 100644 (file)
@@ -1,5 +1,5 @@
 /* Reading/parsing the initialization file.
-   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2003
+   Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2003, 2004
    Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
@@ -43,16 +43,6 @@ so, delete this exception statement from your version.  */
 #endif
 #include <errno.h>
 
-#ifdef WINDOWS
-# include <winsock.h>
-#else
-# include <sys/socket.h>
-# include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#endif
-#endif
-
 #ifdef HAVE_PWD_H
 # include <pwd.h>
 #endif
@@ -114,7 +104,7 @@ CMD_DECLARE (cmd_spec_useragent);
    cleanup() function below. */
 
 static struct {
-  char *name;
+  const char *name;
   void *closure;
   int (*action) PARAMS ((const char *, const char *, void *));
 } commands[] = {
@@ -153,9 +143,10 @@ static struct {
   { "followftp",       &opt.follow_ftp,        cmd_boolean },
   { "followtags",      &opt.follow_tags,       cmd_vector },
   { "forcehtml",       &opt.force_html,        cmd_boolean },
+  { "ftppasswd",       &opt.ftp_pass,          cmd_string },
   { "ftpproxy",                &opt.ftp_proxy,         cmd_string },
   { "glob",            &opt.ftp_glob,          cmd_boolean },
-  { "header",          NULL,                   cmd_spec_header },
+  { "header",          &opt.user_headers,      cmd_spec_header },
   { "htmlextension",   &opt.html_extension,    cmd_boolean },
   { "htmlify",         NULL,                   cmd_spec_htmlify },
   { "httpkeepalive",   &opt.http_keep_alive,   cmd_boolean },
@@ -166,6 +157,10 @@ static struct {
   { "ignorelength",    &opt.ignore_length,     cmd_boolean },
   { "ignoretags",      &opt.ignore_tags,       cmd_vector },
   { "includedirectories", &opt.includes,       cmd_directory_vector },
+#ifdef ENABLE_IPV6
+  { "inet4only",       &opt.ipv4_only,         cmd_boolean },
+  { "inet6only",       &opt.ipv6_only,         cmd_boolean },
+#endif
   { "input",           &opt.input_filename,    cmd_file },
   { "keepsessioncookies", &opt.keep_session_cookies, cmd_boolean },
   { "killlonger",      &opt.kill_longer,       cmd_boolean },
@@ -182,10 +177,11 @@ static struct {
   { "outputdocument",  &opt.output_document,   cmd_file },
   { "pagerequisites",  &opt.page_requisites,   cmd_boolean },
   { "passiveftp",      &opt.ftp_pasv,          cmd_lockable_boolean },
-  { "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 },
+  { "protocoldirectories", &opt.protocol_directories, cmd_boolean },
   { "proxypasswd",     &opt.proxy_passwd,      cmd_string },
   { "proxyuser",       &opt.proxy_user,        cmd_string },
   { "quiet",           &opt.quiet,             cmd_boolean },
@@ -318,9 +314,9 @@ home_dir (void)
        return NULL;
       home = pwd->pw_dir;
 #else  /* WINDOWS */
-      home = "C:\\";
-      /* #### Maybe I should grab home_dir from registry, but the best
-        that I could get from there is user's Start menu.  It sucks!  */
+      /* Under Windows, if $HOME isn't defined, use the directory where
+         `wget.exe' resides.  */
+      home = ws_mypath ();
 #endif /* WINDOWS */
     }
 
@@ -351,27 +347,24 @@ wgetrc_file_name (void)
       return xstrdup (env);
     }
 
-#ifndef WINDOWS
   /* If that failed, try $HOME/.wgetrc.  */
   home = home_dir ();
   if (home)
-    {
-      file = (char *)xmalloc (strlen (home) + 1 + strlen (".wgetrc") + 1);
-      sprintf (file, "%s/.wgetrc", home);
-    }
+    file = aprintf ("%s/.wgetrc", home);
   xfree_null (home);
-#else  /* WINDOWS */
-  /* Under Windows, "home" is (for the purposes of this function) the
-     directory where `wget.exe' resides, and `wget.ini' will be used
-     as file name.  SYSTEM_WGETRC should not be defined under WINDOWS.
 
-     It is not as trivial as I assumed, because on 95 argv[0] is full
-     path, but on NT you get what you typed in command line.  --dbudor */
-  home = ws_mypath ();
-  if (home)
+#ifdef WINDOWS
+  /* Under Windows, if we still haven't found .wgetrc, look for the file
+     `wget.ini' in the directory where `wget.exe' resides; we do this for
+     backward compatibility with previous versions of Wget.
+     SYSTEM_WGETRC should not be defined under WINDOWS.  */
+  if (!file || !file_exists_p (file))
     {
-      file = (char *)xmalloc (strlen (home) + strlen ("wget.ini") + 1);
-      sprintf (file, "%swget.ini", home);
+      xfree_null (file);
+      file = NULL;
+      home = ws_mypath ();
+      if (home)
+       file = aprintf ("%s/wget.ini", home);
     }
 #endif /* WINDOWS */
 
@@ -406,7 +399,7 @@ run_wgetrc (const char *file)
     }
   enable_tilde_expansion = 1;
   ln = 1;
-  while ((line = read_whole_line (fp)))
+  while ((line = read_whole_line (fp)) != NULL)
     {
       char *com, *val;
       int comind, status;
@@ -859,8 +852,8 @@ cmd_directory_vector (const char *com, const char *val, void *closure)
 
 static int simple_atof PARAMS ((const char *, const char *, double *));
 
-/* Enginge for cmd_bytes and cmd_bytes_large: converts a string such
-   as "100k" or "2.5G" to a floating point number.  */
+/* Engine for cmd_bytes and cmd_bytes_large: converts a string such as
+   "100k" or "2.5G" to a floating point number.  */
 
 static int
 parse_bytes_helper (const char *val, double *result)
@@ -917,7 +910,7 @@ parse_bytes_helper (const char *val, double *result)
 }
 
 /* Parse VAL as a number and set its value to CLOSURE (which should
-   point to a long int).
+   point to a wgint).
 
    By default, the value is assumed to be in bytes.  If "K", "M", or
    "G" are appended, the value is multiplied with 1<<10, 1<<20, or
@@ -940,7 +933,7 @@ cmd_bytes (const char *com, const char *val, void *closure)
               exec_name, com, val);
       return 0;
     }
-  *(long *)closure = (long)byte_value;
+  *(wgint *)closure = (wgint)byte_value;
   return 1;
 }
 
@@ -1045,32 +1038,13 @@ cmd_spec_dirstruct (const char *com, const char *val, void *closure)
 static int
 cmd_spec_header (const char *com, const char *val, void *closure)
 {
-  if (!*val)
+  if (!check_user_specified_header (val))
     {
-      /* Empty header means reset headers.  */
-      xfree_null (opt.user_header);
-      opt.user_header = NULL;
-    }
-  else
-    {
-      int i;
-
-      if (!check_user_specified_header (val))
-       {
-         fprintf (stderr, _("%s: %s: Invalid header `%s'.\n"),
-                  exec_name, com, val);
-         return 0;
-       }
-      i = opt.user_header ? strlen (opt.user_header) : 0;
-      opt.user_header = (char *)xrealloc (opt.user_header, i + strlen (val)
-                                         + 2 + 1);
-      strcpy (opt.user_header + i, val);
-      i += strlen (val);
-      opt.user_header[i++] = '\r';
-      opt.user_header[i++] = '\n';
-      opt.user_header[i] = '\0';
+      fprintf (stderr, _("%s: %s: Invalid header `%s'.\n"),
+              exec_name, com, val);
+      return 0;
     }
-  return 1;
+  return cmd_vector (com, val, closure);
 }
 
 static int
@@ -1308,8 +1282,13 @@ cleanup (void)
 {
   /* Free external resources, close files, etc. */
 
-  if (opt.dfp)
-    fclose (opt.dfp);
+  {
+    extern FILE *output_stream;
+    if (output_stream)
+      fclose (output_stream);
+    /* No need to check for error because Wget flushes its output (and
+       checks for errors) after any data arrives.  */
+  }
 
   /* We're exiting anyway so there's no real need to call free()
      hundreds of times.  Skipping the frees will make Wget exit