xref: /titanic_44/usr/src/lib/libcurses/screen/mbinsshift.c (revision 3c112a2b34403220c06c3e2fcac403358cfba168)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*LINTLIBRARY*/
34 
35 #include	<sys/types.h>
36 #include	"curses_inc.h"
37 
38 /*
39  *	Shift right an interval of characters
40  */
41 
42 int
43 _mbinsshift(WINDOW *win, int len)
44 {
45 	int	x, y, maxx,  mv;
46 	chtype	*wcp, *wp, *ep;
47 
48 	y = win->_cury;
49 	x = win->_curx;
50 	maxx = win->_maxx;
51 	wcp  = win->_y[y];
52 
53 	/* ASSERT(!ISCBIT(wcp[x])); */
54 
55 	/* shift up to a whole character */
56 	if (_scrmax > 1) {
57 		wp = wcp + maxx - 1;
58 		if (ISMBIT(*wp)) {
59 			reg chtype	rb;
60 
61 			for (; wp >= wcp; --wp)
62 				if (!ISCBIT(*wp))
63 					break;
64 			if (wp < wcp)
65 				return (ERR);
66 			rb = RBYTE(*wp);
67 			if ((wp + _curs_scrwidth[TYPE(rb)]) > (wcp + maxx))
68 				/*LINTED*/
69 				maxx = (int)(wp - wcp);
70 			}
71 		}
72 
73 	/* see if any data need to move */
74 	if ((mv = maxx - (x+len)) <= 0)
75 		return (OK);
76 
77 	/* the end of the moved interval must be whole */
78 	if (ISCBIT(wcp[x + mv]))
79 		(void) _mbclrch(win, y, x + mv - 1);
80 
81 	/* move data */
82 	ep = wcp + x + len;
83 	for (wp = wcp + maxx - 1; wp >= ep; --wp)
84 		*wp = *(wp - len);
85 
86 	/* clear a possible partial multibyte character */
87 	if (ISMBIT(*wp))
88 		for (ep = wp; ep >= wcp; --ep) {
89 			mv = (int)(ISCBIT(*ep));
90 			*ep = win->_bkgd;
91 			if (!mv)
92 				break;
93 		}
94 
95 	/* update the change structure */
96 	if (x < win->_firstch[y])
97 		/*LINTED*/
98 		win->_firstch[y] = (short)x;
99 	win->_lastch[y] = maxx - 1;
100 
101 	return (OK);
102 }
103