From 8f7dd09b8aecb1f62c249d26dfad008d1b9bfb6a Mon Sep 17 00:00:00 2001 From: Ivy Foster Date: Fri, 22 Apr 2016 20:32:36 -0500 Subject: [PATCH] Optionally look for configuration in $XDG_CONFIG_HOME Also check $HOME/.frotzrc, for backwards compatibility. reference: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html --- src/curses/ux_frotz.h | 3 --- src/curses/ux_init.c | 30 ++++++++++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/curses/ux_frotz.h b/src/curses/ux_frotz.h index 1985053..1637e86 100644 --- a/src/curses/ux_frotz.h +++ b/src/curses/ux_frotz.h @@ -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 diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 4d69ad8..cc68fba 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -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 */ -- 2.34.1