diff --git a/src/boxes.c b/src/boxes.c index 61fca6824..2c1039d44 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -623,12 +623,14 @@ display_bits_box (void) run_dlg (dbits_dlg); if (dbits_dlg->ret_value == B_ENTER) { - const char *errmsg; + char *errmsg; + display_codepage = new_display_codepage; - errmsg = - init_translation_table (source_codepage, display_codepage); - if (errmsg) + errmsg = init_translation_table (source_codepage, display_codepage); + if (errmsg != NULL) { message (D_ERROR, MSG_ERROR, "%s", errmsg); + g_free (errmsg); + } #ifdef HAVE_SLANG tty_display_8bit (display_codepage != 0 && display_codepage != 1); #else diff --git a/src/charsets.c b/src/charsets.c index fa0dc5748..0958f7fb5 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -179,15 +179,13 @@ translate_character (GIConv cd, char c) return ch; } -char errbuf[255]; - /* * FIXME: This assumes that ASCII is always the first encoding * in mc.charsets */ #define CP_ASCII 0 -const char * +char * init_translation_table (int cpsource, int cpdisplay) { int i; @@ -214,11 +212,8 @@ init_translation_table (int cpsource, int cpdisplay) /* display <- inpit table */ cd = g_iconv_open (cp_display, cp_source); - if (cd == INVALID_CONV) { - g_snprintf (errbuf, sizeof (errbuf), - _("Cannot translate from %s to %s"), cp_source, cp_display); - return errbuf; - } + if (cd == INVALID_CONV) + return g_strdup_printf (_("Cannot translate from %s to %s"), cp_source, cp_display); for (i = 128; i <= 255; ++i) conv_displ[i] = translate_character (cd, i); @@ -228,11 +223,8 @@ init_translation_table (int cpsource, int cpdisplay) /* inpit <- display table */ cd = g_iconv_open (cp_source, cp_display); - if (cd == INVALID_CONV) { - g_snprintf (errbuf, sizeof (errbuf), - _("Cannot translate from %s to %s"), cp_display, cp_source); - return errbuf; - } + if (cd == INVALID_CONV) + return g_strdup_printf (_("Cannot translate from %s to %s"), cp_display, cp_source); for (i = 128; i <= 255; ++i) { unsigned char ch; diff --git a/src/charsets.h b/src/charsets.h index 98186b8cb..087a5bb1f 100644 --- a/src/charsets.h +++ b/src/charsets.h @@ -28,7 +28,7 @@ const char *get_codepage_id (const int n); int get_codepage_index (const char *id); int load_codepages_list (void); void free_codepages_list (void); -const char *init_translation_table (int cpsource, int cpdisplay); +char *init_translation_table (int cpsource, int cpdisplay); void convert_to_display (char *str); void convert_from_input (char *str); void convert_string (unsigned char *str); diff --git a/src/screen.c b/src/screen.c index f9a0ff88f..22cc7127d 100644 --- a/src/screen.c +++ b/src/screen.c @@ -3428,7 +3428,7 @@ set_panel_encoding (WPanel * panel) const char *encoding = NULL; char *cd_path; #ifdef HAVE_CHARSET - const char *errmsg; + char *errmsg; int r; r = select_charset (-1, -1, default_source_codepage, FALSE); @@ -3439,7 +3439,7 @@ set_panel_encoding (WPanel * panel) if (r == SELECT_CHARSET_NO_TRANSLATE) { /* No translation */ - errmsg = init_translation_table (display_codepage, display_codepage); + g_free (init_translation_table (display_codepage, display_codepage)); cd_path = remove_encoding_from_path (panel->cwd); do_panel_cd (panel, cd_path, 0); g_free (cd_path); @@ -3449,9 +3449,10 @@ set_panel_encoding (WPanel * panel) source_codepage = r; errmsg = init_translation_table (source_codepage, display_codepage); - if (errmsg) + if (errmsg != NULL) { message (D_ERROR, MSG_ERROR, "%s", errmsg); + g_free (errmsg); return; } diff --git a/src/selcodepage.c b/src/selcodepage.c index 69f75b3d3..63a5847ce 100644 --- a/src/selcodepage.c +++ b/src/selcodepage.c @@ -115,16 +115,21 @@ select_charset (int center_y, int center_x, int current_charset, gboolean seldis gboolean do_set_codepage (int codepage) { - const char *errmsg = NULL; + char *errmsg; + gboolean ret; source_codepage = codepage; errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ? display_codepage : source_codepage, display_codepage); - if (errmsg != NULL) - message (D_ERROR, MSG_ERROR, "%s", errmsg); + ret = errmsg == NULL; - return (errmsg == NULL); + if (!ret) { + message (D_ERROR, MSG_ERROR, "%s", errmsg); + g_free (errmsg); + } + + return ret; } /* Show menu selecting codepage */ diff --git a/src/setup.c b/src/setup.c index b195cca73..7ad8444df 100644 --- a/src/setup.c +++ b/src/setup.c @@ -868,7 +868,7 @@ load_setup (void) if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off"))) is_autodetect_codeset_enabled = TRUE; - init_translation_table (source_codepage, display_codepage); + g_free (init_translation_table (source_codepage, display_codepage)); if (get_codepage_id (display_codepage)) utf8_display = str_isutf8 (get_codepage_id (display_codepage)); #endif /* HAVE_CHARSET */