Source-Changes-HG archive

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

[src/trunk]: src/lib/libcurses curses: fix ripoffline



details:   https://anonhg.NetBSD.org/src/rev/63702c065243
branches:  trunk
changeset: 836195:63702c065243
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Oct 02 17:35:44 2018 +0000

description:
curses: fix ripoffline

When creating stdscr, ensure it's placed and sized in accordance with
lines ripped off.
LINES is no longer adjusted for lines ripped off.
POSIX makes no mention that it should be adjusted.
Bottom lines are now placed correctly.
Lines ripped off are now displayed after calling initscr.

ok kamil@

Fixes PR #53635

diffstat:

 lib/libcurses/curses_private.h |   9 ++++---
 lib/libcurses/curses_screen.3  |   6 +---
 lib/libcurses/fileio.c         |   6 ++--
 lib/libcurses/initscr.c        |   5 ++-
 lib/libcurses/newwin.c         |  24 ++++++++++++------
 lib/libcurses/resize.c         |   8 +++---
 lib/libcurses/ripoffline.c     |  52 ++++++++++++++++++++++++++++-------------
 lib/libcurses/screen.c         |  17 ++++++-------
 lib/libcurses/setterm.c        |   8 +++---
 9 files changed, 80 insertions(+), 55 deletions(-)

diffs (truncated from 444 to 300 lines):

diff -r 98c229ed4a4e -r 63702c065243 lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h    Tue Oct 02 13:53:51 2018 +0000
+++ b/lib/libcurses/curses_private.h    Tue Oct 02 17:35:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_private.h,v 1.63 2018/09/27 14:05:26 roy Exp $  */
+/*     $NetBSD: curses_private.h,v 1.64 2018/10/02 17:35:44 roy Exp $  */
 
 /*-
  * Copyright (c) 1998-2000 Brett Lymn
@@ -368,7 +368,7 @@
 int     __fgetc_resize(FILE *);
 int     __unget(wint_t);
 int     __mvcur(int, int, int, int, int);
-WINDOW  *__newwin(SCREEN *, int, int, int, int, int);
+WINDOW  *__newwin(SCREEN *, int, int, int, int, int, int);
 int     __nodelay(void);
 int     __notimeout(void);
 void    __restartwin(void);
@@ -378,9 +378,10 @@
 void    __restore_termios(void);
 void    __restore_stophandler(void);
 void    __restore_winchhandler(void);
-int     __ripoffscreen(SCREEN *, int *);
+int     __ripoffscreen(SCREEN *);
 void    __ripoffresize(SCREEN *);
-int     __rippedlines(const SCREEN *);
+void    __ripofftouch(SCREEN *);
+int     __rippedlines(const SCREEN *, int);
 void    __save_termios(void);
 void    __set_color(WINDOW *win, attr_t attr);
 void    __set_stophandler(void);
diff -r 98c229ed4a4e -r 63702c065243 lib/libcurses/curses_screen.3
--- a/lib/libcurses/curses_screen.3     Tue Oct 02 13:53:51 2018 +0000
+++ b/lib/libcurses/curses_screen.3     Tue Oct 02 17:35:44 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: curses_screen.3,v 1.24 2018/09/28 08:11:34 kamil Exp $
+.\"    $NetBSD: curses_screen.3,v 1.25 2018/10/02 17:35:44 roy Exp $
 .\"
 .\" Copyright (c) 2002
 .\"    Brett Lymn (blymn%NetBSD.org@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"
-.Dd September 28, 2018
+.Dd October 2, 2018
 .Dt CURSES_SCREEN 3
 .Os
 .Sh NAME
@@ -239,8 +239,6 @@
 .Xr doupdate 3 ,
 but may call
 .Xr wnoutrefresh 3 .
-.Dv LINES
-will be reduced by the total number of lines ripped off.
 .Fn ripoffline
 can be called up to five times.
 .Pp
diff -r 98c229ed4a4e -r 63702c065243 lib/libcurses/fileio.c
--- a/lib/libcurses/fileio.c    Tue Oct 02 13:53:51 2018 +0000
+++ b/lib/libcurses/fileio.c    Tue Oct 02 17:35:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fileio.c,v 1.5 2016/10/22 21:55:06 christos Exp $      */
+/*     $NetBSD: fileio.c,v 1.6 2018/10/02 17:35:44 roy Exp $   */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fileio.c,v 1.5 2016/10/22 21:55:06 christos Exp $");
+__RCSID("$NetBSD: fileio.c,v 1.6 2018/10/02 17:35:44 roy Exp $");
 #endif                         /* not lint */
 
 #include "curses.h"
@@ -195,7 +195,7 @@
        if (fread(wtmp, sizeof(WINDOW), 1, fp) != 1)
                goto error0;
        win = __newwin(_cursesi_screen, wtmp->maxy, wtmp->maxx,
-           wtmp->begy, wtmp->begx, FALSE);
+           wtmp->begy, wtmp->begx, FALSE, FALSE);
        if (win == NULL)
                goto error0;
        win->cury = wtmp->cury;
diff -r 98c229ed4a4e -r 63702c065243 lib/libcurses/initscr.c
--- a/lib/libcurses/initscr.c   Tue Oct 02 13:53:51 2018 +0000
+++ b/lib/libcurses/initscr.c   Tue Oct 02 17:35:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: initscr.c,v 1.32 2017/01/11 17:15:27 roy Exp $ */
+/*     $NetBSD: initscr.c,v 1.33 2018/10/02 17:35:44 roy Exp $ */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)initscr.c  8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: initscr.c,v 1.32 2017/01/11 17:15:27 roy Exp $");
+__RCSID("$NetBSD: initscr.c,v 1.33 2018/10/02 17:35:44 roy Exp $");
 #endif
 #endif /* not lint */
 
@@ -70,6 +70,7 @@
 
        set_term(_cursesi_screen);
        wrefresh(curscr);
+       __ripofftouch(_cursesi_screen);
 
        return stdscr;
 }
diff -r 98c229ed4a4e -r 63702c065243 lib/libcurses/newwin.c
--- a/lib/libcurses/newwin.c    Tue Oct 02 13:53:51 2018 +0000
+++ b/lib/libcurses/newwin.c    Tue Oct 02 17:35:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: newwin.c,v 1.51 2017/09/18 10:18:13 roy Exp $  */
+/*     $NetBSD: newwin.c,v 1.52 2018/10/02 17:35:44 roy Exp $  */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)newwin.c   8.3 (Berkeley) 7/27/94";
 #else
-__RCSID("$NetBSD: newwin.c,v 1.51 2017/09/18 10:18:13 roy Exp $");
+__RCSID("$NetBSD: newwin.c,v 1.52 2018/10/02 17:35:44 roy Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -85,7 +85,8 @@
        WINDOW *new_one;
 
        if ((new_one = __newwin(_cursesi_screen, win->maxy, win->maxx,
-                               win->begy, win->begx, FALSE)) == NULL)
+                               win->begy, win->begx, FALSE,
+                               win == stdscr ? TRUE : FALSE)) == NULL)
                return NULL;
 
        overwrite(win, new_one);
