src/setup.c: use macros in keymap load/set/free functions.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-03-14 13:07:39 +03:00
parent 2f22ce9434
commit 2ba413333b

View File

@ -1350,82 +1350,64 @@ load_keymap_defs (gboolean load_from_file)
if (mc_global_keymap != NULL) if (mc_global_keymap != NULL)
{ {
main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); #define LOAD_KEYMAP(s,km) \
load_keymap_from_section (KEYMAP_SECTION_MAIN, main_keymap, mc_global_keymap); km##_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); \
main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); load_keymap_from_section (KEYMAP_SECTION_##s, km##_keymap, mc_global_keymap)
load_keymap_from_section (KEYMAP_SECTION_MAIN_EXT, main_x_keymap, mc_global_keymap);
panel_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_PANEL, panel_keymap, mc_global_keymap);
dialog_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_DIALOG, dialog_keymap, mc_global_keymap);
menu_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_MENU, menu_keymap, mc_global_keymap);
input_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_INPUT, input_keymap, mc_global_keymap);
listbox_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_LISTBOX, listbox_keymap, mc_global_keymap);
radio_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_RADIO, radio_keymap, mc_global_keymap);
tree_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_TREE, tree_keymap, mc_global_keymap);
help_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_HELP, help_keymap, mc_global_keymap);
LOAD_KEYMAP (MAIN, main);
LOAD_KEYMAP (MAIN_EXT, main_x);
LOAD_KEYMAP (PANEL, panel);
LOAD_KEYMAP (DIALOG, dialog);
LOAD_KEYMAP (MENU, menu);
LOAD_KEYMAP (INPUT, input);
LOAD_KEYMAP (LISTBOX, listbox);
LOAD_KEYMAP (RADIO, radio);
LOAD_KEYMAP (TREE, tree);
LOAD_KEYMAP (HELP, help);
#ifdef ENABLE_EXT2FS_ATTR #ifdef ENABLE_EXT2FS_ATTR
chattr_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); LOAD_KEYMAP (CHATTR, chattr);
load_keymap_from_section (KEYMAP_SECTION_CHATTR, chattr_keymap, mc_global_keymap);
#endif #endif
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT
editor_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); LOAD_KEYMAP (EDITOR, editor);
load_keymap_from_section (KEYMAP_SECTION_EDITOR, editor_keymap, mc_global_keymap); LOAD_KEYMAP (EDITOR_EXT, editor_x);
editor_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_EDITOR_EXT, editor_x_keymap, mc_global_keymap);
#endif #endif
LOAD_KEYMAP (VIEWER, viewer);
viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); LOAD_KEYMAP (VIEWER_HEX, viewer_hex);
load_keymap_from_section (KEYMAP_SECTION_VIEWER, viewer_keymap, mc_global_keymap);
viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section (KEYMAP_SECTION_VIEWER_HEX, viewer_hex_keymap, mc_global_keymap);
#ifdef USE_DIFF_VIEW #ifdef USE_DIFF_VIEW
diff_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t)); LOAD_KEYMAP (DIFFVIEWER, diff);
load_keymap_from_section (KEYMAP_SECTION_DIFFVIEWER, diff_keymap, mc_global_keymap);
#endif #endif
#undef LOAD_KEYMAP
mc_config_deinit (mc_global_keymap); mc_config_deinit (mc_global_keymap);
} }
main_map = (global_keymap_t *) main_keymap->data; #define SET_MAP(m) \
main_x_map = (global_keymap_t *) main_x_keymap->data; m##_map = (global_keymap_t *) m##_keymap->data
panel_map = (global_keymap_t *) panel_keymap->data;
dialog_map = (global_keymap_t *) dialog_keymap->data; SET_MAP (main);
menu_map = (global_keymap_t *) menu_keymap->data; SET_MAP (main_x);
input_map = (global_keymap_t *) input_keymap->data; SET_MAP (panel);
listbox_map = (global_keymap_t *) listbox_keymap->data; SET_MAP (dialog);
radio_map = (global_keymap_t *) radio_keymap->data; SET_MAP (menu);
tree_map = (global_keymap_t *) tree_keymap->data; SET_MAP (input);
help_map = (global_keymap_t *) help_keymap->data; SET_MAP (listbox);
SET_MAP (radio);
SET_MAP (tree);
SET_MAP (help);
#ifdef ENABLE_EXT2FS_ATTR #ifdef ENABLE_EXT2FS_ATTR
chattr_map = (global_keymap_t *) chattr_keymap->data; SET_MAP (chattr);
#endif #endif
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT
editor_map = (global_keymap_t *) editor_keymap->data; SET_MAP (editor);
editor_x_map = (global_keymap_t *) editor_x_keymap->data; SET_MAP (editor_x);
#endif #endif
viewer_map = (global_keymap_t *) viewer_keymap->data; SET_MAP (viewer);
viewer_hex_map = (global_keymap_t *) viewer_hex_keymap->data; SET_MAP (viewer_hex);
#ifdef USE_DIFF_VIEW #ifdef USE_DIFF_VIEW
diff_map = (global_keymap_t *) diff_keymap->data; SET_MAP (diff);
#endif #endif
#undef SET_MAP
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -1433,44 +1415,34 @@ load_keymap_defs (gboolean load_from_file)
void void
free_keymap_defs (void) free_keymap_defs (void)
{ {
if (main_keymap != NULL) #define FREE_KEYMAP(km) \
g_array_free (main_keymap, TRUE); if (km##_keymap != NULL) \
if (main_x_keymap != NULL) g_array_free (km##_keymap, TRUE)
g_array_free (main_x_keymap, TRUE);
if (panel_keymap != NULL) FREE_KEYMAP (main);
g_array_free (panel_keymap, TRUE); FREE_KEYMAP (main_x);
if (dialog_keymap != NULL) FREE_KEYMAP (panel);
g_array_free (dialog_keymap, TRUE); FREE_KEYMAP (dialog);
if (menu_keymap != NULL) FREE_KEYMAP (menu);
g_array_free (menu_keymap, TRUE); FREE_KEYMAP (input);
if (input_keymap != NULL) FREE_KEYMAP (listbox);
g_array_free (input_keymap, TRUE); FREE_KEYMAP (radio);
if (listbox_keymap != NULL) FREE_KEYMAP (tree);
g_array_free (listbox_keymap, TRUE); FREE_KEYMAP (help);
if (radio_keymap != NULL)
g_array_free (radio_keymap, TRUE);
if (tree_keymap != NULL)
g_array_free (tree_keymap, TRUE);
if (help_keymap != NULL)
g_array_free (help_keymap, TRUE);
#ifdef ENABLE_EXT2FS_ATTR #ifdef ENABLE_EXT2FS_ATTR
if (chattr_keymap != NULL) FREE_KEYMAP (chattr);
g_array_free (chattr_keymap, TRUE);
#endif #endif
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT
if (editor_keymap != NULL) FREE_KEYMAP (editor);
g_array_free (editor_keymap, TRUE); FREE_KEYMAP (editor_x);
if (editor_x_keymap != NULL)
g_array_free (editor_x_keymap, TRUE);
#endif #endif
if (viewer_keymap != NULL) FREE_KEYMAP (viewer);
g_array_free (viewer_keymap, TRUE); FREE_KEYMAP (viewer_hex);
if (viewer_hex_keymap != NULL)
g_array_free (viewer_hex_keymap, TRUE);
#ifdef USE_DIFF_VIEW #ifdef USE_DIFF_VIEW
if (diff_keymap != NULL) FREE_KEYMAP (diff);
g_array_free (diff_keymap, TRUE);
#endif #endif
#undef FREE_KEYMAP
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */