From be2424c9602fa5f2341a24abdcf57e4681675d0b Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 28 Sep 2009 11:04:54 +0300 Subject: [PATCH] Ticket #1635: No drawing lines with LANG=C Fixed drawing of ordinary lines in POSIX codepage. Signed-off-by: Slava Zanko --- src/tty/tty-internal.h | 2 ++ src/tty/tty-ncurses.c | 20 +++++++++++++----- src/tty/tty-slang.c | 55 +++++++++++++++++++++++++------------------------- src/tty/tty.c | 26 ++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 33 deletions(-) diff --git a/src/tty/tty-internal.h b/src/tty/tty-internal.h index 772cfd415..113330746 100644 --- a/src/tty/tty-internal.h +++ b/src/tty/tty-internal.h @@ -17,4 +17,6 @@ extern gboolean ugly_line_drawing; /* The mouse is currently: TRUE - enabled, FALSE - disabled */ extern gboolean mouse_enabled; +char *mc_tty_normalize_from_utf8 (const char *); + #endif /* MC_TTY_INTERNAL_H */ diff --git a/src/tty/tty-ncurses.c b/src/tty/tty-ncurses.c index b8b5c9776..8371d41c9 100644 --- a/src/tty/tty-ncurses.c +++ b/src/tty/tty-ncurses.c @@ -73,7 +73,9 @@ int mc_tty_normalize_lines_char (const char *ch) { - int i; + char *str2; + int res; + struct mc_tty_lines_struct { const char *line; int line_code; @@ -89,6 +91,7 @@ mc_tty_normalize_lines_char (const char *ch) {"\342\224\200", ACS_HLINE}, /* ─ */ {"\342\224\202", ACS_VLINE}, /* │ */ {"\342\224\274", ACS_PLUS}, /* ┼ */ + {"\342\225\235", ACS_LRCORNER | A_BOLD}, /* ╔ */ {"\342\225\232", ACS_LLCORNER | 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\220", ACS_HLINE | A_BOLD}, /* ═ */ {"\342\225\221", ACS_VLINE | A_BOLD}, /* ║ */ + {NULL, 0} }; if (ch == NULL) return (int) ' '; - for (i = 0; lines_codes[i].line; i++) { - if (strcmp (ch, lines_codes[i].line) == 0) - return lines_codes[i].line_code; + for (res = 0; lines_codes[res].line; res++) { + if (strcmp (ch, lines_codes[res].line) == 0) + 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; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/tty/tty-slang.c b/src/tty/tty-slang.c index 295158010..316ca335f 100644 --- a/src/tty/tty-slang.c +++ b/src/tty/tty-slang.c @@ -191,32 +191,6 @@ load_terminfo_keys (void) 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 **************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -227,8 +201,33 @@ mc_tty_normalize_lines_char (const char *str) char *str2; 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) 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); res = g_utf8_get_char_validated (str2, -1); @@ -513,8 +512,8 @@ void tty_print_alt_char (int c) { #define DRAW(x, y) (x == y) \ - ? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \ - : SLsmg_write_char ((unsigned int) y) + ? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \ + : SLsmg_write_char ((unsigned int) y) switch (c) { case ACS_VLINE: DRAW (c, mc_tty_ugly_frm[MC_TTY_FRM_thinvert]); diff --git a/src/tty/tty.c b/src/tty/tty.c index 3adcc259c..3d31b515b 100644 --- a/src/tty/tty.c +++ b/src/tty/tty.c @@ -148,3 +148,29 @@ tty_draw_box (int y, int x, int ys, int xs) tty_gotoyx (y + ys - 1, x + xs - 1); 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); +} -- 2.11.4.GIT