@@ -100,7 +101,7 @@
 newwin(int nlines, int ncols, int by, int bx)
 {
 
-       return __newwin(_cursesi_screen, nlines, ncols, by, bx, FALSE);
+       return __newwin(_cursesi_screen, nlines, ncols, by, bx, FALSE, FALSE);
 }
 
 /*
@@ -113,22 +114,29 @@
 
        if (nlines < 1 || ncols < 1)
                return NULL;
-       return __newwin(_cursesi_screen, nlines, ncols, 0, 0, TRUE);
+       return __newwin(_cursesi_screen, nlines, ncols, 0, 0, TRUE, FALSE);
 }
 
 WINDOW *
-__newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad)
+__newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad,
+    int isstdscr)
 {
        WINDOW *win;
        __LINE *lp;
        int     i, j;
-       int     maxy, maxx;
+       int     ry, maxy, maxx;
        __LDATA *sp;
 
        if (by < 0 || bx < 0)
                return NULL;
 
-       maxy = nlines > 0 ? nlines : LINES - by + nlines;
+       if (isstdscr) {
+               ry = __rippedlines(screen, -1);
+               by += __rippedlines(screen, 1);
+       } else
+               ry = 0;
+
+       maxy = nlines > 0 ? nlines : LINES - by - ry + nlines;
        maxx = ncols > 0 ? ncols : COLS - bx + ncols;
 
        if ((win = __makenew(screen, maxy, maxx, by, bx, 0, ispad)) == NULL)
diff -r 98c229ed4a4e -r 63702c065243 lib/libcurses/resize.c
--- a/lib/libcurses/resize.c    Tue Oct 02 13:53:51 2018 +0000
+++ b/lib/libcurses/resize.c    Tue Oct 02 17:35:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize.c,v 1.27 2018/09/28 15:03:48 roy Exp $  */
+/*     $NetBSD: resize.c,v 1.28 2018/10/02 17:35:44 roy 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.27 2018/09/28 15:03:48 roy Exp $");
+__RCSID("$NetBSD: resize.c,v 1.28 2018/10/02 17:35:44 roy Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -209,13 +209,13 @@
                return ERR;
        if (__resizeterm(__virtscr, nlines, ncols) == ERR)
                return ERR;
-       rlines = nlines - __rippedlines(_cursesi_screen);
+       rlines = nlines - __rippedlines(_cursesi_screen, 0);
        if (__resizeterm(stdscr, rlines, ncols) == ERR)
                return ERR;
 
        _cursesi_screen->LINES = nlines;
        _cursesi_screen->COLS = ncols;
-       LINES = rlines;
+       LINES = nlines;
        COLS = ncols;
 
        if (_cursesi_screen->slk_window != NULL &&
diff -r 98c229ed4a4e -r 63702c065243 lib/libcurses/ripoffline.c
--- a/lib/libcurses/ripoffline.c        Tue Oct 02 13:53:51 2018 +0000
+++ b/lib/libcurses/ripoffline.c        Tue Oct 02 17:35:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ripoffline.c,v 1.3 2017/01/24 17:27:30 roy Exp $       */
+/*     $NetBSD: ripoffline.c,v 1.4 2018/10/02 17:35:44 roy Exp $       */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ripoffline.c,v 1.3 2017/01/24 17:27:30 roy Exp $");
+__RCSID("$NetBSD: ripoffline.c,v 1.4 2018/10/02 17:35:44 roy Exp $");
 #endif                         /* not lint */
 
 #include "curses.h"
@@ -54,7 +54,7 @@
 {
 
 #ifdef DEBUG
-       __CTRACE(__CTRACE_SCREEN, "ripoffline: %d\n", line);
+       __CTRACE(__CTRACE_WINDOW, "ripoffline: %d\n", line);
 #endif
 
        if (nrips >= MAX_RIPS || init == NULL)
@@ -71,16 +71,16 @@
  *     Returns the number of ripped lines from the screen.
  */
 int
-__rippedlines(const SCREEN *screen)
+__rippedlines(const SCREEN *screen, int line)
 {
        const struct __ripoff *rip;
        int i, n;
 
        n = 0;
        for (i = 0, rip = screen->ripped; i < screen->nripped; i++, rip++) {
-               if (rip->nlines < 0)
+               if (line < 1 && rip->nlines < 0)
                        n += -rip->nlines;
-               else
+               else if (line > 0 && rip->nlines > 0)
                        n += rip->nlines;
        }
        return n;
@@ -93,38 +93,40 @@
  *     this implemenation allows for N lines if needed.
  */
 int
-__ripoffscreen(SCREEN *screen, int *rtop)
+__ripoffscreen(SCREEN *screen)
 {
-       int i, nlines;
+       int i, nlines, rbot, rtop;
        const struct ripoff *srip;
        struct __ripoff *rip;
        WINDOW *w;
 
-       *rtop = 0;
        rip = screen->ripped;
+       rbot = LINES;
+       rtop = 0;
        for (i = 0, srip = ripoffs; i < nrips; i++, srip++) {
                if (srip->nlines == 0)
                        continue;
                nlines = srip->nlines < 0 ? -srip->nlines : srip->nlines;
                w = __newwin(screen, nlines, 0,
-                   srip->nlines < 0 ? LINES - nlines : *rtop,
-                   0, FALSE);
+                   srip->nlines < 0 ? rbot - nlines : rtop,
+                   0, FALSE, FALSE);
                if (w != NULL) {
                        rip->win = w;
                        rip->nlines = srip->nlines;
                        rip++;
                        screen->nripped++;
-                       if (rip->nlines > 0)
-                               (*rtop) += rip->nlines;
-                       LINES -= nlines;
+                       if (srip->nlines > 0)
+                               rtop += nlines;
+                       else



Home | Main Index | Thread Index | Old Index