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 #pragma ident "%Z%%M% %I% %E% SMI"
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
36*7c478bd9Sstevel@tonic-gate #include "curses_inc.h"
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate * Add ncols worth of data to win, using string as input.
40*7c478bd9Sstevel@tonic-gate * Return the number of chtypes copied.
41*7c478bd9Sstevel@tonic-gate * Note: chtype contains 32/16 bit process code.
42*7c478bd9Sstevel@tonic-gate */
43*7c478bd9Sstevel@tonic-gate int
waddwchnstr(WINDOW * win,chtype * string,int ncols)44*7c478bd9Sstevel@tonic-gate waddwchnstr(WINDOW *win, chtype *string, int ncols)
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate int my_x = win->_curx;
47*7c478bd9Sstevel@tonic-gate int my_y = win->_cury;
48*7c478bd9Sstevel@tonic-gate short my_maxx;
49*7c478bd9Sstevel@tonic-gate int counter;
50*7c478bd9Sstevel@tonic-gate chtype *ptr = &(win->_y[my_y][my_x]);
51*7c478bd9Sstevel@tonic-gate chtype *sptr = ptr;
52*7c478bd9Sstevel@tonic-gate char mbbuf[CSMAX+1];
53*7c478bd9Sstevel@tonic-gate int mp, s, scrw;
54*7c478bd9Sstevel@tonic-gate chtype rawc;
55*7c478bd9Sstevel@tonic-gate chtype attr;
56*7c478bd9Sstevel@tonic-gate short my_x1 = win->_curx;
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate while (ISCBIT(*ptr)) {
60*7c478bd9Sstevel@tonic-gate ptr--;
61*7c478bd9Sstevel@tonic-gate my_x1--;
62*7c478bd9Sstevel@tonic-gate }
63*7c478bd9Sstevel@tonic-gate while (ptr < sptr)
64*7c478bd9Sstevel@tonic-gate *ptr++ = win->_bkgd;
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate if (ncols == -1)
67*7c478bd9Sstevel@tonic-gate ncols = MAXINT;
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate counter = win->_maxx - my_x;
70*7c478bd9Sstevel@tonic-gate while ((ncols > 0) && (*string) && (counter > 0)) {
71*7c478bd9Sstevel@tonic-gate attr = *string & A_WATTRIBUTES;
72*7c478bd9Sstevel@tonic-gate rawc = *string & A_WCHARTEXT;
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gate /* conver wchar_t to mbuti byte string */
75*7c478bd9Sstevel@tonic-gate for (mp = 0; mp < sizeof (mbbuf); mp++)
76*7c478bd9Sstevel@tonic-gate mbbuf[mp] = '\0';
77*7c478bd9Sstevel@tonic-gate if (_curs_wctomb(mbbuf, rawc) <= 0)
78*7c478bd9Sstevel@tonic-gate goto out;
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate /* if there are no cols on screen, end */
81*7c478bd9Sstevel@tonic-gate if ((scrw = wcscrw(rawc)) > counter)
82*7c478bd9Sstevel@tonic-gate goto out;
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate if (rawc & WCHAR_CSMASK) {
85*7c478bd9Sstevel@tonic-gate /* store multi-byte string into chtype */
86*7c478bd9Sstevel@tonic-gate for (s = 0, mp = 0; s < scrw; s++, mp += 2) {
87*7c478bd9Sstevel@tonic-gate *ptr = _CHAR(RBYTE(mbbuf[mp]) |
88*7c478bd9Sstevel@tonic-gate RBYTE(mbbuf[mp + 1]) << 8) | CBIT;
89*7c478bd9Sstevel@tonic-gate SETMBIT(*ptr);
90*7c478bd9Sstevel@tonic-gate if (mp > 0)
91*7c478bd9Sstevel@tonic-gate SETCBIT(*ptr);
92*7c478bd9Sstevel@tonic-gate else
93*7c478bd9Sstevel@tonic-gate CLRCBIT(*ptr);
94*7c478bd9Sstevel@tonic-gate *ptr |= attr;
95*7c478bd9Sstevel@tonic-gate ptr++;
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate } else {
98*7c478bd9Sstevel@tonic-gate /* store single-byte string into chtype */
99*7c478bd9Sstevel@tonic-gate *ptr = mbbuf[0];
100*7c478bd9Sstevel@tonic-gate *ptr |= attr;
101*7c478bd9Sstevel@tonic-gate ptr++;
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate ncols--;
105*7c478bd9Sstevel@tonic-gate string++;
106*7c478bd9Sstevel@tonic-gate counter -= scrw;
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate out :
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate while (ISCBIT(*ptr))
111*7c478bd9Sstevel@tonic-gate *ptr++ = win->_bkgd;
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate /* LINTED */
114*7c478bd9Sstevel@tonic-gate my_maxx = (short) (ptr - sptr + my_x);
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate if (my_x1 < win->_firstch[my_y])
117*7c478bd9Sstevel@tonic-gate win->_firstch[my_y] = my_x1;
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate if (my_maxx > win->_lastch[my_y])
120*7c478bd9Sstevel@tonic-gate win->_lastch[my_y] = my_maxx;
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate win->_flags |= _WINCHANGED;
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate /* sync with ancestor structures */
125*7c478bd9Sstevel@tonic-gate if (win->_sync)
126*7c478bd9Sstevel@tonic-gate wsyncup(win);
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate return (win->_immed ? wrefresh(win) : OK);
129*7c478bd9Sstevel@tonic-gate }
130