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/test/test_addwstr.c b/test/test_addwstr.c
index ff5a350..9e51f49 100644
--- a/test/test_addwstr.c
+++ b/test/test_addwstr.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2009-2012,2014 Free Software Foundation, Inc.              *
+ * Copyright 2020-2022,2023 Thomas E. Dickey                                *
+ * Copyright 2009-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            *
@@ -26,7 +27,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: test_addwstr.c,v 1.12 2014/08/02 17:24:55 tom Exp $
+ * $Id: test_addwstr.c,v 1.22 2023/05/27 20:13:10 tom Exp $
  *
  * Demonstrate the waddwstr() and wadd_wch functions.
  * Thomas Dickey - 2009/9/12
@@ -48,12 +49,16 @@
 #define WIDE_LINEDATA
 #include <linedata.h>
 
+#undef AddCh
 #undef MvAddCh
 #undef MvAddStr
 #undef MvWAddCh
 #undef MvWAddStr
+#undef WAddCh
 
-/* definitions to make it simpler to compare with inserts.c */
+/*
+ * redefinitions to simplify comparison between test_*str programs
+ */
 #define AddNStr    addnwstr
 #define AddStr     addwstr
 #define MvAddNStr  (void) mvaddnwstr
@@ -103,14 +108,13 @@
     wprintw(win,
 	    "down-arrow or ^N to repeat on next line, ^W for inner window, ESC to exit.\n");
     wclrtoeol(win);
-    wprintw(win, "Level %d,%s inserted %d characters <", level,
-	    showstate, length);
+    wprintw(win, "Level %d,%s added %d characters <", level, showstate, length);
     waddwstr(win, buffer);
     waddstr(win, ">");
 }
 
 static int
-ColOf(wchar_t *buffer, int length, int margin)
+ColOf(const wchar_t *const buffer, int length, int margin)
 {
     int n;
     int result;
@@ -218,7 +222,7 @@
 
 #define LEN(n) ((length - (n) > n_opt) ? n_opt : (length - (n)))
 static void
-test_inserts(int level)
+recursive_test(int level)
 {
     static bool first = TRUE;
 
@@ -233,15 +237,19 @@
     WINDOW *work = 0;
     WINDOW *show = 0;
     int margin = (2 * MY_TABSIZE) - 1;
-    Options option = (Options) ((int) (m_opt ? oMove : oDefault)
-				| (int) ((w_opt || (level > 0))
-					 ? oWindow : oDefault));
+    Options option = (Options) ((unsigned) (m_opt
+					    ? oMove
+					    : oDefault)
+				| (unsigned) ((w_opt || (level > 0))
+					      ? oWindow
+					      : oDefault));
 
     if (first) {
 	static char cmd[80];
 	setlocale(LC_ALL, "");
 
-	putenv(strcpy(cmd, "TABSIZE=8"));
+	_nc_STRCPY(cmd, "TABSIZE=8", sizeof(cmd));
+	putenv(cmd);
 
 	initscr();
 	(void) cbreak();	/* take input chars one at a time, no wait for \n */
@@ -249,7 +257,7 @@
 	keypad(stdscr, TRUE);
 
 	/*
-	 * Show the characters inserted in color, to distinguish from those that
+	 * Show the characters added in color, to distinguish from those that
 	 * are shifted.
 	 */
 	if (has_colors()) {
@@ -297,7 +305,7 @@
 	wmove(work, row, margin + 1);
 	switch (ch) {
 	case key_RECUR:
-	    test_inserts(level + 1);
+	    recursive_test(level + 1);
 
 	    if (look)
 		touchwin(look);
@@ -367,7 +375,7 @@
 		    break;
 		}
 
-		/* do the corresponding single-character insertion */
+		/* do the corresponding single-character add */
 		row2 = limit + row;
 		for (col = 0; col < length; ++col) {
 		    col2 = ColOf(buffer, col, margin);
@@ -422,7 +430,7 @@
 		break;
 	    }
 
-	    /* do the corresponding single-character insertion */
+	    /* do the corresponding single-character add */
 	    switch (option) {
 	    case oDefault:
 		if (move(limit + row, col) != ERR) {
@@ -459,32 +467,36 @@
 }
 
 static void
-usage(void)
+usage(int ok)
 {
     static const char *tbl[] =
     {
-	"Usage: inserts [options]"
+	"Usage: test_addwstr [options]"
 	,""
+	,USAGE_COMMON
 	,"Options:"
-	,"  -f FILE read data from given file"
-	,"  -n NUM  limit string-inserts to NUM bytes on ^N replay"
-	,"  -m      perform wmove/move separately from insert-functions"
-	,"  -w      use window-parameter even when stdscr would be implied"
+	," -f FILE  read data from given file"
+	," -n NUM   limit string-adds to NUM bytes on ^N replay"
+	," -m       perform wmove/move separately from add-functions"
+	," -w       use window-parameter even when stdscr would be implied"
     };
     unsigned n;
     for (n = 0; n < SIZEOF(tbl); ++n)
 	fprintf(stderr, "%s\n", tbl[n]);
-    ExitProgram(EXIT_FAILURE);
+    ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
 
 int
-main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+main(int argc, char *argv[])
 {
     int ch;
 
     setlocale(LC_ALL, "");
 
-    while ((ch = getopt(argc, argv, "f:mn:w")) != -1) {
+    while ((ch = getopt(argc, argv, OPTS_COMMON "f:mn:w")) != -1) {
 	switch (ch) {
 	case 'f':
 	    init_linedata(optarg);
@@ -500,15 +512,18 @@
 	case 'w':
 	    w_opt = TRUE;
 	    break;
+	case OPTS_VERSION:
+	    show_version(argv);
+	    ExitProgram(EXIT_SUCCESS);
 	default:
-	    usage();
-	    break;
+	    usage(ch == OPTS_USAGE);
+	    /* NOTREACHED */
 	}
     }
     if (optind < argc)
-	usage();
+	usage(FALSE);
 
-    test_inserts(0);
+    recursive_test(0);
     endwin();
     ExitProgram(EXIT_SUCCESS);
 }