xref: /illumos-gate/usr/src/lib/libcurses/screen/init_acs.c (revision b210e77709da8e42dfe621e10ccf4be504206058)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 /*LINTLIBRARY*/
41 
42 #include	<stdlib.h>
43 #include	<sys/types.h>
44 #include	"curses_inc.h"
45 
46 /*
47  * When the keyboard can send more than eight bits, offsets array
48  * should be changed from chars to shorts.
49  * The offsets MUST match what is in curses.h.
50  */
51 
52 static	unsigned	char	offsets[][2] = {
53 				    { '`', '*' },	/* ACS_DIAMOND */
54 				    { 'a', ':' },	/* ACS_CKBOARD */
55 				    { 'f', '\'' },	/* ACS_DEGREE */
56 				    { 'g', '#' },	/* ACS_PLMINUS */
57 				    { 'o', '-' },	/* ACS_S1 */
58 				    { 'q', '-' },	/* ACS_HLINE */
59 				    { 's', '_' },	/* ACS_S9 */
60 				    { 'x', '|' },	/* ACS_VLINE */
61 				    { '~', 'o' },	/* ACS_BULLET */
62 				    { ',', '<' },	/* ACS_LARROW */
63 				    { '+', '>' },	/* ACS_RARROW */
64 				    { '.', 'v' },	/* ACS_DARROW */
65 				    { '-', '^' },	/* ACS_UARROW */
66 				    { 'h', '#' },	/* ACS_BOARD */
67 				    { 'i', '#' },	/* ACS_LANTERN */
68 				    { '0', '#' },	/* ACS_BLOCK */
69 				};
70 
71 int
72 init_acs(void)
73 {
74 	chtype	*nacsmap;
75 	char	*cp;
76 	int	i = sizeof (offsets) / 2, to_get, must_output;
77 
78 #ifdef	_VR3_COMPAT_CODE
79 	if ((nacsmap = cur_term->_acs32map = (chtype *)
80 	    malloc(sizeof (chtype) * 0400)) == NULL)
81 #else	/* _VR3_COMPAT_CODE */
82 	if ((nacsmap = cur_term->_acsmap = (chtype *)
83 	    malloc(sizeof (chtype) * 0400)) == NULL)
84 #endif	/* _VR3_COMPAT_CODE */
85 	{
86 #ifdef	_VR3_COMPAT_CODE
87 bad:
88 #endif	/* _VR3_COMPAT_CODE */
89 		term_errno = TERM_BAD_MALLOC;
90 #ifdef	DEBUG
91 		strcpy(term_parm_err, "init_acs");
92 #endif	/* DEBUG */
93 		return (ERR);
94 	}
95 
96 	/* Default acs chars for regular ASCII terminals are plus signs. */
97 
98 	memSset(nacsmap, (chtype) '+', 0400);
99 
100 	/*
101 	* Now load in defaults for some of the characters which have close
102 	* approximations in the normal ascii set.
103 	*/
104 
105 	while (i-- > 0)
106 		nacsmap[offsets[i][0]] = offsets[i][1];
107 
108 	/* Now do mapping for terminals own ACS, if any */
109 
110 	if ((cp = acs_chars) != 0)
111 		while (*cp) {
112 			to_get = *cp++;		/* to get this ... */
113 			must_output = *cp++;	/* must output this ... */
114 #ifdef	DEBUG
115 			if (outf)
116 				fprintf(outf, "acs %d, was %d, now %d\n",
117 				    to_get, nacsmap[to_get], must_output);
118 #endif	/* DEBUG */
119 			nacsmap[to_get] = ( must_output & 0xFF ) | A_ALTCHARSET;
120 		}
121 
122 	acs_map = nacsmap;
123 
124 #ifdef	_VR3_COMPAT_CODE
125 	if (_y16update) {
126 		_ochtype	*n16acsmap;
127 
128 		if ((n16acsmap = cur_term->_acsmap = (_ochtype *)
129 		    malloc(sizeof (_ochtype) * 0400)) == NULL) {
130 			goto bad;
131 		}
132 
133 		for (i = 0; i < 0400; i++)
134 			/*LINTED*/
135 			n16acsmap[i] = _TO_OCHTYPE(nacsmap[i]);
136 #undef	acs_map
137 			acs_map = n16acsmap;
138 	}
139 #endif	/* _VR3_COMPAT_CODE */
140 	return (OK);
141 }
142