mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-22 03:02:06 +03:00
(mc_config_get_keys): optimization of function itself and usage.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
dbf405d290
commit
e62906473b
@ -51,7 +51,7 @@ gboolean mc_config_save_to_file (mc_config_t * config, const gchar * filename, G
|
||||
|
||||
gchar **mc_config_get_groups (const mc_config_t *, gsize *);
|
||||
|
||||
gchar **mc_config_get_keys (const mc_config_t *, const gchar *, gsize *);
|
||||
gchar **mc_config_get_keys (const mc_config_t * mc_config, const gchar * group, gsize * len);
|
||||
|
||||
gchar *mc_config_get_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
||||
|
||||
|
@ -216,7 +216,6 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
|
||||
{
|
||||
mc_config_t *tmp_config;
|
||||
gchar **groups, **curr_grp;
|
||||
gchar **keys, **curr_key;
|
||||
gchar *value;
|
||||
|
||||
if (mc_config == NULL)
|
||||
@ -236,7 +235,10 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
|
||||
|
||||
for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
|
||||
{
|
||||
gchar **keys, **curr_key;
|
||||
|
||||
keys = mc_config_get_keys (tmp_config, *curr_grp, NULL);
|
||||
|
||||
for (curr_key = keys; *curr_key != NULL; curr_key++)
|
||||
{
|
||||
value = g_key_file_get_value (tmp_config->handle, *curr_grp, *curr_key, NULL);
|
||||
|
@ -63,20 +63,18 @@ 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 **ret;
|
||||
gchar **ret = NULL;
|
||||
|
||||
if (!mc_config || !group)
|
||||
if (mc_config != NULL && group != NULL)
|
||||
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
|
||||
|
||||
if (ret == NULL)
|
||||
{
|
||||
ret = g_try_malloc0 (sizeof (gchar **));
|
||||
if (len != NULL)
|
||||
*len = 0;
|
||||
return ret;
|
||||
}
|
||||
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
|
||||
if (ret == NULL)
|
||||
{
|
||||
ret = g_try_malloc0 (sizeof (gchar **));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,6 @@ mc_serialize_config (const mc_config_t * data, GError ** error)
|
||||
{
|
||||
char *serialized_str;
|
||||
gchar **params, **param_iterator;
|
||||
size_t param_count;
|
||||
|
||||
serialized_str = mc_serialize_str ('g', *group_iterator, error);
|
||||
if (serialized_str == NULL)
|
||||
@ -218,11 +217,12 @@ mc_serialize_config (const mc_config_t * data, GError ** error)
|
||||
g_string_append (buffer, serialized_str);
|
||||
g_free (serialized_str);
|
||||
|
||||
param_iterator = params = mc_config_get_keys (data, *group_iterator, ¶m_count);
|
||||
params = mc_config_get_keys (data, *group_iterator, NULL);
|
||||
|
||||
while (param_count-- != 0)
|
||||
for (param_iterator = params; *param_iterator != NULL; param_iterator++)
|
||||
{
|
||||
char *value;
|
||||
|
||||
serialized_str = mc_serialize_str ('p', *param_iterator, error);
|
||||
if (serialized_str == NULL)
|
||||
{
|
||||
@ -248,8 +248,6 @@ mc_serialize_config (const mc_config_t * data, GError ** error)
|
||||
|
||||
g_string_append (buffer, serialized_str);
|
||||
g_free (serialized_str);
|
||||
|
||||
param_iterator++;
|
||||
}
|
||||
|
||||
g_strfreev (params);
|
||||
|
@ -302,7 +302,6 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
|
||||
{
|
||||
gsize items_count;
|
||||
gchar **groups, **orig_groups;
|
||||
gchar **keys, **orig_keys;
|
||||
mc_skin_color_t *mc_skin_color;
|
||||
|
||||
mc_skin_color_check_bw_mode (mc_skin);
|
||||
@ -325,14 +324,14 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
|
||||
|
||||
for (; *groups != NULL; groups++)
|
||||
{
|
||||
gchar **keys, **orig_keys;
|
||||
|
||||
if (!mc_skin_color_check_inisection (*groups))
|
||||
continue;
|
||||
|
||||
orig_keys = keys = mc_config_get_keys (mc_skin->config, *groups, &items_count);
|
||||
if (keys == NULL)
|
||||
continue;
|
||||
orig_keys = mc_config_get_keys (mc_skin->config, *groups, NULL);
|
||||
|
||||
for (; *keys != NULL; keys++)
|
||||
for (keys = orig_keys; *keys != NULL; keys++)
|
||||
{
|
||||
mc_skin_color = mc_skin_color_get_from_ini_file (mc_skin, *groups, *keys);
|
||||
if (mc_skin_color != NULL)
|
||||
|
@ -1921,7 +1921,7 @@ edit_load_macro_cmd (WEdit * edit)
|
||||
mc_config_t *macros_config = NULL;
|
||||
gchar **profile_keys, **keys;
|
||||
gchar **values, **curr_values;
|
||||
gsize len, values_len;
|
||||
gsize values_len;
|
||||
const char *section_name = "editor";
|
||||
gchar *macros_fname;
|
||||
|
||||
@ -1934,7 +1934,8 @@ edit_load_macro_cmd (WEdit * edit)
|
||||
if (macros_config == NULL || macros_list == NULL || macros_list->len != 0)
|
||||
return FALSE;
|
||||
|
||||
keys = mc_config_get_keys (macros_config, section_name, &len);
|
||||
keys = mc_config_get_keys (macros_config, section_name, NULL);
|
||||
|
||||
for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
|
||||
{
|
||||
int hotkey;
|
||||
|
@ -1159,33 +1159,28 @@ static void
|
||||
load_group (struct hotlist *grp)
|
||||
{
|
||||
gchar **profile_keys, **keys;
|
||||
gsize len;
|
||||
char *group_section;
|
||||
struct hotlist *current = 0;
|
||||
|
||||
group_section = find_group_section (grp);
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (mc_main_config, group_section, &len);
|
||||
keys = mc_config_get_keys (mc_main_config, group_section, NULL);
|
||||
|
||||
current_group = grp;
|
||||
|
||||
while (*profile_keys != NULL)
|
||||
{
|
||||
for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
|
||||
add2hotlist (mc_config_get_string (mc_main_config, group_section, *profile_keys, ""),
|
||||
g_strdup (*profile_keys), HL_TYPE_GROUP, LISTBOX_APPEND_AT_END);
|
||||
profile_keys++;
|
||||
}
|
||||
|
||||
g_free (group_section);
|
||||
g_strfreev (keys);
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (mc_main_config, grp->directory, &len);
|
||||
keys = mc_config_get_keys (mc_main_config, grp->directory, NULL);
|
||||
|
||||
while (*profile_keys != NULL)
|
||||
{
|
||||
for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
|
||||
add2hotlist (mc_config_get_string (mc_main_config, group_section, *profile_keys, ""),
|
||||
g_strdup (*profile_keys), HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
|
||||
profile_keys++;
|
||||
}
|
||||
|
||||
g_strfreev (keys);
|
||||
|
||||
for (current = grp->head; current; current = current->next)
|
||||
@ -1392,7 +1387,6 @@ static void
|
||||
clean_up_hotlist_groups (const char *section)
|
||||
{
|
||||
char *grp_section;
|
||||
gsize len;
|
||||
|
||||
grp_section = g_strconcat (section, ".Group", (char *) NULL);
|
||||
if (mc_config_has_group (mc_main_config, section))
|
||||
@ -1402,13 +1396,11 @@ clean_up_hotlist_groups (const char *section)
|
||||
{
|
||||
char **profile_keys, **keys;
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (mc_main_config, grp_section, &len);
|
||||
keys = mc_config_get_keys (mc_main_config, grp_section, NULL);
|
||||
|
||||
while (*profile_keys != NULL)
|
||||
{
|
||||
for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
|
||||
clean_up_hotlist_groups (*profile_keys);
|
||||
profile_keys++;
|
||||
}
|
||||
|
||||
g_strfreev (keys);
|
||||
mc_config_del_group (mc_main_config, grp_section);
|
||||
}
|
||||
|
@ -560,13 +560,12 @@ void
|
||||
load_panelize (void)
|
||||
{
|
||||
char **keys;
|
||||
gsize len;
|
||||
|
||||
keys = mc_config_get_keys (mc_main_config, panelize_section, &len);
|
||||
keys = mc_config_get_keys (mc_main_config, panelize_section, NULL);
|
||||
|
||||
add2panelize (g_strdup (_("Other command")), g_strdup (""));
|
||||
|
||||
if (keys == NULL || *keys == NULL)
|
||||
if (*keys == NULL)
|
||||
{
|
||||
add2panelize (g_strdup (_("Modified git files")), g_strdup ("git ls-files --modified"));
|
||||
add2panelize (g_strdup (_("Find rejects after patching")),
|
||||
|
16
src/setup.c
16
src/setup.c
@ -627,15 +627,15 @@ load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
gchar **values, **curr_values;
|
||||
char *valcopy, *value;
|
||||
long key_code;
|
||||
gsize len, values_len;
|
||||
gsize values_len;
|
||||
|
||||
if (terminal == NULL)
|
||||
return;
|
||||
|
||||
section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
|
||||
profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
|
||||
keys = mc_config_get_keys (cfg, section_name, NULL);
|
||||
|
||||
while (*profile_keys != NULL)
|
||||
for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
|
||||
{
|
||||
/* copy=other causes all keys from [terminal:other] to be loaded. */
|
||||
if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
|
||||
@ -643,7 +643,6 @@ load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
|
||||
load_keys_from_section (valcopy, cfg);
|
||||
g_free (valcopy);
|
||||
profile_keys++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -674,7 +673,6 @@ load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
}
|
||||
}
|
||||
|
||||
profile_keys++;
|
||||
g_strfreev (values);
|
||||
}
|
||||
g_strfreev (keys);
|
||||
@ -687,16 +685,16 @@ static void
|
||||
load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
|
||||
{
|
||||
gchar **profile_keys, **keys;
|
||||
gsize len;
|
||||
|
||||
if (section_name == NULL)
|
||||
return;
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
|
||||
keys = mc_config_get_keys (cfg, section_name, NULL);
|
||||
|
||||
while (*profile_keys != NULL)
|
||||
for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
|
||||
{
|
||||
gchar **values, **curr_values;
|
||||
gsize len;
|
||||
|
||||
curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
|
||||
|
||||
@ -714,8 +712,6 @@ load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t
|
||||
|
||||
g_strfreev (values);
|
||||
}
|
||||
|
||||
profile_keys++;
|
||||
}
|
||||
|
||||
g_strfreev (keys);
|
||||
|
Loading…
Reference in New Issue
Block a user