Source-Changes-HG archive

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

[src/netbsd-8]: src/lib/libcurses Pull up following revision(s) (requested by...



details:   https://anonhg.NetBSD.org/src/rev/e53023803947
branches:  netbsd-8
changeset: 435281:e53023803947
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Sep 27 15:12:15 2018 +0000

description:
Pull up following revision(s) (requested by roy in ticket #1042):
        lib/libcurses/getch.c: revision 1.68
        lib/libcurses/getch.c: revision 1.69
        lib/libcurses/get_wch.c: revision 1.17
        lib/libcurses/get_wch.c: revision 1.18
        lib/libcurses/curses_private.h: revision 1.63
curses: unify resize handling in getch
Instead of testing each fgetc call for resize event, add the wrapper
__fgetc_resize to simplify the logic.
While here, ensure that get_wch uses the correct input stream which
may or may not be stdin.
curses: call resizeterm if getch issues KEY_RESIZE
This fixes PR #53633.

diffstat:

 lib/libcurses/curses_private.h |   3 +-
 lib/libcurses/get_wch.c        |  68 +++++++++++++++++++++++++----------------
 lib/libcurses/getch.c          |  64 +++++++++++++++++++++-----------------
 3 files changed, 79 insertions(+), 56 deletions(-)

diffs (274 lines):

diff -r 64a96407066a -r e53023803947 lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h    Thu Sep 27 15:07:34 2018 +0000
+++ b/lib/libcurses/curses_private.h    Thu Sep 27 15:12:15 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_private.h,v 1.62 2017/01/31 09:17:53 roy Exp $  */
+/*     $NetBSD: curses_private.h,v 1.62.4.1 2018/09/27 15:12:15 martin Exp $   */
 
 /*-
  * Copyright (c) 1998-2000 Brett Lymn
@@ -365,6 +365,7 @@
 void   __cursesi_putnsp(nschar_t *, const int, const int);
 void   __cursesi_chtype_to_cchar(chtype, cchar_t *);
 #endif /* HAVE_WCHAR */
+int     __fgetc_resize(FILE *);
 int     __unget(wint_t);
 int     __mvcur(int, int, int, int, int);
 WINDOW  *__newwin(SCREEN *, int, int, int, int, int);
diff -r 64a96407066a -r e53023803947 lib/libcurses/get_wch.c
--- a/lib/libcurses/get_wch.c   Thu Sep 27 15:07:34 2018 +0000
+++ b/lib/libcurses/get_wch.c   Thu Sep 27 15:12:15 2018 +0000
@@ -1,4 +1,4 @@
-/*   $NetBSD: get_wch.c,v 1.14.4.1 2018/09/27 14:59:28 martin Exp $ */
+/*   $NetBSD: get_wch.c,v 1.14.4.2 2018/09/27 15:12:15 martin Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: get_wch.c,v 1.14.4.1 2018/09/27 14:59:28 martin Exp $");
+__RCSID("$NetBSD: get_wch.c,v 1.14.4.2 2018/09/27 15:12:15 martin Exp $");
 #endif                                           /* not lint */
 
 #include <errno.h>
@@ -56,6 +56,7 @@
 /* prototypes for private functions */
 #ifdef HAVE_WCHAR
 static int inkey(wchar_t *wc, int to, int delay);
+static wint_t __fgetwc_resize(FILE *infd, bool *resized);
 #endif /* HAVE_WCHAR */
 
 #ifdef HAVE_WCHAR
@@ -100,14 +101,10 @@
                if (wstate == INKEY_NORM) {
                        if (delay && __timeout(delay) == ERR)
                                return ERR;
-                       c = fgetc(infd);
-                       if (c == WEOF) {
+                       c = __fgetc_resize(infd);
+                       if (c == ERR || c == KEY_RESIZE) {
                                clearerr(infd);
-                               if (errno == EINTR && _cursesi_screen->resized) {
-                                       _cursesi_screen->resized = 0;
-                                       return KEY_RESIZE;
-                               } else
-                                       return ERR;
+                               return c;
                        }
 
                        if (delay && (__notimeout() == ERR))
@@ -152,14 +149,10 @@
                                        return ERR;
                        }
 
-                       c = fgetc(infd);
+                       c = __fgetc_resize(infd);
                        if (ferror(infd)) {
                                clearerr(infd);
-                               if (errno == EINTR && _cursesi_screen->resized) {
-                                       _cursesi_screen->resized = 0;
-                                       return KEY_RESIZE;
-                               } else
-                                       return ERR;
+                               return c;
                        }
 
                        if ((to || delay) && (__notimeout() == ERR))
@@ -206,10 +199,10 @@
                                        return ERR;
                        }
 
-                       c = fgetc(infd);
+                       c = __fgetc_resize(infd);
                        if (ferror(infd)) {
                                clearerr(infd);
-                               return ERR;
+                               return c;
                        }
 
                        if ((to || delay) && (__notimeout() == ERR))
@@ -538,6 +531,7 @@
 #endif
        if (_cursesi_screen->resized) {
                _cursesi_screen->resized = 0;
+               resizeterm(LINES, COLS);
                *ch = KEY_RESIZE;
                return KEY_CODE_YES;
        }
@@ -583,6 +577,8 @@
                if ( ret == ERR )
                        return ERR;
        } else {
+               bool resized;
+
                switch (win->delay) {
                        case -1:
                                break;
@@ -596,17 +592,11 @@
                                break;
                }
 
-               c = getwchar();
-               if (feof(infd)) {
+               c = __fgetwc_resize(infd, &resized);
+               if (c == WEOF) {
                        clearerr(infd);
                        __restore_termios();
-                       return ERR;     /* we have timed out */
-               }
-
-               if (ferror(infd)) {
-                       clearerr(infd);
-                       if (errno == EINTR && _cursesi_screen->resized) {
-                               _cursesi_screen->resized = 0;
+                       if (resized) {
                                *ch = KEY_RESIZE;
                                return KEY_CODE_YES;
                        } else
@@ -674,3 +664,29 @@
 {
        return __unget((wint_t)c);
 }
+
+#ifdef HAVE_WCHAR
+/*
+ * __fgetwc_resize --
+ *    Any call to fgetwc(3) should use this function instead.
+ */
+static wint_t
+__fgetwc_resize(FILE *infd, bool *resized)
+{
+       wint_t c;
+
+       c = fgetwc(infd);
+       if (c != WEOF)
+               return c;
+
+       if (!ferror(infd) || errno != EINTR || !_cursesi_screen->resized)
+               return ERR;
+#ifdef DEBUG
+       __CTRACE(__CTRACE_INPUT, "__fgetwc_resize returning KEY_RESIZE\n");
+#endif
+       _cursesi_screen->resized = 0;
+       resizeterm(LINES, COLS);
+       *resized = true;
+       return c;
+}
+#endif
diff -r 64a96407066a -r e53023803947 lib/libcurses/getch.c
--- a/lib/libcurses/getch.c     Thu Sep 27 15:07:34 2018 +0000
+++ b/lib/libcurses/getch.c     Thu Sep 27 15:12:15 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getch.c,v 1.65.4.1 2018/09/27 14:59:28 martin Exp $    */
+/*     $NetBSD: getch.c,v 1.65.4.2 2018/09/27 15:12:15 martin Exp $    */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getch.c    8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: getch.c,v 1.65.4.1 2018/09/27 14:59:28 martin Exp $");
+__RCSID("$NetBSD: getch.c,v 1.65.4.2 2018/09/27 15:12:15 martin Exp $");
 #endif
 #endif                                 /* not lint */
 
@@ -560,14 +560,10 @@
                if (state == INKEY_NORM) {
                        if (delay && __timeout(delay) == ERR)
                                return ERR;
-                       c = fgetc(infd);
-                       if (c == EOF) {
+                       c = __fgetc_resize(infd);
+                       if (c == ERR || c == KEY_RESIZE) {
                                clearerr(infd);
-                               if (errno == EINTR && _cursesi_screen->resized) {
-                                       _cursesi_screen->resized = 0;
-                                       return KEY_RESIZE;
-                               } else
-                                       return ERR;
+                               return c;
                        }
 
                        if (delay && (__notimeout() == ERR))
@@ -606,14 +602,10 @@
                                        return ERR;
                        }
 
-                       c = fgetc(infd);
+                       c = __fgetc_resize(infd);
                        if (ferror(infd)) {
                                clearerr(infd);
-                               if (errno == EINTR && _cursesi_screen->resized) {
-                                       _cursesi_screen->resized = 0;
-                                       return KEY_RESIZE;
-                               } else
-                                       return ERR;
+                               return c;
                        }
 
                        if ((to || delay) && (__notimeout() == ERR))
@@ -833,6 +825,7 @@
 #endif
        if (_cursesi_screen->resized) {
                _cursesi_screen->resized = 0;
+               resizeterm(LINES, COLS);
 #ifdef DEBUG
                __CTRACE(__CTRACE_INPUT, "wgetch returning KEY_RESIZE\n");
 #endif
@@ -889,22 +882,11 @@
                        break;
                }
 
-               c = fgetc(infd);
-               if (feof(infd)) {
+               inp = __fgetc_resize(infd);
+               if (inp == ERR || inp == KEY_RESIZE) {
                        clearerr(infd);
                        __restore_termios();
-                       return ERR;     /* we have timed out */
-               }
-
-               if (ferror(infd)) {
-                       clearerr(infd);
-                       if (errno == EINTR && _cursesi_screen->resized) {
-                               _cursesi_screen->resized = 0;
-                               inp = KEY_RESIZE;
-                       } else
-                               inp = ERR;
-               } else {
-                       inp = c;
+                       return inp;
                }
        }
 #ifdef DEBUG
@@ -1011,3 +993,27 @@
        ESCDELAY = escdelay;
        return OK;
 }
+
+/*
+ * __fgetc_resize --
+ *    Any call to fgetc(3) should use this function instead
+ *    and test for the return value of KEY_RESIZE as well as ERR.
+ */
+int
+__fgetc_resize(FILE *infd)
+{
+       int c;
+
+       c = fgetc(infd);
+       if (c != EOF)
+               return c;
+
+       if (!ferror(infd) || errno != EINTR || !_cursesi_screen->resized)
+               return ERR;
+#ifdef DEBUG
+       __CTRACE(__CTRACE_INPUT, "__fgetc_resize returning KEY_RESIZE\n");
+#endif
+       _cursesi_screen->resized = 0;
+       resizeterm(LINES, COLS);
+       return KEY_RESIZE;
+}



Home | Main Index | Thread Index | Old Index