1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
29 */
30
31 /*LINTLIBRARY*/
32
33 #include <sys/types.h>
34 #include "curses_inc.h"
35
36 /*
37 * Copy n chars(wchar_t) in window win from current cursor position to end
38 * of window into char buffer str. Return the number of chars copied.
39 */
40
41 int
winnwstr(WINDOW * win,wchar_t * wstr,int ncols)42 winnwstr(WINDOW *win, wchar_t *wstr, int ncols)
43 {
44 int counter = 0;
45 int cy = win->_cury;
46 chtype *ptr = &(win->_y[cy][win->_curx]),
47 *pmax = &(win->_y[cy][win->_maxx]);
48 wchar_t wc, *cp;
49 int scrw, s;
50 char cbuf[CSMAX+1];
51
52
53 while (ISCBIT(*ptr))
54 ptr--;
55
56 if (ncols < -1)
57 ncols = MAXINT;
58
59 while (counter < ncols) {
60 wc = RBYTE(*ptr);
61 scrw = mbscrw((int) wc);
62 (void) mbeucw((int) wc);
63 /* LINTED */
64 cp = (wchar_t *)cbuf;
65 for (s = 0; s < scrw; s++, ptr++) {
66 if ((wc = RBYTE(*ptr)) == MBIT)
67 continue;
68 *cp++ = wc;
69 if ((wc = LBYTE(*ptr) | MBIT) == MBIT)
70 continue;
71 *cp++ = wc;
72 }
73 *cp = (char)0;
74
75 if (_curs_mbtowc(&wc, cbuf, CSMAX) <= 0)
76 break;
77
78 *wstr++ = wc;
79 counter++;
80
81 if (ptr >= pmax) {
82 if (++cy == win->_maxy)
83 break;
84
85 ptr = &(win->_y[cy][0]);
86 pmax = ptr + win->_maxx;
87 }
88 }
89 if (counter < ncols)
90 *wstr = (wchar_t)0;
91
92 return (counter);
93 }
94