mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Optimization of ini files load.
Some ini files (keymaps, skins) are loaded in read-only mode. For those files, we don't need load and keep comments. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
5e136a8981
commit
260bd9742d
@ -184,9 +184,9 @@ 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, FALSE);
|
||||
return mc_config_read_file (fhl->config, filename, TRUE, FALSE);
|
||||
|
||||
fhl->config = mc_config_init (filename);
|
||||
fhl->config = mc_config_init (filename, TRUE);
|
||||
return (fhl->config != NULL);
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@ extern mc_config_t *mc_panels_config;
|
||||
|
||||
/* mcconfig/common.c: */
|
||||
|
||||
mc_config_t *mc_config_init (const gchar *);
|
||||
void mc_config_deinit (mc_config_t *);
|
||||
mc_config_t *mc_config_init (const gchar * ini_path, gboolean read_only);
|
||||
void mc_config_deinit (mc_config_t * mc_config);
|
||||
|
||||
gboolean mc_config_del_key (mc_config_t *, const char *, const gchar *);
|
||||
gboolean mc_config_del_group (mc_config_t *, const char *);
|
||||
@ -38,7 +38,7 @@ gboolean mc_config_del_group (mc_config_t *, const char *);
|
||||
gboolean mc_config_has_param (const 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 * mc_config, const gchar * ini_path,
|
||||
gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only,
|
||||
gboolean remove_empty);
|
||||
|
||||
gboolean mc_config_save_file (mc_config_t * config, GError ** error);
|
||||
|
@ -102,7 +102,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
mc_config_t *
|
||||
mc_config_init (const gchar * ini_path)
|
||||
mc_config_init (const gchar * ini_path, gboolean read_only)
|
||||
{
|
||||
mc_config_t *mc_config;
|
||||
struct stat st;
|
||||
@ -128,8 +128,13 @@ mc_config_init (const gchar * ini_path)
|
||||
vpath = vfs_path_from_str (ini_path);
|
||||
if (mc_stat (vpath, &st) == 0 && st.st_size != 0)
|
||||
{
|
||||
GKeyFileFlags flags = G_KEY_FILE_NONE;
|
||||
|
||||
if (!read_only)
|
||||
flags |= G_KEY_FILE_KEEP_COMMENTS;
|
||||
|
||||
/* file exists and not empty */
|
||||
g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
g_key_file_load_from_file (mc_config->handle, ini_path, flags, NULL);
|
||||
}
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
@ -207,7 +212,8 @@ 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, gboolean remove_empty)
|
||||
mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only,
|
||||
gboolean remove_empty)
|
||||
{
|
||||
mc_config_t *tmp_config;
|
||||
gchar **groups, **curr_grp;
|
||||
@ -217,7 +223,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
|
||||
if (mc_config == NULL)
|
||||
return FALSE;
|
||||
|
||||
tmp_config = mc_config_init (ini_path);
|
||||
tmp_config = mc_config_init (ini_path, read_only);
|
||||
if (tmp_config == NULL)
|
||||
return FALSE;
|
||||
|
||||
|
@ -281,7 +281,7 @@ mc_deserialize_config (const char *data, GError ** error)
|
||||
{
|
||||
char *current_group = NULL, *current_param = NULL, *current_value = NULL;
|
||||
size_t current_position = 0;
|
||||
mc_config_t *ret_data = mc_config_init (NULL);
|
||||
mc_config_t *ret_data;
|
||||
enum automat_status
|
||||
{
|
||||
WAIT_GROUP,
|
||||
@ -289,6 +289,8 @@ mc_deserialize_config (const char *data, GError ** error)
|
||||
WAIT_VALUE
|
||||
} current_status = WAIT_GROUP;
|
||||
|
||||
ret_data = mc_config_init (NULL, FALSE);
|
||||
|
||||
while (data != NULL)
|
||||
{
|
||||
if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL))
|
||||
|
@ -51,7 +51,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
|
||||
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL);
|
||||
if (exist_file (file_name))
|
||||
{
|
||||
mc_skin->config = mc_config_init (file_name);
|
||||
mc_skin->config = mc_config_init (file_name, TRUE);
|
||||
g_free (file_name);
|
||||
return (mc_skin->config != NULL);
|
||||
}
|
||||
@ -63,7 +63,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
|
||||
|
||||
if (exist_file (file_name))
|
||||
{
|
||||
mc_skin->config = mc_config_init (file_name);
|
||||
mc_skin->config = mc_config_init (file_name, TRUE);
|
||||
g_free (file_name);
|
||||
return (mc_skin->config != NULL);
|
||||
}
|
||||
@ -89,7 +89,7 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
|
||||
g_free (file_name);
|
||||
if (!g_path_is_absolute (mc_skin->name))
|
||||
return FALSE;
|
||||
mc_skin->config = mc_config_init (mc_skin->name);
|
||||
mc_skin->config = mc_config_init (mc_skin->name, TRUE);
|
||||
return (mc_skin->config != NULL);
|
||||
}
|
||||
g_free (file_name);
|
||||
@ -127,7 +127,7 @@ mc_skin_ini_file_parse (mc_skin_t * mc_skin)
|
||||
void
|
||||
mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin)
|
||||
{
|
||||
mc_skin->config = mc_config_init (NULL);
|
||||
mc_skin->config = mc_config_init (NULL, TRUE);
|
||||
|
||||
mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin");
|
||||
|
||||
|
@ -1064,7 +1064,7 @@ vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element)
|
||||
char *
|
||||
vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
|
||||
{
|
||||
mc_config_t *cpath = mc_config_init (NULL);
|
||||
mc_config_t *cpath;
|
||||
ssize_t element_index;
|
||||
char *ret_value;
|
||||
|
||||
@ -1074,6 +1074,9 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
cpath = mc_config_init (NULL, FALSE);
|
||||
|
||||
for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++)
|
||||
{
|
||||
char *groupname;
|
||||
@ -1117,10 +1120,11 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
|
||||
vfs_path_t *
|
||||
vfs_path_deserialize (const char *data, GError ** error)
|
||||
{
|
||||
mc_config_t *cpath = mc_deserialize_config (data, error);
|
||||
mc_config_t *cpath;
|
||||
size_t element_index = 0;
|
||||
vfs_path_t *vpath;
|
||||
|
||||
cpath = mc_deserialize_config (data, error);
|
||||
if (cpath == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -166,7 +166,7 @@ dlg_read_history (Dlg_head * h)
|
||||
return;
|
||||
|
||||
profile = mc_config_get_full_path (MC_HISTORY_FILE);
|
||||
event_data.cfg = mc_config_init (profile);
|
||||
event_data.cfg = mc_config_init (profile, TRUE);
|
||||
event_data.receiver = NULL;
|
||||
|
||||
/* create all histories in dialog */
|
||||
@ -1202,7 +1202,7 @@ dlg_save_history (Dlg_head * h)
|
||||
{
|
||||
ev_history_load_save_t event_data;
|
||||
|
||||
event_data.cfg = mc_config_init (profile);
|
||||
event_data.cfg = mc_config_init (profile, FALSE);
|
||||
event_data.receiver = NULL;
|
||||
|
||||
/* get all histories in dialog */
|
||||
|
@ -151,7 +151,7 @@ history_get (const char *input_name)
|
||||
return NULL;
|
||||
|
||||
profile = mc_config_get_full_path (MC_HISTORY_FILE);
|
||||
cfg = mc_config_init (profile);
|
||||
cfg = mc_config_init (profile, TRUE);
|
||||
|
||||
hist = history_load (cfg, input_name);
|
||||
|
||||
|
@ -1524,7 +1524,7 @@ edit_delete_macro (WEdit * edit, int hotkey)
|
||||
}
|
||||
|
||||
macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
|
||||
macros_config = mc_config_init (macros_fname);
|
||||
macros_config = mc_config_init (macros_fname, FALSE);
|
||||
g_free (macros_fname);
|
||||
|
||||
if (macros_config == NULL)
|
||||
@ -1862,7 +1862,7 @@ edit_store_macro_cmd (WEdit * edit)
|
||||
edit_delete_macro (edit, hotkey);
|
||||
|
||||
macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
|
||||
macros_config = mc_config_init (macros_fname);
|
||||
macros_config = mc_config_init (macros_fname, FALSE);
|
||||
g_free (macros_fname);
|
||||
|
||||
if (macros_config == NULL)
|
||||
@ -1966,7 +1966,7 @@ edit_load_macro_cmd (WEdit * edit)
|
||||
(void) edit;
|
||||
|
||||
macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
|
||||
macros_config = mc_config_init (macros_fname);
|
||||
macros_config = mc_config_init (macros_fname, TRUE);
|
||||
g_free (macros_fname);
|
||||
|
||||
if (macros_config == NULL)
|
||||
|
@ -555,7 +555,7 @@ process_special_dirs (GList ** special_dirs, char *file)
|
||||
mc_config_t *cfg;
|
||||
gsize buffers_len;
|
||||
|
||||
cfg = mc_config_init (file);
|
||||
cfg = mc_config_init (file, TRUE);
|
||||
if (cfg == NULL)
|
||||
return;
|
||||
|
||||
|
@ -571,7 +571,7 @@ create_default_keymap (void)
|
||||
{
|
||||
mc_config_t *keymap;
|
||||
|
||||
keymap = mc_config_init (NULL);
|
||||
keymap = mc_config_init (NULL, TRUE);
|
||||
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN, default_main_keymap);
|
||||
create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EXT, default_main_x_keymap);
|
||||
|
28
src/setup.c
28
src/setup.c
@ -464,7 +464,7 @@ setup__move_panels_config_into_separate_file (const char *profile)
|
||||
if (!exist_file (profile))
|
||||
return;
|
||||
|
||||
tmp_cfg = mc_config_init (profile);
|
||||
tmp_cfg = mc_config_init (profile, FALSE);
|
||||
if (!tmp_cfg)
|
||||
return;
|
||||
|
||||
@ -485,7 +485,7 @@ setup__move_panels_config_into_separate_file (const char *profile)
|
||||
mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL);
|
||||
mc_config_deinit (tmp_cfg);
|
||||
|
||||
tmp_cfg = mc_config_init (profile);
|
||||
tmp_cfg = mc_config_init (profile, FALSE);
|
||||
if (!tmp_cfg)
|
||||
{
|
||||
g_strfreev (groups);
|
||||
@ -516,7 +516,7 @@ setup__move_panels_config_into_separate_file (const char *profile)
|
||||
*/
|
||||
|
||||
static void
|
||||
load_setup_init_config_from_file (mc_config_t ** config, const char *fname)
|
||||
load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only)
|
||||
{
|
||||
/*
|
||||
TODO: IMHO, in future, this function shall be placed in mcconfig module.
|
||||
@ -524,9 +524,9 @@ 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, TRUE);
|
||||
mc_config_read_file (*config, fname, read_only, TRUE);
|
||||
else
|
||||
*config = mc_config_init (fname);
|
||||
*config = mc_config_init (fname, read_only);
|
||||
}
|
||||
}
|
||||
|
||||
@ -691,11 +691,11 @@ load_setup_get_keymap_profile_config (gboolean load_from_file)
|
||||
|
||||
/* 1) /usr/share/mc (mc_global.share_data_dir) */
|
||||
share_keymap = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
|
||||
load_setup_init_config_from_file (&keymap_config, share_keymap);
|
||||
load_setup_init_config_from_file (&keymap_config, share_keymap, TRUE);
|
||||
|
||||
/* 2) /etc/mc (mc_global.sysconfig_dir) */
|
||||
sysconfig_keymap = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
|
||||
load_setup_init_config_from_file (&keymap_config, sysconfig_keymap);
|
||||
load_setup_init_config_from_file (&keymap_config, sysconfig_keymap, TRUE);
|
||||
|
||||
/* then load and merge one of user-defined keymap */
|
||||
|
||||
@ -703,7 +703,7 @@ load_setup_get_keymap_profile_config (gboolean load_from_file)
|
||||
fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
|
||||
if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
|
||||
{
|
||||
load_setup_init_config_from_file (&keymap_config, fname);
|
||||
load_setup_init_config_from_file (&keymap_config, fname, TRUE);
|
||||
goto done;
|
||||
}
|
||||
g_free (fname);
|
||||
@ -712,7 +712,7 @@ load_setup_get_keymap_profile_config (gboolean load_from_file)
|
||||
fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
|
||||
if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
|
||||
{
|
||||
load_setup_init_config_from_file (&keymap_config, fname);
|
||||
load_setup_init_config_from_file (&keymap_config, fname, TRUE);
|
||||
goto done;
|
||||
}
|
||||
g_free (fname);
|
||||
@ -724,14 +724,14 @@ load_setup_get_keymap_profile_config (gboolean load_from_file)
|
||||
g_free (fname2);
|
||||
if (fname != NULL && strcmp (fname, sysconfig_keymap) != 0 && strcmp (fname, share_keymap) != 0)
|
||||
{
|
||||
load_setup_init_config_from_file (&keymap_config, fname);
|
||||
load_setup_init_config_from_file (&keymap_config, fname, TRUE);
|
||||
goto done;
|
||||
}
|
||||
g_free (fname);
|
||||
|
||||
/* 6) ${XDG_CONFIG_HOME}/mc/mc.keymap */
|
||||
fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
|
||||
load_setup_init_config_from_file (&keymap_config, fname);
|
||||
load_setup_init_config_from_file (&keymap_config, fname, TRUE);
|
||||
|
||||
done:
|
||||
g_free (fname);
|
||||
@ -890,12 +890,12 @@ load_setup (void)
|
||||
|
||||
panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
|
||||
|
||||
mc_main_config = mc_config_init (profile);
|
||||
mc_main_config = mc_config_init (profile, FALSE);
|
||||
|
||||
if (!exist_file (panels_profile_name))
|
||||
setup__move_panels_config_into_separate_file (profile);
|
||||
|
||||
mc_panels_config = mc_config_init (panels_profile_name);
|
||||
mc_panels_config = mc_config_init (panels_profile_name, FALSE);
|
||||
|
||||
/* Load integer boolean options */
|
||||
for (i = 0; int_options[i].opt_name != NULL; i++)
|
||||
@ -1154,7 +1154,7 @@ load_key_defs (void)
|
||||
*/
|
||||
mc_config_t *mc_global_config;
|
||||
|
||||
mc_global_config = mc_config_init (global_profile_name);
|
||||
mc_global_config = mc_config_init (global_profile_name, FALSE);
|
||||
if (mc_global_config != NULL)
|
||||
{
|
||||
load_keys_from_section ("general", mc_global_config);
|
||||
|
@ -69,7 +69,7 @@ START_TEST (create_ini_file)
|
||||
ini_filename = g_build_filename(WORKDIR, "test-create_ini_file.ini",NULL);
|
||||
unlink(ini_filename);
|
||||
|
||||
mc_config = mc_config_init (ini_filename);
|
||||
mc_config = mc_config_init (ini_filename, FALSE);
|
||||
if (mc_config == NULL)
|
||||
{
|
||||
fail("unable to create mc_congif_t object!");
|
||||
@ -91,7 +91,7 @@ START_TEST (create_ini_file)
|
||||
}
|
||||
|
||||
mc_config_deinit (mc_config);
|
||||
mc_config = mc_config_init (ini_filename);
|
||||
mc_config = mc_config_init (ini_filename, FALSE);
|
||||
|
||||
actual_value = mc_config_get_string(mc_config, "group-not-exists", "param-not_exists", NULL);
|
||||
fail_unless(actual_value == NULL, "return value for nonexistent ini-parameters isn't NULL (default value)!");
|
||||
@ -139,7 +139,7 @@ START_TEST (emulate__learn_save)
|
||||
ini_filename = g_build_filename(WORKDIR, "test-emulate__learn_save.ini",NULL);
|
||||
unlink(ini_filename);
|
||||
|
||||
mc_config = mc_config_init (ini_filename);
|
||||
mc_config = mc_config_init (ini_filename, FALSE);
|
||||
if (mc_config == NULL)
|
||||
{
|
||||
fail("unable to create mc_congif_t object!");
|
||||
@ -157,7 +157,7 @@ START_TEST (emulate__learn_save)
|
||||
}
|
||||
|
||||
mc_config_deinit (mc_config);
|
||||
mc_config = mc_config_init (ini_filename);
|
||||
mc_config = mc_config_init (ini_filename, FALSE);
|
||||
|
||||
actual_value = mc_config_get_string_raw( mc_config, "test-group1", "test-param1", "not-exists");
|
||||
fail_unless_strcmp("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
|
||||
|
@ -117,7 +117,7 @@ START_TEST (test_serialize_config)
|
||||
GError *error = NULL;
|
||||
char *actual;
|
||||
|
||||
test_data = mc_config_init (NULL);
|
||||
test_data = mc_config_init (NULL, FALSE);
|
||||
|
||||
mc_config_set_string_raw (test_data, "group1", "param1", "some value");
|
||||
mc_config_set_string (test_data, "group1", "param2", "some value ");
|
||||
|
Loading…
Reference in New Issue
Block a user