mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-04 22:11:07 +01:00
Unify config file search order Linux/Unix and Windows #69
This means we have some XDG support on Windows, too, although some global locations like /etc/xdg are unlikely to exist.
This commit is contained in:
parent
68098e4480
commit
d952bd6eea
58
src/boxes.c
58
src/boxes.c
@ -264,47 +264,9 @@ static char *exe_to_cfg()
|
||||
return exepath;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static char *determine_config_file()
|
||||
{
|
||||
int error_printed = 0;
|
||||
char *result = locate_config_common(&error_printed);
|
||||
|
||||
if (result == NULL && !error_printed) {
|
||||
const char *dirs[] = {
|
||||
".",
|
||||
from_env_var("HOME", "")
|
||||
};
|
||||
for (size_t i = 0; i < (sizeof(dirs) / sizeof(const char *)); i++) {
|
||||
const char *dir = dirs[i];
|
||||
if (can_read_dir(dir)) {
|
||||
result = locate_config_in_dir(dir);
|
||||
if (result != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result == NULL) { // TODO same determine_config_file(), but globalconf_marker triggers different things
|
||||
char *exepath = exe_to_cfg();
|
||||
if (can_read_file(exepath)) {
|
||||
result = exepath;
|
||||
} else {
|
||||
fprintf(stderr, "%s: Couldn\'t find config file at \'%s\'\n", PROJECT, exepath);
|
||||
error_printed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result == NULL && !error_printed) {
|
||||
fprintf(stderr, "%s: Can't find config file.\n", PROJECT);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static char *determine_config_file()
|
||||
{
|
||||
int error_printed = 0;
|
||||
@ -323,8 +285,20 @@ static char *determine_config_file()
|
||||
};
|
||||
for (size_t i = 0; i < (sizeof(dirs) / sizeof(const char *)); i++) {
|
||||
const char *dir = dirs[i];
|
||||
if (dir == globalconf_marker && can_read_file(GLOBALCONF)) {
|
||||
result = strdup(GLOBALCONF);
|
||||
if (dir == globalconf_marker) {
|
||||
#ifdef __MINGW32__
|
||||
char *exepath = exe_to_cfg();
|
||||
if (can_read_file(exepath)) {
|
||||
result = exepath;
|
||||
} else {
|
||||
fprintf(stderr, "%s: Couldn\'t find config file at \'%s\'\n", PROJECT, exepath);
|
||||
error_printed = 1;
|
||||
}
|
||||
#else
|
||||
if (can_read_file(GLOBALCONF)) {
|
||||
result = strdup(GLOBALCONF);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (can_read_dir(dir)) {
|
||||
result = locate_config_in_dir(dir);
|
||||
@ -341,8 +315,6 @@ static char *determine_config_file()
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static int open_yy_config_file(const char *config_file_name)
|
||||
|
@ -2,8 +2,6 @@
|
||||
Tests that the config file is found by looking in $HOME/.config/boxes.
|
||||
Also tests a shape length problem, where the least common multiple must be found (here: 3 x 5 = 15).
|
||||
|
||||
:SKIP-IF
|
||||
Msys
|
||||
:ENV
|
||||
export HOME="`pwd`/123_data"
|
||||
:ARGS
|
||||
|
@ -2,8 +2,6 @@
|
||||
Tests that the config file is found by looking in $XDG_CONFIG_HOME/boxes with higher precedence
|
||||
than $HOME/.config/boxes. Also tests a particular shape length problem.
|
||||
|
||||
:SKIP-IF
|
||||
Msys
|
||||
:ENV
|
||||
export HOME="`pwd`/124_data/home"
|
||||
export XDG_CONFIG_HOME="`pwd`/124_data/xdg"
|
||||
|
Loading…
Reference in New Issue
Block a user