1 /****************************************************************************
2 * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * Rewritten 2001-2002 to support wide-characters by *
36 ****************************************************************************/
41 ** The routines waddnstr(), waddchnstr().
45 #include <curses.priv.h>
47 MODULE_ID("$Id: lib_addstr.c,v 1.39 2003/12/06 18:04:33 tom Exp $")
50 waddnstr(WINDOW *win, const char *astr, int n)
52 const char *str = astr;
55 T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbufn(astr, n), n));
57 if (win && (str != 0)) {
58 TR(TRACE_VIRTPUT | TRACE_ATTRS, ("... current %s", _traceattr(win->_attrs)));
61 n = (int) strlen(astr);
63 TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
64 while ((n-- > 0) && (*str != '\0')) {
66 TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str)));
67 SetChar(ch, UChar(*str++), A_NORMAL);
68 if (_nc_waddch_nosync(win, ch) == ERR) {
75 TR(TRACE_VIRTPUT, ("waddnstr returns %d", code));
80 waddchnstr(WINDOW *win, const chtype *astr, int n)
82 NCURSES_SIZE_T y = win->_cury;
83 NCURSES_SIZE_T x = win->_curx;
87 T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n));
95 for (str = (const chtype *) astr; *str != 0; str++)
98 if (n > win->_maxx - x + 1)
99 n = win->_maxx - x + 1;
103 line = &(win->_line[y]);
104 #if USE_WIDEC_SUPPORT
107 for (i = 0; i < n; ++i)
108 SetChar(line->text[i + x], ChCharOf(astr[i]), ChAttrOf(astr[i]));
111 memcpy(line->text + x, astr, n * sizeof(*astr));
113 CHANGED_RANGE(line, x, x + n - 1);
119 #if USE_WIDEC_SUPPORT
122 _nc_wchstrlen(const cchar_t * s)
125 while (CharOf(s[result]) != L'\0') {
132 wadd_wchnstr(WINDOW *win, const cchar_t * astr, int n)
134 NCURSES_SIZE_T y = win->_cury;
135 NCURSES_SIZE_T x = win->_curx;
140 T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n));
146 n = _nc_wchstrlen(astr);
148 if (n > win->_maxx - x + 1)
149 n = win->_maxx - x + 1;
153 line = &(win->_line[y]);
156 if (isnac(line->text[x])) {
157 line->text[x - 1] = win->_nc_bkgd;
160 for (i = 0; i < n && x <= win->_maxx; ++i) {
161 line->text[x++] = astr[i];
162 if (wcwidth(CharOf(astr[i])) > 1) {
164 AddAttr(line->text[x++], WA_NAC);
166 line->text[x - 1] = win->_nc_bkgd;
169 if (x <= win->_maxx && isnac(line->text[x])) {
170 line->text[x] = win->_nc_bkgd;
173 CHANGED_RANGE(line, start, end);
180 waddnwstr(WINDOW *win, const wchar_t * str, int n)
184 T((T_CALLED("waddnwstr(%p,%s,%d)"), win, _nc_viswbufn(str, n), n));
186 if (win && (str != 0)) {
187 TR(TRACE_VIRTPUT | TRACE_ATTRS, ("... current %s", _traceattr(win->_attrs)));
190 n = (int) wcslen(str);
192 TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
193 while ((n-- > 0) && (*str != L('\0'))) {
195 TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str));
196 SetChar(ch, *str++, A_NORMAL);
197 if (wadd_wch(win, &ch) == ERR) {
204 TR(TRACE_VIRTPUT, ("waddnwstr returns %d", code));