Back to index

tetex-bin  3.0
lib_insch.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: Sven Verdoolaege                                                *
00033  *     and: Thomas E. Dickey                                                *
00034  ****************************************************************************/
00035 
00036 /*
00037 **     lib_insch.c
00038 **
00039 **     The routine winsch().
00040 **
00041 */
00042 
00043 #include <curses.priv.h>
00044 #include <ctype.h>
00045 
00046 MODULE_ID("$Id: lib_insch.c,v 1.21 2004/06/19 22:52:59 tom Exp $")
00047 
00048 /*
00049  * Insert the given character, updating the current location to simplify
00050  * inserting a string.
00051  */
00052 void
00053 _nc_insert_ch(WINDOW *win, chtype ch)
00054 {
00055     NCURSES_CH_T wch;
00056     int count;
00057     NCURSES_CONST char *s;
00058 
00059     switch (ch) {
00060     case '\t':
00061        for (count = (TABSIZE - (win->_curx % TABSIZE)); count > 0; count--)
00062            _nc_insert_ch(win, ' ');
00063        break;
00064     case '\n':
00065     case '\r':
00066     case '\b':
00067        SetChar2(wch, ch);
00068        _nc_waddch_nosync(win, wch);
00069        break;
00070     default:
00071        if (
00072 #if USE_WIDEC_SUPPORT
00073               WINDOW_EXT(win, addch_used) == 0 &&
00074 #endif
00075               is8bits(ChCharOf(ch)) &&
00076               isprint(ChCharOf(ch))) {
00077            if (win->_curx <= win->_maxx) {
00078               struct ldat *line = &(win->_line[win->_cury]);
00079               NCURSES_CH_T *end = &(line->text[win->_curx]);
00080               NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
00081               NCURSES_CH_T *temp2 = temp1 - 1;
00082 
00083               SetChar2(wch, ch);
00084 
00085               CHANGED_TO_EOL(line, win->_curx, win->_maxx);
00086               while (temp1 > end)
00087                   *temp1-- = *temp2--;
00088 
00089               *temp1 = _nc_render(win, wch);
00090 
00091               win->_curx++;
00092            }
00093        } else if (is8bits(ChCharOf(ch)) && iscntrl(ChCharOf(ch))) {
00094            s = unctrl(ChCharOf(ch));
00095            while (*s != '\0') {
00096               _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
00097               ++s;
00098            }
00099        }
00100 #if USE_WIDEC_SUPPORT
00101        else {
00102            /*
00103             * Handle multibyte characters here
00104             */
00105            if (WINDOW_EXT(win, addch_used) == 0) {
00106               _nc_insert_ch(win, ChAttrOf(ch) | ' ');
00107            }
00108            SetChar2(wch, ch);
00109            _nc_waddch_nosync(win, wch);
00110        }
00111 #endif
00112        break;
00113     }
00114 }
00115 
00116 NCURSES_EXPORT(int)
00117 winsch(WINDOW *win, chtype c)
00118 {
00119     NCURSES_SIZE_T oy;
00120     NCURSES_SIZE_T ox;
00121     int code = ERR;
00122 
00123     T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c)));
00124 
00125     if (win != 0) {
00126        oy = win->_cury;
00127        ox = win->_curx;
00128 
00129        _nc_insert_ch(win, c);
00130 
00131        win->_curx = ox;
00132        win->_cury = oy;
00133        _nc_synchook(win);
00134        code = OK;
00135     }
00136     returnCode(code);
00137 }