From d75ec8181ef0a40405bc71191ad79f3416306694 Mon Sep 17 00:00:00 2001 From: dsl Date: Mon, 17 Feb 2003 11:07:19 +0000 Subject: [PATCH] Fix resize of windows with subwins. Let window size be given as a -ver number => lines from bottom. Fix trace calls of pointers (approved by Brett Lumn) --- lib/libcurses/addbytes.c | 6 +- lib/libcurses/attributes.c | 12 +- lib/libcurses/background.c | 8 +- lib/libcurses/color.c | 6 +- lib/libcurses/curses_private.h | 9 +- lib/libcurses/erase.c | 6 +- lib/libcurses/getch.c | 6 +- lib/libcurses/getstr.c | 6 +- lib/libcurses/insdelln.c | 6 +- lib/libcurses/keypad.c | 6 +- lib/libcurses/newwin.c | 55 ++++----- lib/libcurses/overlay.c | 6 +- lib/libcurses/overwrite.c | 6 +- lib/libcurses/refresh.c | 16 +-- lib/libcurses/resize.c | 196 +++++++++++++++++---------------- lib/libcurses/screen.c | 16 +-- lib/libcurses/scroll.c | 6 +- lib/libcurses/toucholap.c | 6 +- lib/libcurses/touchwin.c | 12 +- 19 files changed, 201 insertions(+), 189 deletions(-) diff --git a/lib/libcurses/addbytes.c b/lib/libcurses/addbytes.c index e15aa3e2831f..3a066cf3a7e8 100644 --- a/lib/libcurses/addbytes.c +++ b/lib/libcurses/addbytes.c @@ -1,4 +1,4 @@ -/* $NetBSD: addbytes.c,v 1.24 2002/12/23 12:26:07 jdc Exp $ */ +/* $NetBSD: addbytes.c,v 1.25 2003/02/17 11:07:19 dsl Exp $ */ /* * Copyright (c) 1987, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: addbytes.c,v 1.24 2002/12/23 12:26:07 jdc Exp $"); +__RCSID("$NetBSD: addbytes.c,v 1.25 2003/02/17 11:07:19 dsl Exp $"); #endif #endif /* not lint */ @@ -135,7 +135,7 @@ __waddbytes(WINDOW *win, const char *bytes, int count, attr_t attr) default: #ifdef DEBUG - __CTRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x); + __CTRACE("ADDBYTES(%p, %d, %d)\n", win, y, x); #endif lp = win->lines[y]; diff --git a/lib/libcurses/attributes.c b/lib/libcurses/attributes.c index 7d2e943280ef..e9bdc0111a35 100644 --- a/lib/libcurses/attributes.c +++ b/lib/libcurses/attributes.c @@ -1,4 +1,4 @@ -/* $NetBSD: attributes.c,v 1.10 2003/01/27 21:04:10 jdc Exp $ */ +/* $NetBSD: attributes.c,v 1.11 2003/02/17 11:07:19 dsl Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #ifndef lint -__RCSID("$NetBSD: attributes.c,v 1.10 2003/01/27 21:04:10 jdc Exp $"); +__RCSID("$NetBSD: attributes.c,v 1.11 2003/02/17 11:07:19 dsl Exp $"); #endif /* not lint */ #include "curses.h" @@ -91,7 +91,7 @@ int wattron(WINDOW *win, int attr) { #ifdef DEBUG - __CTRACE ("wattron: win %0.2o, attr %08x\n", win, attr); + __CTRACE ("wattron: win %p, attr %08x\n", win, attr); #endif /* If can enter modes, set the relevent attribute bits. */ if (__tc_me != NULL) { @@ -133,7 +133,7 @@ int wattroff(WINDOW *win, int attr) { #ifdef DEBUG - __CTRACE ("wattroff: win %0.2o, attr %08x\n", win, attr); + __CTRACE ("wattroff: win %p, attr %08x\n", win, attr); #endif /* If can do exit modes, unset the relevent attribute bits. */ if (__tc_me != NULL) { @@ -170,7 +170,7 @@ int wattrset(WINDOW *win, int attr) { #ifdef DEBUG - __CTRACE ("wattrset: win %0.2o, attr %08x\n", win, attr); + __CTRACE ("wattrset: win %p, attr %08x\n", win, attr); #endif wattron(win, attr); wattroff(win, (~attr & ~__COLOR) | ((attr & __COLOR) ? 0 : __COLOR)); @@ -185,7 +185,7 @@ chtype getattrs(WINDOW *win) { #ifdef DEBUG - __CTRACE ("getattrs: win %0.2o\n", win); + __CTRACE ("getattrs: win %p\n", win); #endif return((chtype) win->wattr); } diff --git a/lib/libcurses/background.c b/lib/libcurses/background.c index 8fd4797d3e9f..f7ad06738473 100644 --- a/lib/libcurses/background.c +++ b/lib/libcurses/background.c @@ -1,4 +1,4 @@ -/* $NetBSD: background.c,v 1.7 2002/08/04 16:43:05 jdc Exp $ */ +/* $NetBSD: background.c,v 1.8 2003/02/17 11:07:19 dsl Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #ifndef lint -__RCSID("$NetBSD: background.c,v 1.7 2002/08/04 16:43:05 jdc Exp $"); +__RCSID("$NetBSD: background.c,v 1.8 2003/02/17 11:07:19 dsl Exp $"); #endif /* not lint */ #include "curses.h" @@ -72,7 +72,7 @@ void wbkgdset(WINDOW *win, chtype ch) { #ifdef DEBUG - __CTRACE("wbkgdset: (%0.2o), '%s', %08x\n", + __CTRACE("wbkgdset: (%p), '%s', %08x\n", win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES); #endif @@ -96,7 +96,7 @@ wbkgd(WINDOW *win, chtype ch) int y, x; #ifdef DEBUG - __CTRACE("wbkgd: (%0.2o), '%s', %08x\n", + __CTRACE("wbkgd: (%p), '%s', %08x\n", win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES); #endif diff --git a/lib/libcurses/color.c b/lib/libcurses/color.c index fb2d81b1f04a..d01e1c7a32ce 100644 --- a/lib/libcurses/color.c +++ b/lib/libcurses/color.c @@ -1,4 +1,4 @@ -/* $NetBSD: color.c,v 1.22 2003/01/27 21:06:16 jdc Exp $ */ +/* $NetBSD: color.c,v 1.23 2003/02/17 11:07:19 dsl Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #ifndef lint -__RCSID("$NetBSD: color.c,v 1.22 2003/01/27 21:06:16 jdc Exp $"); +__RCSID("$NetBSD: color.c,v 1.23 2003/02/17 11:07:19 dsl Exp $"); #endif /* not lint */ #include "curses.h" @@ -546,7 +546,7 @@ __change_pair(short pair) for (wlp = __winlistp; wlp != NULL; wlp = wlp->nextp) { #ifdef DEBUG - __CTRACE("__change_pair: win = %0.2o\n", wlp->winp); + __CTRACE("__change_pair: win = %p\n", wlp->winp); #endif win = wlp->winp; if (win == curscr) { diff --git a/lib/libcurses/curses_private.h b/lib/libcurses/curses_private.h index 84e00a08a1ee..777fa289cb65 100644 --- a/lib/libcurses/curses_private.h +++ b/lib/libcurses/curses_private.h @@ -1,4 +1,4 @@ -/* $NetBSD: curses_private.h,v 1.28 2003/01/27 21:09:20 jdc Exp $ */ +/* $NetBSD: curses_private.h,v 1.29 2003/02/17 11:07:19 dsl Exp $ */ /*- * Copyright (c) 1998-2000 Brett Lymn @@ -99,7 +99,8 @@ struct __window { /* Window structure. */ int begy, begx; /* Window home. */ int cury, curx; /* Current x, y coordinates. */ int maxy, maxx; /* Maximum values for curx, cury. */ - short ch_off; /* x offset for firstch/lastch. */ + int reqy, reqx; /* Size requested when created */ + int ch_off; /* x offset for firstch/lastch. */ __LINE **lines; /* Array of pointers to the lines */ __LINE *lspace; /* line space (for cleanup) */ __LDATA *wspace; /* window space (for cleanup) */ @@ -164,7 +165,7 @@ struct __screen { WINDOW *stdscr; /* Standard screen. */ WINDOW *__virtscr; /* Virtual screen (for doupdate()). */ int curwin; /* current window for refresh */ - short lx, ly; /* loop parameters for refresh */ + int lx, ly; /* loop parameters for refresh */ int COLS; /* Columns on the screen. */ int LINES; /* Lines on the screen. */ int COLORS; /* Maximum colors on the screen */ @@ -254,7 +255,7 @@ extern SCREEN *_cursesi_screen; /* The current screen in use */ /* Private functions. */ #ifdef DEBUG -void __CTRACE(const char *, ...); +void __CTRACE(const char *, ...) __attribute__((__format__(__printf__, 1, 0))); #endif void __cputchar_args(char, void *); void _cursesi_free_keymap(keymap_t *); diff --git a/lib/libcurses/erase.c b/lib/libcurses/erase.c index e92f1b4e18a1..73da3dafa823 100644 --- a/lib/libcurses/erase.c +++ b/lib/libcurses/erase.c @@ -1,4 +1,4 @@ -/* $NetBSD: erase.c,v 1.15 2000/05/20 15:12:15 mycroft Exp $ */ +/* $NetBSD: erase.c,v 1.16 2003/02/17 11:07:19 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)erase.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: erase.c,v 1.15 2000/05/20 15:12:15 mycroft Exp $"); +__RCSID("$NetBSD: erase.c,v 1.16 2003/02/17 11:07:19 dsl Exp $"); #endif #endif /* not lint */ @@ -71,7 +71,7 @@ werase(WINDOW *win) __LDATA *sp, *end, *start, *maxx; #ifdef DEBUG - __CTRACE("werase: (%0.2o)\n", win); + __CTRACE("werase: (%p)\n", win); #endif #ifdef __GNUC__ maxx = NULL; /* XXX gcc -Wuninitialized */ diff --git a/lib/libcurses/getch.c b/lib/libcurses/getch.c index e8c2845eb36d..6e2490fbdbcf 100644 --- a/lib/libcurses/getch.c +++ b/lib/libcurses/getch.c @@ -1,4 +1,4 @@ -/* $NetBSD: getch.c,v 1.38 2002/12/23 12:11:38 jdc Exp $ */ +/* $NetBSD: getch.c,v 1.39 2003/02/17 11:07:20 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: getch.c,v 1.38 2002/12/23 12:11:38 jdc Exp $"); +__RCSID("$NetBSD: getch.c,v 1.39 2003/02/17 11:07:20 dsl Exp $"); #endif #endif /* not lint */ @@ -847,7 +847,7 @@ wgetch(WINDOW *win) if (is_wintouched(win)) wrefresh(win); #ifdef DEBUG - __CTRACE("wgetch: __echoit = %d, __rawmode = %d, flags = %0.2o\n", + __CTRACE("wgetch: __echoit = %d, __rawmode = %d, flags = %#.4x\n", __echoit, __rawmode, win->flags); #endif if (__echoit && !__rawmode) { diff --git a/lib/libcurses/getstr.c b/lib/libcurses/getstr.c index 4c7d471cebbc..f737c88698a1 100644 --- a/lib/libcurses/getstr.c +++ b/lib/libcurses/getstr.c @@ -1,4 +1,4 @@ -/* $NetBSD: getstr.c,v 1.16 2002/01/02 10:38:27 blymn Exp $ */ +/* $NetBSD: getstr.c,v 1.17 2003/02/17 11:07:20 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)getstr.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: getstr.c,v 1.16 2002/01/02 10:38:27 blymn Exp $"); +__RCSID("$NetBSD: getstr.c,v 1.17 2003/02/17 11:07:20 dsl Exp $"); #endif #endif /* not lint */ @@ -176,7 +176,7 @@ __wgetnstr(WINDOW *win, char *str, int n) while ((c = wgetch(win)) != ERR && c != '\n' && c != '\r') { #ifdef DEBUG - __CTRACE("__wgetnstr: win %0.2o, char 0x%x, remain %d\n", win, + __CTRACE("__wgetnstr: win %p, char 0x%x, remain %d\n", win, c, remain); #endif *str = c; diff --git a/lib/libcurses/insdelln.c b/lib/libcurses/insdelln.c index d306b21011f3..ff09b0392587 100644 --- a/lib/libcurses/insdelln.c +++ b/lib/libcurses/insdelln.c @@ -1,4 +1,4 @@ -/* $NetBSD: insdelln.c,v 1.8 2001/04/20 12:56:08 jdc Exp $ */ +/* $NetBSD: insdelln.c,v 1.9 2003/02/17 11:07:20 dsl Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #ifndef lint -__RCSID("$NetBSD: insdelln.c,v 1.8 2001/04/20 12:56:08 jdc Exp $"); +__RCSID("$NetBSD: insdelln.c,v 1.9 2003/02/17 11:07:20 dsl Exp $"); #endif /* not lint */ /* @@ -77,7 +77,7 @@ winsdelln(WINDOW *win, int lines) __LINE *temp; #ifdef DEBUG - __CTRACE("winsdelln: (%0.2o) cury=%d lines=%d\n", win, win->cury, + __CTRACE("winsdelln: (%p) cury=%d lines=%d\n", win, win->cury, lines); #endif diff --git a/lib/libcurses/keypad.c b/lib/libcurses/keypad.c index 6c0f4ce9098c..8f583f9ce0f2 100644 --- a/lib/libcurses/keypad.c +++ b/lib/libcurses/keypad.c @@ -1,4 +1,4 @@ -/* $NetBSD: keypad.c,v 1.8 2001/06/13 10:45:57 wiz Exp $ */ +/* $NetBSD: keypad.c,v 1.9 2003/02/17 11:07:20 dsl Exp $ */ /*- * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com) @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: keypad.c,v 1.8 2001/06/13 10:45:57 wiz Exp $"); +__RCSID("$NetBSD: keypad.c,v 1.9 2003/02/17 11:07:20 dsl Exp $"); #endif /* not lint */ #include "curses.h" @@ -43,7 +43,7 @@ void keypad(WINDOW *win, bool bf) { #ifdef DEBUG - __CTRACE("keypad: win %0.2o, %s\n", win, bf ? "TRUE" : "FALSE"); + __CTRACE("keypad: win %p, %s\n", win, bf ? "TRUE" : "FALSE"); #endif if (bf) { win->flags |= __KEYPAD; diff --git a/lib/libcurses/newwin.c b/lib/libcurses/newwin.c index be4266cd1eaf..f859161ca53f 100644 --- a/lib/libcurses/newwin.c +++ b/lib/libcurses/newwin.c @@ -1,4 +1,4 @@ -/* $NetBSD: newwin.c,v 1.33 2002/12/23 12:17:03 jdc Exp $ */ +/* $NetBSD: newwin.c,v 1.34 2003/02/17 11:07:20 dsl 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.33 2002/12/23 12:17:03 jdc Exp $"); +__RCSID("$NetBSD: newwin.c,v 1.34 2003/02/17 11:07:20 dsl Exp $"); #endif #endif /* not lint */ @@ -93,8 +93,8 @@ dupwin(WINDOW *win) { WINDOW *new_one; - if ((new_one = - newwin(win->maxy, win->maxx, win->begy, win->begx)) == NULL) + if ((new_one = __newwin(_cursesi_screen, win->maxy, win->maxx, + win->begy, win->begx, FALSE)) == NULL) return NULL; overwrite(win, new_one); @@ -129,28 +129,29 @@ __newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad) WINDOW *win; __LINE *lp; int i, j; + int maxy, maxx; __LDATA *sp; - if (nlines == 0) - nlines = LINES - by; - if (ncols == 0) - ncols = COLS - bx; + maxy = nlines > 0 ? nlines : LINES - by + nlines; + maxx = ncols > 0 ? ncols : COLS - bx + ncols; - if ((win = __makenew(screen, nlines, ncols, by, bx, 0, ispad)) == NULL) + if ((win = __makenew(screen, maxy, maxx, by, bx, 0, ispad)) == NULL) return (NULL); win->nextp = win; win->ch_off = 0; win->orig = NULL; + win->reqy = nlines; + win->reqx = ncols; #ifdef DEBUG __CTRACE("newwin: win->ch_off = %d\n", win->ch_off); #endif - for (i = 0; i < nlines; i++) { + for (i = 0; i < maxy; i++) { lp = win->lines[i]; lp->flags = 0; - for (sp = lp->line, j = 0; j < ncols; j++, sp++) { + for (sp = lp->line, j = 0; j < maxx; j++, sp++) { sp->ch = ' '; sp->bch = ' '; sp->attr = 0; @@ -168,11 +169,10 @@ __newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad) WINDOW * subwin(WINDOW *orig, int nlines, int ncols, int by, int bx) { - if (orig == NULL) + if (orig == NULL || orig->orig != NULL) return NULL; - return __subwin(orig, nlines, ncols, orig->begy + by, orig->begx + bx, - TRUE); + return __subwin(orig, nlines, ncols, by, bx, TRUE); } WINDOW * @@ -181,23 +181,24 @@ __subwin(WINDOW *orig, int nlines, int ncols, int by, int bx, int ispad) int i; __LINE *lp; WINDOW *win; + int maxy, maxx; /* Make sure window fits inside the original one. */ #ifdef DEBUG - __CTRACE("subwin: (%0.2o, %d, %d, %d, %d, %d)\n", orig, nlines, ncols, + __CTRACE("subwin: (%p, %d, %d, %d, %d, %d)\n", orig, nlines, ncols, by, bx, ispad); #endif + maxy = nlines > 0 ? nlines : orig->maxy + orig->begy - by + nlines; + maxx = ncols > 0 ? ncols : orig->maxx + orig->begx - bx + ncols; if (by < orig->begy || bx < orig->begx - || by + nlines > orig->maxy + orig->begy - || bx + ncols > orig->maxx + orig->begx) + || by + maxy > orig->maxy + orig->begy + || bx + maxx > orig->maxx + orig->begx) return (NULL); - if (nlines == 0) - nlines = orig->maxy + orig->begy - by; - if (ncols == 0) - ncols = orig->maxx + orig->begx - bx; - if ((win = __makenew(_cursesi_screen, nlines, ncols, + if ((win = __makenew(_cursesi_screen, maxy, maxx, by, bx, 1, ispad)) == NULL) return (NULL); + win->reqy = nlines; + win->reqx = ncols; win->nextp = orig->nextp; orig->nextp = win; win->orig = orig; @@ -253,11 +254,13 @@ __makenew(SCREEN *screen, int nlines, int ncols, int by, int bx, int sub, #ifdef DEBUG __CTRACE("makenew: (%d, %d, %d, %d)\n", nlines, ncols, by, bx); #endif + if (nlines <= 0 || ncols <= 0) + return NULL; + if ((win = malloc(sizeof(WINDOW))) == NULL) return (NULL); #ifdef DEBUG - __CTRACE("makenew: win = %0.2o\n", win); - __CTRACE("makenew: nlines = %d\n", nlines); + __CTRACE("makenew: win = %p\n", win); #endif /* Set up line pointer array and line space. */ @@ -324,6 +327,8 @@ __makenew(SCREEN *screen, int nlines, int ncols, int by, int bx, int sub, win->cury = win->curx = 0; win->maxy = nlines; win->maxx = ncols; + win->reqy = nlines; + win->reqx = ncols; win->begy = by; win->begx = bx; @@ -343,7 +348,7 @@ __makenew(SCREEN *screen, int nlines, int ncols, int by, int bx, int sub, __swflags(win); #ifdef DEBUG __CTRACE("makenew: win->wattr = %08x\n", win->wattr); - __CTRACE("makenew: win->flags = %0.2o\n", win->flags); + __CTRACE("makenew: win->flags = %#.4x\n", win->flags); __CTRACE("makenew: win->maxy = %d\n", win->maxy); __CTRACE("makenew: win->maxx = %d\n", win->maxx); __CTRACE("makenew: win->begy = %d\n", win->begy); diff --git a/lib/libcurses/overlay.c b/lib/libcurses/overlay.c index f1b31e45192e..723746a8b63b 100644 --- a/lib/libcurses/overlay.c +++ b/lib/libcurses/overlay.c @@ -1,4 +1,4 @@ -/* $NetBSD: overlay.c,v 1.13 2000/04/18 12:23:01 blymn Exp $ */ +/* $NetBSD: overlay.c,v 1.14 2003/02/17 11:07:20 dsl 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.13 2000/04/18 12:23:01 blymn Exp $"); +__RCSID("$NetBSD: overlay.c,v 1.14 2003/02/17 11:07:20 dsl Exp $"); #endif #endif /* not lint */ @@ -56,7 +56,7 @@ overlay(const WINDOW *win1, WINDOW *win2) { #ifdef DEBUG - __CTRACE("overlay: (%0.2o, %0.2o);\n", win1, win2); + __CTRACE("overlay: (%p, %p);\n", win1, win2); #endif return copywin(win1, win2, win1->begy, win1->begx, win2->begy, win2->begx, win2->maxy, win2->maxx, TRUE); diff --git a/lib/libcurses/overwrite.c b/lib/libcurses/overwrite.c index 87dc73885327..d2f86fbdfe9f 100644 --- a/lib/libcurses/overwrite.c +++ b/lib/libcurses/overwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: overwrite.c,v 1.14 2000/04/26 12:29:47 blymn Exp $ */ +/* $NetBSD: overwrite.c,v 1.15 2003/02/17 11:07:20 dsl 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.14 2000/04/26 12:29:47 blymn Exp $"); +__RCSID("$NetBSD: overwrite.c,v 1.15 2003/02/17 11:07:20 dsl Exp $"); #endif #endif /* not lint */ @@ -56,7 +56,7 @@ int overwrite(const WINDOW *win1, WINDOW *win2) { #ifdef DEBUG - __CTRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2); + __CTRACE("overwrite: (%p, %p);\n", win1, win2); #endif return copywin(win1, win2, win1->begy, win1->begx, win2->begy, win2->begx, win2->begy + win2->maxy, diff --git a/lib/libcurses/refresh.c b/lib/libcurses/refresh.c index 27ca3ac1d011..9c4b1a71a147 100644 --- a/lib/libcurses/refresh.c +++ b/lib/libcurses/refresh.c @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.c,v 1.52 2003/01/27 21:11:12 jdc Exp $ */ +/* $NetBSD: refresh.c,v 1.53 2003/02/17 11:07:20 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94"; #else -__RCSID("$NetBSD: refresh.c,v 1.52 2003/01/27 21:11:12 jdc Exp $"); +__RCSID("$NetBSD: refresh.c,v 1.53 2003/02/17 11:07:20 dsl Exp $"); #endif #endif /* not lint */ @@ -76,7 +76,7 @@ int wnoutrefresh(WINDOW *win) { #ifdef DEBUG - __CTRACE("wnoutrefresh: win %0.2o\n", win); + __CTRACE("wnoutrefresh: win %p\n", win); #endif return _cursesi_wnoutrefresh(_cursesi_screen, win, 0, 0, win->begy, @@ -94,7 +94,7 @@ pnoutrefresh(WINDOW *pad, int pbegy, int pbegx, int sbegy, int sbegx, int pmaxy, pmaxx; #ifdef DEBUG - __CTRACE("pnoutrefresh: pad %0.2o, flags 0x%08x\n", pad, pad->flags); + __CTRACE("pnoutrefresh: pad %p, flags 0x%08x\n", pad, pad->flags); __CTRACE("pnoutrefresh: (%d, %d), (%d, %d), (%d, %d)\n", pbegy, pbegx, sbegy, sbegx, smaxy, smaxx); #endif @@ -142,7 +142,7 @@ _cursesi_wnoutrefresh(SCREEN *screen, WINDOW *win, int begy, int begx, __LINE *wlp, *vlp; #ifdef DEBUG - __CTRACE("wnoutrefresh: win %0.2o, flags 0x%08x\n", win, win->flags); + __CTRACE("wnoutrefresh: win %p, flags 0x%08x\n", win, win->flags); __CTRACE("wnoutrefresh: (%d, %d), (%d, %d), (%d, %d)\n", begy, begx, wbegy, wbegx, maxy, maxx); #endif @@ -268,7 +268,7 @@ wrefresh(WINDOW *win) int retval; #ifdef DEBUG - __CTRACE("wrefresh: win %0.2o\n", win); + __CTRACE("wrefresh: win %p\n", win); #endif _cursesi_screen->curwin = (win == _cursesi_screen->curscr); @@ -300,7 +300,7 @@ prefresh(WINDOW *pad, int pbegy, int pbegx, int sbegy, int sbegx, int retval; #ifdef DEBUG - __CTRACE("prefresh: pad %0.2o, flags 0x%08x\n", pad, pad->flags); + __CTRACE("prefresh: pad %p, flags 0x%08x\n", pad, pad->flags); #endif /* Use pnoutrefresh() to avoid duplicating code here */ @@ -372,7 +372,7 @@ doupdate(void) werase(curscr); } #ifdef DEBUG - __CTRACE("doupdate: (%0.2o): curwin = %d\n", win, + __CTRACE("doupdate: (%p): curwin = %d\n", win, _cursesi_screen->curwin); __CTRACE("doupdate: \tfirstch\tlastch\n"); #endif diff --git a/lib/libcurses/resize.c b/lib/libcurses/resize.c index 7ded53a7dbc4..3e8bc97db150 100644 --- a/lib/libcurses/resize.c +++ b/lib/libcurses/resize.c @@ -1,4 +1,4 @@ -/* $NetBSD: resize.c,v 1.6 2003/02/10 23:24:27 dsl Exp $ */ +/* $NetBSD: resize.c,v 1.7 2003/02/17 11:07:21 dsl Exp $ */ /* * Copyright (c) 2001 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)resize.c blymn 2001/08/26"; #else -__RCSID("$NetBSD: resize.c,v 1.6 2003/02/10 23:24:27 dsl Exp $"); +__RCSID("$NetBSD: resize.c,v 1.7 2003/02/17 11:07:21 dsl Exp $"); #endif #endif /* not lint */ @@ -58,54 +58,43 @@ static int __resizewin(WINDOW *win, int nlines, int ncols); * Resize the given window to the new size. */ int -wresize(WINDOW *win, int nlines, int ncols) +wresize(WINDOW *win, int req_nlines, int req_ncols) { - __LINE *lp; - int i, j; - __LDATA *sp; + int nlines = req_nlines; + int ncols = req_ncols; - if ((win == NULL) || (nlines < 0) || (ncols < 0)) + if (win == NULL) return ERR; + nlines = req_nlines; + ncols = req_ncols; if (win->orig == NULL) { - if (nlines == 0) - nlines = LINES - win->begy; - if (ncols == 0) - ncols = COLS - win->begx; + /* bound window to screen */ + if (win->begy + nlines > LINES) + nlines = 0; + if (nlines <= 0) + nlines += LINES - win->begy; + if (win->begx + ncols > COLS) + ncols = 0; + if (ncols <= 0) + ncols += COLS - win->begx; } else { - /* subwins must fit inside the parent - check this */ - if ((nlines == 0) - || (nlines > (win->orig->maxy + win->orig->begy - - win->begy))) - nlines = win->orig->maxy + win->orig->begy - win->begy; - - if ((ncols == 0) - || (ncols > (win->orig->maxx + win->orig->begx - - win->begx))) - ncols = win->orig->maxx + win->orig->begx - win->begx; + /* subwins must fit inside the parent - check this */ + if (win->begy + nlines > win->orig->begy + win->orig->maxy) + nlines = 0; + if (nlines <= 0) + nlines += win->orig->begy + win->orig->maxy - win->begy; + if (win->begx + ncols > win->orig->begx + win->orig->maxx) + ncols = 0; + if (ncols <= 0) + ncols += win->orig->begx + win->orig->maxx - win->begx; } if ((__resizewin(win, nlines, ncols)) == ERR) return ERR; - /* - * we must zot the window contents otherwise lines may pick - * up attributes from the previous line when the window is - * made smaller. The client will redraw the window anyway - * so this is no big deal. - */ - for (i = 0; i < win->maxy; i++) { - lp = win->lines[i]; - for (sp = lp->line, j = 0; j < win->maxx; - j++, sp++) { - sp->ch = ' '; - sp->bch = ' '; - sp->attr = 0; - sp->battr = 0; - } - lp->hash = __hash((char *)(void *)lp->line, - (size_t) (ncols * __LDATASIZE)); - } + win->reqy = req_nlines; + win->reqx = req_ncols; return OK; } @@ -119,7 +108,7 @@ resizeterm(int nlines, int ncols) { WINDOW *win; struct __winlist *list; - int newlines, newcols, ldelta, cdelta; + int newlines, newcols; /* don't worry if things have not changed... we would like to do this but some bastard programs update LINES and COLS before @@ -131,40 +120,23 @@ resizeterm(int nlines, int ncols) __CTRACE("resizeterm: (%d, %d)\n", nlines, ncols); #endif - ldelta = nlines - __virtscr->maxy; - cdelta = ncols - __virtscr->maxx; for (list = __winlistp; list != NULL; list = list->nextp) { win = list->winp; - newlines = win->maxy; - newcols = win->maxx; - - if (win->begy >= (nlines - 1)) { - win->begy = nlines - win->maxx - 1; - if (win->begy < 0) - win->begy = 0; - } - - if ((newlines + win->begy + ldelta) == nlines) - newlines = nlines; - - if (newlines > nlines) { + newlines = win->reqy; + if (win->begy + newlines >= nlines) + newlines = 0; + if (newlines == 0) newlines = nlines - win->begy; - if (newlines < 0) - newlines = 1; - } - - if ((newcols + win->begx + cdelta) == ncols) - newcols = ncols; - if (newcols > ncols) { + newcols = win->reqx; + if (win->begx + newcols >= ncols) + newcols = 0; + if (newcols == 0) newcols = ncols - win->begx; - if (newcols < 0) - newcols = 1; - } - - if (wresize(win, newlines, newcols) != OK) + + if (__resizewin(win, newlines, newcols) != OK) return ERR; } @@ -180,7 +152,7 @@ resizeterm(int nlines, int ncols) wrefresh(curscr); return OK; } - + /* * __resizewin -- * Resize the given window. @@ -189,14 +161,16 @@ static int __resizewin(WINDOW *win, int nlines, int ncols) { __LINE *lp, *olp, **newlines, *newlspace; + __LDATA *sp; __LDATA *newwspace; - int i; + int i, j; + int y, x; WINDOW *swin; #ifdef DEBUG - __CTRACE("resize: (%d, %d)\n", nlines, ncols); - __CTRACE("resize: win->wattr = %0.2o\n", win->wattr); - __CTRACE("resize: win->flags = %0.2o\n", win->flags); + __CTRACE("resize: (%p, %d, %d)\n", win, nlines, ncols); + __CTRACE("resize: win->wattr = %08x\n", win->wattr); + __CTRACE("resize: win->flags = %#.4x\n", win->flags); __CTRACE("resize: win->maxy = %d\n", win->maxy); __CTRACE("resize: win->maxx = %d\n", win->maxx); __CTRACE("resize: win->begy = %d\n", win->begy); @@ -205,32 +179,34 @@ __resizewin(WINDOW *win, int nlines, int ncols) __CTRACE("resize: win->scr_b = %d\n", win->scr_b); #endif - /* Reallocate line pointer array and line space. */ - if ((newlines = realloc(win->lines, - nlines * sizeof(__LINE *))) == NULL) { - return ERR; - } - win->lines = newlines; + if (nlines <= 0 || ncols <= 0) + nlines = ncols = 0; + else { + /* Reallocate line pointer array and line space. */ + newlines = realloc(win->lines, nlines * sizeof(__LINE *)); + if (newlines == NULL) + return ERR; + win->lines = newlines; - if ((newlspace = realloc(win->lspace, - nlines * sizeof(__LINE))) == NULL) { - return ERR; + newlspace = realloc(win->lspace, nlines * sizeof(__LINE)); + if (newlspace == NULL) + return ERR; + win->lspace = newlspace; } - win->lspace = newlspace; /* Don't allocate window and line space if it's a subwindow */ if (win->orig == NULL) { /* * Allocate window space in one chunk. */ - if ((newwspace = - realloc(win->wspace, - ncols * nlines * sizeof(__LDATA))) == NULL) { - return ERR; + if (ncols != 0) { + newwspace = realloc(win->wspace, + ncols * nlines * sizeof(__LDATA)); + if (newwspace == NULL) + return ERR; + win->wspace = newwspace; } - win->wspace = newwspace; - /* * Point line pointers to line space, and lines themselves into * window space. @@ -248,7 +224,7 @@ __resizewin(WINDOW *win, int nlines, int ncols) lp->flags = __ISDIRTY; } } else { - + win->ch_off = win->begx - win->orig->begx; /* Point line pointers to line space. */ for (lp = win->lspace, i = 0; i < nlines; i++, lp++) { @@ -261,8 +237,6 @@ __resizewin(WINDOW *win, int nlines, int ncols) #endif lp->firstchp = &olp->firstch; lp->lastchp = &olp->lastch; - lp->hash = __hash((char *)(void *)lp->line, - (size_t) (win->maxx * __LDATASIZE)); lp->flags = __ISDIRTY; } } @@ -274,9 +248,27 @@ __resizewin(WINDOW *win, int nlines, int ncols) win->scr_b = win->maxy - 1; __swflags(win); + /* + * we must zot the window contents otherwise lines may pick + * up attributes from the previous line when the window is + * made smaller. The client will redraw the window anyway + * so this is no big deal. + */ + for (i = 0; i < win->maxy; i++) { + lp = win->lines[i]; + for (sp = lp->line, j = 0; j < win->maxx; j++, sp++) { + sp->ch = ' '; + sp->bch = ' '; + sp->attr = 0; + sp->battr = 0; + } + lp->hash = __hash((char *)(void *)lp->line, + (size_t) (ncols * __LDATASIZE)); + } + #ifdef DEBUG - __CTRACE("resize: win->wattr = %0.2o\n", win->wattr); - __CTRACE("resize: win->flags = %0.2o\n", win->flags); + __CTRACE("resize: win->wattr = %08x\n", win->wattr); + __CTRACE("resize: win->flags = %#.4x\n", win->flags); __CTRACE("resize: win->maxy = %d\n", win->maxy); __CTRACE("resize: win->maxx = %d\n", win->maxx); __CTRACE("resize: win->begy = %d\n", win->begy); @@ -284,10 +276,24 @@ __resizewin(WINDOW *win, int nlines, int ncols) __CTRACE("resize: win->scr_t = %d\n", win->scr_t); __CTRACE("resize: win->scr_b = %d\n", win->scr_b); #endif + if (win->orig == NULL) { - for (swin = win->nextp; swin != win; swin = swin->nextp) - wresize(swin, nlines - swin->begy, ncols - swin->begx); + /* bound subwindows to new size and fixup their pointers */ + for (swin = win->nextp; swin != win; swin = swin->nextp) { + y = swin->reqy; + if (swin->begy + y > win->begy + win->maxy) + y = 0; + if (y <= 0) + y += win->begy + win->maxy - swin->begy; + x = swin->reqx; + if (swin->begx + x > win->begx + win->maxx) + x = 0; + if (x <= 0) + x += win->begy + win->maxx - swin->begx; + __resizewin(swin, y, x); + } } + return OK; } diff --git a/lib/libcurses/screen.c b/lib/libcurses/screen.c index 5a8a3b96aa80..be46289a7a3a 100644 --- a/lib/libcurses/screen.c +++ b/lib/libcurses/screen.c @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.11 2003/02/02 17:52:29 jdc Exp $ */ +/* $NetBSD: screen.c,v 1.12 2003/02/17 11:07:21 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001"; #else -__RCSID("$NetBSD: screen.c,v 1.11 2003/02/02 17:52:29 jdc Exp $"); +__RCSID("$NetBSD: screen.c,v 1.12 2003/02/17 11:07:21 dsl Exp $"); #endif #endif /* not lint */ @@ -151,20 +151,20 @@ newterm(char *type, FILE *outfd, FILE *infd) new_screen->winlistp = NULL; - if ((new_screen->curscr = __newwin(new_screen, new_screen->LINES, - new_screen->COLS, 0, 0, FALSE)) == ERR) + if ((new_screen->curscr = __newwin(new_screen, 0, + 0, 0, 0, FALSE)) == ERR) goto error_exit; - if ((new_screen->stdscr = __newwin(new_screen, new_screen->LINES, - new_screen->COLS, 0, 0, FALSE)) == ERR) { + if ((new_screen->stdscr = __newwin(new_screen, 0, + 0, 0, 0, FALSE)) == ERR) { delwin(new_screen->curscr); goto error_exit; } clearok(new_screen->stdscr, 1); - if ((new_screen->__virtscr = __newwin(new_screen, new_screen->LINES, - new_screen->COLS, 0, 0, FALSE)) == ERR) { + if ((new_screen->__virtscr = __newwin(new_screen, 0, + 0, 0, 0, FALSE)) == ERR) { delwin(new_screen->curscr); delwin(new_screen->stdscr); goto error_exit; diff --git a/lib/libcurses/scroll.c b/lib/libcurses/scroll.c index ba8c3ed13b00..c72daf8b0941 100644 --- a/lib/libcurses/scroll.c +++ b/lib/libcurses/scroll.c @@ -1,4 +1,4 @@ -/* $NetBSD: scroll.c,v 1.16 2001/05/17 19:04:01 jdc Exp $ */ +/* $NetBSD: scroll.c,v 1.17 2003/02/17 11:07:21 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)scroll.c 8.3 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: scroll.c,v 1.16 2001/05/17 19:04:01 jdc Exp $"); +__RCSID("$NetBSD: scroll.c,v 1.17 2003/02/17 11:07:21 dsl Exp $"); #endif #endif /* not lint */ @@ -89,7 +89,7 @@ wscrl(WINDOW *win, int lines) int oy, ox; #ifdef DEBUG - __CTRACE("wscrl: (%0.2o) lines=%d\n", win, lines); + __CTRACE("wscrl: (%p) lines=%d\n", win, lines); #endif if (!(win->flags & __SCROLLOK)) diff --git a/lib/libcurses/toucholap.c b/lib/libcurses/toucholap.c index a83d0f087cf2..800d71d91a1b 100644 --- a/lib/libcurses/toucholap.c +++ b/lib/libcurses/toucholap.c @@ -1,4 +1,4 @@ -/* $NetBSD: toucholap.c,v 1.12 2000/05/20 15:12:15 mycroft Exp $ */ +/* $NetBSD: toucholap.c,v 1.13 2003/02/17 11:07:21 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)toucholap.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: toucholap.c,v 1.12 2000/05/20 15:12:15 mycroft Exp $"); +__RCSID("$NetBSD: toucholap.c,v 1.13 2003/02/17 11:07:21 dsl Exp $"); #endif #endif /* not lint */ @@ -55,7 +55,7 @@ touchoverlap(WINDOW *win1, WINDOW *win2) int y, endy, endx, starty, startx; #ifdef DEBUG - __CTRACE("touchoverlap: (%0.2o, %0.2o);\n", win1, win2); + __CTRACE("touchoverlap: (%p, %p);\n", win1, win2); #endif starty = max(win1->begy, win2->begy); startx = max(win1->begx, win2->begx); diff --git a/lib/libcurses/touchwin.c b/lib/libcurses/touchwin.c index 7de9279071d7..3f3f8bc7b39a 100644 --- a/lib/libcurses/touchwin.c +++ b/lib/libcurses/touchwin.c @@ -1,4 +1,4 @@ -/* $NetBSD: touchwin.c,v 1.17 2002/12/05 17:23:51 jdc Exp $ */ +/* $NetBSD: touchwin.c,v 1.18 2003/02/17 11:07:21 dsl Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)touchwin.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: touchwin.c,v 1.17 2002/12/05 17:23:51 jdc Exp $"); +__RCSID("$NetBSD: touchwin.c,v 1.18 2003/02/17 11:07:21 dsl Exp $"); #endif #endif /* not lint */ @@ -96,7 +96,7 @@ int touchwin(WINDOW *win) { #ifdef DEBUG - __CTRACE("touchwin: (%0.2o)\n", win); + __CTRACE("touchwin: (%p)\n", win); #endif return wtouchln(win, 0, win->maxy, 1); } @@ -123,7 +123,7 @@ wtouchln(WINDOW *win, int line, int n, int changed) __LINE *wlp; #ifdef DEBUG - __CTRACE("wtouchln: (%0.2o) %d, %d, %d\n", win, line, n, changed); + __CTRACE("wtouchln: (%p) %d, %d, %d\n", win, line, n, changed); #endif for (y = line; y < line + n; y++) { if (changed == 1) @@ -150,7 +150,7 @@ __touchwin(WINDOW *win) int y, maxy; #ifdef DEBUG - __CTRACE("touchwin: (%0.2o)\n", win); + __CTRACE("touchwin: (%p)\n", win); #endif maxy = win->maxy; for (y = 0; y < maxy; y++) @@ -162,7 +162,7 @@ int __touchline(WINDOW *win, int y, int sx, int ex) { #ifdef DEBUG - __CTRACE("touchline: (%0.2o, %d, %d, %d)\n", win, y, sx, ex); + __CTRACE("touchline: (%p, %d, %d, %d)\n", win, y, sx, ex); __CTRACE("touchline: first = %d, last = %d\n", *win->lines[y]->firstchp, *win->lines[y]->lastchp); #endif