xref: /csrg-svn/lib/libcurses/overwrite.c (revision 56238)
122678Sdist /*
234677Sbostic  * Copyright (c) 1981 Regents of the University of California.
334677Sbostic  * All rights reserved.
434677Sbostic  *
542655Sbostic  * %sccs.include.redist.c%
622678Sdist  */
722678Sdist 
822678Sdist #ifndef lint
9*56238Selan static char sccsid[] = "@(#)overwrite.c	5.7 (Berkeley) 09/14/92";
1055973Sbostic #endif	/* not lint */
1122678Sdist 
1255973Sbostic #include <ctype.h>
1355973Sbostic #include <curses.h>
1455984Sbostic #include <string.h>
152259Sarnold 
162259Sarnold /*
1755973Sbostic  * overwrite --
1855973Sbostic  *	Writes win1 on win2 destructively.
192259Sarnold  */
2055973Sbostic int
212259Sarnold overwrite(win1, win2)
2255973Sbostic 	register WINDOW *win1, *win2;
2355973Sbostic {
2455973Sbostic 	register int x, y, endy, endx, starty, startx;
252259Sarnold 
2655973Sbostic #ifdef DEBUG
2755973Sbostic 	__TRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2);
2855973Sbostic #endif
29*56238Selan 	starty = max(win1->begy, win2->begy);
30*56238Selan 	startx = max(win1->begx, win2->begx);
31*56238Selan 	endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
32*56238Selan 	endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
3319890Sbloom 	if (starty >= endy || startx >= endx)
3455973Sbostic 		return (OK);
3555973Sbostic #ifdef DEBUG
3655973Sbostic 	__TRACE("overwrite: from (%d, %d) to (%d, %d)\n",
3755973Sbostic 	    starty, startx, endy, endx);
3855973Sbostic #endif
3919890Sbloom 	x = endx - startx;
4019890Sbloom 	for (y = starty; y < endy; y++) {
41*56238Selan 		bcopy(&win1->lines[y - win1->begy]->line[startx - win1->begx],
42*56238Selan 		    &win2->lines[y - win2->begy]->line[startx - win2->begx],
43*56238Selan 		    x);
44*56238Selan 		touchline(win2, y, startx - win2->begx, endx - win2->begx);
4519890Sbloom 	}
4655973Sbostic 	return (OK);
472259Sarnold }
48