static void check_codeset (void) { const char *current_system_codepage = NULL; current_system_codepage = str_detect_termencoding (); #ifdef HAVE_CHARSET { const char *_display_codepage; _display_codepage = get_codepage_id (mc_global.display_codepage); if (strcmp (_display_codepage, current_system_codepage) != 0) { mc_global.display_codepage = get_codepage_index (current_system_codepage); if (mc_global.display_codepage == -1) mc_global.display_codepage = 0; mc_config_set_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", cp_display); } } #endif mc_global.utf8_display = str_isutf8 (current_system_codepage); }
static int sel_charset_button (WButton * button, int action) { int new_dcp; (void) button; (void) action; new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); if (new_dcp != SELECT_CHARSET_CANCEL) { const char *cpname; char buf[BUF_TINY]; new_display_codepage = new_dcp; cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ? _("Other 8 bit") : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; if (cpname != NULL) utf8_display = str_isutf8 (cpname); /* avoid strange bug with label repainting */ g_snprintf (buf, sizeof (buf), "%-27s", cpname); label_set_text (cplabel, buf); } return 0; }
static int sel_charset_button (WButton * button, int action) { int new_dcp; (void) action; new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); if (new_dcp != SELECT_CHARSET_CANCEL) { const char *cpname; new_display_codepage = new_dcp; cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ? _("Other 8 bit") : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; if (cpname != NULL) mc_global.utf8_display = str_isutf8 (cpname); else cpname = _("7-bit ASCII"); /* FIXME */ button_set_text (button, cpname); dlg_redraw (WIDGET (button)->owner); } return 0; }
char * mc_tty_normalize_from_utf8 (const char *str) { GIConv conv; GString *buffer; const char *_system_codepage = str_detect_termencoding (); if (str_isutf8 (_system_codepage)) return g_strdup (str); conv = g_iconv_open (_system_codepage, "UTF-8"); if (conv == INVALID_CONV) return g_strdup (str); buffer = g_string_new (""); if (str_convert (conv, str, buffer) == ESTR_FAILURE) { g_string_free (buffer, TRUE); str_close_conv (conv); return g_strdup (str); } str_close_conv (conv); return g_string_free (buffer, FALSE); }
void mcview_set_codeset (mcview_t * view) { #ifdef HAVE_CHARSET const char *cp_id = NULL; view->utf8 = TRUE; cp_id = get_codepage_id (mc_global.source_codepage >= 0 ? mc_global.source_codepage : mc_global.display_codepage); if (cp_id != NULL) { GIConv conv; conv = str_crt_conv_from (cp_id); if (conv != INVALID_CONV) { if (view->converter != str_cnv_from_term) str_close_conv (view->converter); view->converter = conv; } view->utf8 = (gboolean) str_isutf8 (cp_id); } #else (void) view; #endif }
gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror) { const gchar *_system_codepage; gboolean ok = TRUE; mc_return_val_if_error (mcerror, FALSE); _system_codepage = str_detect_termencoding (); #ifdef ENABLE_NLS if (!str_isutf8 (_system_codepage)) bind_textdomain_codeset ("mc", "UTF-8"); #endif context = g_option_context_new (mc_args_add_usage_info ()); g_option_context_set_ignore_unknown_options (context, FALSE); mc_args_add_extended_info_to_help (); main_group = g_option_group_new ("main", _("Main options"), _("Main options"), NULL, NULL); g_option_group_add_entries (main_group, argument_main_table); g_option_context_set_main_group (context, main_group); g_option_group_set_translation_domain (main_group, translation_domain); terminal_group = g_option_group_new ("terminal", _("Terminal options"), _("Terminal options"), NULL, NULL); g_option_group_add_entries (terminal_group, argument_terminal_table); g_option_context_add_group (context, terminal_group); g_option_group_set_translation_domain (terminal_group, translation_domain); color_group = mc_args_new_color_group (); g_option_group_add_entries (color_group, argument_color_table); g_option_context_add_group (context, color_group); g_option_group_set_translation_domain (color_group, translation_domain); if (!g_option_context_parse (context, argc, argv, mcerror)) { if (*mcerror == NULL) mc_propagate_error (mcerror, 0, "%s\n", _("Arguments parse error!")); else { gchar *help_str; help_str = g_option_context_get_help (context, TRUE, NULL); if (str_isutf8 (_system_codepage)) mc_replace_error (mcerror, (*mcerror)->code, "%s\n\n%s\n", (*mcerror)->message, help_str); else { gchar *full_help_str; full_help_str = mc_args__convert_help_to_syscharset (_system_codepage, (*mcerror)->message, help_str); mc_replace_error (mcerror, (*mcerror)->code, "%s", full_help_str); g_free (full_help_str); } g_free (help_str); } ok = FALSE; } g_option_context_free (context); mc_args_clean_temp_help_strings (); #ifdef ENABLE_NLS if (!str_isutf8 (_system_codepage)) bind_textdomain_codeset ("mc", _system_codepage); #endif return ok; }
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", ""); }