aboutsummaryrefslogtreecommitdiffstats
path: root/src/config-ini.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config-ini.c')
-rw-r--r--src/config-ini.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/config-ini.c b/src/config-ini.c
index 334a541..4f12610 100644
--- a/src/config-ini.c
+++ b/src/config-ini.c
@@ -14,9 +14,12 @@
You should have received a copy of the GNU General Public License
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
- Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
+ Copyright (c) 2010-2018 Jon Lund Steffensen <jonlst@gmail.com>
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#include <stdio.h>
#include <stdlib.h>
@@ -63,8 +66,15 @@ open_config_file(const char *filepath)
if (f == NULL && (env = getenv("XDG_CONFIG_HOME")) != NULL &&
env[0] != '\0') {
- snprintf(cp, sizeof(cp), "%s/redshift.conf", env);
+ snprintf(cp, sizeof(cp),
+ "%s/redshift/redshift.conf", env);
f = fopen(cp, "r");
+ if (f == NULL) {
+ /* Fall back to formerly used path. */
+ snprintf(cp, sizeof(cp),
+ "%s/redshift.conf", env);
+ f = fopen(cp, "r");
+ }
}
#ifdef _WIN32
@@ -78,8 +88,14 @@ open_config_file(const char *filepath)
if (f == NULL && (env = getenv("HOME")) != NULL &&
env[0] != '\0') {
snprintf(cp, sizeof(cp),
- "%s/.config/redshift.conf", env);
+ "%s/.config/redshift/redshift.conf", env);
f = fopen(cp, "r");
+ if (f == NULL) {
+ /* Fall back to formerly used path. */
+ snprintf(cp, sizeof(cp),
+ "%s/.config/redshift.conf", env);
+ f = fopen(cp, "r");
+ }
}
#ifndef _WIN32
@@ -89,8 +105,14 @@ open_config_file(const char *filepath)
char *home = pwd->pw_dir;
if ((home != NULL) && (*home != '\0')) {
snprintf(cp, sizeof(cp),
- "%s/.config/redshift.conf", home);
+ "%s/.config/redshift/redshift.conf", home);
f = fopen(cp, "r");
+ if (f == NULL) {
+ /* Fall back to formerly used path. */
+ snprintf(cp, sizeof(cp),
+ "%s/.config/redshift.conf", home);
+ f = fopen(cp, "r");
+ }
} else {
fprintf(stderr, _("Cannot determine your home directory, "
"it is from the system's user table.\n"));
@@ -115,9 +137,14 @@ open_config_file(const char *filepath)
int len = end - begin;
if (len > 0) {
snprintf(cp, sizeof(cp),
- "%.*s/redshift.conf", len, begin);
-
+ "%.*s/redshift/redshift.conf", len, begin);
f = fopen(cp, "r");
+ if (f != NULL) {
+ /* Fall back to formerly used path. */
+ snprintf(cp, sizeof(cp),
+ "%.*s/redshift.conf", len, begin);
+ f = fopen(cp, "r");
+ }
if (f != NULL) break;
}
@@ -171,7 +198,7 @@ config_ini_init(config_ini_state_t *state, const char *filepath)
s[strcspn(s, "\r\n")] = '\0';
/* Skip comments and empty lines. */
- if (s[0] == ';' || s[0] == '\0') continue;
+ if (s[0] == ';' || s[0] == '#' || s[0] == '\0') continue;
if (s[0] == '[') {
/* Read name of section. */
@@ -240,7 +267,7 @@ config_ini_init(config_ini_state_t *state, const char *filepath)
config_ini_free(state);
return -1;
}
-
+
/* Insert into section list. */
setting->name = NULL;
setting->value = NULL;