xref: /original-bsd/lib/libcurses/overwrite.c (revision e59fb703)
1 /*
2  * Copyright (c) 1981 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)overwrite.c	5.4 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 # include	"curses.ext"
13 # include	<ctype.h>
14 
15 # define	min(a,b)	(a < b ? a : b)
16 # define	max(a,b)	(a > b ? a : b)
17 
18 /*
19  *	This routine writes win1 on win2 destructively.
20  *
21  */
22 overwrite(win1, win2)
23 reg WINDOW	*win1, *win2; {
24 
25 	reg char	*sp, *end;
26 	reg int		x, y, endy, endx, starty, startx;
27 
28 # ifdef DEBUG
29 	fprintf(outf, "OVERWRITE(%0.2o, %0.2o);\n", win1, win2);
30 # endif
31 	starty = max(win1->_begy, win2->_begy);
32 	startx = max(win1->_begx, win2->_begx);
33 	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
34 	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
35 	if (starty >= endy || startx >= endx)
36 		return;
37 # ifdef DEBUG
38 	fprintf(outf, "OVERWRITE:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
39 # endif
40 	x = endx - startx;
41 	for (y = starty; y < endy; y++) {
42 		bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
43 		      &win2->_y[y - win2->_begy][startx - win2->_begx], x);
44 		touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
45 	}
46 }
47