xref: /titanic_52/usr/src/lib/libcurses/screen/init_acs.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 /*LINTLIBRARY*/
43 
44 #include	<stdlib.h>
45 #include	<sys/types.h>
46 #include	"curses_inc.h"
47 
48 /*
49  * When the keyboard can send more than eight bits, offsets array
50  * should be changed from chars to shorts.
51  * The offsets MUST match what is in curses.h.
52  */
53 
54 static	unsigned	char	offsets[][2] = {
55 				    { '`', '*' },	/* ACS_DIAMOND */
56 				    { 'a', ':' },	/* ACS_CKBOARD */
57 				    { 'f', '\'' },	/* ACS_DEGREE */
58 				    { 'g', '#' },	/* ACS_PLMINUS */
59 				    { 'o', '-' },	/* ACS_S1 */
60 				    { 'q', '-' },	/* ACS_HLINE */
61 				    { 's', '_' },	/* ACS_S9 */
62 				    { 'x', '|' },	/* ACS_VLINE */
63 				    { '~', 'o' },	/* ACS_BULLET */
64 				    { ',', '<' },	/* ACS_LARROW */
65 				    { '+', '>' },	/* ACS_RARROW */
66 				    { '.', 'v' },	/* ACS_DARROW */
67 				    { '-', '^' },	/* ACS_UARROW */
68 				    { 'h', '#' },	/* ACS_BOARD */
69 				    { 'i', '#' },	/* ACS_LANTERN */
70 				    { '0', '#' },	/* ACS_BLOCK */
71 				};
72 
73 int
74 init_acs(void)
75 {
76 	chtype	*nacsmap;
77 	char	*cp;
78 	int	i = sizeof (offsets) / 2, to_get, must_output;
79 
80 #ifdef	_VR3_COMPAT_CODE
81 	if ((nacsmap = cur_term->_acs32map = (chtype *)
82 	    malloc(sizeof (chtype) * 0400)) == NULL)
83 #else	/* _VR3_COMPAT_CODE */
84 	if ((nacsmap = cur_term->_acsmap = (chtype *)
85 	    malloc(sizeof (chtype) * 0400)) == NULL)
86 #endif	/* _VR3_COMPAT_CODE */
87 	{
88 #ifdef	_VR3_COMPAT_CODE
89 bad:
90 #endif	/* _VR3_COMPAT_CODE */
91 		term_errno = TERM_BAD_MALLOC;
92 #ifdef	DEBUG
93 		strcpy(term_parm_err, "init_acs");
94 #endif	/* DEBUG */
95 		return (ERR);
96 	}
97 
98 	/* Default acs chars for regular ASCII terminals are plus signs. */
99 
100 	memSset(nacsmap, (chtype) '+', 0400);
101 
102 	/*
103 	* Now load in defaults for some of the characters which have close
104 	* approximations in the normal ascii set.
105 	*/
106 
107 	while (i-- > 0)
108 		nacsmap[offsets[i][0]] = offsets[i][1];
109 
110 	/* Now do mapping for terminals own ACS, if any */
111 
112 	if ((cp = acs_chars) != 0)
113 		while (*cp) {
114 			to_get = *cp++;		/* to get this ... */
115 			must_output = *cp++;	/* must output this ... */
116 #ifdef	DEBUG
117 			if (outf)
118 				fprintf(outf, "acs %d, was %d, now %d\n",
119 				    to_get, nacsmap[to_get], must_output);
120 #endif	/* DEBUG */
121 			nacsmap[to_get] = ( must_output & 0xFF ) | A_ALTCHARSET;
122 		}
123 
124 	acs_map = nacsmap;
125 
126 #ifdef	_VR3_COMPAT_CODE
127 	if (_y16update) {
128 		_ochtype	*n16acsmap;
129 
130 		if ((n16acsmap = cur_term->_acsmap = (_ochtype *)
131 		    malloc(sizeof (_ochtype) * 0400)) == NULL) {
132 			goto bad;
133 		}
134 
135 		for (i = 0; i < 0400; i++)
136 			/*LINTED*/
137 			n16acsmap[i] = _TO_OCHTYPE(nacsmap[i]);
138 #undef	acs_map
139 			acs_map = n16acsmap;
140 	}
141 #endif	/* _VR3_COMPAT_CODE */
142 	return (OK);
143 }
144