xref: /openbsd/lib/libcurses/tinfo/lib_acs.c (revision 133306f0)
1 /*	$OpenBSD: lib_acs.c,v 1.4 2001/01/22 18:01:52 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,1999,2000 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  ****************************************************************************/
35 
36 #include <curses.priv.h>
37 #include <term.h>		/* ena_acs, acs_chars */
38 
39 MODULE_ID("$From: lib_acs.c,v 1.18 2000/12/10 02:55:07 tom Exp $")
40 
41 NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
42 {
43     0
44 };
45 
46 NCURSES_EXPORT(void)
47 _nc_init_acs(void)
48 {
49     T(("initializing ACS map"));
50 
51     /*
52      * Initializations for a UNIX-like multi-terminal environment.  Use
53      * ASCII chars and count on the terminfo description to do better.
54      */
55     ACS_ULCORNER = '+';		/* should be upper left corner */
56     ACS_LLCORNER = '+';		/* should be lower left corner */
57     ACS_URCORNER = '+';		/* should be upper right corner */
58     ACS_LRCORNER = '+';		/* should be lower right corner */
59     ACS_RTEE = '+';		/* should be tee pointing left */
60     ACS_LTEE = '+';		/* should be tee pointing right */
61     ACS_BTEE = '+';		/* should be tee pointing up */
62     ACS_TTEE = '+';		/* should be tee pointing down */
63     ACS_HLINE = '-';		/* should be horizontal line */
64     ACS_VLINE = '|';		/* should be vertical line */
65     ACS_PLUS = '+';		/* should be large plus or crossover */
66     ACS_S1 = '~';		/* should be scan line 1 */
67     ACS_S9 = '_';		/* should be scan line 9 */
68     ACS_DIAMOND = '+';		/* should be diamond */
69     ACS_CKBOARD = ':';		/* should be checker board (stipple) */
70     ACS_DEGREE = '\'';		/* should be degree symbol */
71     ACS_PLMINUS = '#';		/* should be plus/minus */
72     ACS_BULLET = 'o';		/* should be bullet */
73     ACS_LARROW = '<';		/* should be arrow pointing left */
74     ACS_RARROW = '>';		/* should be arrow pointing right */
75     ACS_DARROW = 'v';		/* should be arrow pointing down */
76     ACS_UARROW = '^';		/* should be arrow pointing up */
77     ACS_BOARD = '#';		/* should be board of squares */
78     ACS_LANTERN = '#';		/* should be lantern symbol */
79     ACS_BLOCK = '#';		/* should be solid square block */
80     /* these defaults were invented for ncurses */
81     ACS_S3 = '-';		/* should be scan line 3 */
82     ACS_S7 = '-';		/* should be scan line 7 */
83     ACS_LEQUAL = '<';		/* should be less-than-or-equal-to */
84     ACS_GEQUAL = '>';		/* should be greater-than-or-equal-to */
85     ACS_PI = '*';		/* should be greek pi */
86     ACS_NEQUAL = '!';		/* should be not-equal */
87     ACS_STERLING = 'f';		/* should be pound-sterling symbol */
88 
89     if (ena_acs != NULL) {
90 	TPUTS_TRACE("ena_acs");
91 	putp(ena_acs);
92     }
93 #define ALTCHAR(c)	((chtype)(((unsigned char)(c)) | A_ALTCHARSET))
94 
95     if (acs_chars != NULL) {
96 	size_t i = 0;
97 	size_t length = strlen(acs_chars);
98 
99 	while (i < length)
100 	    switch (acs_chars[i]) {
101 	    case 'l':
102 	    case 'm':
103 	    case 'k':
104 	    case 'j':
105 	    case 'u':
106 	    case 't':
107 	    case 'v':
108 	    case 'w':
109 	    case 'q':
110 	    case 'x':
111 	    case 'n':
112 	    case 'o':
113 	    case 's':
114 	    case '`':
115 	    case 'a':
116 	    case 'f':
117 	    case 'g':
118 	    case '~':
119 	    case ',':
120 	    case '+':
121 	    case '.':
122 	    case '-':
123 	    case 'h':
124 	    case 'i':
125 	    case '0':
126 	    case 'p':
127 	    case 'r':
128 	    case 'y':
129 	    case 'z':
130 	    case '{':
131 	    case '|':
132 	    case '}':
133 		acs_map[(unsigned int) acs_chars[i]] =
134 		    ALTCHAR(acs_chars[i + 1]);
135 		i++;
136 		/* FALLTHRU */
137 	    default:
138 		i++;
139 		break;
140 	    }
141     }
142 #ifdef TRACE
143     /* Show the equivalent mapping, noting if it does not match the
144      * given attribute, whether by re-ordering or duplication.
145      */
146     if (_nc_tracing & TRACE_CALLS) {
147 	size_t n, m;
148 	char show[SIZEOF(acs_map) + 1];
149 	for (n = 1, m = 0; n < SIZEOF(acs_map); n++) {
150 	    if (acs_map[n] != 0) {
151 		show[m++] = (char) n;
152 		show[m++] = TextOf(acs_map[n]);
153 	    }
154 	}
155 	show[m] = 0;
156 	_tracef("%s acs_chars %s",
157 		(acs_chars == NULL)
158 		? "NULL"
159 		: (strcmp(acs_chars, show)
160 		   ? "DIFF"
161 		   : "SAME"),
162 		_nc_visbuf(show));
163     }
164 #endif /* TRACE */
165 }
166