]> git.saurik.com Git - apple/shell_cmds.git/blame - window/wwframe.c
shell_cmds-34.tar.gz
[apple/shell_cmds.git] / window / wwframe.c
CommitLineData
44bd5ea7
A
1/* $NetBSD: wwframe.c,v 1.5 1997/11/21 08:37:22 lukem Exp $ */
2
3/*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
9 *
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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39#include <sys/cdefs.h>
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)wwframe.c 8.1 (Berkeley) 6/6/93";
43#else
44__RCSID("$NetBSD: wwframe.c,v 1.5 1997/11/21 08:37:22 lukem Exp $");
45#endif
46#endif /* not lint */
47
48#include "ww.h"
49#include "tt.h"
50
51#define frameok(w, r, c) (w1 = wwindex[wwsmap[r][c]], \
52 w1->ww_fmap || w1->ww_order > (w)->ww_order)
53
54void
55wwframe(w, wframe)
56 struct ww *w;
57 struct ww *wframe;
58{
59 int r, c;
60 char a1, a2, a3;
61 char b1, b2, b3;
62 int code;
63 struct ww *w1;
64
65 if (w->ww_w.t > 0) {
66 r = w->ww_w.t - 1;
67 c = w->ww_i.l - 1;
68 a1 = 0;
69 a2 = 0;
70 b1 = 0;
71 b2 = c < 0 || frameok(w, r, c);
72
73 for (; c < w->ww_i.r; c++) {
74 if (c + 1 >= wwncol) {
75 a3 = 1;
76 b3 = 1;
77 } else {
78 a3 = w->ww_index == wwsmap[r + 1][c + 1];
79 b3 = frameok(w, r, c + 1);
80 }
81 if (b2) {
82 code = 0;
83 if ((a1 || a2) && b1)
84 code |= WWF_L;
85 if ((a2 || a3) && b3)
86 code |= WWF_R;
87 if (code)
88 wwframec(wframe, r, c, code|WWF_TOP);
89 }
90 a1 = a2;
91 a2 = a3;
92 b1 = b2;
93 b2 = b3;
94 }
95 if ((a1 || a2) && b1 && b2)
96 wwframec(wframe, r, c, WWF_L|WWF_TOP);
97 }
98
99 if (w->ww_w.b < wwnrow) {
100 r = w->ww_w.b;
101 c = w->ww_i.l - 1;
102 a1 = 0;
103 a2 = 0;
104 b1 = 0;
105 b2 = c < 0 || frameok(w, r, c);
106
107 for (; c < w->ww_i.r; c++) {
108 if (c + 1 >= wwncol) {
109 a3 = 1;
110 b3 = 1;
111 } else {
112 a3 = w->ww_index == wwsmap[r - 1][c + 1];
113 b3 = frameok(w, r, c + 1);
114 }
115 if (b2) {
116 code = 0;
117 if ((a1 || a2) && b1)
118 code |= WWF_L;
119 if ((a2 || a3) && b3)
120 code |= WWF_R;
121 if (code)
122 wwframec(wframe, r, c, code);
123 }
124 a1 = a2;
125 a2 = a3;
126 b1 = b2;
127 b2 = b3;
128 }
129 if ((a1 || a2) && b1 && b2)
130 wwframec(wframe, r, c, WWF_L);
131 }
132
133 if (w->ww_w.l > 0) {
134 r = w->ww_i.t - 1;
135 c = w->ww_w.l - 1;
136 a1 = 0;
137 a2 = 0;
138 b1 = 0;
139 b2 = r < 0 || frameok(w, r, c);
140
141 for (; r < w->ww_i.b; r++) {
142 if (r + 1 >= wwnrow) {
143 a3 = 1;
144 b3 = 1;
145 } else {
146 a3 = w->ww_index == wwsmap[r + 1][c + 1];
147 b3 = frameok(w, r + 1, c);
148 }
149 if (b2) {
150 code = 0;
151 if ((a1 || a2) && b1)
152 code |= WWF_U;
153 if ((a2 || a3) && b3)
154 code |= WWF_D;
155 if (code)
156 wwframec(wframe, r, c, code);
157 }
158 a1 = a2;
159 a2 = a3;
160 b1 = b2;
161 b2 = b3;
162 }
163 if ((a1 || a2) && b1 && b2)
164 wwframec(wframe, r, c, WWF_U);
165 }
166
167 if (w->ww_w.r < wwncol) {
168 r = w->ww_i.t - 1;
169 c = w->ww_w.r;
170 a1 = 0;
171 a2 = 0;
172 b1 = 0;
173 b2 = r < 0 || frameok(w, r, c);
174
175 for (; r < w->ww_i.b; r++) {
176 if (r + 1 >= wwnrow) {
177 a3 = 1;
178 b3 = 1;
179 } else {
180 a3 = w->ww_index == wwsmap[r + 1][c - 1];
181 b3 = frameok(w, r + 1, c);
182 }
183 if (b2) {
184 code = 0;
185 if ((a1 || a2) && b1)
186 code |= WWF_U;
187 if ((a2 || a3) && b3)
188 code |= WWF_D;
189 if (code)
190 wwframec(wframe, r, c, code);
191 }
192 a1 = a2;
193 a2 = a3;
194 b1 = b2;
195 b2 = b3;
196 }
197 if ((a1 || a2) && b1 && b2)
198 wwframec(wframe, r, c, WWF_U);
199 }
200}
201
202void
203wwframec(f, r, c, code)
204 struct ww *f;
205 int r, c;
206 char code;
207{
208 char oldcode;
209 unsigned char *smap;
210
211 if (r < f->ww_i.t || r >= f->ww_i.b || c < f->ww_i.l || c >= f->ww_i.r)
212 return;
213
214 smap = &wwsmap[r][c];
215
216 {
217 struct ww *w;
218
219 w = wwindex[*smap];
220 if (w->ww_order > f->ww_order) {
221 if (w != &wwnobody && w->ww_win[r][c] == 0)
222 w->ww_nvis[r]--;
223 *smap = f->ww_index;
224 }
225 }
226
227 if (f->ww_fmap != 0) {
228 char *fmap;
229
230 fmap = &f->ww_fmap[r][c];
231 oldcode = *fmap;
232 *fmap |= code;
233 if (code & WWF_TOP)
234 *fmap &= ~WWF_LABEL;
235 code = *fmap;
236 } else
237 oldcode = 0;
238 {
239 char *win = &f->ww_win[r][c];
240
241 if (*win == WWM_GLS && *smap == f->ww_index)
242 f->ww_nvis[r]++;
243 *win &= ~WWM_GLS;
244 }
245 if (oldcode != code && (code & WWF_LABEL) == 0) {
246 short frame;
247
248 frame = tt.tt_frame[code & WWF_MASK];
249 f->ww_buf[r][c].c_w = frame;
250 if (wwsmap[r][c] == f->ww_index) {
251 wwtouched[r] |= WWU_TOUCHED;
252 wwns[r][c].c_w = frame;
253 }
254 }
255}