More multiple changes:

* Added function derwin.
* Added function copywin.
* Modified both overlay and overwrite to use copywin.
* Updated man page with new functions and fixed minor format glitch.
This commit is contained in:
blymn 2000-04-18 12:23:01 +00:00
parent ae62335eb5
commit e79669d636
7 changed files with 146 additions and 67 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.23 2000/04/12 21:50:46 jdc Exp $
# $NetBSD: Makefile,v 1.24 2000/04/18 12:23:01 blymn Exp $
# @(#)Makefile 8.2 (Berkeley) 1/2/94
CPPFLAGS+=#-DTFILE=\"/dev/ttyp0\"
@ -6,13 +6,13 @@ CPPFLAGS+=-D_CURSES_PRIVATE -I${.CURDIR}
LIB= curses
SRCS= addbytes.c addch.c addnstr.c acs.c attributes.c background.c bell.c \
border.c box.c clear.c clearok.c clrtobot.c clrtoeol.c color.c \
cr_put.c ctrace.c cur_hash.c curses.c delch.c deleteln.c delwin.c \
erase.c flushok.c fullname.c getch.c getstr.c getyx.c id_subwins.c \
idlok.c inch.c initscr.c insch.c insdelln.c insertln.c keypad.c \
leaveok.c longname.c move.c mvwin.c newwin.c nodelay.c notimeout.c \
overlay.c overwrite.c printw.c putchar.c refresh.c scanw.c scroll.c \
scrollok.c setterm.c standout.c timeout.c toucholap.c touchwin.c \
tscroll.c tstp.c tty.c unctrl.c underscore.c
copywin.c cr_put.c ctrace.c cur_hash.c curses.c delch.c deleteln.c \
delwin.c erase.c flushok.c fullname.c getch.c getstr.c getyx.c \
id_subwins.c idlok.c inch.c initscr.c insch.c insdelln.c insertln.c \
keypad.c leaveok.c longname.c move.c mvwin.c newwin.c nodelay.c \
notimeout.c overlay.c overwrite.c printw.c putchar.c refresh.c \
scanw.c scroll.c scrollok.c setterm.c standout.c timeout.c \
toucholap.c touchwin.c tscroll.c tstp.c tty.c unctrl.c underscore.c
MAN= curses.3
INCS= curses.h unctrl.h wchar.h
INCSDIR=/usr/include

99
lib/libcurses/copywin.c Normal file
View File

