add log device ; unused reset routines are nulldev
[unix-history] / usr / src / usr.bin / window / wwupdate.c
CommitLineData
bbb8329f 1#ifndef lint
2bb24b34 2static char sccsid[] = "@(#)wwupdate.c 3.15 %G%";
bbb8329f
EW
3#endif
4
5#include "ww.h"
e908bfac 6#include "tt.h"
bbb8329f 7
b1189050 8wwupdate1(top, bot)
bbb8329f 9{
b7f39bc5
EW
10 int i;
11 register j;
bbb8329f 12 register union ww_char *ns, *os;
b7f39bc5 13 char *touched;
6e3b31ff 14 char didit;
bbb8329f 15
861cd1ed 16 wwnupdate++;
b1189050
EW
17 for (i = top, touched = &wwtouched[i]; i < bot && !wwinterrupt();
18 i++, touched++) {
861cd1ed
EW
19 if (!*touched)
20 continue;
6e3b31ff
EW
21 if (*touched & WWU_MAJOR && tt.tt_clreol != 0) {
22 register gain = 0;
23 register best_gain = 0;
24 register best;
b7f39bc5 25
04d70db4
EW
26 wwnmajline++;
27 j = wwncol;
6e3b31ff
EW
28 ns = &wwns[i][j];
29 os = &wwos[i][j];
04d70db4 30 while (--j >= 0) {
6e3b31ff
EW
31 /*
32 * The cost of clearing is:
33 * ncol - nblank + X
34 * The cost of straight update is:
35 * ncol - nsame
36 * We clear if: nblank - nsame > X
37 * X is the clreol overhead.
38 * So we make gain = nblank - nsame.
39 */
40 if ((--ns)->c_w == (--os)->c_w)
41 gain--;
42 else
43 best_gain--;
44 if (ns->c_w == ' ')
45 gain++;
46 if (gain >= best_gain) {
47 best = j;
48 best_gain = gain;
49 }
04d70db4 50 }
6e3b31ff
EW
51 if (best_gain > 4) {
52 (*tt.tt_move)(i, best);
04d70db4 53 (*tt.tt_clreol)();
6e3b31ff
EW
54 for (j = wwncol - best, os = &wwos[i][best];
55 --j >= 0;)
04d70db4
EW
56 os++->c_w = ' ';
57 } else
58 wwnmajmiss++;
59 }
2b19684f 60 *touched = 0;
04d70db4
EW
61 wwnupdline++;
62 didit = 0;
bbb8329f
EW
63 ns = wwns[i];
64 os = wwos[i];
b7f39bc5 65 for (j = 0; j < wwncol;) {
6e3b31ff
EW
66 register char *p, *q;
67 char m;
68 int c;
69 register n;
70 char buf[512]; /* > wwncol */
71 union ww_char lastc;
72
b7f39bc5
EW
73 for (; j++ < wwncol && ns++->c_w == os++->c_w;)
74 ;
75 if (j > wwncol)
76 break;
77 p = buf;
3130283e 78 m = ns[-1].c_m & tt.tt_availmodes;
b7f39bc5
EW
79 c = j - 1;
80 os[-1] = ns[-1];
81 *p++ = ns[-1].c_c;
6e3b31ff 82 n = 5;
b7f39bc5 83 q = p;
3130283e 84 while (j < wwncol && (ns->c_m&tt.tt_availmodes) == m) {
b7f39bc5
EW
85 *p++ = ns->c_c;
86 if (ns->c_w == os->c_w) {
6e3b31ff 87 if (--n <= 0)
b7f39bc5
EW
88 break;
89 os++;
90 ns++;
91 } else {
6e3b31ff 92 n = 5;
b7f39bc5 93 q = p;
5e785082 94 lastc = *os;
b7f39bc5
EW
95 *os++ = *ns++;
96 }
97 j++;
bbb8329f 98 }
3130283e 99 tt.tt_nmodes = m;
5e785082
EW
100 if (wwwrap
101 && i == wwnrow - 1 && q - buf + c == wwncol) {
3130283e 102 if (tt.tt_hasinsert) {
594208de
EW
103 if (q - buf != 1) {
104 (*tt.tt_move)(i, c);
105 (*tt.tt_write)(buf + 1,
106 q - buf - 1);
107 (*tt.tt_move)(i, c);
108 tt.tt_ninsert = 1;
109 (*tt.tt_write)(buf, 1);
110 tt.tt_ninsert = 0;
111 } else {
112 (*tt.tt_move)(i, c - 1);
113 (*tt.tt_write)(buf, 1);
114 tt.tt_nmodes = ns[-2].c_m;
115 (*tt.tt_move)(i, c - 1);
116 tt.tt_ninsert = 1;
117 (*tt.tt_write)(&ns[-2].c_c, 1);
118 tt.tt_ninsert = 0;
119 }
5e785082 120 } else {
2bb24b34
EW
121 if (q - buf > 1) {
122 (*tt.tt_move)(i, c);
123 (*tt.tt_write)(buf, q-buf-1);
124 }
2b19684f
EW
125 os[-1] = lastc;
126 *touched = WWU_TOUCHED;
5e785082 127 }
594208de
EW
128 } else {
129 (*tt.tt_move)(i, c);
3130283e 130 (*tt.tt_write)(buf, q - buf);
594208de 131 }
b7f39bc5 132 didit++;
bbb8329f 133 }
861cd1ed 134 if (!didit)
04d70db4 135 wwnupdmiss++;
bbb8329f
EW
136 }
137}