HAMMER - Try to improve backend stalls due to heavy write activity.
[dragonfly.git] / usr.bin / window / wwframe.c
bloba67c71b47fc43d1e5cd1ad11fb038c8423c50057
1 /* $NetBSD: wwframe.c,v 1.7 2003/08/07 11:17:39 agc Exp $ */
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)wwframe.c 8.1 (Berkeley) 6/6/93";
39 #else
40 __RCSID("$NetBSD: wwframe.c,v 1.7 2003/08/07 11:17:39 agc Exp $");
41 #endif
42 #endif /* not lint */
44 #include "ww.h"
45 #include "tt.h"
47 #define frameok(w, r, c) (w1 = wwindex[wwsmap[r][c]], \
48 w1->ww_fmap || w1->ww_order > (w)->ww_order)
50 void
51 wwframe(struct ww *w, struct ww *wframe)
53 int r, c;
54 char a1, a2, a3;
55 char b1, b2, b3;
56 int code;
57 struct ww *w1;
59 if (w->ww_w.t > 0) {
60 r = w->ww_w.t - 1;
61 c = w->ww_i.l - 1;
62 a1 = 0;
63 a2 = 0;
64 b1 = 0;
65 b2 = c < 0 || frameok(w, r, c);
67 for (; c < w->ww_i.r; c++) {
68 if (c + 1 >= wwncol) {
69 a3 = 1;
70 b3 = 1;
71 } else {
72 a3 = w->ww_index == wwsmap[r + 1][c + 1];
73 b3 = frameok(w, r, c + 1);
75 if (b2) {
76 code = 0;
77 if ((a1 || a2) && b1)
78 code |= WWF_L;
79 if ((a2 || a3) && b3)
80 code |= WWF_R;
81 if (code)
82 wwframec(wframe, r, c, code|WWF_TOP);
84 a1 = a2;
85 a2 = a3;
86 b1 = b2;
87 b2 = b3;
89 if ((a1 || a2) && b1 && b2)
90 wwframec(wframe, r, c, WWF_L|WWF_TOP);
93 if (w->ww_w.b < wwnrow) {
94 r = w->ww_w.b;
95 c = w->ww_i.l - 1;
96 a1 = 0;
97 a2 = 0;
98 b1 = 0;
99 b2 = c < 0 || frameok(w, r, c);
101 for (; c < w->ww_i.r; c++) {
102 if (c + 1 >= wwncol) {
103 a3 = 1;
104 b3 = 1;
105 } else {
106 a3 = w->ww_index == wwsmap[r - 1][c + 1];
107 b3 = frameok(w, r, c + 1);
109 if (b2) {
110 code = 0;
111 if ((a1 || a2) && b1)
112 code |= WWF_L;
113 if ((a2 || a3) && b3)
114 code |= WWF_R;
115 if (code)
116 wwframec(wframe, r, c, code);
118 a1 = a2;
119 a2 = a3;
120 b1 = b2;
121 b2 = b3;
123 if ((a1 || a2) && b1 && b2)
124 wwframec(wframe, r, c, WWF_L);
127 if (w->ww_w.l > 0) {
128 r = w->ww_i.t - 1;
129 c = w->ww_w.l - 1;
130 a1 = 0;
131 a2 = 0;
132 b1 = 0;
133 b2 = r < 0 || frameok(w, r, c);
135 for (; r < w->ww_i.b; r++) {
136 if (r + 1 >= wwnrow) {
137 a3 = 1;
138 b3 = 1;
139 } else {
140 a3 = w->ww_index == wwsmap[r + 1][c + 1];
141 b3 = frameok(w, r + 1, c);
143 if (b2) {
144 code = 0;
145 if ((a1 || a2) && b1)
146 code |= WWF_U;
147 if ((a2 || a3) && b3)
148 code |= WWF_D;
149 if (code)
150 wwframec(wframe, r, c, code);
152 a1 = a2;
153 a2 = a3;
154 b1 = b2;
155 b2 = b3;
157 if ((a1 || a2) && b1 && b2)
158 wwframec(wframe, r, c, WWF_U);
161 if (w->ww_w.r < wwncol) {
162 r = w->ww_i.t - 1;
163 c = w->ww_w.r;
164 a1 = 0;
165 a2 = 0;
166 b1 = 0;
167 b2 = r < 0 || frameok(w, r, c);
169 for (; r < w->ww_i.b; r++) {
170 if (r + 1 >= wwnrow) {
171 a3 = 1;
172 b3 = 1;
173 } else {
174 a3 = w->ww_index == wwsmap[r + 1][c - 1];
175 b3 = frameok(w, r + 1, c);
177 if (b2) {
178 code = 0;
179 if ((a1 || a2) && b1)
180 code |= WWF_U;
181 if ((a2 || a3) && b3)
182 code |= WWF_D;
183 if (code)
184 wwframec(wframe, r, c, code);
186 a1 = a2;
187 a2 = a3;
188 b1 = b2;
189 b2 = b3;
191 if ((a1 || a2) && b1 && b2)
192 wwframec(wframe, r, c, WWF_U);
196 void
197 wwframec(struct ww *f, int r, int c, char code)
199 char oldcode;
200 unsigned char *smap;
202 if (r < f->ww_i.t || r >= f->ww_i.b || c < f->ww_i.l || c >= f->ww_i.r)
203 return;
205 smap = &wwsmap[r][c];
208 struct ww *w;
210 w = wwindex[*smap];
211 if (w->ww_order > f->ww_order) {
212 if (w != &wwnobody && w->ww_win[r][c] == 0)
213 w->ww_nvis[r]--;
214 *smap = f->ww_index;
218 if (f->ww_fmap != 0) {
219 char *fmap;
221 fmap = &f->ww_fmap[r][c];
222 oldcode = *fmap;
223 *fmap |= code;
224 if (code & WWF_TOP)
225 *fmap &= ~WWF_LABEL;
226 code = *fmap;
227 } else
228 oldcode = 0;
230 char *win = &f->ww_win[r][c];
232 if (*win == WWM_GLS && *smap == f->ww_index)
233 f->ww_nvis[r]++;
234 *win &= ~WWM_GLS;
236 if (oldcode != code && (code & WWF_LABEL) == 0) {
237 short frame;
239 frame = tt.tt_frame[code & WWF_MASK];
240 f->ww_buf[r][c].c_w = frame;
241 if (wwsmap[r][c] == f->ww_index) {
242 wwtouched[r] |= WWU_TOUCHED;
243 wwns[r][c].c_w = frame;