mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
Ticket #2078: changed return value of init_translation_table() function.
init_translation_table() now returnes newly-allocated string instead of pointer to the static buffer. Thanks Vit Rosin for original patch. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
993d678ed9
commit
7ada01bfa1
10
src/boxes.c
10
src/boxes.c
@ -623,12 +623,14 @@ display_bits_box (void)
|
|||||||
run_dlg (dbits_dlg);
|
run_dlg (dbits_dlg);
|
||||||
|
|
||||||
if (dbits_dlg->ret_value == B_ENTER) {
|
if (dbits_dlg->ret_value == B_ENTER) {
|
||||||
const char *errmsg;
|
char *errmsg;
|
||||||
|
|
||||||
display_codepage = new_display_codepage;
|
display_codepage = new_display_codepage;
|
||||||
errmsg =
|
errmsg = init_translation_table (source_codepage, display_codepage);
|
||||||
init_translation_table (source_codepage, display_codepage);
|
if (errmsg != NULL) {
|
||||||
if (errmsg)
|
|
||||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||||
|
g_free (errmsg);
|
||||||
|
}
|
||||||
#ifdef HAVE_SLANG
|
#ifdef HAVE_SLANG
|
||||||
tty_display_8bit (display_codepage != 0 && display_codepage != 1);
|
tty_display_8bit (display_codepage != 0 && display_codepage != 1);
|
||||||
#else
|
#else
|
||||||
|
@ -179,15 +179,13 @@ translate_character (GIConv cd, char c)
|
|||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
char errbuf[255];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: This assumes that ASCII is always the first encoding
|
* FIXME: This assumes that ASCII is always the first encoding
|
||||||
* in mc.charsets
|
* in mc.charsets
|
||||||
*/
|
*/
|
||||||
#define CP_ASCII 0
|
#define CP_ASCII 0
|
||||||
|
|
||||||
const char *
|
char *
|
||||||
init_translation_table (int cpsource, int cpdisplay)
|
init_translation_table (int cpsource, int cpdisplay)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -214,11 +212,8 @@ init_translation_table (int cpsource, int cpdisplay)
|
|||||||
/* display <- inpit table */
|
/* display <- inpit table */
|
||||||
|
|
||||||
cd = g_iconv_open (cp_display, cp_source);
|
cd = g_iconv_open (cp_display, cp_source);
|
||||||
if (cd == INVALID_CONV) {
|
if (cd == INVALID_CONV)
|
||||||
g_snprintf (errbuf, sizeof (errbuf),
|
return g_strdup_printf (_("Cannot translate from %s to %s"), cp_source, cp_display);
|
||||||
_("Cannot translate from %s to %s"), cp_source, cp_display);
|
|
||||||
return errbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 128; i <= 255; ++i)
|
for (i = 128; i <= 255; ++i)
|
||||||
conv_displ[i] = translate_character (cd, i);
|
conv_displ[i] = translate_character (cd, i);
|
||||||
@ -228,11 +223,8 @@ init_translation_table (int cpsource, int cpdisplay)
|
|||||||
/* inpit <- display table */
|
/* inpit <- display table */
|
||||||
|
|
||||||
cd = g_iconv_open (cp_source, cp_display);
|
cd = g_iconv_open (cp_source, cp_display);
|
||||||
if (cd == INVALID_CONV) {
|
if (cd == INVALID_CONV)
|
||||||
g_snprintf (errbuf, sizeof (errbuf),
|
return g_strdup_printf (_("Cannot translate from %s to %s"), cp_display, cp_source);
|
||||||
_("Cannot translate from %s to %s"), cp_display, cp_source);
|
|
||||||
return errbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 128; i <= 255; ++i) {
|
for (i = 128; i <= 255; ++i) {
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
|
@ -28,7 +28,7 @@ const char *get_codepage_id (const int n);
|
|||||||
int get_codepage_index (const char *id);
|
int get_codepage_index (const char *id);
|
||||||
int load_codepages_list (void);
|
int load_codepages_list (void);
|
||||||
void free_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_to_display (char *str);
|
||||||
void convert_from_input (char *str);
|
void convert_from_input (char *str);
|
||||||
void convert_string (unsigned char *str);
|
void convert_string (unsigned char *str);
|
||||||
|
@ -3428,7 +3428,7 @@ set_panel_encoding (WPanel * panel)
|
|||||||
const char *encoding = NULL;
|
const char *encoding = NULL;
|
||||||
char *cd_path;
|
char *cd_path;
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
const char *errmsg;
|
char *errmsg;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = select_charset (-1, -1, default_source_codepage, FALSE);
|
r = select_charset (-1, -1, default_source_codepage, FALSE);
|
||||||
@ -3439,7 +3439,7 @@ set_panel_encoding (WPanel * panel)
|
|||||||
if (r == SELECT_CHARSET_NO_TRANSLATE)
|
if (r == SELECT_CHARSET_NO_TRANSLATE)
|
||||||
{
|
{
|
||||||
/* No translation */
|
/* 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);
|
cd_path = remove_encoding_from_path (panel->cwd);
|
||||||
do_panel_cd (panel, cd_path, 0);
|
do_panel_cd (panel, cd_path, 0);
|
||||||
g_free (cd_path);
|
g_free (cd_path);
|
||||||
@ -3449,9 +3449,10 @@ set_panel_encoding (WPanel * panel)
|
|||||||
source_codepage = r;
|
source_codepage = r;
|
||||||
|
|
||||||
errmsg = init_translation_table (source_codepage, display_codepage);
|
errmsg = init_translation_table (source_codepage, display_codepage);
|
||||||
if (errmsg)
|
if (errmsg != NULL)
|
||||||
{
|
{
|
||||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||||
|
g_free (errmsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,16 +115,21 @@ select_charset (int center_y, int center_x, int current_charset, gboolean seldis
|
|||||||
gboolean
|
gboolean
|
||||||
do_set_codepage (int codepage)
|
do_set_codepage (int codepage)
|
||||||
{
|
{
|
||||||
const char *errmsg = NULL;
|
char *errmsg;
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
source_codepage = codepage;
|
source_codepage = codepage;
|
||||||
errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
|
errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
|
||||||
display_codepage : source_codepage,
|
display_codepage : source_codepage,
|
||||||
display_codepage);
|
display_codepage);
|
||||||
if (errmsg != NULL)
|
ret = errmsg == NULL;
|
||||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
|
||||||
|
|
||||||
return (errmsg == NULL);
|
if (!ret) {
|
||||||
|
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||||
|
g_free (errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show menu selecting codepage */
|
/* Show menu selecting codepage */
|
||||||
|
@ -868,7 +868,7 @@ load_setup (void)
|
|||||||
if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off")))
|
if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off")))
|
||||||
is_autodetect_codeset_enabled = TRUE;
|
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))
|
if (get_codepage_id (display_codepage))
|
||||||
utf8_display = str_isutf8 (get_codepage_id (display_codepage));
|
utf8_display = str_isutf8 (get_codepage_id (display_codepage));
|
||||||
#endif /* HAVE_CHARSET */
|
#endif /* HAVE_CHARSET */
|
||||||
|
Loading…
Reference in New Issue
Block a user