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