mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-08 13:45:59 +01:00
Read global configuration file
Thanks to Sebastinas
This commit is contained in:
parent
49e4e8abe1
commit
98bf13102c
2 changed files with 40 additions and 35 deletions
|
@ -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";
|
||||||
|
|
74
zathura.c
74
zathura.c
|
@ -1365,45 +1365,49 @@ update_status()
|
||||||
g_free(zoom_level);
|
g_free(zoom_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
read_configuration_file(const char* rcfile)
|
||||||
|
{
|
||||||
|
if(!rcfile)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!g_file_test(rcfile, G_FILE_TEST_IS_REGULAR))
|
||||||
|
return;
|
||||||
|
|
||||||
|
char* content = NULL;
|
||||||
|
if(g_file_get_contents(rcfile, &content, NULL, NULL))
|
||||||
|
{
|
||||||
|
gchar **lines = g_strsplit(content, "\n", -1);
|
||||||
|
int n = g_strv_length(lines) - 1;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i <= n; i++)
|
||||||
|
{
|
||||||
|
if(!strlen(lines[i]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gchar **tokens = g_strsplit(lines[i], " ", -1);
|
||||||
|
int length = g_strv_length(tokens);
|
||||||
|
|
||||||
|
if(!strcmp(tokens[0], "set"))
|
||||||
|
cmd_set(length - 1, tokens + 1);
|
||||||
|
else if(!strcmp(tokens[0], "map"))
|
||||||
|
cmd_map(length - 1, tokens + 1);
|
||||||
|
|
||||||
|
g_strfreev(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev(lines);
|
||||||
|
g_free(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
read_configuration()
|
read_configuration()
|
||||||
{
|
{
|
||||||
char* zathurarc = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, ZATHURA_RC);
|
char* zathurarc = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, ZATHURA_RC);
|
||||||
|
read_configuration_file(GLOBAL_RC);
|
||||||
if(!zathurarc)
|
read_configuration_file(zathurarc);
|
||||||
return;
|
|
||||||
|
|
||||||
if(g_file_test(zathurarc, G_FILE_TEST_IS_REGULAR))
|
|
||||||
{
|
|
||||||
char* content = NULL;
|
|
||||||
|
|
||||||
if(g_file_get_contents(zathurarc, &content, NULL, NULL))
|
|
||||||
{
|
|
||||||
gchar **lines = g_strsplit(content, "\n", -1);
|
|
||||||
int n = g_strv_length(lines) - 1;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for(i = 0; i <= n; i++)
|
|
||||||
{
|
|
||||||
if(!strlen(lines[i]))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
gchar **tokens = g_strsplit(lines[i], " ", -1);
|
|
||||||
int length = g_strv_length(tokens);
|
|
||||||
|
|
||||||
if(!strcmp(tokens[0], "set"))
|
|
||||||
cmd_set(length - 1, tokens + 1);
|
|
||||||
else if(!strcmp(tokens[0], "map"))
|
|
||||||
cmd_map(length - 1, tokens + 1);
|
|
||||||
|
|
||||||
g_strfreev(tokens);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_strfreev(lines);
|
|
||||||
g_free(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(zathurarc);
|
g_free(zathurarc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue