xref: /original-bsd/lib/libcurses/overwrite.c (revision 02e832b2)
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.11 (Berkeley) 12/30/92";
10 #endif	/* not lint */
11 
12 #include <ctype.h>
13 #include <curses.h>
14 #include <string.h>
15 
16 /*
17  * overwrite --
18  *	Writes win1 on win2 destructively.
19  */
20 int
21 overwrite(win1, win2)
22 	register WINDOW *win1, *win2;
23 {
24 	register int x, y, endy, endx, starty, startx;
25 
26 #ifdef DEBUG
27 	__TRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2);
28 #endif
29 	starty = max(win1->begy, win2->begy);
30 	startx = max(win1->begx, win2->begx);
31 	endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
32 	endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
33 	if (starty >= endy || startx >= endx)
34 		return (CURSES_OK);
35 #ifdef DEBUG
36 	__TRACE("overwrite: from (%d, %d) to (%d, %d)\n",
37 	    starty, startx, endy, endx);
38 #endif
39 	x = endx - startx;
40 	for (y = starty; y < endy; y++) {
41 		bcopy(&win1->lines[y - win1->begy]->line[startx - win1->begx],
42 		    &win2->lines[y - win2->begy]->line[startx - win2->begx],
43 		    x * __LDATASIZE);
44 		__touchline(win2, y, startx - win2->begx, endx - win2->begx,
45 		    0);
46 	}
47 	return (CURSES_OK);
48 }
49