Ticket #268 (Allow using SI-based size prefixes)
[midnight-commander.git] / src / setup.c
blob256cca147b2bb083bf38a26d361a470616b77cbd
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_visible_tabs", &visible_tabs },
229 { "editor_visible_spaces", &visible_tws },
230 { "editor_line_state", &option_line_state },
231 { "editor_simple_statusbar", &simple_statusbar },
232 #endif /* USE_INTERNAL_EDIT */
234 { "nice_rotating_dash", &nice_rotating_dash },
235 { "horizontal_split", &horizontal_split },
236 { "mcview_remember_file_position", &mcview_remember_file_position },
237 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
238 { 0, 0 }
241 static const struct {
242 const char *opt_name;
243 char **opt_addr;
244 const char *opt_defval;
245 } str_options [] = {
246 #ifdef USE_INTERNAL_EDIT
247 { "editor_backup_extension", &option_backup_ext, "~" },
248 #endif
249 { NULL, NULL, NULL }
252 void
253 panel_save_setup (struct WPanel *panel, const char *section)
255 char *buffer;
256 int i;
258 mc_config_set_int(mc_panels_config, section, "reverse", panel->reverse);
259 mc_config_set_int(mc_panels_config, section, "case_sensitive", panel->case_sensitive);
260 mc_config_set_int(mc_panels_config, section, "exec_first", panel->exec_first);
263 for (i = 0; sort_names [i].key; i++)
264 if (sort_names [i].sort_type == (sortfn *) panel->sort_type){
265 mc_config_set_string(mc_panels_config, section, "sort_order", sort_names [i].key);
266 break;
269 for (i = 0; list_types [i].key; i++)
270 if (list_types [i].list_type == panel->list_type){
271 mc_config_set_string(mc_panels_config, section, "list_mode", list_types [i].key);
272 break;
275 mc_config_set_string(mc_panels_config, section, "user_format", panel->user_format);
277 for (i = 0; i < LIST_TYPES; i++){
278 buffer = g_strdup_printf("user_status%d", i);
279 mc_config_set_string(mc_panels_config, section, buffer, panel->user_status_format [i]);
280 g_free(buffer);
283 mc_config_set_int(mc_panels_config, section, "user_mini_status", panel->user_mini_status);
286 void
287 save_layout (void)
289 char *profile;
290 int i;
292 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
294 /* Save integer options */
295 for (i = 0; layout [i].opt_name; i++){
296 mc_config_set_int(mc_main_config, "Layout", layout [i].opt_name, *layout [i].opt_addr);
298 mc_config_save_to_file (mc_main_config, profile);
300 g_free (profile);
303 void
304 save_configure (void)
306 char *profile;
307 int i;
309 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
311 /* Save integer options */
312 for (i = 0; int_options[i].opt_name; i++)
313 mc_config_set_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
315 /* Save string options */
316 for (i = 0; str_options[i].opt_name != NULL; i++)
317 mc_config_set_string(mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, *str_options[i].opt_addr);
319 mc_config_save_to_file (mc_main_config, profile);
320 g_free (profile);
323 static void
324 panel_save_type (const char *section, int type)
326 int i;
328 for (i = 0; panel_types [i].opt_name; i++)
329 if (panel_types [i].opt_type == type){
330 mc_config_set_string(mc_panels_config, section,
331 "display", panel_types [i].opt_name);
332 break;
336 void
337 save_panel_types (void)
339 int type;
341 type = get_display_type (0);
342 panel_save_type ("New Left Panel", type);
343 if (type == view_listing)
344 panel_save_setup (left_panel, left_panel->panel_name);
345 type = get_display_type (1);
346 panel_save_type ("New Right Panel", type);
347 if (type == view_listing)
348 panel_save_setup (right_panel, right_panel->panel_name);
350 mc_config_set_string(mc_panels_config, "Dirs" , "other_dir",
351 get_other_type () == view_listing
352 ? other_panel->cwd : ".");
353 if (current_panel != NULL)
354 mc_config_set_string(mc_panels_config, "Dirs" , "current_is_left",
355 get_current_index () == 0 ? "1" : "0");
357 if (mc_panels_config->ini_path == NULL)
358 mc_panels_config->ini_path = g_strdup(panels_profile_name);
360 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
361 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
363 mc_config_save_file (mc_panels_config);
366 void
367 save_setup (void)
369 char *tmp_profile;
371 saving_setup = 1;
373 save_configure ();
375 save_layout ();
377 save_hotlist ();
379 save_panelize ();
380 save_panel_types ();
381 /* directory_history_save (); */
383 #if defined(USE_VFS) && defined (USE_NETCODE)
384 mc_config_set_string(mc_main_config, "Misc" , "ftpfs_password",
385 ftpfs_anonymous_passwd);
386 if (ftpfs_proxy_host)
387 mc_config_set_string(mc_main_config, "Misc" , "ftp_proxy_host",
388 ftpfs_proxy_host);
389 #endif /* USE_VFS && USE_NETCODE */
391 #ifdef HAVE_CHARSET
392 mc_config_set_string(mc_main_config, "Misc" , "display_codepage",
393 get_codepage_id( display_codepage ));
394 mc_config_set_string(mc_main_config, "Misc" , "source_codepage",
395 get_codepage_id( source_codepage ));
396 #endif /* HAVE_CHARSET */
397 tmp_profile = concat_dir_and_file (home_dir, PROFILE_NAME);
398 mc_config_save_to_file (mc_main_config, tmp_profile);
399 g_free (tmp_profile);
400 saving_setup = 0;
403 void
404 panel_load_setup (WPanel *panel, const char *section)
406 int i;
407 char *buffer;
409 panel->reverse = mc_config_get_int(mc_panels_config, section, "reverse", 0);
410 panel->case_sensitive = mc_config_get_int(mc_panels_config, section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
411 panel->exec_first = mc_config_get_int(mc_panels_config, section, "exec_first", 0);
413 /* Load sort order */
414 buffer = mc_config_get_string(mc_panels_config, section, "sort_order", "name");
416 panel->sort_type = (sortfn *) sort_name;
417 for (i = 0; sort_names [i].key; i++)
418 if ( g_strcasecmp (sort_names [i].key, buffer) == 0){
419 panel->sort_type = sort_names [i].sort_type;
420 break;
422 g_free(buffer);
423 /* Load the listing mode */
424 buffer = mc_config_get_string(mc_panels_config, section, "list_mode", "full");
425 panel->list_type = list_full;
426 for (i = 0; list_types [i].key; i++)
427 if ( g_strcasecmp (list_types [i].key, buffer) == 0){
428 panel->list_type = list_types [i].list_type;
429 break;
431 g_free(buffer);
433 /* User formats */
434 g_free (panel->user_format);
435 panel->user_format = mc_config_get_string(mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
437 for (i = 0; i < LIST_TYPES; i++){
438 g_free (panel->user_status_format [i]);
439 buffer = g_strdup_printf("user_status%d",i);
440 panel->user_status_format [i] =
441 mc_config_get_string(mc_panels_config, section, buffer, DEFAULT_USER_FORMAT);
442 g_free(buffer);
445 panel->user_mini_status =
446 mc_config_get_int(mc_panels_config, section, "user_mini_status", 0);
450 static void
451 load_layout ()
453 int i;
455 for (i = 0; layout [i].opt_name; i++)
456 *layout [i].opt_addr =
457 mc_config_get_int(mc_main_config,"Layout", layout [i].opt_name, *layout [i].opt_addr);
460 static int
461 setup__load_panel_state (const char *section)
463 char *buffer;
464 int i;
466 int mode = view_listing;
468 /* Load the display mode */
469 buffer = mc_config_get_string(mc_panels_config, section, "display", "listing");
471 for (i = 0; panel_types [i].opt_name; i++)
472 if ( g_strcasecmp (panel_types [i].opt_name, buffer) == 0){
473 mode = panel_types [i].opt_type;
474 break;
476 g_free(buffer);
477 return mode;
480 static const char *
481 setup__is_cfg_group_must_panel_config(const char *grp)
483 if (
484 ! strcasecmp("Dirs",grp) ||
485 ! strcasecmp("Temporal:New Right Panel",grp) ||
486 ! strcasecmp("Temporal:New Left Panel",grp) ||
487 ! strcasecmp("New Left Panel",grp) ||
488 ! strcasecmp("New Right Panel",grp)
490 return grp;
491 return NULL;
494 static void
495 setup__move_panels_config_into_separate_file(const char*profile)
497 mc_config_t *tmp_cfg;
498 char **groups, **curr_grp;
499 const char *need_grp;
500 gsize groups_count;
502 if (!exist_file(profile))
503 return;
505 tmp_cfg = mc_config_init(profile);
506 if (!tmp_cfg)
507 return;
509 curr_grp = groups = mc_config_get_groups (tmp_cfg, &groups_count);
510 if (!groups)
512 mc_config_deinit(tmp_cfg);
513 return;
515 while (*curr_grp)
517 if ( setup__is_cfg_group_must_panel_config(*curr_grp) == NULL)
519 mc_config_del_group (tmp_cfg, *curr_grp);
521 curr_grp++;
524 mc_config_save_to_file (tmp_cfg, panels_profile_name);
525 mc_config_deinit(tmp_cfg);
527 tmp_cfg = mc_config_init(profile);
528 if (!tmp_cfg)
530 g_strfreev(groups);
531 return;
534 curr_grp = groups;
536 while (*curr_grp)
538 need_grp = setup__is_cfg_group_must_panel_config(*curr_grp);
539 if ( need_grp != NULL)
541 mc_config_del_group (tmp_cfg, need_grp);
543 curr_grp++;
545 g_strfreev(groups);
546 mc_config_save_file (tmp_cfg);
547 mc_config_deinit(tmp_cfg);
551 char *
552 setup_init (void)
554 char *profile;
555 char *inifile;
557 if (profile_name)
558 return profile_name;
560 profile = concat_dir_and_file (home_dir, PROFILE_NAME);
561 if (!exist_file (profile)){
562 inifile = concat_dir_and_file (mc_home, "mc.ini");
563 if (exist_file (inifile)){
564 g_free (profile);
565 profile = inifile;
566 } else {
567 g_free (inifile);
568 inifile = concat_dir_and_file (mc_home_alt, "mc.ini");
569 if (exist_file (inifile)) {
570 g_free (profile);
571 profile = inifile;
572 } else
573 g_free (inifile);
577 profile_name = profile;
579 return profile;
582 void
583 load_setup (void)
585 char *profile;
586 int i;
587 char *buffer;
589 profile = setup_init ();
591 /* mc.lib is common for all users, but has priority lower than
592 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
593 global_profile_name = concat_dir_and_file (mc_home, "mc.lib");
595 if (!exist_file(global_profile_name)) {
596 g_free (global_profile_name);
597 global_profile_name = concat_dir_and_file (mc_home_alt, "mc.lib");
599 panels_profile_name = concat_dir_and_file (home_dir, PANELS_PROFILE_NAME);
601 mc_main_config = mc_config_init(profile);
603 if (!exist_file(panels_profile_name))
604 setup__move_panels_config_into_separate_file(profile);
606 mc_panels_config = mc_config_init(panels_profile_name);
608 /* Load integer boolean options */
609 for (i = 0; int_options[i].opt_name; i++)
610 *int_options[i].opt_addr =
611 mc_config_get_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
613 /* Load string options */
614 for (i = 0; str_options[i].opt_name != NULL; i++)
615 *str_options[i].opt_addr =
616 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, str_options[i].opt_defval);
618 load_layout ();
620 load_panelize ();
622 startup_left_mode = setup__load_panel_state ("New Left Panel");
623 startup_right_mode = setup__load_panel_state ("New Right Panel");
625 /* At least one of the panels is a listing panel */
626 if (startup_left_mode != view_listing && startup_right_mode!=view_listing)
627 startup_left_mode = view_listing;
629 if (!other_dir){
630 buffer = mc_config_get_string(mc_panels_config, "Dirs", "other_dir", ".");
631 if (vfs_file_is_local (buffer))
632 other_dir = buffer;
633 else
634 g_free (buffer);
637 boot_current_is_left =
638 mc_config_get_int(mc_panels_config, "Dirs", "current_is_left", 1);
640 #ifdef USE_NETCODE
641 ftpfs_proxy_host = mc_config_get_string(mc_main_config, "Misc", "ftp_proxy_host", "gate");
642 #endif
643 setup_color_string = mc_config_get_string(mc_main_config, "Misc", "find_ignore_dirs", "");
644 if (setup_color_string [0])
645 find_ignore_dirs = g_strconcat (":", setup_color_string, ":", (char *) NULL);
646 g_free(setup_color_string);
648 /* The default color and the terminal dependent color */
649 setup_color_string = mc_config_get_string(mc_main_config, "Colors", "base_color", "");
650 term_color_string = mc_config_get_string(mc_main_config, "Colors", getenv ("TERM"), "");
651 color_terminal_string = mc_config_get_string(mc_main_config, "Colors", "color_terminals", "");
653 /* Load the directory history */
654 /* directory_history_load (); */
655 /* Remove the temporal entries */
656 #if defined(USE_VFS) && defined (USE_NETCODE)
657 ftpfs_init_passwd ();
658 #endif /* USE_VFS && USE_NETCODE */
660 #ifdef HAVE_CHARSET
661 if ( load_codepages_list() > 0 ) {
662 buffer = mc_config_get_string(mc_main_config, "Misc", "display_codepage", "");
663 if ( buffer[0] != '\0' )
665 display_codepage = get_codepage_index( buffer );
666 cp_display = get_codepage_id (display_codepage);
668 g_free(buffer);
669 buffer = mc_config_get_string(mc_main_config, "Misc", "source_codepage", "");
670 if ( buffer[0] != '\0' )
672 source_codepage = get_codepage_index( buffer );
673 cp_source = get_codepage_id (source_codepage);
675 g_free(buffer);
677 init_translation_table( source_codepage, display_codepage );
678 if ( get_codepage_id( display_codepage ) )
679 utf8_display = str_isutf8 (get_codepage_id( display_codepage ));
680 #endif /* HAVE_CHARSET */
683 #if defined(USE_VFS) && defined (USE_NETCODE)
684 char *
685 load_anon_passwd ()
687 char *buffer;
689 buffer = mc_config_get_string(mc_main_config, "Misc", "ftpfs_password", "");
690 if (buffer [0])
691 return buffer;
693 g_free(buffer);
694 return NULL;
696 #endif /* USE_VFS && USE_NETCODE */
698 void done_setup (void)
700 g_free (profile_name);
701 g_free (global_profile_name);
702 g_free(color_terminal_string);
703 g_free(term_color_string);
704 g_free(setup_color_string);
705 mc_config_deinit(mc_main_config);
706 mc_config_deinit(mc_panels_config);
707 done_hotlist ();
708 done_panelize ();
709 /* directory_history_free (); */
712 static void
713 load_keys_from_section (const char *terminal, mc_config_t *cfg)
715 char *section_name;
716 gchar **profile_keys, **keys;
717 gchar **values, **curr_values;
718 char *valcopy, *value;
719 int key_code;
720 gsize len, values_len;
722 if (!terminal)
723 return;
725 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
726 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
728 while (*profile_keys){
730 /* copy=other causes all keys from [terminal:other] to be loaded. */
731 if (g_strcasecmp (*profile_keys, "copy") == 0) {
732 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
733 load_keys_from_section (valcopy, cfg);
734 g_free(valcopy);
735 profile_keys++;
736 continue;
738 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
740 key_code = lookup_key (*profile_keys);
741 if (key_code){
742 if (curr_values){
743 while (*curr_values){
744 valcopy = convert_controls (*curr_values);
745 define_sequence (key_code, valcopy, MCKEY_NOACTION);
746 g_free (valcopy);
747 curr_values++;
749 } else {
750 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
751 valcopy = convert_controls (value);
752 define_sequence (key_code, valcopy, MCKEY_NOACTION);
753 g_free (valcopy);
754 g_free(value);
757 profile_keys++;
758 if (values)
759 g_strfreev(values);
761 g_strfreev(keys);
762 g_free (section_name);
765 void load_key_defs (void)
768 * Load keys from mc.lib before ~/.mc/ini, so that the user
769 * definitions override global settings.
771 mc_config_t *mc_global_config;
773 mc_global_config = mc_config_init(global_profile_name);
774 if (mc_global_config != NULL)
776 load_keys_from_section ("general", mc_global_config);
777 load_keys_from_section (getenv ("TERM"), mc_global_config);
778 mc_config_deinit(mc_global_config);
780 load_keys_from_section ("general", mc_main_config);
781 load_keys_from_section (getenv ("TERM"), mc_main_config);