Home | History | Annotate | Line # | Download | only in libcurses
acs.c revision 1.18
      1  1.18  drochner /*	$NetBSD: acs.c,v 1.18 2010/02/23 19:48:26 drochner 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.18  drochner __RCSID("$NetBSD: acs.c,v 1.18 2010/02/23 19:48:26 drochner 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.18  drochner #include <locale.h>
     44  1.16   tnozaki #include <langinfo.h>
     45  1.16   tnozaki #include <strings.h>
     46  1.13     blymn 
     47  1.13     blymn cchar_t _wacs_char[ NUM_ACS ];
     48  1.13     blymn #endif /* HAVE_WCHAR */
     49   1.2     blymn 
     50   1.2     blymn /*
     51   1.2     blymn  * __init_acs --
     52   1.2     blymn  *	Fill in the ACS characters.  The 'ac' termcap entry is a list of
     53   1.2     blymn  *	character pairs - ACS definition then terminal representation.
     54   1.2     blymn  */
     55   1.2     blymn void
     56   1.9     blymn __init_acs(SCREEN *screen)
     57   1.2     blymn {
     58   1.5       jdc 	int		count;
     59  1.17       roy 	const char	*aofac;	/* Address of 'ac' */
     60   1.5       jdc 	unsigned char	acs, term;
     61   1.2     blymn 
     62   1.2     blymn 	/* Default value '+' for all ACS characters */
     63   1.2     blymn 	for (count=0; count < NUM_ACS; count++)
     64   1.2     blymn 		_acs_char[count]= '+';
     65   1.2     blymn 
     66   1.2     blymn 	/* Add the SUSv2 defaults (those that are not '+') */
     67   1.2     blymn 	ACS_RARROW = '>';
     68   1.2     blymn 	ACS_LARROW = '<';
     69   1.2     blymn 	ACS_UARROW = '^';
     70   1.2     blymn 	ACS_DARROW = 'v';
     71   1.2     blymn 	ACS_BLOCK = '#';
     72   1.2     blymn /*	ACS_DIAMOND = '+';	*/
     73   1.2     blymn 	ACS_CKBOARD = ':';
     74   1.2     blymn 	ACS_DEGREE = 39;	/* ' */
     75   1.2     blymn 	ACS_PLMINUS = '#';
     76   1.2     blymn 	ACS_BOARD = '#';
     77   1.2     blymn 	ACS_LANTERN = '#';
     78   1.2     blymn /*	ACS_LRCORNER = '+';	*/
     79   1.2     blymn /*	ACS_URCORNER = '+';	*/
     80   1.2     blymn /*	ACS_ULCORNER = '+';	*/
     81   1.2     blymn /*	ACS_LLCORNER = '+';	*/
     82   1.2     blymn /*	ACS_PLUS = '+';		*/
     83   1.2     blymn 	ACS_HLINE = '-';
     84   1.2     blymn 	ACS_S1 = '-';
     85   1.2     blymn 	ACS_S9 = '_';
     86   1.2     blymn /*	ACS_LTEE = '+';		*/
     87   1.2     blymn /*	ACS_RTEE = '+';		*/
     88   1.2     blymn /*	ACS_BTEE = '+';		*/
     89   1.2     blymn /*	ACS_TTEE = '+';		*/
     90   1.2     blymn 	ACS_VLINE = '|';
     91   1.2     blymn 	ACS_BULLET = 'o';
     92  1.14       jdc 	/* Add the extensions defaults */
     93  1.14       jdc 	ACS_S3 = '-';
     94  1.14       jdc 	ACS_S7 = '-';
     95  1.14       jdc 	ACS_LEQUAL = '<';
     96  1.14       jdc 	ACS_GEQUAL = '>';
     97  1.14       jdc 	ACS_PI = '*';
     98  1.14       jdc 	ACS_NEQUAL = '!';
     99  1.14       jdc 	ACS_STERLING = 'f';
    100   1.2     blymn 
    101  1.17       roy 	if (t_acs_chars(screen->term) == NULL)
    102  1.11   mycroft 		goto out;
    103   1.2     blymn 
    104  1.17       roy 	aofac = t_acs_chars(screen->term);
    105   1.2     blymn 
    106   1.2     blymn 	while (*aofac != '\0') {
    107   1.2     blymn 		if ((acs = *aofac) == '\0')
    108   1.2     blymn 			return;
    109  1.18  drochner 		if ((term = *++aofac) == '\0')
    110   1.2     blymn 			return;
    111   1.5       jdc 	 	/* Only add characters 1 to 127 */
    112   1.5       jdc 		if (acs < NUM_ACS)
    113   1.5       jdc 			_acs_char[acs] = term | __ALTCHARSET;
    114   1.2     blymn 		aofac++;
    115   1.2     blymn #ifdef DEBUG
    116  1.12       jdc 		__CTRACE(__CTRACE_INIT, "__init_acs: %c = %c\n", acs, term);
    117   1.2     blymn #endif
    118   1.2     blymn 	}
    119   1.2     blymn 
    120  1.17       roy 	if (t_ena_acs(screen->term) != NULL)
    121  1.17       roy 		ti_puts(screen->term, t_ena_acs(screen->term), 0,
    122  1.13     blymn 		    __cputchar_args, screen->outfd);
    123  1.11   mycroft 
    124  1.11   mycroft out:
    125  1.11   mycroft 	for (count=0; count < NUM_ACS; count++)
    126  1.11   mycroft 		screen->acs_char[count]= _acs_char[count];
    127   1.9     blymn }
    128   1.9     blymn 
    129   1.9     blymn void
    130   1.9     blymn _cursesi_reset_acs(SCREEN *screen)
    131   1.9     blymn {
    132   1.9     blymn 	int count;
    133   1.9     blymn 
    134   1.9     blymn 	for (count=0; count < NUM_ACS; count++)
    135   1.9     blymn 		_acs_char[count]= screen->acs_char[count];
    136   1.2     blymn }
    137  1.13     blymn 
    138  1.13     blymn #ifdef HAVE_WCHAR
    139  1.13     blymn /*
    140  1.13     blymn  * __init_wacs --
    141  1.13     blymn  *	Fill in the ACS characters.  The 'ac' termcap entry is a list of
    142  1.13     blymn  *	character pairs - ACS definition then terminal representation.
    143  1.13     blymn  */
    144  1.13     blymn void
    145  1.13     blymn __init_wacs(SCREEN *screen)
    146  1.13     blymn {
    147  1.13     blymn 	int		count;
    148  1.17       roy 	const char	*aofac;	/* Address of 'ac' */
    149  1.13     blymn 	unsigned char	acs, term;
    150  1.13     blymn 	char	*lstr;
    151  1.13     blymn 
    152  1.13     blymn 	/* Default value '+' for all ACS characters */
    153  1.13     blymn 	for (count=0; count < NUM_ACS; count++) {
    154  1.13     blymn 		_wacs_char[ count ].vals[ 0 ] = ( wchar_t )btowc( '+' );
    155  1.13     blymn 		_wacs_char[ count ].attributes = 0;
    156  1.13     blymn 		_wacs_char[ count ].elements = 1;
    157  1.13     blymn 	}
    158  1.13     blymn 
    159  1.13     blymn 	/* Add the SUSv2 defaults (those that are not '+') */
    160  1.18  drochner 	if (!strcmp(setlocale(LC_CTYPE, NULL), "C"))
    161  1.18  drochner 		setlocale(LC_CTYPE, "");
    162  1.16   tnozaki 	lstr = nl_langinfo(CODESET);
    163  1.16   tnozaki 	_DIAGASSERT(lstr);
    164  1.18  drochner 	if (strcasecmp(lstr, "UTF-8")) {
    165  1.13     blymn #ifdef DEBUG
    166  1.13     blymn 		__CTRACE(__CTRACE_INIT, "__init_wacs: setting defaults\n" );
    167  1.13     blymn #endif /* DEBUG */
    168  1.18  drochner 		WACS_RARROW->vals[0]  = ( wchar_t )btowc( '>' );
    169  1.18  drochner 		WACS_LARROW->vals[0]  = ( wchar_t )btowc( '<' );
    170  1.18  drochner 		WACS_UARROW->vals[0]  = ( wchar_t )btowc( '^' );
    171  1.18  drochner 		WACS_DARROW->vals[0]  = ( wchar_t )btowc( 'v' );
    172  1.18  drochner 		WACS_BLOCK->vals[0]   = ( wchar_t )btowc( '#' );
    173  1.18  drochner 		WACS_CKBOARD->vals[0] = ( wchar_t )btowc( ':' );
    174  1.18  drochner 		WACS_DEGREE->vals[0]  = ( wchar_t )btowc( 39 );	/* ' */
    175  1.18  drochner 		WACS_PLMINUS->vals[0] = ( wchar_t )btowc( '#' );
    176  1.18  drochner 		WACS_BOARD->vals[0]   = ( wchar_t )btowc( '#' );
    177  1.18  drochner 		WACS_LANTERN->vals[0] = ( wchar_t )btowc( '#' );
    178  1.18  drochner 		WACS_HLINE->vals[0]   = ( wchar_t )btowc( '-' );
    179  1.18  drochner 		WACS_S1->vals[0]      = ( wchar_t )btowc( '-' );
    180  1.18  drochner 		WACS_S9->vals[0]      = ( wchar_t )btowc( '_' );
    181  1.18  drochner 		WACS_VLINE->vals[0]   = ( wchar_t )btowc( '|' );
    182  1.18  drochner 		WACS_BULLET->vals[0]  = ( wchar_t )btowc( 'o' );
    183  1.18  drochner 		WACS_S3->vals[0]      = ( wchar_t )btowc( 'p' );
    184  1.18  drochner 		WACS_S7->vals[0]      = ( wchar_t )btowc( 'r' );
    185  1.18  drochner 		WACS_LEQUAL->vals[0]  = ( wchar_t )btowc( 'y' );
    186  1.18  drochner 		WACS_GEQUAL->vals[0]  = ( wchar_t )btowc( 'z' );
    187  1.18  drochner 		WACS_PI->vals[0]      = ( wchar_t )btowc( '{' );
    188  1.18  drochner 		WACS_NEQUAL->vals[0]  = ( wchar_t )btowc( '|' );
    189  1.18  drochner 		WACS_STERLING->vals[0]= ( wchar_t )btowc( '}' );
    190  1.13     blymn 	} else {
    191  1.13     blymn 		/* Unicode defaults */
    192  1.13     blymn #ifdef DEBUG
    193  1.13     blymn 		__CTRACE(__CTRACE_INIT,
    194  1.13     blymn 		    "__init_wacs: setting Unicode defaults\n" );
    195  1.13     blymn #endif /* DEBUG */
    196  1.18  drochner 		WACS_RARROW->vals[0]  = 0x2192;
    197  1.18  drochner 		ACS_RARROW = '+' | __ACS_IS_WACS;
    198  1.18  drochner 		WACS_LARROW->vals[0]  = 0x2190;
    199  1.18  drochner 		ACS_LARROW = ',' | __ACS_IS_WACS;
    200  1.18  drochner 		WACS_UARROW->vals[0]  = 0x2192;
    201  1.18  drochner 		ACS_UARROW = '-' | __ACS_IS_WACS;
    202  1.18  drochner 		WACS_DARROW->vals[0]  = 0x2193;
    203  1.18  drochner 		ACS_DARROW = '.' | __ACS_IS_WACS;
    204  1.18  drochner 		WACS_BLOCK->vals[0]   = 0x25ae;
    205  1.18  drochner 		ACS_BLOCK = '0' | __ACS_IS_WACS;
    206  1.18  drochner   		WACS_DIAMOND->vals[0] = 0x25c6;
    207  1.18  drochner 		ACS_DIAMOND = '`' | __ACS_IS_WACS;
    208  1.18  drochner 		WACS_CKBOARD->vals[0] = 0x2592;
    209  1.18  drochner 		ACS_CKBOARD = 'a' | __ACS_IS_WACS;
    210  1.18  drochner 		WACS_DEGREE->vals[0]  = 0x00b0;
    211  1.18  drochner 		ACS_DEGREE = 'f' | __ACS_IS_WACS;
    212  1.18  drochner 		WACS_PLMINUS->vals[0] = 0x00b1;
    213  1.18  drochner 		ACS_PLMINUS = 'g' | __ACS_IS_WACS;
    214  1.18  drochner 		WACS_BOARD->vals[0]   = 0x2592;
    215  1.18  drochner 		ACS_BOARD = 'h' | __ACS_IS_WACS;
    216  1.18  drochner 		WACS_LANTERN->vals[0] = 0x2603;
    217  1.18  drochner 		ACS_LANTERN = 'i' | __ACS_IS_WACS;
    218  1.18  drochner   		WACS_LRCORNER->vals[0]= 0x2518;
    219  1.18  drochner 		ACS_LRCORNER = 'j' | __ACS_IS_WACS;
    220  1.18  drochner   		WACS_URCORNER->vals[0]= 0x2510;
    221  1.18  drochner 		ACS_URCORNER = 'k' | __ACS_IS_WACS;
    222  1.18  drochner   		WACS_ULCORNER->vals[0]= 0x250c;
    223  1.18  drochner 		ACS_ULCORNER = 'l' | __ACS_IS_WACS;
    224  1.18  drochner   		WACS_LLCORNER->vals[0]= 0x2514;
    225  1.18  drochner 		ACS_LLCORNER = 'm' | __ACS_IS_WACS;
    226  1.18  drochner   		WACS_PLUS->vals[0]    = 0x253c;
    227  1.18  drochner 		ACS_PLUS = 'n' | __ACS_IS_WACS;
    228  1.18  drochner 		WACS_HLINE->vals[0]   = 0x2500;
    229  1.18  drochner 		ACS_HLINE = 'q' | __ACS_IS_WACS;
    230  1.18  drochner 		WACS_S1->vals[0]      = 0x23ba;
    231  1.18  drochner 		ACS_S1 = 'o' | __ACS_IS_WACS;
    232  1.18  drochner 		WACS_S9->vals[0]      = 0x23bd;
    233  1.18  drochner 		ACS_S9 = 's' | __ACS_IS_WACS;
    234  1.18  drochner   		WACS_LTEE->vals[0]    = 0x251c;
    235  1.18  drochner 		ACS_LTEE = 't' | __ACS_IS_WACS;
    236  1.18  drochner   		WACS_RTEE->vals[0]    = 0x2524;
    237  1.18  drochner 		ACS_RTEE = 'u' | __ACS_IS_WACS;
    238  1.18  drochner   		WACS_BTEE->vals[0]    = 0x2534;
    239  1.18  drochner 		ACS_BTEE = 'v' | __ACS_IS_WACS;
    240  1.18  drochner   		WACS_TTEE->vals[0]    = 0x252c;
    241  1.18  drochner 		ACS_TTEE = 'w' | __ACS_IS_WACS;
    242  1.18  drochner 		WACS_VLINE->vals[0]   = 0x2502;
    243  1.18  drochner 		ACS_VLINE = 'x' | __ACS_IS_WACS;
    244  1.18  drochner 		WACS_BULLET->vals[0]  = 0x00b7;
    245  1.18  drochner 		ACS_BULLET = '~' | __ACS_IS_WACS;
    246  1.18  drochner 		WACS_S3->vals[0]      = 0x23bb;
    247  1.18  drochner 		ACS_S3 = 'p' | __ACS_IS_WACS;
    248  1.18  drochner 		WACS_S7->vals[0]      = 0x23bc;
    249  1.18  drochner 		ACS_S7 = 'r' | __ACS_IS_WACS;
    250  1.18  drochner 		WACS_LEQUAL->vals[0]  = 0x2264;
    251  1.18  drochner 		ACS_LEQUAL = 'y' | __ACS_IS_WACS;
    252  1.18  drochner 		WACS_GEQUAL->vals[0]  = 0x2265;
    253  1.18  drochner 		ACS_GEQUAL = 'z' | __ACS_IS_WACS;
    254  1.18  drochner 		WACS_PI->vals[0]      = 0x03C0;
    255  1.18  drochner 		ACS_PI = '{' | __ACS_IS_WACS;
    256  1.18  drochner 		WACS_NEQUAL->vals[0]  = 0x2260;
    257  1.18  drochner 		ACS_NEQUAL = '|' | __ACS_IS_WACS;
    258  1.18  drochner 		WACS_STERLING->vals[0]= 0x00A3;
    259  1.18  drochner 		ACS_STERLING = '}' | __ACS_IS_WACS;
    260  1.13     blymn 	}
    261  1.13     blymn 
    262  1.17       roy 	if (t_acs_chars(screen->term) == NULL) {
    263  1.13     blymn #ifdef DEBUG
    264  1.13     blymn 		__CTRACE(__CTRACE_INIT,
    265  1.13     blymn 		    "__init_wacs: no alternative characters\n" );
    266  1.13     blymn #endif /* DEBUG */
    267  1.13     blymn 		goto out;
    268  1.13     blymn 	}
    269  1.13     blymn 
    270  1.17       roy 	aofac = t_acs_chars(screen->term);
    271  1.13     blymn 
    272  1.13     blymn 	while (*aofac != '\0') {
    273  1.13     blymn 		if ((acs = *aofac) == '\0')
    274  1.13     blymn 			return;
    275  1.18  drochner 		if ((term = *++aofac) == '\0')
    276  1.13     blymn 			return;
    277  1.13     blymn 	 	/* Only add characters 1 to 127 */
    278  1.13     blymn 		if (acs < NUM_ACS) {
    279  1.13     blymn 			_wacs_char[acs].vals[ 0 ] = term;
    280  1.13     blymn 			_wacs_char[acs].attributes |= WA_ALTCHARSET;
    281  1.13     blymn 		}
    282  1.13     blymn 		aofac++;
    283  1.13     blymn #ifdef DEBUG
    284  1.13     blymn 		__CTRACE(__CTRACE_INIT, "__init_wacs: %c = %c\n", acs, term);
    285  1.13     blymn #endif
    286  1.13     blymn 	}
    287  1.13     blymn 
    288  1.17       roy 	if (t_ena_acs(screen->term) != NULL)
    289  1.17       roy 		ti_puts(screen->term, t_ena_acs(screen->term), 0,
    290  1.13     blymn 			   __cputchar_args, screen->outfd);
    291  1.13     blymn 
    292  1.13     blymn out:
    293  1.18  drochner 	for (count=0; count < NUM_ACS; count++) {
    294  1.13     blymn 		memcpy(&screen->wacs_char[count], &_wacs_char[count],
    295  1.13     blymn 			sizeof(cchar_t));
    296  1.18  drochner 		screen->acs_char[count]= _acs_char[count];
    297  1.18  drochner 	}
    298  1.13     blymn }
    299  1.13     blymn 
    300  1.13     blymn void
    301  1.13     blymn _cursesi_reset_wacs(SCREEN *screen)
    302  1.13     blymn {
    303  1.13     blymn 	int count;
    304  1.13     blymn 
    305  1.13     blymn 	for (count=0; count < NUM_ACS; count++)
    306  1.13     blymn 		memcpy( &_wacs_char[count], &screen->wacs_char[count],
    307  1.13     blymn 			sizeof( cchar_t ));
    308  1.13     blymn }
    309  1.13     blymn #endif /* HAVE_WCHAR */
    310