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