From bb828ddee8c67a31cd35db54968da2cb24d60ac6 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Mon, 27 Apr 2009 17:46:51 +0100 Subject: Added support for $XDG_CONFIG_DIRS. --- uzbl.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'uzbl.c') diff --git a/uzbl.c b/uzbl.c index f3e5649..de00c5f 100644 --- a/uzbl.c +++ b/uzbl.c @@ -100,6 +100,9 @@ typedef struct void (*func_2_params)(WebKitWebView*, const gchar *); } Command; +/* XDG stuff */ +char *XDG_CONFIG_HOME_default = "~/.config"; +char *XDG_CONFIG_DIRS_default = "/etc/xdg"; static void update_title (GtkWindow* window); @@ -443,15 +446,36 @@ settings_init () { gchar** keyse = NULL; if (! config_file) { - const char* xdg = getenv ("XDG_CONFIG_HOME"); + const char* XDG_CONFIG_HOME = getenv ("XDG_CONFIG_HOME"); char conf[256]; - if (xdg) { - printf("XDG_CONFIG_DIR: %s\n", xdg); - strcpy (conf, xdg); - strcat (conf, "/uzbl"); - if (file_exists (conf)) { - printf ("Config file %s found.\n", conf); - config_file = &conf[0]; + if (! XDG_CONFIG_HOME) { + XDG_CONFIG_HOME = XDG_CONFIG_HOME_default; + } + printf("XDG_CONFIG_HOME: %s\n", XDG_CONFIG_HOME); + + strcpy (conf, XDG_CONFIG_HOME); + strcat (conf, "/uzbl"); + if (file_exists (conf)) { + printf ("Config file %s found.\n", conf); + config_file = &conf[0]; + } else { + // Now we check $XDG_CONFIG_DIRS + char *XDG_CONFIG_DIRS = getenv ("XDG_CONFIG_DIRS"); + if (! XDG_CONFIG_DIRS) + XDG_CONFIG_DIRS = XDG_CONFIG_DIRS_default; + + printf("XDG_CONFIG_DIRS: %s\n", XDG_CONFIG_DIRS); + + char *dirs = XDG_CONFIG_DIRS; + char *dir = (char *)strtok (dirs, ":"); + while (dir && ! file_exists (conf)) { + strcpy (conf, dir); + strcat (conf, "/uzbl"); + if (file_exists (conf)) { + printf ("Config file %s found.\n", conf); + config_file = &conf[0]; + } + dir = (char *)strtok (NULL, ":"); } } } -- cgit v1.2.3