added linesize argument to readline()
[unix-history] / usr / src / usr.bin / window / wwdelete.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60de5df9
EW
16 */
17
46e9ea25 18#ifndef lint
6a1ef78a 19static char sccsid[] = "@(#)wwdelete.c 3.17 (Berkeley) %G%";
46e9ea25
KB
20#endif /* not lint */
21
07662491
EW
22#include "ww.h"
23
24/*
25 * Pull w free from the cover list.
26 */
27wwdelete(w)
28register struct ww *w;
29{
c05972b9
EW
30 register i;
31
32 for (i = w->ww_i.t; i < w->ww_i.b; i++) {
33 register j;
34 register char *smap = wwsmap[i];
6ef62e9e 35 register union ww_char *ns = wwns[i];
04d70db4 36 register int nchanged = 0;
84ad208b 37
84ad208b 38 for (j = w->ww_i.l; j < w->ww_i.r; j++)
c05972b9
EW
39 if (smap[j] == w->ww_index) {
40 smap[j] = WWX_NOBODY;
41 ns[j].c_w = ' ';
04d70db4 42 nchanged++;
84ad208b 43 }
6a1ef78a 44 if (nchanged > 0)
04d70db4 45 wwtouched[i] |= WWU_TOUCHED;
c05972b9 46 }
84ad208b 47
c05972b9
EW
48 {
49 register struct ww *wp;
665bc9e7 50
c05972b9
EW
51 for (wp = w->ww_forw; wp != &wwhead; wp = wp->ww_forw)
52 wp->ww_order--;
53 }
54
55 if (w->ww_forw != &wwhead)
56 wwdelete1(w->ww_forw,
57 w->ww_i.t, w->ww_i.b, w->ww_i.l, w->ww_i.r);
861cd1ed 58
07662491
EW
59 w->ww_back->ww_forw = w->ww_forw;
60 w->ww_forw->ww_back = w->ww_back;
61 w->ww_forw = w->ww_back = 0;
62}
665bc9e7
EW
63
64wwdelete1(w, t, b, l, r)
65register struct ww *w;
66{
67 int i;
68 int tt, bb, ll, rr;
1ceeb7e2 69 char hasglass;
665bc9e7 70
1ceeb7e2
EW
71again:
72 hasglass = 0;
665bc9e7
EW
73 tt = MAX(t, w->ww_i.t);
74 bb = MIN(b, w->ww_i.b);
75 ll = MAX(l, w->ww_i.l);
76 rr = MIN(r, w->ww_i.r);
1ceeb7e2
EW
77 if (tt >= bb || ll >= rr) {
78 if ((w = w->ww_forw) == &wwhead)
79 return;
80 goto again;
81 }
665bc9e7 82 for (i = tt; i < bb; i++) {
c05972b9 83 register j;
665bc9e7
EW
84 register char *smap = wwsmap[i];
85 register union ww_char *ns = wwns[i];
86 register char *win = w->ww_win[i];
87 register union ww_char *buf = w->ww_buf[i];
88 int nvis = w->ww_nvis[i];
04d70db4 89 int nchanged = 0;
665bc9e7
EW
90
91 for (j = ll; j < rr; j++) {
1ceeb7e2
EW
92 if (smap[j] != WWX_NOBODY)
93 continue;
94 if (win[j] & WWM_GLS) {
95 hasglass = 1;
665bc9e7 96 continue;
1ceeb7e2 97 }
c05972b9
EW
98 smap[j] = w->ww_index;
99 ns[j].c_w = buf[j].c_w ^ win[j] << WWC_MSHIFT;
04d70db4 100 nchanged++;
c05972b9
EW
101 if (win[j] == 0)
102 nvis++;
665bc9e7 103 }
6a1ef78a 104 if (nchanged > 0)
04d70db4 105 wwtouched[i] |= WWU_TOUCHED;
665bc9e7
EW
106 w->ww_nvis[i] = nvis;
107 }
108 if ((w = w->ww_forw) == &wwhead)
109 return;
1ceeb7e2
EW
110 if (hasglass)
111 goto again;
665bc9e7
EW
112 if (tt > t)
113 wwdelete1(w, t, tt, l, r);
114 if (bb < b)
115 wwdelete1(w, bb, b, l, r);
116 if (ll > l)
1ceeb7e2 117 wwdelete1(w, tt, bb, l, ll);
665bc9e7 118 if (rr < r)
1ceeb7e2 119 wwdelete1(w, tt, bb, rr, r);
665bc9e7 120}