1
1

Allow remove key with empty value from target config.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2011-02-23 15:19:37 +03:00
родитель 35b429f625
Коммит 6484b1dce7
4 изменённых файлов: 15 добавлений и 11 удалений

Просмотреть файл

@ -187,7 +187,7 @@ mc_fhl_read_ini_file (mc_fhl_t * fhl, const gchar * filename)
return FALSE; return FALSE;
if (fhl->config != NULL) 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); fhl->config = mc_config_init (filename);
return (fhl->config != NULL); 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_param (mc_config_t *, const char *, const gchar *);
gboolean mc_config_has_group (mc_config_t *, const char *); 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); 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 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; mc_config_t *tmp_config;
gchar **groups, **curr_grp; gchar **groups, **curr_grp;
@ -202,9 +202,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path)
gchar *value; gchar *value;
if (mc_config == NULL) if (mc_config == NULL)
{
return FALSE; return FALSE;
}
tmp_config = mc_config_init (ini_path); tmp_config = mc_config_init (ini_path);
if (tmp_config == NULL) 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++) for (curr_key = keys; *curr_key != NULL; curr_key++)
{ {
value = g_key_file_get_value (tmp_config->handle, *curr_grp, *curr_key, NULL); value = g_key_file_get_value (tmp_config->handle, *curr_grp, *curr_key, NULL);
if (value == NULL) if (value != NULL)
continue; {
if (*value == '\0' && remove_empty)
g_key_file_set_value (mc_config->handle, *curr_grp, *curr_key, value); g_key_file_remove_key (mc_config->handle, *curr_grp, *curr_key, NULL);
g_free (value); 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); 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 (exist_file (fname))
{ {
if (*config != NULL) if (*config != NULL)
mc_config_read_file (*config, fname); mc_config_read_file (*config, fname, TRUE);
else else
*config = mc_config_init (fname); *config = mc_config_init (fname);
} }