document distributed with 4.1BSD
[unix-history] / usr / src / lib / libcurses / overwrite.c
CommitLineData
87c6fcf8
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
8static char sccsid[] = "@(#)overwrite.c 5.1 (Berkeley) %G%";
9#endif not lint
10
421683f2 11# include "curses.ext"
52f06ac3 12# include <ctype.h>
b17f6be0
KA
13
14# define min(a,b) (a < b ? a : b)
52f06ac3 15# define max(a,b) (a > b ? a : b)
b17f6be0
KA
16
17/*
18 * This routine writes win1 on win2 destructively.
19 *
b17f6be0
KA
20 */
21overwrite(win1, win2)
22reg WINDOW *win1, *win2; {
23
52f06ac3
JB
24 reg char *sp, *end;
25 reg int x, y, endy, endx, starty, startx;
b17f6be0
KA
26
27# ifdef DEBUG
52f06ac3 28 fprintf(outf, "OVERWRITE(%0.2o, %0.2o);\n", win1, win2);
b17f6be0 29# endif
52f06ac3
JB
30 starty = max(win1->_begy, win2->_begy);
31 startx = max(win1->_begx, win2->_begx);
32 endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
33 endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
34 if (starty >= endy || startx >= endx)
35 return;
b17f6be0 36# ifdef DEBUG
52f06ac3 37 fprintf(outf, "OVERWRITE:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
b17f6be0 38# endif
52f06ac3
JB
39 x = endx - startx;
40 for (y = starty; y < endy; y++) {
41 bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
42 &win2->_y[y - win2->_begy][startx - win2->_begx], x);
43 touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
44 }
b17f6be0 45}