From 1305fa0d410ecc66a1956056cb9fc6b831d5b775 Mon Sep 17 00:00:00 2001
From: Vit Rosin <vit_r@list.ru>
Date: Tue, 2 Mar 2010 20:48:39 +0000
Subject: [PATCH] src/charsets.c getting rid of errbuf_255
---
src/boxes.c | 10 ++++++----
src/charsets.c | 20 +++++++-------------
src/charsets.h | 2 +-
src/screen.c | 21 +++++++++++----------
src/selcodepage.c | 10 ++++++----
src/setup.c | 11 ++++++++++-
6 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/src/boxes.c b/src/boxes.c
index 61fca68..cfaad50 100644
a
|
b
|
display_bits_box (void) |
623 | 623 | run_dlg (dbits_dlg); |
624 | 624 | |
625 | 625 | if (dbits_dlg->ret_value == B_ENTER) { |
626 | | const char *errmsg; |
| 626 | char *errmsg = NULL; |
| 627 | |
627 | 628 | display_codepage = new_display_codepage; |
628 | | errmsg = |
629 | | init_translation_table (source_codepage, display_codepage); |
630 | | if (errmsg) |
| 629 | errmsg = init_translation_table (source_codepage, display_codepage); |
| 630 | if (errmsg != NULL) { |
631 | 631 | message (D_ERROR, MSG_ERROR, "%s", errmsg); |
| 632 | g_free (errmsg); |
| 633 | } |
632 | 634 | #ifdef HAVE_SLANG |
633 | 635 | tty_display_8bit (display_codepage != 0 && display_codepage != 1); |
634 | 636 | #else |
diff --git a/src/charsets.c b/src/charsets.c
index b290e72..a1bcd5d 100644
a
|
b
|
translate_character (GIConv cd, char c) |
177 | 177 | return ch; |
178 | 178 | } |
179 | 179 | |
180 | | char errbuf[255]; |
181 | | |
182 | 180 | /* |
183 | 181 | * FIXME: This assumes that ASCII is always the first encoding |
184 | 182 | * in mc.charsets |
185 | 183 | */ |
186 | 184 | #define CP_ASCII 0 |
187 | 185 | |
188 | | const char * |
| 186 | char * |
189 | 187 | init_translation_table (int cpsource, int cpdisplay) |
190 | 188 | { |
191 | 189 | int i; |
… |
… |
init_translation_table (int cpsource, int cpdisplay) |
212 | 210 | /* display <- inpit table */ |
213 | 211 | |
214 | 212 | cd = g_iconv_open (cp_display, cp_source); |
215 | | if (cd == INVALID_CONV) { |
216 | | g_snprintf (errbuf, sizeof (errbuf), |
217 | | _("Cannot translate from %s to %s"), cp_source, cp_display); |
218 | | return errbuf; |
219 | | } |
| 213 | if (cd == INVALID_CONV) |
| 214 | return g_strdup_printf (_("Cannot translate from %s to %s"), |
| 215 | cp_source, cp_display); |
220 | 216 | |
221 | 217 | for (i = 128; i <= 255; ++i) |
222 | 218 | conv_displ[i] = translate_character (cd, i); |
… |
… |
init_translation_table (int cpsource, int cpdisplay) |
226 | 222 | /* inpit <- display table */ |
227 | 223 | |
228 | 224 | cd = g_iconv_open (cp_source, cp_display); |
229 | | if (cd == INVALID_CONV) { |
230 | | g_snprintf (errbuf, sizeof (errbuf), |
231 | | _("Cannot translate from %s to %s"), cp_display, cp_source); |
232 | | return errbuf; |
233 | | } |
| 225 | if (cd == INVALID_CONV) |
| 226 | return g_strdup_printf (_("Cannot translate from %s to %s"), |
| 227 | cp_display, cp_source); |
234 | 228 | |
235 | 229 | for (i = 128; i <= 255; ++i) { |
236 | 230 | unsigned char ch; |
diff --git a/src/charsets.h b/src/charsets.h
index 98186b8..087a5bb 100644
a
|
b
|
const char *get_codepage_id (const int n); |
28 | 28 | int get_codepage_index (const char *id); |
29 | 29 | int load_codepages_list (void); |
30 | 30 | void free_codepages_list (void); |
31 | | const char *init_translation_table (int cpsource, int cpdisplay); |
| 31 | char *init_translation_table (int cpsource, int cpdisplay); |
32 | 32 | void convert_to_display (char *str); |
33 | 33 | void convert_from_input (char *str); |
34 | 34 | void convert_string (unsigned char *str); |
diff --git a/src/screen.c b/src/screen.c
index e158312..24ffbf9 100644
a
|
b
|
void |
3392 | 3392 | set_panel_encoding (WPanel * panel) |
3393 | 3393 | { |
3394 | 3394 | const char *encoding = NULL; |
3395 | | char *cd_path; |
| 3395 | char *cd_path = NULL; |
3396 | 3396 | #ifdef HAVE_CHARSET |
3397 | | const char *errmsg; |
3398 | 3397 | int r; |
3399 | 3398 | |
3400 | 3399 | r = select_charset (-1, -1, default_source_codepage, FALSE); |
… |
… |
set_panel_encoding (WPanel * panel) |
3405 | 3404 | if (r == SELECT_CHARSET_NO_TRANSLATE) |
3406 | 3405 | { |
3407 | 3406 | /* No translation */ |
3408 | | errmsg = init_translation_table (display_codepage, display_codepage); |
| 3407 | init_translation_table (display_codepage, display_codepage); |
3409 | 3408 | cd_path = remove_encoding_from_path (panel->cwd); |
3410 | 3409 | do_panel_cd (panel, cd_path, 0); |
3411 | 3410 | g_free (cd_path); |
3412 | 3411 | return; |
3413 | 3412 | } |
3414 | | |
3415 | 3413 | source_codepage = r; |
3416 | | |
3417 | | errmsg = init_translation_table (source_codepage, display_codepage); |
3418 | | if (errmsg) |
3419 | 3414 | { |
3420 | | message (D_ERROR, MSG_ERROR, "%s", errmsg); |
3421 | | return; |
3422 | | } |
| 3415 | char *errmsg = NULL; |
3423 | 3416 | |
| 3417 | errmsg = init_translation_table (source_codepage, display_codepage); |
| 3418 | if (errmsg != NULL) |
| 3419 | { |
| 3420 | message (D_ERROR, MSG_ERROR, "%s", errmsg); |
| 3421 | g_free (errmsg); |
| 3422 | return; |
| 3423 | } |
| 3424 | } |
3424 | 3425 | encoding = get_codepage_id (source_codepage); |
3425 | 3426 | #endif |
3426 | 3427 | if (encoding != NULL) |
diff --git a/src/selcodepage.c b/src/selcodepage.c
index 69f75b3..56e8d5c 100644
a
|
b
|
select_charset (int center_y, int center_x, int current_charset, gboolean seldis |
115 | 115 | gboolean |
116 | 116 | do_set_codepage (int codepage) |
117 | 117 | { |
118 | | const char *errmsg = NULL; |
| 118 | char *errmsg = NULL; |
119 | 119 | |
120 | 120 | source_codepage = codepage; |
121 | 121 | errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ? |
122 | 122 | display_codepage : source_codepage, |
123 | 123 | display_codepage); |
124 | | if (errmsg != NULL) |
| 124 | if (errmsg != NULL) { |
125 | 125 | message (D_ERROR, MSG_ERROR, "%s", errmsg); |
126 | | |
127 | | return (errmsg == NULL); |
| 126 | g_free (errmsg); |
| 127 | return FALSE; |
| 128 | } |
| 129 | return TRUE; |
128 | 130 | } |
129 | 131 | |
130 | 132 | /* Show menu selecting codepage */ |
diff --git a/src/setup.c b/src/setup.c
index 78dfb1b..178c47d 100644
a
|
b
|
load_setup (void) |
867 | 867 | if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off"))) |
868 | 868 | is_autodetect_codeset_enabled = TRUE; |
869 | 869 | |
870 | | init_translation_table (source_codepage, display_codepage); |
| 870 | { |
| 871 | char *errmsg = NULL; |
| 872 | |
| 873 | errmsg = init_translation_table (source_codepage, display_codepage); |
| 874 | if (errmsg != NULL) { |
| 875 | message (D_ERROR, MSG_ERROR, "%s", errmsg); |
| 876 | g_free (errmsg); |
| 877 | } |
| 878 | } |
| 879 | |
871 | 880 | if (get_codepage_id (display_codepage)) |
872 | 881 | utf8_display = str_isutf8 (get_codepage_id (display_codepage)); |
873 | 882 | #endif /* HAVE_CHARSET */ |