Back to index

tetex-bin  3.0
lib_acs.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2002,2004 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00031  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00032  *     and: Thomas E. Dickey                        1996-on                 *
00033  ****************************************************************************/
00034 
00035 #include <curses.priv.h>
00036 #include <term.h>           /* ena_acs, acs_chars */
00037 
00038 MODULE_ID("$Id: lib_acs.c,v 1.27 2004/10/16 15:42:40 tom Exp $")
00039 
00040 #if BROKEN_LINKER
00041 NCURSES_EXPORT_VAR(chtype *)
00042 _nc_acs_map(void)
00043 {
00044     static chtype *the_map = 0;
00045     if (the_map == 0)
00046        the_map = typeCalloc(chtype, ACS_LEN);
00047     return the_map;
00048 }
00049 #else
00050 NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
00051 {
00052     0
00053 };
00054 #endif
00055 
00056 NCURSES_EXPORT(void)
00057 _nc_init_acs(void)
00058 {
00059     chtype *fake_map = acs_map;
00060     chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
00061     int j;
00062 
00063     T(("initializing ACS map"));
00064 
00065     /*
00066      * If we're using this from curses (rather than terminfo), we are storing
00067      * the mapping information in the SCREEN struct so we can decide how to
00068      * render it.
00069      */
00070     if (real_map != fake_map) {
00071        for (j = 1; j < ACS_LEN; ++j) {
00072            real_map[j] = 0;
00073            fake_map[j] = A_ALTCHARSET | j;
00074            SP->_screen_acs_map[j] = FALSE;
00075        }
00076     } else {
00077        for (j = 1; j < ACS_LEN; ++j) {
00078            real_map[j] = 0;
00079        }
00080     }
00081 
00082     /*
00083      * Initializations for a UNIX-like multi-terminal environment.  Use
00084      * ASCII chars and count on the terminfo description to do better.
00085      */
00086     real_map['l'] = '+';    /* should be upper left corner */
00087     real_map['m'] = '+';    /* should be lower left corner */
00088     real_map['k'] = '+';    /* should be upper right corner */
00089     real_map['j'] = '+';    /* should be lower right corner */
00090     real_map['u'] = '+';    /* should be tee pointing left */
00091     real_map['t'] = '+';    /* should be tee pointing right */
00092     real_map['v'] = '+';    /* should be tee pointing up */
00093     real_map['w'] = '+';    /* should be tee pointing down */
00094     real_map['q'] = '-';    /* should be horizontal line */
00095     real_map['x'] = '|';    /* should be vertical line */
00096     real_map['n'] = '+';    /* should be large plus or crossover */
00097     real_map['o'] = '~';    /* should be scan line 1 */
00098     real_map['s'] = '_';    /* should be scan line 9 */
00099     real_map['`'] = '+';    /* should be diamond */
00100     real_map['a'] = ':';    /* should be checker board (stipple) */
00101     real_map['f'] = '\'';   /* should be degree symbol */
00102     real_map['g'] = '#';    /* should be plus/minus */
00103     real_map['~'] = 'o';    /* should be bullet */
00104     real_map[','] = '<';    /* should be arrow pointing left */
00105     real_map['+'] = '>';    /* should be arrow pointing right */
00106     real_map['.'] = 'v';    /* should be arrow pointing down */
00107     real_map['-'] = '^';    /* should be arrow pointing up */
00108     real_map['h'] = '#';    /* should be board of squares */
00109     real_map['i'] = '#';    /* should be lantern symbol */
00110     real_map['0'] = '#';    /* should be solid square block */
00111     /* these defaults were invented for ncurses */
00112     real_map['p'] = '-';    /* should be scan line 3 */
00113     real_map['r'] = '-';    /* should be scan line 7 */
00114     real_map['y'] = '<';    /* should be less-than-or-equal-to */
00115     real_map['z'] = '>';    /* should be greater-than-or-equal-to */
00116     real_map['{'] = '*';    /* should be greek pi */
00117     real_map['|'] = '!';    /* should be not-equal */
00118     real_map['}'] = 'f';    /* should be pound-sterling symbol */
00119 
00120 #if !USE_WIDEC_SUPPORT
00121     if (_nc_unicode_locale() && _nc_locale_breaks_acs()) {
00122        acs_chars = NULL;
00123        ena_acs = NULL;
00124        enter_alt_charset_mode = NULL;
00125        exit_alt_charset_mode = NULL;
00126        set_attributes = NULL;
00127     }
00128 #endif
00129 
00130     if (ena_acs != NULL) {
00131        TPUTS_TRACE("ena_acs");
00132        putp(ena_acs);
00133     }
00134 
00135     if (acs_chars != NULL) {
00136        size_t i = 0;
00137        size_t length = strlen(acs_chars);
00138 
00139        while (i + 1 < length) {
00140            if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
00141               real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
00142               if (SP != 0)
00143                   SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
00144            }
00145            i += 2;
00146        }
00147     }
00148 #ifdef TRACE
00149     /* Show the equivalent mapping, noting if it does not match the
00150      * given attribute, whether by re-ordering or duplication.
00151      */
00152     if (_nc_tracing & TRACE_CALLS) {
00153        size_t n, m;
00154        char show[ACS_LEN + 1];
00155        for (n = 1, m = 0; n < ACS_LEN; n++) {
00156            if (real_map[n] != 0) {
00157               show[m++] = (char) n;
00158               show[m++] = ChCharOf(real_map[n]);
00159            }
00160        }
00161        show[m] = 0;
00162        if (acs_chars == NULL || strcmp(acs_chars, show))
00163            _tracef("%s acs_chars %s",
00164                   (acs_chars == NULL) ? "NULL" : "READ",
00165                   _nc_visbuf(acs_chars));
00166        _tracef("%s acs_chars %s",
00167               (acs_chars == NULL)
00168               ? "NULL"
00169               : (strcmp(acs_chars, show)
00170                  ? "DIFF"
00171                  : "SAME"),
00172               _nc_visbuf(show));
00173     }
00174 #endif /* TRACE */
00175 }