static void load_layout (void) { size_t i; int equal_split; int first_panel_size; /* legacy options */ panels_layout.horizontal_split = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, "horizontal_split", 0); equal_split = mc_config_get_int (mc_main_config, "Layout", "equal_split", 1); first_panel_size = mc_config_get_int (mc_main_config, "Layout", "first_panel_size", 1); if (panels_layout.horizontal_split) { panels_layout.horizontal_equal = equal_split; panels_layout.left_panel_size = first_panel_size; } else { panels_layout.vertical_equal = equal_split; panels_layout.top_panel_size = first_panel_size; } /* actual options override legacy ones */ for (i = 0; layout[i].opt_name != NULL; i++) *layout[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name, *layout[i].opt_addr); /* remove legacy options */ mc_config_del_key (mc_main_config, CONFIG_APP_SECTION, "horizontal_split"); mc_config_del_key (mc_main_config, "Layout", "equal_split"); mc_config_del_key (mc_main_config, "Layout", "first_panel_size"); }
/** Load panels options from [Panels] section. */ void panels_load_options (void) { if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION)) { size_t i; int qmode; for (i = 0; panels_ini_options[i].opt_name != NULL; i++) *panels_ini_options[i].opt_addr = mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION, panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr); qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION, "quick_search_mode", (int) panels_options.qsearch_mode); if (qmode < 0) panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE; else if (qmode >= QSEARCH_NUM) panels_options.qsearch_mode = QSEARCH_PANEL_CASE; else panels_options.qsearch_mode = (qsearch_mode_t) qmode; panels_options.select_flags = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION, "select_flags", (int) panels_options.select_flags); } }
void panel_load_setup (WPanel * panel, const char *section) { size_t i; char *buffer, buffer2[BUF_TINY]; panel->sort_info.reverse = mc_config_get_int (mc_panels_config, section, "reverse", 0); panel->sort_info.case_sensitive = mc_config_get_int (mc_panels_config, section, "case_sensitive", OS_SORT_CASE_SENSITIVE_DEFAULT); panel->sort_info.exec_first = mc_config_get_int (mc_panels_config, section, "exec_first", 0); /* Load sort order */ buffer = mc_config_get_string (mc_panels_config, section, "sort_order", "name"); panel->sort_field = panel_get_field_by_id (buffer); if (panel->sort_field == NULL) panel->sort_field = panel_get_field_by_id ("name"); g_free (buffer); /* Load the listing mode */ buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full"); panel->list_type = list_full; for (i = 0; list_types[i].key != NULL; i++) if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0) { panel->list_type = list_types[i].list_type; break; } g_free (buffer); /* User formats */ g_free (panel->user_format); panel->user_format = mc_config_get_string (mc_panels_config, section, "user_format", DEFAULT_USER_FORMAT); for (i = 0; i < LIST_TYPES; i++) { g_free (panel->user_status_format[i]); g_snprintf (buffer2, BUF_TINY, "user_status%lld", (long long) i); panel->user_status_format[i] = mc_config_get_string (mc_panels_config, section, buffer2, DEFAULT_USER_FORMAT); } panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0); }
/* *INDENT-OFF* */ END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ /* *INDENT-OFF* */ START_TEST (test_deserialize_config) /* *INDENT-ON* */ { /* given */ mc_config_t *actual; char *actual_value; /* when */ actual = mc_deserialize_config (deserialize_input_value1, &error); /* then */ mctest_assert_not_null (actual); actual_value = mc_config_get_string_raw (actual, "group1", "param1", ""); mctest_assert_str_eq (actual_value, "some value"); g_free (actual_value); actual_value = mc_config_get_string (actual, "group1", "param2", ""); mctest_assert_str_eq (actual_value, "some value "); g_free (actual_value); mctest_assert_int_eq (mc_config_get_bool (actual, "group2", "param1", FALSE), TRUE); mctest_assert_int_eq (mc_config_get_int (actual, "group2", "param2", 0), 123456); actual_value = mc_config_get_string_raw (actual, "group3", "param1", ""); mctest_assert_str_eq (actual_value, "::bla-bla::"); g_free (actual_value); actual_value = mc_config_get_string (actual, "group3", "param2", ""); mctest_assert_str_eq (actual_value, "bla-:p1:w:v2:12:g3:123:bla-bla\n"); g_free (actual_value); mctest_assert_int_eq (mc_config_get_bool (actual, "group4", "param1", TRUE), FALSE); mctest_assert_int_eq (mc_config_get_int (actual, "group4", "param2", 0), 654321); mc_config_deinit (actual); }
static void load_layout (void) { size_t i; for (i = 0; layout[i].opt_name != NULL; i++) *layout[i].opt_addr = mc_config_get_int (mc_main_config, "Layout", layout[i].opt_name, *layout[i].opt_addr); }
void save_file_position (const vfs_path_t * filename_vpath, long line, long column, off_t offset, GArray * bookmarks) { static size_t filepos_max_saved_entries = 0; char *fn, *tmp_fn; FILE *f, *tmp_f; char buf[MC_MAXPATHLEN + 100]; size_t i; const size_t len = vfs_path_len (filename_vpath); gboolean src_error = FALSE; if (filepos_max_saved_entries == 0) filepos_max_saved_entries = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, "filepos_max_saved_entries", 1024); fn = mc_config_get_full_path (MC_FILEPOS_FILE); if (fn == NULL) goto early_error; mc_util_make_backup_if_possible (fn, TMP_SUFFIX); /* open file */ f = fopen (fn, "w"); if (f == NULL) goto open_target_error; tmp_fn = g_strdup_printf ("%s" TMP_SUFFIX, fn); tmp_f = fopen (tmp_fn, "r"); if (tmp_f == NULL) { src_error = TRUE; goto open_source_error; } /* put the new record */ if (line != 1 || column != 0 || bookmarks != NULL) { if (fprintf (f, "%s %ld;%ld;%" PRIuMAX, vfs_path_as_str (filename_vpath), line, column, (uintmax_t) offset) < 0) goto write_position_error; if (bookmarks != NULL) for (i = 0; i < bookmarks->len && i < MAX_SAVED_BOOKMARKS; i++) if (fprintf (f, ";%zu", g_array_index (bookmarks, size_t, i)) < 0) goto write_position_error; if (fprintf (f, "\n") < 0) goto write_position_error; } i = 1; while (fgets (buf, sizeof (buf), tmp_f) != NULL) { if (buf[len] == ' ' && strncmp (buf, vfs_path_as_str (filename_vpath), len) == 0 && strchr (&buf[len + 1], ' ') == NULL) continue; fprintf (f, "%s", buf); if (++i > filepos_max_saved_entries) break; } write_position_error: fclose (tmp_f); open_source_error: g_free (tmp_fn); fclose (f); if (src_error) mc_util_restore_from_backup_if_possible (fn, TMP_SUFFIX); else mc_util_unlink_backup_if_possible (fn, TMP_SUFFIX); open_target_error: g_free (fn); early_error: if (bookmarks != NULL) g_array_free (bookmarks, TRUE); }
END_TEST /* --------------------------------------------------------------------------------------------- */ #undef deserialize_check_incorrect #define deserialize_check_incorrect( etalon_code, etalon_str ) { \ if (actual != NULL) \ { \ fail("actual value but should be NULL", actual); \ mc_config_deinit(actual); \ } \ else \ { \ fail_unless (error->code == etalon_code && strcmp(error->message, etalon_str) == 0, \ "\nerror code is %d (should be %d);\nerror message is '%s' (should be '%s')", \ error->code, etalon_code, error->message, etalon_str); \ g_clear_error(&error); \ } \ } START_TEST (test_deserialize_config) { mc_config_t *actual; GError *error = NULL; char *actual_value; actual = mc_deserialize_config ("g123error in group name", &error); deserialize_check_incorrect( -3, "mc_deserialize_config() at 1: mc_serialize_str(): Length delimiter ':' doesn't exists"); actual = mc_deserialize_config ("p6:param1v10:some valuep6:param2v11:some value ", &error); deserialize_check_incorrect( -2, "mc_deserialize_config() at 1: mc_serialize_str(): String prefix doesn't equal to 'g'"); actual = mc_deserialize_config ("g6:group1v10:some valuep6:param2v11:some value ", &error); deserialize_check_incorrect( -2, "mc_deserialize_config() at 10: mc_serialize_str(): String prefix doesn't equal to 'p'"); actual = mc_deserialize_config ("g6:group1p6000:param2v11:some value ", &error); deserialize_check_incorrect( -3, "mc_deserialize_config() at 10: mc_serialize_str(): Specified data length (6000) is greater than actual data length (21)"); actual = mc_deserialize_config (etalon_str, &error); if (actual == NULL) { fail("actual value is NULL!\nError code is '%d'; error message is '%s'", error->code, error->message); g_clear_error(&error); return; } actual_value = mc_config_get_string_raw(actual, "group1", "param1", ""); fail_unless( strcmp(actual_value, "some value") == 0, "group1->param1(%s) should be equal to 'some value'", actual_value); g_free(actual_value); actual_value = mc_config_get_string(actual, "group1", "param2", ""); fail_unless( strcmp(actual_value, "some value ") == 0, "group1->param2(%s) should be equal to 'some value '", actual_value); g_free(actual_value); fail_unless( mc_config_get_bool(actual, "group2", "param1", FALSE) == TRUE, "group2->param1(FALSE) should be equal to TRUE"); fail_unless( mc_config_get_int(actual, "group2", "param2", 0) == 123456, "group2->param2(%d) should be equal to 123456", mc_config_get_int(actual, "group2", "param2", 0)); actual_value = mc_config_get_string_raw(actual, "group3", "param1", ""); fail_unless( strcmp(actual_value, "::bla-bla::") == 0, "group3->param1(%s) should be equal to '::bla-bla::'", actual_value); g_free(actual_value); actual_value = mc_config_get_string(actual, "group3", "param2", ""); fail_unless( strcmp(actual_value, "bla-:p1:w:v2:12:g3:123:bla-bla\n") == 0, "group3->param2(%s) should be equal to 'bla-:p1:w:v2:12:g3:123:bla-bla\n'", actual_value); g_free(actual_value); fail_unless( mc_config_get_bool(actual, "group4", "param1", TRUE) == FALSE, "group4->param1(TRUE) should be equal to FALSE"); fail_unless( mc_config_get_int(actual, "group4", "param2", 0) == 654321, "group4->param2(%d) should be equal to 654321", mc_config_get_int(actual, "group4", "param2", 0)); mc_config_deinit (actual); }
void load_setup (void) { const char *profile; size_t i; const char *kt; #ifdef HAVE_CHARSET char *buffer; load_codepages_list (); #endif /* HAVE_CHARSET */ profile = setup_init (); /* mc.lib is common for all users, but has priority lower than ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */ global_profile_name = g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL); if (!exist_file (global_profile_name)) { g_free (global_profile_name); global_profile_name = g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL); } panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE); mc_main_config = mc_config_init (profile, FALSE); if (!exist_file (panels_profile_name)) setup__move_panels_config_into_separate_file (profile); mc_panels_config = mc_config_init (panels_profile_name, FALSE); /* Load integer boolean options */ for (i = 0; int_options[i].opt_name != NULL; i++) *int_options[i].opt_addr = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, *int_options[i].opt_addr); #ifndef USE_INTERNAL_EDIT /* reset forced in case of build without internal editor */ use_internal_edit = 0; #endif /* USE_INTERNAL_EDIT */ if (option_tab_spacing <= 0) option_tab_spacing = DEFAULT_TAB_SPACING; #ifdef USE_INTERNAL_EDIT if (option_word_wrap_line_length <= 0) option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH; #endif /* USE_INTERNAL_EDIT */ /* overwrite old_esc_mode_timeout */ kt = getenv ("KEYBOARD_KEY_TIMEOUT_US"); if ((kt != NULL) && (kt[0] != '\0')) old_esc_mode_timeout = atoi (kt); /* Load string options */ for (i = 0; str_options[i].opt_name != NULL; i++) *str_options[i].opt_addr = mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, str_options[i].opt_defval); load_layout (); panels_load_options (); load_panelize (); startup_left_mode = setup__load_panel_state ("New Left Panel"); startup_right_mode = setup__load_panel_state ("New Right Panel"); /* At least one of the panels is a listing panel */ if (startup_left_mode != view_listing && startup_right_mode != view_listing) startup_left_mode = view_listing; boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE); /* Load time formats */ user_recent_timeformat = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME); user_old_timeformat = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR); #ifdef ENABLE_VFS_FTP ftpfs_proxy_host = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate"); ftpfs_ignore_chattr_errors = mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE); ftpfs_init_passwd (); #endif /* ENABLE_VFS_FTP */ /* The default color and the terminal dependent color */ mc_global.tty.setup_color_string = mc_config_get_string (mc_main_config, "Colors", "base_color", ""); mc_global.tty.term_color_string = mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), ""); mc_global.tty.color_terminal_string = mc_config_get_string (mc_main_config, "Colors", "color_terminals", ""); /* Load the directory history */ /* directory_history_load (); */ /* Remove the temporal entries */ #ifdef HAVE_CHARSET if (codepages->len > 1) { buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", ""); if (buffer[0] != '\0') { mc_global.display_codepage = get_codepage_index (buffer); cp_display = get_codepage_id (mc_global.display_codepage); } g_free (buffer); buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", ""); if (buffer[0] != '\0') { default_source_codepage = get_codepage_index (buffer); mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */ cp_source = get_codepage_id (mc_global.source_codepage); } g_free (buffer); } autodetect_codeset = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", ""); if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0)) is_autodetect_codeset_enabled = TRUE; g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage)); buffer = (char *) get_codepage_id (mc_global.display_codepage); if (buffer != NULL) mc_global.utf8_display = str_isutf8 (buffer); #endif /* HAVE_CHARSET */ #ifdef HAVE_ASPELL spell_language = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en"); #endif /* HAVE_ASPELL */ clipboard_store_path = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", ""); clipboard_paste_path = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", ""); }