xref: /csrg-svn/lib/libcurses/overwrite.c (revision 67082)
122678Sdist /*
2*67082Sbostic  * Copyright (c) 1981, 1993, 1994
361272Sbostic  *	The Regents of the University of California.  All rights reserved.
434677Sbostic  *
542655Sbostic  * %sccs.include.redist.c%
622678Sdist  */
722678Sdist 
822678Sdist #ifndef lint
9*67082Sbostic static char sccsid[] = "@(#)overwrite.c	8.2 (Berkeley) 05/04/94";
1055973Sbostic #endif	/* not lint */
1122678Sdist 
1255973Sbostic #include <ctype.h>
1355984Sbostic #include <string.h>
142259Sarnold 
15*67082Sbostic #include "curses.h"
16*67082Sbostic 
172259Sarnold /*
1855973Sbostic  * overwrite --
1955973Sbostic  *	Writes win1 on win2 destructively.
202259Sarnold  */
2155973Sbostic int
overwrite(win1,win2)222259Sarnold overwrite(win1, win2)
2355973Sbostic 	register WINDOW *win1, *win2;
2455973Sbostic {
2555973Sbostic 	register int x, y, endy, endx, starty, startx;
262259Sarnold 
2755973Sbostic #ifdef DEBUG
2860058Sbostic 	__CTRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2);
2955973Sbostic #endif
3056238Selan 	starty = max(win1->begy, win2->begy);
3156238Selan 	startx = max(win1->begx, win2->begx);
3256238Selan 	endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
3356238Selan 	endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
3419890Sbloom 	if (starty >= endy || startx >= endx)
3557472Sbostic 		return (OK);
3655973Sbostic #ifdef DEBUG
3760058Sbostic 	__CTRACE("overwrite: from (%d, %d) to (%d, %d)\n",
3855973Sbostic 	    starty, startx, endy, endx);
3955973Sbostic #endif
4019890Sbloom 	x = endx - startx;
4119890Sbloom 	for (y = starty; y < endy; y++) {
4258041Selan 		(void)memcpy(
4356238Selan 		    &win2->lines[y - win2->begy]->line[startx - win2->begx],
4458041Selan 		    &win1->lines[y - win1->begy]->line[startx - win1->begx],
4556647Selan 		    x * __LDATASIZE);
4656650Selan 		__touchline(win2, y, startx - win2->begx, endx - win2->begx,
4756650Selan 		    0);
4819890Sbloom 	}
4957472Sbostic 	return (OK);
502259Sarnold }
51