make sure unavailable mode bits are not set,
[unix-history] / usr / src / usr.bin / window / wwclreol.c
CommitLineData
a43a8870 1#ifndef lint
60de5df9 2static char sccsid[] = "@(#)wwclreol.c 3.14 %G%";
a43a8870
EW
3#endif
4
60de5df9
EW
5/*
6 * Copyright (c) 1983 Regents of the University of California,
7 * All rights reserved. Redistribution permitted subject to
8 * the terms of the Berkeley Software License Agreement.
9 */
10
a43a8870 11#include "ww.h"
e908bfac 12#include "tt.h"
a43a8870
EW
13
14/*
15 * Clear w to the end of line.
16 * If cleared is true, then the screen line has already been cleared
17 * previously.
18 */
f2a77fe1 19wwclreol1(w, row, col, cleared)
a43a8870 20register struct ww *w;
f2a77fe1 21int row, col;
14f251df 22char cleared;
a43a8870
EW
23{
24 register i;
2012dbdd 25 int gain;
a43a8870 26
19f9784c
EW
27 /*
28 * Clear the buffer right off
29 */
30 {
31 register union ww_char *buf;
32
f2a77fe1
EW
33 buf = &w->ww_buf[row][col];
34 for (i = w->ww_b.r - col; --i >= 0;)
a43a8870 35 buf++->c_w = ' ';
a43a8870 36 }
19f9784c
EW
37
38 /*
39 * If can't see it, just return.
40 */
f2a77fe1
EW
41 if (row < w->ww_i.t || row >= w->ww_i.b
42 || w->ww_i.r <= 0 || w->ww_i.r <= col)
19f9784c
EW
43 return;
44
f2a77fe1
EW
45 if (col < w->ww_i.l)
46 col = w->ww_i.l;
19f9784c
EW
47
48 /*
49 * Now find out how much is actually cleared, and fix wwns.
50 */
2012dbdd 51 if (cleared) {
19f9784c
EW
52 register union ww_char *s;
53 register char *smap, *win;
19f9784c 54
2012dbdd
EW
55 i = col;
56 smap = &wwsmap[row][i];
57 s = &wwns[row][i];
58 win = &w->ww_win[row][i];
59 for (i = w->ww_i.r - i; --i >= 0;) {
60 if (*smap++ != w->ww_index)
61 continue;
62 s++->c_w = ' ' | *win++ << WWC_MSHIFT;
63 }
64 } else {
65 register union ww_char *s;
66 register char *smap, *win;
67 int ntouched = 0;
68
d069a508
EW
69 i = col;
70 smap = &wwsmap[row][i];
04d70db4 71 s = wwns[row];
d069a508 72 win = w->ww_win[row];
2012dbdd 73 gain = 0;
d069a508 74 for (; i < w->ww_i.r; i++) {
19f9784c 75 if (*smap++ != w->ww_index) {
2012dbdd
EW
76 if (s[i].c_w != ' ')
77 gain--;
04d70db4 78 } else if (win[i] == 0) {
04d70db4 79 if (s[i].c_w != ' ') {
2012dbdd
EW
80 gain++;
81 ntouched++;
04d70db4
EW
82 s[i].c_w = ' ';
83 }
2012dbdd
EW
84 } else {
85 short c = ' ' | win[i] << WWC_MSHIFT;
86 if (s[i].c_w == c)
87 gain--;
88 else {
89 s[i].c_w = c;
90 ntouched++;
91 }
92 }
a43a8870 93 }
2012dbdd
EW
94 s += i;
95 for (i = wwncol - i; --i >= 0;)
96 if (s++->c_w != ' ')
97 gain--;
98 if (ntouched > 0)
04d70db4 99 wwtouched[row] |= WWU_TOUCHED;
a43a8870 100 }
19f9784c
EW
101
102 /*
103 * Can/Should we use clear eol?
104 */
2012dbdd 105 if (!cleared && tt.tt_clreol != 0 && gain > 4) {
19f9784c
EW
106 register union ww_char *s;
107
a43a8870 108 /* clear to the end */
f2a77fe1 109 (*tt.tt_move)(row, col);
a43a8870 110 (*tt.tt_clreol)();
f2a77fe1
EW
111 s = &wwos[row][col];
112 for (i = wwncol - col; --i >= 0;)
a43a8870
EW
113 s++->c_w = ' ';
114 }
115}