ncurses 4.1
[ncurses.git] / ncurses / lib_clrbot.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22 /*
23 **      lib_clrbot.c
24 **
25 **      The routine wclrtobot().
26 **
27 */
28
29 #include <curses.priv.h>
30
31 MODULE_ID("$Id: lib_clrbot.c,v 1.9 1997/02/01 23:18:18 tom Exp $")
32
33 int wclrtobot(WINDOW *win)
34 {
35 chtype  *ptr, *end, *maxx = NULL;
36 short   y, startx, minx;
37
38         T((T_CALLED("wclrtobot(%p)"), win));
39
40         startx = win->_curx;
41
42         T(("clearing from y = %d to y = %d with maxx =  %d", win->_cury, win->_maxy, win->_maxx));
43
44         for (y = win->_cury; y <= win->_maxy; y++) {
45                 minx = _NOCHANGE;
46                 end = &win->_line[y].text[win->_maxx];
47
48                 for (ptr = &win->_line[y].text[startx]; ptr <= end; ptr++) {
49                         chtype blank = _nc_background(win);
50
51                         if (*ptr != blank) {
52                                 maxx = ptr;
53                                 if (minx == _NOCHANGE)
54                                         minx = ptr - win->_line[y].text;
55                                 *ptr = blank;
56                         }
57                 }
58
59                 if (minx != _NOCHANGE) {
60                         if (win->_line[y].firstchar > minx
61                                         ||  win->_line[y].firstchar == _NOCHANGE)
62                             win->_line[y].firstchar = minx;
63
64                         if (win->_line[y].lastchar < maxx - win->_line[y].text)
65                             win->_line[y].lastchar = maxx - win->_line[y].text;
66                 }
67
68                 startx = 0;
69         }
70         _nc_synchook(win);
71         returnCode(OK);
72 }