From 6484b1dce724a5743d1ca91ae82e25178e94595d Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 23 Feb 2011 15:19:37 +0300 Subject: [PATCH] Allow remove key with empty value from target config. Signed-off-by: Andrew Borodin --- lib/filehighlight/ini-file-read.c | 2 +- lib/mcconfig.h | 3 ++- lib/mcconfig/common.c | 19 +++++++++++-------- src/setup.c | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/filehighlight/ini-file-read.c b/lib/filehighlight/ini-file-read.c index 6ffcfa9f4..a82eb7e45 100644 --- a/lib/filehighlight/ini-file-read.c +++ b/lib/filehighlight/ini-file-read.c @@ -187,7 +187,7 @@ mc_fhl_read_ini_file (mc_fhl_t * fhl, const gchar * filename) return FALSE; if (fhl->config != NULL) - return mc_config_read_file (fhl->config, filename); + return mc_config_read_file (fhl->config, filename, FALSE); fhl->config = mc_config_init (filename); return (fhl->config != NULL); diff --git a/lib/mcconfig.h b/lib/mcconfig.h index 316ee498b..f3f754405 100644 --- a/lib/mcconfig.h +++ b/lib/mcconfig.h @@ -34,7 +34,8 @@ gboolean mc_config_del_group (mc_config_t *, const char *); gboolean mc_config_has_param (mc_config_t *, const char *, const gchar *); gboolean mc_config_has_group (mc_config_t *, const char *); -gboolean mc_config_read_file (mc_config_t *, const gchar *); +gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, + gboolean remove_empty); gboolean mc_config_save_file (mc_config_t * config, GError ** error); diff --git a/lib/mcconfig/common.c b/lib/mcconfig/common.c index a4c97318a..a411af0ca 100644 --- a/lib/mcconfig/common.c +++ b/lib/mcconfig/common.c @@ -194,7 +194,7 @@ mc_config_del_group (mc_config_t * mc_config, const char *group) /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ gboolean -mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path) +mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean remove_empty) { mc_config_t *tmp_config; gchar **groups, **curr_grp; @@ -202,9 +202,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path) gchar *value; if (mc_config == NULL) - { return FALSE; - } tmp_config = mc_config_init (ini_path); if (tmp_config == NULL) @@ -224,11 +222,16 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path) for (curr_key = keys; *curr_key != NULL; curr_key++) { value = g_key_file_get_value (tmp_config->handle, *curr_grp, *curr_key, NULL); - if (value == NULL) - continue; - - g_key_file_set_value (mc_config->handle, *curr_grp, *curr_key, value); - g_free (value); + if (value != NULL) + { + if (*value == '\0' && remove_empty) + g_key_file_remove_key (mc_config->handle, *curr_grp, *curr_key, NULL); + else + g_key_file_set_value (mc_config->handle, *curr_grp, *curr_key, value); + g_free (value); + } + else if (remove_empty) + g_key_file_remove_key (mc_config->handle, *curr_grp, *curr_key, NULL); } g_strfreev (keys); } diff --git a/src/setup.c b/src/setup.c index 4c9b7fb40..c32a5e935 100644 --- a/src/setup.c +++ b/src/setup.c @@ -529,7 +529,7 @@ load_setup_init_config_from_file (mc_config_t ** config, const char *fname) if (exist_file (fname)) { if (*config != NULL) - mc_config_read_file (*config, fname); + mc_config_read_file (*config, fname, TRUE); else *config = mc_config_init (fname); }