8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / lib / libcurses / screen / waddwchnstr.c
blobe7c084466d410454cb33badc84187b9186bcc419
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 /*LINTLIBRARY*/
35 #include <sys/types.h>
36 #include "curses_inc.h"
39 * Add ncols worth of data to win, using string as input.
40 * Return the number of chtypes copied.
41 * Note: chtype contains 32/16 bit process code.
43 int
44 waddwchnstr(WINDOW *win, chtype *string, int ncols)
46 int my_x = win->_curx;
47 int my_y = win->_cury;
48 short my_maxx;
49 int counter;
50 chtype *ptr = &(win->_y[my_y][my_x]);
51 chtype *sptr = ptr;
52 char mbbuf[CSMAX+1];
53 int mp, s, scrw;
54 chtype rawc;
55 chtype attr;
56 short my_x1 = win->_curx;
59 while (ISCBIT(*ptr)) {
60 ptr--;
61 my_x1--;
63 while (ptr < sptr)
64 *ptr++ = win->_bkgd;
66 if (ncols == -1)
67 ncols = MAXINT;
69 counter = win->_maxx - my_x;
70 while ((ncols > 0) && (*string) && (counter > 0)) {
71 attr = *string & A_WATTRIBUTES;
72 rawc = *string & A_WCHARTEXT;
74 /* conver wchar_t to mbuti byte string */
75 for (mp = 0; mp < sizeof (mbbuf); mp++)
76 mbbuf[mp] = '\0';
77 if (_curs_wctomb(mbbuf, rawc) <= 0)
78 goto out;
80 /* if there are no cols on screen, end */
81 if ((scrw = wcscrw(rawc)) > counter)
82 goto out;
84 if (rawc & WCHAR_CSMASK) {
85 /* store multi-byte string into chtype */
86 for (s = 0, mp = 0; s < scrw; s++, mp += 2) {
87 *ptr = _CHAR(RBYTE(mbbuf[mp]) |
88 RBYTE(mbbuf[mp + 1]) << 8) | CBIT;
89 SETMBIT(*ptr);
90 if (mp > 0)
91 SETCBIT(*ptr);
92 else
93 CLRCBIT(*ptr);
94 *ptr |= attr;
95 ptr++;
97 } else {
98 /* store single-byte string into chtype */
99 *ptr = mbbuf[0];
100 *ptr |= attr;
101 ptr++;
104 ncols--;
105 string++;
106 counter -= scrw;
108 out :
110 while (ISCBIT(*ptr))
111 *ptr++ = win->_bkgd;
113 /* LINTED */
114 my_maxx = (short) (ptr - sptr + my_x);
116 if (my_x1 < win->_firstch[my_y])
117 win->_firstch[my_y] = my_x1;
119 if (my_maxx > win->_lastch[my_y])
120 win->_lastch[my_y] = my_maxx;
122 win->_flags |= _WINCHANGED;
124 /* sync with ancestor structures */
125 if (win->_sync)
126 wsyncup(win);
128 return (win->_immed ? wrefresh(win) : OK);