mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-03 00:25:53 +02:00
Add global_only argument to discover_config_file()
This commit is contained in:
parent
365dcea348
commit
97a2e2d76d
@ -107,7 +107,7 @@ static void usage(FILE *st)
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*/
|
||||
{
|
||||
char *config_file = discover_config_file();
|
||||
char *config_file = discover_config_file(0);
|
||||
|
||||
fprintf(st, "Usage: %s [options] [infile [outfile]]\n", PROJECT);
|
||||
fprintf(st, " -a fmt alignment/positioning of text inside box [default: hlvt]\n");
|
||||
@ -1368,7 +1368,7 @@ int main(int argc, char *argv[])
|
||||
/*
|
||||
* Parse config file, then reset design pointer
|
||||
*/
|
||||
char *config_file = discover_config_file();
|
||||
char *config_file = discover_config_file(0);
|
||||
if (config_file == NULL) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -224,22 +224,34 @@ static char *exe_to_cfg()
|
||||
#endif
|
||||
|
||||
|
||||
char *discover_config_file()
|
||||
char *discover_config_file(const int global_only)
|
||||
{
|
||||
int error_printed = 0;
|
||||
char *result = locate_config_common(&error_printed);
|
||||
int error_printed = global_only;
|
||||
char *result = NULL;
|
||||
if (!global_only) {
|
||||
result = locate_config_common(&error_printed);
|
||||
}
|
||||
|
||||
if (result == NULL && !error_printed) {
|
||||
const char *globalconf_marker = "::GLOBALCONF::";
|
||||
const char *dirs[] = {
|
||||
const char *user_dirs[] = {
|
||||
from_env_var("HOME", ""),
|
||||
from_env_var("XDG_CONFIG_HOME", "/boxes"),
|
||||
from_env_var("HOME", "/.config/boxes"),
|
||||
from_env_var("HOME", "/.config/boxes")
|
||||
};
|
||||
const char *global_dirs[] = {
|
||||
globalconf_marker,
|
||||
"/etc/xdg/boxes",
|
||||
"/usr/local/share/boxes",
|
||||
"/usr/share/boxes"
|
||||
};
|
||||
const char *dirs[global_only ? 4 : 7];
|
||||
if (global_only) {
|
||||
memcpy(dirs, global_dirs, 4 * sizeof(char *));
|
||||
} else {
|
||||
memcpy(dirs, user_dirs, 3 * sizeof(char *));
|
||||
memcpy(dirs + 3, global_dirs, 4 * sizeof(char *));
|
||||
}
|
||||
for (size_t i = 0; i < (sizeof(dirs) / sizeof(const char *)); i++) {
|
||||
const char *dir = dirs[i];
|
||||
if (dir == globalconf_marker) {
|
||||
|
@ -26,7 +26,7 @@
|
||||
#define BOXES_DISCOVERY_H
|
||||
|
||||
|
||||
char *discover_config_file();
|
||||
char *discover_config_file(const int global_only);
|
||||
|
||||
|
||||
#endif /* BOXES_DISCOVERY_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user