[Vimprobable-users] [PATCH REROLL 1/1] Saner config file checking.

Thomas Adam thomas at xteddy.org
Sun Nov 7 23:15:52 GMT 2010


Don't moan if RCFILE cannot be opened -- instead, use give_feedback() if an
explicit config file was passed on the command-line, but couldn't be opened.
For everything else, use an explicit error, because we assume the file
could be opened, but not parsed for some reason.
---
 This appears to have fallen through the cracks...
 Have updated it to sit atop of 0.9.20.

 I broke this by mistake when I introduced "-c" on the command line.

 main.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/main.c b/main.c
index 99ce2b0..5ec92c8 100644
--- a/main.c
+++ b/main.c
@@ -2308,6 +2308,7 @@ main(int argc, char *argv[]) {
     static Arg a;
     static char url[256] = "";
     static gboolean ver = false;
+    static gboolean configfile_exists = false;
     static const char *cfile = NULL;
     static GOptionEntry opts[] = {
             { "version", 'v', 0, G_OPTION_ARG_NONE, &ver, "print version", NULL },
@@ -2348,12 +2349,25 @@ main(int argc, char *argv[]) {
     setup_cookies();
 #endif
 
+    /* Check if the specified file exists. */
+    /* And only warn the user, if they explicitly asked for a config on the
+     * command line.
+     */
+    if (!(access(configfile, F_OK) == 0) && cfile) {
+	    char *feedback_str;
+
+	    feedback_str = g_strdup_printf("Config file '%s' doesn't exist", cfile);
+	    give_feedback(feedback_str);
+    } else if ((access(configfile, F_OK) == 0))
+	    configfile_exists = true;
+
     /* read config file */
-    if (!read_rcfile(configfile)) {
-	free(configfile);
+    /* But only report errors if we failed, and the file existed. */
+    if (!read_rcfile(configfile) && configfile_exists) {
         a.i = Error;
-        a.s = g_strdup_printf("Error in config file");
+        a.s = g_strdup_printf("Error in config file '%s'", configfile);
         echo(&a);
+	g_free(configfile);
     }
 
     /* command line argument: URL */
-- 
1.7.1


More information about the Vimprobable-users mailing list