xref: /openbsd/lib/libcurses/base/lib_clreol.c (revision c7ef0cfc)
1*c7ef0cfcSnicm /* $OpenBSD: lib_clreol.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
292dd1ec0Smillert 
392dd1ec0Smillert /****************************************************************************
4*c7ef0cfcSnicm  * Copyright 2020,2021 Thomas E. Dickey                                     *
5*c7ef0cfcSnicm  * Copyright 1998-2001,2009 Free Software Foundation, Inc.                  *
692dd1ec0Smillert  *                                                                          *
792dd1ec0Smillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
892dd1ec0Smillert  * copy of this software and associated documentation files (the            *
992dd1ec0Smillert  * "Software"), to deal in the Software without restriction, including      *
1092dd1ec0Smillert  * without limitation the rights to use, copy, modify, merge, publish,      *
1192dd1ec0Smillert  * distribute, distribute with modifications, sublicense, and/or sell       *
1292dd1ec0Smillert  * copies of the Software, and to permit persons to whom the Software is    *
1392dd1ec0Smillert  * furnished to do so, subject to the following conditions:                 *
1492dd1ec0Smillert  *                                                                          *
1592dd1ec0Smillert  * The above copyright notice and this permission notice shall be included  *
1692dd1ec0Smillert  * in all copies or substantial portions of the Software.                   *
1792dd1ec0Smillert  *                                                                          *
1892dd1ec0Smillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1992dd1ec0Smillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
2092dd1ec0Smillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
2192dd1ec0Smillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
2292dd1ec0Smillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2392dd1ec0Smillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2492dd1ec0Smillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2592dd1ec0Smillert  *                                                                          *
2692dd1ec0Smillert  * Except as contained in this notice, the name(s) of the above copyright   *
2792dd1ec0Smillert  * holders shall not be used in advertising or otherwise to promote the     *
2892dd1ec0Smillert  * sale, use or other dealings in this Software without prior written       *
2992dd1ec0Smillert  * authorization.                                                           *
3092dd1ec0Smillert  ****************************************************************************/
3192dd1ec0Smillert 
3292dd1ec0Smillert /****************************************************************************
3392dd1ec0Smillert  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
3492dd1ec0Smillert  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
3592dd1ec0Smillert  ****************************************************************************/
3692dd1ec0Smillert 
3792dd1ec0Smillert /*
3892dd1ec0Smillert **	lib_clreol.c
3992dd1ec0Smillert **
4092dd1ec0Smillert **	The routine wclrtoeol().
4192dd1ec0Smillert **
4292dd1ec0Smillert */
4392dd1ec0Smillert 
4492dd1ec0Smillert #include <curses.priv.h>
4592dd1ec0Smillert 
46*c7ef0cfcSnicm MODULE_ID("$Id: lib_clreol.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
4792dd1ec0Smillert 
NCURSES_EXPORT(int)4884af20ceSmillert NCURSES_EXPORT(int)
491fe33145Smillert wclrtoeol(WINDOW *win)
5092dd1ec0Smillert {
5192dd1ec0Smillert     int code = ERR;
5292dd1ec0Smillert 
53*c7ef0cfcSnicm     T((T_CALLED("wclrtoeol(%p)"), (void *) win));
5492dd1ec0Smillert 
5592dd1ec0Smillert     if (win) {
5681d8c4e1Snicm 	NCURSES_CH_T blank;
5781d8c4e1Snicm 	NCURSES_CH_T *ptr, *end;
5892dd1ec0Smillert 	struct ldat *line;
591fe33145Smillert 	NCURSES_SIZE_T y = win->_cury;
601fe33145Smillert 	NCURSES_SIZE_T x = win->_curx;
6192dd1ec0Smillert 
6292dd1ec0Smillert 	/*
6392dd1ec0Smillert 	 * If we have just wrapped the cursor, the clear applies to the
6492dd1ec0Smillert 	 * new line, unless we are at the lower right corner.
6592dd1ec0Smillert 	 */
66*c7ef0cfcSnicm 	if (IS_WRAPPED(win) != 0
6792dd1ec0Smillert 	    && y < win->_maxy) {
6892dd1ec0Smillert 	    win->_flags &= ~_WRAPPED;
6992dd1ec0Smillert 	}
7092dd1ec0Smillert 
7192dd1ec0Smillert 	/*
7292dd1ec0Smillert 	 * There's no point in clearing if we're not on a legal
7392dd1ec0Smillert 	 * position, either.
7492dd1ec0Smillert 	 */
75*c7ef0cfcSnicm 	if (IS_WRAPPED(win)
7692dd1ec0Smillert 	    || y > win->_maxy
7792dd1ec0Smillert 	    || x > win->_maxx)
7892dd1ec0Smillert 	    returnCode(ERR);
7992dd1ec0Smillert 
8081d8c4e1Snicm 	blank = win->_nc_bkgd;
8192dd1ec0Smillert 	line = &win->_line[y];
8292dd1ec0Smillert 	CHANGED_TO_EOL(line, x, win->_maxx);
8392dd1ec0Smillert 
8492dd1ec0Smillert 	ptr = &(line->text[x]);
8592dd1ec0Smillert 	end = &(line->text[win->_maxx]);
8692dd1ec0Smillert 
8792dd1ec0Smillert 	while (ptr <= end)
8892dd1ec0Smillert 	    *ptr++ = blank;
8992dd1ec0Smillert 
9092dd1ec0Smillert 	_nc_synchook(win);
9192dd1ec0Smillert 	code = OK;
9292dd1ec0Smillert     }
9392dd1ec0Smillert     returnCode(code);
9492dd1ec0Smillert }
95