From cf363ad022690b3aa5b9a4f9c75cf8884660abe8 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 8 Jul 2009 15:17:10 +0300 Subject: [PATCH] Ticket #391 (history is broken). Reason: glib ini-function works only with UTF-8 in files. Bug raised if system charset not UTF-8. Issue: * recode to utf-8 before saving values of ini-params and * recode from utf-8 after reading values of ini-params Also fixed: * if system codepage is not UTF-8, panelize named is always in utf-8 and seems as non-sense string. * Recode panelize command names into system codepage from utf-8 * global variable utf8_display now initialized in any case (non-relative to ENABLE_CHARSET) Signed-off-by: Slava Zanko --- src/main.c | 7 +++++-- src/main.h | 3 ++- src/mcconfig/get.c | 29 ++++++++++++++++++++++++++++- src/mcconfig/set.c | 31 ++++++++++++++++++++++++++++++- src/panelize.c | 23 ++++++++++++++++++++--- 5 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 1e98c82e0..3d25111a1 100644 --- a/src/main.c +++ b/src/main.c @@ -1457,8 +1457,8 @@ setup_dummy_mc () static void check_codeset() { -#ifdef HAVE_CHARSET const char *_system_codepage = NULL; +#ifdef HAVE_CHARSET const char *_source_codepage = NULL; const char *_display_codepage = NULL; int profile_changed = 0; @@ -1519,7 +1519,10 @@ static void check_codeset() if ( profile_changed ) save_configure (); } -#endif +#else /* HAVE_CHARSET */ + _system_codepage = str_detect_termencoding(); + utf8_display = str_isutf8 (_system_codepage); +#endif /* HAVE_CHARSET */ } static void diff --git a/src/main.h b/src/main.h index 583cffe5c..588ec5b97 100644 --- a/src/main.h +++ b/src/main.h @@ -46,12 +46,13 @@ extern int mouse_move_pages; #ifdef HAVE_CHARSET extern int source_codepage; extern int display_codepage; -extern int utf8_display; #else extern int eight_bit_clean; extern int full_eight_bits; #endif /* !HAVE_CHARSET */ +extern int utf8_display; + extern int confirm_view_dir; extern int fast_refresh; extern int navigate_with_arrows; diff --git a/src/mcconfig/get.c b/src/mcconfig/get.c index 03d59c718..f18adc028 100644 --- a/src/mcconfig/get.c +++ b/src/mcconfig/get.c @@ -22,8 +22,12 @@ #include "global.h" #include "mcconfig.h" +#include "../src/strutil.h" + /*** global variables **************************************************/ +extern int utf8_display; + /*** file scope macro definitions **************************************/ /*** file scope type declarations **************************************/ @@ -80,7 +84,10 @@ gchar * mc_config_get_string (mc_config_t * mc_config, const gchar * group, const gchar * param, const gchar * def) { + GIConv conv; + GString *buffer; gchar *ret; + if (!mc_config || !group || !param) return def ? g_strdup (def) : NULL; @@ -94,7 +101,27 @@ mc_config_get_string (mc_config_t * mc_config, const gchar * group, if (!ret) ret = def ? g_strdup (def) : NULL; - return ret; + + if (utf8_display) + return ret; + + conv = str_crt_conv_from ("UTF-8"); + if (conv == INVALID_CONV) + return ret; + + buffer = g_string_new (""); + + if (str_convert (conv, ret, buffer) == ESTR_FAILURE) + { + g_string_free(buffer, TRUE); + str_close_conv (conv); + return ret; + } + str_close_conv (conv); + + g_free(ret); + + return g_string_free(buffer, FALSE); } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ diff --git a/src/mcconfig/set.c b/src/mcconfig/set.c index ae241f743..30c67cbaf 100644 --- a/src/mcconfig/set.c +++ b/src/mcconfig/set.c @@ -22,8 +22,12 @@ #include "global.h" #include "mcconfig.h" +#include "../src/strutil.h" + /*** global variables **************************************************/ +extern int utf8_display; + /*** file scope macro definitions **************************************/ /*** file scope type declarations **************************************/ @@ -38,10 +42,35 @@ void mc_config_set_string (mc_config_t * mc_config, const gchar * group, const gchar * param, const gchar * value) { + GIConv conv; + GString *buffer; + if (!mc_config || !group || !param || !value) return; - g_key_file_set_string (mc_config->handle, group, param, value); + if (utf8_display) + { + buffer = g_string_new(value); + } + else + { + conv = str_crt_conv_to ("UTF-8"); + if (conv == INVALID_CONV) + return; + + buffer = g_string_new (""); + + if (str_convert (conv, value, buffer) == ESTR_FAILURE) + { + g_string_free(buffer, TRUE); + buffer = g_string_new(value); + } + + str_close_conv (conv); + } + + g_key_file_set_string (mc_config->handle, group, param, buffer->str); + g_string_free(buffer, TRUE); } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ diff --git a/src/panelize.c b/src/panelize.c index 80ebbb124..b25addf90 100644 --- a/src/panelize.c +++ b/src/panelize.c @@ -314,7 +314,11 @@ void load_panelize (void) { gchar **profile_keys, **keys; gsize len; - + GIConv conv; + GString *buffer; + + conv = str_crt_conv_from ("UTF-8"); + profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section,&len); add2panelize (g_strdup (_("Other command")), g_strdup ("")); @@ -325,15 +329,28 @@ void load_panelize (void) add2panelize (g_strdup (_("Find SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print")); return; } - + while (*profile_keys){ + + if (utf8_display || conv == INVALID_CONV){ + buffer = g_string_new (*profile_keys); + } else { + buffer = g_string_new (""); + if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE) + { + g_string_free(buffer, TRUE); + buffer = g_string_new (*profile_keys); + } + } + add2panelize ( - g_strdup (*profile_keys), + g_string_free(buffer, FALSE), mc_config_get_string(mc_main_config,panelize_section,*profile_keys,"") ); profile_keys++; } g_strfreev(keys); + str_close_conv (conv); } void save_panelize (void) -- 2.11.4.GIT