1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
24*7c478bd9Sstevel@tonic-gate
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate * Copyright (c) 1997, by Sun Microsystems, Inc.
28*7c478bd9Sstevel@tonic-gate * All rights reserved.
29*7c478bd9Sstevel@tonic-gate */
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include "curses_inc.h"
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate * Add ncols worth of data to win, using string as input.
38*7c478bd9Sstevel@tonic-gate * Return the number of chtypes copied.
39*7c478bd9Sstevel@tonic-gate * Note: chtype contains 32/16 bit process code.
40*7c478bd9Sstevel@tonic-gate */
41*7c478bd9Sstevel@tonic-gate int
waddwchnstr(WINDOW * win,chtype * string,int ncols)42*7c478bd9Sstevel@tonic-gate waddwchnstr(WINDOW *win, chtype *string, int ncols)
43*7c478bd9Sstevel@tonic-gate {
44*7c478bd9Sstevel@tonic-gate int my_x = win->_curx;
45*7c478bd9Sstevel@tonic-gate int my_y = win->_cury;
46*7c478bd9Sstevel@tonic-gate short my_maxx;
47*7c478bd9Sstevel@tonic-gate int counter;
48*7c478bd9Sstevel@tonic-gate chtype *ptr = &(win->_y[my_y][my_x]);
49*7c478bd9Sstevel@tonic-gate chtype *sptr = ptr;
50*7c478bd9Sstevel@tonic-gate char mbbuf[CSMAX+1];
51*7c478bd9Sstevel@tonic-gate int mp, s, scrw;
52*7c478bd9Sstevel@tonic-gate chtype rawc;
53*7c478bd9Sstevel@tonic-gate chtype attr;
54*7c478bd9Sstevel@tonic-gate short my_x1 = win->_curx;
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate while (ISCBIT(*ptr)) {
58*7c478bd9Sstevel@tonic-gate ptr--;
59*7c478bd9Sstevel@tonic-gate my_x1--;
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate while (ptr < sptr)
62*7c478bd9Sstevel@tonic-gate *ptr++ = win->_bkgd;
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate if (ncols == -1)
65*7c478bd9Sstevel@tonic-gate ncols = MAXINT;
66*7c478bd9Sstevel@tonic-gate
67*7c478bd9Sstevel@tonic-gate counter = win->_maxx - my_x;
68*7c478bd9Sstevel@tonic-gate while ((ncols > 0) && (*string) && (counter > 0)) {
69*7c478bd9Sstevel@tonic-gate attr = *string & A_WATTRIBUTES;
70*7c478bd9Sstevel@tonic-gate rawc = *string & A_WCHARTEXT;
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate /* conver wchar_t to mbuti byte string */
73*7c478bd9Sstevel@tonic-gate for (mp = 0; mp < sizeof (mbbuf); mp++)
74*7c478bd9Sstevel@tonic-gate mbbuf[mp] = '\0';
75*7c478bd9Sstevel@tonic-gate if (_curs_wctomb(mbbuf, rawc) <= 0)
76*7c478bd9Sstevel@tonic-gate goto out;
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gate /* if there are no cols on screen, end */
79*7c478bd9Sstevel@tonic-gate if ((scrw = wcscrw(rawc)) > counter)
80*7c478bd9Sstevel@tonic-gate goto out;
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gate if (rawc & WCHAR_CSMASK) {
83*7c478bd9Sstevel@tonic-gate /* store multi-byte string into chtype */
84*7c478bd9Sstevel@tonic-gate for (s = 0, mp = 0; s < scrw; s++, mp += 2) {
85*7c478bd9Sstevel@tonic-gate *ptr = _CHAR(RBYTE(mbbuf[mp]) |
86*7c478bd9Sstevel@tonic-gate RBYTE(mbbuf[mp + 1]) << 8) | CBIT;
87*7c478bd9Sstevel@tonic-gate SETMBIT(*ptr);
88*7c478bd9Sstevel@tonic-gate if (mp > 0)
89*7c478bd9Sstevel@tonic-gate SETCBIT(*ptr);
90*7c478bd9Sstevel@tonic-gate else
91*7c478bd9Sstevel@tonic-gate CLRCBIT(*ptr);
92*7c478bd9Sstevel@tonic-gate *ptr |= attr;
93*7c478bd9Sstevel@tonic-gate ptr++;
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate } else {
96*7c478bd9Sstevel@tonic-gate /* store single-byte string into chtype */
97*7c478bd9Sstevel@tonic-gate *ptr = mbbuf[0];
98*7c478bd9Sstevel@tonic-gate *ptr |= attr;
99*7c478bd9Sstevel@tonic-gate ptr++;
100*7c478bd9Sstevel@tonic-gate }
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate ncols--;
103*7c478bd9Sstevel@tonic-gate string++;
104*7c478bd9Sstevel@tonic-gate counter -= scrw;
105*7c478bd9Sstevel@tonic-gate }
106*7c478bd9Sstevel@tonic-gate out :
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate while (ISCBIT(*ptr))
109*7c478bd9Sstevel@tonic-gate *ptr++ = win->_bkgd;
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate /* LINTED */
112*7c478bd9Sstevel@tonic-gate my_maxx = (short) (ptr - sptr + my_x);
113*7c478bd9Sstevel@tonic-gate
114*7c478bd9Sstevel@tonic-gate if (my_x1 < win->_firstch[my_y])
115*7c478bd9Sstevel@tonic-gate win->_firstch[my_y] = my_x1;
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate if (my_maxx > win->_lastch[my_y])
118*7c478bd9Sstevel@tonic-gate win->_lastch[my_y] = my_maxx;
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate win->_flags |= _WINCHANGED;
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate /* sync with ancestor structures */
123*7c478bd9Sstevel@tonic-gate if (win->_sync)
124*7c478bd9Sstevel@tonic-gate wsyncup(win);
125*7c478bd9Sstevel@tonic-gate
126*7c478bd9Sstevel@tonic-gate return (win->_immed ? wrefresh(win) : OK);
127*7c478bd9Sstevel@tonic-gate }
128