Mercurial > hg > nnchat
comparison main.c @ 650:98f5d15d5ec4
Improve and fix XDG support.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Jan 2015 06:44:25 +0200 |
parents | a190b618100a |
children | 58a376f86cdf |
comparison
equal
deleted
inserted
replaced
649:a190b618100a | 650:98f5d15d5ec4 |
---|---|
22 #ifdef __WIN32 | 22 #ifdef __WIN32 |
23 # define SET_CONFIG_FILE "nnchat.txt" | 23 # define SET_CONFIG_FILE "nnchat.txt" |
24 # define SET_LOG_DIR "NNChat Log Files" | 24 # define SET_LOG_DIR "NNChat Log Files" |
25 # define SET_DIR_SEPARATOR '\\' | 25 # define SET_DIR_SEPARATOR '\\' |
26 #else | 26 #else |
27 #define SET_CONFIG_FILE ".nnchat" | 27 # define SET_DIR_SEPARATOR '/' |
28 #define SET_LOG_DIR "nnlogs" | 28 # define SET_LOG_DIR "nnlogs" |
29 #define SET_DIR_SEPARATOR '/' | 29 # if defined(USE_XDG) |
30 # define SET_XDG_CONFIG_DIR "nnchat" | |
31 # define SET_CONFIG_FILE "config" | |
32 # else | |
33 # define SET_CONFIG_FILE ".nnchat" | |
34 # endif | |
30 #endif | 35 #endif |
31 | 36 |
32 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/" | 37 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/" |
33 #define SET_NICK_SEPARATOR ':' | 38 #define SET_NICK_SEPARATOR ':' |
34 | 39 |
1800 } | 1805 } |
1801 | 1806 |
1802 | 1807 |
1803 BOOL nn_log_open(nn_window_t *win) | 1808 BOOL nn_log_open(nn_window_t *win) |
1804 { | 1809 { |
1805 char *path = NULL; | 1810 char *path = NULL, *plt; |
1806 #ifndef __WIN32 | 1811 #ifndef __WIN32 |
1807 int logFd = -1; | 1812 int logFd = -1; |
1808 #endif | 1813 #endif |
1809 | 1814 |
1810 if (!optLogEnable) | 1815 if (!optLogEnable || optLogPath == NULL) |
1811 return FALSE; | 1816 return FALSE; |
1812 | 1817 |
1813 if (optLogPath != NULL) | 1818 plt = strrchr(optLogPath, SET_DIR_SEPARATOR); |
1814 { | 1819 if (plt == NULL || plt[1] != 0) |
1815 char *lt = strrchr(optLogPath, SET_DIR_SEPARATOR); | 1820 path = th_strdup_printf("%s%c", optLogPath, SET_DIR_SEPARATOR); |
1816 if (lt == NULL || lt[1] != 0) | 1821 else |
1817 path = th_strdup_printf("%s%c", optLogPath, SET_DIR_SEPARATOR); | 1822 path = th_strdup(optLogPath); |
1818 else | |
1819 path = th_strdup(optLogPath); | |
1820 } | |
1821 | 1823 |
1822 if (win->id == NULL) | 1824 if (win->id == NULL) |
1823 { | 1825 { |
1824 // Main window log (aka room log) | 1826 // Main window log (aka room log) |
1825 if (optLogDaily) | 1827 if (optLogDaily) |
2078 const char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); | 2080 const char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); |
2079 setHomeDir = th_strdup(getenv("HOME")); | 2081 setHomeDir = th_strdup(getenv("HOME")); |
2080 | 2082 |
2081 // If XDG is enabled, try the environment variable first | 2083 // If XDG is enabled, try the environment variable first |
2082 if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) | 2084 if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) |
2083 setConfigDir = th_strdup_printf("%s/nnchat/", xdgConfigDir); | 2085 setConfigDir = th_strdup_printf("%s/%s/", xdgConfigDir, SET_XDG_CONFIG_DIR); |
2084 else | 2086 else |
2085 // Nope, try the obvious alternative | 2087 // Nope, try the obvious alternative |
2086 setConfigDir = th_strdup_printf("%s/.config/nnchat/", setHomeDir); | 2088 setConfigDir = th_strdup_printf("%s/.config/%s/", setHomeDir, SET_XDG_CONFIG_DIR); |
2087 #else | 2089 #else |
2088 setHomeDir = th_strdup(getenv("HOME")); | 2090 setHomeDir = th_strdup(getenv("HOME")); |
2089 setConfigDir = th_strdup(setHomeDir); | 2091 setConfigDir = th_strdup(setHomeDir); |
2090 #endif | 2092 #endif |
2091 } | 2093 } |