lib_acs.c revision 184989
140516Swpaul/****************************************************************************
2119868Swpaul * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
340516Swpaul *                                                                          *
440516Swpaul * Permission is hereby granted, free of charge, to any person obtaining a  *
540516Swpaul * copy of this software and associated documentation files (the            *
640516Swpaul * "Software"), to deal in the Software without restriction, including      *
740516Swpaul * without limitation the rights to use, copy, modify, merge, publish,      *
840516Swpaul * distribute, distribute with modifications, sublicense, and/or sell       *
940516Swpaul * copies of the Software, and to permit persons to whom the Software is    *
1040516Swpaul * furnished to do so, subject to the following conditions:                 *
1140516Swpaul *                                                                          *
1240516Swpaul * The above copyright notice and this permission notice shall be included  *
1340516Swpaul * in all copies or substantial portions of the Software.                   *
1440516Swpaul *                                                                          *
1540516Swpaul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1640516Swpaul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1740516Swpaul * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1840516Swpaul * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1940516Swpaul * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2040516Swpaul * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2140516Swpaul * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2240516Swpaul *                                                                          *
2340516Swpaul * Except as contained in this notice, the name(s) of the above copyright   *
2440516Swpaul * holders shall not be used in advertising or otherwise to promote the     *
2540516Swpaul * sale, use or other dealings in this Software without prior written       *
2640516Swpaul * authorization.                                                           *
2740516Swpaul ****************************************************************************/
2840516Swpaul
2940516Swpaul/****************************************************************************
3040516Swpaul *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
3140516Swpaul *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
3240516Swpaul *     and: Thomas E. Dickey                        1996-on                 *
33122678Sobrien ****************************************************************************/
34122678Sobrien
35122678Sobrien#include <curses.priv.h>
3640516Swpaul#include <term.h>		/* ena_acs, acs_chars */
37119868Swpaul
3840516SwpaulMODULE_ID("$Id: lib_acs.c,v 1.36 2008/08/16 19:22:55 tom Exp $")
39119868Swpaul
40119868Swpaul#if BROKEN_LINKER || USE_REENTRANT
4140516Swpaul#define MyBuffer _nc_prescreen.real_acs_map
4240516SwpaulNCURSES_EXPORT_VAR(chtype *)
43119868Swpaul_nc_acs_map(void)
44119868Swpaul{
45119868Swpaul    if (MyBuffer == 0)
4640516Swpaul	MyBuffer = typeCalloc(chtype, ACS_LEN);
4740516Swpaul    return MyBuffer;
4840516Swpaul}
4940516Swpaul#undef MyBuffer
5040516Swpaul#else
5140516SwpaulNCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
5240516Swpaul{
5340516Swpaul    0
5440516Swpaul};
5540516Swpaul#endif
5641569Swpaul
5740516SwpaulNCURSES_EXPORT(void)
5840516Swpaul_nc_init_acs(void)
5940516Swpaul{
6040516Swpaul    chtype *fake_map = acs_map;
6140516Swpaul    chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
6240516Swpaul    int j;
6340516Swpaul
6440516Swpaul    T(("initializing ACS map"));
6540516Swpaul
6640516Swpaul    /*
6740516Swpaul     * If we're using this from curses (rather than terminfo), we are storing
6840516Swpaul     * the mapping information in the SCREEN struct so we can decide how to
6940516Swpaul     * render it.
7040516Swpaul     */
7140516Swpaul    if (real_map != fake_map) {
7240516Swpaul	for (j = 1; j < ACS_LEN; ++j) {
7340516Swpaul	    real_map[j] = 0;
7440516Swpaul	    fake_map[j] = A_ALTCHARSET | j;
7540516Swpaul	    if (SP)
7640516Swpaul		SP->_screen_acs_map[j] = FALSE;
7740516Swpaul	}
7840516Swpaul    } else {
7940516Swpaul	for (j = 1; j < ACS_LEN; ++j) {
8040516Swpaul	    real_map[j] = 0;
8140516Swpaul	}
8240516Swpaul    }
8340516Swpaul
8440516Swpaul    /*
8540516Swpaul     * Initializations for a UNIX-like multi-terminal environment.  Use
8640516Swpaul     * ASCII chars and count on the terminfo description to do better.
87108729Sjake     */
8840516Swpaul    real_map['l'] = '+';	/* should be upper left corner */
8940516Swpaul    real_map['m'] = '+';	/* should be lower left corner */
9040516Swpaul    real_map['k'] = '+';	/* should be upper right corner */
9140516Swpaul    real_map['j'] = '+';	/* should be lower right corner */
9240516Swpaul    real_map['u'] = '+';	/* should be tee pointing left */
9340516Swpaul    real_map['t'] = '+';	/* should be tee pointing right */
9440516Swpaul    real_map['v'] = '+';	/* should be tee pointing up */
9540516Swpaul    real_map['w'] = '+';	/* should be tee pointing down */
9640516Swpaul    real_map['q'] = '-';	/* should be horizontal line */
9740516Swpaul    real_map['x'] = '|';	/* should be vertical line */
9840516Swpaul    real_map['n'] = '+';	/* should be large plus or crossover */
9940516Swpaul    real_map['o'] = '~';	/* should be scan line 1 */
10040516Swpaul    real_map['s'] = '_';	/* should be scan line 9 */
10140516Swpaul    real_map['`'] = '+';	/* should be diamond */
10240516Swpaul    real_map['a'] = ':';	/* should be checker board (stipple) */
10341569Swpaul    real_map['f'] = '\'';	/* should be degree symbol */
10441569Swpaul    real_map['g'] = '#';	/* should be plus/minus */
10541569Swpaul    real_map['~'] = 'o';	/* should be bullet */
10650703Swpaul    real_map[','] = '<';	/* should be arrow pointing left */
10750703Swpaul    real_map['+'] = '>';	/* should be arrow pointing right */
10850703Swpaul    real_map['.'] = 'v';	/* should be arrow pointing down */
10940516Swpaul    real_map['-'] = '^';	/* should be arrow pointing up */
11050703Swpaul    real_map['h'] = '#';	/* should be board of squares */
11150703Swpaul    real_map['i'] = '#';	/* should be lantern symbol */
11250703Swpaul    real_map['0'] = '#';	/* should be solid square block */
113119871Swpaul    /* these defaults were invented for ncurses */
114119871Swpaul    real_map['p'] = '-';	/* should be scan line 3 */
11540516Swpaul    real_map['r'] = '-';	/* should be scan line 7 */
116113506Smdodd    real_map['y'] = '<';	/* should be less-than-or-equal-to */
117113506Smdodd    real_map['z'] = '>';	/* should be greater-than-or-equal-to */
11859758Speter    real_map['{'] = '*';	/* should be greek pi */
11959758Speter    real_map['|'] = '!';	/* should be not-equal */
12051089Speter    real_map['}'] = 'f';	/* should be pound-sterling symbol */
12150703Swpaul
12250703Swpaul    if (ena_acs != NULL) {
12340516Swpaul	TPUTS_TRACE("ena_acs");
12440516Swpaul	putp(ena_acs);
12540516Swpaul    }
12640516Swpaul#if NCURSES_EXT_FUNCS
12740516Swpaul    /*
12840516Swpaul     * Linux console "supports" the "PC ROM" character set by the coincidence
12940516Swpaul     * that smpch/rmpch and smacs/rmacs have the same values.  ncurses has
13040516Swpaul     * no codepage support (see SCO Merge for an example).  Outside of the
13140516Swpaul     * values defined in acsc, there are no definitions for the "PC ROM"
13240516Swpaul     * character set (assumed by some applications to be codepage 437), but we
13340516Swpaul     * allow those applications to use those codepoints.
13440516Swpaul     *
13540516Swpaul     * test/blue.c uses this feature.
13640516Swpaul     */
13740516Swpaul#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
13840516Swpaul    if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
139117388Swpaul	PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
14040516Swpaul	size_t i;
141117388Swpaul	for (i = 1; i < ACS_LEN; ++i) {
14240516Swpaul	    if (real_map[i] == 0) {
143117388Swpaul		real_map[i] = i;
14467771Swpaul		if (real_map != fake_map) {
145118978Swpaul		    if (SP != 0)
146118978Swpaul			SP->_screen_acs_map[i] = TRUE;
147117388Swpaul		}
14841243Swpaul	    }
149117388Swpaul	}
15044238Swpaul    }
151117388Swpaul#endif
15244238Swpaul
153117388Swpaul    if (acs_chars != NULL) {
15472813Swpaul	size_t i = 0;
155117388Swpaul	size_t length = strlen(acs_chars);
15696112Sjhb
157117388Swpaul	while (i + 1 < length) {
15894400Swpaul	    if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
159117388Swpaul		real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
160103020Siwasaki		if (SP != 0)
161117388Swpaul		    SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
162109095Ssanpei	    }
163117388Swpaul	    i += 2;
164111381Sdan	}
165117388Swpaul    }
166112379Ssanpei#ifdef TRACE
167117388Swpaul    /* Show the equivalent mapping, noting if it does not match the
168117388Swpaul     * given attribute, whether by re-ordering or duplication.
169117388Swpaul     */
170117388Swpaul    if (USE_TRACEF(TRACE_CALLS)) {
171117388Swpaul	size_t n, m;
172117388Swpaul	char show[ACS_LEN * 2 + 1];
173123740Speter	for (n = 1, m = 0; n < ACS_LEN; n++) {
17440516Swpaul	    if (real_map[n] != 0) {
17540516Swpaul		show[m++] = (char) n;
17692739Salfred		show[m++] = (char) ChCharOf(real_map[n]);
17792739Salfred	    }
17892739Salfred	}
17940516Swpaul	show[m] = 0;
180119868Swpaul	if (acs_chars == NULL || strcmp(acs_chars, show))
18140516Swpaul	    _tracef("%s acs_chars %s",
18292739Salfred		    (acs_chars == NULL) ? "NULL" : "READ",
18392739Salfred		    _nc_visbuf(acs_chars));
18492739Salfred	_tracef("%s acs_chars %s",
18592739Salfred		(acs_chars == NULL)
18692739Salfred		? "NULL"
18792739Salfred		: (strcmp(acs_chars, show)
18892739Salfred		   ? "DIFF"
18992739Salfred		   : "SAME"),
19092739Salfred		_nc_visbuf(show));
19192739Salfred	_nc_unlock_global(tracef);
19292739Salfred    }
19392739Salfred#endif /* TRACE */
19492739Salfred}
19592739Salfred