Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses More multiple changes:



details:   https://anonhg.NetBSD.org/src/rev/7cf82a27cdb8
branches:  trunk
changeset: 485071:7cf82a27cdb8
user:      blymn <blymn%NetBSD.org@localhost>
date:      Tue Apr 18 12:23:01 2000 +0000

description:
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.

diffstat:

 lib/libcurses/Makefile    |  16 +++---
 lib/libcurses/copywin.c   |  99 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/libcurses/curses.3    |  12 ++++-
 lib/libcurses/curses.h    |   6 ++-
 lib/libcurses/newwin.c    |  18 +++++++-
 lib/libcurses/overlay.c   |  34 +--------------
 lib/libcurses/overwrite.c |  28 +-----------
 7 files changed, 146 insertions(+), 67 deletions(-)

diffs (truncated from 340 to 300 lines):

diff -r c52c5873b435 -r 7cf82a27cdb8 lib/libcurses/Makefile
--- a/lib/libcurses/Makefile    Tue Apr 18 03:46:41 2000 +0000
+++ b/lib/libcurses/Makefile    Tue Apr 18 12:23:01 2000 +0000
@@ -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 @@
 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
diff -r c52c5873b435 -r 7cf82a27cdb8 lib/libcurses/copywin.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libcurses/copywin.c   Tue Apr 18 12:23:01 2000 +0000
@@ -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@localhost, brett_lymn%yahoo.com.au@localhost)
+ * 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);
+       }
+}
+
diff -r c52c5873b435 -r 7cf82a27cdb8 lib/libcurses/curses.3
--- a/lib/libcurses/curses.3    Tue Apr 18 03:46:41 2000 +0000
+++ b/lib/libcurses/curses.3    Tue Apr 18 12:23:01 2000 +0000
@@ -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 @@
 .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 @@
 .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
diff -r c52c5873b435 -r 7cf82a27cdb8 lib/libcurses/curses.h
--- a/lib/libcurses/curses.h    Tue Apr 18 03:46:41 2000 +0000
+++ b/lib/libcurses/curses.h    Tue Apr 18 12:23:01 2000 +0000
@@ -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     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);
diff -r c52c5873b435 -r 7cf82a27cdb8 lib/libcurses/newwin.c
--- a/lib/libcurses/newwin.c    Tue Apr 18 03:46:41 2000 +0000
+++ b/lib/libcurses/newwin.c    Tue Apr 18 12:23:01 2000 +0000
@@ -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 */
 
@@ -54,6 +54,20 @@
 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.
  */
diff -r c52c5873b435 -r 7cf82a27cdb8 lib/libcurses/overlay.c
--- a/lib/libcurses/overlay.c   Tue Apr 18 03:46:41 2000 +0000
+++ b/lib/libcurses/overlay.c   Tue Apr 18 12:23:01 2000 +0000
@@ -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 @@
 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);
 }
diff -r c52c5873b435 -r 7cf82a27cdb8 lib/libcurses/overwrite.c
--- a/lib/libcurses/overwrite.c Tue Apr 18 03:46:41 2000 +0000
+++ b/lib/libcurses/overwrite.c Tue Apr 18 12:23:01 2000 +0000
@@ -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 @@



Home | Main Index | Thread Index | Old Index