acs.c revision 1.16 1 1.16 tnozaki /* $NetBSD: acs.c,v 1.16 2008/07/04 16:24:45 tnozaki Exp $ */
2 1.2 blymn
3 1.2 blymn /*
4 1.2 blymn * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.2 blymn * All rights reserved.
6 1.2 blymn *
7 1.2 blymn * This code is derived from software contributed to The NetBSD Foundation
8 1.2 blymn * by Julian Coleman.
9 1.2 blymn *
10 1.2 blymn * Redistribution and use in source and binary forms, with or without
11 1.2 blymn * modification, are permitted provided that the following conditions
12 1.2 blymn * are met:
13 1.2 blymn * 1. Redistributions of source code must retain the above copyright
14 1.2 blymn * notice, this list of conditions and the following disclaimer.
15 1.2 blymn * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 blymn * notice, this list of conditions and the following disclaimer in the
17 1.2 blymn * documentation and/or other materials provided with the distribution.
18 1.2 blymn *
19 1.2 blymn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 blymn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 blymn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 blymn * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 blymn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 blymn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 blymn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 blymn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 blymn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 blymn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 blymn * POSSIBILITY OF SUCH DAMAGE.
30 1.2 blymn */
31 1.7 blymn
32 1.7 blymn #include <sys/cdefs.h>
33 1.7 blymn #ifndef lint
34 1.16 tnozaki __RCSID("$NetBSD: acs.c,v 1.16 2008/07/04 16:24:45 tnozaki Exp $");
35 1.7 blymn #endif /* not lint */
36 1.2 blymn
37 1.2 blymn #include "curses.h"
38 1.2 blymn #include "curses_private.h"
39 1.2 blymn
40 1.2 blymn chtype _acs_char[NUM_ACS];
41 1.13 blymn #ifdef HAVE_WCHAR
42 1.16 tnozaki #include <assert.h>
43 1.16 tnozaki #include <langinfo.h>
44 1.16 tnozaki #include <strings.h>
45 1.13 blymn
46 1.13 blymn cchar_t _wacs_char[ NUM_ACS ];
47 1.13 blymn #endif /* HAVE_WCHAR */
48 1.2 blymn
49 1.2 blymn /*
50 1.2 blymn * __init_acs --
51 1.2 blymn * Fill in the ACS characters. The 'ac' termcap entry is a list of
52 1.2 blymn * character pairs - ACS definition then terminal representation.
53 1.2 blymn */
54 1.2 blymn void
55 1.9 blymn __init_acs(SCREEN *screen)
56 1.2 blymn {
57 1.5 jdc int count;
58 1.5 jdc char *aofac; /* Address of 'ac' */
59 1.5 jdc unsigned char acs, term;
60 1.2 blymn
61 1.2 blymn /* Default value '+' for all ACS characters */
62 1.2 blymn for (count=0; count < NUM_ACS; count++)
63 1.2 blymn _acs_char[count]= '+';
64 1.2 blymn
65 1.2 blymn /* Add the SUSv2 defaults (those that are not '+') */
66 1.2 blymn ACS_RARROW = '>';
67 1.2 blymn ACS_LARROW = '<';
68 1.2 blymn ACS_UARROW = '^';
69 1.2 blymn ACS_DARROW = 'v';
70 1.2 blymn ACS_BLOCK = '#';
71 1.2 blymn /* ACS_DIAMOND = '+'; */
72 1.2 blymn ACS_CKBOARD = ':';
73 1.2 blymn ACS_DEGREE = 39; /* ' */
74 1.2 blymn ACS_PLMINUS = '#';
75 1.2 blymn ACS_BOARD = '#';
76 1.2 blymn ACS_LANTERN = '#';
77 1.2 blymn /* ACS_LRCORNER = '+'; */
78 1.2 blymn /* ACS_URCORNER = '+'; */
79 1.2 blymn /* ACS_ULCORNER = '+'; */
80 1.2 blymn /* ACS_LLCORNER = '+'; */
81 1.2 blymn /* ACS_PLUS = '+'; */
82 1.2 blymn ACS_HLINE = '-';
83 1.2 blymn ACS_S1 = '-';
84 1.2 blymn ACS_S9 = '_';
85 1.2 blymn /* ACS_LTEE = '+'; */
86 1.2 blymn /* ACS_RTEE = '+'; */
87 1.2 blymn /* ACS_BTEE = '+'; */
88 1.2 blymn /* ACS_TTEE = '+'; */
89 1.2 blymn ACS_VLINE = '|';
90 1.2 blymn ACS_BULLET = 'o';
91 1.14 jdc /* Add the extensions defaults */
92 1.14 jdc ACS_S3 = '-';
93 1.14 jdc ACS_S7 = '-';
94 1.14 jdc ACS_LEQUAL = '<';
95 1.14 jdc ACS_GEQUAL = '>';
96 1.14 jdc ACS_PI = '*';
97 1.14 jdc ACS_NEQUAL = '!';
98 1.14 jdc ACS_STERLING = 'f';
99 1.2 blymn
100 1.10 blymn if (screen->tc_ac == NULL)
101 1.11 mycroft goto out;
102 1.2 blymn
103 1.10 blymn aofac = screen->tc_ac;
104 1.2 blymn
105 1.2 blymn while (*aofac != '\0') {
106 1.2 blymn if ((acs = *aofac) == '\0')
107 1.2 blymn return;
108 1.2 blymn if (++aofac == '\0')
109 1.2 blymn return;
110 1.2 blymn if ((term = *aofac) == '\0')
111 1.2 blymn return;
112 1.5 jdc /* Only add characters 1 to 127 */
113 1.5 jdc if (acs < NUM_ACS)
114 1.5 jdc _acs_char[acs] = term | __ALTCHARSET;
115 1.2 blymn aofac++;
116 1.2 blymn #ifdef DEBUG
117 1.12 jdc __CTRACE(__CTRACE_INIT, "__init_acs: %c = %c\n", acs, term);
118 1.2 blymn #endif
119 1.2 blymn }
120 1.2 blymn
121 1.10 blymn if (screen->tc_eA != NULL)
122 1.10 blymn t_puts(screen->cursesi_genbuf, screen->tc_eA, 0,
123 1.13 blymn __cputchar_args, screen->outfd);
124 1.11 mycroft
125 1.11 mycroft out:
126 1.11 mycroft for (count=0; count < NUM_ACS; count++)
127 1.11 mycroft screen->acs_char[count]= _acs_char[count];
128 1.9 blymn }
129 1.9 blymn
130 1.9 blymn void
131 1.9 blymn _cursesi_reset_acs(SCREEN *screen)
132 1.9 blymn {
133 1.9 blymn int count;
134 1.9 blymn
135 1.9 blymn for (count=0; count < NUM_ACS; count++)
136 1.9 blymn _acs_char[count]= screen->acs_char[count];
137 1.2 blymn }
138 1.13 blymn
139 1.13 blymn #ifdef HAVE_WCHAR
140 1.13 blymn /*
141 1.13 blymn * __init_wacs --
142 1.13 blymn * Fill in the ACS characters. The 'ac' termcap entry is a list of
143 1.13 blymn * character pairs - ACS definition then terminal representation.
144 1.13 blymn */
145 1.13 blymn void
146 1.13 blymn __init_wacs(SCREEN *screen)
147 1.13 blymn {
148 1.13 blymn int count;
149 1.13 blymn char *aofac; /* Address of 'ac' */
150 1.13 blymn unsigned char acs, term;
151 1.13 blymn char *lstr;
152 1.13 blymn
153 1.13 blymn /* Default value '+' for all ACS characters */
154 1.13 blymn for (count=0; count < NUM_ACS; count++) {
155 1.13 blymn _wacs_char[ count ].vals[ 0 ] = ( wchar_t )btowc( '+' );
156 1.13 blymn _wacs_char[ count ].attributes = 0;
157 1.13 blymn _wacs_char[ count ].elements = 1;
158 1.13 blymn }
159 1.13 blymn
160 1.13 blymn /* Add the SUSv2 defaults (those that are not '+') */
161 1.16 tnozaki lstr = nl_langinfo(CODESET);
162 1.16 tnozaki _DIAGASSERT(lstr);
163 1.16 tnozaki if (!strcasecmp(lstr, "UTF-8")) {
164 1.13 blymn #ifdef DEBUG
165 1.13 blymn __CTRACE(__CTRACE_INIT, "__init_wacs: setting defaults\n" );
166 1.13 blymn #endif /* DEBUG */
167 1.13 blymn WACS_RARROW = ( wchar_t )btowc( '>' );
168 1.13 blymn WACS_LARROW = ( wchar_t )btowc( '<' );
169 1.13 blymn WACS_UARROW = ( wchar_t )btowc( '^' );
170 1.13 blymn WACS_DARROW = ( wchar_t )btowc( 'v' );
171 1.13 blymn WACS_BLOCK = ( wchar_t )btowc( '#' );
172 1.13 blymn WACS_CKBOARD = ( wchar_t )btowc( ':' );
173 1.13 blymn WACS_DEGREE = ( wchar_t )btowc( 39 ); /* ' */
174 1.13 blymn WACS_PLMINUS = ( wchar_t )btowc( '#' );
175 1.13 blymn WACS_BOARD = ( wchar_t )btowc( '#' );
176 1.13 blymn WACS_LANTERN = ( wchar_t )btowc( '#' );
177 1.13 blymn WACS_HLINE = ( wchar_t )btowc( '-' );
178 1.13 blymn WACS_S1 = ( wchar_t )btowc( '-' );
179 1.13 blymn WACS_S9 = ( wchar_t )btowc( '_' );
180 1.13 blymn WACS_VLINE = ( wchar_t )btowc( '|' );
181 1.13 blymn WACS_BULLET = ( wchar_t )btowc( 'o' );
182 1.14 jdc WACS_S3 = ( wchar_t )btowc( 'p' );
183 1.14 jdc WACS_S7 = ( wchar_t )btowc( 'r' );
184 1.14 jdc WACS_LEQUAL = ( wchar_t )btowc( 'y' );
185 1.14 jdc WACS_GEQUAL = ( wchar_t )btowc( 'z' );
186 1.14 jdc WACS_PI = ( wchar_t )btowc( '{' );
187 1.14 jdc WACS_NEQUAL = ( wchar_t )btowc( '|' );
188 1.14 jdc WACS_STERLING = ( wchar_t )btowc( '}' );
189 1.13 blymn } else {
190 1.13 blymn /* Unicode defaults */
191 1.13 blymn #ifdef DEBUG
192 1.13 blymn __CTRACE(__CTRACE_INIT,
193 1.13 blymn "__init_wacs: setting Unicode defaults\n" );
194 1.13 blymn #endif /* DEBUG */
195 1.13 blymn WACS_RARROW = 0x2192;
196 1.13 blymn WACS_LARROW = 0x2190;
197 1.13 blymn WACS_UARROW = 0x2192;
198 1.13 blymn WACS_DARROW = 0x2193;
199 1.13 blymn WACS_BLOCK = 0x25ae;
200 1.13 blymn WACS_DIAMOND = 0x25c6;
201 1.13 blymn WACS_CKBOARD = 0x2592;
202 1.13 blymn WACS_DEGREE = 0x00b0;
203 1.13 blymn WACS_PLMINUS = 0x00b1;
204 1.13 blymn WACS_BOARD = 0x2592;
205 1.13 blymn WACS_LANTERN = 0x2603;
206 1.13 blymn WACS_LRCORNER = 0x2518;
207 1.13 blymn WACS_URCORNER = 0x2510;
208 1.13 blymn WACS_ULCORNER = 0x250c;
209 1.13 blymn WACS_LLCORNER = 0x2514;
210 1.13 blymn WACS_PLUS = 0x253c;
211 1.13 blymn WACS_HLINE = 0x2500;
212 1.13 blymn WACS_S1 = 0x23ba;
213 1.13 blymn WACS_S9 = 0x23bd;
214 1.13 blymn WACS_LTEE = 0x251c;
215 1.13 blymn WACS_RTEE = 0x2524;
216 1.13 blymn WACS_BTEE = 0x2534;
217 1.13 blymn WACS_TTEE = 0x252c;
218 1.13 blymn WACS_VLINE = 0x2502;
219 1.13 blymn WACS_BULLET = 0x00b7;
220 1.14 jdc WACS_S3 = 0x23bb;
221 1.14 jdc WACS_S7 = 0x23bc;
222 1.14 jdc WACS_LEQUAL = 0x2264;
223 1.14 jdc WACS_GEQUAL = 0x2265;
224 1.14 jdc WACS_PI = 0x03C0;
225 1.14 jdc WACS_NEQUAL = 0x2260;
226 1.14 jdc WACS_STERLING = 0x00A3;
227 1.13 blymn }
228 1.13 blymn
229 1.13 blymn if (screen->tc_ac == NULL) {
230 1.13 blymn #ifdef DEBUG
231 1.13 blymn __CTRACE(__CTRACE_INIT,
232 1.13 blymn "__init_wacs: no alternative characters\n" );
233 1.13 blymn #endif /* DEBUG */
234 1.13 blymn goto out;
235 1.13 blymn }
236 1.13 blymn
237 1.13 blymn aofac = screen->tc_ac;
238 1.13 blymn
239 1.13 blymn while (*aofac != '\0') {
240 1.13 blymn if ((acs = *aofac) == '\0')
241 1.13 blymn return;
242 1.13 blymn if (++aofac == '\0')
243 1.13 blymn return;
244 1.13 blymn if ((term = *aofac) == '\0')
245 1.13 blymn return;
246 1.13 blymn /* Only add characters 1 to 127 */
247 1.13 blymn if (acs < NUM_ACS) {
248 1.13 blymn _wacs_char[acs].vals[ 0 ] = term;
249 1.13 blymn _wacs_char[acs].attributes |= WA_ALTCHARSET;
250 1.13 blymn }
251 1.13 blymn aofac++;
252 1.13 blymn #ifdef DEBUG
253 1.13 blymn __CTRACE(__CTRACE_INIT, "__init_wacs: %c = %c\n", acs, term);
254 1.13 blymn #endif
255 1.13 blymn }
256 1.13 blymn
257 1.13 blymn if (screen->tc_eA != NULL)
258 1.13 blymn t_puts(screen->cursesi_genbuf, screen->tc_eA, 0,
259 1.13 blymn __cputchar_args, screen->outfd);
260 1.13 blymn
261 1.13 blymn out:
262 1.13 blymn for (count=0; count < NUM_ACS; count++)
263 1.13 blymn memcpy(&screen->wacs_char[count], &_wacs_char[count],
264 1.13 blymn sizeof(cchar_t));
265 1.13 blymn }
266 1.13 blymn
267 1.13 blymn void
268 1.13 blymn _cursesi_reset_wacs(SCREEN *screen)
269 1.13 blymn {
270 1.13 blymn int count;
271 1.13 blymn
272 1.13 blymn for (count=0; count < NUM_ACS; count++)
273 1.13 blymn memcpy( &_wacs_char[count], &screen->wacs_char[count],
274 1.13 blymn sizeof( cchar_t ));
275 1.13 blymn }
276 1.13 blymn #endif /* HAVE_WCHAR */
277