@ -0,0 +1,99 @@
/* $NetBSD: copywin.c,v 1.1 2000/04/18 12:23:01 blymn Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn
* (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* This code has been donated to The NetBSD Foundation by the Author.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software withough specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <ctype.h>
#include "curses.h"
#include "curses_private.h"
/*
* copywin --
* Copy the box starting at (sminrow, smincol) with a size that
* matches the destination box (dminrow, dmincol) by (dmaxrow, dmaxcol)
* from the source window srcwin to the destination window dstwin.
* If overlay is true then the copy is nondestructive otherwise the
* copy is destructive.
*/
int copywin(const WINDOW *srcwin, WINDOW *dstwin, int sminrow,
int smincol, int dminrow, int dmincol, int dmaxrow,
int dmaxcol, int overlay)
{
int starty, startx, endy, endx, x, y, y1, y2, smaxrow, smaxcol;
__LDATA *sp, *end;
smaxrow = sminrow + dmaxrow - dminrow;
smaxcol = smincol + dmaxcol - dmincol;
starty = max(sminrow, dminrow);
startx = max(smincol, dmincol);
endy = min(sminrow + smaxrow, dminrow + dmaxrow);
endx = min(smincol + smaxcol, dmincol + dmaxcol);
if (starty >= endy || startx >= endx)
return (OK);
if (overlay == TRUE) {
/* non destructive copy */
#ifdef DEBUG
__CTRACE("copywin overlay mode: from (%d,%d) to (%d,%d)\n",
starty, startx, endy, endx);
#endif
y1 = starty - sminrow;
y2 = starty - dminrow;
for (y = starty; y < endy; y++, y1++, y2++) {
end = &srcwin->lines[y1]->line[endx - srcwin->begx];
x = startx - dstwin->begx;
for (sp = &srcwin->lines[y1]->line[startx - srcwin->begx];
sp < end; sp++) {
if (!isspace(sp->ch)) {
wmove(dstwin, y2, x);
__waddch(dstwin, sp);
}
x++;
}
}
return (OK);
} else {
/* destructive copy */
#ifdef DEBUG
__CTRACE("copywin overwrite mode: from (%d,%d) to (%d,%d)\n",
starty, startx, endy, endx);
#endif
x = endx - startx;
for (y = starty; y < endy; y++) {
(void) memcpy(
&dstwin->lines[y - dstwin->begy]->line[startx - dstwin->begx],
&srcwin->lines[y - srcwin->begy]->line[startx - srcwin->begx],
(size_t) x * __LDATASIZE);
__touchline(dstwin, y, (int) (startx - dstwin->begx),
(int) (endx - dstwin->begx), 0);
}
return (OK);
}
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: curses.3,v 1.17 2000/04/12 21:49:29 jdc Exp $
.\" $NetBSD: curses.3,v 1.18 2000/04/18 12:23:01 blymn Exp $
.\"
.\" Copyright (c) 1985, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -106,12 +106,20 @@ and applies this rendition to
.It clrtoeol() clear to end of line on
.Em stdscr
.It color_content(c, r, g, b) get rgb values of color
.It copywin(srcwin,dstwin,sminrow,smincol,dminrow,dmincol,dmaxrow,dmaxcol,overlay)
Copy rectangle from
.Em srcwin
to
.Em dstwin.
If overlay is true then copy is nondestructive.
.It def_prog_mode() define program (in curses) terminal modes
.It def_shell_mode() define shell (not in curses) terminal modes
.It delch() delete a character
.It deleteln() delete a line
.It delwin(win) delete
.Em win
.It derwin(win,lines,cols,begin_y,begin_x)\ create a subwindow
relative to win.
.It echo() set echo mode
.It endwin() end window modes
.It erase() erase
@ -120,7 +128,7 @@ and applies this rendition to
.It flushinp() flush terminal input
.It flushok(win,boolf) set flush-on-refresh flag for
.Em win
.It fullname(termbuf,name) get full name from
.It fullname(termbuf,name) get full name from
.Em termbuf
.It getbkgd(win) get background rendition for
.Em win

View File

@ -1,4 +1,4 @@
/* $NetBSD: curses.h,v 1.37 2000/04/17 12:25:45 blymn Exp $ */
/* $NetBSD: curses.h,v 1.38 2000/04/18 12:23:01 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -489,9 +489,13 @@ int cbreak(void);
int clearok(WINDOW *win, bool flag);
bool can_change_colors(void);
int color_content(short colour, short *redp, short *greenp, short *bluep);
int copywin(const WINDOW *srcwin, WINDOW *dstwin, int sminrow,
int smincol, int dminrow, int dmincol, int dmaxrow,
int dmaxcol, int overlay);
int def_prog_mode(void);
int def_shell_mode(void);
int delwin(WINDOW *win);
WINDOW *derwin(WINDOW *orig, int nlines, int ncols, int by, int bx);
int echo(void);
int endwin(void);
int flash(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: newwin.c,v 1.19 2000/04/17 12:25:46 blymn Exp $ */
/* $NetBSD: newwin.c,v 1.20 2000/04/18 12:23:01 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94";
#else
__RCSID("$NetBSD: newwin.c,v 1.19 2000/04/17 12:25:46 blymn Exp $");
__RCSID("$NetBSD: newwin.c,v 1.20 2000/04/18 12:23:01 blymn Exp $");
#endif
#endif /* not lint */
@ -53,6 +53,20 @@ static WINDOW *__makenew(int nlines, int ncols, int by, int bx, int sub);
void __set_subwin(WINDOW *orig, WINDOW *win);
/*
* derwin --
* Create a new window in the same manner as subwin but (by, bx)
* are relative to the origin of window orig instead of absolute.
*/
WINDOW *
derwin(WINDOW *orig, int nlines, int ncols, int by, int bx)
{
if (orig == NULL)
return ERR;
return subwin(orig, nlines, ncols, orig->begy + by, orig->begx + bx);
}
/*
* newwin --
* Allocate space for and set up defaults for a new window.

View File

@ -1,4 +1,4 @@
/* $NetBSD: overlay.c,v 1.12 2000/04/15 13:17:04 blymn Exp $ */
/* $NetBSD: overlay.c,v 1.13 2000/04/18 12:23:01 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)overlay.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: overlay.c,v 1.12 2000/04/15 13:17:04 blymn Exp $");
__RCSID("$NetBSD: overlay.c,v 1.13 2000/04/18 12:23:01 blymn Exp $");
#endif
#endif /* not lint */
@ -55,35 +55,9 @@ int
overlay(const WINDOW *win1, WINDOW *win2)
{
int x, y, y1, y2, endy, endx, starty, startx;
__LDATA *sp, *end;
#ifdef DEBUG
__CTRACE("overlay: (%0.2o, %0.2o);\n", win1, win2);
#endif
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);
#ifdef DEBUG
__CTRACE("overlay: from (%d,%d) to (%d,%d)\n",
starty, startx, endy, endx);
#endif
if (starty >= endy || startx >= endx)
return (OK);
y1 = starty - win1->begy;
y2 = starty - win2->begy;
for (y = starty; y < endy; y++, y1++, y2++) {
end = &win1->lines[y1]->line[endx - win1->begx];
x = startx - win2->begx;
for (sp = &win1->lines[y1]->line[startx - win1->begx];
sp < end; sp++) {
if (!isspace(sp->ch)) {
wmove(win2, y2, x);
__waddch(win2, sp);
}
x++;
}
}
return (OK);
return copywin(win1, win2, win1->begy, win1->begx, win2->begy,
win2->begx, win2->maxy, win2->maxx, TRUE);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: overwrite.c,v 1.12 2000/04/15 13:17:04 blymn Exp $ */
/* $NetBSD: overwrite.c,v 1.13 2000/04/18 12:23:01 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)overwrite.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: overwrite.c,v 1.12 2000/04/15 13:17:04 blymn Exp $");
__RCSID("$NetBSD: overwrite.c,v 1.13 2000/04/18 12:23:01 blymn Exp $");
#endif
#endif /* not lint */
@ -55,29 +55,9 @@ __RCSID("$NetBSD: overwrite.c,v 1.12 2000/04/15 13:17:04 blymn Exp $");
int
overwrite(const WINDOW *win1, WINDOW *win2)
{
int x, y, endy, endx, starty, startx;
#ifdef DEBUG
__CTRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2);
#endif
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 (OK);
#ifdef DEBUG
__CTRACE("overwrite: from (%d, %d) to (%d, %d)\n",
starty, startx, endy, endx);
#endif
x = endx - startx;
for (y = starty; y < endy; y++) {
(void) memcpy(
&win2->lines[y - win2->begy]->line[startx - win2->begx],
&win1->lines[y - win1->begy]->line[startx - win1->begx],
(size_t) x * __LDATASIZE);
__touchline(win2, y, (int) (startx - win2->begx), (int) (endx - win2->begx),
0);
}
return (OK);
return copywin(win1, win2, win1->begy, win1->begx, win2->begy,
win2->begx, win2->maxy, win2->maxx, FALSE);
}