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