mirror of https://github.com/MidnightCommander/mc
Allow remove key with empty value from target config.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
35b429f625
commit
6484b1dce7
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue