GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libcurses/tinfo/lib_acs.c Lines: 0 59 0.0 %
Date: 2017-11-13 Branches: 0 40 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: lib_acs.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
2
3
/****************************************************************************
4
 * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
5
 *                                                                          *
6
 * Permission is hereby granted, free of charge, to any person obtaining a  *
7
 * copy of this software and associated documentation files (the            *
8
 * "Software"), to deal in the Software without restriction, including      *
9
 * without limitation the rights to use, copy, modify, merge, publish,      *
10
 * distribute, distribute with modifications, sublicense, and/or sell       *
11
 * copies of the Software, and to permit persons to whom the Software is    *
12
 * furnished to do so, subject to the following conditions:                 *
13
 *                                                                          *
14
 * The above copyright notice and this permission notice shall be included  *
15
 * in all copies or substantial portions of the Software.                   *
16
 *                                                                          *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20
 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24
 *                                                                          *
25
 * Except as contained in this notice, the name(s) of the above copyright   *
26
 * holders shall not be used in advertising or otherwise to promote the     *
27
 * sale, use or other dealings in this Software without prior written       *
28
 * authorization.                                                           *
29
 ****************************************************************************/
30
31
/****************************************************************************
32
 *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33
 *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34
 *     and: Thomas E. Dickey                        1996-on                 *
35
 ****************************************************************************/
36
37
#include <curses.priv.h>
38
#include <term.h>		/* ena_acs, acs_chars */
39
40
MODULE_ID("$Id: lib_acs.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
41
42
#if BROKEN_LINKER || USE_REENTRANT
43
#define MyBuffer _nc_prescreen.real_acs_map
44
NCURSES_EXPORT_VAR(chtype *)
45
_nc_acs_map(void)
46
{
47
    if (MyBuffer == 0)
48
	MyBuffer = typeCalloc(chtype, ACS_LEN);
49
    return MyBuffer;
50
}
51
#undef MyBuffer
52
#else
53
NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
54
{
55
    0
56
};
57
#endif
58
59
NCURSES_EXPORT(void)
60
_nc_init_acs(void)
61
{
62
    chtype *fake_map = acs_map;
63
    chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
64
    int j;
65
66
    T(("initializing ACS map"));
67
68
    /*
69
     * If we're using this from curses (rather than terminfo), we are storing
70
     * the mapping information in the SCREEN struct so we can decide how to
71
     * render it.
72
     */
73
    if (real_map != fake_map) {
74
	for (j = 1; j < ACS_LEN; ++j) {
75
	    real_map[j] = 0;
76
	    fake_map[j] = A_ALTCHARSET | j;
77
	    if (SP)
78
		SP->_screen_acs_map[j] = FALSE;
79
	}
80
    } else {
81
	for (j = 1; j < ACS_LEN; ++j) {
82
	    real_map[j] = 0;
83
	}
84
    }
85
86
    /*
87
     * Initializations for a UNIX-like multi-terminal environment.  Use
88
     * ASCII chars and count on the terminfo description to do better.
89
     */
90
    real_map['l'] = '+';	/* should be upper left corner */
91
    real_map['m'] = '+';	/* should be lower left corner */
92
    real_map['k'] = '+';	/* should be upper right corner */
93
    real_map['j'] = '+';	/* should be lower right corner */
94
    real_map['u'] = '+';	/* should be tee pointing left */
95
    real_map['t'] = '+';	/* should be tee pointing right */
96
    real_map['v'] = '+';	/* should be tee pointing up */
97
    real_map['w'] = '+';	/* should be tee pointing down */
98
    real_map['q'] = '-';	/* should be horizontal line */
99
    real_map['x'] = '|';	/* should be vertical line */
100
    real_map['n'] = '+';	/* should be large plus or crossover */
101
    real_map['o'] = '~';	/* should be scan line 1 */
102
    real_map['s'] = '_';	/* should be scan line 9 */
103
    real_map['`'] = '+';	/* should be diamond */
104
    real_map['a'] = ':';	/* should be checker board (stipple) */
105
    real_map['f'] = '\'';	/* should be degree symbol */
106
    real_map['g'] = '#';	/* should be plus/minus */
107
    real_map['~'] = 'o';	/* should be bullet */
108
    real_map[','] = '<';	/* should be arrow pointing left */
109
    real_map['+'] = '>';	/* should be arrow pointing right */
110
    real_map['.'] = 'v';	/* should be arrow pointing down */
111
    real_map['-'] = '^';	/* should be arrow pointing up */
112
    real_map['h'] = '#';	/* should be board of squares */
113
    real_map['i'] = '#';	/* should be lantern symbol */
114
    real_map['0'] = '#';	/* should be solid square block */
115
    /* these defaults were invented for ncurses */
116
    real_map['p'] = '-';	/* should be scan line 3 */
117
    real_map['r'] = '-';	/* should be scan line 7 */
118
    real_map['y'] = '<';	/* should be less-than-or-equal-to */
119
    real_map['z'] = '>';	/* should be greater-than-or-equal-to */
120
    real_map['{'] = '*';	/* should be greek pi */
121
    real_map['|'] = '!';	/* should be not-equal */
122
    real_map['}'] = 'f';	/* should be pound-sterling symbol */
123
124
    if (ena_acs != NULL) {
125
	TPUTS_TRACE("ena_acs");
126
	putp(ena_acs);
127
    }
128
#if NCURSES_EXT_FUNCS
129
    /*
130
     * Linux console "supports" the "PC ROM" character set by the coincidence
131
     * that smpch/rmpch and smacs/rmacs have the same values.  ncurses has
132
     * no codepage support (see SCO Merge for an example).  Outside of the
133
     * values defined in acsc, there are no definitions for the "PC ROM"
134
     * character set (assumed by some applications to be codepage 437), but we
135
     * allow those applications to use those codepoints.
136
     *
137
     * test/blue.c uses this feature.
138
     */
139
#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
140
    if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
141
	PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
142
	size_t i;
143
	for (i = 1; i < ACS_LEN; ++i) {
144
	    if (real_map[i] == 0) {
145
		real_map[i] = i;
146
		if (real_map != fake_map) {
147
		    if (SP != 0)
148
			SP->_screen_acs_map[i] = TRUE;
149
		}
150
	    }
151
	}
152
    }
153
#endif
154
155
    if (acs_chars != NULL) {
156
	size_t i = 0;
157
	size_t length = strlen(acs_chars);
158
159
	while (i + 1 < length) {
160
	    if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
161
		real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
162
		if (SP != 0)
163
		    SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
164
	    }
165
	    i += 2;
166
	}
167
    }
168
#ifdef TRACE
169
    /* Show the equivalent mapping, noting if it does not match the
170
     * given attribute, whether by re-ordering or duplication.
171
     */
172
    if (USE_TRACEF(TRACE_CALLS)) {
173
	size_t n, m;
174
	char show[ACS_LEN * 2 + 1];
175
	for (n = 1, m = 0; n < ACS_LEN; n++) {
176
	    if (real_map[n] != 0) {
177
		show[m++] = (char) n;
178
		show[m++] = (char) ChCharOf(real_map[n]);
179
	    }
180
	}
181
	show[m] = 0;
182
	if (acs_chars == NULL || strcmp(acs_chars, show))
183
	    _tracef("%s acs_chars %s",
184
		    (acs_chars == NULL) ? "NULL" : "READ",
185
		    _nc_visbuf(acs_chars));
186
	_tracef("%s acs_chars %s",
187
		(acs_chars == NULL)
188
		? "NULL"
189
		: (strcmp(acs_chars, show)
190
		   ? "DIFF"
191
		   : "SAME"),
192
		_nc_visbuf(show));
193
	_nc_unlock_global(tracef);
194
    }
195
#endif /* TRACE */
196
}