]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_clreol.c
ncurses 4.1
[ncurses.git] / ncurses / lib_clreol.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 /*
24 **      lib_clreol.c
25 **
26 **      The routine wclrtoeol().
27 **
28 */
29
30 #include <curses.priv.h>
31
32 MODULE_ID("$Id: lib_clreol.c,v 1.9 1997/02/01 23:22:54 tom Exp $")
33
34 int  wclrtoeol(WINDOW *win)
35 {
36 chtype  *maxx, *ptr, *end;
37 short   y, x, minx;
38
39         T((T_CALLED("wclrtoeol(%p)"), win));
40
41         y = win->_cury;
42         x = win->_curx;
43
44         /*
45          * We don't want to clear if we just wrapped the cursor.  There's no
46          * point in clearing if we're not on a legal position, either.
47          */
48         if (win->_flags & _WRAPPED
49          || y > win->_maxy
50          || x > win->_maxx)
51                 returnCode(ERR);
52
53         end = &win->_line[y].text[win->_maxx];
54         minx = _NOCHANGE;
55         maxx = &win->_line[y].text[x];
56
57         for (ptr = maxx; ptr <= end; ptr++) {
58             chtype blank = _nc_background(win);
59
60             if (*ptr != blank) {
61                         maxx = ptr;
62                         if (minx == _NOCHANGE)
63                             minx = ptr - win->_line[y].text;
64                         *ptr = blank;
65             }
66         }
67
68         if (minx != _NOCHANGE) {
69             if (win->_line[y].firstchar > minx || win->_line[y].firstchar == _NOCHANGE)
70                         win->_line[y].firstchar = minx;
71
72             if (win->_line[y].lastchar < maxx - win->_line[y].text)
73                         win->_line[y].lastchar = maxx - win->_line[y].text;
74         }
75         _nc_synchook(win);
76         returnCode(OK);
77 }