static gboolean mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir) { char *file_name, *file_name2; file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, (char *) NULL); if (exist_file (file_name)) { mc_skin->config = mc_config_init (file_name, TRUE); g_free (file_name); return (mc_skin->config != NULL); } g_free (file_name); file_name2 = g_strdup_printf ("%s.ini", mc_skin->name); file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, file_name2, (char *) NULL); g_free (file_name2); if (exist_file (file_name)) { mc_skin->config = mc_config_init (file_name, TRUE); g_free (file_name); return (mc_skin->config != NULL); } g_free (file_name); return FALSE; }
static void setup__move_panels_config_into_separate_file (const char *profile) { mc_config_t *tmp_cfg; char **groups, **curr_grp; if (!exist_file (profile)) return; tmp_cfg = mc_config_init (profile, FALSE); if (!tmp_cfg) return; curr_grp = groups = mc_config_get_groups (tmp_cfg, NULL); if (!groups) { mc_config_deinit (tmp_cfg); return; } while (*curr_grp) { if (setup__is_cfg_group_must_panel_config (*curr_grp) == NULL) mc_config_del_group (tmp_cfg, *curr_grp); curr_grp++; } mc_config_save_to_file (tmp_cfg, panels_profile_name, NULL); mc_config_deinit (tmp_cfg); tmp_cfg = mc_config_init (profile, FALSE); if (!tmp_cfg) { g_strfreev (groups); return; } curr_grp = groups; while (*curr_grp) { const char *need_grp; need_grp = setup__is_cfg_group_must_panel_config (*curr_grp); if (need_grp != NULL) { mc_config_del_group (tmp_cfg, need_grp); } curr_grp++; } g_strfreev (groups); mc_config_save_file (tmp_cfg, NULL); mc_config_deinit (tmp_cfg); }
gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path) { mc_config_t *tmp_config; gchar **groups, **curr_grp; gchar **keys, **curr_key; gchar *value; if (mc_config == NULL) { return FALSE; } tmp_config = mc_config_init (ini_path); if (tmp_config == NULL) return FALSE; groups = mc_config_get_groups (tmp_config, NULL); for (curr_grp = groups; *curr_grp != NULL; curr_grp++) { keys = mc_config_get_keys (tmp_config, *curr_grp, NULL); for (curr_key = keys; *curr_key != NULL; curr_key++) { value = g_key_file_get_value (tmp_config->handle, *curr_grp, *curr_key, NULL); if (value == NULL) continue; g_key_file_set_value (mc_config->handle, *curr_grp, *curr_key, value); g_free (value); } g_strfreev (keys); } g_strfreev (groups); mc_config_deinit (tmp_config); return TRUE; }
mc_config_t * create_default_keymap (void) { mc_config_t *keymap; keymap = mc_config_init (NULL, TRUE); create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN, default_main_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_MAIN_EXT, default_main_x_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_PANEL, default_panel_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_DIALOG, default_dialog_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_INPUT, default_input_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_LISTBOX, default_listbox_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_TREE, default_tree_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_HELP, default_help_keymap); #ifdef USE_INTERNAL_EDIT create_default_keymap_section (keymap, KEYMAP_SECTION_EDITOR, default_editor_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_EDITOR_EXT, default_editor_x_keymap); #endif create_default_keymap_section (keymap, KEYMAP_SECTION_VIEWER, default_viewer_keymap); create_default_keymap_section (keymap, KEYMAP_SECTION_VIEWER_HEX, default_viewer_hex_keymap); #ifdef USE_DIFF_VIEW create_default_keymap_section (keymap, KEYMAP_SECTION_DIFFVIEWER, default_diff_keymap); #endif return keymap; }
/** * Write history to the ${XDG_CACHE_HOME}/mc/history file */ void dlg_save_history (WDialog * h) { char *profile; int i; if (num_history_items_recorded == 0) /* this is how to disable */ return; profile = mc_config_get_full_path (MC_HISTORY_FILE); i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); if (i != -1) close (i); /* Make sure the history is only readable by the user */ if (chmod (profile, S_IRUSR | S_IWUSR) != -1 || errno == ENOENT) { ev_history_load_save_t event_data; event_data.cfg = mc_config_init (profile, FALSE); event_data.receiver = NULL; /* get all histories in dialog */ mc_event_raise (h->event_group, MCEVENT_HISTORY_SAVE, &event_data); mc_config_save_file (event_data.cfg, NULL); mc_config_deinit (event_data.cfg); } g_free (profile); }
gboolean mc_skin_ini_file_load (mc_skin_t * mc_skin) { char *file_name; file_name = g_path_get_basename (mc_skin->name); if (file_name == NULL) return FALSE; if (strcmp (file_name, mc_skin->name) != 0) { g_free (file_name); if (!g_path_is_absolute (mc_skin->name)) return FALSE; mc_skin->config = mc_config_init (mc_skin->name, TRUE); return (mc_skin->config != NULL); } g_free (file_name); /* ${XDG_DATA_HOME}/mc/skins/ */ if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_config_get_data_path ())) return TRUE; /* /etc/mc/skins/ */ if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.sysconfig_dir)) return TRUE; /* /usr/share/mc/skins/ */ return mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.share_data_dir); }
static void config_object__init (void) { ini_filename = g_build_filename (WORKDIR, "config_string.ini", (char *) NULL); unlink (ini_filename); mc_config = mc_config_init (ini_filename, FALSE); }
void mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin) { mc_skin->config = mc_config_init (NULL, TRUE); mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin"); mc_skin_hardcoded_ugly_lines (mc_skin); mc_skin_hardcoded_blackwhite_colors (mc_skin); }
END_TEST /* --------------------------------------------------------------------------------------------- */ START_TEST (emulate__learn_save) { mc_config_t *mc_config; char *actual_value, *esc_str; char *ini_filename = NULL; GError *error = NULL; ini_filename = g_build_filename(WORKDIR, "test-emulate__learn_save.ini",NULL); unlink(ini_filename); mc_config = mc_config_init (ini_filename, FALSE); if (mc_config == NULL) { fail("unable to create mc_congif_t object!"); return; } esc_str = strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE); mc_config_set_string_raw (mc_config, "test-group1", "test-param1", esc_str); g_free (esc_str); if (!mc_config_save_file (mc_config, &error)) { fail("Unable to save config file: %s",error->message); g_error_free(error); } mc_config_deinit (mc_config); mc_config = mc_config_init (ini_filename, FALSE); actual_value = mc_config_get_string_raw( mc_config, "test-group1", "test-param1", "not-exists"); fail_unless_strcmp("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G"); g_free(actual_value); mc_config_deinit (mc_config); g_free(ini_filename); }
gboolean mc_fhl_read_ini_file (mc_fhl_t * fhl, const gchar * filename) { if (fhl == NULL || filename == NULL || !exist_file (filename)) return FALSE; if (fhl->config != NULL) return mc_config_read_file (fhl->config, filename, TRUE, FALSE); fhl->config = mc_config_init (filename, TRUE); return (fhl->config != NULL); }
static void config_object__reopen (void) { GError *error = NULL; if (!mc_config_save_file (mc_config, &error)) { fail ("Unable to save config file: %s", error->message); g_error_free (error); } mc_config_deinit (mc_config); mc_config = mc_config_init (ini_filename, FALSE); }
static void load_setup_init_config_from_file (mc_config_t ** config, const char *fname, gboolean read_only) { /* TODO: IMHO, in future, this function shall be placed in mcconfig module. */ if (exist_file (fname)) { if (*config != NULL) mc_config_read_file (*config, fname, read_only, TRUE); else *config = mc_config_init (fname, read_only); } }
static void load_setup_init_config_from_file (mc_config_t ** config, const char *fname) { /* TODO: IMHO, in future this function must be placed into mc_config module. */ if (exist_file (fname)) { if (*config != NULL) mc_config_read_file (*config, fname); else *config = mc_config_init (fname); } }
gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only, gboolean remove_empty) { mc_config_t *tmp_config; gchar **groups, **curr_grp; gchar **keys, **curr_key; gchar *value; if (mc_config == NULL) return FALSE; tmp_config = mc_config_init (ini_path, read_only); if (tmp_config == NULL) return FALSE; groups = mc_config_get_groups (tmp_config, NULL); if (groups == NULL) { mc_config_deinit (tmp_config); return FALSE; } for (curr_grp = groups; *curr_grp != NULL; curr_grp++) { keys = mc_config_get_keys (tmp_config, *curr_grp, NULL); for (curr_key = keys; *curr_key != NULL; curr_key++) { value = g_key_file_get_value (tmp_config->handle, *curr_grp, *curr_key, NULL); if (value != NULL) { if (*value == '\0' && remove_empty) g_key_file_remove_key (mc_config->handle, *curr_grp, *curr_key, NULL); else g_key_file_set_value (mc_config->handle, *curr_grp, *curr_key, value); g_free (value); } else if (remove_empty) g_key_file_remove_key (mc_config->handle, *curr_grp, *curr_key, NULL); } g_strfreev (keys); } g_strfreev (groups); mc_config_deinit (tmp_config); return TRUE; }
/** * Read histories from the ${XDG_CACHE_HOME}/mc/history file */ static void dlg_read_history (WDialog * h) { char *profile; ev_history_load_save_t event_data; if (num_history_items_recorded == 0) /* this is how to disable */ return; profile = mc_config_get_full_path (MC_HISTORY_FILE); event_data.cfg = mc_config_init (profile, TRUE); event_data.receiver = NULL; /* create all histories in dialog */ mc_event_raise (h->event_group, MCEVENT_HISTORY_LOAD, &event_data); mc_config_deinit (event_data.cfg); g_free (profile); }
END_TEST /* --------------------------------------------------------------------------------------------- */ #define etalon_str "g6:group1p6:param1v10:some valuep6:param2v11:some value " \ "g6:group2p6:param1v4:truep6:param2v6:123456" \ "g6:group3p6:param1v11:::bla-bla::p6:param2v31:bla-:p1:w:v2:12:g3:123:bla-bla\n" \ "g6:group4p6:param1v5:falsep6:param2v6:654321" START_TEST (test_serialize_config) { mc_config_t *test_data; GError *error = NULL; char *actual; test_data = mc_config_init (NULL); mc_config_set_string_raw (test_data, "group1", "param1", "some value"); mc_config_set_string (test_data, "group1", "param2", "some value "); mc_config_set_bool (test_data, "group2", "param1", TRUE); mc_config_set_int (test_data, "group2", "param2", 123456); mc_config_set_string_raw (test_data, "group3", "param1", "::bla-bla::"); mc_config_set_string (test_data, "group3", "param2", "bla-:p1:w:v2:12:g3:123:bla-bla\n"); mc_config_set_bool (test_data, "group4", "param1", FALSE); mc_config_set_int (test_data, "group4", "param2", 654321); actual = mc_serialize_config (test_data, &error); mc_config_deinit (test_data); 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; } fail_unless(strcmp(actual, etalon_str) == 0, "Not equal:\nactual (%s)\netalon (%s)", actual, etalon_str); g_free(actual); }
void load_key_defs (void) { /* * Load keys from mc.lib before ${XDG_CONFIG_HOME}/mc/ini, so that the user * definitions override global settings. */ mc_config_t *mc_global_config; mc_global_config = mc_config_init (global_profile_name, FALSE); if (mc_global_config != NULL) { load_keys_from_section ("general", mc_global_config); load_keys_from_section (getenv ("TERM"), mc_global_config); mc_config_deinit (mc_global_config); } load_keys_from_section ("general", mc_main_config); load_keys_from_section (getenv ("TERM"), mc_main_config); }
/* *INDENT-OFF* */ END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ /* *INDENT-OFF* */ START_TEST (test_serialize_config) /* *INDENT-ON* */ { /* given */ mc_config_t *test_data; char *actual; const char *expected_result = "g6:group1p6:param1v10:some valuep6:param2v11:some value " "g6:group2p6:param1v4:truep6:param2v6:123456" "g6:group3p6:param1v11:::bla-bla::p6:param2v31:bla-:p1:w:v2:12:g3:123:bla-bla\n" "g6:group4p6:param1v5:falsep6:param2v6:654321"; test_data = mc_config_init (NULL, FALSE); mc_config_set_string_raw (test_data, "group1", "param1", "some value"); mc_config_set_string (test_data, "group1", "param2", "some value "); mc_config_set_bool (test_data, "group2", "param1", TRUE); mc_config_set_int (test_data, "group2", "param2", 123456); mc_config_set_string_raw (test_data, "group3", "param1", "::bla-bla::"); mc_config_set_string (test_data, "group3", "param2", "bla-:p1:w:v2:12:g3:123:bla-bla\n"); mc_config_set_bool (test_data, "group4", "param1", FALSE); mc_config_set_int (test_data, "group4", "param2", 654321); /* when */ actual = mc_serialize_config (test_data, &error); mc_config_deinit (test_data); /* then */ mctest_assert_not_null (actual); mctest_assert_str_eq (actual, expected_result); g_free (actual); }
GList * history_get (const char *input_name) { GList *hist = NULL; char *profile; mc_config_t *cfg; if (num_history_items_recorded == 0) /* this is how to disable */ return NULL; if ((input_name == NULL) || (*input_name == '\0')) return NULL; profile = mc_config_get_full_path (MC_HISTORY_FILE); cfg = mc_config_init (profile); hist = history_load (cfg, input_name); mc_config_deinit (cfg); g_free (profile); return hist; }
static char * execute_get_opts_from_cfg (const char *command, const char *default_str) { char *str_from_config; str_from_config = mc_config_get_string_raw (mc_main_config, CONFIG_EXT_EDITOR_VIEWER_SECTION, command, NULL); if (str_from_config == NULL) { mc_config_t *cfg; cfg = mc_config_init (global_profile_name, TRUE); if (cfg == NULL) return g_strdup (default_str); str_from_config = mc_config_get_string_raw (cfg, CONFIG_EXT_EDITOR_VIEWER_SECTION, command, default_str); mc_config_deinit (cfg); } return str_from_config; }
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", ""); }
mc_config_t * mc_deserialize_config (const char *data, GError ** error) { char *current_group = NULL, *current_param = NULL, *current_value = NULL; size_t current_position = 0; mc_config_t *ret_data = mc_config_init (NULL); enum automat_status { WAIT_GROUP, WAIT_PARAM, WAIT_VALUE } current_status = WAIT_GROUP; while (data != NULL) { if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL)) current_status = WAIT_PARAM; switch (current_status) { case WAIT_GROUP: g_free (current_group); current_group = mc_deserialize_str ('g', data, error); if (current_group == NULL) prepend_error_and_exit (); data = go_to_end_of_serialized_string (data, current_group, ¤t_position); current_status = WAIT_PARAM; break; case WAIT_PARAM: g_free (current_param); current_param = mc_deserialize_str ('p', data, error); if (current_param == NULL) { g_free (current_group); prepend_error_and_exit (); } data = go_to_end_of_serialized_string (data, current_param, ¤t_position); current_status = WAIT_VALUE; break; case WAIT_VALUE: current_value = mc_deserialize_str ('v', data, error); if (current_param == NULL) { g_free (current_group); g_free (current_param); prepend_error_and_exit (); } mc_config_set_string (ret_data, current_group, current_param, current_value); data = go_to_end_of_serialized_string (data, current_value, ¤t_position); g_free (current_value); current_status = WAIT_GROUP; break; } } g_free (current_group); g_free (current_param); return ret_data; }