Read global configuration file

Thanks to Sebastinas
This commit is contained in:
Moritz Lipp 2010-07-22 23:27:17 +02:00
parent 49e4e8abe1
commit 98bf13102c
2 changed files with 40 additions and 35 deletions

View file

@ -17,6 +17,7 @@ static const char FORMAT_DESCRIPTION[] = "<i>%s</i>";
static const char ZATHURA_DIR[] = ".config/zathura"; static const char ZATHURA_DIR[] = ".config/zathura";
static const char BOOKMARK_FILE[] = "bookmarks"; static const char BOOKMARK_FILE[] = "bookmarks";
static const char ZATHURA_RC[] = "zathurarc"; static const char ZATHURA_RC[] = "zathurarc";
static const char GLOBAL_RC[] = "/etc/zathurarc";
/* bookmarks */ /* bookmarks */
static const char BM_PAGE_ENTRY[] = "page"; static const char BM_PAGE_ENTRY[] = "page";

View file

@ -1366,18 +1366,16 @@ update_status()
} }
void void
read_configuration() read_configuration_file(const char* rcfile)
{ {
char* zathurarc = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, ZATHURA_RC); if(!rcfile)
if(!zathurarc)
return; return;
if(g_file_test(zathurarc, G_FILE_TEST_IS_REGULAR)) if(!g_file_test(rcfile, G_FILE_TEST_IS_REGULAR))
{ return;
char* content = NULL;
if(g_file_get_contents(zathurarc, &content, NULL, NULL)) char* content = NULL;
if(g_file_get_contents(rcfile, &content, NULL, NULL))
{ {
gchar **lines = g_strsplit(content, "\n", -1); gchar **lines = g_strsplit(content, "\n", -1);
int n = g_strv_length(lines) - 1; int n = g_strv_length(lines) - 1;
@ -1402,8 +1400,14 @@ read_configuration()
g_strfreev(lines); g_strfreev(lines);
g_free(content); g_free(content);
} }
} }
void
read_configuration()
{
char* zathurarc = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, ZATHURA_RC);
read_configuration_file(GLOBAL_RC);
read_configuration_file(zathurarc);
g_free(zathurarc); g_free(zathurarc);
} }