Optionally look for configuration in $XDG_CONFIG_HOME
authorIvy Foster <ivy.foster@gmail.com>
Sat, 23 Apr 2016 01:32:36 +0000 (20:32 -0500)
committerIvy Foster <ivy.foster@gmail.com>
Sat, 23 Apr 2016 01:32:36 +0000 (20:32 -0500)
Also check $HOME/.frotzrc, for backwards compatibility.
reference: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

src/curses/ux_frotz.h
src/curses/ux_init.c

index 19850539879c8ea609b2762d1278e9e2ed2532b1..1637e86764699621c9fc7d7d91e91c4d6200b4c2 100644 (file)
@@ -9,9 +9,6 @@
 #include "../blorb/blorb.h"
 #include "ux_setup.h"
 
-#define MASTER_CONFIG          "frotz.conf"
-#define USER_CONFIG            ".frotzrc"
-
 #define ASCII_DEF              1
 #define ATTRIB_ASSIG_DEF       0
 #define ATTRIB_TEST_DEF                0
index 4d69ad8d8f85bd0fb2246606474d0c2bdf851f4f..cc68fbaef8b3c26bf9b7131580e768bd02fad785 100644 (file)
@@ -192,20 +192,22 @@ void os_process_arguments (int argc, char *argv[])
     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
        signal(SIGINT, sigint_handler);
 
-    /* First check for a "$HOME/.frotzrc". */
-    /* If not found, look for CONFIG_DIR/frotz.conf */
-    /* $HOME/.frotzrc overrides CONFIG_DIR/frotz.conf */
-
-    strncpy(configfile, home, FILENAME_MAX);
-    strncat(configfile, "/", 1);
-
-    strncat(configfile, USER_CONFIG, strlen(USER_CONFIG));
-    if (!getconfig(configfile)) {
-       strncpy(configfile, CONFIG_DIR, FILENAME_MAX);
-       strncat(configfile, "/", 1);    /* added by DJP */
-       strncat(configfile, MASTER_CONFIG, FILENAME_MAX-10);
-       getconfig(configfile);  /* we're not concerned if this fails */
-    }
+       if (getenv("XDG_CONFIG_HOME")) {
+               snprintf(configfile, FILENAME_MAX,
+                       "%s/frotz/frotz.conf", getenv("XDG_CONFIG_HOME"));
+       } else {
+               snprintf(configfile, FILENAME_MAX,
+                       "%s/.config/frotz/frotz.conf", home);
+       }
+
+       if (!getconfig(configfile)) {
+               snprintf(configfile, FILENAME_MAX, "%s/.frotzrc", home);
+       }
+    
+       if (!getconfig(configfile)) {
+               snprintf(configfile, FILENAME_MAX, "%s/frotz.conf", CONFIG_DIR);
+               getconfig(configfile);  /* we're not concerned if this fails */
+       }
 
     /* Parse the options */