1 /**************************************************************************** 2 * Copyright (c) 2002-2014,2015 Free Software Foundation, Inc. * 3 * * 4 * Permission is hereby granted, free of charge, to any person obtaining a * 5 * copy of this software and associated documentation files (the * 6 * "Software"), to deal in the Software without restriction, including * 7 * without limitation the rights to use, copy, modify, merge, publish, * 8 * distribute, distribute with modifications, sublicense, and/or sell * 9 * copies of the Software, and to permit persons to whom the Software is * 10 * furnished to do so, subject to the following conditions: * 11 * * 12 * The above copyright notice and this permission notice shall be included * 13 * in all copies or substantial portions of the Software. * 14 * * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22 * * 23 * Except as contained in this notice, the name(s) of the above copyright * 24 * holders shall not be used in advertising or otherwise to promote the * 25 * sale, use or other dealings in this Software without prior written * 26 * authorization. * 27 ****************************************************************************/ 28 29 /**************************************************************************** 30 * Author: Thomas Dickey 2002 * 31 ****************************************************************************/ 32 33 #include <curses.priv.h> 34 35 MODULE_ID("$Id: lib_wacs.c,v 1.16 2015/12/19 23:29:03 tom Exp $") 36 37 NCURSES_EXPORT_VAR(cchar_t) * _nc_wacs = 0; 38 39 NCURSES_EXPORT(void) 40 _nc_init_wacs(void) 41 { 42 /* *INDENT-OFF* */ 43 static const struct { 44 unsigned map; 45 int value[2]; 46 } table[] = { 47 /* VT100 symbols */ 48 { 'l', { '+', 0x250c }}, /* upper left corner */ 49 { 'm', { '+', 0x2514 }}, /* lower left corner */ 50 { 'k', { '+', 0x2510 }}, /* upper right corner */ 51 { 'j', { '+', 0x2518 }}, /* lower right corner */ 52 { 't', { '+', 0x251c }}, /* tee pointing left */ 53 { 'u', { '+', 0x2524 }}, /* tee pointing right */ 54 { 'v', { '+', 0x2534 }}, /* tee pointing up */ 55 { 'w', { '+', 0x252c }}, /* tee pointing down */ 56 { 'q', { '-', 0x2500 }}, /* horizontal line */ 57 { 'x', { '|', 0x2502 }}, /* vertical line */ 58 { 'n', { '+', 0x253c }}, /* large plus or crossover */ 59 { 'o', { '~', 0x23ba }}, /* scan line 1 */ 60 { 's', { '_', 0x23bd }}, /* scan line 9 */ 61 { '`', { '+', 0x25c6 }}, /* diamond */ 62 { 'a', { ':', 0x2592 }}, /* checker board (stipple) */ 63 { 'f', { '\'', 0x00b0 }}, /* degree symbol */ 64 { 'g', { '#', 0x00b1 }}, /* plus/minus */ 65 { '~', { 'o', 0x00b7 }}, /* bullet */ 66 /* Teletype 5410v1 symbols */ 67 { ',', { '<', 0x2190 }}, /* arrow pointing left */ 68 { '+', { '>', 0x2192 }}, /* arrow pointing right */ 69 { '.', { 'v', 0x2193 }}, /* arrow pointing down */ 70 { '-', { '^', 0x2191 }}, /* arrow pointing up */ 71 { 'h', { '#', 0x2592 }}, /* board of squares */ 72 { 'i', { '#', 0x2603 }}, /* lantern symbol */ 73 { '0', { '#', 0x25ae }}, /* solid square block */ 74 /* these defaults were invented for ncurses */ 75 { 'p', { '-', 0x23bb }}, /* scan line 3 */ 76 { 'r', { '-', 0x23bc }}, /* scan line 7 */ 77 { 'y', { '<', 0x2264 }}, /* less-than-or-equal-to */ 78 { 'z', { '>', 0x2265 }}, /* greater-than-or-equal-to */ 79 { '{', { '*', 0x03c0 }}, /* greek pi */ 80 { '|', { '!', 0x2260 }}, /* not-equal */ 81 { '}', { 'f', 0x00a3 }}, /* pound-sterling symbol */ 82 /* thick-line-drawing */ 83 { 'L', { '+', 0x250f }}, /* upper left corner */ 84 { 'M', { '+', 0x2517 }}, /* lower left corner */ 85 { 'K', { '+', 0x2513 }}, /* upper right corner */ 86 { 'J', { '+', 0x251b }}, /* lower right corner */ 87 { 'T', { '+', 0x2523 }}, /* tee pointing left */ 88 { 'U', { '+', 0x252b }}, /* tee pointing right */ 89 { 'V', { '+', 0x253b }}, /* tee pointing up */ 90 { 'W', { '+', 0x2533 }}, /* tee pointing down */ 91 { 'Q', { '-', 0x2501 }}, /* horizontal line */ 92 { 'X', { '|', 0x2503 }}, /* vertical line */ 93 { 'N', { '+', 0x254b }}, /* large plus or crossover */ 94 /* double-line-drawing */ 95 { 'C', { '+', 0x2554 }}, /* upper left corner */ 96 { 'D', { '+', 0x255a }}, /* lower left corner */ 97 { 'B', { '+', 0x2557 }}, /* upper right corner */ 98 { 'A', { '+', 0x255d }}, /* lower right corner */ 99 { 'G', { '+', 0x2563 }}, /* tee pointing left */ 100 { 'F', { '+', 0x2560 }}, /* tee pointing right */ 101 { 'H', { '+', 0x2569 }}, /* tee pointing up */ 102 { 'I', { '+', 0x2566 }}, /* tee pointing down */ 103 { 'R', { '-', 0x2550 }}, /* horizontal line */ 104 { 'Y', { '|', 0x2551 }}, /* vertical line */ 105 { 'E', { '+', 0x256c }}, /* large plus or crossover */ 106 }; 107 /* *INDENT-ON* */ 108 109 unsigned n, m; 110 int active = _nc_unicode_locale(); 111 112 /* 113 * If we're running in a UTF-8 locale, will use the Unicode equivalents 114 * rather than the terminfo information. Actually the terminfo should 115 * be the rule, but there are people who are offended by the notion that 116 * a Unicode-capable terminal would have something resembling a mode. 117 * So the smacs/rmacs may be disabled -- sometime. 118 */ 119 T(("initializing WIDE-ACS map (Unicode is%s active)", 120 active ? "" : " not")); 121 122 if ((_nc_wacs = typeCalloc(cchar_t, ACS_LEN)) != 0) { 123 124 for (n = 0; n < SIZEOF(table); ++n) { 125 #if NCURSES_WCWIDTH_GRAPHICS 126 int wide = wcwidth((wchar_t) table[n].value[active]); 127 #else 128 int wide = 1; 129 #endif 130 131 m = table[n].map; 132 SetChar(_nc_wacs[m], 133 table[n].value[(active && (wide == 1)) ? 1 : 0], 134 A_NORMAL); 135 136 T(("#%d, wide:%d SetChar(%c, %#04x) = %s", 137 n, wide, m, 138 table[n].value[active], 139 _tracecchar_t(&_nc_wacs[m]))); 140 } 141 } 142 } 143