More translates of doc/man/es/mc.1.in
[midnight-commander.git] / src / setup.c
blob2da14582c9fca89a0f626c15e1456a0bb9abaa90
1 /* Setup loading/saving.
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /** \file setup.c
20 * \brief Source: setup loading/saving
23 #include <config.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
31 #include "global.h"
33 #include "../src/tty/tty.h"
34 #include "../src/tty/key.h"
35 #include "../src/tty/mouse.h" /* To make view.h happy */
37 #include "dir.h"
38 #include "panel.h"
39 #include "main.h"
40 #include "tree.h" /* xtree_mode */
41 #include "../src/mcconfig/mcconfig.h"
42 #include "setup.h"
43 #include "../src/viewer/mcviewer.h" /* For the externs */
44 #include "hotlist.h" /* load/save/done hotlist */
45 #include "panelize.h" /* load/save/done panelize */
46 #include "layout.h"
47 #include "menu.h" /* menubar_visible declaration */
48 #include "cmd.h"
49 #include "file.h" /* safe_delete */
51 #ifdef USE_VFS
52 #include "../vfs/gc.h"
53 #endif
55 #ifdef HAVE_CHARSET
56 #include "charsets.h"
57 #endif
59 #ifdef USE_NETCODE
60 # include "../vfs/ftpfs.h"
61 # include "../vfs/fish.h"
62 #endif
64 #ifdef USE_INTERNAL_EDIT
65 # include "../edit/edit.h"
66 #endif
68 #include "../src/strutil.h" /* str_isutf8 () */
71 extern char *find_ignore_dirs;
73 extern int num_history_items_recorded;
75 char *profile_name; /* .mc/ini */
76 char *global_profile_name; /* mc.lib */
77 char *panels_profile_name; /* .mc/panels.ini */
79 char *setup_color_string;
80 char *term_color_string;
81 char *color_terminal_string;
83 int startup_left_mode;
84 int startup_right_mode;
86 /* Ugly hack to allow panel_save_setup to work as a place holder for */
87 /* default panel values */
88 int saving_setup;
90 static const struct {
91 const char *key;
92 sortfn *sort_type;
93 } sort_names [] = {
94 { "name", (sortfn *) sort_name },
95 { "extension", (sortfn *) sort_ext },
96 { "time", (sortfn *) sort_time },
97 { "atime", (sortfn *) sort_atime },
98 { "ctime", (sortfn *) sort_ctime },
99 { "size", (sortfn *) sort_size },
100 { "inode", (sortfn *) sort_inode },
101 { "unsorted", (sortfn *) unsorted },
102 { 0, 0 }
105 static const struct {
106 const char *key;
107 int list_type;
108 } list_types [] = {
109 { "full", list_full },
110 { "brief", list_brief },
111 { "long", list_long },
112 { "user", list_user },
113 { 0, 0 }
116 static const struct {
117 const char *opt_name;
118 int opt_type;
119 } panel_types [] = {
120 { "listing", view_listing },
121 { "quickview", view_quick },
122 { "info", view_info },
123 { "tree", view_tree },
124 { 0, 0 }
127 static const struct {
128 const char *opt_name;
129 int *opt_addr;
130 } layout [] = {
131 { "equal_split", &equal_split },
132 { "first_panel_size", &first_panel_size },
133 { "message_visible", &message_visible },
134 { "keybar_visible", &keybar_visible },
135 { "xterm_title", &xterm_title },
136 { "output_lines", &output_lines },
137 { "command_prompt", &command_prompt },
138 { "menubar_visible", &menubar_visible },
139 { "show_mini_info", &show_mini_info },
140 { "permission_mode", &permission_mode },
141 { "filetype_mode", &filetype_mode },
142 { "free_space", &free_space },
143 { 0, 0 }
146 static const struct {
147 const char *opt_name;
148 int *opt_addr;
149 } int_options [] = {
150 { "show_backups", &show_backups },
151 { "kilobyte_si", &kilobyte_si },
152 { "show_dot_files", &show_dot_files },
153 { "verbose", &verbose },
154 { "mark_moves_down", &mark_moves_down },
155 { "pause_after_run", &pause_after_run },
156 { "shell_patterns", &easy_patterns },
157 { "auto_save_setup", &auto_save_setup },
158 { "auto_menu", &auto_menu },
159 { "use_internal_view", &use_internal_view },
160 { "use_internal_edit", &use_internal_edit },
161 { "clear_before_exec", &clear_before_exec },
162 { "mix_all_files", &mix_all_files },
163 { "fast_reload", &fast_reload },
164 { "fast_reload_msg_shown", &fast_reload_w },
165 { "confirm_delete", &confirm_delete },
166 { "confirm_overwrite", &confirm_overwrite },
167 { "confirm_execute", &confirm_execute },
168 { "confirm_exit", &confirm_exit },
169 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
170 { "safe_delete", &safe_delete },
171 { "mouse_repeat_rate", &mou_auto_repeat },
172 { "double_click_speed", &double_click_speed },
173 #ifndef HAVE_CHARSET
174 { "eight_bit_clean", &eight_bit_clean },
175 { "full_eight_bits", &full_eight_bits },
176 #endif /* !HAVE_CHARSET */
177 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
178 { "confirm_view_dir", &confirm_view_dir },
179 { "mouse_move_pages", &mouse_move_pages },
180 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
181 { "mouse_close_dialog", &mouse_close_dialog},
182 { "fast_refresh", &fast_refresh },
183 { "navigate_with_arrows", &navigate_with_arrows },
184 { "drop_menus", &drop_menus },
185 { "wrap_mode", &mcview_global_wrap_mode},
186 { "old_esc_mode", &old_esc_mode },
187 { "cd_symlinks", &cd_symlinks },
188 { "show_all_if_ambiguous", &show_all_if_ambiguous },
189 { "max_dirt_limit", &mcview_max_dirt_limit },
190 { "torben_fj_mode", &torben_fj_mode },
191 { "use_file_to_guess_type", &use_file_to_check_type },
192 { "alternate_plus_minus", &alternate_plus_minus },
193 { "only_leading_plus_minus", &only_leading_plus_minus },
194 { "show_output_starts_shell", &output_starts_shell },
195 { "panel_scroll_pages", &panel_scroll_pages },
196 { "xtree_mode", &xtree_mode },
197 { "num_history_items_recorded", &num_history_items_recorded },
198 { "file_op_compute_totals", &file_op_compute_totals },
199 { "skip_check_codeset", &skip_check_codeset },
200 #ifdef USE_VFS
201 { "vfs_timeout", &vfs_timeout },
202 #ifdef USE_NETCODE
203 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
204 { "use_netrc", &use_netrc },
205 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
206 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
207 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
208 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
209 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
210 { "fish_directory_timeout", &fish_directory_timeout },
211 #endif /* USE_NETCODE */
212 #endif /* USE_VFS */
213 #ifdef USE_INTERNAL_EDIT
214 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
215 { "editor_key_emulation", &edit_key_emulation },
216 { "editor_tab_spacing", &option_tab_spacing },
217 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
218 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
219 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
220 { "editor_fake_half_tabs", &option_fake_half_tabs },
221 { "editor_option_save_mode", &option_save_mode },
222 { "editor_option_save_position", &option_save_position },
223 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
224 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
225 { "editor_edit_confirm_save", &edit_confirm_save },
226 { "editor_syntax_highlighting", &option_syntax_highlighting },
227 { "editor_persistent_selections", &option_persistent_selections },
228 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
229 { "editor_visible_tabs", &visible_tabs },
230 { "editor_visible_spaces", &visible_tws },
231 { "editor_line_state", &option_line_state },
232 { "editor_simple_statusbar", &simple_statusbar },
233 #endif /* USE_INTERNAL_EDIT */
235 { "nice_rotating_dash", &nice_rotating_dash },
236 { "horizontal_split", &horizontal_split },
237 { "mcview_remember_file_position", &mcview_remember_file_position },
238 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
239 { "reverse_files_only", &reverse_files_only },
240 { 0, 0 }
243 static const struct {
244 const char *opt_name;
245 char **opt_addr;
246 const char *opt_defval;
247 } str_options [] = {
248 #ifdef USE_INTERNAL_EDIT
249 { "editor_backup_extension", &option_backup_ext, "~" },
250 #endif
251 { NULL, NULL, NULL }
254 void
255 panel_save_setup (struct WPanel *panel, const char *section)
257 char *buffer;
258 int i;
260 mc_config_set_int(mc_panels_config, section, "reverse", panel->reverse);
261 mc_config_set_int(mc_panels_config, section, "case_sensitive", panel->case_sensitive);
262 mc_config_set_int(mc_panels_config, section, "exec_first", panel->exec_first);
265 for (i = 0; sort_names [i].key; i++)
266 if (sort_names [i].sort_type == (sortfn *) panel->sort_type){
267 mc_config_set_string(mc_panels_config, section, "sort_order", sort_names [i].key);
268 break;
271 for (i = 0; list_types [i].key; i++)
272 if (list_types [i].list_type == panel->list_type){
273 mc_config_set_string(mc_panels_config, section, "list_mode", list_types [i].key);
274 break;
277 mc_config_set_string(mc_panels_config, section, "user_format", panel->user_format);
279 for (i = 0; i < LIST_TYPES; i++){
280 buffer = g_strdup_printf("user_status%d", i);
281 mc_config_set_string(mc_panels_config, section, buffer, panel->user_status_format [i]);
282 g_free(buffer);
285 mc_config_set_int(mc_panels_config, section, "user_mini_status", panel->user_mini_status);
288 void
289 save_layout (void)
291 char *profile;
292 int i;
294 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
296 /* Save integer options */
297 for (i = 0; layout [i].opt_name; i++){
298 mc_config_set_int(mc_main_config, "Layout", layout [i].opt_name, *layout [i].opt_addr);
300 mc_config_save_to_file (mc_main_config, profile);
302 g_free (profile);
305 void
306 save_configure (void)
308 char *profile;
309 int i;
311 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
313 /* Save integer options */
314 for (i = 0; int_options[i].opt_name; i++)
315 mc_config_set_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
317 /* Save string options */
318 for (i = 0; str_options[i].opt_name != NULL; i++)
319 mc_config_set_string(mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, *str_options[i].opt_addr);
321 mc_config_save_to_file (mc_main_config, profile);
322 g_free (profile);
325 static void
326 panel_save_type (const char *section, int type)
328 int i;
330 for (i = 0; panel_types [i].opt_name; i++)
331 if (panel_types [i].opt_type == type){
332 mc_config_set_string(mc_panels_config, section,
333 "display", panel_types [i].opt_name);
334 break;
338 void
339 save_panel_types (void)
341 int type;
343 type = get_display_type (0);
344 panel_save_type ("New Left Panel", type);
345 if (type == view_listing)
346 panel_save_setup (left_panel, left_panel->panel_name);
347 type = get_display_type (1);
348 panel_save_type ("New Right Panel", type);
349 if (type == view_listing)
350 panel_save_setup (right_panel, right_panel->panel_name);
352 mc_config_set_string(mc_panels_config, "Dirs" , "other_dir",
353 get_other_type () == view_listing
354 ? other_panel->cwd : ".");
355 if (current_panel != NULL)
356 mc_config_set_string(mc_panels_config, "Dirs" , "current_is_left",
357 get_current_index () == 0 ? "1" : "0");
359 if (mc_panels_config->ini_path == NULL)
360 mc_panels_config->ini_path = g_strdup(panels_profile_name);
362 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
363 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
365 mc_config_save_file (mc_panels_config);
368 void
369 save_setup (void)
371 char *tmp_profile;
373 saving_setup = 1;
375 save_configure ();
377 save_layout ();
379 save_hotlist ();
381 save_panelize ();
382 save_panel_types ();
383 /* directory_history_save (); */
385 #if defined(USE_VFS) && defined (USE_NETCODE)
386 mc_config_set_string(mc_main_config, "Misc" , "ftpfs_password",
387 ftpfs_anonymous_passwd);
388 if (ftpfs_proxy_host)
389 mc_config_set_string(mc_main_config, "Misc" , "ftp_proxy_host",
390 ftpfs_proxy_host);
391 #endif /* USE_VFS && USE_NETCODE */
393 #ifdef HAVE_CHARSET
394 mc_config_set_string(mc_main_config, "Misc" , "display_codepage",
395 get_codepage_id( display_codepage ));
396 mc_config_set_string(mc_main_config, "Misc" , "source_codepage",
397 get_codepage_id( source_codepage ));
398 #endif /* HAVE_CHARSET */
399 tmp_profile = concat_dir_and_file (home_dir, PROFILE_NAME);
400 mc_config_save_to_file (mc_main_config, tmp_profile);
401 g_free (tmp_profile);
402 saving_setup = 0;
405 void
406 panel_load_setup (WPanel *panel, const char *section)
408 int i;
409 char *buffer;
411 panel->reverse = mc_config_get_int(mc_panels_config, section, "reverse", 0);
412 panel->case_sensitive = mc_config_get_int(mc_panels_config, section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
413 panel->exec_first = mc_config_get_int(mc_panels_config, section, "exec_first", 0);
415 /* Load sort order */
416 buffer = mc_config_get_string(mc_panels_config, section, "sort_order", "name");
418 panel->sort_type = (sortfn *) sort_name;
419 for (i = 0; sort_names [i].key; i++)
420 if ( g_strcasecmp (sort_names [i].key, buffer) == 0){
421 panel->sort_type = sort_names [i].sort_type;
422 break;
424 g_free(buffer);
425 /* Load the listing mode */
426 buffer = mc_config_get_string(mc_panels_config, section, "list_mode", "full");
427 panel->list_type = list_full;
428 for (i = 0; list_types [i].key; i++)
429 if ( g_strcasecmp (list_types [i].key, buffer) == 0){
430 panel->list_type = list_types [i].list_type;
431 break;
433 g_free(buffer);
435 /* User formats */
436 g_free (panel->user_format);
437 panel->user_format = mc_config_get_string(mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
439 for (i = 0; i < LIST_TYPES; i++){
440 g_free (panel->user_status_format [i]);
441 buffer = g_strdup_printf("user_status%d",i);
442 panel->user_status_format [i] =
443 mc_config_get_string(mc_panels_config, section, buffer, DEFAULT_USER_FORMAT);
444 g_free(buffer);
447 panel->user_mini_status =
448 mc_config_get_int(mc_panels_config, section, "user_mini_status", 0);
452 static void
453 load_layout ()
455 int i;
457 for (i = 0; layout [i].opt_name; i++)
458 *layout [i].opt_addr =
459 mc_config_get_int(mc_main_config,"Layout", layout [i].opt_name, *layout [i].opt_addr);
462 static int
463 setup__load_panel_state (const char *section)
465 char *buffer;
466 int i;
468 int mode = view_listing;
470 /* Load the display mode */
471 buffer = mc_config_get_string(mc_panels_config, section, "display", "listing");
473 for (i = 0; panel_types [i].opt_name; i++)
474 if ( g_strcasecmp (panel_types [i].opt_name, buffer) == 0){
475 mode = panel_types [i].opt_type;
476 break;
478 g_free(buffer);
479 return mode;
482 static const char *
483 setup__is_cfg_group_must_panel_config(const char *grp)
485 if (
486 ! strcasecmp("Dirs",grp) ||
487 ! strcasecmp("Temporal:New Right Panel",grp) ||
488 ! strcasecmp("Temporal:New Left Panel",grp) ||
489 ! strcasecmp("New Left Panel",grp) ||
490 ! strcasecmp("New Right Panel",grp)
492 return grp;
493 return NULL;
496 static void
497 setup__move_panels_config_into_separate_file(const char*profile)
499 mc_config_t *tmp_cfg;
500 char **groups, **curr_grp;
501 const char *need_grp;
502 gsize groups_count;
504 if (!exist_file(profile))
505 return;
507 tmp_cfg = mc_config_init(profile);
508 if (!tmp_cfg)
509 return;
511 curr_grp = groups = mc_config_get_groups (tmp_cfg, &groups_count);
512 if (!groups)
514 mc_config_deinit(tmp_cfg);
515 return;
517 while (*curr_grp)
519 if ( setup__is_cfg_group_must_panel_config(*curr_grp) == NULL)
521 mc_config_del_group (tmp_cfg, *curr_grp);
523 curr_grp++;
526 mc_config_save_to_file (tmp_cfg, panels_profile_name);
527 mc_config_deinit(tmp_cfg);
529 tmp_cfg = mc_config_init(profile);
530 if (!tmp_cfg)
532 g_strfreev(groups);
533 return;
536 curr_grp = groups;
538 while (*curr_grp)
540 need_grp = setup__is_cfg_group_must_panel_config(*curr_grp);
541 if ( need_grp != NULL)
543 mc_config_del_group (tmp_cfg, need_grp);
545 curr_grp++;
547 g_strfreev(groups);
548 mc_config_save_file (tmp_cfg);
549 mc_config_deinit(tmp_cfg);
553 char *
554 setup_init (void)
556 char *profile;
557 char *inifile;
559 if (profile_name)
560 return profile_name;
562 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
563 if (!exist_file (profile)){
564 inifile = concat_dir_and_file (mc_home, "mc.ini");
565 if (exist_file (inifile)){
566 g_free (profile);
567 profile = inifile;
568 } else {
569 g_free (inifile);
570 inifile = concat_dir_and_file (mc_home_alt, "mc.ini");
571 if (exist_file (inifile)) {
572 g_free (profile);
573 profile = inifile;
574 } else
575 g_free (inifile);
579 profile_name = profile;
581 return profile;
584 void
585 load_setup (void)
587 char *profile;
588 int i;
589 char *buffer;
591 profile = setup_init ();
593 /* mc.lib is common for all users, but has priority lower than
594 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
595 global_profile_name = concat_dir_and_file (mc_home, "mc.lib");
597 if (!exist_file(global_profile_name)) {
598 g_free (global_profile_name);
599 global_profile_name = concat_dir_and_file (mc_home_alt, "mc.lib");
601 panels_profile_name = concat_dir_and_file (home_dir, PANELS_PROFILE_NAME);
603 mc_main_config = mc_config_init(profile);
605 if (!exist_file(panels_profile_name))
606 setup__move_panels_config_into_separate_file(profile);
608 mc_panels_config = mc_config_init(panels_profile_name);
610 /* Load integer boolean options */
611 for (i = 0; int_options[i].opt_name; i++)
612 *int_options[i].opt_addr =
613 mc_config_get_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
615 /* Load string options */
616 for (i = 0; str_options[i].opt_name != NULL; i++)
617 *str_options[i].opt_addr =
618 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, str_options[i].opt_defval);
620 load_layout ();
622 load_panelize ();
624 startup_left_mode = setup__load_panel_state ("New Left Panel");
625 startup_right_mode = setup__load_panel_state ("New Right Panel");
627 /* At least one of the panels is a listing panel */
628 if (startup_left_mode != view_listing && startup_right_mode!=view_listing)
629 startup_left_mode = view_listing;
631 if (!other_dir){
632 buffer = mc_config_get_string(mc_panels_config, "Dirs", "other_dir", ".");
633 if (vfs_file_is_local (buffer))
634 other_dir = buffer;
635 else
636 g_free (buffer);
639 boot_current_is_left =
640 mc_config_get_int(mc_panels_config, "Dirs", "current_is_left", 1);
642 #ifdef USE_NETCODE
643 ftpfs_proxy_host = mc_config_get_string(mc_main_config, "Misc", "ftp_proxy_host", "gate");
644 #endif
645 setup_color_string = mc_config_get_string(mc_main_config, "Misc", "find_ignore_dirs", "");
646 if (setup_color_string [0])
647 find_ignore_dirs = g_strconcat (":", setup_color_string, ":", (char *) NULL);
648 g_free(setup_color_string);
650 /* The default color and the terminal dependent color */
651 setup_color_string = mc_config_get_string(mc_main_config, "Colors", "base_color", "");
652 term_color_string = mc_config_get_string(mc_main_config, "Colors", getenv ("TERM"), "");
653 color_terminal_string = mc_config_get_string(mc_main_config, "Colors", "color_terminals", "");
655 /* Load the directory history */
656 /* directory_history_load (); */
657 /* Remove the temporal entries */
658 #if defined(USE_VFS) && defined (USE_NETCODE)
659 ftpfs_init_passwd ();
660 #endif /* USE_VFS && USE_NETCODE */
662 #ifdef HAVE_CHARSET
663 if ( load_codepages_list() > 0 ) {
664 buffer = mc_config_get_string(mc_main_config, "Misc", "display_codepage", "");
665 if ( buffer[0] != '\0' )
667 display_codepage = get_codepage_index( buffer );
668 cp_display = get_codepage_id (display_codepage);
670 g_free(buffer);
671 buffer = mc_config_get_string(mc_main_config, "Misc", "source_codepage", "");
672 if ( buffer[0] != '\0' )
674 source_codepage = get_codepage_index( buffer );
675 cp_source = get_codepage_id (source_codepage);
677 g_free(buffer);
679 init_translation_table( source_codepage, display_codepage );
680 if ( get_codepage_id( display_codepage ) )
681 utf8_display = str_isutf8 (get_codepage_id( display_codepage ));
682 #endif /* HAVE_CHARSET */
685 #if defined(USE_VFS) && defined (USE_NETCODE)
686 char *
687 load_anon_passwd ()
689 char *buffer;
691 buffer = mc_config_get_string(mc_main_config, "Misc", "ftpfs_password", "");
692 if (buffer [0])
693 return buffer;
695 g_free(buffer);
696 return NULL;
698 #endif /* USE_VFS && USE_NETCODE */
700 void done_setup (void)
702 g_free (profile_name);
703 g_free (global_profile_name);
704 g_free(color_terminal_string);
705 g_free(term_color_string);
706 g_free(setup_color_string);
707 mc_config_deinit(mc_main_config);
708 mc_config_deinit(mc_panels_config);
709 done_hotlist ();
710 done_panelize ();
711 /* directory_history_free (); */
714 static void
715 load_keys_from_section (const char *terminal, mc_config_t *cfg)
717 char *section_name;
718 gchar **profile_keys, **keys;
719 gchar **values, **curr_values;
720 char *valcopy, *value;
721 int key_code;
722 gsize len, values_len;
724 if (!terminal)
725 return;
727 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
728 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
730 while (*profile_keys){
732 /* copy=other causes all keys from [terminal:other] to be loaded. */
733 if (g_strcasecmp (*profile_keys, "copy") == 0) {
734 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
735 load_keys_from_section (valcopy, cfg);
736 g_free(valcopy);
737 profile_keys++;
738 continue;
740 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
742 key_code = lookup_key (*profile_keys);
743 if (key_code){
744 if (curr_values){
745 while (*curr_values){
746 valcopy = convert_controls (*curr_values);
747 define_sequence (key_code, valcopy, MCKEY_NOACTION);
748 g_free (valcopy);
749 curr_values++;
751 } else {
752 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
753 valcopy = convert_controls (value);
754 define_sequence (key_code, valcopy, MCKEY_NOACTION);
755 g_free (valcopy);
756 g_free(value);
759 profile_keys++;
760 if (values)
761 g_strfreev(values);
763 g_strfreev(keys);
764 g_free (section_name);
767 void load_key_defs (void)
770 * Load keys from mc.lib before ~/.mc/ini, so that the user
771 * definitions override global settings.
773 mc_config_t *mc_global_config;
775 mc_global_config = mc_config_init(global_profile_name);
776 if (mc_global_config != NULL)
778 load_keys_from_section ("general", mc_global_config);
779 load_keys_from_section (getenv ("TERM"), mc_global_config);
780 mc_config_deinit(mc_global_config);
782 load_keys_from_section ("general", mc_main_config);
783 load_keys_from_section (getenv ("TERM"), mc_main_config);