From 68b665a49d9749c37d03394c02c385666f536753 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 6 Jan 2014 16:02:58 +0100 Subject: [PATCH] Move config file loading to config.c --- config.c | 26 ++++++++++++++++++++++---- config.h | 5 +---- print.c | 4 ++-- zathura.c | 21 +-------------------- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/config.c b/config.c index aea58d1..e1faa6c 100644 --- a/config.c +++ b/config.c @@ -15,8 +15,12 @@ #include #include #include +#include #include +#define GLOBAL_RC "/etc/zathurarc" +#define ZATHURA_RC "zathurarc" + static void cb_jumplist_change(girara_session_t* session, const char* name, girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) @@ -454,11 +458,25 @@ config_load_default(zathura_t* zathura) } void -config_load_file(zathura_t* zathura, const char* path) +config_load_files(zathura_t* zathura) { - if (zathura == NULL || path == NULL) { - return; + /* load global configuration files */ + char* config_path = girara_get_xdg_path(XDG_CONFIG_DIRS); + girara_list_t* config_dirs = girara_split_path_array(config_path); + ssize_t size = girara_list_size(config_dirs) - 1; + for (; size >= 0; --size) { + const char* dir = girara_list_nth(config_dirs, size); + char* file = g_build_filename(dir, ZATHURA_RC, NULL); + girara_config_parse(zathura->ui.session, file); + g_free(file); } + girara_list_free(config_dirs); + g_free(config_path); - girara_config_parse(zathura->ui.session, path); + girara_config_parse(zathura->ui.session, GLOBAL_RC); + + /* load local configuration files */ + char* configuration_file = g_build_filename(zathura->config.config_dir, ZATHURA_RC, NULL); + girara_config_parse(zathura->ui.session, configuration_file); + g_free(configuration_file); } diff --git a/config.h b/config.h index 1d107c6..833cfd5 100644 --- a/config.h +++ b/config.h @@ -3,9 +3,6 @@ #ifndef CONFIG_H #define CONFIG_H -#define GLOBAL_RC "/etc/zathurarc" -#define ZATHURA_RC "zathurarc" - #include "zathura.h" /** @@ -21,6 +18,6 @@ void config_load_default(zathura_t* zathura); * @param zathura The zathura session * @param path Path to the configuration file */ -void config_load_file(zathura_t* zathura, const char* path); +void config_load_files(zathura_t* zathura); #endif // CONFIG_H diff --git a/print.c b/print.c index 454512e..d1d6e3d 100644 --- a/print.c +++ b/print.c @@ -168,8 +168,8 @@ cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext* static void cb_print_request_page_setup(GtkPrintOperation* UNUSED(print_operation), - GtkPrintContext* UNUSED(context), gint page_number, GtkPageSetup* setup, - zathura_t* zathura) + GtkPrintContext* UNUSED(context), gint page_number, + GtkPageSetup* setup, zathura_t* zathura) { if (zathura == NULL || zathura->document == NULL) { return; diff --git a/zathura.c b/zathura.c index 67b7a5d..dcfca92 100644 --- a/zathura.c +++ b/zathura.c @@ -101,26 +101,7 @@ zathura_init(zathura_t* zathura) /* configuration */ config_load_default(zathura); - - /* load global configuration files */ - char* config_path = girara_get_xdg_path(XDG_CONFIG_DIRS); - girara_list_t* config_dirs = girara_split_path_array(config_path); - ssize_t size = girara_list_size(config_dirs) - 1; - for (; size >= 0; --size) { - const char* dir = girara_list_nth(config_dirs, size); - char* file = g_build_filename(dir, ZATHURA_RC, NULL); - config_load_file(zathura, file); - g_free(file); - } - girara_list_free(config_dirs); - g_free(config_path); - - config_load_file(zathura, GLOBAL_RC); - - /* load local configuration files */ - char* configuration_file = g_build_filename(zathura->config.config_dir, ZATHURA_RC, NULL); - config_load_file(zathura, configuration_file); - g_free(configuration_file); + config_load_files(zathura); /* UI */ if (girara_session_init(zathura->ui.session, "zathura") == false) {