Merge branch '1635_lang_c_no_lines'

* 1635_lang_c_no_lines:
  Ticket #1635: No drawing lines with LANG=C
This commit is contained in:
Slava Zanko 2009-09-28 15:47:12 +03:00
commit 4ea55c0b93
4 changed files with 70 additions and 33 deletions

View File

@ -17,4 +17,6 @@ extern gboolean ugly_line_drawing;
/* The mouse is currently: TRUE - enabled, FALSE - disabled */ /* The mouse is currently: TRUE - enabled, FALSE - disabled */
extern gboolean mouse_enabled; extern gboolean mouse_enabled;
char *mc_tty_normalize_from_utf8 (const char *);
#endif /* MC_TTY_INTERNAL_H */ #endif /* MC_TTY_INTERNAL_H */

View File

@ -73,7 +73,9 @@
int int
mc_tty_normalize_lines_char (const char *ch) mc_tty_normalize_lines_char (const char *ch)
{ {
int i; char *str2;
int res;
struct mc_tty_lines_struct { struct mc_tty_lines_struct {
const char *line; const char *line;
int line_code; int line_code;
@ -89,6 +91,7 @@ mc_tty_normalize_lines_char (const char *ch)
{"\342\224\200", ACS_HLINE}, /* ─ */ {"\342\224\200", ACS_HLINE}, /* ─ */
{"\342\224\202", ACS_VLINE}, /* │ */ {"\342\224\202", ACS_VLINE}, /* │ */
{"\342\224\274", ACS_PLUS}, /* ┼ */ {"\342\224\274", ACS_PLUS}, /* ┼ */
{"\342\225\235", ACS_LRCORNER | A_BOLD}, /* ╔ */ {"\342\225\235", ACS_LRCORNER | A_BOLD}, /* ╔ */
{"\342\225\232", ACS_LLCORNER | A_BOLD}, /* ╗ */ {"\342\225\232", ACS_LLCORNER | A_BOLD}, /* ╗ */
{"\342\225\227", ACS_URCORNER | A_BOLD}, /* ╚ */ {"\342\225\227", ACS_URCORNER | A_BOLD}, /* ╚ */
@ -99,19 +102,26 @@ mc_tty_normalize_lines_char (const char *ch)
{"\342\225\247", ACS_BTEE | A_BOLD}, /* ╧ */ {"\342\225\247", ACS_BTEE | A_BOLD}, /* ╧ */
{"\342\225\220", ACS_HLINE | A_BOLD}, /* ═ */ {"\342\225\220", ACS_HLINE | A_BOLD}, /* ═ */
{"\342\225\221", ACS_VLINE | A_BOLD}, /* ║ */ {"\342\225\221", ACS_VLINE | A_BOLD}, /* ║ */
{NULL, 0} {NULL, 0}
}; };
if (ch == NULL) if (ch == NULL)
return (int) ' '; return (int) ' ';
for (i = 0; lines_codes[i].line; i++) { for (res = 0; lines_codes[res].line; res++) {
if (strcmp (ch, lines_codes[i].line) == 0) if (strcmp (ch, lines_codes[res].line) == 0)
return lines_codes[i].line_code; return lines_codes[res].line_code;
} }
return (int) ' '; str2 = mc_tty_normalize_from_utf8 (ch);
res = g_utf8_get_char_validated (str2, -1);
if (res < 0)
res = (unsigned char) str2[0];
g_free (str2);
return res;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -191,32 +191,6 @@ load_terminfo_keys (void)
do_define_key (key_table[i].key_code, key_table[i].key_name); do_define_key (key_table[i].key_code, key_table[i].key_name);
} }
static 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);
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/*** public functions **************************************************/ /*** public functions **************************************************/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -227,8 +201,33 @@ mc_tty_normalize_lines_char (const char *str)
char *str2; char *str2;
int res; int res;
struct mc_tty_lines_struct {
const char *line;
int line_code;
} const lines_codes[] = {
{"\342\224\214", SLSMG_ULCORN_CHAR},
{"\342\224\220", SLSMG_URCORN_CHAR},
{"\342\224\224", SLSMG_LLCORN_CHAR},
{"\342\224\230", SLSMG_LRCORN_CHAR},
{"\342\224\234", SLSMG_LTEE_CHAR},
{"\342\224\244", SLSMG_RTEE_CHAR},
{"\342\224\254", SLSMG_UTEE_CHAR},
{"\342\224\264", SLSMG_DTEE_CHAR},
{"\342\224\200", SLSMG_HLINE_CHAR},
{"\342\224\202", SLSMG_VLINE_CHAR},
{"\342\224\274", SLSMG_PLUS_CHAR},
{NULL, 0}
};
if (!str) if (!str)
return (int) ' '; return (int) ' ';
for (res = 0; lines_codes[res].line; res++) {
if (strcmp (str, lines_codes[res].line) == 0)
return lines_codes[res].line_code;
}
str2 = mc_tty_normalize_from_utf8 (str); str2 = mc_tty_normalize_from_utf8 (str);
res = g_utf8_get_char_validated (str2, -1); res = g_utf8_get_char_validated (str2, -1);
@ -513,8 +512,8 @@ void
tty_print_alt_char (int c) tty_print_alt_char (int c)
{ {
#define DRAW(x, y) (x == y) \ #define DRAW(x, y) (x == y) \
? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \ ? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \
: SLsmg_write_char ((unsigned int) y) : SLsmg_write_char ((unsigned int) y)
switch (c) { switch (c) {
case ACS_VLINE: case ACS_VLINE:
DRAW (c, mc_tty_ugly_frm[MC_TTY_FRM_thinvert]); DRAW (c, mc_tty_ugly_frm[MC_TTY_FRM_thinvert]);

View File

@ -148,3 +148,29 @@ tty_draw_box (int y, int x, int ys, int xs)
tty_gotoyx (y + ys - 1, x + xs - 1); tty_gotoyx (y + ys - 1, x + xs - 1);
tty_print_alt_char (mc_tty_ugly_frm[MC_TTY_FRM_rightbottom]); tty_print_alt_char (mc_tty_ugly_frm[MC_TTY_FRM_rightbottom]);
} }
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);
}