copywin.c revision 1.9 1 /* $NetBSD: copywin.c,v 1.9 2002/01/02 10:38:27 blymn Exp $ */
2
3 /*-
4 * Copyright (c) 1998-1999 Brett Lymn
5 * (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
6 * All rights reserved.
7 *
8 * This code has been donated to The NetBSD Foundation by the Author.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 *
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 __RCSID("$NetBSD: copywin.c,v 1.9 2002/01/02 10:38:27 blymn Exp $");
35 #endif /* not lint */
36
37 #include <ctype.h>
38 #include <string.h>
39 #include "curses.h"
40 #include "curses_private.h"
41
42 /*
43 * copywin --
44 * Copy the box starting at (sminrow, smincol) with a size that
45 * matches the destination box (dminrow, dmincol) by (dmaxrow, dmaxcol)
46 * from the source window srcwin to the destination window dstwin.
47 * If dooverlay is true then the copy is nondestructive otherwise the
48 * copy is destructive.
49 */
50 int copywin(const WINDOW *srcwin, WINDOW *dstwin, int sminrow,
51 int smincol, int dminrow, int dmincol, int dmaxrow,
52 int dmaxcol, int dooverlay)
53 {
54 int starty, startx, endy, endx, x, y, y1, y2, smaxrow, smaxcol;
55 __LDATA *sp, *end;
56
57 smaxrow = min(sminrow + dmaxrow - dminrow, srcwin->maxy);
58 smaxcol = min(smincol + dmaxcol - dmincol, srcwin->maxx);
59 starty = max(sminrow, dminrow);
60 startx = max(smincol, dmincol);
61 endy = min(sminrow + smaxrow, dminrow + dmaxrow);
62 endx = min(smincol + smaxcol, dmincol + dmaxcol);
63 if (starty >= endy || startx >= endx)
64 return (OK);
65
66 #ifdef DEBUG
67 if (dooverlay == TRUE) {
68 __CTRACE("copywin overlay mode: from (%d,%d) to (%d,%d)\n",
69 starty, startx, endy, endx);
70 } else {
71 __CTRACE("copywin overwrite mode: from (%d,%d) to (%d,%d)\n",
72 starty, startx, endy, endx);
73 }
74
75 #endif
76 y1 = starty - sminrow;
77 y2 = starty - dminrow;
78 for (y = starty; y < endy; y++, y1++, y2++) {
79 end = &srcwin->lines[y1]->line[endx - srcwin->begx];
80 x = startx - dstwin->begx;
81 for (sp = &srcwin->lines[y1]->line[startx - srcwin->begx];
82 sp < end; sp++) {
83 if ((!isspace(sp->ch)) || (dooverlay == FALSE)){
84 wmove(dstwin, y2, x);
85 __waddch(dstwin, sp);
86 }
87 x++;
88 }
89 }
90 return (OK);
91 }
92
93