150276Speter/****************************************************************************
2184989Srafan * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
350276Speter *                                                                          *
450276Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
550276Speter * copy of this software and associated documentation files (the            *
650276Speter * "Software"), to deal in the Software without restriction, including      *
750276Speter * without limitation the rights to use, copy, modify, merge, publish,      *
850276Speter * distribute, distribute with modifications, sublicense, and/or sell       *
950276Speter * copies of the Software, and to permit persons to whom the Software is    *
1050276Speter * furnished to do so, subject to the following conditions:                 *
1150276Speter *                                                                          *
1250276Speter * The above copyright notice and this permission notice shall be included  *
1350276Speter * in all copies or substantial portions of the Software.                   *
1450276Speter *                                                                          *
1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2250276Speter *                                                                          *
2350276Speter * Except as contained in this notice, the name(s) of the above copyright   *
2450276Speter * holders shall not be used in advertising or otherwise to promote the     *
2550276Speter * sale, use or other dealings in this Software without prior written       *
2650276Speter * authorization.                                                           *
2750276Speter ****************************************************************************/
2850276Speter
2950276Speter/****************************************************************************
3050276Speter *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
3150276Speter *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32166124Srafan *     and: Thomas E. Dickey                        1996-on                 *
3350276Speter ****************************************************************************/
3450276Speter
3550276Speter#include <curses.priv.h>
3676726Speter#include <term.h>		/* ena_acs, acs_chars */
3750276Speter
38184989SrafanMODULE_ID("$Id: lib_acs.c,v 1.36 2008/08/16 19:22:55 tom Exp $")
3950276Speter
40174993Srafan#if BROKEN_LINKER || USE_REENTRANT
41174993Srafan#define MyBuffer _nc_prescreen.real_acs_map
4297049SpeterNCURSES_EXPORT_VAR(chtype *)
4397049Speter_nc_acs_map(void)
4497049Speter{
45174993Srafan    if (MyBuffer == 0)
46174993Srafan	MyBuffer = typeCalloc(chtype, ACS_LEN);
47174993Srafan    return MyBuffer;
4897049Speter}
49174993Srafan#undef MyBuffer
5097049Speter#else
5176726SpeterNCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
5276726Speter{
5376726Speter    0
5476726Speter};
5597049Speter#endif
5650276Speter
5776726SpeterNCURSES_EXPORT(void)
5876726Speter_nc_init_acs(void)
5950276Speter{
60166124Srafan    chtype *fake_map = acs_map;
61166124Srafan    chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
62166124Srafan    int j;
63166124Srafan
6476726Speter    T(("initializing ACS map"));
6550276Speter
6676726Speter    /*
67166124Srafan     * If we're using this from curses (rather than terminfo), we are storing
68166124Srafan     * the mapping information in the SCREEN struct so we can decide how to
69166124Srafan     * render it.
70166124Srafan     */
71166124Srafan    if (real_map != fake_map) {
72166124Srafan	for (j = 1; j < ACS_LEN; ++j) {
73166124Srafan	    real_map[j] = 0;
74166124Srafan	    fake_map[j] = A_ALTCHARSET | j;
75184989Srafan	    if (SP)
76184989Srafan		SP->_screen_acs_map[j] = FALSE;
77166124Srafan	}
78166124Srafan    } else {
79166124Srafan	for (j = 1; j < ACS_LEN; ++j) {
80166124Srafan	    real_map[j] = 0;
81166124Srafan	}
82166124Srafan    }
83166124Srafan
84166124Srafan    /*
8576726Speter     * Initializations for a UNIX-like multi-terminal environment.  Use
8676726Speter     * ASCII chars and count on the terminfo description to do better.
8776726Speter     */
88166124Srafan    real_map['l'] = '+';	/* should be upper left corner */
89166124Srafan    real_map['m'] = '+';	/* should be lower left corner */
90166124Srafan    real_map['k'] = '+';	/* should be upper right corner */
91166124Srafan    real_map['j'] = '+';	/* should be lower right corner */
92166124Srafan    real_map['u'] = '+';	/* should be tee pointing left */
93166124Srafan    real_map['t'] = '+';	/* should be tee pointing right */
94166124Srafan    real_map['v'] = '+';	/* should be tee pointing up */
95166124Srafan    real_map['w'] = '+';	/* should be tee pointing down */
96166124Srafan    real_map['q'] = '-';	/* should be horizontal line */
97166124Srafan    real_map['x'] = '|';	/* should be vertical line */
98166124Srafan    real_map['n'] = '+';	/* should be large plus or crossover */
99166124Srafan    real_map['o'] = '~';	/* should be scan line 1 */
100166124Srafan    real_map['s'] = '_';	/* should be scan line 9 */
101166124Srafan    real_map['`'] = '+';	/* should be diamond */
102166124Srafan    real_map['a'] = ':';	/* should be checker board (stipple) */
103166124Srafan    real_map['f'] = '\'';	/* should be degree symbol */
104166124Srafan    real_map['g'] = '#';	/* should be plus/minus */
105166124Srafan    real_map['~'] = 'o';	/* should be bullet */
106166124Srafan    real_map[','] = '<';	/* should be arrow pointing left */
107166124Srafan    real_map['+'] = '>';	/* should be arrow pointing right */
108166124Srafan    real_map['.'] = 'v';	/* should be arrow pointing down */
109166124Srafan    real_map['-'] = '^';	/* should be arrow pointing up */
110166124Srafan    real_map['h'] = '#';	/* should be board of squares */
111166124Srafan    real_map['i'] = '#';	/* should be lantern symbol */
112166124Srafan    real_map['0'] = '#';	/* should be solid square block */
11376726Speter    /* these defaults were invented for ncurses */
114166124Srafan    real_map['p'] = '-';	/* should be scan line 3 */
115166124Srafan    real_map['r'] = '-';	/* should be scan line 7 */
116166124Srafan    real_map['y'] = '<';	/* should be less-than-or-equal-to */
117166124Srafan    real_map['z'] = '>';	/* should be greater-than-or-equal-to */
118166124Srafan    real_map['{'] = '*';	/* should be greek pi */
119166124Srafan    real_map['|'] = '!';	/* should be not-equal */
120166124Srafan    real_map['}'] = 'f';	/* should be pound-sterling symbol */
12150276Speter
12276726Speter    if (ena_acs != NULL) {
12376726Speter	TPUTS_TRACE("ena_acs");
12476726Speter	putp(ena_acs);
12576726Speter    }
126166124Srafan#if NCURSES_EXT_FUNCS
127166124Srafan    /*
128166124Srafan     * Linux console "supports" the "PC ROM" character set by the coincidence
129166124Srafan     * that smpch/rmpch and smacs/rmacs have the same values.  ncurses has
130166124Srafan     * no codepage support (see SCO Merge for an example).  Outside of the
131166124Srafan     * values defined in acsc, there are no definitions for the "PC ROM"
132166124Srafan     * character set (assumed by some applications to be codepage 437), but we
133166124Srafan     * allow those applications to use those codepoints.
134166124Srafan     *
135166124Srafan     * test/blue.c uses this feature.
136166124Srafan     */
137166124Srafan#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
138166124Srafan    if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
139166124Srafan	PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
140166124Srafan	size_t i;
141166124Srafan	for (i = 1; i < ACS_LEN; ++i) {
142166124Srafan	    if (real_map[i] == 0) {
143166124Srafan		real_map[i] = i;
144166124Srafan		if (real_map != fake_map) {
145166124Srafan		    if (SP != 0)
146166124Srafan			SP->_screen_acs_map[i] = TRUE;
147166124Srafan		}
148166124Srafan	    }
149166124Srafan	}
150166124Srafan    }
151166124Srafan#endif
15250276Speter
15376726Speter    if (acs_chars != NULL) {
15476726Speter	size_t i = 0;
15576726Speter	size_t length = strlen(acs_chars);
15650276Speter
157166124Srafan	while (i + 1 < length) {
158166124Srafan	    if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
159166124Srafan		real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
160166124Srafan		if (SP != 0)
161166124Srafan		    SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
16276726Speter	    }
163166124Srafan	    i += 2;
164166124Srafan	}
16576726Speter    }
16650276Speter#ifdef TRACE
16776726Speter    /* Show the equivalent mapping, noting if it does not match the
16876726Speter     * given attribute, whether by re-ordering or duplication.
16976726Speter     */
170174993Srafan    if (USE_TRACEF(TRACE_CALLS)) {
17176726Speter	size_t n, m;
172166124Srafan	char show[ACS_LEN * 2 + 1];
17397049Speter	for (n = 1, m = 0; n < ACS_LEN; n++) {
174166124Srafan	    if (real_map[n] != 0) {
17576726Speter		show[m++] = (char) n;
176184989Srafan		show[m++] = (char) ChCharOf(real_map[n]);
17776726Speter	    }
17850276Speter	}
17976726Speter	show[m] = 0;
180166124Srafan	if (acs_chars == NULL || strcmp(acs_chars, show))
181166124Srafan	    _tracef("%s acs_chars %s",
182166124Srafan		    (acs_chars == NULL) ? "NULL" : "READ",
183166124Srafan		    _nc_visbuf(acs_chars));
18476726Speter	_tracef("%s acs_chars %s",
18576726Speter		(acs_chars == NULL)
18676726Speter		? "NULL"
18776726Speter		: (strcmp(acs_chars, show)
18876726Speter		   ? "DIFF"
18976726Speter		   : "SAME"),
19076726Speter		_nc_visbuf(show));
191174993Srafan	_nc_unlock_global(tracef);
19276726Speter    }
19350276Speter#endif /* TRACE */
19450276Speter}
195