Ticket #1725: Do not abort on broken .cpio file
[midnight-commander.git] / src / setup.c
blob34fe20563599765a8a38c28cc76a678f2463c006
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 "args.h"
38 #include "dir.h"
39 #include "panel.h"
40 #include "main.h"
41 #include "tree.h" /* xtree_mode */
42 #include "../src/mcconfig/mcconfig.h"
43 #include "setup.h"
44 #include "../src/viewer/mcviewer.h" /* For the externs */
45 #include "hotlist.h" /* load/save/done hotlist */
46 #include "panelize.h" /* load/save/done panelize */
47 #include "layout.h"
48 #include "menu.h" /* menubar_visible declaration */
49 #include "cmd.h"
50 #include "file.h" /* safe_delete */
51 #include "keybind.h" /* lookup_action */
52 #include "fileloc.h"
54 #ifdef USE_VFS
55 #include "../vfs/gc.h"
56 #endif
58 #ifdef HAVE_CHARSET
59 #include "charsets.h"
60 #endif
62 #ifdef USE_NETCODE
63 # include "../vfs/ftpfs.h"
64 # include "../vfs/fish.h"
65 #endif
67 #ifdef USE_INTERNAL_EDIT
68 # include "../edit/edit.h"
69 #endif
71 #include "../src/strutil.h" /* str_isutf8 () */
74 extern char *find_ignore_dirs;
76 extern int num_history_items_recorded;
78 char *profile_name; /* .mc/ini */
79 char *global_profile_name; /* mc.lib */
80 char *panels_profile_name; /* .mc/panels.ini */
82 char *setup_color_string;
83 char *term_color_string;
84 char *color_terminal_string;
86 int startup_left_mode;
87 int startup_right_mode;
89 /* Ugly hack to allow panel_save_setup to work as a place holder for */
90 /* default panel values */
91 int saving_setup;
93 static const struct {
94 const char *key;
95 int list_type;
96 } list_types [] = {
97 { "full", list_full },
98 { "brief", list_brief },
99 { "long", list_long },
100 { "user", list_user },
101 { 0, 0 }
104 static const struct {
105 const char *opt_name;
106 int opt_type;
107 } panel_types [] = {
108 { "listing", view_listing },
109 { "quickview", view_quick },
110 { "info", view_info },
111 { "tree", view_tree },
112 { 0, 0 }
115 static const struct {
116 const char *opt_name;
117 int *opt_addr;
118 } layout [] = {
119 { "equal_split", &equal_split },
120 { "first_panel_size", &first_panel_size },
121 { "message_visible", &message_visible },
122 { "keybar_visible", &keybar_visible },
123 { "xterm_title", &xterm_title },
124 { "output_lines", &output_lines },
125 { "command_prompt", &command_prompt },
126 { "menubar_visible", &menubar_visible },
127 { "show_mini_info", &show_mini_info },
128 { "permission_mode", &permission_mode },
129 { "filetype_mode", &filetype_mode },
130 { "free_space", &free_space },
131 { 0, 0 }
134 static const struct {
135 const char *opt_name;
136 int *opt_addr;
137 } int_options [] = {
138 { "show_backups", &show_backups },
139 { "kilobyte_si", &kilobyte_si },
140 { "show_dot_files", &show_dot_files },
141 { "verbose", &verbose },
142 { "mark_moves_down", &mark_moves_down },
143 { "pause_after_run", &pause_after_run },
144 { "shell_patterns", &easy_patterns },
145 { "auto_save_setup", &auto_save_setup },
146 { "auto_menu", &auto_menu },
147 { "use_internal_view", &use_internal_view },
148 { "use_internal_edit", &use_internal_edit },
149 { "clear_before_exec", &clear_before_exec },
150 { "mix_all_files", &mix_all_files },
151 { "fast_reload", &fast_reload },
152 { "fast_reload_msg_shown", &fast_reload_w },
153 { "confirm_delete", &confirm_delete },
154 { "confirm_overwrite", &confirm_overwrite },
155 { "confirm_execute", &confirm_execute },
156 { "confirm_exit", &confirm_exit },
157 { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete },
158 { "safe_delete", &safe_delete },
159 { "mouse_repeat_rate", &mou_auto_repeat },
160 { "double_click_speed", &double_click_speed },
161 #ifndef HAVE_CHARSET
162 { "eight_bit_clean", &eight_bit_clean },
163 { "full_eight_bits", &full_eight_bits },
164 #endif /* !HAVE_CHARSET */
165 { "use_8th_bit_as_meta", &use_8th_bit_as_meta },
166 { "confirm_view_dir", &confirm_view_dir },
167 { "mouse_move_pages", &mouse_move_pages },
168 { "mouse_move_pages_viewer", &mcview_mouse_move_pages },
169 { "mouse_close_dialog", &mouse_close_dialog},
170 { "fast_refresh", &fast_refresh },
171 { "navigate_with_arrows", &navigate_with_arrows },
172 { "drop_menus", &drop_menus },
173 { "wrap_mode", &mcview_global_wrap_mode},
174 { "old_esc_mode", &old_esc_mode },
175 { "cd_symlinks", &cd_symlinks },
176 { "show_all_if_ambiguous", &show_all_if_ambiguous },
177 { "max_dirt_limit", &mcview_max_dirt_limit },
178 { "torben_fj_mode", &torben_fj_mode },
179 { "use_file_to_guess_type", &use_file_to_check_type },
180 { "alternate_plus_minus", &alternate_plus_minus },
181 { "only_leading_plus_minus", &only_leading_plus_minus },
182 { "show_output_starts_shell", &output_starts_shell },
183 { "panel_scroll_pages", &panel_scroll_pages },
184 { "xtree_mode", &xtree_mode },
185 { "num_history_items_recorded", &num_history_items_recorded },
186 { "file_op_compute_totals", &file_op_compute_totals },
187 { "skip_check_codeset", &skip_check_codeset },
188 #ifdef USE_VFS
189 { "vfs_timeout", &vfs_timeout },
190 #ifdef USE_NETCODE
191 { "ftpfs_directory_timeout", &ftpfs_directory_timeout },
192 { "use_netrc", &use_netrc },
193 { "ftpfs_retry_seconds", &ftpfs_retry_seconds },
194 { "ftpfs_always_use_proxy", &ftpfs_always_use_proxy },
195 { "ftpfs_use_passive_connections", &ftpfs_use_passive_connections },
196 { "ftpfs_use_unix_list_options", &ftpfs_use_unix_list_options },
197 { "ftpfs_first_cd_then_ls", &ftpfs_first_cd_then_ls },
198 { "fish_directory_timeout", &fish_directory_timeout },
199 #endif /* USE_NETCODE */
200 #endif /* USE_VFS */
201 #ifdef USE_INTERNAL_EDIT
202 { "editor_word_wrap_line_length", &option_word_wrap_line_length },
203 { "editor_key_emulation", &edit_key_emulation },
204 { "editor_tab_spacing", &option_tab_spacing },
205 { "editor_fill_tabs_with_spaces", &option_fill_tabs_with_spaces },
206 { "editor_return_does_auto_indent", &option_return_does_auto_indent },
207 { "editor_backspace_through_tabs", &option_backspace_through_tabs },
208 { "editor_fake_half_tabs", &option_fake_half_tabs },
209 { "editor_option_save_mode", &option_save_mode },
210 { "editor_option_save_position", &option_save_position },
211 { "editor_option_auto_para_formatting", &option_auto_para_formatting },
212 { "editor_option_typewriter_wrap", &option_typewriter_wrap },
213 { "editor_edit_confirm_save", &edit_confirm_save },
214 { "editor_syntax_highlighting", &option_syntax_highlighting },
215 { "editor_persistent_selections", &option_persistent_selections },
216 { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },
217 { "editor_visible_tabs", &visible_tabs },
218 { "editor_visible_spaces", &visible_tws },
219 { "editor_line_state", &option_line_state },
220 { "editor_simple_statusbar", &simple_statusbar },
221 #endif /* USE_INTERNAL_EDIT */
223 { "nice_rotating_dash", &nice_rotating_dash },
224 { "horizontal_split", &horizontal_split },
225 { "mcview_remember_file_position", &mcview_remember_file_position },
226 { "auto_fill_mkdir_name", &auto_fill_mkdir_name },
227 { "reverse_files_only", &reverse_files_only },
228 { 0, 0 }
231 static const struct {
232 const char *opt_name;
233 char **opt_addr;
234 const char *opt_defval;
235 } str_options [] = {
236 #ifdef USE_INTERNAL_EDIT
237 { "editor_backup_extension", &option_backup_ext, "~" },
238 #endif
239 { NULL, NULL, NULL }
242 void
243 panel_save_setup (struct WPanel *panel, const char *section)
245 char *buffer;
246 int i;
248 mc_config_set_int(mc_panels_config, section, "reverse", panel->reverse);
249 mc_config_set_int(mc_panels_config, section, "case_sensitive", panel->case_sensitive);
250 mc_config_set_int(mc_panels_config, section, "exec_first", panel->exec_first);
253 mc_config_set_string(mc_panels_config, section, "sort_order", panel->current_sort_field->id);
255 for (i = 0; list_types [i].key; i++)
256 if (list_types [i].list_type == panel->list_type){
257 mc_config_set_string(mc_panels_config, section, "list_mode", list_types [i].key);
258 break;
261 mc_config_set_string(mc_panels_config, section, "user_format", panel->user_format);
263 for (i = 0; i < LIST_TYPES; i++){
264 buffer = g_strdup_printf("user_status%d", i);
265 mc_config_set_string(mc_panels_config, section, buffer, panel->user_status_format [i]);
266 g_free(buffer);
269 mc_config_set_int(mc_panels_config, section, "user_mini_status", panel->user_mini_status);
272 void
273 save_layout (void)
275 char *profile;
276 int i;
278 profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
280 /* Save integer options */
281 for (i = 0; layout [i].opt_name; i++){
282 mc_config_set_int(mc_main_config, "Layout", layout [i].opt_name, *layout [i].opt_addr);
284 mc_config_save_to_file (mc_main_config, profile);
286 g_free (profile);
289 void
290 save_configure (void)
292 char *profile;
293 int i;
295 profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
297 /* Save integer options */
298 for (i = 0; int_options[i].opt_name; i++)
299 mc_config_set_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
301 /* Save string options */
302 for (i = 0; str_options[i].opt_name != NULL; i++)
303 mc_config_set_string(mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, *str_options[i].opt_addr);
305 mc_config_save_to_file (mc_main_config, profile);
306 g_free (profile);
309 static void
310 panel_save_type (const char *section, int type)
312 int i;
314 for (i = 0; panel_types [i].opt_name; i++)
315 if (panel_types [i].opt_type == type){
316 mc_config_set_string(mc_panels_config, section,
317 "display", panel_types [i].opt_name);
318 break;
322 void
323 save_panel_types (void)
325 int type;
327 type = get_display_type (0);
328 panel_save_type ("New Left Panel", type);
329 if (type == view_listing)
330 panel_save_setup (left_panel, left_panel->panel_name);
331 type = get_display_type (1);
332 panel_save_type ("New Right Panel", type);
333 if (type == view_listing)
334 panel_save_setup (right_panel, right_panel->panel_name);
336 mc_config_set_string (mc_panels_config, "Dirs" , "other_dir",
337 get_panel_dir_for (other_panel));
339 if (current_panel != NULL)
340 mc_config_set_string (mc_panels_config, "Dirs" , "current_is_left",
341 get_current_index () == 0 ? "1" : "0");
343 if (mc_panels_config->ini_path == NULL)
344 mc_panels_config->ini_path = g_strdup(panels_profile_name);
346 mc_config_del_group (mc_panels_config, "Temporal:New Left Panel");
347 mc_config_del_group (mc_panels_config, "Temporal:New Right Panel");
349 mc_config_save_file (mc_panels_config);
352 void
353 save_setup (void)
355 char *tmp_profile;
357 saving_setup = 1;
359 save_configure ();
361 save_layout ();
363 save_hotlist ();
365 save_panelize ();
366 save_panel_types ();
367 /* directory_history_save (); */
369 #if defined(USE_VFS) && defined (USE_NETCODE)
370 mc_config_set_string(mc_main_config, "Misc" , "ftpfs_password",
371 ftpfs_anonymous_passwd);
372 if (ftpfs_proxy_host)
373 mc_config_set_string(mc_main_config, "Misc" , "ftp_proxy_host",
374 ftpfs_proxy_host);
375 #endif /* USE_VFS && USE_NETCODE */
377 #ifdef HAVE_CHARSET
378 mc_config_set_string(mc_main_config, "Misc" , "display_codepage",
379 get_codepage_id( display_codepage ));
380 mc_config_set_string(mc_main_config, "Misc" , "source_codepage",
381 get_codepage_id( source_codepage ));
382 #endif /* HAVE_CHARSET */
383 tmp_profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
384 mc_config_save_to_file (mc_main_config, tmp_profile);
385 g_free (tmp_profile);
386 saving_setup = 0;
389 void
390 panel_load_setup (WPanel *panel, const char *section)
392 int i;
393 char *buffer;
395 panel->reverse = mc_config_get_int(mc_panels_config, section, "reverse", 0);
396 panel->case_sensitive = mc_config_get_int(mc_panels_config, section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT);
397 panel->exec_first = mc_config_get_int(mc_panels_config, section, "exec_first", 0);
399 /* Load sort order */
400 buffer = mc_config_get_string(mc_panels_config, section, "sort_order", "name");
401 panel->current_sort_field = panel_get_field_by_id(buffer);
402 g_free(buffer);
404 /* Load the listing mode */
405 buffer = mc_config_get_string(mc_panels_config, section, "list_mode", "full");
406 panel->list_type = list_full;
407 for (i = 0; list_types [i].key; i++)
408 if ( g_strcasecmp (list_types [i].key, buffer) == 0){
409 panel->list_type = list_types [i].list_type;
410 break;
412 g_free(buffer);
414 /* User formats */
415 g_free (panel->user_format);
416 panel->user_format = mc_config_get_string(mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT);
418 for (i = 0; i < LIST_TYPES; i++){
419 g_free (panel->user_status_format [i]);
420 buffer = g_strdup_printf("user_status%d",i);
421 panel->user_status_format [i] =
422 mc_config_get_string(mc_panels_config, section, buffer, DEFAULT_USER_FORMAT);
423 g_free(buffer);
426 panel->user_mini_status =
427 mc_config_get_int(mc_panels_config, section, "user_mini_status", 0);
431 static void
432 load_layout ()
434 int i;
436 for (i = 0; layout [i].opt_name; i++)
437 *layout [i].opt_addr =
438 mc_config_get_int(mc_main_config,"Layout", layout [i].opt_name, *layout [i].opt_addr);
441 static int
442 setup__load_panel_state (const char *section)
444 char *buffer;
445 int i;
447 int mode = view_listing;
449 /* Load the display mode */
450 buffer = mc_config_get_string(mc_panels_config, section, "display", "listing");
452 for (i = 0; panel_types [i].opt_name; i++)
453 if ( g_strcasecmp (panel_types [i].opt_name, buffer) == 0){
454 mode = panel_types [i].opt_type;
455 break;
457 g_free(buffer);
458 return mode;
461 static const char *
462 setup__is_cfg_group_must_panel_config(const char *grp)
464 if (
465 ! strcasecmp("Dirs",grp) ||
466 ! strcasecmp("Temporal:New Right Panel",grp) ||
467 ! strcasecmp("Temporal:New Left Panel",grp) ||
468 ! strcasecmp("New Left Panel",grp) ||
469 ! strcasecmp("New Right Panel",grp)
471 return grp;
472 return NULL;
475 static void
476 setup__move_panels_config_into_separate_file(const char*profile)
478 mc_config_t *tmp_cfg;
479 char **groups, **curr_grp;
480 const char *need_grp;
481 gsize groups_count;
483 if (!exist_file(profile))
484 return;
486 tmp_cfg = mc_config_init(profile);
487 if (!tmp_cfg)
488 return;
490 curr_grp = groups = mc_config_get_groups (tmp_cfg, &groups_count);
491 if (!groups)
493 mc_config_deinit(tmp_cfg);
494 return;
496 while (*curr_grp)
498 if ( setup__is_cfg_group_must_panel_config(*curr_grp) == NULL)
500 mc_config_del_group (tmp_cfg, *curr_grp);
502 curr_grp++;
505 mc_config_save_to_file (tmp_cfg, panels_profile_name);
506 mc_config_deinit(tmp_cfg);
508 tmp_cfg = mc_config_init(profile);
509 if (!tmp_cfg)
511 g_strfreev(groups);
512 return;
515 curr_grp = groups;
517 while (*curr_grp)
519 need_grp = setup__is_cfg_group_must_panel_config(*curr_grp);
520 if ( need_grp != NULL)
522 mc_config_del_group (tmp_cfg, need_grp);
524 curr_grp++;
526 g_strfreev(groups);
527 mc_config_save_file (tmp_cfg);
528 mc_config_deinit(tmp_cfg);
533 Get name of config file.
535 \param subdir
536 if not NULL, then config also search into specified subdir
538 \param config_file_name
539 If specified filename is relative, then will search in standart patches.
541 \return
542 Newly allocated path to config name or NULL if file not found
544 If config_file_name is a relative path, then search config in stantart pathes */
545 static char*
546 load_setup_get_full_config_name(const char *subdir, const char *config_file_name)
549 TODO: IMHO, in future this function must be placed into mc_config module.
550 Also, need to rename stupid mc_home and mc_home_alt to mc_sysconfdir and mc_datadir;
551 home_mc => mc_user_homedir
553 char *basename, *ret;
555 if (config_file_name == NULL)
556 return NULL;
558 if (g_path_is_absolute (config_file_name))
559 return g_strdup(config_file_name);
562 basename = g_path_get_basename(config_file_name);
563 if (basename == NULL)
564 return NULL;
567 if (subdir)
568 ret = g_build_filename (home_dir, MC_USERCONF_DIR, subdir, basename, NULL);
569 else
570 ret = g_build_filename (home_dir, MC_USERCONF_DIR, basename, NULL);
572 if (exist_file(ret)) {
573 g_free(basename);
574 return ret;
576 g_free(ret);
579 if (subdir)
580 ret = g_build_filename (mc_home, subdir, basename, NULL);
581 else
582 ret = g_build_filename (mc_home, basename, NULL);
584 if (exist_file(ret)) {
585 g_free(basename);
586 return ret;
588 g_free(ret);
590 if (subdir)
591 ret = g_build_filename (mc_home_alt, subdir, basename, NULL);
592 else
593 ret = g_build_filename (mc_home_alt, basename, NULL);
595 if (exist_file(ret)) {
596 g_free(basename);
597 return ret;
599 g_free(ret);
600 g_free(basename);
601 return NULL;
606 Create new mc_config object from specified ini-file or
607 append data to existing mc_config object from ini-file
610 static void
611 load_setup_init_config_from_file(mc_config_t **config, const char *fname)
614 TODO: IMHO, in future this function must be placed into mc_config module.
616 if (exist_file(fname)) {
617 if (*config)
618 mc_config_read_file( *config, fname);
619 else
620 *config = mc_config_init(fname);
626 static mc_config_t *
627 load_setup_get_keymap_profile_config(void)
630 TODO: IMHO, in future this function must be placed into mc_config module.
632 mc_config_t *keymap_config = NULL ;
634 char *fname, *fname2;
636 /* 1) /usr/share/mc (mc_home_alt) */
637 fname = g_build_filename (mc_home_alt, GLOBAL_KEYMAP_FILE, NULL);
638 load_setup_init_config_from_file( &keymap_config, fname);
639 g_free(fname);
641 /* 2) /etc/mc (mc_home) */
642 fname = g_build_filename (mc_home, GLOBAL_KEYMAP_FILE, NULL);
643 load_setup_init_config_from_file( &keymap_config, fname);
644 g_free(fname);
646 /* 3) ~/.mc (home_dir?) */
647 fname = g_build_filename (home_dir, MC_USERCONF_DIR, GLOBAL_KEYMAP_FILE, NULL);
648 load_setup_init_config_from_file( &keymap_config, fname);
649 g_free(fname);
651 /* 4) main config; [Midnight Commander] -> keymap*/
653 fname2 = mc_config_get_string(mc_main_config, CONFIG_APP_SECTION, "keymap" , GLOBAL_KEYMAP_FILE);
654 fname = load_setup_get_full_config_name(NULL, fname2);
655 if (fname)
657 load_setup_init_config_from_file( &keymap_config, fname);
658 g_free(fname);
660 g_free(fname2);
662 /* 5) getenv("MC_KEYMAP") */
663 fname = load_setup_get_full_config_name(NULL, g_getenv ("MC_KEYMAP"));
664 if (fname)
666 load_setup_init_config_from_file( &keymap_config, fname);
667 g_free(fname);
670 /* 6) --keymap=<keymap> */
671 fname = load_setup_get_full_config_name(NULL, mc_args__keymap_file);
672 if (fname)
674 load_setup_init_config_from_file( &keymap_config, fname);
675 g_free(fname);
678 return keymap_config;
681 char *
682 setup_init (void)
684 char *profile;
685 char *inifile;
687 if (profile_name)
688 return profile_name;
690 profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
691 if (!exist_file (profile)){
692 inifile = concat_dir_and_file (mc_home, "mc.ini");
693 if (exist_file (inifile)){
694 g_free (profile);
695 profile = inifile;
696 } else {
697 g_free (inifile);
698 inifile = concat_dir_and_file (mc_home_alt, "mc.ini");
699 if (exist_file (inifile)) {
700 g_free (profile);
701 profile = inifile;
702 } else
703 g_free (inifile);
707 profile_name = profile;
709 return profile;
712 void
713 load_setup (void)
715 char *profile;
716 int i;
717 char *buffer;
719 profile = setup_init ();
721 /* mc.lib is common for all users, but has priority lower than
722 ~/.mc/ini. FIXME: it's only used for keys and treestore now */
723 global_profile_name = concat_dir_and_file (mc_home, MC_GLOBAL_CONFIG_FILE);
724 if (!exist_file(global_profile_name)) {
725 g_free (global_profile_name);
726 global_profile_name = concat_dir_and_file (mc_home_alt, MC_GLOBAL_CONFIG_FILE);
729 panels_profile_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_PANELS_FILE, NULL);
731 mc_main_config = mc_config_init(profile);
733 if (!exist_file(panels_profile_name))
734 setup__move_panels_config_into_separate_file(profile);
736 mc_panels_config = mc_config_init(panels_profile_name);
738 /* Load integer boolean options */
739 for (i = 0; int_options[i].opt_name; i++)
740 *int_options[i].opt_addr =
741 mc_config_get_int(mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr);
743 /* Load string options */
744 for (i = 0; str_options[i].opt_name != NULL; i++)
745 *str_options[i].opt_addr =
746 mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, str_options[i].opt_defval);
748 load_layout ();
750 load_panelize ();
752 startup_left_mode = setup__load_panel_state ("New Left Panel");
753 startup_right_mode = setup__load_panel_state ("New Right Panel");
755 /* At least one of the panels is a listing panel */
756 if (startup_left_mode != view_listing && startup_right_mode!=view_listing)
757 startup_left_mode = view_listing;
759 if (!other_dir){
760 buffer = mc_config_get_string(mc_panels_config, "Dirs", "other_dir", ".");
761 if (vfs_file_is_local (buffer))
762 other_dir = buffer;
763 else
764 g_free (buffer);
767 boot_current_is_left =
768 mc_config_get_int(mc_panels_config, "Dirs", "current_is_left", 1);
770 #ifdef USE_NETCODE
771 ftpfs_proxy_host = mc_config_get_string(mc_main_config, "Misc", "ftp_proxy_host", "gate");
772 #endif
773 setup_color_string = mc_config_get_string(mc_main_config, "Misc", "find_ignore_dirs", "");
774 if (setup_color_string [0])
775 find_ignore_dirs = g_strconcat (":", setup_color_string, ":", (char *) NULL);
776 g_free(setup_color_string);
778 /* The default color and the terminal dependent color */
779 setup_color_string = mc_config_get_string(mc_main_config, "Colors", "base_color", "");
780 term_color_string = mc_config_get_string(mc_main_config, "Colors", getenv ("TERM"), "");
781 color_terminal_string = mc_config_get_string(mc_main_config, "Colors", "color_terminals", "");
783 /* Load the directory history */
784 /* directory_history_load (); */
785 /* Remove the temporal entries */
786 #if defined(USE_VFS) && defined (USE_NETCODE)
787 ftpfs_init_passwd ();
788 #endif /* USE_VFS && USE_NETCODE */
790 #ifdef HAVE_CHARSET
791 if ( load_codepages_list() > 0 ) {
792 buffer = mc_config_get_string(mc_main_config, "Misc", "display_codepage", "");
793 if ( buffer[0] != '\0' )
795 display_codepage = get_codepage_index( buffer );
796 cp_display = get_codepage_id (display_codepage);
798 g_free(buffer);
799 buffer = mc_config_get_string(mc_main_config, "Misc", "source_codepage", "");
800 if ( buffer[0] != '\0' )
802 source_codepage = get_codepage_index( buffer );
803 cp_source = get_codepage_id (source_codepage);
805 g_free(buffer);
807 init_translation_table( source_codepage, display_codepage );
808 if ( get_codepage_id( display_codepage ) )
809 utf8_display = str_isutf8 (get_codepage_id( display_codepage ));
810 #endif /* HAVE_CHARSET */
813 #if defined(USE_VFS) && defined (USE_NETCODE)
814 char *
815 load_anon_passwd ()
817 char *buffer;
819 buffer = mc_config_get_string(mc_main_config, "Misc", "ftpfs_password", "");
820 if (buffer [0])
821 return buffer;
823 g_free(buffer);
824 return NULL;
826 #endif /* USE_VFS && USE_NETCODE */
828 void done_setup (void)
830 g_free (profile_name);
831 g_free (global_profile_name);
832 g_free(color_terminal_string);
833 g_free(term_color_string);
834 g_free(setup_color_string);
835 mc_config_deinit(mc_main_config);
836 mc_config_deinit(mc_panels_config);
837 done_hotlist ();
838 done_panelize ();
839 /* directory_history_free (); */
842 static void
843 load_keys_from_section (const char *terminal, mc_config_t *cfg)
845 char *section_name;
846 gchar **profile_keys, **keys;
847 gchar **values, **curr_values;
848 char *valcopy, *value;
849 int key_code;
850 gsize len, values_len;
852 if (!terminal)
853 return;
855 section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
856 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
858 while (*profile_keys){
860 /* copy=other causes all keys from [terminal:other] to be loaded. */
861 if (g_strcasecmp (*profile_keys, "copy") == 0) {
862 valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
863 load_keys_from_section (valcopy, cfg);
864 g_free(valcopy);
865 profile_keys++;
866 continue;
868 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
870 key_code = lookup_key (*profile_keys);
871 if (key_code){
872 if (curr_values){
873 while (*curr_values){
874 valcopy = convert_controls (*curr_values);
875 define_sequence (key_code, valcopy, MCKEY_NOACTION);
876 g_free (valcopy);
877 curr_values++;
879 } else {
880 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
881 valcopy = convert_controls (value);
882 define_sequence (key_code, valcopy, MCKEY_NOACTION);
883 g_free (valcopy);
884 g_free(value);
887 profile_keys++;
888 if (values)
889 g_strfreev(values);
891 g_strfreev(keys);
892 g_free (section_name);
895 void load_key_defs (void)
898 * Load keys from mc.lib before ~/.mc/ini, so that the user
899 * definitions override global settings.
901 mc_config_t *mc_global_config;
903 mc_global_config = mc_config_init(global_profile_name);
904 if (mc_global_config != NULL)
906 load_keys_from_section ("general", mc_global_config);
907 load_keys_from_section (getenv ("TERM"), mc_global_config);
908 mc_config_deinit(mc_global_config);
910 load_keys_from_section ("general", mc_main_config);
911 load_keys_from_section (getenv ("TERM"), mc_main_config);
915 static void
916 load_keymap_from_section (const char *section_name, GArray *keymap, mc_config_t *cfg)
918 gchar **profile_keys, **keys;
919 gchar **values, **curr_values;
920 char *valcopy, *value;
921 int action;
922 gsize len, values_len;
924 if (!section_name)
925 return;
927 profile_keys = keys = mc_config_get_keys (cfg, section_name, &len);
929 while (*profile_keys) {
930 curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &values_len);
931 action = lookup_action (*profile_keys);
932 if (action>0) {
933 if (curr_values){
934 while (*curr_values){
935 valcopy = convert_controls (*curr_values);
936 keybind_cmd_bind (keymap, valcopy, action);
937 g_free (valcopy);
938 curr_values++;
940 } else {
941 value = mc_config_get_string (cfg, section_name, *profile_keys, "");
942 valcopy = convert_controls (value);
943 //define_sequence (key_code, valcopy, MCKEY_NOACTION);
944 g_free (valcopy);
945 g_free(value);
948 profile_keys++;
949 if (values)
950 g_strfreev(values);
952 g_strfreev(keys);
955 void
956 load_keymap_defs (void)
959 * Load keymap from GLOBAL_KEYMAP_FILE before ~/.mc/keymap, so that the user
960 * definitions override global settings.
962 mc_config_t *mc_global_keymap;
964 mc_global_keymap = load_setup_get_keymap_profile_config();
966 if (mc_global_keymap != NULL)
968 editor_keymap = g_array_new(TRUE, FALSE, sizeof(global_key_map_t));
969 load_keymap_from_section ("editor", editor_keymap, mc_global_keymap);
971 viewer_keymap = g_array_new(TRUE, FALSE, sizeof(global_key_map_t));
972 load_keymap_from_section ("viewer", viewer_keymap, mc_global_keymap);
974 viewer_hex_keymap = g_array_new(TRUE, FALSE, sizeof(global_key_map_t));
975 load_keymap_from_section ("viewer:hex", viewer_hex_keymap, mc_global_keymap);
977 main_keymap = g_array_new(TRUE, FALSE, sizeof(global_key_map_t));
978 load_keymap_from_section ("main", main_keymap, mc_global_keymap);
980 main_x_keymap = g_array_new(TRUE, FALSE, sizeof(global_key_map_t));
981 load_keymap_from_section ("main:xmap", main_x_keymap, mc_global_keymap);
983 panel_keymap = g_array_new(TRUE, FALSE, sizeof(global_key_map_t));
984 load_keymap_from_section ("panel", panel_keymap, mc_global_keymap);
986 input_keymap = g_array_new(TRUE, FALSE, sizeof(global_key_map_t));
987 load_keymap_from_section ("input", input_keymap, mc_global_keymap);
989 mc_config_deinit(mc_global_keymap);