Hi

This is for the latest branch. I've started on the Changelog but it
needs more done to it. I just thought I'd send it for a review first
before completing it.

Reza
=== modified file 'src/ChangeLog'
--- src/ChangeLog	2010-08-01 20:55:53 +0000
+++ src/ChangeLog	2010-08-05 17:55:28 +0000
@@ -1,3 +1,18 @@
+2010-08-04  Reza Snowdon <[email protected]>
+
+       * main.c (main): inserted 'defaults'
+       * init.c: Include stdbool.h.
+          (commands):Added config detailsi.
+         (defaults): Removed static. 
+         (wgetrc): Removed static.  
+         (initialize): Removed 'defaults ()',
+          changed 'int ok' to 'bool ok'
+       * init.h (defaults): exported function.
+         (run_wgetrc): exported function.
+       * options.h: New variable 'choose_config'
+      
+
+
 2010-07-25  John Trengrove  <[email protected]> (tiny change)
 
 	* ftp.h: Added enum `parsetype'.  Modified struct to hold parsetype.

=== modified file 'src/init.c'
--- src/init.c	2010-07-28 19:22:22 +0000
+++ src/init.c	2010-08-05 18:13:02 +0000
@@ -32,6 +32,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
@@ -136,6 +137,7 @@
   { "certificatetype",  &opt.cert_type,         cmd_cert_type },
   { "checkcertificate", &opt.check_cert,        cmd_boolean },
 #endif
+  { "chooseconfig",     &opt.choose_config,     cmd_file },
   { "connecttimeout",   &opt.connect_timeout,   cmd_time },
   { "contentdisposition", &opt.content_disposition, cmd_boolean },
   { "continue",         &opt.always_rest,       cmd_boolean },
@@ -290,7 +292,7 @@
 }
 
 /* Reset the variables to default values.  */
-static void
+void
 defaults (void)
 {
   char *tmp;
@@ -509,7 +511,7 @@
 /* Initialize variables from a wgetrc file.  Returns zero (failure) if
    there were errors in the file.  */
 
-static bool
+bool
 run_wgetrc (const char *file)
 {
   FILE *fp;
@@ -573,10 +575,7 @@
 initialize (void)
 {
   char *file, *env_sysrc;
-  int ok = true;
-
-  /* Load the hard-coded defaults.  */
-  defaults ();
+  bool ok = true;
 
   /* Run a non-standard system rc file when the according environment
      variable has been set. For internal testing purposes only!  */
@@ -1577,6 +1576,7 @@
     extern acc_t *netrc_list;
     free_netrc (netrc_list);
   }
+  xfree_null (opt.choose_config); 
   xfree_null (opt.lfilename);
   xfree_null (opt.dir_prefix);
   xfree_null (opt.input_filename);

=== modified file 'src/init.h'
--- src/init.h	2010-05-08 19:56:15 +0000
+++ src/init.h	2010-08-05 17:58:15 +0000
@@ -39,5 +39,7 @@
 void setoptval (const char *, const char *, const char *);
 char *home_dir (void);
 void cleanup (void);
+void defaults (void);
+bool run_wgetrc (const char *file);
 
 #endif /* INIT_H */

=== modified file 'src/main.c'
--- src/main.c	2010-07-28 19:22:22 +0000
+++ src/main.c	2010-08-05 18:03:20 +0000
@@ -164,6 +164,7 @@
     { IF_SSL ("certificate-type"), 0, OPT_VALUE, "certificatetype", -1 },
     { IF_SSL ("check-certificate"), 0, OPT_BOOLEAN, "checkcertificate", -1 },
     { "clobber", 0, OPT__CLOBBER, NULL, optional_argument },
+    { "config", 0, OPT_VALUE, "chooseconfig", -1 },
     { "connect-timeout", 0, OPT_VALUE, "connecttimeout", -1 },
     { "continue", 'c', OPT_BOOLEAN, "continue", -1 },
     { "convert-links", 'k', OPT_BOOLEAN, "convertlinks", -1 },
@@ -439,6 +440,9 @@
     N_("\
   -B,  --base=URL            resolves HTML input-file links (-i -F)\n\
                              relative to URL.\n"),
+    N_("\
+       --config=FILE         Specify config file to use.\n"),
+
     "\n",
 
     N_("\
@@ -892,10 +896,45 @@
   windows_main ((char **) &exec_name);
 #endif
 
-  /* Set option defaults; read the system wgetrc and ~/.wgetrc.  */
-  initialize ();
+  /* Load the hard-coded defaults.  */
+  defaults ();
 
   init_switches ();
+
+  /* This seperate getopt_long is needed to find the user config
+     and parse it before the other user options. */
+
+  longindex = -1;
+  int retconf;
+  bool use_userconfig = false;
+  while ((retconf = getopt_long (argc, argv, 
+                                short_options, long_options, &longindex)) != -1)
+    {
+      int confval;
+      bool userrc_ret = true;   
+      struct cmdline_option *config_opt;
+      confval = long_options[longindex].val;
+      config_opt = &option_data[confval & ~BOOLEAN_NEG_MARKER];
+      if (strcmp (config_opt->long_name, "config") == 0) 
+        {
+          userrc_ret &= run_wgetrc (optarg);  
+          use_userconfig = true;
+        }
+      if (!userrc_ret)
+        {
+          printf("Exiting due to error in %s\n", optarg);
+          exit (2);
+        }
+      else
+        break;
+    }
+
+  /* If the user did not specify a config, read the system wgetrc and ~/.wgetrc. */
+  if (use_userconfig == false)
+    initialize();
+
+  opterr = 0; 
+  optind = 0;
   longindex = -1;
   while ((ret = getopt_long (argc, argv,
                              short_options, long_options, &longindex)) != -1)

=== modified file 'src/options.h'
--- src/options.h	2010-07-28 19:22:22 +0000
+++ src/options.h	2010-08-05 18:03:33 +0000
@@ -57,6 +57,7 @@
   char *dir_prefix;		/* The top of directory tree */
   char *lfilename;		/* Log filename */
   char *input_filename;		/* Input filename */
+  char *choose_config;          /* Specified config file */
   bool force_html;		/* Is the input file an HTML file? */
 
   char *default_page;           /* Alternative default page (index file) */

Reply via email to