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/widechar/charable.c b/ncurses/widechar/charable.c
index 91ceb32..55d4890 100644
--- a/ncurses/widechar/charable.c
+++ b/ncurses/widechar/charable.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2003-2005,2008 Free Software Foundation, Inc.              *
+ * Copyright 2018,2020 Thomas E. Dickey                                     *
+ * Copyright 2003-2005,2008 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            *
@@ -32,7 +33,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: charable.c,v 1.5 2008/07/05 20:51:41 tom Exp $")
+MODULE_ID("$Id: charable.c,v 1.8 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch)
 {
@@ -57,6 +58,8 @@
 	result = UChar(temp[0]);
     else
 	result = -1;
+#else
+#error expected either wctob/wctomb
 #endif
     return result;
 }
@@ -75,6 +78,8 @@
 	result = convert;
     else
 	result = WEOF;
+#else
+#error expected either btowc/mbtowc
 #endif
     return result;
 }
diff --git a/ncurses/widechar/lib_add_wch.c b/ncurses/widechar/lib_add_wch.c
index 38d3130..be1bbb0 100644
--- a/ncurses/widechar/lib_add_wch.c
+++ b/ncurses/widechar/lib_add_wch.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2004-2010,2011 Free Software Foundation, Inc.              *
+ * Copyright 2019-2021,2023 Thomas E. Dickey                                *
+ * Copyright 2004-2011,2016 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            *
@@ -39,7 +40,7 @@
 #include <wctype.h>
 #endif
 
-MODULE_ID("$Id: lib_add_wch.c,v 1.12 2011/03/22 09:31:15 Petr.Pavlu Exp $")
+MODULE_ID("$Id: lib_add_wch.c,v 1.18 2023/07/15 17:34:12 tom Exp $")
 
 /* clone/adapt lib_addch.c */
 static const cchar_t blankchar = NewChar(BLANK_TEXT);
@@ -55,7 +56,7 @@
  */
 
 /* Return bit mask for clearing color pair number if given ch has color */
-#define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0))
+#define COLOR_MASK(ch) (~(attr_t)(((ch) & A_COLOR) ? A_COLOR : 0))
 
 static NCURSES_INLINE cchar_t
 render_char(WINDOW *win, cchar_t ch)
@@ -114,7 +115,7 @@
 #endif
 
 static bool
-newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T * ypos)
+newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T *ypos)
 {
     bool result = FALSE;
 
@@ -132,7 +133,7 @@
  * wrapped the cursor.  We don't do anything with this flag except set it when
  * wrapping, and clear it whenever we move the cursor.  If we try to wrap at
  * the lower-right corner of a window, we cannot move the cursor (since that
- * wouldn't be legal).  So we return an error (which is what SVr4 does). 
+ * wouldn't be legal).  So we return an error (which is what SVr4 does).
  * Unlike SVr4, we can successfully add a character to the lower-right corner
  * (Solaris 2.6 does this also, however).
  */
@@ -195,7 +196,7 @@
      * adjustments.
      */
     {
-	int len = wcwidth(CharOf(ch));
+	int len = _nc_wacs_width(CharOf(ch));
 	int i;
 	int j;
 	wchar_t *chars;
@@ -203,10 +204,16 @@
 	if (len == 0) {		/* non-spacing */
 	    if ((x > 0 && y >= 0)
 		|| (win->_maxx >= 0 && win->_cury >= 1)) {
-		if (x > 0 && y >= 0)
-		    chars = (win->_line[y].text[x - 1].chars);
-		else
+		if (x > 0 && y >= 0) {
+		    for (j = x - 1; j > 0; --j) {
+			if (!isWidecExt(win->_line[y].text[j])) {
+			    break;
+			}
+		    }
+		    chars = (win->_line[y].text[j].chars);
+		} else {
 		    chars = (win->_line[y - 1].text[win->_maxx].chars);
+		}
 		for (i = 0; i < CCHARW_MAX; ++i) {
 		    if (chars[i] == 0) {
 			TR(TRACE_VIRTPUT,
diff --git a/ncurses/widechar/lib_box_set.c b/ncurses/widechar/lib_box_set.c
index f9e701f..ef2e1a7 100644
--- a/ncurses/widechar/lib_box_set.c
+++ b/ncurses/widechar/lib_box_set.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2009,2011 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2002-2009,2011 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            *
@@ -39,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_box_set.c,v 1.6 2011/06/25 19:02:07 Vassili.Courzakis Exp $")
+MODULE_ID("$Id: lib_box_set.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 wborder_set(WINDOW *win,
diff --git a/ncurses/widechar/lib_cchar.c b/ncurses/widechar/lib_cchar.c
index 654bebb..451c5dc 100644
--- a/ncurses/widechar/lib_cchar.c
+++ b/ncurses/widechar/lib_cchar.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2001-2012,2014 Free Software Foundation, Inc.              *
+ * Copyright 2019-2021,2022 Thomas E. Dickey                                *
+ * Copyright 2001-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            *
@@ -34,10 +35,11 @@
 */
 
 #include <curses.priv.h>
+#include <wchar.h>
 
-MODULE_ID("$Id: lib_cchar.c,v 1.27 2014/02/01 22:10:42 tom Exp $")
+MODULE_ID("$Id: lib_cchar.c,v 1.38 2022/07/27 08:03:16 tom Exp $")
 
-/* 
+/*
  * The SuSv2 description leaves some room for interpretation.  We'll assume wch
  * points to a string which is L'\0' terminated, contains at least one
  * character with strictly positive width, which must be the first, and
@@ -47,22 +49,25 @@
 setcchar(cchar_t *wcval,
 	 const wchar_t *wch,
 	 const attr_t attrs,
-	 NCURSES_PAIRS_T color_pair,
+	 NCURSES_PAIRS_T pair_arg,
 	 const void *opts)
 {
-    unsigned i;
-    unsigned len;
     int code = OK;
+    int color_pair = pair_arg;
+    unsigned len;
 
-    TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"),
+    TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,attrs=%lu,pair=%d,%p)"),
 		      (void *) wcval, _nc_viswbuf(wch),
-		      (unsigned long) attrs, (int) color_pair, opts));
+		      (unsigned long) attrs, color_pair, opts));
 
-    if (opts != NULL
-	|| wch == NULL
-	|| ((len = (unsigned) wcslen(wch)) > 1 && wcwidth(wch[0]) < 0)) {
+    set_extended_pair(opts, color_pair);
+    if (wch == NULL
+	|| ((len = (unsigned) wcslen(wch)) > 1 && _nc_wacs_width(wch[0]) < 0)
+	|| color_pair < 0) {
 	code = ERR;
     } else {
+	unsigned i;
+
 	if (len > CCHARW_MAX)
 	    len = CCHARW_MAX;
 
@@ -71,7 +76,7 @@
 	 * are only interested in adding non-spacing characters.
 	 */
 	for (i = 1; i < len; ++i) {
-	    if (wcwidth(wch[i]) != 0) {
+	    if (_nc_wacs_width(wch[i]) != 0) {
 		len = i;
 		break;
 	    }
@@ -96,39 +101,55 @@
 getcchar(const cchar_t *wcval,
 	 wchar_t *wch,
 	 attr_t *attrs,
-	 NCURSES_PAIRS_T *color_pair,
+	 NCURSES_PAIRS_T *pair_arg,
 	 void *opts)
 {
-    wchar_t *wp;
-    int len;
     int code = ERR;
 
     TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
 		      (const void *) wcval,
 		      (void *) wch,
 		      (void *) attrs,
-		      (void *) color_pair,
+		      (void *) pair_arg,
 		      opts));
 
-    if (opts == NULL && wcval != NULL) {
+#if !NCURSES_EXT_COLORS
+    if (opts != NULL) {
+	;			/* empty */
+    } else
+#endif
+    if (wcval != NULL) {
+	wchar_t *wp;
+	int len;
+
+#if HAVE_WMEMCHR
 	len = ((wp = wmemchr(wcval->chars, L'\0', (size_t) CCHARW_MAX))
 	       ? (int) (wp - wcval->chars)
 	       : CCHARW_MAX);
-
+#else
+	len = wcsnlen(wcval->chars, CCHARW_MAX);
+#endif
 	if (wch == NULL) {
 	    /*
 	     * If the value is a null, set the length to 1.
 	     * If the value is not a null, return the length plus 1 for null.
 	     */
 	    code = (len < CCHARW_MAX) ? (len + 1) : CCHARW_MAX;
-	} else if (attrs == 0 || color_pair == 0) {
+	} else if (attrs == 0 || pair_arg == 0) {
 	    code = ERR;
 	} else if (len >= 0) {
+	    int color_pair;
+
+	    TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
+			      _tracecchar_t(wcval)));
 	    *attrs = AttrOf(*wcval) & A_ATTRIBUTES;
-	    *color_pair = (NCURSES_PAIRS_T) GetPair(*wcval);
+	    color_pair = GetPair(*wcval);
+	    get_extended_pair(opts, color_pair);
+	    *pair_arg = limit_PAIRS(color_pair);
 	    wmemcpy(wch, wcval->chars, (size_t) len);
 	    wch[len] = L'\0';
-	    code = OK;
+	    if (*pair_arg >= 0)
+		code = OK;
 	}
     }
 
diff --git a/ncurses/widechar/lib_erasewchar.c b/ncurses/widechar/lib_erasewchar.c
index ddce27a..197f80b 100644
--- a/ncurses/widechar/lib_erasewchar.c
+++ b/ncurses/widechar/lib_erasewchar.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2010,2014 Free Software Foundation, Inc.              *
+ * Copyright 2020,2021 Thomas E. Dickey                                     *
+ * Copyright 2002-2010,2014 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            *
@@ -32,46 +33,64 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_erasewchar.c,v 1.3 2014/02/23 01:21:08 tom Exp $")
+MODULE_ID("$Id: lib_erasewchar.c,v 1.5 2021/05/22 23:51:14 tom Exp $")
 
 /*
  *	erasewchar()
  *
  *	Return erase character as given in cur_term->Ottyb.
- *
  */
 
 NCURSES_EXPORT(int)
-erasewchar(wchar_t *wch)
+NCURSES_SP_NAME(erasewchar) (NCURSES_SP_DCLx wchar_t *wch);
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(erasewchar) (NCURSES_SP_DCLx wchar_t *wch)
 {
     int value;
     int result = ERR;
 
     T((T_CALLED("erasewchar()")));
-    if ((value = erasechar()) != ERR) {
+    if ((value = NCURSES_SP_NAME(erasechar) (NCURSES_SP_ARG)) != ERR) {
 	*wch = (wchar_t) value;
 	result = OK;
     }
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+erasewchar(wchar_t *wch)
+{
+    return NCURSES_SP_NAME(erasewchar) (CURRENT_SCREEN, wch);
+}
+#endif
+
 /*
  *	killwchar()
  *
  *	Return kill character as given in cur_term->Ottyb.
- *
  */
 
 NCURSES_EXPORT(int)
-killwchar(wchar_t *wch)
+NCURSES_SP_NAME(killwchar) (NCURSES_SP_DCLx wchar_t *wch);
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(killwchar) (NCURSES_SP_DCLx wchar_t *wch)
 {
     int value;
     int result = ERR;
 
     T((T_CALLED("killwchar()")));
-    if ((value = killchar()) != ERR) {
+    if ((value = NCURSES_SP_NAME(killchar) (NCURSES_SP_ARG)) != ERR) {
 	*wch = (wchar_t) value;
 	result = OK;
     }
     returnCode(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+killwchar(wchar_t *wch)
+{
+    return NCURSES_SP_NAME(killwchar) (CURRENT_SCREEN, wch);
+}
+#endif
diff --git a/ncurses/widechar/lib_get_wch.c b/ncurses/widechar/lib_get_wch.c
index 71d5603..9f10d3b 100644
--- a/ncurses/widechar/lib_get_wch.c
+++ b/ncurses/widechar/lib_get_wch.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2010,2011 Free Software Foundation, Inc.              *
+ * Copyright 2020,2021 Thomas E. Dickey                                     *
+ * Copyright 2002-2011,2016 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            *
@@ -40,18 +41,14 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_get_wch.c,v 1.23 2011/05/28 23:00:29 tom Exp $")
+MODULE_ID("$Id: lib_get_wch.c,v 1.26 2021/04/17 16:12:54 tom Exp $")
 
 NCURSES_EXPORT(int)
 wget_wch(WINDOW *win, wint_t *result)
 {
     SCREEN *sp;
     int code;
-    char buffer[(MB_LEN_MAX * 9) + 1];	/* allow some redundant shifts */
-    int status;
-    size_t count = 0;
     int value = 0;
-    wchar_t wch;
 #ifndef state_unused
     mbstate_t state;
 #endif
@@ -64,8 +61,13 @@
      */
     _nc_lock_global(curses);
     sp = _nc_screen_of(win);
+
     if (sp != 0) {
+	size_t count = 0;
+
 	for (;;) {
+	    char buffer[(MB_LEN_MAX * 9) + 1];	/* allow some redundant shifts */
+
 	    T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer)));
 	    code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist
 							       *) 0));
@@ -89,10 +91,13 @@
 		code = ERR;
 		break;
 	    } else {
+		int status;
+
 		buffer[count++] = (char) UChar(value);
 		reset_mbytes(state);
 		status = count_mbytes(buffer, count, state);
 		if (status >= 0) {
+		    wchar_t wch;
 		    reset_mbytes(state);
 		    if (check_mbytes(wch, buffer, count, state) != status) {
 			code = ERR;	/* the two calls should match */
diff --git a/ncurses/widechar/lib_get_wstr.c b/ncurses/widechar/lib_get_wstr.c
index 27cdae0..3b3bd52 100644
--- a/ncurses/widechar/lib_get_wstr.c
+++ b/ncurses/widechar/lib_get_wstr.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2009,2011 Free Software Foundation, Inc.              *
+ * Copyright 2018-2021,2023 Thomas E. Dickey                                *
+ * Copyright 2002-2009,2011 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            *
@@ -39,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_get_wstr.c,v 1.13 2011/10/22 16:31:35 tom Exp $")
+MODULE_ID("$Id: lib_get_wstr.c,v 1.21 2023/04/29 19:02:03 tom Exp $")
 
 static int
 wadd_wint(WINDOW *win, wint_t *src)
@@ -87,9 +88,9 @@
 {
     SCREEN *sp = _nc_screen_of(win);
     TTY buf;
-    bool oldnl, oldecho, oldraw, oldcbreak;
-    wint_t erasec;
-    wint_t killc;
+    TTY_FLAGS save_flags;
+    wchar_t erasec = 0;
+    wchar_t killc = 0;
     wint_t *oldstr = str;
     wint_t *tmpstr = str;
     wint_t ch;
@@ -100,19 +101,18 @@
     if (!win)
 	returnCode(ERR);
 
+    maxlen = _nc_getstr_limit(maxlen);
+
     _nc_get_tty_mode(&buf);
 
-    oldnl = sp->_nl;
-    oldecho = sp->_echo;
-    oldraw = sp->_raw;
-    oldcbreak = sp->_cbreak;
-    nl();
-    noecho();
-    noraw();
-    cbreak();
+    save_flags = sp->_tty_flags;
+    NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
+    NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
+    if (!save_flags._raw)
+	NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
 
-    erasec = (wint_t) erasechar();
-    killc = (wint_t) killchar();
+    NCURSES_SP_NAME(erasewchar) (NCURSES_SP_ARGx &erasec);
+    NCURSES_SP_NAME(killwchar) (NCURSES_SP_ARGx &killc);
 
     getyx(win, y, x);
 
@@ -129,12 +129,12 @@
 	    code = KEY_CODE_YES;
 	    ch = KEY_ENTER;
 	}
-	if (ch < KEY_MIN) {
-	    if (ch == erasec) {
+	if (ch != 0 && ch < KEY_MIN) {
+	    if (ch == (wint_t) erasec) {
 		ch = KEY_BACKSPACE;
 		code = KEY_CODE_YES;
 	    }
-	    if (ch == killc) {
+	    if (ch == (wint_t) killc) {
 		ch = KEY_EOL;
 		code = KEY_CODE_YES;
 	    }
@@ -142,12 +142,12 @@
 	if (code == KEY_CODE_YES) {
 	    /*
 	     * Some terminals (the Wyse-50 is the most common) generate a \n
-	     * from the down-arrow key.  With this logic, it's the user's
+	     * from the down-arrow key.  With this logic, it is the user's
 	     * choice whether to set kcud=\n for wget_wch(); terminating
 	     * *getn_wstr() with \n should work either way.
 	     */
 	    if (ch == KEY_DOWN || ch == KEY_ENTER) {
-		if (oldecho == TRUE
+		if (save_flags._echo == TRUE
 		    && win->_cury == win->_maxy
 		    && win->_scroll)
 		    wechochar(win, (chtype) '\n');
@@ -155,21 +155,21 @@
 	    }
 	    if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
 		if (tmpstr > oldstr) {
-		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, save_flags._echo);
 		}
 	    } else if (ch == KEY_EOL) {
 		while (tmpstr > oldstr) {
-		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, save_flags._echo);
 		}
 	    } else {
 		beep();
 	    }
-	} else if (maxlen >= 0 && tmpstr - oldstr >= maxlen) {
+	} else if (tmpstr - oldstr >= maxlen) {
 	    beep();
 	} else {
 	    *tmpstr++ = ch;
 	    *tmpstr = 0;
-	    if (oldecho == TRUE) {
+	    if (save_flags._echo == TRUE) {
 		int oldy = win->_cury;
 
 		if (wadd_wint(win, tmpstr - 1) == ERR) {
@@ -179,9 +179,9 @@
 		     */
 		    win->_flags &= ~_WRAPPED;
 		    waddch(win, (chtype) ' ');
-		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, save_flags._echo);
 		    continue;
-		} else if (win->_flags & _WRAPPED) {
+		} else if (IS_WRAPPED(win)) {
 		    /*
 		     * If the last waddch forced a wrap & scroll, adjust our
 		     * reference point for erasures.
@@ -209,11 +209,7 @@
     /* Restore with a single I/O call, to fix minor asymmetry between
      * raw/noraw, etc.
      */
-    sp->_nl = oldnl;
-    sp->_echo = oldecho;
-    sp->_raw = oldraw;
-    sp->_cbreak = oldcbreak;
-
+    sp->_tty_flags = save_flags;
     (void) _nc_set_tty_mode(&buf);
 
     *tmpstr = 0;
diff --git a/ncurses/widechar/lib_hline_set.c b/ncurses/widechar/lib_hline_set.c
index da92b83..8d5e026 100644
--- a/ncurses/widechar/lib_hline_set.c
+++ b/ncurses/widechar/lib_hline_set.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2002-2010,2016 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            *
@@ -39,23 +40,21 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_hline_set.c,v 1.4 2010/12/19 01:45:03 tom Exp $")
+MODULE_ID("$Id: lib_hline_set.c,v 1.6 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 whline_set(WINDOW *win, const cchar_t *ch, int n)
 {
     int code = ERR;
-    int start;
-    int end;
 
     T((T_CALLED("whline_set(%p,%s,%d)"), (void *) win, _tracecchar_t(ch), n));
 
     if (win) {
 	struct ldat *line = &(win->_line[win->_cury]);
 	NCURSES_CH_T wch;
+	int start = win->_curx;
+	int end = start + n - 1;
 
-	start = win->_curx;
-	end = start + n - 1;
 	if (end > win->_maxx)
 	    end = win->_maxx;
 
diff --git a/ncurses/widechar/lib_in_wch.c b/ncurses/widechar/lib_in_wch.c
index b239650..1d27332 100644
--- a/ncurses/widechar/lib_in_wch.c
+++ b/ncurses/widechar/lib_in_wch.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2006,2009 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2002-2009,2016 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            *
@@ -39,17 +40,19 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_in_wch.c,v 1.5 2009/10/24 22:37:55 tom Exp $")
+MODULE_ID("$Id: lib_in_wch.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 win_wch(WINDOW *win, cchar_t *wcval)
 {
-    int row, col;
     int code = OK;
 
     TR(TRACE_CCALLS, (T_CALLED("win_wch(%p,%p)"), (void *) win, (void *) wcval));
+
     if (win != 0
 	&& wcval != 0) {
+	int row, col;
+
 	getyx(win, row, col);
 
 	*wcval = win->_line[row].text[col];
diff --git a/ncurses/widechar/lib_in_wchnstr.c b/ncurses/widechar/lib_in_wchnstr.c
index 57cc2ca..40a2bb6 100644
--- a/ncurses/widechar/lib_in_wchnstr.c
+++ b/ncurses/widechar/lib_in_wchnstr.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2007,2009 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2002-2007,2009 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            *
@@ -39,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_in_wchnstr.c,v 1.8 2009/10/24 22:37:48 tom Exp $")
+MODULE_ID("$Id: lib_in_wchnstr.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 win_wchnstr(WINDOW *win, cchar_t *wchstr, int n)
diff --git a/ncurses/widechar/lib_ins_wch.c b/ncurses/widechar/lib_ins_wch.c
index 2aa71a5..ecaabcc 100644
--- a/ncurses/widechar/lib_ins_wch.c
+++ b/ncurses/widechar/lib_ins_wch.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2010,2011 Free Software Foundation, Inc.              *
+ * Copyright 2019-2020,2023 Thomas E. Dickey                                *
+ * Copyright 2002-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            *
@@ -39,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_ins_wch.c,v 1.17 2011/10/22 16:34:50 tom Exp $")
+MODULE_ID("$Id: lib_ins_wch.c,v 1.29 2023/11/21 21:53:28 tom Exp $")
 
 /*
  * Insert the given character, updating the current location to simplify
@@ -48,8 +49,7 @@
 NCURSES_EXPORT(int)
 _nc_insert_wch(WINDOW *win, const cchar_t *wch)
 {
-    int cells = wcwidth(CharOf(CHDEREF(wch)));
-    int cell;
+    int cells = _nc_wacs_width(CharOf(CHDEREF(wch)));
     int code = OK;
 
     if (cells < 0) {
@@ -59,6 +59,7 @@
 	    cells = 1;
 
 	if (win->_curx <= win->_maxx) {
+	    int cell;
 	    struct ldat *line = &(win->_line[win->_cury]);
 	    NCURSES_CH_T *end = &(line->text[win->_curx]);
 	    NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
@@ -73,7 +74,7 @@
 		SetWidecExt(temp1[cell], cell);
 	    }
 
-	    win->_curx++;
+	    win->_curx = (NCURSES_SIZE_T) (win->_curx + cells);
 	}
     }
     return code;
@@ -82,15 +83,13 @@
 NCURSES_EXPORT(int)
 wins_wch(WINDOW *win, const cchar_t *wch)
 {
-    NCURSES_SIZE_T oy;
-    NCURSES_SIZE_T ox;
     int code = ERR;
 
     T((T_CALLED("wins_wch(%p, %s)"), (void *) win, _tracecchar_t(wch)));
 
     if (win != 0) {
-	oy = win->_cury;
-	ox = win->_curx;
+	NCURSES_SIZE_T oy = win->_cury;
+	NCURSES_SIZE_T ox = win->_curx;
 
 	code = _nc_insert_wch(win, wch);
 
@@ -105,25 +104,27 @@
 wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
 {
     int code = ERR;
-    NCURSES_SIZE_T oy;
-    NCURSES_SIZE_T ox;
-    const wchar_t *cp;
 
     T((T_CALLED("wins_nwstr(%p,%s,%d)"),
        (void *) win, _nc_viswbufn(wstr, n), n));
 
     if (win != 0
-	&& wstr != 0) {
-	if (n < 1)
-	    n = (int) wcslen(wstr);
-	code = OK;
-	if (n > 0) {
-	    SCREEN *sp = _nc_screen_of(win);
+	&& wstr != 0
+	&& n != 0) {
 
-	    oy = win->_cury;
-	    ox = win->_curx;
-	    for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
-		int len = wcwidth(*cp);
+	if (n < 0) {
+	    n = INT_MAX;
+	}
+	code = OK;
+
+	if (n > 0) {
+	    const wchar_t *cp;
+	    SCREEN *sp = _nc_screen_of(win);
+	    NCURSES_SIZE_T oy = win->_cury;
+	    NCURSES_SIZE_T ox = win->_curx;
+
+	    for (cp = wstr; ((cp - wstr) < n) && (*cp != L'\0'); cp++) {
+		int len = _nc_wacs_width(*cp);
 
 		if ((len >= 0 && len != 1) || !is7bits(*cp)) {
 		    cchar_t tmp_cchar;
diff --git a/ncurses/widechar/lib_inwstr.c b/ncurses/widechar/lib_inwstr.c
index a4f5b8e..b2fdaea 100644
--- a/ncurses/widechar/lib_inwstr.c
+++ b/ncurses/widechar/lib_inwstr.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2009,2011 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2002-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            *
@@ -39,31 +40,39 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_inwstr.c,v 1.6 2011/05/28 22:49:49 tom Exp $")
+MODULE_ID("$Id: lib_inwstr.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 winnwstr(WINDOW *win, wchar_t *wstr, int n)
 {
-    int row, col, inx;
     int count = 0;
-    int last = 0;
     cchar_t *text;
-    wchar_t wch;
 
     T((T_CALLED("winnwstr(%p,%p,%d)"), (void *) win, (void *) wstr, n));
     if (wstr != 0) {
 	if (win) {
+	    int row, col;
+	    int last = 0;
+	    bool done = FALSE;
+
 	    getyx(win, row, col);
 
 	    text = win->_line[row].text;
-	    while (count < n && count != ERR) {
+	    while (count < n && !done && count != ERR) {
+
 		if (!isWidecExt(text[col])) {
+		    int inx;
+		    wchar_t wch;
+
 		    for (inx = 0; (inx < CCHARW_MAX)
 			 && ((wch = text[col].chars[inx]) != 0);
 			 ++inx) {
 			if (count + 1 > n) {
-			    if ((count = last) == 0) {
+			    done = TRUE;
+			    if (last == 0) {
 				count = ERR;	/* error if we store nothing */
+			    } else {
+				count = last;	/* only store complete chars */
 			    }
 			    break;
 			}
diff --git a/ncurses/widechar/lib_key_name.c b/ncurses/widechar/lib_key_name.c
index da65f21..379bdc2 100644
--- a/ncurses/widechar/lib_key_name.c
+++ b/ncurses/widechar/lib_key_name.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2007 Free Software Foundation, Inc.                        *
+ * Copyright 2020,2023 Thomas E. Dickey                                     *
+ * Copyright 2007-2008,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            *
@@ -35,7 +36,9 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_key_name.c,v 1.3 2008/10/11 20:15:14 tom Exp $")
+MODULE_ID("$Id: lib_key_name.c,v 1.6 2023/06/03 12:15:34 tom Exp $")
+
+#define MyData _nc_globals.key_name
 
 NCURSES_EXPORT(NCURSES_CONST char *)
 key_name(wchar_t c)
@@ -43,20 +46,22 @@
     cchar_t my_cchar;
     wchar_t *my_wchars;
     size_t len;
-
-    /* FIXME: move to _nc_globals */
-    static char result[MB_LEN_MAX + 1];
+    NCURSES_CONST char *result = NULL;
 
     memset(&my_cchar, 0, sizeof(my_cchar));
     my_cchar.chars[0] = c;
     my_cchar.chars[1] = L'\0';
 
     my_wchars = wunctrl(&my_cchar);
-    len = wcstombs(result, my_wchars, sizeof(result) - 1);
-    if (isEILSEQ(len) || (len == 0)) {
-	return 0;
+    /*
+     * wunctrl() could return a wide character rather than just a "printable"
+     * representation.  Check for that and return a corresponding multibyte
+     * character string.
+     */
+    len = wcstombs(MyData, my_wchars, sizeof(MyData) - 1);
+    if (!isEILSEQ(len) && (len != 0) && (len <= MB_LEN_MAX)) {
+	MyData[len] = '\0';
+	result = MyData;
     }
-
-    result[len] = '\0';
     return result;
 }
diff --git a/ncurses/widechar/lib_pecho_wchar.c b/ncurses/widechar/lib_pecho_wchar.c
index b6da7a8..502967f 100644
--- a/ncurses/widechar/lib_pecho_wchar.c
+++ b/ncurses/widechar/lib_pecho_wchar.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2004,2009 Free Software Foundation, Inc.                   *
+ * Copyright 2020,2021 Thomas E. Dickey                                     *
+ * Copyright 2004,2009 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            *
@@ -32,7 +33,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_pecho_wchar.c,v 1.2 2009/10/24 22:43:32 tom Exp $")
+MODULE_ID("$Id: lib_pecho_wchar.c,v 1.4 2021/10/23 17:07:56 tom Exp $")
 
 NCURSES_EXPORT(int)
 pecho_wchar(WINDOW *pad, const cchar_t *wch)
@@ -42,7 +43,7 @@
     if (pad == 0)
 	returnCode(ERR);
 
-    if (!(pad->_flags & _ISPAD))
+    if (!IS_PAD(pad))
 	returnCode(wecho_wchar(pad, wch));
 
     wadd_wch(pad, wch);
diff --git a/ncurses/widechar/lib_slk_wset.c b/ncurses/widechar/lib_slk_wset.c
index 8927556..5aa75ff 100644
--- a/ncurses/widechar/lib_slk_wset.c
+++ b/ncurses/widechar/lib_slk_wset.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2003-2002,2011 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2003-2011,2016 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            *
@@ -40,23 +41,26 @@
 #include <wctype.h>
 #endif
 
-MODULE_ID("$Id: lib_slk_wset.c,v 1.13 2011/10/22 15:52:20 tom Exp $")
+MODULE_ID("$Id: lib_slk_wset.c,v 1.15 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 slk_wset(int i, const wchar_t *astr, int format)
 {
     int result = ERR;
-    size_t arglen;
     const wchar_t *str;
-    char *mystr;
     mbstate_t state;
 
     T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format));
 
     if (astr != 0) {
+	size_t arglen;
+
 	init_mb(state);
 	str = astr;
+
 	if ((arglen = wcsrtombs(NULL, &str, (size_t) 0, &state)) != (size_t) -1) {
+	    char *mystr;
+
 	    if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) {
 		str = astr;
 		if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) {
diff --git a/ncurses/widechar/lib_unget_wch.c b/ncurses/widechar/lib_unget_wch.c
index d5ae608..1a81fec 100644
--- a/ncurses/widechar/lib_unget_wch.c
+++ b/ncurses/widechar/lib_unget_wch.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2010,2011 Free Software Foundation, Inc.              *
+ * Copyright 2020,2023 Thomas E. Dickey                                     *
+ * Copyright 2002-2011,2016 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            *
@@ -39,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_unget_wch.c,v 1.15 2011/10/22 16:34:50 tom Exp $")
+MODULE_ID("$Id: lib_unget_wch.c,v 1.18 2023/06/03 12:50:52 tom Exp $")
 
 /*
  * Wrapper for wcrtomb() which obtains the length needed for the given
@@ -59,7 +60,7 @@
     } else {
 	result = (int) wcrtomb(target, source, state);
     }
-    if (!isEILSEQ(result) && (result == 0))
+    if (!isEILSEQ(result) && ((result == 0) || (result > MB_LEN_MAX)))
 	result = 1;
     return (size_t) result;
 }
@@ -70,7 +71,6 @@
     int result = OK;
     mbstate_t state;
     size_t length;
-    int n;
 
     T((T_CALLED("unget_wch(%p, %#lx)"), (void *) SP_PARM, (unsigned long) wch));
 
@@ -82,6 +82,8 @@
 	char *string;
 
 	if ((string = (char *) malloc(length)) != 0) {
+	    int n;
+
 	    init_mb(state);
 	    /* ignore the result, since we already validated the character */
 	    IGNORE_RC((int) wcrtomb(string, wch, &state));
diff --git a/ncurses/widechar/lib_vid_attr.c b/ncurses/widechar/lib_vid_attr.c
index 80c1ea4..f108b30 100644
--- a/ncurses/widechar/lib_vid_attr.c
+++ b/ncurses/widechar/lib_vid_attr.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2013,2014 Free Software Foundation, Inc.              *
+ * Copyright 2018-2020,2023 Thomas E. Dickey                                *
+ * Copyright 2002-2014,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            *
@@ -36,27 +37,34 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_vid_attr.c,v 1.23 2014/06/07 22:13:46 tom Exp $")
+MODULE_ID("$Id: lib_vid_attr.c,v 1.31 2023/04/28 20:59:34 tom Exp $")
 
 #define doPut(mode) \
 	TPUTS_TRACE(#mode); \
 	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc)
 
 #define TurnOn(mask, mode) \
-	if ((turn_on & mask) && mode) { doPut(mode); }
+	if ((turn_on & mask) && mode) { \
+	    TPUTS_TRACE(#mode); \
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc); \
+	}
 
 #define TurnOff(mask, mode) \
-	if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; }
+	if ((turn_off & mask) && mode) { \
+	    TPUTS_TRACE(#mode); \
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc); \
+	    turn_off &= ~mask; \
+	}
 
 	/* if there is no current screen, assume we *can* do color */
 #define SetColorsIf(why, old_attr, old_pair) \
 	if (can_color && (why)) { \
-		TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, pair)); \
-		if ((pair != old_pair) \
-		 || (fix_pair0 && (pair == 0)) \
+		TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, color_pair)); \
+		if ((color_pair != old_pair) \
+		 || (fix_pair0 && (color_pair == 0)) \
 		 || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \
 		    NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx \
-						   old_pair, pair, \
+						   old_pair, color_pair, \
 						   reverse, outc); \
 		} \
 	}
@@ -68,10 +76,11 @@
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(vid_puts) (NCURSES_SP_DCLx
 			   attr_t newmode,
-			   NCURSES_PAIRS_T pair,
-			   void *opts GCC_UNUSED,
+			   NCURSES_PAIRS_T pair_arg,
+			   void *opts OPTIONAL_PAIR,
 			   NCURSES_SP_OUTC outc)
 {
+    int color_pair = pair_arg;
 #if NCURSES_EXT_COLORS
     static attr_t previous_attr = A_NORMAL;
     static int previous_pair = 0;
@@ -85,8 +94,12 @@
 #define fix_pair0 FALSE
 #endif
 
+    if (!IsValidTIScreen(SP_PARM))
+	returnCode(ERR);
+
     newmode &= A_ATTRIBUTES;
-    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair));
+    set_extended_pair(opts, color_pair);
+    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), color_pair));
 
     /* this allows us to go on whether or not newterm() has been called */
     if (SP_PARM) {
@@ -107,7 +120,7 @@
      * If we have a terminal that cannot combine color with video
      * attributes, use the colors in preference.
      */
-    if ((pair != 0
+    if ((color_pair != 0
 	 || fix_pair0)
 	&& (no_color_video > 0)) {
 	/*
@@ -136,7 +149,7 @@
     }
 
     if (newmode == previous_attr
-	&& pair == previous_pair)
+	&& color_pair == previous_pair)
 	returnCode(OK);
 
     if (reverse) {
@@ -146,7 +159,7 @@
     turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR;
     turn_on = (newmode & ~(previous_attr & TPARM_ATTR)) & ALL_BUT_COLOR;
 
-    SetColorsIf(((pair == 0) && !fix_pair0), previous_attr, previous_pair);
+    SetColorsIf(((color_pair == 0) && !fix_pair0), previous_attr, previous_pair);
 
     if (newmode == A_NORMAL) {
 	if ((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) {
@@ -168,26 +181,27 @@
 		    TurnOff(A_ITALIC, exit_italics_mode);
 		}
 #endif
+		(void) turn_off;
 	    }
 	    previous_attr &= ALL_BUT_COLOR;
 	    previous_pair = 0;
 	}
 
-	SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+	SetColorsIf((color_pair != 0) || fix_pair0, previous_attr, previous_pair);
     } else if (set_attributes) {
 	if (turn_on || turn_off) {
 	    TPUTS_TRACE("set_attributes");
 	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
-				    TPARM_9(set_attributes,
-					    (newmode & A_STANDOUT) != 0,
-					    (newmode & A_UNDERLINE) != 0,
-					    (newmode & A_REVERSE) != 0,
-					    (newmode & A_BLINK) != 0,
-					    (newmode & A_DIM) != 0,
-					    (newmode & A_BOLD) != 0,
-					    (newmode & A_INVIS) != 0,
-					    (newmode & A_PROTECT) != 0,
-					    (newmode & A_ALTCHARSET) != 0),
+				    TIPARM_9(set_attributes,
+					       (newmode & A_STANDOUT) != 0,
+					       (newmode & A_UNDERLINE) != 0,
+					       (newmode & A_REVERSE) != 0,
+					       (newmode & A_BLINK) != 0,
+					       (newmode & A_DIM) != 0,
+					       (newmode & A_BOLD) != 0,
+					       (newmode & A_INVIS) != 0,
+					       (newmode & A_PROTECT) != 0,
+					       (newmode & A_ALTCHARSET) != 0),
 				    1, outc);
 	    previous_attr &= ALL_BUT_COLOR;
 	    previous_pair = 0;
@@ -199,9 +213,10 @@
 	    } else if (turn_off & A_ITALIC) {
 		TurnOff(A_ITALIC, exit_italics_mode);
 	    }
+	    (void) turn_off;
 	}
 #endif
-	SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+	SetColorsIf((color_pair != 0) || fix_pair0, previous_attr, previous_pair);
     } else {
 
 	TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off)));
@@ -226,7 +241,7 @@
 	    previous_attr &= ALL_BUT_COLOR;
 	    previous_pair = 0;
 	}
-	SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+	SetColorsIf((color_pair != 0) || fix_pair0, previous_attr, previous_pair);
 
 	TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on)));
 	/* *INDENT-OFF* */
@@ -242,7 +257,7 @@
 #if USE_ITALIC
 	TurnOn(A_ITALIC,	enter_italics_mode);
 #endif
-#if USE_WIDEC_SUPPORT
+#if USE_WIDEC_SUPPORT && defined(enter_horizontal_hl_mode)
 	TurnOn(A_HORIZONTAL,	enter_horizontal_hl_mode);
 	TurnOn(A_LEFT,		enter_left_hl_mode);
 	TurnOn(A_LOW,		enter_low_hl_mode);
@@ -251,7 +266,6 @@
 	TurnOn(A_VERTICAL,	enter_vertical_hl_mode);
 #endif
 	/* *INDENT-ON* */
-
     }
 
     if (reverse)
@@ -259,16 +273,17 @@
 
     if (SP_PARM) {
 	SetAttr(SCREEN_ATTRS(SP_PARM), newmode);
-	SetPair(SCREEN_ATTRS(SP_PARM), pair);
+	SetPair(SCREEN_ATTRS(SP_PARM), color_pair);
     } else {
 	previous_attr = newmode;
-	previous_pair = pair;
+	previous_pair = color_pair;
     }
 
     returnCode(OK);
 #else
-    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), (int) pair));
-    set_color(newmode, pair);
+    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), color_pair));
+    (void) opts;
+    set_color(newmode, color_pair);
     returnCode(NCURSES_SP_NAME(vidputs) (NCURSES_SP_ARGx newmode, outc));
 #endif
 }
@@ -276,14 +291,14 @@
 #if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 vid_puts(attr_t newmode,
-	 NCURSES_PAIRS_T pair,
+	 NCURSES_PAIRS_T pair_arg,
 	 void *opts GCC_UNUSED,
 	 NCURSES_OUTC outc)
 {
     SetSafeOutcWrapper(outc);
     return NCURSES_SP_NAME(vid_puts) (CURRENT_SCREEN,
 				      newmode,
-				      pair,
+				      pair_arg,
 				      opts,
 				      _nc_outc_wrapper);
 }
@@ -293,22 +308,22 @@
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(vid_attr) (NCURSES_SP_DCLx
 			   attr_t newmode,
-			   NCURSES_PAIRS_T pair,
+			   NCURSES_PAIRS_T pair_arg,
 			   void *opts)
 {
-    T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), (int) pair));
+    T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), (int) pair_arg));
     returnCode(NCURSES_SP_NAME(vid_puts) (NCURSES_SP_ARGx
 					  newmode,
-					  pair,
+					  pair_arg,
 					  opts,
 					  NCURSES_SP_NAME(_nc_putchar)));
 }
 
 #if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-vid_attr(attr_t newmode, NCURSES_PAIRS_T pair, void *opts)
+vid_attr(attr_t newmode, NCURSES_PAIRS_T pair_arg, void *opts)
 {
-    return NCURSES_SP_NAME(vid_attr) (CURRENT_SCREEN, newmode, pair, opts);
+    return NCURSES_SP_NAME(vid_attr) (CURRENT_SCREEN, newmode, pair_arg, opts);
 }
 #endif
 
@@ -325,6 +340,7 @@
     if (SP_PARM) {
 	attrs = NCURSES_SP_NAME(termattrs) (NCURSES_SP_ARG);
 
+#if USE_WIDEC_SUPPORT && defined(enter_horizontal_hl_mode)
 	/* these are only supported for wide-character mode */
 	if (enter_horizontal_hl_mode)
 	    attrs |= WA_HORIZONTAL;
@@ -338,6 +354,7 @@
 	    attrs |= WA_TOP;
 	if (enter_vertical_hl_mode)
 	    attrs |= WA_VERTICAL;
+#endif
     }
 
     returnAttr(attrs);
diff --git a/ncurses/widechar/lib_vline_set.c b/ncurses/widechar/lib_vline_set.c
index 917caac..f7bb581 100644
--- a/ncurses/widechar/lib_vline_set.c
+++ b/ncurses/widechar/lib_vline_set.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2002-2010,2016 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            *
@@ -39,22 +40,21 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_vline_set.c,v 1.4 2010/12/19 01:50:50 tom Exp $")
+MODULE_ID("$Id: lib_vline_set.c,v 1.6 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(int)
 wvline_set(WINDOW *win, const cchar_t *ch, int n)
 {
     int code = ERR;
-    int row, col;
-    int end;
 
     T((T_CALLED("wvline(%p,%s,%d)"), (void *) win, _tracecchar_t(ch), n));
 
     if (win) {
 	NCURSES_CH_T wch;
-	row = win->_cury;
-	col = win->_curx;
-	end = row + n - 1;
+	int row = win->_cury;
+	int col = win->_curx;
+	int end = row + n - 1;
+
 	if (end > win->_maxy)
 	    end = win->_maxy;
 
diff --git a/ncurses/widechar/lib_wacs.c b/ncurses/widechar/lib_wacs.c
index dc3af21..5b6f6da 100644
--- a/ncurses/widechar/lib_wacs.c
+++ b/ncurses/widechar/lib_wacs.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2002-2013,2014 Free Software Foundation, Inc.              *
+ * Copyright 2018,2020 Thomas E. Dickey                                     *
+ * Copyright 2002-2015,2016 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            *
@@ -32,7 +33,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_wacs.c,v 1.14 2014/02/23 01:21:08 tom Exp $")
+MODULE_ID("$Id: lib_wacs.c,v 1.20 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT_VAR(cchar_t) * _nc_wacs = 0;
 
@@ -106,7 +107,6 @@
     };
     /* *INDENT-ON* */
 
-    unsigned n, m;
     int active = _nc_unicode_locale();
 
     /*
@@ -120,9 +120,15 @@
        active ? "" : " not"));
 
     if ((_nc_wacs = typeCalloc(cchar_t, ACS_LEN)) != 0) {
+	unsigned n;
 
 	for (n = 0; n < SIZEOF(table); ++n) {
+	    unsigned m;
+#if NCURSES_WCWIDTH_GRAPHICS
 	    int wide = wcwidth((wchar_t) table[n].value[active]);
+#else
+	    int wide = 1;
+#endif
 
 	    m = table[n].map;
 	    if (active && (wide == 1)) {
@@ -133,9 +139,9 @@
 		SetChar(_nc_wacs[m], table[n].value[0], A_NORMAL);
 	    }
 
-	    T(("#%d, SetChar(%c, %#04x) = %s",
-	       n, m,
-	       table[n].value[active],
+	    T(("#%d, width:%d SetChar(%c, %s) = %s",
+	       n, wide, m,
+	       _tracechar(table[n].value[active]),
 	       _tracecchar_t(&_nc_wacs[m])));
 	}
     }
diff --git a/ncurses/widechar/lib_wunctrl.c b/ncurses/widechar/lib_wunctrl.c
index 45d4952..155da22 100644
--- a/ncurses/widechar/lib_wunctrl.c
+++ b/ncurses/widechar/lib_wunctrl.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2001-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2001-2011,2012 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            *
@@ -35,7 +36,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_wunctrl.c,v 1.16 2012/12/15 20:53:42 tom Exp $")
+MODULE_ID("$Id: lib_wunctrl.c,v 1.17 2020/02/02 23:34:34 tom Exp $")
 
 NCURSES_EXPORT(wchar_t *)
 NCURSES_SP_NAME(wunctrl) (NCURSES_SP_DCLx cchar_t *wc)
diff --git a/ncurses/widechar/widechars.c b/ncurses/widechar/widechars.c
index 6951e28..d05ba98 100644
--- a/ncurses/widechar/widechars.c
+++ b/ncurses/widechar/widechars.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2012,2013 Free Software Foundation, Inc.                   *
+ * Copyright 2018,2020 Thomas E. Dickey                                     *
+ * Copyright 2012,2013 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            *
@@ -30,9 +31,9 @@
 
 #if USE_WIDEC_SUPPORT
 
-MODULE_ID("$Id: widechars.c,v 1.5 2013/03/02 18:55:51 tom Exp $")
+MODULE_ID("$Id: widechars.c,v 1.9 2020/08/29 16:22:03 juergen Exp $")
 
-#if defined(__MINGW32__)
+#if (defined(_NC_WINDOWS)) && !defined(_NC_MSC)
 /*
  * MinGW has wide-character functions, but they do not work correctly.
  */
@@ -147,6 +148,6 @@
     return result;
 }
 
-#endif /* __MINGW32__ */
+#endif /* _NC_WINDOWS */
 
 #endif /* USE_WIDEC_SUPPORT */