summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 64f78d3)
raw | patch | inline | side by side (parent: 64f78d3)
author | Max Kellermann <max@duempel.org> | |
Fri, 8 Nov 2013 18:41:53 +0000 (19:41 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 8 Nov 2013 18:41:53 +0000 (19:41 +0100) |
Move code to find_config_file() and find_keys_file().
src/conf.c | patch | blob | history |
diff --git a/src/conf.c b/src/conf.c
index 87dd310cb815e0ef8c68ea06f17aa9477f607467..87fa51e7a05e2b356dc9118d81f09975438bb6af 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
#endif
}
-void
-read_configuration(void)
+static char *
+find_config_file(void)
{
- char *filename = NULL;
-
/* check for command line configuration file */
- if (options.config_file)
- filename = g_strdup(options.config_file);
+ if (options.config_file != NULL)
+ return g_strdup(options.config_file);
/* check for user configuration ~/.ncmpc/config */
- if (filename == NULL) {
- filename = build_user_conf_filename();
- if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
- g_free(filename);
- filename = NULL;
- }
- }
+ char *filename = build_user_conf_filename();
+ if (g_file_test(filename, G_FILE_TEST_IS_REGULAR))
+ return filename;
+
+ g_free(filename);
/* check for global configuration SYSCONFDIR/ncmpc/config */
- if (filename == NULL) {
- filename = build_system_conf_filename();
- if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
- g_free(filename);
- filename = NULL;
- }
- }
+ filename = build_system_conf_filename();
+ if (g_file_test(filename, G_FILE_TEST_IS_REGULAR))
+ return filename;
- /* load configuration */
- if (filename) {
- read_rc_file(filename);
- g_free(filename);
- filename = NULL;
- }
+ g_free(filename);
+ return NULL;
+}
+static char *
+find_keys_file(void)
+{
/* check for command line key binding file */
- if (options.key_file)
- filename = g_strdup(options.key_file);
+ if (options.key_file != NULL)
+ return g_strdup(options.key_file);
/* check for user key bindings ~/.ncmpc/keys */
- if (filename == NULL) {
- filename = build_user_key_binding_filename();
- if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
- g_free(filename);
- filename = NULL;
- }
- }
+ char *filename = build_user_key_binding_filename();
+ if (g_file_test(filename, G_FILE_TEST_IS_REGULAR))
+ return filename;
+
+ g_free(filename);
/* check for global key bindings SYSCONFDIR/ncmpc/keys */
- if (filename == NULL) {
- filename = g_build_system_key_binding_filename();
- if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
- g_free(filename);
- filename = NULL;
- }
+ filename = g_build_system_key_binding_filename();
+ if (g_file_test(filename, G_FILE_TEST_IS_REGULAR))
+ return filename;
+
+ g_free(filename);
+ return NULL;
+}
+
+void
+read_configuration(void)
+{
+ /* load configuration */
+ char *filename = find_config_file();
+ if (filename != NULL) {
+ read_rc_file(filename);
+ g_free(filename);
}
/* load key bindings */
- if (filename) {
+ filename = find_keys_file();
+ if (filename != NULL) {
read_rc_file(filename);
g_free(filename);
- filename = NULL;
}
}