lib_clreol.c revision 97050
18281Sjkh/****************************************************************************
28281Sjkh * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc.         *
38281Sjkh *                                                                          *
48281Sjkh * Permission is hereby granted, free of charge, to any person obtaining a  *
58281Sjkh * copy of this software and associated documentation files (the            *
68281Sjkh * "Software"), to deal in the Software without restriction, including      *
721673Sjkh * without limitation the rights to use, copy, modify, merge, publish,      *
88281Sjkh * distribute, distribute with modifications, sublicense, and/or sell       *
98281Sjkh * copies of the Software, and to permit persons to whom the Software is    *
108281Sjkh * furnished to do so, subject to the following conditions:                 *
118281Sjkh *                                                                          *
128281Sjkh * The above copyright notice and this permission notice shall be included  *
138281Sjkh * in all copies or substantial portions of the Software.                   *
148281Sjkh *                                                                          *
158281Sjkh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
168881Srgrimes * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
178881Srgrimes * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
188281Sjkh * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
198281Sjkh * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
208281Sjkh * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
218281Sjkh * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
228281Sjkh *                                                                          *
238281Sjkh * Except as contained in this notice, the name(s) of the above copyright   *
248281Sjkh * holders shall not be used in advertising or otherwise to promote the     *
258281Sjkh * sale, use or other dealings in this Software without prior written       *
268281Sjkh * authorization.                                                           *
278281Sjkh ****************************************************************************/
288281Sjkh
298281Sjkh/****************************************************************************
308281Sjkh *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
318281Sjkh *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
328281Sjkh ****************************************************************************/
338281Sjkh
348281Sjkh/*
358281Sjkh**	lib_clreol.c
368281Sjkh**
378281Sjkh**	The routine wclrtoeol().
388302Sjkh**
398307Sjkh*/
408281Sjkh
418549Sjkh#include <curses.priv.h>
428549Sjkh
438302SjkhMODULE_ID("$Id: lib_clreol.c,v 1.21 2001/12/19 01:06:04 tom Exp $")
448549Sjkh
4512661SpeterNCURSES_EXPORT(int)
468302Sjkhwclrtoeol(WINDOW *win)
478302Sjkh{
488549Sjkh    int code = ERR;
498549Sjkh
508302Sjkh    T((T_CALLED("wclrtoeol(%p)"), win));
5118650Sjkh
528549Sjkh    if (win) {
538549Sjkh	NCURSES_CH_T blank;
5418650Sjkh	NCURSES_CH_T *ptr, *end;
558549Sjkh	struct ldat *line;
568549Sjkh	NCURSES_SIZE_T y = win->_cury;
5718650Sjkh	NCURSES_SIZE_T x = win->_curx;
5812661Speter
598549Sjkh	/*
608549Sjkh	 * If we have just wrapped the cursor, the clear applies to the
618549Sjkh	 * new line, unless we are at the lower right corner.
628549Sjkh	 */
638549Sjkh	if ((win->_flags & _WRAPPED) != 0
648302Sjkh	    && y < win->_maxy) {
658549Sjkh	    win->_flags &= ~_WRAPPED;
6618744Sjkh	}
6718744Sjkh
688302Sjkh	/*
698302Sjkh	 * There's no point in clearing if we're not on a legal
7018744Sjkh	 * position, either.
7118744Sjkh	 */
728302Sjkh	if ((win->_flags & _WRAPPED) != 0
738549Sjkh	    || y > win->_maxy
748302Sjkh	    || x > win->_maxx)
758549Sjkh	    returnCode(ERR);
7618744Sjkh
778302Sjkh	blank = win->_nc_bkgd;
7818744Sjkh	line = &win->_line[y];
7918744Sjkh	CHANGED_TO_EOL(line, x, win->_maxx);
8019992Sphk
8117404Sjkh	ptr = &(line->text[x]);
8217362Sjkh	end = &(line->text[win->_maxx]);
8319992Sphk
8419992Sphk	while (ptr <= end)
8519992Sphk	    *ptr++ = blank;
8619992Sphk
8719992Sphk	_nc_synchook(win);
8819992Sphk	code = OK;
8912661Speter    }
908302Sjkh    returnCode(code);
918549Sjkh}
928668Sphk