1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2013,2016 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Sven Verdoolaege *
34 * and: Thomas E. Dickey *
35 ****************************************************************************/
40 ** The routine winsch().
44 #include <curses.priv.h>
47 MODULE_ID("$Id: lib_insch.c,v 1.37 2020/02/02 23:34:34 tom Exp $")
50 * Insert the given character, updating the current location to simplify
54 _nc_insert_ch(SCREEN *sp, WINDOW *win, chtype ch)
57 int ch8 = (int) ChCharOf(ch);
70 for (count = (tabsize - (win->_curx % tabsize)); count > 0; count--) {
71 if ((code = _nc_insert_ch(sp, win, ' ')) != OK)
79 _nc_waddch_nosync(win, wch);
84 WINDOW_EXT(win, addch_used) == 0 &&
87 (ChAttrOf(ch) & A_ALTCHARSET) ||
88 (sp != 0 && sp->_legacy_coding && !iscntrl(ch8)))) {
89 if (win->_curx <= win->_maxx) {
90 struct ldat *line = &(win->_line[win->_cury]);
91 NCURSES_CH_T *end = &(line->text[win->_curx]);
92 NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
93 NCURSES_CH_T *temp2 = temp1 - 1;
97 CHANGED_TO_EOL(line, win->_curx, win->_maxx);
101 *temp1 = _nc_render(win, wch);
104 } else if (iscntrl(ch8)) {
105 NCURSES_CONST char *s;
106 s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
108 code = _nc_insert_ch(sp, win, ChAttrOf(ch) | UChar(*s));
114 #if USE_WIDEC_SUPPORT
117 * Handle multibyte characters here
120 wch = _nc_render(win, wch);
121 count = _nc_build_wch(win, &wch);
123 code = _nc_insert_wch(win, &wch);
124 } else if (count == -1) {
125 NCURSES_CONST char *s;
127 s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
130 code = _nc_insert_ch(sp, win,
131 ChAttrOf(ch) | UChar(*s));
148 winsch(WINDOW *win, chtype c)
152 T((T_CALLED("winsch(%p, %s)"), (void *) win, _tracechtype(c)));
155 NCURSES_SIZE_T oy = win->_cury;
156 NCURSES_SIZE_T ox = win->_curx;
158 code = _nc_insert_ch(_nc_screen_of(win), win, c);