add option "Cursor beyond end of line" into "Options\General..." dialog (editor_b...
[midnight-commander.git] / src / setup.c
blobeb58948ce4adfbae67b9f9576e157a558b96bec2
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 "view.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", &mouse_move_pages_viewer },
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", &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", &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 { 0, 0 }
242 static const struct {
243 const char *opt_name;
244 char **opt_addr;
245 const char *opt_defval;
246 } str_options [] = {
247 #ifdef USE_INTERNAL_EDIT
248 { "editor_backup_extension", &option_backup_ext, "~" },
249 #endif
250 { NULL, NULL, NULL }
253 void
254 panel_save_setup (struct WPanel *panel, const char *section)
256 char *buffer;
257 int i;
259 mc_config_set_int(mc_panels_config, section, "reverse", panel->reverse);
260 mc_config_set_int(mc_panels_config, section, "case_sensitive", panel->case_sensitive);
261 mc_config_set_int(mc_panels_config, section, "exec_first", panel->exec_first);
264 for (i = 0; sort_names [i].key; i++)
265 if (sort_names [i].sort_type == (sortfn *) panel->sort_type){
266 mc_config_set_string(mc_panels_config, section, "sort_order", sort_names [i].key);
267 break;
270 for (i = 0; list_types [i].key; i++)
271 if (list_types [i].list_type == panel->list_type){
272 mc_config_set_string(mc_panels_config, section, "list_mode", list_types [i].key);
273 break;
276 mc_config_set_string(mc_panels_config, section, "user_format", panel->user_format);
278 for (i = 0; i < LIST_TYPES; i++){
279 buffer = g_strdup_printf("user_status%d", i);
280 mc_config_set_string(mc_panels_config, section, buffer, panel->user_status_format [i]);
281 g_free(buffer);
284 mc_config_set_int(mc_panels_config, section, "user_mini_status", panel->user_mini_status);
287 void
288 save_layout (void)
290 char *profile;
291 int i;
293 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
295 /* Save integer options */
296 for (i = 0; layout [i].opt_name; i++){
297 mc_config_set_int(mc_main_config, "Layout", layout [i].opt_name, *layout [i].opt_addr);
299 mc_config_save_to_file (mc_main_config, profile);
301 g_free (profile);
304 void
305 save_configure (void)
307 char *profile;
308 int i;
310 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
312 /* Save integer options */
313 for (i = 0; int_options[i].opt_name; i++)
314 mc_config_set_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
316 /* Save string options */
317 for (i = 0; str_options[i].opt_name != NULL; i++)
318 mc_config_set_string(mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, *str_options[i].opt_addr);
320 mc_config_save_to_file (mc_main_config, profile);
321 g_free (profile);
324 static void
325 panel_save_type (const char *section, int type)
327 int i;
329 for (i = 0; panel_types [i].opt_name; i++)
330 if (panel_types [i].opt_type == type){
331 mc_config_set_string(mc_panels_config, section,
332 "display", panel_types [i].opt_name);
333 break;
337 void
338 save_panel_types (void)
340 int type;
342 type = get_display_type (0);
343 panel_save_type ("New Left Panel", type);
344 if (type == view_listing)
345 panel_save_setup (left_panel, left_panel->panel_name);
346 type = get_display_type (1);
347 panel_save_type ("New Right Panel", type);
348 if (type == view_listing)
349 panel_save_setup (right_panel, right_panel->panel_name);
351 mc_config_set_string(mc_panels_config, "Dirs" , "other_dir",
352 get_other_type () == view_listing
353 ? other_panel->cwd : ".");
354 if (current_panel != NULL)
355 mc_config_set_string(mc_panels_config, "Dirs" , "current_is_left",
356 get_current_index () == 0 ? "1" : "0");
358 if (mc_panels_config->ini_path == NULL)
359 mc_panels_config->ini_path = g_strdup(panels_profile_name);
361 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
362 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
364 mc_config_save_file (mc_panels_config);
367 void
368 save_setup (void)
370 char *tmp_profile;
372 saving_setup = 1;
374 save_configure ();
376 save_layout ();
378 save_hotlist ();
380 save_panelize ();
381 save_panel_types ();
382 /* directory_history_save (); */
384 #if defined(USE_VFS) && defined (USE_NETCODE)
385 mc_config_set_string(mc_main_config, "Misc" , "ftpfs_password",
386 ftpfs_anonymous_passwd);
387 if (ftpfs_proxy_host)
388 mc_config_set_string(mc_main_config, "Misc" , "ftp_proxy_host",
389 ftpfs_proxy_host);
390 #endif /* USE_VFS && USE_NETCODE */
392 #ifdef HAVE_CHARSET
393 mc_config_set_string(mc_main_config, "Misc" , "display_codepage",
394 get_codepage_id( display_codepage ));
395 mc_config_set_string(mc_main_config, "Misc" , "source_codepage",
396 get_codepage_id( source_codepage ));
397 #endif /* HAVE_CHARSET */
398 tmp_profile = concat_dir_and_file (home_dir, PROFILE_NAME);
399 mc_config_save_to_file (mc_main_config, tmp_profile);
400 g_free (tmp_profile);
401 saving_setup = 0;
404 void
405 panel_load_setup (WPanel *panel, const char *section)
407 int i;
408 char *buffer;
410 panel->reverse = mc_config_get_int(mc_panels_config, section, "reverse", 0);
411 panel->case_sensitive = mc_config_get_int(mc_panels_config, section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
412 panel->exec_first = mc_config_get_int(mc_panels_config, section, "exec_first", 0);
414 /* Load sort order */
415 buffer = mc_config_get_string(mc_panels_config, section, "sort_order", "name");
417 panel->sort_type = (sortfn *) sort_name;
418 for (i = 0; sort_names [i].key; i++)
419 if ( g_strcasecmp (sort_names [i].key, buffer) == 0){
420 panel->sort_type = sort_names [i].sort_type;
421 break;
423 g_free(buffer);
424 /* Load the listing mode */
425 buffer = mc_config_get_string(mc_panels_config, section, "list_mode", "full");
426 panel->list_type = list_full;
427 for (i = 0; list_types [i].key; i++)
428 if ( g_strcasecmp (list_types [i].key, buffer) == 0){
429 panel->list_type = list_types [i].list_type;
430 break;
432 g_free(buffer);
434 /* User formats */
435 g_free (panel->user_format);
436 panel->user_format = mc_config_get_string(mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
438 for (i = 0; i < LIST_TYPES; i++){
439 g_free (panel->user_status_format [i]);
440 buffer = g_strdup_printf("user_status%d",i);
441 panel->user_status_format [i] =
442 mc_config_get_string(mc_panels_config, section, buffer, DEFAULT_USER_FORMAT);
443 g_free(buffer);
446 panel->user_mini_status =
447 mc_config_get_int(mc_panels_config, section, "user_mini_status", 0);
451 static void
452 load_layout ()
454 int i;
456 for (i = 0; layout [i].opt_name; i++)
457 *layout [i].opt_addr =
458 mc_config_get_int(mc_main_config,"Layout", layout [i].opt_name, *layout [i].opt_addr);
461 static int
462 setup__load_panel_state (const char *section)
464 char *buffer;
465 int i;
467 int mode = view_listing;
469 /* Load the display mode */
470 buffer = mc_config_get_string(mc_panels_config, section, "display", "listing");
472 for (i = 0; panel_types [i].opt_name; i++)
473 if ( g_strcasecmp (panel_types [i].opt_name, buffer) == 0){
474 mode = panel_types [i].opt_type;
475 break;
477 g_free(buffer);
478 return mode;
481 static const char *
482 setup__is_cfg_group_must_panel_config(const char *grp)
484 if (
485 ! strcasecmp("Dirs",grp) ||
486 ! strcasecmp("Temporal:New Right Panel",grp) ||
487 ! strcasecmp("Temporal:New Left Panel",grp) ||
488 ! strcasecmp("New Left Panel",grp) ||
489 ! strcasecmp("New Right Panel",grp)
491 return grp;
492 return NULL;
495 static void
496 setup__move_panels_config_into_separate_file(const char*profile)
498 mc_config_t *tmp_cfg;
499 char **groups, **curr_grp;
500 const char *need_grp;
501 gsize groups_count;
503 if (!exist_file(profile))
504 return;
506 tmp_cfg = mc_config_init(profile);
507 if (!tmp_cfg)
508 return;
510 curr_grp = groups = mc_config_get_groups (tmp_cfg, &groups_count);
511 if (!groups)
513 mc_config_deinit(tmp_cfg);
514 return;
516 while (*curr_grp)
518 if ( setup__is_cfg_group_must_panel_config(*curr_grp) == NULL)
520 mc_config_del_group (tmp_cfg, *curr_grp);
522 curr_grp++;
525 mc_config_save_to_file (tmp_cfg, panels_profile_name);
526 mc_config_deinit(tmp_cfg);
528 tmp_cfg = mc_config_init(profile);
529 if (!tmp_cfg)
531 g_strfreev(groups);
532 return;
535 curr_grp = groups;
537 while (*curr_grp)
539 need_grp = setup__is_cfg_group_must_panel_config(*curr_grp);
540 if ( need_grp != NULL)
542 mc_config_del_group (tmp_cfg, need_grp);
544 curr_grp++;
546 g_strfreev(groups);
547 mc_config_save_file (tmp_cfg);
548 mc_config_deinit(tmp_cfg);
552 char *
553 setup_init (void)
555 char *profile;
556 char *inifile;
558 if (profile_name)
559 return profile_name;
561 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
562 if (!exist_file (profile)){
563 inifile = concat_dir_and_file (mc_home, "mc.ini");
564 if (exist_file (inifile)){
565 g_free (profile);
566 profile = inifile;
567 } else {
568 g_free (inifile);
569 inifile = concat_dir_and_file (mc_home_alt, "mc.ini");
570 if (exist_file (inifile)) {
571 g_free (profile);
572 profile = inifile;
573 } else
574 g_free (inifile);
578 profile_name = profile;
580 return profile;
583 void
584 load_setup (void)
586 char *profile;
587 int i;
588 char *buffer;
590 profile = setup_init ();
592 /* mc.lib is common for all users, but has priority lower than
593 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
594 global_profile_name = concat_dir_and_file (mc_home, "mc.lib");
596 if (!exist_file(global_profile_name)) {
597 g_free (global_profile_name);
598 global_profile_name = concat_dir_and_file (mc_home_alt, "mc.lib");
600 panels_profile_name = concat_dir_and_file (home_dir, PANELS_PROFILE_NAME);
602 mc_main_config = mc_config_init(profile);
604 if (!exist_file(panels_profile_name))
605 setup__move_panels_config_into_separate_file(profile);
607 mc_panels_config = mc_config_init(panels_profile_name);
609 /* Load integer boolean options */
610 for (i = 0; int_options[i].opt_name; i++)
611 *int_options[i].opt_addr =
612 mc_config_get_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
614 /* Load string options */
615 for (i = 0; str_options[i].opt_name != NULL; i++)
616 *str_options[i].opt_addr =
617 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, str_options[i].opt_defval);
619 load_layout ();
621 load_panelize ();
623 startup_left_mode = setup__load_panel_state ("New Left Panel");
624 startup_right_mode = setup__load_panel_state ("New Right Panel");
626 /* At least one of the panels is a listing panel */
627 if (startup_left_mode != view_listing && startup_right_mode!=view_listing)
628 startup_left_mode = view_listing;
630 if (!other_dir){
631 buffer = mc_config_get_string(mc_panels_config, "Dirs", "other_dir", ".");
632 if (vfs_file_is_local (buffer))
633 other_dir = buffer;
634 else
635 g_free (buffer);
638 boot_current_is_left =
639 mc_config_get_int(mc_panels_config, "Dirs", "current_is_left", 1);
641 #ifdef USE_NETCODE
642 ftpfs_proxy_host = mc_config_get_string(mc_main_config, "Misc", "ftp_proxy_host", "gate");
643 #endif
644 setup_color_string = mc_config_get_string(mc_main_config, "Misc", "find_ignore_dirs", "");
645 if (setup_color_string [0])
646 find_ignore_dirs = g_strconcat (":", setup_color_string, ":", (char *) NULL);
647 g_free(setup_color_string);
649 /* The default color and the terminal dependent color */
650 setup_color_string = mc_config_get_string(mc_main_config, "Colors", "base_color", "");
651 term_color_string = mc_config_get_string(mc_main_config, "Colors", getenv ("TERM"), "");
652 color_terminal_string = mc_config_get_string(mc_main_config, "Colors", "color_terminals", "");
654 /* Load the directory history */
655 /* directory_history_load (); */
656 /* Remove the temporal entries */
657 #if defined(USE_VFS) && defined (USE_NETCODE)
658 ftpfs_init_passwd ();
659 #endif /* USE_VFS && USE_NETCODE */
661 #ifdef HAVE_CHARSET
662 if ( load_codepages_list() > 0 ) {
663 buffer = mc_config_get_string(mc_main_config, "Misc", "display_codepage", "");
664 if ( buffer[0] != '\0' )
666 display_codepage = get_codepage_index( buffer );
667 cp_display = get_codepage_id (display_codepage);
669 g_free(buffer);
670 buffer = mc_config_get_string(mc_main_config, "Misc", "source_codepage", "");
671 if ( buffer[0] != '\0' )
673 source_codepage = get_codepage_index( buffer );
674 cp_source = get_codepage_id (source_codepage);
676 g_free(buffer);
678 init_translation_table( source_codepage, display_codepage );
679 if ( get_codepage_id( display_codepage ) )
680 utf8_display = str_isutf8 (get_codepage_id( display_codepage ));
681 #endif /* HAVE_CHARSET */
684 #if defined(USE_VFS) && defined (USE_NETCODE)
685 char *
686 load_anon_passwd ()
688 char *buffer;
690 buffer = mc_config_get_string(mc_main_config, "Misc", "ftpfs_password", "");
691 if (buffer [0])
692 return buffer;
694 g_free(buffer);
695 return NULL;
697 #endif /* USE_VFS && USE_NETCODE */
699 void done_setup (void)
701 g_free (profile_name);
702 g_free (global_profile_name);
703 g_free(color_terminal_string);
704 g_free(term_color_string);
705 g_free(setup_color_string);
706 mc_config_deinit(mc_main_config);
707 mc_config_deinit(mc_panels_config);
708 done_hotlist ();
709 done_panelize ();
710 /* directory_history_free (); */
713 static void
714 load_keys_from_section (const char *terminal, mc_config_t *cfg)
716 char *section_name;
717 gchar **profile_keys, **keys;
718 gchar **values, **curr_values;
719 char *valcopy, *value;
720 int key_code;
721 gsize len, values_len;
723 if (!terminal)
724 return;
726 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
727 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
729 while (*profile_keys){
731 /* copy=other causes all keys from [terminal:other] to be loaded. */
732 if (g_strcasecmp (*profile_keys, "copy") == 0) {
733 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
734 load_keys_from_section (valcopy, cfg);
735 g_free(valcopy);
736 profile_keys++;
737 continue;
739 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
741 key_code = lookup_key (*profile_keys);
742 if (key_code){
743 if (curr_values){
744 while (*curr_values){
745 valcopy = convert_controls (*curr_values);
746 define_sequence (key_code, valcopy, MCKEY_NOACTION);
747 g_free (valcopy);
748 curr_values++;
750 } else {
751 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
752 valcopy = convert_controls (value);
753 define_sequence (key_code, valcopy, MCKEY_NOACTION);
754 g_free (valcopy);
755 g_free(value);
758 profile_keys++;
759 if (values)
760 g_strfreev(values);
762 g_strfreev(keys);
763 g_free (section_name);
766 void load_key_defs (void)
769 * Load keys from mc.lib before ~/.mc/ini, so that the user
770 * definitions override global settings.
772 mc_config_t *mc_global_config;
774 mc_global_config = mc_config_init(global_profile_name);
775 if (mc_global_config != NULL)
777 load_keys_from_section ("general", mc_global_config);
778 load_keys_from_section (getenv ("TERM"), mc_global_config);
779 mc_config_deinit(mc_global_config);
781 load_keys_from_section ("general", mc_main_config);
782 load_keys_from_section (getenv ("TERM"), mc_main_config);