]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/lib_acs.c
ncurses 5.4
[ncurses.git] / ncurses / tinfo / lib_acs.c
1 /****************************************************************************
2  * Copyright (c) 1998-2001,2002 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: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  ****************************************************************************/
33
34 #include <curses.priv.h>
35 #include <term.h>               /* ena_acs, acs_chars */
36
37 MODULE_ID("$Id: lib_acs.c,v 1.25 2002/12/28 16:26:46 tom Exp $")
38
39 #if BROKEN_LINKER
40 NCURSES_EXPORT_VAR(chtype *)
41 _nc_acs_map(void)
42 {
43     static chtype *the_map = 0;
44     if (the_map == 0)
45         the_map = typeCalloc(chtype, ACS_LEN);
46     return the_map;
47 }
48 #else
49 NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
50 {
51     0
52 };
53 #endif
54
55 NCURSES_EXPORT(void)
56 _nc_init_acs(void)
57 {
58     chtype *fake_map = acs_map;
59     chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
60     int j;
61
62     T(("initializing ACS map"));
63
64     /*
65      * If we're using this from curses (rather than terminfo), we are storing
66      * the mapping information in the SCREEN struct so we can decide how to
67      * render it.
68      */
69     if (real_map != fake_map) {
70         for (j = 1; j < ACS_LEN; ++j) {
71             real_map[j] = 0;
72             fake_map[j] = A_ALTCHARSET | j;
73         }
74     } else {
75         for (j = 1; j < ACS_LEN; ++j) {
76             real_map[j] = 0;
77         }
78     }
79
80     /*
81      * Initializations for a UNIX-like multi-terminal environment.  Use
82      * ASCII chars and count on the terminfo description to do better.
83      */
84     real_map['l'] = '+';        /* should be upper left corner */
85     real_map['m'] = '+';        /* should be lower left corner */
86     real_map['k'] = '+';        /* should be upper right corner */
87     real_map['j'] = '+';        /* should be lower right corner */
88     real_map['u'] = '+';        /* should be tee pointing left */
89     real_map['t'] = '+';        /* should be tee pointing right */
90     real_map['v'] = '+';        /* should be tee pointing up */
91     real_map['w'] = '+';        /* should be tee pointing down */
92     real_map['q'] = '-';        /* should be horizontal line */
93     real_map['x'] = '|';        /* should be vertical line */
94     real_map['n'] = '+';        /* should be large plus or crossover */
95     real_map['o'] = '~';        /* should be scan line 1 */
96     real_map['s'] = '_';        /* should be scan line 9 */
97     real_map['`'] = '+';        /* should be diamond */
98     real_map['a'] = ':';        /* should be checker board (stipple) */
99     real_map['f'] = '\'';       /* should be degree symbol */
100     real_map['g'] = '#';        /* should be plus/minus */
101     real_map['~'] = 'o';        /* should be bullet */
102     real_map[','] = '<';        /* should be arrow pointing left */
103     real_map['+'] = '>';        /* should be arrow pointing right */
104     real_map['.'] = 'v';        /* should be arrow pointing down */
105     real_map['-'] = '^';        /* should be arrow pointing up */
106     real_map['h'] = '#';        /* should be board of squares */
107     real_map['i'] = '#';        /* should be lantern symbol */
108     real_map['0'] = '#';        /* should be solid square block */
109     /* these defaults were invented for ncurses */
110     real_map['p'] = '-';        /* should be scan line 3 */
111     real_map['r'] = '-';        /* should be scan line 7 */
112     real_map['y'] = '<';        /* should be less-than-or-equal-to */
113     real_map['z'] = '>';        /* should be greater-than-or-equal-to */
114     real_map['{'] = '*';        /* should be greek pi */
115     real_map['|'] = '!';        /* should be not-equal */
116     real_map['}'] = 'f';        /* should be pound-sterling symbol */
117
118 #if !USE_WIDEC_SUPPORT
119     if (_nc_unicode_locale() && _nc_locale_breaks_acs()) {
120         acs_chars = NULL;
121         ena_acs = NULL;
122     }
123 #endif
124
125     if (ena_acs != NULL) {
126         TPUTS_TRACE("ena_acs");
127         putp(ena_acs);
128     }
129
130     if (acs_chars != NULL) {
131         size_t i = 0;
132         size_t length = strlen(acs_chars);
133
134         while (i + 1 < length) {
135             if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
136                 real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
137             }
138             i += 2;
139         }
140     }
141 #ifdef TRACE
142     /* Show the equivalent mapping, noting if it does not match the
143      * given attribute, whether by re-ordering or duplication.
144      */
145     if (_nc_tracing & TRACE_CALLS) {
146         size_t n, m;
147         char show[ACS_LEN + 1];
148         for (n = 1, m = 0; n < ACS_LEN; n++) {
149             if (real_map[n] != 0) {
150                 show[m++] = (char) n;
151                 show[m++] = ChCharOf(real_map[n]);
152             }
153         }
154         show[m] = 0;
155         _tracef("%s acs_chars %s",
156                 (acs_chars == NULL)
157                 ? "NULL"
158                 : (strcmp(acs_chars, show)
159                    ? "DIFF"
160                    : "SAME"),
161                 _nc_visbuf(show));
162     }
163 #endif /* TRACE */
164 }