1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 2002-2016,2017 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: Thomas Dickey *
32 ****************************************************************************/
37 ** The routines winnwstr() and winwstr().
41 #include <curses.priv.h>
43 MODULE_ID("$Id: lib_inwstr.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
46 winnwstr(WINDOW *win, wchar_t *wstr, int n)
51 T((T_CALLED("winnwstr(%p,%p,%d)"), (void *) win, (void *) wstr, n));
60 text = win->_line[row].text;
61 while (count < n && !done && count != ERR) {
63 if (!isWidecExt(text[col])) {
67 for (inx = 0; (inx < CCHARW_MAX)
68 && ((wch = text[col].chars[inx]) != 0);
73 count = ERR; /* error if we store nothing */
75 count = last; /* only store complete chars */
83 if (++col > win->_maxx) {
90 T(("winnwstr returns %s", _nc_viswbuf(wstr)));
97 * X/Open says winwstr() returns OK if not ERR. If that is not a blunder, it
98 * must have a null termination on the string (see above). Unlike winnstr(),
99 * it does not define what happens for a negative count with winnwstr().
102 winwstr(WINDOW *win, wchar_t *wstr)
106 T((T_CALLED("winwstr(%p,%p)"), (void *) win, (void *) wstr));
109 } else if (winnwstr(win, wstr,
110 CCHARW_MAX * (win->_maxx - win->_curx + 1)) == ERR) {