libncurses: Import https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz changes

Change-Id: I3433d30ca01359fd2e3623ede96b531f0b39cbfa
Signed-off-by: micky387 <mickaelsaibi@free.fr>
diff --git a/ncurses/tinfo/lib_raw.c b/ncurses/tinfo/lib_raw.c
index 928692b..fda6dea 100644
--- a/ncurses/tinfo/lib_raw.c
+++ b/ncurses/tinfo/lib_raw.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright 2020-2023,2024 Thomas E. Dickey                                *
+ * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -49,7 +50,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_raw.c,v 1.21 2012/01/21 19:21:29 KO.Myung-Hun Exp $")
+MODULE_ID("$Id: lib_raw.c,v 1.30 2024/03/30 15:54:17 tom Exp $")
 
 #if HAVE_SYS_TERMIO_H
 #include <sys/termio.h>		/* needed for ISC */
@@ -96,6 +97,8 @@
 	buf.c_iflag &= (unsigned) ~(COOKED_INPUT);
 	buf.c_cc[VMIN] = 1;
 	buf.c_cc[VTIME] = 0;
+#elif defined(EXP_WIN32_DRIVER)
+	buf.dwFlagIn &= (unsigned long) ~CONMODE_NORAW;
 #else
 	buf.sg_flags |= RAW;
 #endif
@@ -112,8 +115,10 @@
 	    kbdinfo.fsMask |= KEYBOARD_BINARY_MODE;
 	    KbdSetStatus(&kbdinfo, 0);
 #endif
-	    SP_PARM->_raw = TRUE;
-	    SP_PARM->_cbreak = 1;
+	    if (SP_PARM) {
+		IsRaw(SP_PARM) = TRUE;
+		IsCbreak(SP_PARM) = 1;
+	    }
 	    termp->Nttyb = buf;
 	}
 	AFTER("raw");
@@ -146,15 +151,19 @@
 #ifdef TERMIOS
 	buf.c_lflag &= (unsigned) ~ICANON;
 	buf.c_iflag &= (unsigned) ~ICRNL;
-	buf.c_lflag |= ISIG;
 	buf.c_cc[VMIN] = 1;
 	buf.c_cc[VTIME] = 0;
+#elif defined(EXP_WIN32_DRIVER)
+	buf.dwFlagIn |= CONMODE_NORAW;
+	buf.dwFlagIn &= (unsigned long) ~CONMODE_NOCBREAK;
 #else
 	buf.sg_flags |= CBREAK;
 #endif
 	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 	if (result == OK) {
-	    SP_PARM->_cbreak = 1;
+	    if (SP_PARM) {
+		IsCbreak(SP_PARM) = 1;
+	    }
 	    termp->Nttyb = buf;
 	}
 	AFTER("cbreak");
@@ -177,12 +186,12 @@
 NCURSES_EXPORT(void)
 NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
 {
-    int result = ERR;
     TERMINAL *termp;
 
     T((T_CALLED("qiflush(%p)"), (void *) SP_PARM));
     if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
+	int result;
 
 	BEFORE("qiflush");
 	buf = termp->Nttyb;
@@ -190,6 +199,7 @@
 	buf.c_lflag &= (unsigned) ~(NOFLSH);
 	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
+	result = ERR;
 	/* FIXME */
 #endif
 	if (result == OK)
@@ -225,6 +235,8 @@
 	buf.c_lflag |= ISIG | ICANON |
 	    (termp->Ottyb.c_lflag & IEXTEN);
 	buf.c_iflag |= COOKED_INPUT;
+#elif defined(EXP_WIN32_DRIVER)
+	buf.dwFlagIn |= CONMODE_NORAW;
 #else
 	buf.sg_flags &= ~(RAW | CBREAK);
 #endif
@@ -241,8 +253,10 @@
 	    kbdinfo.fsMask |= KEYBOARD_ASCII_MODE;
 	    KbdSetStatus(&kbdinfo, 0);
 #endif
-	    SP_PARM->_raw = FALSE;
-	    SP_PARM->_cbreak = 0;
+	    if (SP_PARM) {
+		IsRaw(SP_PARM) = FALSE;
+		IsCbreak(SP_PARM) = 0;
+	    }
 	    termp->Nttyb = buf;
 	}
 	AFTER("noraw");
@@ -275,12 +289,16 @@
 #ifdef TERMIOS
 	buf.c_lflag |= ICANON;
 	buf.c_iflag |= ICRNL;
+#elif defined(EXP_WIN32_DRIVER)
+	buf.dwFlagIn |= (CONMODE_NOCBREAK | CONMODE_NORAW);
 #else
 	buf.sg_flags &= ~CBREAK;
 #endif
 	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 	if (result == OK) {
-	    SP_PARM->_cbreak = 0;
+	    if (SP_PARM) {
+		IsCbreak(SP_PARM) = 0;
+	    }
 	    termp->Nttyb = buf;
 	}
 	AFTER("nocbreak");
@@ -299,12 +317,12 @@
 NCURSES_EXPORT(void)
 NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
 {
-    int result = ERR;
     TERMINAL *termp;
 
     T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM));
     if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
+	int result;
 
 	BEFORE("noqiflush");
 	buf = termp->Nttyb;
@@ -313,6 +331,7 @@
 	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
 	/* FIXME */
+	result = ERR;
 #endif
 	if (result == OK)
 	    termp->Nttyb = buf;
@@ -375,3 +394,46 @@
     return NCURSES_SP_NAME(intrflush) (CURRENT_SCREEN, win, flag);
 }
 #endif
+
+#if NCURSES_EXT_FUNCS
+/* *INDENT-OFF* */
+
+/*
+ * SCREEN is always opaque, but nl/raw/cbreak/echo set properties in it.
+ * As an extension, provide a way to query the properties.
+ *
+ * There are other properties which could be queried, e.g., filter, keypad,
+ * use_env, use_meta, but these particular properties are saved/restored within
+ * the wgetnstr() and wgetn_wstr() functions, which requires that the higher
+ * level curses library knows about the internal state of the lower level
+ * terminfo library.
+ */
+
+#define is_TEST(show,what) \
+    NCURSES_EXPORT(int) \
+    NCURSES_SP_NAME(show) (NCURSES_SP_DCL0) \
+    { \
+	return ((SP_PARM != NULL) ? (what(SP_PARM) ? 1 : 0) : -1); \
+    }
+
+is_TEST(is_nl, IsNl)
+is_TEST(is_raw, IsRaw)
+is_TEST(is_cbreak, IsCbreak)
+is_TEST(is_echo, IsEcho)
+
+#if NCURSES_SP_FUNCS
+#undef is_TEST
+#define is_TEST(show) \
+    NCURSES_EXPORT(int) \
+    show(void) \
+    { \
+	return NCURSES_SP_NAME(show) (CURRENT_SCREEN); \
+    }
+is_TEST(is_nl)
+is_TEST(is_raw)
+is_TEST(is_cbreak)
+is_TEST(is_echo)
+#endif
+
+/* *INDENT-ON* */
+#endif /* extensions */