smart wwrite: copy in chunks.
[unix-history] / usr / src / usr.bin / window / wwclreol.c
CommitLineData
a43a8870 1#ifndef lint
861cd1ed 2static char *sccsid = "@(#)wwclreol.c 3.5 83/08/16";
a43a8870
EW
3#endif
4
5#include "ww.h"
e908bfac 6#include "tt.h"
a43a8870 7
14f251df
EW
8wwclreol(w, line, col)
9struct ww *w;
10{
11 wwclreol1(w, line, col, 0);
12}
13
a43a8870
EW
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 */
14f251df 19wwclreol1(w, line, col, cleared)
a43a8870 20register struct ww *w;
14f251df
EW
21int line, col;
22char cleared;
a43a8870
EW
23{
24 register i;
25 int row = line - w->ww_scroll;
26 int srow = w->ww_w.t + row;
27 int scol = w->ww_w.l + col;
28 register union ww_char *s, *buf;
29 register char *smap, *win;
861cd1ed 30 char *touched;
a43a8870
EW
31 int nblank, ncleared;
32
33 if (row < 0 || row >= w->ww_w.nr) {
34 /* can't even see it, so just clear the buffer */
35 buf = &w->ww_buf[line][col];
36 for (i = w->ww_w.nc - col; --i >= 0;)
37 buf++->c_w = ' ';
38 return;
39 }
40 smap = &wwsmap[srow][scol];
41 s = &wwns[srow][scol];
861cd1ed 42 touched = &wwtouched[srow];
a43a8870
EW
43 win = &w->ww_win[row][col];
44 buf = &w->ww_buf[row][col];
45 ncleared = nblank = 0;
46 for (i = w->ww_w.nc - col; --i >= 0;) {
47 if (*smap++ != w->ww_index) {
48 if (s++->c_w == ' ')
49 nblank++;
50 buf++;
51 win++;
52 continue;
53 }
54 ncleared++;
55 buf++->c_w = ' ';
861cd1ed 56 *touched = 1;
a43a8870
EW
57 if (*win == 0) {
58 nblank++;
59 s++->c_w = ' ';
60 win++;
61 } else
62 s++->c_w = ' ' | *win++ << WWC_MSHIFT;
63 }
64 if (!cleared && tt.tt_clreol != 0
65 && ncleared > wwncol - scol - nblank
66 && nblank > (wwncol - scol) / 2) {
67 /* clear to the end */
68 (*tt.tt_move)(srow, scol);
69 (*tt.tt_clreol)();
70 s = &wwos[srow][scol];
b1db5e4e 71 for (i = wwncol - scol; --i >= 0;)
a43a8870
EW
72 s++->c_w = ' ';
73 }
74}