xref: /original-bsd/usr.bin/window/wwadd.c (revision a4d3ae46)
1 /*
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
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)wwadd.c	3.10 (Berkeley) 02/21/88";
15 #endif /* not lint */
16 
17 #include "ww.h"
18 
19 /*
20  * Stick w1 behind w2.
21  */
22 wwadd(w1, w2)
23 register struct ww *w1;
24 struct ww *w2;
25 {
26 	register i;
27 	register struct ww *w;
28 
29 	w1->ww_order = w2->ww_order + 1;
30 	w1->ww_back = w2;
31 	w1->ww_forw = w2->ww_forw;
32 	w2->ww_forw->ww_back = w1;
33 	w2->ww_forw = w1;
34 
35 	for (w = w1->ww_forw; w != &wwhead; w = w->ww_forw)
36 		w->ww_order++;
37 	for (i = w1->ww_i.t; i < w1->ww_i.b; i++) {
38 		register j;
39 		register char *smap = wwsmap[i];
40 		register char *win = w1->ww_win[i];
41 		union ww_char *ns = wwns[i];
42 		union ww_char *buf = w1->ww_buf[i];
43 		int nvis = 0;
44 		int nchanged = 0;
45 
46 		for (j = w1->ww_i.l; j < w1->ww_i.r; j++) {
47 			w = wwindex[smap[j]];
48 			if (w1->ww_order > w->ww_order)
49 				continue;
50 			if (win[j] & WWM_GLS)
51 				continue;
52 			if (w != &wwnobody && w->ww_win[i][j] == 0)
53 				w->ww_nvis[i]--;
54 			smap[j] = w1->ww_index;
55 			if (win[j] == 0)
56 				nvis++;
57 			ns[j].c_w = buf[j].c_w ^ win[j] << WWC_MSHIFT;
58 			nchanged++;
59 		}
60 		if (nchanged > 4)
61 			wwtouched[i] |= WWU_MAJOR|WWU_TOUCHED;
62 		else if (nchanged > 0)
63 			wwtouched[i] |= WWU_TOUCHED;
64 		w1->ww_nvis[i] = nvis;
65 	}
66 }
67