mirror of
https://github.com/MidnightCommander/mc
synced 2025-04-02 21:22:54 +03:00
(mc_config_get_groups): optimization of function itself and usage.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
e62906473b
commit
725997c8d0
@ -225,18 +225,16 @@ gboolean
|
|||||||
mc_fhl_parse_ini_file (mc_fhl_t * fhl)
|
mc_fhl_parse_ini_file (mc_fhl_t * fhl)
|
||||||
{
|
{
|
||||||
gchar **group_names, **orig_group_names;
|
gchar **group_names, **orig_group_names;
|
||||||
|
gboolean ok;
|
||||||
|
|
||||||
mc_fhl_array_free (fhl);
|
mc_fhl_array_free (fhl);
|
||||||
fhl->filters = g_ptr_array_new ();
|
fhl->filters = g_ptr_array_new ();
|
||||||
|
|
||||||
orig_group_names = group_names = mc_config_get_groups (fhl->config, NULL);
|
orig_group_names = mc_config_get_groups (fhl->config, NULL);
|
||||||
|
ok = (*orig_group_names != NULL);
|
||||||
|
|
||||||
if (group_names == NULL)
|
for (group_names = orig_group_names; *group_names != NULL; group_names++)
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
while (*group_names)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if (mc_config_has_param (fhl->config, *group_names, "type"))
|
if (mc_config_has_param (fhl->config, *group_names, "type"))
|
||||||
{
|
{
|
||||||
/* parse filetype filter */
|
/* parse filetype filter */
|
||||||
@ -252,11 +250,11 @@ mc_fhl_parse_ini_file (mc_fhl_t * fhl)
|
|||||||
/* parse extensions filter */
|
/* parse extensions filter */
|
||||||
mc_fhl_parse_get_extensions (fhl, *group_names);
|
mc_fhl_parse_get_extensions (fhl, *group_names);
|
||||||
}
|
}
|
||||||
group_names++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (orig_group_names);
|
g_strfreev (orig_group_names);
|
||||||
return TRUE;
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -49,7 +49,7 @@ gboolean mc_config_save_to_file (mc_config_t * config, const gchar * filename, G
|
|||||||
|
|
||||||
/* mcconfig/get.c: */
|
/* mcconfig/get.c: */
|
||||||
|
|
||||||
gchar **mc_config_get_groups (const mc_config_t *, gsize *);
|
gchar **mc_config_get_groups (const mc_config_t * mc_config, gsize * len);
|
||||||
|
|
||||||
gchar **mc_config_get_keys (const mc_config_t * mc_config, const gchar * group, gsize * len);
|
gchar **mc_config_get_keys (const mc_config_t * mc_config, const gchar * group, gsize * len);
|
||||||
|
|
||||||
|
@ -217,6 +217,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
|
|||||||
mc_config_t *tmp_config;
|
mc_config_t *tmp_config;
|
||||||
gchar **groups, **curr_grp;
|
gchar **groups, **curr_grp;
|
||||||
gchar *value;
|
gchar *value;
|
||||||
|
gboolean ok;
|
||||||
|
|
||||||
if (mc_config == NULL)
|
if (mc_config == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -226,12 +227,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
groups = mc_config_get_groups (tmp_config, NULL);
|
groups = mc_config_get_groups (tmp_config, NULL);
|
||||||
|
ok = (*groups != NULL);
|
||||||
if (groups == NULL)
|
|
||||||
{
|
|
||||||
mc_config_deinit (tmp_config);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
|
for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
|
||||||
{
|
{
|
||||||
@ -255,9 +251,11 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
|
|||||||
}
|
}
|
||||||
g_strfreev (keys);
|
g_strfreev (keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (groups);
|
g_strfreev (groups);
|
||||||
mc_config_deinit (tmp_config);
|
mc_config_deinit (tmp_config);
|
||||||
return TRUE;
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
@ -41,20 +41,18 @@
|
|||||||
gchar **
|
gchar **
|
||||||
mc_config_get_groups (const mc_config_t * mc_config, gsize * len)
|
mc_config_get_groups (const mc_config_t * mc_config, gsize * len)
|
||||||
{
|
{
|
||||||
gchar **ret;
|
gchar **ret = NULL;
|
||||||
|
|
||||||
if (!mc_config)
|
if (mc_config != NULL)
|
||||||
|
ret = g_key_file_get_groups (mc_config->handle, len);
|
||||||
|
|
||||||
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
ret = g_try_malloc0 (sizeof (gchar **));
|
ret = g_try_malloc0 (sizeof (gchar **));
|
||||||
if (len != NULL)
|
if (len != NULL)
|
||||||
*len = 0;
|
*len = 0;
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ret = g_key_file_get_groups (mc_config->handle, len);
|
|
||||||
if (ret == NULL)
|
|
||||||
{
|
|
||||||
ret = g_try_malloc0 (sizeof (gchar **));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,13 +196,12 @@ char *
|
|||||||
mc_serialize_config (const mc_config_t * data, GError ** error)
|
mc_serialize_config (const mc_config_t * data, GError ** error)
|
||||||
{
|
{
|
||||||
gchar **groups, **group_iterator;
|
gchar **groups, **group_iterator;
|
||||||
size_t group_count;
|
|
||||||
GString *buffer;
|
GString *buffer;
|
||||||
|
|
||||||
buffer = g_string_new ("");
|
buffer = g_string_new ("");
|
||||||
group_iterator = groups = mc_config_get_groups (data, &group_count);
|
groups = mc_config_get_groups (data, NULL);
|
||||||
|
|
||||||
while (group_count-- != 0)
|
for (group_iterator = groups; *group_iterator != NULL; group_iterator++)
|
||||||
{
|
{
|
||||||
char *serialized_str;
|
char *serialized_str;
|
||||||
gchar **params, **param_iterator;
|
gchar **params, **param_iterator;
|
||||||
@ -251,8 +250,6 @@ mc_serialize_config (const mc_config_t * data, GError ** error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (params);
|
g_strfreev (params);
|
||||||
|
|
||||||
group_iterator++;
|
|
||||||
}
|
}
|
||||||
return g_string_free (buffer, FALSE);
|
return g_string_free (buffer, FALSE);
|
||||||
}
|
}
|
||||||
|
@ -279,17 +279,14 @@ mc_skin_color_check_bw_mode (mc_skin_t * mc_skin)
|
|||||||
if (tty_use_colors () && !mc_global.tty.disable_colors)
|
if (tty_use_colors () && !mc_global.tty.disable_colors)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
orig_groups = groups = mc_config_get_groups (mc_skin->config, NULL);
|
orig_groups = mc_config_get_groups (mc_skin->config, NULL);
|
||||||
|
|
||||||
if (groups == NULL)
|
for (groups = orig_groups; *groups != NULL; groups++)
|
||||||
return;
|
|
||||||
|
|
||||||
for (; *groups != NULL; groups++)
|
|
||||||
{
|
|
||||||
if (mc_skin_color_check_inisection (*groups))
|
if (mc_skin_color_check_inisection (*groups))
|
||||||
mc_config_del_group (mc_skin->config, *groups);
|
mc_config_del_group (mc_skin->config, *groups);
|
||||||
}
|
|
||||||
g_strfreev (orig_groups);
|
g_strfreev (orig_groups);
|
||||||
|
|
||||||
mc_skin_hardcoded_blackwhite_colors (mc_skin);
|
mc_skin_hardcoded_blackwhite_colors (mc_skin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,10 +303,10 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
|
|||||||
|
|
||||||
mc_skin_color_check_bw_mode (mc_skin);
|
mc_skin_color_check_bw_mode (mc_skin);
|
||||||
|
|
||||||
orig_groups = groups = mc_config_get_groups (mc_skin->config, &items_count);
|
orig_groups = mc_config_get_groups (mc_skin->config, &items_count);
|
||||||
if (groups == NULL || groups[0] == NULL)
|
if (*orig_groups == NULL)
|
||||||
{
|
{
|
||||||
g_strfreev (groups);
|
g_strfreev (orig_groups);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +319,7 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
|
|||||||
tty_color_set_defaults (mc_skin_color->fgcolor, mc_skin_color->bgcolor, mc_skin_color->attrs);
|
tty_color_set_defaults (mc_skin_color->fgcolor, mc_skin_color->bgcolor, mc_skin_color->attrs);
|
||||||
mc_skin_color_add_to_hash (mc_skin, "core", "_default_", mc_skin_color);
|
mc_skin_color_add_to_hash (mc_skin, "core", "_default_", mc_skin_color);
|
||||||
|
|
||||||
for (; *groups != NULL; groups++)
|
for (groups = orig_groups ; *groups != NULL; groups++)
|
||||||
{
|
{
|
||||||
gchar **keys, **orig_keys;
|
gchar **keys, **orig_keys;
|
||||||
|
|
||||||
|
21
src/setup.c
21
src/setup.c
@ -514,45 +514,38 @@ setup__move_panels_config_into_separate_file (const char *profile)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
tmp_cfg = mc_config_init (profile, FALSE);
|
tmp_cfg = mc_config_init (profile, FALSE);
|
||||||
if (!tmp_cfg)
|
if (tmp_cfg == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL);
|
groups = mc_config_get_groups (tmp_cfg, NULL);
|
||||||
if (!groups)
|
if (*groups == NULL)
|
||||||
{
|
{
|
||||||
|
g_strfreev (groups);
|
||||||
mc_config_deinit (tmp_cfg);
|
mc_config_deinit (tmp_cfg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*curr_grp)
|
for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
|
||||||
{
|
|
||||||
if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
|
if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL)
|
||||||
mc_config_del_group (tmp_cfg, *curr_grp);
|
mc_config_del_group (tmp_cfg, *curr_grp);
|
||||||
curr_grp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
|
mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
|
||||||
mc_config_deinit (tmp_cfg);
|
mc_config_deinit (tmp_cfg);
|
||||||
|
|
||||||
tmp_cfg = mc_config_init (profile, FALSE);
|
tmp_cfg = mc_config_init (profile, FALSE);
|
||||||
if (!tmp_cfg)
|
if (tmp_cfg == NULL)
|
||||||
{
|
{
|
||||||
g_strfreev (groups);
|
g_strfreev (groups);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
curr_grp = groups;
|
for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
|
||||||
|
|
||||||
while (*curr_grp)
|
|
||||||
{
|
{
|
||||||
const char *need_grp;
|
const char *need_grp;
|
||||||
|
|
||||||
need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
|
need_grp = setup__is_cfg_group_must_panel_config (*curr_grp);
|
||||||
if (need_grp != NULL)
|
if (need_grp != NULL)
|
||||||
{
|
|
||||||
mc_config_del_group (tmp_cfg, need_grp);
|
mc_config_del_group (tmp_cfg, need_grp);
|
||||||
}
|
|
||||||
curr_grp++;
|
|
||||||
}
|
}
|
||||||
g_strfreev (groups);
|
g_strfreev (groups);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user