Add copyright
[unix-history] / usr / src / lib / libcurses / overwrite.c
index dbd29f4..6ba5eea 100644 (file)
@@ -1,31 +1,45 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)overwrite.c        5.1 (Berkeley) %G%";
+#endif not lint
+
 # include      "curses.ext"
 # include      "curses.ext"
+# include      <ctype.h>
 
 # define       min(a,b)        (a < b ? a : b)
 
 # define       min(a,b)        (a < b ? a : b)
+# define       max(a,b)        (a > b ? a : b)
 
 /*
  *     This routine writes win1 on win2 destructively.
  *
 
 /*
  *     This routine writes win1 on win2 destructively.
  *
- * %G% (Berkeley) @(#)overwrite.c      1.3
  */
 overwrite(win1, win2)
 reg WINDOW     *win1, *win2; {
 
  */
 overwrite(win1, win2)
 reg WINDOW     *win1, *win2; {
 
-       reg int         x, y, minx, miny, startx, starty;
+       reg char        *sp, *end;
+       reg int         x, y, endy, endx, starty, startx;
 
 # ifdef DEBUG
 
 # ifdef DEBUG
-       fprintf(outf, "OVERWRITE(0%o, 0%o);\n", win1, win2);
+       fprintf(outf, "OVERWRITE(%0.2o, %0.2o);\n", win1, win2);
 # endif
 # endif
-       miny = min(win1->_maxy, win2->_maxy);
-       minx = min(win1->_maxx, win2->_maxx);
+       starty = max(win1->_begy, win2->_begy);
+       startx = max(win1->_begx, win2->_begx);
+       endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
+       endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
+       if (starty >= endy || startx >= endx)
+               return;
 # ifdef DEBUG
 # ifdef DEBUG
-       fprintf(outf, "OVERWRITE:\tminx = %d,  miny = %d\n", minx, miny);
+       fprintf(outf, "OVERWRITE:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
 # endif
 # endif
-       starty = win1->_begy - win2->_begy;
-       startx = win1->_begx - win2->_begx;
-       if (startx < 0)
-               startx = 0;
-       for (y = 0; y < miny; y++)
-               if (wmove(win2, y + starty, startx) != ERR)
-                       for (x = 0; x < minx; x++)
-                               waddch(win2, win1->_y[y][x]);
+       x = endx - startx;
+       for (y = starty; y < endy; y++) {
+               bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
+                     &win2->_y[y - win2->_begy][startx - win2->_begx], x);
+               touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
+       }
 }
 }