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_get_wstr.c b/test/test_get_wstr.c
index dc01b0e..2a788fc 100644
--- a/test/test_get_wstr.c
+++ b/test/test_get_wstr.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2007-2009,2011 Free Software Foundation, Inc.              *
+ * Copyright 2020,2022 Thomas E. Dickey                                     *
+ * Copyright 2007-2011,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_get_wstr.c,v 1.8 2011/01/15 18:15:11 tom Exp $
+ * $Id: test_get_wstr.c,v 1.14 2022/12/10 23:59:13 tom Exp $
  *
  * Author: Thomas E Dickey
  *
@@ -43,6 +44,7 @@
  */
 
 #include <test.priv.h>
+#include <popup_msg.h>
 
 #if HAVE_CHGAT
 /* NetBSD curses wchgat */
@@ -79,14 +81,14 @@
 static void
 ShowPrompt(WINDOW *txtwin, int limit)
 {
-    wchgat(txtwin, limit, A_REVERSE, 0, NULL);
+    wchgat(txtwin, limit, WA_REVERSE, 0, NULL);
     wnoutrefresh(txtwin);
 }
 
 static void
 MovePrompt(WINDOW *txtwin, int limit, int y, int x)
 {
-    wchgat(txtwin, Remainder(txtwin), A_NORMAL, 0, NULL);
+    wchgat(txtwin, Remainder(txtwin), WA_NORMAL, 0, NULL);
     wmove(txtwin, y, x);
     ShowPrompt(txtwin, limit);
 }
@@ -134,8 +136,30 @@
 }
 
 static int
-test_get_wstr(int level, char **argv, WINDOW *strwin)
+recursive_test(int level, char **argv, WINDOW *strwin)
 {
+    static const char *help[] =
+    {
+	"Commands:",
+	"  q,^Q,ESC       - quit this program",
+	"  ^Q,ESC         - quit help-screen",
+	"",
+	"  p,<Up>         - move beginning of prompt one up row",
+	"  j,<Down>       - move beginning of prompt one down row",
+	"  h,<Left>       - move beginning of prompt one left column",
+	"  l,<Right>      - move beginning of prompt one right column",
+	"",
+	"  -              - reduce getnstr buffer-size one column",
+	"  +              - increase getnstr buffer-size one column",
+	"  :              - prompt for input-text",
+	"",
+	"  <              - scroll \"left\" through getstr-functions",
+	"  >              - scroll \"right\" through getstr-functions",
+	"",
+	"  w              - recur to subwindow",
+	"  ?,<F1>         - show help-screen",
+	0
+    };
     WINDOW *txtbox = 0;
     WINDOW *txtwin = 0;
     FILE *fp;
@@ -225,7 +249,7 @@
 	    break;
 
 	case 'w':
-	    test_get_wstr(level + 1, argv, strwin);
+	    recursive_test(level + 1, argv, strwin);
 	    if (txtbox != 0) {
 		touchwin(txtbox);
 		wnoutrefresh(txtbox);
@@ -311,10 +335,13 @@
 	    }
 	    noecho();
 	    (void) wattrset(txtwin, A_NORMAL);
-	    wprintw(strwin, "%d", rc);
+	    wprintw(strwin, "%s:", (rc == OK) ? "OK" : "ERR");
 	    (void) waddwstr(strwin, (wchar_t *) buffer);
 	    wnoutrefresh(strwin);
 	    break;
+	case HELP_KEY_1:
+	    popup_msg(stdscr, help);
+	    break;
 	default:
 	    beep();
 	    break;
@@ -328,18 +355,48 @@
     return TRUE;
 }
 
+static void
+usage(int ok)
+{
+    static const char *msg[] =
+    {
+	"Usage: test_get_wstr [options] [file1 [...]]"
+	,""
+	,USAGE_COMMON
+    };
+    size_t n;
+
+    for (n = 0; n < SIZEOF(msg); n++)
+	fprintf(stderr, "%s\n", msg[n]);
+
+    ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
+
 int
 main(int argc, char *argv[])
 {
     WINDOW *chrbox;
     WINDOW *strwin;
+    int ch;
+
+    while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
+	switch (ch) {
+	case OPTS_VERSION:
+	    show_version(argv);
+	    ExitProgram(EXIT_SUCCESS);
+	default:
+	    usage(ch == OPTS_USAGE);
+	    /* NOTREACHED */
+	}
+    }
 
     setlocale(LC_ALL, "");
 
-    if (argc < 2) {
-	fprintf(stderr, "usage: %s file\n", argv[0]);
-	return EXIT_FAILURE;
-    }
+    if (optind + 1 > argc)
+	usage(FALSE);
 
     initscr();
 
@@ -349,7 +406,7 @@
 
     strwin = derwin(chrbox, 4, COLS - 2, 1, 1);
 
-    test_get_wstr(1, argv, strwin);
+    recursive_test(optind, argv, strwin);
 
     endwin();
     ExitProgram(EXIT_SUCCESS);