xref: /openbsd/lib/libcurses/base/lib_touch.c (revision c7ef0cfc)
1*c7ef0cfcSnicm /* $OpenBSD: lib_touch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
292dd1ec0Smillert 
392dd1ec0Smillert /****************************************************************************
4*c7ef0cfcSnicm  * Copyright 2020 Thomas E. Dickey                                          *
5*c7ef0cfcSnicm  * Copyright 1998-2016,2017 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_touch.c
3992dd1ec0Smillert **
4092dd1ec0Smillert **	   The routines	untouchwin(),
4192dd1ec0Smillert **			wtouchln(),
4292dd1ec0Smillert **			is_linetouched()
4392dd1ec0Smillert **			is_wintouched().
4492dd1ec0Smillert **
4592dd1ec0Smillert */
4692dd1ec0Smillert 
4792dd1ec0Smillert #include <curses.priv.h>
4892dd1ec0Smillert 
49*c7ef0cfcSnicm MODULE_ID("$Id: lib_touch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
50*c7ef0cfcSnicm 
51*c7ef0cfcSnicm #undef is_linetouched
5292dd1ec0Smillert 
NCURSES_EXPORT(bool)5384af20ceSmillert NCURSES_EXPORT(bool)
5484af20ceSmillert is_linetouched(WINDOW *win, int line)
5592dd1ec0Smillert {
56*c7ef0cfcSnicm     T((T_CALLED("is_linetouched(%p,%d)"), (void *) win, line));
5792dd1ec0Smillert 
58*c7ef0cfcSnicm     /* XSI doesn't define any error, and gcc ultimately made it impossible */
59*c7ef0cfcSnicm     if (!win || (line > win->_maxy) || (line < 0)) {
60*c7ef0cfcSnicm 	returnCode(FALSE);
61*c7ef0cfcSnicm     }
6292dd1ec0Smillert 
6392dd1ec0Smillert     returnCode(win->_line[line].firstchar != _NOCHANGE ? TRUE : FALSE);
6492dd1ec0Smillert }
6592dd1ec0Smillert 
6684af20ceSmillert NCURSES_EXPORT(bool)
is_wintouched(WINDOW * win)6784af20ceSmillert is_wintouched(WINDOW *win)
6892dd1ec0Smillert {
69*c7ef0cfcSnicm     T((T_CALLED("is_wintouched(%p)"), (void *) win));
70*c7ef0cfcSnicm 
71*c7ef0cfcSnicm     if (win) {
7292dd1ec0Smillert 	int i;
7392dd1ec0Smillert 
7492dd1ec0Smillert 	for (i = 0; i <= win->_maxy; i++)
7592dd1ec0Smillert 	    if (win->_line[i].firstchar != _NOCHANGE)
7692dd1ec0Smillert 		returnCode(TRUE);
77*c7ef0cfcSnicm     }
7892dd1ec0Smillert     returnCode(FALSE);
7992dd1ec0Smillert }
8092dd1ec0Smillert 
8184af20ceSmillert NCURSES_EXPORT(int)
wtouchln(WINDOW * win,int y,int n,int changed)8284af20ceSmillert wtouchln(WINDOW *win, int y, int n, int changed)
8392dd1ec0Smillert {
8492dd1ec0Smillert     int i;
8592dd1ec0Smillert 
86*c7ef0cfcSnicm     T((T_CALLED("wtouchln(%p,%d,%d,%d)"), (void *) win, y, n, changed));
8792dd1ec0Smillert 
8892dd1ec0Smillert     if (!win || (n < 0) || (y < 0) || (y > win->_maxy))
8992dd1ec0Smillert 	returnCode(ERR);
9092dd1ec0Smillert 
9192dd1ec0Smillert     for (i = y; i < y + n; i++) {
9284af20ceSmillert 	if (i > win->_maxy)
9384af20ceSmillert 	    break;
94*c7ef0cfcSnicm 	win->_line[i].firstchar = (NCURSES_SIZE_T) (changed ? 0 : _NOCHANGE);
95*c7ef0cfcSnicm 	win->_line[i].lastchar = (NCURSES_SIZE_T) (changed
96*c7ef0cfcSnicm 						   ? win->_maxx
97*c7ef0cfcSnicm 						   : _NOCHANGE);
9892dd1ec0Smillert     }
9992dd1ec0Smillert     returnCode(OK);
10092dd1ec0Smillert }
101