X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=madtty%2Fmadtty.c;h=317712c147756556deca45b2eb9abe76151c8536;hb=c50afdbb8673cc2becc273935b05833c0b06daf2;hp=ef1230bc8d2b58a95c68502a96b8904b00c8f2f1;hpb=db8ff78290e27a9978b51865ab40d30e78469ed5;p=apps%2Fmadtty.git diff --git a/madtty/madtty.c b/madtty/madtty.c index ef1230b..317712c 100644 --- a/madtty/madtty.c +++ b/madtty/madtty.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ # include #elif defined(__FreeBSD__) # include -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) # include #endif #include "madtty.h" @@ -47,7 +48,7 @@ #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) -static int has_default = 0; +static int has_default, is_utf8; enum { C0_NUL = 0x00, @@ -687,13 +688,10 @@ static void madtty_process_nonprinting(madtty_t *t, wchar_t wc) } } -bool is_utf8 = true; - static void is_utf8_locale(void) { - const char *l = getenv("LANG"); - if (l) - is_utf8 = (strstr(l, "UTF-8") != NULL); + const char *cset = nl_langinfo(CODESET) ?: "ANSI_X3.4-1968"; + is_utf8 = !strcmp(cset, "UTF-8"); } // vt100 special graphics and line drawing @@ -771,10 +769,9 @@ static void madtty_putc(madtty_t *t, wchar_t wc) if (t->graphmode) { if (wc >= 0x41 && wc <= 0x7e) { - if(is_utf8 && vt100_utf8[wc - 0x41]) - wc = vt100_utf8[wc - 0x41]; - else if(!is_utf8 && vt100[wc - 0x41]) - wc = vt100[wc - 0x41]; + wchar_t gc = is_utf8 ? vt100_utf8[wc - 0x41] : vt100[wc - 0x41]; + if (gc) + wc = gc; } width = 1; } else { @@ -968,7 +965,7 @@ void madtty_draw(madtty_t *t, WINDOW *win, int srow, int scol) for (int j = 0; j < t->cols; j++) { if (!j || row->attr[j] != row->attr[j - 1]) wattrset(win, (attr_t)row->attr[j] << NCURSES_ATTR_SHIFT); - if (is_utf8 && row->text[j] >= 128) { + if (row->text[j] >= 128) { char buf[MB_CUR_MAX + 1]; int len; @@ -1064,11 +1061,11 @@ void madtty_init_colors(void) fg == COLOR_WHITE ? -1 : fg, bg == COLOR_BLACK ? -1 : bg); } else { - init_pair((7 - fg) * 8 + bg, fg, bg); + init_pair((7 - fg) * 8 + bg, fg, bg); + } } } } - } } int madtty_color_pair(int fg, int bg)