/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002-2015,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
****************************************************************************/
#include <curses.priv.h>
-#include <term.h>
-MODULE_ID("$Id: lib_wacs.c,v 1.5 2002/08/31 19:44:17 tom Exp $")
+MODULE_ID("$Id: lib_wacs.c,v 1.18 2016/05/28 23:09:20 tom Exp $")
NCURSES_EXPORT_VAR(cchar_t) * _nc_wacs = 0;
-static int
-_nc_unicode_locale(void)
-{
- char *s;
- if (((s = getenv("LC_ALL")) != 0 && *s != '\0')
- || ((s = getenv("LC_ALL")) != 0 && *s != '\0')
- || ((s = getenv("LC_ALL")) != 0 && *s != '\0')) {
- if (strstr(s, ".UTF-8") != 0)
- return 1;
- }
- return 0;
-}
-
NCURSES_EXPORT(void)
_nc_init_wacs(void)
{
/* *INDENT-OFF* */
static const struct {
- int map;
+ unsigned map;
int value[2];
} table[] = {
/* VT100 symbols */
{ '{', { '*', 0x03c0 }}, /* greek pi */
{ '|', { '!', 0x2260 }}, /* not-equal */
{ '}', { 'f', 0x00a3 }}, /* pound-sterling symbol */
+ /* thick-line-drawing */
+ { 'L', { '+', 0x250f }}, /* upper left corner */
+ { 'M', { '+', 0x2517 }}, /* lower left corner */
+ { 'K', { '+', 0x2513 }}, /* upper right corner */
+ { 'J', { '+', 0x251b }}, /* lower right corner */
+ { 'T', { '+', 0x2523 }}, /* tee pointing left */
+ { 'U', { '+', 0x252b }}, /* tee pointing right */
+ { 'V', { '+', 0x253b }}, /* tee pointing up */
+ { 'W', { '+', 0x2533 }}, /* tee pointing down */
+ { 'Q', { '-', 0x2501 }}, /* horizontal line */
+ { 'X', { '|', 0x2503 }}, /* vertical line */
+ { 'N', { '+', 0x254b }}, /* large plus or crossover */
+ /* double-line-drawing */
+ { 'C', { '+', 0x2554 }}, /* upper left corner */
+ { 'D', { '+', 0x255a }}, /* lower left corner */
+ { 'B', { '+', 0x2557 }}, /* upper right corner */
+ { 'A', { '+', 0x255d }}, /* lower right corner */
+ { 'G', { '+', 0x2563 }}, /* tee pointing left */
+ { 'F', { '+', 0x2560 }}, /* tee pointing right */
+ { 'H', { '+', 0x2569 }}, /* tee pointing up */
+ { 'I', { '+', 0x2566 }}, /* tee pointing down */
+ { 'R', { '-', 0x2550 }}, /* horizontal line */
+ { 'Y', { '|', 0x2551 }}, /* vertical line */
+ { 'E', { '+', 0x256c }}, /* large plus or crossover */
};
/* *INDENT-ON* */
- unsigned n, m;
int active = _nc_unicode_locale();
/*
T(("initializing WIDE-ACS map (Unicode is%s active)",
active ? "" : " not"));
- _nc_wacs = typeCalloc(cchar_t, ACS_LEN);
- for (n = 0; n < SIZEOF(table); ++n) {
- m = table[n].map;
- if (active) {
- SetChar(_nc_wacs[m], table[n].value[active], A_NORMAL);
- } else if (acs_map[m] & A_ALTCHARSET) {
- SetChar(_nc_wacs[m], m, A_ALTCHARSET);
- } else {
- SetChar(_nc_wacs[m], table[n].value[0], A_NORMAL);
+ if ((_nc_wacs = typeCalloc(cchar_t, ACS_LEN)) != 0) {
+ unsigned n;
+
+ for (n = 0; n < SIZEOF(table); ++n) {
+ unsigned m;
+#if NCURSES_WCWIDTH_GRAPHICS
+ int wide = wcwidth((wchar_t) table[n].value[active]);
+#else
+ int wide = 1;
+#endif
+
+ m = table[n].map;
+ if (active && (wide == 1)) {
+ SetChar(_nc_wacs[m], table[n].value[1], A_NORMAL);
+ } else if (acs_map[m] & A_ALTCHARSET) {
+ SetChar(_nc_wacs[m], m, A_ALTCHARSET);
+ } else {
+ SetChar(_nc_wacs[m], table[n].value[0], A_NORMAL);
+ }
+
+ T(("#%d, wide:%d SetChar(%c, %#04x) = %s",
+ n, wide, m,
+ table[n].value[active],
+ _tracecchar_t(&_nc_wacs[m])));
}
- T(("#%d, SetChar(%c, %#04x) = %s",
- n, m,
- table[n].value[active],
- _tracecchar_t(&_nc_wacs[m])));
}
}