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