# HG changeset patch # User Matti Hamalainen # Date 1422247465 -7200 # Node ID 98f5d15d5ec43da5e5afe74b3248fabdf64a9050 # Parent a190b618100ac006d33f8cc559191425016f5525 Improve and fix XDG support. diff -r a190b618100a -r 98f5d15d5ec4 main.c --- a/main.c Mon Jan 26 06:44:05 2015 +0200 +++ b/main.c Mon Jan 26 06:44:25 2015 +0200 @@ -24,9 +24,14 @@ # define SET_LOG_DIR "NNChat Log Files" # define SET_DIR_SEPARATOR '\\' #else -#define SET_CONFIG_FILE ".nnchat" -#define SET_LOG_DIR "nnlogs" -#define SET_DIR_SEPARATOR '/' +# define SET_DIR_SEPARATOR '/' +# define SET_LOG_DIR "nnlogs" +# if defined(USE_XDG) +# define SET_XDG_CONFIG_DIR "nnchat" +# define SET_CONFIG_FILE "config" +# else +# define SET_CONFIG_FILE ".nnchat" +# endif #endif #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/" @@ -1802,22 +1807,19 @@ BOOL nn_log_open(nn_window_t *win) { - char *path = NULL; + char *path = NULL, *plt; #ifndef __WIN32 int logFd = -1; #endif - if (!optLogEnable) + if (!optLogEnable || optLogPath == NULL) return FALSE; - if (optLogPath != NULL) - { - char *lt = strrchr(optLogPath, SET_DIR_SEPARATOR); - if (lt == NULL || lt[1] != 0) - path = th_strdup_printf("%s%c", optLogPath, SET_DIR_SEPARATOR); - else - path = th_strdup(optLogPath); - } + plt = strrchr(optLogPath, SET_DIR_SEPARATOR); + if (plt == NULL || plt[1] != 0) + path = th_strdup_printf("%s%c", optLogPath, SET_DIR_SEPARATOR); + else + path = th_strdup(optLogPath); if (win->id == NULL) { @@ -2080,10 +2082,10 @@ // If XDG is enabled, try the environment variable first if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) - setConfigDir = th_strdup_printf("%s/nnchat/", xdgConfigDir); + setConfigDir = th_strdup_printf("%s/%s/", xdgConfigDir, SET_XDG_CONFIG_DIR); else // Nope, try the obvious alternative - setConfigDir = th_strdup_printf("%s/.config/nnchat/", setHomeDir); + setConfigDir = th_strdup_printf("%s/.config/%s/", setHomeDir, SET_XDG_CONFIG_DIR); #else setHomeDir = th_strdup(getenv("HOME")); setConfigDir = th_strdup(setHomeDir);