xref: /minix3/lib/libcurses/clrtoeol.c (revision 0c3ae37f525eceade8dc047e551f5c9cb33faeb1)
1*0c3ae37fSLionel Sambuc /*	$NetBSD: clrtoeol.c,v 1.26 2012/02/19 19:38:13 christos Exp $	*/
251ffecc1SBen Gras 
351ffecc1SBen Gras /*
451ffecc1SBen Gras  * Copyright (c) 1981, 1993, 1994
551ffecc1SBen Gras  *	The Regents of the University of California.  All rights reserved.
651ffecc1SBen Gras  *
751ffecc1SBen Gras  * Redistribution and use in source and binary forms, with or without
851ffecc1SBen Gras  * modification, are permitted provided that the following conditions
951ffecc1SBen Gras  * are met:
1051ffecc1SBen Gras  * 1. Redistributions of source code must retain the above copyright
1151ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer.
1251ffecc1SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
1351ffecc1SBen Gras  *    notice, this list of conditions and the following disclaimer in the
1451ffecc1SBen Gras  *    documentation and/or other materials provided with the distribution.
1551ffecc1SBen Gras  * 3. Neither the name of the University nor the names of its contributors
1651ffecc1SBen Gras  *    may be used to endorse or promote products derived from this software
1751ffecc1SBen Gras  *    without specific prior written permission.
1851ffecc1SBen Gras  *
1951ffecc1SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2051ffecc1SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2151ffecc1SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2251ffecc1SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2351ffecc1SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2451ffecc1SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2551ffecc1SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2651ffecc1SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2751ffecc1SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2851ffecc1SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2951ffecc1SBen Gras  * SUCH DAMAGE.
3051ffecc1SBen Gras  */
3151ffecc1SBen Gras 
3251ffecc1SBen Gras #include <sys/cdefs.h>
3351ffecc1SBen Gras #ifndef lint
3451ffecc1SBen Gras #if 0
3551ffecc1SBen Gras static char sccsid[] = "@(#)clrtoeol.c	8.2 (Berkeley) 5/4/94";
3651ffecc1SBen Gras #else
37*0c3ae37fSLionel Sambuc __RCSID("$NetBSD: clrtoeol.c,v 1.26 2012/02/19 19:38:13 christos Exp $");
3851ffecc1SBen Gras #endif
3951ffecc1SBen Gras #endif				/* not lint */
4051ffecc1SBen Gras 
4151ffecc1SBen Gras #include <stdlib.h>
4251ffecc1SBen Gras #include "curses.h"
4351ffecc1SBen Gras #include "curses_private.h"
4451ffecc1SBen Gras 
4551ffecc1SBen Gras #ifndef _CURSES_USE_MACROS
4651ffecc1SBen Gras 
4751ffecc1SBen Gras /*
4851ffecc1SBen Gras  * clrtoeol --
4951ffecc1SBen Gras  *	Clear up to the end of line.
5051ffecc1SBen Gras  */
5151ffecc1SBen Gras int
clrtoeol(void)5251ffecc1SBen Gras clrtoeol(void)
5351ffecc1SBen Gras {
5451ffecc1SBen Gras 	return wclrtoeol(stdscr);
5551ffecc1SBen Gras }
5651ffecc1SBen Gras 
5751ffecc1SBen Gras #endif
5851ffecc1SBen Gras 
5951ffecc1SBen Gras /*
6051ffecc1SBen Gras  * wclrtoeol --
6151ffecc1SBen Gras  *	Clear up to the end of line.
6251ffecc1SBen Gras  */
6351ffecc1SBen Gras int
wclrtoeol(WINDOW * win)6451ffecc1SBen Gras wclrtoeol(WINDOW *win)
6551ffecc1SBen Gras {
6651ffecc1SBen Gras 	int     minx, x, y;
6751ffecc1SBen Gras 	__LDATA *end, *maxx, *sp;
6851ffecc1SBen Gras 	attr_t	attr;
6951ffecc1SBen Gras 
7051ffecc1SBen Gras 	y = win->cury;
7151ffecc1SBen Gras 	x = win->curx;
7251ffecc1SBen Gras 	if (win->alines[y]->flags & __ISPASTEOL) {
7351ffecc1SBen Gras 		if (y < win->maxy - 1) {
7451ffecc1SBen Gras 			win->alines[y]->flags &= ~__ISPASTEOL;
7551ffecc1SBen Gras 			y++;
7651ffecc1SBen Gras 			x = 0;
7751ffecc1SBen Gras 			win->cury = y;
7851ffecc1SBen Gras 			win->curx = x;
7951ffecc1SBen Gras 		} else
8051ffecc1SBen Gras 			return (OK);
8151ffecc1SBen Gras 	}
8251ffecc1SBen Gras 	end = &win->alines[y]->line[win->maxx];
8351ffecc1SBen Gras 	minx = -1;
8451ffecc1SBen Gras 	maxx = &win->alines[y]->line[x];
85*0c3ae37fSLionel Sambuc 	if (win != curscr)
86*0c3ae37fSLionel Sambuc 		attr = win->battr & __ATTRIBUTES;
8751ffecc1SBen Gras 	else
8851ffecc1SBen Gras 		attr = 0;
8951ffecc1SBen Gras 	for (sp = maxx; sp < end; sp++)
9051ffecc1SBen Gras #ifndef HAVE_WCHAR
9151ffecc1SBen Gras 		if (sp->ch != win->bch || sp->attr != attr) {
9251ffecc1SBen Gras #else
9351ffecc1SBen Gras 		if (sp->ch != ( wchar_t )btowc(( int ) win->bch ) ||
9451ffecc1SBen Gras 		    (sp->attr & WA_ATTRIBUTES) != attr || sp->nsp
9551ffecc1SBen Gras 		    || (WCOL(*sp) < 0)) {
9651ffecc1SBen Gras #endif /* HAVE_WCHAR */
9751ffecc1SBen Gras 			maxx = sp;
9851ffecc1SBen Gras 			if (minx == -1)
9951ffecc1SBen Gras 				minx = (int) (sp - win->alines[y]->line);
100*0c3ae37fSLionel Sambuc 			sp->attr = attr | (sp->attr & __ALTCHARSET);
10151ffecc1SBen Gras #ifdef HAVE_WCHAR
10251ffecc1SBen Gras 			sp->ch = ( wchar_t )btowc(( int ) win->bch);
10351ffecc1SBen Gras 			if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
10451ffecc1SBen Gras 				return ERR;
10551ffecc1SBen Gras 			SET_WCOL( *sp, 1 );
10651ffecc1SBen Gras #else
10751ffecc1SBen Gras 			sp->ch = win->bch;
10851ffecc1SBen Gras #endif /* HAVE_WCHAR */
10951ffecc1SBen Gras 		}
11051ffecc1SBen Gras #ifdef DEBUG
11151ffecc1SBen Gras 	__CTRACE(__CTRACE_ERASE, "CLRTOEOL: y = %d, minx = %d, maxx = %d, "
11251ffecc1SBen Gras 	    "firstch = %d, lastch = %d\n",
11351ffecc1SBen Gras 	    y, minx, (int) (maxx - win->alines[y]->line),
11451ffecc1SBen Gras 	    *win->alines[y]->firstchp, *win->alines[y]->lastchp);
11551ffecc1SBen Gras #endif
11651ffecc1SBen Gras 	/* Update firstch and lastch for the line. */
11751ffecc1SBen Gras 	return (__touchline(win, y, x, (int) win->maxx - 1));
11851ffecc1SBen Gras }
119