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 (c) 1995-1998 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 /* LINTLIBRARY */
30
31 /*
32 * wacs.c
33 *
34 * XCurses Library
35 *
36 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
37 *
38 */
39
40 #if M_RCSID
41 #ifndef lint
42 static char rcsID[] =
43 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
44 "libxcurses/src/libc/xcurses/rcs/wacs.c 1.6 1998/05/04 21:16:22 "
45 "cbates Exp $";
46 #endif
47 #endif
48
49 #include <private.h>
50 #include <limits.h>
51
52 /*
53 * Mapping defined in Xcurses Section 6.2.12 (p260).
54 */
55 const cchar_t __WACS_VLINE =
56 { 1, 1, 0, WA_ALTCHARSET, L"x" };
57 const cchar_t __WACS_HLINE =
58 { 1, 1, 0, WA_ALTCHARSET, L"q" };
59 const cchar_t __WACS_ULCORNER =
60 { 1, 1, 0, WA_ALTCHARSET, L"l" };
61 const cchar_t __WACS_URCORNER =
62 { 1, 1, 0, WA_ALTCHARSET, L"k" };
63 const cchar_t __WACS_LLCORNER =
64 { 1, 1, 0, WA_ALTCHARSET, L"m" };
65 const cchar_t __WACS_LRCORNER =
66 { 1, 1, 0, WA_ALTCHARSET, L"j" };
67 const cchar_t __WACS_RTEE =
68 { 1, 1, 0, WA_ALTCHARSET, L"u" };
69 const cchar_t __WACS_LTEE =
70 { 1, 1, 0, WA_ALTCHARSET, L"t" };
71 const cchar_t __WACS_BTEE =
72 { 1, 1, 0, WA_ALTCHARSET, L"v" };
73 const cchar_t __WACS_TTEE =
74 { 1, 1, 0, WA_ALTCHARSET, L"w" };
75 const cchar_t __WACS_PLUS =
76 { 1, 1, 0, WA_ALTCHARSET, L"n" };
77 const cchar_t __WACS_S1 =
78 { 1, 1, 0, WA_ALTCHARSET, L"o" };
79 const cchar_t __WACS_S9 =
80 { 1, 1, 0, WA_ALTCHARSET, L"s" };
81 const cchar_t __WACS_DIAMOND =
82 { 1, 1, 0, WA_ALTCHARSET, L"`" };
83 const cchar_t __WACS_CKBOARD =
84 { 1, 1, 0, WA_ALTCHARSET, L"a" };
85 const cchar_t __WACS_DEGREE =
86 { 1, 1, 0, WA_ALTCHARSET, L"f" };
87 const cchar_t __WACS_PLMINUS =
88 { 1, 1, 0, WA_ALTCHARSET, L"g" };
89 const cchar_t __WACS_BULLET =
90 { 1, 1, 0, WA_ALTCHARSET, L"~" };
91 const cchar_t __WACS_LARROW =
92 { 1, 1, 0, WA_ALTCHARSET, L"," };
93 const cchar_t __WACS_RARROW =
94 { 1, 1, 0, WA_ALTCHARSET, L"+" };
95 const cchar_t __WACS_DARROW =
96 { 1, 1, 0, WA_ALTCHARSET, L"." };
97 const cchar_t __WACS_UARROW =
98 { 1, 1, 0, WA_ALTCHARSET, L"-" };
99 const cchar_t __WACS_BOARD =
100 { 1, 1, 0, WA_ALTCHARSET, L"h" };
101 const cchar_t __WACS_LANTERN =
102 { 1, 1, 0, WA_ALTCHARSET, L"i" };
103 const cchar_t __WACS_BLOCK =
104 { 1, 1, 0, WA_ALTCHARSET, L"0" };
105
106 /* The default characters are from the _primary_ character set. */
107 static const unsigned char acs_defaults[] =
108 "x|q-l+k+m+j+u+t+v+w+n+o-s_`+a:f\'g#~o,<+>.v-^h#i#0#";
109
110 int
__m_acs_cc(chtype acs,cchar_t * cc)111 __m_acs_cc(chtype acs, cchar_t *cc)
112 {
113 int i;
114 unsigned char *acsc;
115 chtype vacs;
116
117 vacs = acs & A_CHARTEXT;
118
119 /* Is it a single-byte character? */
120 if (UCHAR_MAX < vacs ||
121 __m_chtype_cc(acs, cc) == ERR)
122 return (-1);
123
124 if (!(acs & A_ALTCHARSET))
125 return (0);
126
127 /* Pick the acs mapping string to use. */
128 if (acs_chars == NULL) {
129 /* Use primary character set. */
130 acsc = (unsigned char *) acs_defaults;
131 acs &= ~A_ALTCHARSET;
132 } else {
133 acsc = (unsigned char *) acs_chars;
134 }
135
136 /* Assume that acsc is even in length. */
137 for (i = 0; acsc[i] != '\0'; i += 2) {
138 if (acsc[i] == vacs) {
139 (void) __m_chtype_cc((chtype)
140 ((acs & A_ATTRIBUTES) | acsc[i+1]), cc);
141 break;
142 }
143 }
144
145 return (0);
146 }
147
148 /* Returns 1 if ALTCHARSET is to be cleared (override). 0 Otherwise. */
149 int
__m_wacs_cc(const cchar_t * acs,cchar_t * cc)150 __m_wacs_cc(const cchar_t *acs, cchar_t *cc)
151 {
152 int i;
153 unsigned char *acsc, mb[MB_LEN_MAX];
154 int clearit = 0;
155
156 *cc = *acs;
157 cc->_f = 1;
158
159 /* Is it a single-byte character? */
160 if (!(acs->_at & WA_ALTCHARSET) ||
161 acs->_n != 1 || wctomb((char *) mb, acs->_wc[0]) != 1)
162 /* No, just return the original character. */
163 return (0);
164
165 /* Pick the acs mapping string to use. */
166 if (acs_chars == NULL) {
167 /* Use primary character set. */
168 acsc = (unsigned char *) acs_defaults;
169 clearit = 1;
170 } else {
171 acsc = (unsigned char *) acs_chars;
172 }
173
174 /* Assume that acsc is even in length. */
175 for (i = 0; acsc[i] != '\0'; i += 2) {
176 if (acsc[i] == *mb) {
177 (void) mbtowc(cc->_wc, (char *) &acsc[i+1], 1);
178 break;
179 }
180 }
181
182 return (clearit);
183 }
184