xref: /illumos-gate/usr/src/lib/libcurses/screen/wdelch.c (revision 012e6ce759c490003aed29439cc47d3d73a99ad3)
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 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 /*LINTLIBRARY*/
41 
42 #include	<sys/types.h>
43 #include	"curses_inc.h"
44 
45 /*
46  * This routine performs a delete-char on the line,
47  * leaving (_cury, _curx) unchanged.
48  */
49 
50 int
51 wdelch(WINDOW *win)
52 {
53 	chtype	*temp1, *temp2;
54 	chtype	*end;
55 	int	cury = win->_cury;
56 	short	curx = win->_curx;
57 	chtype	*cp;
58 	int	s;
59 
60 	end = &win->_y[cury][win->_maxx - 1];
61 	temp2 = &win->_y[cury][curx + 1];
62 	temp1 = temp2 - 1;
63 
64 	s = 1;
65 	win->_nbyte = -1;
66 	if (_scrmax > 1) {
67 		if (ISMBIT(*temp1)) {
68 			win->_insmode = TRUE;
69 			if (_mbvalid(win) == ERR)
70 				return (ERR);
71 			curx = win->_curx;
72 			temp1 = &win->_y[cury][curx];
73 		}
74 		if (ISMBIT(*end)) {
75 			for (cp = end; cp >= temp1; --cp)
76 				if (!ISCBIT(*cp))
77 					break;
78 			if (cp + _curs_scrwidth[TYPE(*cp)] > end+1)
79 				end = cp - 1;
80 		}
81 		if (ISMBIT(*temp1))
82 			s = _curs_scrwidth[TYPE(RBYTE(*temp1))];
83 		end -= s - 1;
84 		temp2 = &win->_y[cury][curx+s];
85 	}
86 
87 	while (temp1 < end)
88 		*temp1++ = *temp2++;
89 
90 	while (s--)
91 		*temp1++ = win->_bkgd;
92 
93 #ifdef	_VR3_COMPAT_CODE
94 	if (_y16update)
95 		(*_y16update)(win, 1, win->_maxx - curx, cury, curx);
96 #endif	/* _VR3_COMPAT_CODE */
97 
98 	win->_lastch[cury] = win->_maxx - 1;
99 	if (win->_firstch[cury] > curx)
100 		win->_firstch[cury] = curx;
101 
102 	win->_flags |= _WINCHANGED;
103 
104 	if (win->_sync)
105 		wsyncup(win);
106 
107 	return (win->_immed ? wrefresh(win) : OK);
108 }
109