From 493e2f7b3fc309879f561a094fdfc15e5304b3d6 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 22 Aug 2021 00:41:36 +0000 Subject: [PATCH 1/1] ncurses 6.2 - patch 20210821 + improve tparm implementation of %P and %g, more closely matching SVr4 terminfo. + move internals of TERMINAL structure to new header term.priv.h + add "check" rule for ncurses/Makefile + corrected tsl capability for terminator -TD + add check in tic to report instances where tparm would detect an error in an expression (cf: 20201010). + correct a few places where SP->_pair_limit was used rather than SP->_pair_alloc (cf: 20170812). + fix missing "%d" for setaf/setab code 8-15 in xterm+direct16 (report by Florian Weimer) -TD + fix some documentation errata from OpenBSD changes. + update config.sub --- MANIFEST | 1 + NEWS | 17 +- VERSION | 2 +- announce.html.in | 4 +- config.sub | 21 +- dist.mk | 4 +- doc/html/man/adacurses6-config.1.html | 2 +- doc/html/man/captoinfo.1m.html | 2 +- doc/html/man/clear.1.html | 2 +- doc/html/man/form.3x.html | 2 +- doc/html/man/infocmp.1m.html | 6 +- doc/html/man/infotocap.1m.html | 2 +- doc/html/man/legacy_coding.3x.html | 6 +- doc/html/man/menu.3x.html | 2 +- doc/html/man/ncurses.3x.html | 2 +- doc/html/man/ncurses6-config.1.html | 2 +- doc/html/man/panel.3x.html | 2 +- doc/html/man/tabs.1.html | 2 +- doc/html/man/term.5.html | 8 +- doc/html/man/term.7.html | 8 +- doc/html/man/terminfo.5.html | 33 +- doc/html/man/tic.1m.html | 14 +- doc/html/man/toe.1m.html | 2 +- doc/html/man/tput.1.html | 2 +- doc/html/man/tset.1.html | 2 +- include/MKterm.h.awk.in | 19 +- include/tic.h | 5 +- man/infocmp.1m | 4 +- man/legacy_coding.3x | 6 +- man/term.5 | 8 +- man/term.7 | 8 +- man/terminfo.head | 6 +- man/terminfo.tail | 28 +- man/tic.1m | 4 +- misc/terminfo.src | 23 +- mk-1st.awk | 4 +- ncurses/Makefile.in | 24 +- ncurses/base/new_pair.c | 4 +- ncurses/curses.priv.h | 232 +------------- ncurses/llib-lncurses | 21 +- ncurses/llib-lncursest | 21 +- ncurses/llib-lncursestw | 21 +- ncurses/llib-lncursesw | 21 +- ncurses/llib-ltic | 2 +- ncurses/llib-ltict | 2 +- ncurses/llib-ltictw | 2 +- ncurses/llib-lticw | 2 +- ncurses/llib-ltinfo | 19 ++ ncurses/llib-ltinfot | 19 ++ ncurses/llib-ltinfotw | 19 ++ ncurses/llib-ltinfow | 19 ++ ncurses/new_pair.h | 11 +- ncurses/report_offsets.c | 25 +- ncurses/term.priv.h | 330 ++++++++++++++++++++ ncurses/tinfo/lib_data.c | 3 +- ncurses/tinfo/lib_tparm.c | 432 +++++++++++++++++--------- ncurses/tinfo/make_keys.c | 12 +- ncurses/tinfo/write_entry.c | 6 +- ncurses/tty/tty_update.c | 6 +- ncurses/wcwidth.h | 16 + package/debian-mingw/changelog | 4 +- package/debian-mingw64/changelog | 4 +- package/debian/changelog | 4 +- package/mingw-ncurses.nsi | 4 +- package/mingw-ncurses.spec | 2 +- package/ncurses.map | 3 +- package/ncurses.spec | 2 +- package/ncurses.sym | 3 +- package/ncursest.map | 3 +- package/ncursest.spec | 2 +- package/ncursest.sym | 3 +- package/ncursestw.map | 3 +- package/ncursestw.sym | 3 +- package/ncursesw.map | 3 +- package/ncursesw.sym | 3 +- progs/dump_entry.c | 4 +- progs/tic.c | 131 ++++---- progs/tput.c | 4 +- test/ditto.c | 4 +- 79 files changed, 1137 insertions(+), 586 deletions(-) create mode 100644 ncurses/term.priv.h diff --git a/MANIFEST b/MANIFEST index 9407467f..14296529 100644 --- a/MANIFEST +++ b/MANIFEST @@ -900,6 +900,7 @@ ./ncurses/new_pair.h ./ncurses/report_hashing.c ./ncurses/report_offsets.c +./ncurses/term.priv.h ./ncurses/tinfo/MKcaptab.awk ./ncurses/tinfo/MKcaptab.sh ./ncurses/tinfo/MKcodes.awk diff --git a/NEWS b/NEWS index 74274020..c7e80d8d 100644 --- a/NEWS +++ b/NEWS @@ -26,7 +26,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.3694 2021/08/14 15:01:03 tom Exp $ +-- $Id: NEWS,v 1.3698 2021/08/21 23:25:57 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -46,6 +46,21 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20210821 + + improve tparm implementation of %P and %g, more closely matching + SVr4 terminfo. + + move internals of TERMINAL structure to new header term.priv.h + + add "check" rule for ncurses/Makefile + + corrected tsl capability for terminator -TD + + add check in tic to report instances where tparm would detect an + error in an expression (cf: 20201010). + + correct a few places where SP->_pair_limit was used rather than + SP->_pair_alloc (cf: 20170812). + + fix missing "%d" for setaf/setab code 8-15 in xterm+direct16 (report + by Florian Weimer) -TD + + fix some documentation errata from OpenBSD changes. + + update config.sub + 20210814 + add workaround for broken pcre2 package in Debian 10, from xterm #369. diff --git a/VERSION b/VERSION index f9f2b0ee..7905a058 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5:0:10 6.2 20210814 +5:0:10 6.2 20210821 diff --git a/announce.html.in b/announce.html.in index 9651b06f..24da9f52 100644 --- a/announce.html.in +++ b/announce.html.in @@ -1,5 +1,5 @@ @@ -383,7 +383,7 @@ -Rsubset Restrict output to a given subset. This option is for use with - archaic versions of terminfo like those on SVr1, Ultrix, or HP/UX + archaic versions of terminfo like those on SVr1, Ultrix, or HP-UX that do not support the full set of SVR4/XSI Curses terminfo; and variants such as AIX that have their own extensions incompatible with SVr4/XSI. @@ -514,7 +514,7 @@ https://invisible-island.net/ncurses/tctest.html - This describes ncurses version 6.2 (patch 20210710). + This describes ncurses version 6.2 (patch 20210821).

AUTHOR

diff --git a/doc/html/man/infotocap.1m.html b/doc/html/man/infotocap.1m.html
index 7feb2027..328f9a49 100644
--- a/doc/html/man/infotocap.1m.html
+++ b/doc/html/man/infotocap.1m.html
@@ -91,7 +91,7 @@
 

SEE ALSO

        infocmp(1m), tic(1m), curses(3x), terminfo(5)
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 

AUTHOR

diff --git a/doc/html/man/legacy_coding.3x.html b/doc/html/man/legacy_coding.3x.html
index 5a5a3f0e..ef4cfa04 100644
--- a/doc/html/man/legacy_coding.3x.html
+++ b/doc/html/man/legacy_coding.3x.html
@@ -1,6 +1,6 @@
 
 
 
@@ -90,7 +90,7 @@
 
 
 

SEE ALSO

-       unctrl.
+       unctrl(3x).
 
 
 

AUTHOR

diff --git a/doc/html/man/menu.3x.html b/doc/html/man/menu.3x.html
index 02739bd3..f301005d 100644
--- a/doc/html/man/menu.3x.html
+++ b/doc/html/man/menu.3x.html
@@ -223,7 +223,7 @@
        curses(3x) and related pages whose names  begin  "menu_"  for  detailed
        descriptions of the entry points.
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 
diff --git a/doc/html/man/ncurses.3x.html b/doc/html/man/ncurses.3x.html
index e6211175..163279b5 100644
--- a/doc/html/man/ncurses.3x.html
+++ b/doc/html/man/ncurses.3x.html
@@ -60,7 +60,7 @@
        method of updating  character  screens  with  reasonable  optimization.
        This  implementation  is  "new  curses"  (ncurses)  and is the approved
        replacement for 4.4BSD classic curses,  which  has  been  discontinued.
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
        The  ncurses  library emulates the curses library of System V Release 4
        UNIX, and XPG4 (X/Open Portability Guide) curses  (also  known  as  XSI
diff --git a/doc/html/man/ncurses6-config.1.html b/doc/html/man/ncurses6-config.1.html
index b99dc441..d3a0a86f 100644
--- a/doc/html/man/ncurses6-config.1.html
+++ b/doc/html/man/ncurses6-config.1.html
@@ -113,7 +113,7 @@
 

SEE ALSO

        curses(3x)
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 
diff --git a/doc/html/man/panel.3x.html b/doc/html/man/panel.3x.html
index 05c06a11..909efbfb 100644
--- a/doc/html/man/panel.3x.html
+++ b/doc/html/man/panel.3x.html
@@ -281,7 +281,7 @@
 

SEE ALSO

        curses(3x), curs_variables(3x),
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 

AUTHOR

diff --git a/doc/html/man/tabs.1.html b/doc/html/man/tabs.1.html
index 784a97bc..bbd29aaa 100644
--- a/doc/html/man/tabs.1.html
+++ b/doc/html/man/tabs.1.html
@@ -207,7 +207,7 @@
 

SEE ALSO

        infocmp(1m), tset(1), curses(3x), terminfo(5).
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 
diff --git a/doc/html/man/term.5.html b/doc/html/man/term.5.html
index c2bf0eb8..941c2d82 100644
--- a/doc/html/man/term.5.html
+++ b/doc/html/man/term.5.html
@@ -1,6 +1,6 @@
 
 
 
@@ -249,7 +249,7 @@
 

setupterm

        Note  that  it  is  possible for setupterm to expect a different set of
        capabilities than  are  actually  present  in  the  file.   Either  the
-       database  may  have  been  updated  since setupterm has been recompiled
+       database   may   have  been  updated  since  setupterm  was  recompiled
        (resulting in extra unrecognized entries in the file)  or  the  program
        may  have  been  recompiled more recently than the database was updated
        (resulting in missing entries).  The routine setupterm must be prepared
@@ -362,7 +362,7 @@
 
 
 

FILES

-       /usr/share/terminfo/*/*  compiled terminal capability data base
+       /usr/share/terminfo/*/*  compiled terminal capability database
 
 
 

SEE ALSO

diff --git a/doc/html/man/term.7.html b/doc/html/man/term.7.html
index 8bb02199..e9d3512d 100644
--- a/doc/html/man/term.7.html
+++ b/doc/html/man/term.7.html
@@ -1,6 +1,6 @@
 
 
 
@@ -72,7 +72,7 @@
        termcap  entry  for  your  type  is not compatible with yours, but this
        situation is rare and  can  almost  always  be  avoided  by  explicitly
        exporting  "vt100"  (assuming  you  are  in fact using a VT100-superset
-       console, terminal, or terminal emulator.)
+       console, terminal, or terminal emulator).
 
        In any case, you are free to override the system TERM setting  to  your
        taste in your shell profile.  The tset(1) utility may be of assistance;
@@ -202,7 +202,7 @@
 
 

FILES

        /usr/share/terminfo/?/*
-            compiled terminal capability data base
+            compiled terminal capability database
 
        /etc/inittab
             tty line initialization (AT&T-like UNIXes)
diff --git a/doc/html/man/terminfo.5.html b/doc/html/man/terminfo.5.html
index 953d01ed..16bd0c35 100644
--- a/doc/html/man/terminfo.5.html
+++ b/doc/html/man/terminfo.5.html
@@ -32,7 +32,7 @@
   * sale, use or other dealings in this Software without prior written       *
   * authorization.                                                           *
   ****************************************************************************
-  * @Id: terminfo.head,v 1.40 2021/06/17 21:30:22 tom Exp @
+  * @Id: terminfo.head,v 1.41 2021/08/15 19:32:53 tom Exp @
   * Head of terminfo man page ends here
   ****************************************************************************
   * Copyright 2018-2020,2021 Thomas E. Dickey                                *
@@ -62,7 +62,7 @@
   * sale, use or other dealings in this Software without prior written       *
   * authorization.                                                           *
   ****************************************************************************
-  * @Id: terminfo.tail,v 1.101 2021/06/17 21:30:22 tom Exp @
+  * @Id: terminfo.tail,v 1.102 2021/08/21 22:55:23 tom Exp @
   *.in -2
   *.in +2
   *.in -2
@@ -87,7 +87,7 @@
 
 
 

NAME

-       terminfo - terminal capability data base
+       terminfo - terminal capability database
 
 
 

SYNOPSIS

@@ -95,7 +95,7 @@
 
 
 

DESCRIPTION

-       Terminfo  is  a data base describing terminals, used by screen-oriented
+       Terminfo  is  a  database describing terminals, used by screen-oriented
        programs  such  as  nvi(1),  lynx(1),   mutt(1),   and   other   curses
        applications,  using  high-level calls to libraries such as curses(3x).
        It is also used via low-level calls by  non-curses  applications  which
@@ -106,7 +106,7 @@
        have, by specifying how to perform screen operations, and by specifying
        padding requirements and initialization sequences.
 
-       This manual describes ncurses version 6.2 (patch 20210710).
+       This manual describes ncurses version 6.2 (patch 20210821).
 
 
 

Terminfo Entry Syntax

@@ -1475,7 +1475,27 @@
             these are simply two different sets of variables, whose values are
             not reset between calls to tparm(3x).  However, that fact  is  not
             documented in other implementations.  Relying on it will adversely
-            impact portability to other implementations.
+            impact portability to other implementations:
+
+            o   SVr4 curses  stores  the  static  variables  in  the  TERMINAL
+                structure  (declared  in term.h), and the dynamic variables on
+                the stack in  the  tparm  function.   The  former  are  zeroed
+                automatically  when the setupterm function allocates the data.
+                The latter are set only by a %P operator.  A %g  for  a  given
+                variable   without   first   setting  it  with  %P  will  give
+                unpredictable results.
+
+            o   Solaris XPG4 curses does not distinguish between  dynamic  and
+                static  variables.  They are the same.  Like SVr4 curses, XPG4
+                curses does not initialize these explicitly.
+
+            o   Before version 6.3, ncurses stores  both  dynamic  and  static
+                variables in persistent storage, initialized to zeros.
+
+            o   Beginning  with version 6.3, ncurses stores static and dynamic
+                variables  in  the  same  manner  as   SVr4.    Unlike   other
+                implementations,  ncurses  zeros  dynamic variables before the
+                first %g or %P operator.
 
        %'c' char constant c
 
@@ -2094,7 +2114,6 @@
          board of squares            ACS_BOARD      #         h        0x68
          lantern symbol              ACS_LANTERN    #         i        0x69
          lower right corner          ACS_LRCORNER   +         j        0x6a
-
          upper right corner          ACS_URCORNER   +         k        0x6b
          upper left corner           ACS_ULCORNER   +         l        0x6c
          lower left corner           ACS_LLCORNER   +         m        0x6d
diff --git a/doc/html/man/tic.1m.html b/doc/html/man/tic.1m.html
index 37736469..be0a6dd6 100644
--- a/doc/html/man/tic.1m.html
+++ b/doc/html/man/tic.1m.html
@@ -27,7 +27,7 @@
   * sale, use or other dealings in this Software without prior written       *
   * authorization.                                                           *
   ****************************************************************************
-  * @Id: tic.1m,v 1.79 2021/06/17 21:30:22 tom Exp @
+  * @Id: tic.1m,v 1.80 2021/08/15 20:01:19 tom Exp @
 -->
 
 
@@ -223,11 +223,11 @@
 
        -Rsubset
               Restrict output to a given subset.  This option is for use  with
-              archaic  versions  of  terminfo  like  those on SVr1, Ultrix, or
-              HP/UX that do not  support  the  full  set  of  SVR4/XSI  Curses
-              terminfo; and outright broken ports like AIX 3.x that have their
-              own extensions incompatible with  SVr4/XSI.   Available  subsets
-              are "SVr1", "Ultrix", "HP", "BSD" and "AIX"; see terminfo(5) for
+              archaic  versions of terminfo like those on SVr1, Ultrix, or HP-
+              UX that do not support the full set of SVR4/XSI Curses terminfo;
+              and  outright  broken  ports  like  AIX  3.x that have their own
+              extensions incompatible with SVr4/XSI.   Available  subsets  are
+              "SVr1",  "Ultrix",  "HP",  "BSD"  and "AIX"; see terminfo(5) for
               details.
 
        -r     Force  entry  resolution  (so  there   are   no   remaining   tc
@@ -461,7 +461,7 @@
        captoinfo(1m),   infocmp(1m),   infotocap(1m),   toe(1m),   curses(3x),
        term(5).  terminfo(5).  user_caps(5).
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 

AUTHOR

diff --git a/doc/html/man/toe.1m.html b/doc/html/man/toe.1m.html
index 6ded423d..8a4923f0 100644
--- a/doc/html/man/toe.1m.html
+++ b/doc/html/man/toe.1m.html
@@ -171,7 +171,7 @@
        captoinfo(1m),   infocmp(1m),   infotocap(1m),   tic(1m),   curses(3x),
        terminfo(5).
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 
diff --git a/doc/html/man/tput.1.html b/doc/html/man/tput.1.html
index 6555c356..ff7fca2a 100644
--- a/doc/html/man/tput.1.html
+++ b/doc/html/man/tput.1.html
@@ -526,7 +526,7 @@
 

SEE ALSO

        clear(1), stty(1), tabs(1), tset(1), curs_termcap(3x), terminfo(5).
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 
diff --git a/doc/html/man/tset.1.html b/doc/html/man/tset.1.html
index 0d894e5b..81a75bce 100644
--- a/doc/html/man/tset.1.html
+++ b/doc/html/man/tset.1.html
@@ -385,7 +385,7 @@
        csh(1),   sh(1),   stty(1),   curs_terminfo(3x),  tty(4),  terminfo(5),
        ttys(5), environ(7)
 
-       This describes ncurses version 6.2 (patch 20210710).
+       This describes ncurses version 6.2 (patch 20210821).
 
 
 
diff --git a/include/MKterm.h.awk.in b/include/MKterm.h.awk.in
index b6062c8b..b72136d8 100644
--- a/include/MKterm.h.awk.in
+++ b/include/MKterm.h.awk.in
@@ -60,7 +60,7 @@ BEGIN {
 	print  "/*    and: Thomas E. Dickey                        1995-on                  */"
 	print  "/****************************************************************************/"
 	print  ""
-	print  "/* $Id: MKterm.h.awk.in,v 1.79 2021/03/20 16:08:03 tom Exp $ */"
+	print  "/* $Id: MKterm.h.awk.in,v 1.81 2021/08/18 20:52:42 tom Exp $ */"
 	print  ""
 	print  "/*"
 	print  "**	term.h -- Definition of struct term"
@@ -244,6 +244,9 @@ END {
 	print  " * The only reason these structures are visible is for read-only use."
 	print  " * Programs which modify the data are not, never were, portable across"
 	print  " * curses implementations."
+	print  " *"
+	print  " * The first field in TERMINAL is used in macros."
+	print  " * The remaining fields are private."
 	print  " */"
 	print  "#ifdef NCURSES_INTERNALS"
 	print  ""
@@ -253,19 +256,13 @@ END {
 	print  "typedef TERMTYPE TERMTYPE2;"
 	}
 	print  ""
+	print  "typedef struct term TERMINAL;"
+	print  "#else"
+	print  ""
 	print  "typedef struct term {		/* describe an actual terminal */"
 	print  "    TERMTYPE	type;		/* terminal type description */"
-	print  "    short	Filedes;	/* file description being written to */"
-	print  "    TTY		Ottyb;		/* original state of the terminal */"
-	print  "    TTY		Nttyb;		/* current state of the terminal */"
-	print  "    int		_baudrate;	/* used to compute padding */"
-	print  "    char *	_termname;	/* used for termname() */"
-	if (@NCURSES_EXT_COLORS@) {
-	print  "    TERMTYPE2	type2;		/* extended terminal type description */"
-	}
 	print  "} TERMINAL;"
-	print  "#else"
-	print  "typedef struct term TERMINAL;"
+	print  ""
 	print  "#endif /* NCURSES_INTERNALS */"
 	print  ""
 	print  ""
diff --git a/include/tic.h b/include/tic.h
index 66454862..36169f02 100644
--- a/include/tic.h
+++ b/include/tic.h
@@ -34,7 +34,7 @@
  ****************************************************************************/
 
 /*
- * $Id: tic.h,v 1.82 2021/03/20 16:06:15 tom Exp $
+ * $Id: tic.h,v 1.84 2021/08/21 00:24:45 tom Exp $
  *	tic.h - Global variables and structures for the terminfo compiler.
  */
 
@@ -337,7 +337,8 @@ extern NCURSES_EXPORT_VAR(const struct tinfo_fkeys) _nc_tinfo_fkeys[];
 
 extern NCURSES_EXPORT_VAR(int) _nc_tparm_err;
 
-extern NCURSES_EXPORT(int) _nc_tparm_analyze(const char *, char **, int *);
+extern NCURSES_EXPORT(int) _nc_tparm_analyze(TERMINAL *, const char *, char **, int *);
+extern NCURSES_EXPORT(void) _nc_reset_tparm(TERMINAL *);
 
 /* lib_trace.c */
 extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
diff --git a/man/infocmp.1m b/man/infocmp.1m
index 54839872..087796f1 100644
--- a/man/infocmp.1m
+++ b/man/infocmp.1m
@@ -28,7 +28,7 @@
 .\" authorization.                                                           *
 .\"***************************************************************************
 .\"
-.\" $Id: infocmp.1m,v 1.78 2021/06/17 21:30:22 tom Exp $
+.\" $Id: infocmp.1m,v 1.79 2021/08/15 20:01:31 tom Exp $
 .TH @INFOCMP@ 1M ""
 .ie \n(.g .ds `` \(lq
 .el       .ds `` ``
@@ -476,7 +476,7 @@ Omit the \*(``Reconstructed from\*('' comment for source listings.
 \fB\-R\fR\fIsubset\fR
 Restrict output to a given subset.
 This option is for use with archaic
-versions of terminfo like those on SVr1, Ultrix, or HP/UX that do not support
+versions of terminfo like those on SVr1, Ultrix, or HP-UX that do not support
 the full set of SVR4/XSI Curses terminfo; and variants such as AIX
 that have their own extensions incompatible with SVr4/XSI.
 .RS
diff --git a/man/legacy_coding.3x b/man/legacy_coding.3x
index fa3181a8..42c3dd64 100644
--- a/man/legacy_coding.3x
+++ b/man/legacy_coding.3x
@@ -1,5 +1,5 @@
 .\"***************************************************************************
-.\" Copyright 2020 Thomas E. Dickey                                          *
+.\" Copyright 2020,2021 Thomas E. Dickey                                     *
 .\" Copyright 2005-2016,2017 Free Software Foundation, Inc.                  *
 .\"                                                                          *
 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -29,7 +29,7 @@
 .\"
 .\" Author: Thomas E. Dickey
 .\"
-.\" $Id: legacy_coding.3x,v 1.8 2020/10/17 23:40:23 tom Exp $
+.\" $Id: legacy_coding.3x,v 1.9 2021/08/15 19:32:05 tom Exp $
 .TH legacy_coding 3X ""
 .SH NAME
 \fBuse_legacy_coding\fR \- override locale-encoding checks
@@ -70,6 +70,6 @@ It was not supported on Version 7, BSD or System V implementations.
 It is recommended that any code depending on ncurses extensions
 be conditioned using NCURSES_VERSION.
 .SH SEE ALSO
-\fBunctrl\fR.
+\fBunctrl\fR(3X).
 .SH AUTHOR
 Thomas Dickey (to support lynx's font-switching feature).
diff --git a/man/term.5 b/man/term.5
index e9ae5bd0..3a4a1d07 100644
--- a/man/term.5
+++ b/man/term.5
@@ -1,5 +1,5 @@
 .\"***************************************************************************
-.\" Copyright 2018-2019,2020 Thomas E. Dickey                                *
+.\" Copyright 2018-2020,2021 Thomas E. Dickey                                *
 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
 .\"                                                                          *
 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -27,7 +27,7 @@
 .\" authorization.                                                           *
 .\"***************************************************************************
 .\"
-.\" $Id: term.5,v 1.38 2020/07/25 21:56:02 tom Exp $
+.\" $Id: term.5,v 1.40 2021/08/15 19:38:47 tom Exp $
 .TH term 5
 .ie \n(.g .ds `` \(lq
 .el       .ds `` ``
@@ -286,7 +286,7 @@ to expect a different set of capabilities
 than are actually present in the file.
 Either the database may have been updated since
 .B setupterm
-has been recompiled
+was recompiled
 (resulting in extra unrecognized entries in the file)
 or the program may have been recompiled more recently
 than the database was updated
@@ -400,7 +400,7 @@ Compiled entries are limited to 32768 bytes because offsets into the
 The legacy format could have supported 32768-byte entries,
 but was limited a virtual memory page's 4096 bytes.
 .SH FILES
-\*d/*/*	compiled terminal capability data base
+\*d/*/*	compiled terminal capability database
 .SH SEE ALSO
 \fBcurses\fR(3X), \fBterminfo\fR(\*n).
 .SH AUTHORS
diff --git a/man/term.7 b/man/term.7
index fc46b8a6..4e66ee71 100644
--- a/man/term.7
+++ b/man/term.7
@@ -1,5 +1,5 @@
 .\"***************************************************************************
-.\" Copyright 2018-2019,2020 Thomas E. Dickey                                *
+.\" Copyright 2018-2020,2021 Thomas E. Dickey                                *
 .\" Copyright 1998-2011,2017 Free Software Foundation, Inc.                  *
 .\"                                                                          *
 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -27,7 +27,7 @@
 .\" authorization.                                                           *
 .\"***************************************************************************
 .\"
-.\" $Id: term.7,v 1.28 2020/02/02 23:34:34 tom Exp $
+.\" $Id: term.7,v 1.30 2021/08/15 19:39:57 tom Exp $
 .TH term 7
 .ie \n(.g .ds `` \(lq
 .el       .ds `` ``
@@ -61,7 +61,7 @@ There can be problems if the remote terminfo or termcap entry
 for your type is not compatible with yours, but this situation is rare and
 can almost always be avoided by explicitly exporting \*(``vt100\*(''
 (assuming you are in fact using a VT100-superset console,
-terminal, or terminal emulator.)
+terminal, or terminal emulator).
 .PP
 In any case, you are free to override the system \fBTERM\fR setting to your
 taste in your shell profile.
@@ -213,7 +213,7 @@ should be unique within the first 14 characters.
 .SH FILES
 .TP 5
 \*d/?/*
-compiled terminal capability data base
+compiled terminal capability database
 .TP 5
 /etc/inittab
 tty line initialization (AT&T-like UNIXes)
diff --git a/man/terminfo.head b/man/terminfo.head
index 398f498a..15be24e7 100644
--- a/man/terminfo.head
+++ b/man/terminfo.head
@@ -27,7 +27,7 @@
 .\" authorization.                                                           *
 .\"***************************************************************************
 .\"
-.\" $Id: terminfo.head,v 1.40 2021/06/17 21:30:22 tom Exp $
+.\" $Id: terminfo.head,v 1.41 2021/08/15 19:32:53 tom Exp $
 .TH terminfo 5 "" "" "File Formats"
 .ds n 5
 .ds d @TERMINFO@
@@ -54,12 +54,12 @@
 .el    .in -2
 ..
 .SH NAME
-terminfo \- terminal capability data base
+terminfo \- terminal capability database
 .SH SYNOPSIS
 \*d/*/*
 .SH DESCRIPTION
 .I Terminfo
-is a data base describing terminals,
+is a database describing terminals,
 used by screen-oriented programs such as
 \fBnvi\fR(1),
 \fBlynx\fR(1),
diff --git a/man/terminfo.tail b/man/terminfo.tail
index 3259e981..a4620d19 100644
--- a/man/terminfo.tail
+++ b/man/terminfo.tail
@@ -27,7 +27,7 @@
 .\" authorization.                                                           *
 .\"***************************************************************************
 .\"
-.\" $Id: terminfo.tail,v 1.101 2021/06/17 21:30:22 tom Exp $
+.\" $Id: terminfo.tail,v 1.102 2021/08/21 22:55:23 tom Exp $
 .ps +1
 .SS User-Defined Capabilities
 .
@@ -483,7 +483,31 @@ The terms \*(``static\*('' and \*(``dynamic\*('' are misleading.
 Historically, these are simply two different sets of variables,
 whose values are not reset between calls to \fBtparm\fP(3X).
 However, that fact is not documented in other implementations.
-Relying on it will adversely impact portability to other implementations.
+Relying on it will adversely impact portability to other implementations:
+.RS
+.bP
+SVr4 curses stores the \fIstatic\fP variables in the \fBTERMINAL\fP
+structure (declared in \fBterm.h\fP), and the \fIdynamic variables\fP
+on the stack in the \fBtparm\fP function.
+The former are zeroed automatically when the \fBsetupterm\fP function
+allocates the data.
+The latter are set only by a \fB%P\fP operator.
+A \fB%g\fP for a given variable without first setting it with \fB%P\fP
+will give unpredictable results.
+.bP
+Solaris XPG4 curses does not distinguish between \fIdynamic\fP and
+\fIstatic\fP variables.
+They are the same.
+Like SVr4 curses, XPG4 curses does not initialize these explicitly.
+.bP
+Before version 6.3, ncurses stores both \fIdynamic\fP and \fIstatic\fP
+variables in persistent storage, initialized to zeros.
+.bP
+Beginning with version 6.3, ncurses stores \fIstatic\fP and \fIdynamic\fP
+variables in the same manner as SVr4.
+Unlike other implementations, ncurses zeros dynamic variables 
+before the first \fB%g\fP or \fB%P\fP operator.
+.RE
 .TP
 \fB%'\fP\fIc\fP\fB'\fP
 char constant \fIc\fP
diff --git a/man/tic.1m b/man/tic.1m
index e538e98e..17aa03f0 100644
--- a/man/tic.1m
+++ b/man/tic.1m
@@ -27,7 +27,7 @@
 .\" authorization.                                                           *
 .\"***************************************************************************
 .\"
-.\" $Id: tic.1m,v 1.79 2021/06/17 21:30:22 tom Exp $
+.\" $Id: tic.1m,v 1.80 2021/08/15 20:01:19 tom Exp $
 .TH @TIC@ 1M ""
 .ie \n(.g .ds `` \(lq
 .el       .ds `` ``
@@ -279,7 +279,7 @@ Suppress comments and blank lines when showing translated source.
 \fB\-R\fR\fIsubset\fR
 Restrict output to a given subset.
 This option is for use with archaic
-versions of terminfo like those on SVr1, Ultrix, or HP/UX that do not support
+versions of terminfo like those on SVr1, Ultrix, or HP-UX that do not support
 the full set of SVR4/XSI Curses terminfo; and outright broken ports like AIX 3.x
 that have their own extensions incompatible with SVr4/XSI.
 Available subsets
diff --git a/misc/terminfo.src b/misc/terminfo.src
index e8b3e4b6..86523e5d 100644
--- a/misc/terminfo.src
+++ b/misc/terminfo.src
@@ -6,8 +6,8 @@
 # Report bugs and new terminal descriptions to
 #	bug-ncurses@gnu.org
 #
-#	$Revision: 1.907 $
-#	$Date: 2021/08/01 00:06:57 $
+#	$Revision: 1.909 $
+#	$Date: 2021/08/17 00:26:19 $
 #
 # The original header is preserved below for reference.  It is noted that there
 # is a "newer" version which differs in some cosmetic details (but actually
@@ -5244,12 +5244,12 @@ nsterm-direct|nsterm with direct-color indexing,
 
 xterm+direct16|xterm with direct-color indexing,
 	CO#16,
-	setab=\E[%?%p1%{8}%<%t4%p1%d%e%?%p1%{16}%<%t%p1%{92}%+%e48:2
-	      ::%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%d
+	setab=\E[%?%p1%{8}%<%t4%p1%d%e%?%p1%{16}%<%t%p1%{92}%+%d%e48
+	      :2::%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&
+	      %d%;%;m,
+	setaf=\E[%?%p1%{8}%<%t3%p1%d%e%?%p1%{16}%<%t%p1%'R'%+%d%e38:
+	      2::%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%d
 	      %;%;m,
-	setaf=\E[%?%p1%{8}%<%t3%p1%d%e%?%p1%{16}%<%t%p1%'R'%+%e38:2:
-	      :%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%d%;
-	      %;m,
 	setb@, setf@, use=xterm+direct,
 
 xterm-direct16|xterm with direct-colors and 16 indexed colors,
@@ -7238,7 +7238,7 @@ terminator|Terminator no line wrap,
 	sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p5%t;2%;%?%p1%p3%|%t;7
 	    %;m%?%p9%t\E(0%e\E(B%;,
 	sgr0=\E[m\E(B, smacs=\E(0, smir=\E[4h, smso=\E[7m,
-	smul=\E[4m, tbc=\E[3g, tsl=\E]2;%p1, vpa=\E[%i%p1%dd,
+	smul=\E[4m, tbc=\E[3g, tsl=\E]2;, vpa=\E[%i%p1%dd,
 	use=vt220+pcedit, use=ecma+italics, use=ecma+index,
 	use=xterm+256setaf, use=xterm+sl-twm,
 	use=xterm+alt1049, use=vt220+cvis,
@@ -27178,4 +27178,11 @@ v3220|LANPAR Vision II model 3220/3221/3222,
 #	  but cancel the non-working Cr and Ms capabilities -TD
 #	+ add foot and foot-direct -TD
 #
+# 2021-08-15
+#	+ fix missing "%d" for setaf/setab code 8-15 in xterm+direct16 (report
+#	  by Florian Weimer) -TD
+#
+# 2021-08-16
+#	+ corrected tsl capability for terminator -TD
+#
 ######## SHANTIH!  SHANTIH!  SHANTIH!
diff --git a/mk-1st.awk b/mk-1st.awk
index beb8911f..75811d45 100644
--- a/mk-1st.awk
+++ b/mk-1st.awk
@@ -1,4 +1,4 @@
-# $Id: mk-1st.awk,v 1.122 2021/07/18 18:47:20 tom Exp $
+# $Id: mk-1st.awk,v 1.123 2021/08/15 20:01:44 tom Exp $
 ##############################################################################
 # Copyright 2018-2020,2021 Thomas E. Dickey                                  #
 # Copyright 1998-2016,2017 Free Software Foundation, Inc.                    #
@@ -62,7 +62,7 @@
 # Notes:
 #	CLIXs nawk does not like underscores in command-line variable names.
 #	Mixed-case variable names are ok.
-#	HP/UX requires shared libraries to have executable permissions.
+#	HP-UX requires shared libraries to have executable permissions.
 #
 function is_ticlib() {
 		return ( subset ~ /^ticlib$/ );
diff --git a/ncurses/Makefile.in b/ncurses/Makefile.in
index e08a9b9b..aba25fda 100644
--- a/ncurses/Makefile.in
+++ b/ncurses/Makefile.in
@@ -1,4 +1,4 @@
-# $Id: Makefile.in,v 1.180 2021/07/03 15:27:09 tom Exp $
+# $Id: Makefile.in,v 1.182 2021/08/19 23:43:40 tom Exp $
 ##############################################################################
 # Copyright 2018-2020,2021 Thomas E. Dickey                                  #
 # Copyright 1998-2017,2018 Free Software Foundation, Inc.                    #
@@ -193,7 +193,8 @@ HEADER_DEPS	= @INTERNALS_HDR@ \
 	$(INCDIR)/nc_win32.h \
 	$(INCDIR)/term_entry.h \
 	$(srcdir)/curses.priv.h \
-	$(srcdir)/new_pair.h
+	$(srcdir)/new_pair.h \
+	$(srcdir)/term.priv.h
 
 TEST_DEPS	= ../lib/@LIB_PREFIX@ncurses@DFT_DEP_SUFFIX@
 TEST_ARGS	= @LDFLAGS_STATIC@ @TEST_ARGS@ @LDFLAGS_SHARED@
@@ -219,6 +220,7 @@ win32con = $(srcdir)/win32con
 ################################################################################
 
 @MAKE_PHONY@.PHONY :	all
+@MAKE_PHONY@.PHONY :	check
 @MAKE_PHONY@.PHONY :	clean
 @MAKE_PHONY@.PHONY :	distclean
 @MAKE_PHONY@.PHONY :	libs
@@ -327,6 +329,7 @@ realclean :: distclean
 	( cd ../include && $(MAKE) $(TOP_MFLAGS) )
 
 # These rules build test-programs for the modules that have test-drivers
+@MAKE_PHONY@.PHONY :	test_progs
 test_progs : $(TEST_PROGS)
 
 ./link_test.c : $(base)/MKlib_gen.sh ../include/curses.h
@@ -357,6 +360,23 @@ report_hashing$x : \
 		$(srcdir)/report_hashing.c $(TEST_DEPS)
 	@ECHO_LD@ $(CC) -o $@ $(CFLAGS_DEFAULT) report_hashing.c $(TEST_LDFLAGS)
 
+# Verify that each header-file can be compiled without including another.
+@MAKE_PHONY@.PHONY :	check_headers
+check_headers:
+	@$(SHELL) -c "for header in *.h;\
+		do \
+			echo \"** testing \$${header}\" ; \
+			echo \"#include <\$${header}>\" >headers.c; \
+			echo \"int main(void) { return 0; }\" >>headers.c; \
+			$(CC) -c $(CFLAGS) $(CPPFLAGS) headers.c; \
+		done"
+	-@rm -f headers.*
+
+@MAKE_PHONY@.PHONY :	check_objects
+check_objects: test_progs
+
+check :: check_headers check_objects
+
 ###############################################################################
 # The remainder of this file is automatically generated during configuration
 ###############################################################################
diff --git a/ncurses/base/new_pair.c b/ncurses/base/new_pair.c
index 33369da4..70866c63 100644
--- a/ncurses/base/new_pair.c
+++ b/ncurses/base/new_pair.c
@@ -61,7 +61,7 @@
 
 #endif
 
-MODULE_ID("$Id: new_pair.c,v 1.22 2021/05/08 15:26:34 tom Exp $")
+MODULE_ID("$Id: new_pair.c,v 1.23 2021/08/16 22:11:26 tom Exp $")
 
 #if NCURSES_EXT_COLORS
 
@@ -106,7 +106,7 @@ dumpit(SCREEN *sp, int pair, const char *tag)
     size_t have = sizeof(bigbuf);
 
     _nc_STRCPY(p, tag, have);
-    for (n = 0; n < sp->_pair_limit; ++n) {
+    for (n = 0; n < sp->_pair_alloc; ++n) {
 	if (list[n].mode != cpFREE) {
 	    p += strlen(p);
 	    if ((size_t) (p - bigbuf) + 50 > have)
diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h
index 55446a89..5e490715 100644
--- a/ncurses/curses.priv.h
+++ b/ncurses/curses.priv.h
@@ -35,7 +35,7 @@
  ****************************************************************************/
 
 /*
- * $Id: curses.priv.h,v 1.642 2021/06/26 20:23:20 tom Exp $
+ * $Id: curses.priv.h,v 1.644 2021/08/18 21:55:42 tom Exp $
  *
  *	curses.priv.h
  *
@@ -396,7 +396,7 @@ typedef union {
 
 #include 
 
-#include 
+#include 
 #include 
 
 #define IsPreScreen(sp)      (((sp) != 0) && sp->_prescreen)
@@ -799,12 +799,6 @@ typedef struct _SLK {
 
 #endif	/* USE_TERMLIB */
 
-typedef	struct {
-	WINDOW *win;		/* the window used in the hook      */
-	int	line;		/* lines to take, < 0 => from bottom*/
-	int	(*hook)(WINDOW *, int); /* callback for user	    */
-} ripoff_t;
-
 #if USE_GPM_SUPPORT
 #undef buttons			/* term.h defines this, and gpm uses it! */
 #include 
@@ -832,16 +826,6 @@ typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *);
 #endif /* HAVE_LIBDL */
 #endif /* USE_GPM_SUPPORT */
 
-typedef struct {
-    long sequence;
-    bool last_used;
-    char *fix_sgr0;		/* this holds the filtered sgr0 string */
-    char *last_bufp;		/* help with fix_sgr0 leak */
-    TERMINAL *last_term;
-} TGETENT_CACHE;
-
-#define TGETENT_MAX 4
-
 /*
  * When converting from terminfo to termcap, check for cases where we can trim
  * octal escapes down to 2-character form.  It is useful for terminfo format
@@ -852,46 +836,6 @@ typedef struct {
 
 #define isoctal(c) ((c) >= '0' && (c) <= '7')
 
-/*
- * State of tparm().
- */
-#define STACKSIZE 20
-
-typedef struct {
-	union {
-		int	num;
-		char	*str;
-	} data;
-	bool num_type;
-} STACK_FRAME;
-
-#define NUM_VARS 26
-
-typedef struct {
-	const char	*tparam_base;
-
-	STACK_FRAME	stack[STACKSIZE];
-	int		stack_ptr;
-
-	char		*out_buff;
-	size_t		out_size;
-	size_t		out_used;
-
-	char		*fmt_buff;
-	size_t		fmt_size;
-
-	int		dynamic_var[NUM_VARS];
-	int		static_vars[NUM_VARS];
-#ifdef TRACE
-	const char	*tname;
-#endif
-} TPARM_STATE;
-
-typedef struct {
-    char *text;
-    size_t size;
-} TRACEBUF;
-
 /*
  * The filesystem database normally uses a single-letter for the lower level
  * of directories.  Use a hexadecimal code for filesystems which do not
@@ -922,132 +866,8 @@ struct DriverTCB; /* Terminal Control Block forward declaration */
 #define INIT_TERM_DRIVER()	/* nothing */
 #endif
 
-typedef struct {
-    const char *name;
-    char *value;
-} ITERATOR_VARS;
-
-/*
- * Global data which is not specific to a screen.
- */
-typedef struct {
-	SIG_ATOMIC_T	have_sigtstp;
-	SIG_ATOMIC_T	have_sigwinch;
-	SIG_ATOMIC_T	cleanup_nested;
-
-	bool		init_signals;
-	bool		init_screen;
-
-	char		*comp_sourcename;
-	char		*comp_termtype;
-
-	bool		have_tic_directory;
-	bool		keep_tic_directory;
-	const char	*tic_directory;
-
-	char		*dbi_list;
-	int		dbi_size;
-
-	char		*first_name;
-	char		**keyname_table;
-	int		init_keyname;
-
-	int		slk_format;
-
-	int		getstr_limit;	/* getstr_limit based on POSIX LINE_MAX */
-
-	char		*safeprint_buf;
-	size_t		safeprint_used;
-
-	TGETENT_CACHE	tgetent_cache[TGETENT_MAX];
-	int		tgetent_index;
-	long		tgetent_sequence;
-
-	char		*dbd_blob;	/* string-heap for dbd_list[] */
-	char		**dbd_list;	/* distinct places to look for data */
-	int		dbd_size;	/* length of dbd_list[] */
-	time_t		dbd_time;	/* cache last updated */
-	ITERATOR_VARS	dbd_vars[dbdLAST];
-
-#if HAVE_TSEARCH
-	void		*cached_tparm;
-	int		count_tparm;
-#endif /* HAVE_TSEARCH */
-
-#ifdef USE_TERM_DRIVER
-	int		(*term_driver)(struct DriverTCB*, const char*, int*);
-#endif
-
-#ifndef USE_SP_WINDOWLIST
-	WINDOWLIST	*_nc_windowlist;
-#define WindowList(sp)	_nc_globals._nc_windowlist
-#endif
-
-#if USE_HOME_TERMINFO
-	char		*home_terminfo;
-#endif
-
-#if !USE_SAFE_SPRINTF
-	int		safeprint_cols;
-	int		safeprint_rows;
-#endif
-
-#ifdef USE_PTHREADS
-	pthread_mutex_t	mutex_curses;
-	pthread_mutex_t	mutex_prescreen;
-	pthread_mutex_t	mutex_screen;
-	pthread_mutex_t	mutex_update;
-	pthread_mutex_t	mutex_tst_tracef;
-	pthread_mutex_t	mutex_tracef;
-	int		nested_tracef;
-	int		use_pthreads;
-#define _nc_use_pthreads	_nc_globals.use_pthreads
-#if USE_PTHREADS_EINTR
-	pthread_t	read_thread;		/* The reading thread */
-#endif
-#endif
-#if USE_WIDEC_SUPPORT
-	char		key_name[MB_LEN_MAX + 1];
-#endif
-
-#ifdef TRACE
-	bool		trace_opened;
-	char		trace_fname[PATH_MAX];
-	int		trace_level;
-	FILE		*trace_fp;
-	int		trace_fd;
-
-	char		*tracearg_buf;
-	size_t		tracearg_used;
-
-	TRACEBUF	*tracebuf_ptr;
-	size_t		tracebuf_used;
-
-	char		tracechr_buf[40];
-
-	char		*tracedmp_buf;
-	size_t		tracedmp_used;
-
-	unsigned char	*tracetry_buf;
-	size_t		tracetry_used;
-
-	char		traceatr_color_buf[2][80];
-	int		traceatr_color_sel;
-	int		traceatr_color_last;
-#if !defined(USE_PTHREADS) && USE_REENTRANT
-	int		nested_tracef;
-#endif
-#endif	/* TRACE */
-
-#if NO_LEAKS
-	bool		leak_checking;
-#endif
-} NCURSES_GLOBALS;
-
 extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
 
-#define N_RIPS 5
-
 /* The limit reserves one byte for a terminating NUL */
 #define my_getstr_limit	(_nc_globals.getstr_limit - 1)
 #define _nc_getstr_limit(n) \
@@ -1057,54 +877,6 @@ extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
 	    ? my_getstr_limit \
 	    : (n)))
 
-#ifdef USE_PTHREADS
-typedef struct _prescreen_list {
-	struct _prescreen_list *next;
-	pthread_t id;
-	struct screen *sp;
-} PRESCREEN_LIST;
-#endif
-
-/*
- * Global data which can be swept up into a SCREEN when one is created.
- * It may be modified before the next SCREEN is created.
- */
-typedef struct {
-#ifdef USE_PTHREADS
-	PRESCREEN_LIST *allocated;
-#else
-	struct screen * allocated;
-#endif
-	bool		use_env;
-	bool		filter_mode;
-	attr_t		previous_attr;
-	TPARM_STATE	tparm_state;
-	TTY		*saved_tty;	/* savetty/resetty information	    */
-	bool		use_tioctl;
-	NCURSES_SP_OUTC	_outch;		/* output handler if not putc */
-#ifndef USE_SP_RIPOFF
-	ripoff_t	rippedoff[N_RIPS];
-	ripoff_t	*rsp;
-#endif
-#if NCURSES_NO_PADDING
-	bool		_no_padding;	/* flag to set if padding disabled  */
-#endif
-#if BROKEN_LINKER || USE_REENTRANT
-	chtype		*real_acs_map;
-	int		_LINES;
-	int		_COLS;
-	int		_TABSIZE;
-	int		_ESCDELAY;
-	TERMINAL	*_cur_term;
-#endif
-#ifdef TRACE
-#if BROKEN_LINKER || USE_REENTRANT
-	long		_outchars;
-	const char	*_tputs_trace;
-#endif
-#endif
-} NCURSES_PRESCREEN;
-
 /*
  * Use screen-specific ripoff data (for softkeys) rather than global.
  */
diff --git a/ncurses/llib-lncurses b/ncurses/llib-lncurses
index f0820f67..a0dc78e0 100644
--- a/ncurses/llib-lncurses
+++ b/ncurses/llib-lncurses
@@ -2805,6 +2805,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -3615,6 +3628,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -3639,6 +3653,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
@@ -4201,7 +4220,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-lncursest b/ncurses/llib-lncursest
index 48a31eb4..fe9e11c6 100644
--- a/ncurses/llib-lncursest
+++ b/ncurses/llib-lncursest
@@ -2814,6 +2814,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -3700,6 +3713,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -3724,6 +3738,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
@@ -4322,7 +4341,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-lncursestw b/ncurses/llib-lncursestw
index c98f74f7..71b51822 100644
--- a/ncurses/llib-lncursestw
+++ b/ncurses/llib-lncursestw
@@ -3753,6 +3753,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -4661,6 +4674,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -4685,6 +4699,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
@@ -5323,7 +5342,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-lncursesw b/ncurses/llib-lncursesw
index f5f1bb3c..802740dd 100644
--- a/ncurses/llib-lncursesw
+++ b/ncurses/llib-lncursesw
@@ -3744,6 +3744,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -4576,6 +4589,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -4600,6 +4614,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
@@ -5202,7 +5221,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-ltic b/ncurses/llib-ltic
index d2326f03..2e407fd0 100644
--- a/ncurses/llib-ltic
+++ b/ncurses/llib-ltic
@@ -48,7 +48,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-ltict b/ncurses/llib-ltict
index 2e59b9f0..3a93b75c 100644
--- a/ncurses/llib-ltict
+++ b/ncurses/llib-ltict
@@ -48,7 +48,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-ltictw b/ncurses/llib-ltictw
index d2326f03..2e407fd0 100644
--- a/ncurses/llib-ltictw
+++ b/ncurses/llib-ltictw
@@ -48,7 +48,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-lticw b/ncurses/llib-lticw
index d2326f03..2e407fd0 100644
--- a/ncurses/llib-lticw
+++ b/ncurses/llib-lticw
@@ -48,7 +48,7 @@ ENTRY	*_nc_copy_entry(
 
 #undef _nc_save_str
 char	*_nc_save_str(
-		const char *const string)
+		const char *string)
 		{ return(*(char **)0); }
 
 #undef _nc_wrap_entry
diff --git a/ncurses/llib-ltinfo b/ncurses/llib-ltinfo
index ec24d160..da64694e 100644
--- a/ncurses/llib-ltinfo
+++ b/ncurses/llib-ltinfo
@@ -76,6 +76,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -886,6 +899,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -910,6 +924,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
diff --git a/ncurses/llib-ltinfot b/ncurses/llib-ltinfot
index 2bb72bd7..0980445c 100644
--- a/ncurses/llib-ltinfot
+++ b/ncurses/llib-ltinfot
@@ -76,6 +76,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -962,6 +975,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -986,6 +1000,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
diff --git a/ncurses/llib-ltinfotw b/ncurses/llib-ltinfotw
index 4fd95bfd..0fd8d287 100644
--- a/ncurses/llib-ltinfotw
+++ b/ncurses/llib-ltinfotw
@@ -76,6 +76,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -984,6 +997,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -1008,6 +1022,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
diff --git a/ncurses/llib-ltinfow b/ncurses/llib-ltinfow
index 1c3a2f22..93c9274e 100644
--- a/ncurses/llib-ltinfow
+++ b/ncurses/llib-ltinfow
@@ -76,6 +76,19 @@ NCURSES_BOOL _nc_is_file_path(
 int	_nc_env_access(void)
 		{ return(*(int *)0); }
 
+#undef _nc_safe_fopen
+FILE	*_nc_safe_fopen(
+		const char *path,
+		const char *mode)
+		{ return(*(FILE **)0); }
+
+#undef _nc_safe_open3
+int	_nc_safe_open3(
+		const char *path,
+		int	flags,
+		mode_t	mode)
+		{ return(*(int *)0); }
+
 /* ./tinfo/add_tries.c */
 
 #undef _nc_add_to_try
@@ -908,6 +921,7 @@ int	_nc_tparm_err;
 
 #undef _nc_tparm_analyze
 int	_nc_tparm_analyze(
+		TERMINAL *term,
 		const char *string,
 		char	**p_is_s,
 		int	*_nc_popcount)
@@ -932,6 +946,11 @@ char	*_nc_tiparm(
 		...)
 		{ return(*(char **)0); }
 
+#undef _nc_reset_tparm
+void	_nc_reset_tparm(
+		TERMINAL *term)
+		{ /* void */ }
+
 /* ./tinfo/lib_tputs.c */
 
 #undef PC
diff --git a/ncurses/new_pair.h b/ncurses/new_pair.h
index dfda8907..bc031a70 100644
--- a/ncurses/new_pair.h
+++ b/ncurses/new_pair.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey                                     *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
  * Copyright 2017 Free Software Foundation, Inc.                            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -34,13 +34,20 @@
 /*
  * Common type definitions and macros for new_pair.c, lib_color.c
  *
- * $Id: new_pair.h,v 1.11 2020/04/11 16:43:47 tom Exp $
+ * $Id: new_pair.h,v 1.12 2021/08/18 19:18:12 tom Exp $
  */
 
 #ifndef NEW_PAIR_H
 #define NEW_PAIR_H 1
 /* *INDENT-OFF* */
 
+#include 
+#include 
+
+#include 
+
+typedef struct screen  SCREEN;
+
 #define LIMIT_TYPED(n,t) \
 	(t)(((n) > MAX_OF_TYPE(t)) \
 	    ? MAX_OF_TYPE(t) \
diff --git a/ncurses/report_offsets.c b/ncurses/report_offsets.c
index 2e7083a1..83f6f381 100644
--- a/ncurses/report_offsets.c
+++ b/ncurses/report_offsets.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey                                     *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
  * Copyright 2017 Free Software Foundation, Inc.                            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -33,7 +33,7 @@
 
 #include 
 
-MODULE_ID("$Id: report_offsets.c,v 1.21 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: report_offsets.c,v 1.22 2021/08/19 19:51:33 tom Exp $")
 
 #define show_size(type) \
 	flag = 0; \
@@ -175,6 +175,7 @@ main(void)
     show_offset(TERMINAL, Nttyb);
     show_offset(TERMINAL, _baudrate);
     show_offset(TERMINAL, _termname);
+    show_offset(TERMINAL, tparm_state);
 #if HAVE_INIT_EXTENDED_COLOR
     show_COLORS(TERMINAL, type2);
 #endif
@@ -186,6 +187,15 @@ main(void)
     show_OPTION(TERMTYPE, ext_Strings);
 #endif
 
+    printf("\n");
+    show_size(TPARM_STATE);
+    show_offset(TPARM_STATE, stack);
+    show_offset(TPARM_STATE, stack_ptr);
+    show_offset(TPARM_STATE, out_buff);
+    show_offset(TPARM_STATE, fmt_buff);
+    show_offset(TPARM_STATE, static_vars);
+    show_TRACES(TPARM_STATE, tname);
+
     printf("\n");
     show_size(WINDOW);
     show_WIDECH(WINDOW, _bkgrnd);
@@ -194,6 +204,11 @@ main(void)
     printf("\n");
     show_size(NCURSES_GLOBALS);
     show_offset(NCURSES_GLOBALS, init_signals);
+    show_offset(NCURSES_GLOBALS, tgetent_cache);
+    show_offset(NCURSES_GLOBALS, dbd_vars);
+#if HAVE_TSEARCH
+    show_offset(NCURSES_GLOBALS, cached_tparm);
+#endif
     show_DRIVER(NCURSES_GLOBALS, term_driver);
     show_NORMAL(NCURSES_GLOBALS, _nc_windowlist);
 #if USE_HOME_TERMINFO
@@ -212,10 +227,13 @@ main(void)
 
     printf("\n");
     show_size(NCURSES_PRESCREEN);
+    show_offset(NCURSES_PRESCREEN, tparm_state);
     show_offset(NCURSES_PRESCREEN, saved_tty);
     show_offset(NCURSES_PRESCREEN, use_tioctl);
     show_offset(NCURSES_PRESCREEN, _outch);
+#ifndef USE_SP_RIPOFF
     show_NORMAL(NCURSES_PRESCREEN, rippedoff);
+#endif
 #if NCURSES_NO_PADDING
     show_OPTION(NCURSES_PRESCREEN, _no_padding);
 #endif
@@ -224,6 +242,9 @@ main(void)
 #else
     show_REENTR(NCURSES_PRESCREEN, real_acs_map);
 #endif
+#if BROKEN_LINKER || USE_REENTRANT
+    show_TRACES(NCURSES_PRESCREEN, _outchars);
+#endif
 
     return EXIT_SUCCESS;
 }
diff --git a/ncurses/term.priv.h b/ncurses/term.priv.h
new file mode 100644
index 00000000..f31e9f58
--- /dev/null
+++ b/ncurses/term.priv.h
@@ -0,0 +1,330 @@
+/****************************************************************************
+ * Copyright 2021 Thomas E. Dickey                                          *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "Software"), to deal in the Software without restriction, including      *
+ * without limitation the rights to use, copy, modify, merge, publish,      *
+ * distribute, distribute with modifications, sublicense, and/or sell       *
+ * copies of the Software, and to permit persons to whom the Software is    *
+ * furnished to do so, subject to the following conditions:                 *
+ *                                                                          *
+ * The above copyright notice and this permission notice shall be included  *
+ * in all copies or substantial portions of the Software.                   *
+ *                                                                          *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
+ *                                                                          *
+ * Except as contained in this notice, the name(s) of the above copyright   *
+ * holders shall not be used in advertising or otherwise to promote the     *
+ * sale, use or other dealings in this Software without prior written       *
+ * authorization.                                                           *
+ ****************************************************************************/
+
+/*
+ * $Id: term.priv.h,v 1.4 2021/08/19 20:02:09 tom Exp $
+ *
+ *	term.priv.h
+ *
+ *	Header file for terminfo library objects which are private to
+ *	the library.
+ *
+ */
+
+#ifndef _TERM_PRIV_H
+#define _TERM_PRIV_H 1
+/* *INDENT-OFF* */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+
+#undef NCURSES_OPAQUE
+#define NCURSES_INTERNALS 1
+#define NCURSES_OPAQUE 0
+
+#include 		/* PATH_MAX */
+#include 		/* sig_atomic_t */
+#include 		/* time_t */
+#include 		/* time_t */
+
+/*
+ * State of tparm().
+ */
+#define STACKSIZE 20
+
+typedef struct {
+	union {
+		int	num;
+		char *	str;
+	} data;
+	bool num_type;
+} STACK_FRAME;
+
+#define NUM_VARS 26
+
+typedef struct {
+	const char *	tparam_base;
+
+	STACK_FRAME	stack[STACKSIZE];
+	int		stack_ptr;
+
+	char *		out_buff;
+	size_t		out_size;
+	size_t		out_used;
+
+	char *		fmt_buff;
+	size_t		fmt_size;
+
+	int		static_vars[NUM_VARS];
+#ifdef TRACE
+	const char *	tname;
+#endif
+} TPARM_STATE;
+
+typedef struct {
+	char *		text;
+	size_t		size;
+} TRACEBUF;
+
+typedef struct {
+	const char *	name;
+	char *		value;
+} ITERATOR_VARS;
+
+/*
+ * Internals for term.h
+ */
+
+#if NCURSES_EXT_COLORS
+typedef struct termtype2  TERMTYPE2;
+#endif
+
+typedef struct term {			/* describe an actual terminal */
+	TERMTYPE	type;		/* terminal type description */
+	short		Filedes;	/* file description being written to */
+	TTY		Ottyb;		/* original state of the terminal */
+	TTY		Nttyb;		/* current state of the terminal */
+	int		_baudrate;	/* used to compute padding */
+	char *		_termname;	/* used for termname() */
+	TPARM_STATE	tparm_state;
+#if NCURSES_EXT_COLORS
+	TERMTYPE2	type2;		/* extended terminal type description */
+#endif
+} TERMINAL;
+
+/*
+ * Internals for soft-keys
+ */
+typedef	struct {
+	WINDOW *	win;		/* the window used in the hook      */
+	int		line;		/* lines to take, < 0 => from bottom*/
+	int		(*hook)(WINDOW *, int); /* callback for user	    */
+} ripoff_t;
+
+/*
+ * Internals for tgetent
+ */
+typedef struct {
+	long		sequence;
+	bool		last_used;
+	char *		fix_sgr0;	/* this holds the filtered sgr0 string */
+	char *		last_bufp;	/* help with fix_sgr0 leak */
+	TERMINAL *	last_term;
+} TGETENT_CACHE;
+
+#define TGETENT_MAX 4
+
+#include 		/* dbdLAST */
+
+#ifdef USE_TERM_DRIVER
+struct DriverTCB; /* Terminal Control Block forward declaration */
+#endif
+
+/*
+ * Global data which is not specific to a screen.
+ */
+typedef struct {
+	SIG_ATOMIC_T	have_sigtstp;
+	SIG_ATOMIC_T	have_sigwinch;
+	SIG_ATOMIC_T	cleanup_nested;
+
+	bool		init_signals;
+	bool		init_screen;
+
+	char *		comp_sourcename;
+	char *		comp_termtype;
+
+	bool		have_tic_directory;
+	bool		keep_tic_directory;
+	const char *	tic_directory;
+
+	char *		dbi_list;
+	int		dbi_size;
+
+	char *		first_name;
+	char **		keyname_table;
+	int		init_keyname;
+
+	int		slk_format;
+
+	int		getstr_limit;	/* getstr_limit based on POSIX LINE_MAX */
+
+	char *		safeprint_buf;
+	size_t		safeprint_used;
+
+	TGETENT_CACHE	tgetent_cache[TGETENT_MAX];
+	int		tgetent_index;
+	long		tgetent_sequence;
+
+	char *		dbd_blob;	/* string-heap for dbd_list[] */
+	char **		dbd_list;	/* distinct places to look for data */
+	int		dbd_size;	/* length of dbd_list[] */
+	time_t		dbd_time;	/* cache last updated */
+	ITERATOR_VARS	dbd_vars[dbdLAST];
+
+#if HAVE_TSEARCH
+	void *		cached_tparm;
+	int		count_tparm;
+#endif /* HAVE_TSEARCH */
+
+#ifdef USE_TERM_DRIVER
+	int		(*term_driver)(struct DriverTCB*, const char*, int*);
+#endif
+
+#define WINDOWLIST struct _win_list
+
+#ifndef USE_SP_WINDOWLIST
+	WINDOWLIST *	_nc_windowlist;
+#define WindowList(sp)	_nc_globals._nc_windowlist
+#endif
+
+#if USE_HOME_TERMINFO
+	char *		home_terminfo;
+#endif
+
+#if !USE_SAFE_SPRINTF
+	int		safeprint_cols;
+	int		safeprint_rows;
+#endif
+
+#ifdef USE_PTHREADS
+	pthread_mutex_t	mutex_curses;
+	pthread_mutex_t	mutex_prescreen;
+	pthread_mutex_t	mutex_screen;
+	pthread_mutex_t	mutex_update;
+	pthread_mutex_t	mutex_tst_tracef;
+	pthread_mutex_t	mutex_tracef;
+	int		nested_tracef;
+	int		use_pthreads;
+#define _nc_use_pthreads	_nc_globals.use_pthreads
+#if USE_PTHREADS_EINTR
+	pthread_t	read_thread;	/* The reading thread */
+#endif
+#endif
+#if USE_WIDEC_SUPPORT
+	char		key_name[MB_LEN_MAX + 1];
+#endif
+
+#ifdef TRACE
+	bool		trace_opened;
+	char		trace_fname[PATH_MAX];
+	int		trace_level;
+	FILE *		trace_fp;
+	int		trace_fd;
+
+	char *		tracearg_buf;
+	size_t		tracearg_used;
+
+	TRACEBUF *	tracebuf_ptr;
+	size_t		tracebuf_used;
+
+	char		tracechr_buf[40];
+
+	char *		tracedmp_buf;
+	size_t		tracedmp_used;
+
+	unsigned char *	tracetry_buf;
+	size_t		tracetry_used;
+
+	char		traceatr_color_buf[2][80];
+	int		traceatr_color_sel;
+	int		traceatr_color_last;
+#if !defined(USE_PTHREADS) && USE_REENTRANT
+	int		nested_tracef;
+#endif
+#endif	/* TRACE */
+
+#if NO_LEAKS
+	bool		leak_checking;
+#endif
+} NCURSES_GLOBALS;
+
+extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
+
+#define N_RIPS 5
+
+#ifdef USE_PTHREADS
+typedef struct _prescreen_list {
+	struct _prescreen_list *next;
+	pthread_t	id;
+	struct screen *	sp;
+} PRESCREEN_LIST;
+#endif
+
+/*
+ * Global data which can be swept up into a SCREEN when one is created.
+ * It may be modified before the next SCREEN is created.
+ */
+typedef struct {
+#ifdef USE_PTHREADS
+	PRESCREEN_LIST *allocated;
+#else
+	struct screen * allocated;
+#endif
+	bool		use_env;
+	bool		filter_mode;
+	attr_t		previous_attr;
+	TPARM_STATE	tparm_state;
+	TTY *		saved_tty;	/* savetty/resetty information	  */
+	bool		use_tioctl;
+	NCURSES_SP_OUTC	_outch;		/* output handler if not putc */
+#ifndef USE_SP_RIPOFF
+	ripoff_t	rippedoff[N_RIPS];
+	ripoff_t *	rsp;
+#endif
+#if NCURSES_NO_PADDING
+	bool		_no_padding;	/* flag to set if padding disabled */
+#endif
+#if BROKEN_LINKER || USE_REENTRANT
+	chtype *	real_acs_map;
+	int		_LINES;
+	int		_COLS;
+	int		_TABSIZE;
+	int		_ESCDELAY;
+	TERMINAL *	_cur_term;
+#endif
+#ifdef TRACE
+#if BROKEN_LINKER || USE_REENTRANT
+	long		_outchars;
+	const char *	_tputs_trace;
+#endif
+#endif
+} NCURSES_PRESCREEN;
+
+extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
+
+#ifdef __cplusplus
+}
+#endif
+
+/* *INDENT-ON* */
+
+#endif /* _TERM_PRIV_H */
diff --git a/ncurses/tinfo/lib_data.c b/ncurses/tinfo/lib_data.c
index 39274f4e..6a06cd77 100644
--- a/ncurses/tinfo/lib_data.c
+++ b/ncurses/tinfo/lib_data.c
@@ -43,7 +43,7 @@
 
 #include 
 
-MODULE_ID("$Id: lib_data.c,v 1.81 2020/06/13 22:01:14 tom Exp $")
+MODULE_ID("$Id: lib_data.c,v 1.84 2021/08/19 08:01:33 tom Exp $")
 
 /*
  * OS/2's native linker complains if we don't initialize public data when
@@ -251,7 +251,6 @@ NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = {
 	NULL,			/* fmt_buff */
 	0,			/* fmt_size */
 
-	NUM_VARS_0s,		/* dynamic_var */
 	NUM_VARS_0s,		/* static_vars */
 #ifdef TRACE
 	NULL,			/* tname */
diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c
index 3fe42399..72d88138 100644
--- a/ncurses/tinfo/lib_tparm.c
+++ b/ncurses/tinfo/lib_tparm.c
@@ -53,7 +53,7 @@
 #include 
 #include 
 
-MODULE_ID("$Id: lib_tparm.c,v 1.131 2021/04/03 22:05:59 tom Exp $")
+MODULE_ID("$Id: lib_tparm.c,v 1.134 2021/08/21 21:52:08 tom Exp $")
 
 /*
  *	char *
@@ -117,9 +117,14 @@ MODULE_ID("$Id: lib_tparm.c,v 1.131 2021/04/03 22:05:59 tom Exp $")
 
 NCURSES_EXPORT_VAR(int) _nc_tparm_err = 0;
 
-#define TPS(var) _nc_prescreen.tparm_state.var
+#define TPS(var) tps->var
 #define popcount _nc_popcount	/* workaround for NetBSD 6.0 defect */
 
+#define get_tparm_state(term) \
+	    (term != NULL \
+	      ? &(term->tparm_state) \
+	      : &(_nc_prescreen.tparm_state))
+
 #define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
 #define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
 #define tc_BUMP()  if (level < 0 && number < 2) number++
@@ -171,6 +176,7 @@ visit_nodes(const void *nodep, const VISIT which, const int depth)
 NCURSES_EXPORT(void)
 _nc_free_tparm(void)
 {
+    TPARM_STATE *tps = get_tparm_state(cur_term);	/* FIXME */
 #if HAVE_TSEARCH
     if (MyCount != 0) {
 	delete_tparm = typeCalloc(TPARM_DATA *, MyCount);
@@ -200,105 +206,156 @@ _nc_free_tparm(void)
 }
 #endif
 
-static NCURSES_INLINE void
-get_space(size_t need)
+static int
+tparm_error(TPARM_STATE *tps, const char *message)
 {
-    need += TPS(out_used);
-    if (need > TPS(out_size)) {
-	TPS(out_size) = need * 2;
-	TYPE_REALLOC(char, TPS(out_size), TPS(out_buff));
-    }
+    DEBUG(2, ("%s: %s", message, _nc_visbuf(TPS(tparam_base))));
+    return ++_nc_tparm_err;
 }
 
+#define get_space(tps, need) \
+{ \
+    size_t need2get = need + TPS(out_used); \
+    if (need2get > TPS(out_size)) { \
+	TPS(out_size) = need2get * 2; \
+	TYPE_REALLOC(char, TPS(out_size), TPS(out_buff)); \
+    } \
+}
+
+#if NCURSES_EXPANDED
 static NCURSES_INLINE void
-save_text(const char *fmt, const char *s, int len)
-{
-    size_t s_len = (size_t) len + strlen(s) + strlen(fmt);
-    get_space(s_len + 1);
+  (get_space) (TPARM_STATE *tps, size_t need) {
+    get_space(tps, need);
+}
 
-    _nc_SPRINTF(TPS(out_buff) + TPS(out_used),
-		_nc_SLIMIT(TPS(out_size) - TPS(out_used))
-		fmt, s);
-    TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used));
+#undef get_space
+#endif
+
+#define save_text(tps, fmt, s, len) \
+{ \
+    size_t s_len = (size_t) len + strlen(s) + strlen(fmt); \
+    get_space(tps, s_len + 1); \
+    _nc_SPRINTF(TPS(out_buff) + TPS(out_used), \
+		_nc_SLIMIT(TPS(out_size) - TPS(out_used)) \
+		fmt, s); \
+    TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used)); \
 }
 
+#if NCURSES_EXPANDED
 static NCURSES_INLINE void
-save_number(const char *fmt, int number, int len)
-{
-    size_t s_len = (size_t) len + 30 + strlen(fmt);
-    get_space(s_len + 1);
+  (save_text) (TPARM_STATE *tps, const char *fmt, const char *s, int len) {
+    save_text(tps, fmt, s, len);
+}
+
+#undef save_text
+#endif
 
-    _nc_SPRINTF(TPS(out_buff) + TPS(out_used),
-		_nc_SLIMIT(TPS(out_size) - TPS(out_used))
-		fmt, number);
-    TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used));
+#define save_number(tps, fmt, number, len) \
+{ \
+    size_t s_len = (size_t) len + 30 + strlen(fmt); \
+    get_space(tps, s_len + 1); \
+    _nc_SPRINTF(TPS(out_buff) + TPS(out_used), \
+		_nc_SLIMIT(TPS(out_size) - TPS(out_used)) \
+		fmt, number); \
+    TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used)); \
 }
 
+#if NCURSES_EXPANDED
 static NCURSES_INLINE void
-save_char(int c)
-{
-    if (c == 0)
-	c = 0200;
-    get_space((size_t) 1);
-    TPS(out_buff)[TPS(out_used)++] = (char) c;
+  (save_number) (TPARM_STATE *tps, const char *fmt, int number, int len) {
+    save_number(tps, fmt, number, len);
+}
+
+#undef save_number
+#endif
+
+#define save_char(tps, c) \
+{ \
+    get_space(tps, (size_t) 1); \
+    TPS(out_buff)[TPS(out_used)++] = (char) ((c == 0) ? 0200 : c); \
 }
 
+#if NCURSES_EXPANDED
 static NCURSES_INLINE void
-npush(int x)
-{
-    if (TPS(stack_ptr) < STACKSIZE) {
-	TPS(stack)[TPS(stack_ptr)].num_type = TRUE;
-	TPS(stack)[TPS(stack_ptr)].data.num = x;
-	TPS(stack_ptr)++;
-    } else {
-	DEBUG(2, ("npush: stack overflow: %s", _nc_visbuf(TPS(tparam_base))));
-	_nc_tparm_err++;
-    }
+  (save_char) (TPARM_STATE *tps, int c) {
+    save_char(tps, c);
 }
 
-static NCURSES_INLINE int
-npop(void)
-{
-    int result = 0;
-    if (TPS(stack_ptr) > 0) {
-	TPS(stack_ptr)--;
-	if (TPS(stack)[TPS(stack_ptr)].num_type)
-	    result = TPS(stack)[TPS(stack_ptr)].data.num;
-    } else {
-	DEBUG(2, ("npop: stack underflow: %s", _nc_visbuf(TPS(tparam_base))));
-	_nc_tparm_err++;
-    }
-    return result;
+#undef save_char
+#endif
+
+#define npush(tps, x) \
+{ \
+    if (TPS(stack_ptr) < STACKSIZE) { \
+	TPS(stack)[TPS(stack_ptr)].num_type = TRUE; \
+	TPS(stack)[TPS(stack_ptr)].data.num = x; \
+	TPS(stack_ptr)++; \
+    } else { \
+	(void) tparm_error(tps, "npush: stack overflow"); \
+    } \
 }
 
+#if NCURSES_EXPANDED
 static NCURSES_INLINE void
-spush(char *x)
-{
-    if (TPS(stack_ptr) < STACKSIZE) {
-	TPS(stack)[TPS(stack_ptr)].num_type = FALSE;
-	TPS(stack)[TPS(stack_ptr)].data.str = x;
-	TPS(stack_ptr)++;
-    } else {
-	DEBUG(2, ("spush: stack overflow: %s", _nc_visbuf(TPS(tparam_base))));
-	_nc_tparm_err++;
-    }
+  (npush) (TPARM_STATE *tps, int x) {
+    npush(tps, x);
+}
+
+#undef npush
+#endif
+
+#define spush(tps, x) \
+{ \
+    if (TPS(stack_ptr) < STACKSIZE) { \
+	TPS(stack)[TPS(stack_ptr)].num_type = FALSE; \
+	TPS(stack)[TPS(stack_ptr)].data.str = x; \
+	TPS(stack_ptr)++; \
+    } else { \
+	(void) tparm_error(tps, "spush: stack overflow"); \
+    } \
 }
 
+#if NCURSES_EXPANDED
+static NCURSES_INLINE void
+  (spush) (TPARM_STATE *tps, char *x) {
+    spush(tps, x);
+}
+
+#undef spush
+#endif
+
+#define npop(tps) \
+    ((TPS(stack_ptr)-- > 0) \
+     ? ((TPS(stack)[TPS(stack_ptr)].num_type) \
+	 ? TPS(stack)[TPS(stack_ptr)].data.num \
+	 : 0) \
+     : (tparm_error(tps, "npop: stack underflow"), \
+        TPS(stack_ptr) = 0))
+
+#if NCURSES_EXPANDED
+static NCURSES_INLINE int
+  (npop) (TPARM_STATE *tps) {
+    return npop(tps);
+}
+#undef npop
+#endif
+
+#define spop(tps) \
+    ((TPS(stack_ptr)-- > 0) \
+     ? ((!TPS(stack)[TPS(stack_ptr)].num_type \
+        && TPS(stack)[TPS(stack_ptr)].data.str != 0) \
+         ? TPS(stack)[TPS(stack_ptr)].data.str \
+         : dummy) \
+     : (tparm_error(tps, "spop: stack underflow"), \
+        dummy))
+
+#if NCURSES_EXPANDED
 static NCURSES_INLINE char *
-spop(void)
-{
-    char *result = dummy;
-    if (TPS(stack_ptr) > 0) {
-	TPS(stack_ptr)--;
-	if (!TPS(stack)[TPS(stack_ptr)].num_type
-	    && TPS(stack)[TPS(stack_ptr)].data.str != 0)
-	    result = TPS(stack)[TPS(stack_ptr)].data.str;
-    } else {
-	DEBUG(2, ("spop: stack underflow: %s", _nc_visbuf(TPS(tparam_base))));
-	_nc_tparm_err++;
-    }
-    return result;
+  (spop) (TPARM_STATE *tps) {
+    return spop(tps);
 }
+#undef spop
+#endif
 
 static NCURSES_INLINE const char *
 parse_format(const char *s, char *format, int *len)
@@ -407,8 +464,9 @@ parse_format(const char *s, char *format, int *len)
  * may be cases that we cannot see the explicit parameter numbers.
  */
 NCURSES_EXPORT(int)
-_nc_tparm_analyze(const char *string, char **p_is_s, int *popcount)
+_nc_tparm_analyze(TERMINAL *term, const char *string, char **p_is_s, int *popcount)
 {
+    TPARM_STATE *tps = get_tparm_state(term);
     size_t len2;
     int i;
     int lastpop = -1;
@@ -541,8 +599,9 @@ _nc_tparm_analyze(const char *string, char **p_is_s, int *popcount)
  * TODO: cache the result so that this is done once per capability per term.
  */
 static int
-tparm_setup(const char *string, TPARM_DATA * result)
+tparm_setup(TERMINAL *term, const char *string, TPARM_DATA *result)
 {
+    TPARM_STATE *tps = get_tparm_state(term);
     int rc = OK;
 
     TPS(out_used) = 0;
@@ -558,8 +617,15 @@ tparm_setup(const char *string, TPARM_DATA * result)
 
 	result->format = string;
 	if ((ft = tfind(result, &MyCache, cmp_format)) != 0) {
+	    size_t len2;
 	    fs = *(TPARM_DATA **) ft;
 	    *result = *fs;
+	    if ((len2 = strlen(string)) + 2 > TPS(fmt_size)) {
+		TPS(fmt_size) += len2 + 2;
+		TPS(fmt_buff) = typeRealloc(char, TPS(fmt_size), TPS(fmt_buff));
+		if (TPS(fmt_buff) == 0)
+		    return ERR;
+	    }
 	} else
 #endif
 	{
@@ -568,7 +634,7 @@ tparm_setup(const char *string, TPARM_DATA * result)
 	     * string.  Use this value to limit the number of arguments copied
 	     * from the variable-length argument list.
 	     */
-	    result->num_parsed = _nc_tparm_analyze(string,
+	    result->num_parsed = _nc_tparm_analyze(term, string,
 						   result->p_is_s,
 						   &(result->num_popped));
 	    if (TPS(fmt_buff) == 0) {
@@ -619,7 +685,7 @@ tparm_setup(const char *string, TPARM_DATA * result)
  * long's, which is consistent with our va_arg() usage.
  */
 static void
-tparm_copy_valist(TPARM_DATA * data, int use_TPARM_ARG, va_list ap)
+tparm_copy_valist(TPARM_DATA *data, int use_TPARM_ARG, va_list ap)
 {
     int i;
 
@@ -646,7 +712,7 @@ tparm_copy_valist(TPARM_DATA * data, int use_TPARM_ARG, va_list ap)
  * will expand termcap strings OK.
  */
 static bool
-tparm_tc_compat(TPARM_DATA * data)
+tparm_tc_compat(TPARM_STATE *tps, TPARM_DATA *data)
 {
     bool termcap_hack = FALSE;
 
@@ -657,10 +723,11 @@ tparm_tc_compat(TPARM_DATA * data)
 
 	termcap_hack = TRUE;
 	for (i = data->num_parsed - 1; i >= 0; i--) {
-	    if (data->p_is_s[i])
-		spush(data->p_is_s[i]);
-	    else
-		npush((int) data->param[i]);
+	    if (data->p_is_s[i]) {
+		spush(tps, data->p_is_s[i]);
+	    } else {
+		npush(tps, (int) data->param[i]);
+	    }
 	}
     }
     return termcap_hack;
@@ -668,20 +735,20 @@ tparm_tc_compat(TPARM_DATA * data)
 
 #ifdef TRACE
 static void
-tparm_trace_call(const char *string, TPARM_DATA * data)
+tparm_trace_call(TPARM_STATE *tps, const char *string, TPARM_DATA *data)
 {
     if (USE_TRACEF(TRACE_CALLS)) {
 	int i;
 	for (i = 0; i < data->num_actual; i++) {
 	    if (data->p_is_s[i] != 0) {
-		save_text(", %s", _nc_visbuf(data->p_is_s[i]), 0);
+		save_text(tps, ", %s", _nc_visbuf(data->p_is_s[i]), 0);
 	    } else if ((long) data->param[i] > MAX_OF_TYPE(NCURSES_INT2) ||
 		       (long) data->param[i] < 0) {
 		_tracef("BUG: problem with tparm parameter #%d of %d",
 			i + 1, data->num_actual);
 		break;
 	    } else {
-		save_number(", %d", (int) data->param[i], 0);
+		save_number(tps, ", %d", (int) data->param[i], 0);
 	    }
 	}
 	_tracef(T_CALLED("%s(%s%s)"), TPS(tname), _nc_visbuf(string), TPS(out_buff));
@@ -691,27 +758,49 @@ tparm_trace_call(const char *string, TPARM_DATA * data)
 }
 
 #else
-#define tparm_trace_call(string, data)	/* nothing */
+#define tparm_trace_call(tps, string, data)	/* nothing */
 #endif /* TRACE */
 
+#define init_vars(name) \
+	if (!name##_used) { \
+	    name##_used = TRUE; \
+	    memset(name##_vars, 0, sizeof(name##_vars)); \
+	}
+
 static NCURSES_INLINE char *
-tparam_internal(const char *string, TPARM_DATA * data)
+tparam_internal(TPARM_STATE *tps, const char *string, TPARM_DATA *data)
 {
     int number;
     int len;
     int level;
     int x, y;
     int i;
+    const char *s;
     const char *cp = string;
     size_t len2 = strlen(cp);
     bool incremented_two = FALSE;
-    bool termcap_hack = tparm_tc_compat(data);
-
-    tparm_trace_call(string, data);
+    bool termcap_hack = tparm_tc_compat(tps, data);
+    /*
+     * SVr4 curses stores variables 'A' to 'Z' in the TERMINAL structure (so
+     * they are initialized once to zero), and variables 'a' to 'z' on the
+     * stack in tparm, referring to the former as "static" and the latter as
+     * "dynamic".  However, it makes no check to ensure that the "dynamic"
+     * variables are initialized.
+     *
+     * Solaris xpg4 curses makes no distinction between the upper/lower, and
+     * stores the common set of 26 variables on the stack, without initializing
+     * them.
+     *
+     * In ncurses, both sets of variables are initialized on the first use.
+     */
+    bool dynamic_used = FALSE;
+    int dynamic_vars[NUM_VARS];
+
+    tparm_trace_call(tps, string, data);
 
     while ((cp - string) < (int) len2) {
 	if (*cp != '%') {
-	    save_char(UChar(*cp));
+	    save_char(tps, UChar(*cp));
 	} else {
 	    TPS(tparam_base) = cp++;
 	    cp = parse_format(cp, TPS(fmt_buff), &len);
@@ -719,40 +808,44 @@ tparam_internal(const char *string, TPARM_DATA * data)
 	    default:
 		break;
 	    case '%':
-		save_char('%');
+		save_char(tps, '%');
 		break;
 
 	    case 'd':		/* FALLTHRU */
 	    case 'o':		/* FALLTHRU */
 	    case 'x':		/* FALLTHRU */
 	    case 'X':		/* FALLTHRU */
-		save_number(TPS(fmt_buff), npop(), len);
+		x = npop(tps);
+		save_number(tps, TPS(fmt_buff), x, len);
 		break;
 
 	    case 'c':		/* FALLTHRU */
-		save_char(npop());
+		x = npop(tps);
+		save_char(tps, x);
 		break;
 
 #ifdef EXP_XTERM_1005
 	    case 'u':
 		{
 		    unsigned char target[10];
-		    unsigned source = (unsigned) npop();
+		    unsigned source = (unsigned) npop(tps);
 		    int rc = _nc_conv_to_utf8(target, source, (unsigned)
 					      sizeof(target));
 		    int n;
 		    for (n = 0; n < rc; ++n) {
-			save_char(target[n]);
+			save_char(tps, target[n]);
 		    }
 		}
 		break;
 #endif
 	    case 'l':
-		npush((int) strlen(spop()));
+		s = spop(tps);
+		npush(tps, (int) strlen(s));
 		break;
 
 	    case 's':
-		save_text(TPS(fmt_buff), spop(), len);
+		s = spop(tps);
+		save_text(tps, TPS(fmt_buff), s, len);
 		break;
 
 	    case 'p':
@@ -760,9 +853,9 @@ tparam_internal(const char *string, TPARM_DATA * data)
 		i = (UChar(*cp) - '1');
 		if (i >= 0 && i < NUM_PARM) {
 		    if (data->p_is_s[i]) {
-			spush(data->p_is_s[i]);
+			spush(tps, data->p_is_s[i]);
 		    } else {
-			npush((int) data->param[i]);
+			npush(tps, (int) data->param[i]);
 		    }
 		}
 		break;
@@ -771,10 +864,11 @@ tparam_internal(const char *string, TPARM_DATA * data)
 		cp++;
 		if (isUPPER(*cp)) {
 		    i = (UChar(*cp) - 'A');
-		    TPS(static_vars)[i] = npop();
+		    TPS(static_vars)[i] = npop(tps);
 		} else if (isLOWER(*cp)) {
 		    i = (UChar(*cp) - 'a');
-		    TPS(dynamic_var)[i] = npop();
+		    init_vars(dynamic);
+		    dynamic_vars[i] = npop(tps);
 		}
 		break;
 
@@ -782,16 +876,17 @@ tparam_internal(const char *string, TPARM_DATA * data)
 		cp++;
 		if (isUPPER(*cp)) {
 		    i = (UChar(*cp) - 'A');
-		    npush(TPS(static_vars)[i]);
+		    npush(tps, TPS(static_vars)[i]);
 		} else if (isLOWER(*cp)) {
 		    i = (UChar(*cp) - 'a');
-		    npush(TPS(dynamic_var)[i]);
+		    init_vars(dynamic);
+		    npush(tps, dynamic_vars[i]);
 		}
 		break;
 
 	    case S_QUOTE:
 		cp++;
-		npush(UChar(*cp));
+		npush(tps, UChar(*cp));
 		cp++;
 		break;
 
@@ -802,83 +897,95 @@ tparam_internal(const char *string, TPARM_DATA * data)
 		    number = (number * 10) + (UChar(*cp) - '0');
 		    cp++;
 		}
-		npush(number);
+		npush(tps, number);
 		break;
 
 	    case '+':
-		npush(npop() + npop());
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x + y);
 		break;
 
 	    case '-':
-		y = npop();
-		x = npop();
-		npush(x - y);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x - y);
 		break;
 
 	    case '*':
-		npush(npop() * npop());
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x * y);
 		break;
 
 	    case '/':
-		y = npop();
-		x = npop();
-		npush(y ? (x / y) : 0);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, y ? (x / y) : 0);
 		break;
 
 	    case 'm':
-		y = npop();
-		x = npop();
-		npush(y ? (x % y) : 0);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, y ? (x % y) : 0);
 		break;
 
 	    case 'A':
-		y = npop();
-		x = npop();
-		npush(y && x);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, y && x);
 		break;
 
 	    case 'O':
-		y = npop();
-		x = npop();
-		npush(y || x);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, y || x);
 		break;
 
 	    case '&':
-		npush(npop() & npop());
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x & y);
 		break;
 
 	    case '|':
-		npush(npop() | npop());
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x | y);
 		break;
 
 	    case '^':
-		npush(npop() ^ npop());
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x ^ y);
 		break;
 
 	    case '=':
-		y = npop();
-		x = npop();
-		npush(x == y);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x == y);
 		break;
 
 	    case '<':
-		y = npop();
-		x = npop();
-		npush(x < y);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x < y);
 		break;
 
 	    case '>':
-		y = npop();
-		x = npop();
-		npush(x > y);
+		y = npop(tps);
+		x = npop(tps);
+		npush(tps, x > y);
 		break;
 
 	    case '!':
-		npush(!npop());
+		x = npop(tps);
+		npush(tps, !x);
 		break;
 
 	    case '~':
-		npush(~npop());
+		x = npop(tps);
+		npush(tps, ~x);
 		break;
 
 	    case 'i':
@@ -908,7 +1015,7 @@ tparam_internal(const char *string, TPARM_DATA * data)
 		break;
 
 	    case 't':
-		x = npop();
+		x = npop(tps);
 		if (!x) {
 		    /* scan forward for %e or %; at level zero */
 		    cp++;
@@ -967,7 +1074,7 @@ tparam_internal(const char *string, TPARM_DATA * data)
 	cp++;
     }				/* endwhile (*cp) */
 
-    get_space((size_t) 1);
+    get_space(tps, (size_t) 1);
     TPS(out_buff)[TPS(out_used)] = '\0';
 
     if (TPS(stack_ptr) && !_nc_tparm_err) {
@@ -986,22 +1093,23 @@ tparam_internal(const char *string, TPARM_DATA * data)
 NCURSES_EXPORT(char *)
 tparm(const char *string, ...)
 {
+    TPARM_STATE *tps = get_tparm_state(cur_term);
     TPARM_DATA myData;
     char *result = NULL;
 
     _nc_tparm_err = 0;
 #ifdef TRACE
-    TPS(tname) = "tparm";
+    tps->tname = "tparm";
 #endif /* TRACE */
 
-    if (tparm_setup(string, &myData) == OK) {
+    if (tparm_setup(cur_term, string, &myData) == OK) {
 	va_list ap;
 
 	va_start(ap, string);
 	tparm_copy_valist(&myData, TRUE, ap);
 	va_end(ap);
 
-	result = tparam_internal(string, &myData);
+	result = tparam_internal(tps, string, &myData);
     }
     return result;
 }
@@ -1020,15 +1128,16 @@ tparm(const char *string,
       TPARM_ARG a8,
       TPARM_ARG a9)
 {
+    TPARM_STATE *tps = get_tparm_state(cur_term);
     TPARM_DATA myData;
     char *result = NULL;
 
     _nc_tparm_err = 0;
 #ifdef TRACE
-    TPS(tname) = "tparm";
+    tps->tname = "tparm";
 #endif /* TRACE */
 
-    if (tparm_setup(string, &myData) == OK) {
+    if (tparm_setup(cur_term, string, &myData) == OK) {
 
 	myData.param[0] = a1;
 	myData.param[1] = a2;
@@ -1040,7 +1149,7 @@ tparm(const char *string,
 	myData.param[7] = a8;
 	myData.param[8] = a9;
 
-	result = tparam_internal(string, &myData);
+	result = tparam_internal(tps, string, &myData);
     }
     return result;
 }
@@ -1050,22 +1159,23 @@ tparm(const char *string,
 NCURSES_EXPORT(char *)
 tiparm(const char *string, ...)
 {
+    TPARM_STATE *tps = get_tparm_state(cur_term);
     TPARM_DATA myData;
     char *result = NULL;
 
     _nc_tparm_err = 0;
 #ifdef TRACE
-    TPS(tname) = "tiparm";
+    tps->tname = "tiparm";
 #endif /* TRACE */
 
-    if (tparm_setup(string, &myData) == OK) {
+    if (tparm_setup(cur_term, string, &myData) == OK) {
 	va_list ap;
 
 	va_start(ap, string);
 	tparm_copy_valist(&myData, FALSE, ap);
 	va_end(ap);
 
-	result = tparam_internal(string, &myData);
+	result = tparam_internal(tps, string, &myData);
     }
     return result;
 }
@@ -1076,15 +1186,16 @@ tiparm(const char *string, ...)
 NCURSES_EXPORT(char *)
 _nc_tiparm(int expected, const char *string, ...)
 {
+    TPARM_STATE *tps = get_tparm_state(cur_term);
     TPARM_DATA myData;
     char *result = NULL;
 
     _nc_tparm_err = 0;
 #ifdef TRACE
-    TPS(tname) = "_nc_tiparm";
+    tps->tname = "_nc_tiparm";
 #endif /* TRACE */
 
-    if (tparm_setup(string, &myData) == OK
+    if (tparm_setup(cur_term, string, &myData) == OK
 	&& myData.num_actual <= expected
 	&& myData.tparm_type == 0) {
 	va_list ap;
@@ -1093,7 +1204,18 @@ _nc_tiparm(int expected, const char *string, ...)
 	tparm_copy_valist(&myData, FALSE, ap);
 	va_end(ap);
 
-	result = tparam_internal(string, &myData);
+	result = tparam_internal(tps, string, &myData);
     }
     return result;
 }
+
+/*
+ * Improve tic's checks by resetting the terminfo "static variables" before
+ * calling functions which may update them.
+ */
+NCURSES_EXPORT(void)
+_nc_reset_tparm(TERMINAL *term)
+{
+    TPARM_STATE *tps = get_tparm_state(term);
+    memset(TPS(static_vars), 0, sizeof(TPS(static_vars)));
+}
diff --git a/ncurses/tinfo/make_keys.c b/ncurses/tinfo/make_keys.c
index 80bbf631..b8eb9343 100644
--- a/ncurses/tinfo/make_keys.c
+++ b/ncurses/tinfo/make_keys.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2020,2021 Thomas E. Dickey                                     *
  * Copyright 1998-2011,2015 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -40,7 +40,7 @@
 #define USE_TERMLIB 1
 #include 
 
-MODULE_ID("$Id: make_keys.c,v 1.22 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: make_keys.c,v 1.23 2021/08/18 20:55:25 tom Exp $")
 
 #include 
 
@@ -128,11 +128,13 @@ main(int argc, char *argv[])
 {
     static const char *prefix[] =
     {
-	"#ifndef NCU_KEYS_H",
-	"#define NCU_KEYS_H 1",
+	"#ifndef _INIT_KEYTRY_H",
+	"#define _INIT_KEYTRY_H 1",
 	"",
 	"/* This file was generated by MAKE_KEYS */",
 	"",
+	"#include ",
+	"",
 	"#if BROKEN_LINKER",
 	"static",
 	"#endif",
@@ -143,7 +145,7 @@ main(int argc, char *argv[])
     {
 	"\t{ 0, 0} };",
 	"",
-	"#endif /* NCU_KEYS_H */",
+	"#endif /* _INIT_KEYTRY_H */",
 	0
     };
 
diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c
index 763ddd72..cab47570 100644
--- a/ncurses/tinfo/write_entry.c
+++ b/ncurses/tinfo/write_entry.c
@@ -51,7 +51,7 @@
 #define TRACE_NUM(n)		/* nothing */
 #endif
 
-MODULE_ID("$Id: write_entry.c,v 1.117 2021/06/26 20:43:19 tom Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.118 2021/08/15 20:07:11 tom Exp $")
 
 static int total_written;
 static int total_parts;
@@ -190,7 +190,7 @@ make_db_root(const char *path)
 #else
 	struct stat statbuf;
 
-	if ((rc = stat(path, &statbuf)) < 0) {
+	if ((rc = stat(path, &statbuf)) == -1) {
 	    rc = mkdir(path
 #ifndef _NC_WINDOWS
 		       ,0777
@@ -442,7 +442,7 @@ _nc_write_entry(TERMTYPE2 *const tp)
     write_file(filename, tp);
 
     if (start_time == 0) {
-	if (stat(filename, &statbuf) < 0
+	if (stat(filename, &statbuf) == -1
 	    || (start_time = statbuf.st_mtime) == 0) {
 	    _nc_syserr_abort("error obtaining time from %s/%s",
 			     _nc_tic_dir(0), filename);
diff --git a/ncurses/tty/tty_update.c b/ncurses/tty/tty_update.c
index 20f9349b..70a9859b 100644
--- a/ncurses/tty/tty_update.c
+++ b/ncurses/tty/tty_update.c
@@ -85,7 +85,7 @@
 
 #include 
 
-MODULE_ID("$Id: tty_update.c,v 1.310 2021/02/06 14:24:38 tom Exp $")
+MODULE_ID("$Id: tty_update.c,v 1.311 2021/08/16 21:51:11 tom Exp $")
 
 /*
  * This define controls the line-breakout optimization.  Every once in a
@@ -1325,8 +1325,8 @@ TransformLine(NCURSES_SP_DCLx int const lineno)
 		newPair = GetPair(newLine[n]);
 		if (oldPair != newPair
 		    && unColor(oldLine[n]) == unColor(newLine[n])) {
-		    if (oldPair < SP_PARM->_pair_limit
-			&& newPair < SP_PARM->_pair_limit
+		    if (oldPair < SP_PARM->_pair_alloc
+			&& newPair < SP_PARM->_pair_alloc
 			&& (isSamePair(SP_PARM->_color_pairs[oldPair],
 				       SP_PARM->_color_pairs[newPair]))) {
 			SetPair(oldLine[n], GetPair(newLine[n]));
diff --git a/ncurses/wcwidth.h b/ncurses/wcwidth.h
index c8fb4d42..76673da6 100644
--- a/ncurses/wcwidth.h
+++ b/ncurses/wcwidth.h
@@ -59,6 +59,16 @@
  * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
  */
 
+#ifndef _WCWIDTH_H_incl
+#define _WCWIDTH_H_incl 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+
 #include 
 
 struct interval {
@@ -310,3 +320,9 @@ NCURSES_EXPORT(int) mk_wcswidth_cjk(const wchar_t *pwcs, size_t n)
 
   return width;
 }
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _WCWIDTH_H_incl 1 */
diff --git a/package/debian-mingw/changelog b/package/debian-mingw/changelog
index 9032736c..fa2a466c 100644
--- a/package/debian-mingw/changelog
+++ b/package/debian-mingw/changelog
@@ -1,8 +1,8 @@
-ncurses6 (6.2+20210814) unstable; urgency=low
+ncurses6 (6.2+20210821) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey   Sat, 14 Aug 2021 06:38:41 -0400
+ -- Thomas E. Dickey   Mon, 16 Aug 2021 03:57:50 -0400
 
 ncurses6 (5.9-20131005) unstable; urgency=low
 
diff --git a/package/debian-mingw64/changelog b/package/debian-mingw64/changelog
index 9032736c..fa2a466c 100644
--- a/package/debian-mingw64/changelog
+++ b/package/debian-mingw64/changelog
@@ -1,8 +1,8 @@
-ncurses6 (6.2+20210814) unstable; urgency=low
+ncurses6 (6.2+20210821) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey   Sat, 14 Aug 2021 06:38:41 -0400
+ -- Thomas E. Dickey   Mon, 16 Aug 2021 03:57:50 -0400
 
 ncurses6 (5.9-20131005) unstable; urgency=low
 
diff --git a/package/debian/changelog b/package/debian/changelog
index 8d0f204b..f9182516 100644
--- a/package/debian/changelog
+++ b/package/debian/changelog
@@ -1,8 +1,8 @@
-ncurses6 (6.2+20210814) unstable; urgency=low
+ncurses6 (6.2+20210821) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey   Sat, 14 Aug 2021 06:38:41 -0400
+ -- Thomas E. Dickey   Mon, 16 Aug 2021 03:57:50 -0400
 
 ncurses6 (5.9-20120608) unstable; urgency=low
 
diff --git a/package/mingw-ncurses.nsi b/package/mingw-ncurses.nsi
index d15df3db..c1092a82 100644
--- a/package/mingw-ncurses.nsi
+++ b/package/mingw-ncurses.nsi
@@ -1,4 +1,4 @@
-; $Id: mingw-ncurses.nsi,v 1.472 2021/08/14 10:38:41 tom Exp $
+; $Id: mingw-ncurses.nsi,v 1.473 2021/08/21 14:10:10 tom Exp $
 
 ; TODO add examples
 ; TODO bump ABI to 6
@@ -10,7 +10,7 @@
 !define VERSION_MAJOR "6"
 !define VERSION_MINOR "2"
 !define VERSION_YYYY  "2021"
-!define VERSION_MMDD  "0814"
+!define VERSION_MMDD  "0821"
 !define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD}
 
 !define MY_ABI   "5"
diff --git a/package/mingw-ncurses.spec b/package/mingw-ncurses.spec
index d9863de9..2f4f6c52 100644
--- a/package/mingw-ncurses.spec
+++ b/package/mingw-ncurses.spec
@@ -3,7 +3,7 @@
 Summary: shared libraries for terminal handling
 Name: mingw32-ncurses6
 Version: 6.2
-Release: 20210814
+Release: 20210821
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{version}-%{release}.tgz
diff --git a/package/ncurses.map b/package/ncurses.map
index cf08f55a..52dcf514 100644
--- a/package/ncurses.map
+++ b/package/ncurses.map
@@ -1,4 +1,4 @@
-# $Id: ncurses.map,v 1.53 2021/06/26 20:31:59 tom Exp $
+# $Id: ncurses.map,v 1.54 2021/08/19 23:49:21 tom Exp $
 # script for shared library symbol-versioning using ld
 #
 # This file was generated by ncu-mapsyms
@@ -1210,6 +1210,7 @@ NCURSES_TINFO_6.2.20200212 {
 
 NCURSES_TINFO_6.2.current {
 	global:
+		_nc_reset_tparm;
 		_nc_safe_fopen;
 		_nc_safe_open3;
 		_nc_tiparm;
diff --git a/package/ncurses.spec b/package/ncurses.spec
index bc42d729..41932285 100644
--- a/package/ncurses.spec
+++ b/package/ncurses.spec
@@ -1,7 +1,7 @@
 Summary: shared libraries for terminal handling
 Name: ncurses6
 Version: 6.2
-Release: 20210814
+Release: 20210821
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{version}-%{release}.tgz
diff --git a/package/ncurses.sym b/package/ncurses.sym
index ae798071..d2f6fbc1 100644
--- a/package/ncurses.sym
+++ b/package/ncurses.sym
@@ -1,4 +1,4 @@
-# $Id: ncurses.sym,v 1.36 2021/06/26 20:31:59 tom Exp $
+# $Id: ncurses.sym,v 1.37 2021/08/19 23:50:26 tom Exp $
 # script for shared library symbol-visibility using libtool
 #
 # This file was generated by ncu-mapsyms
@@ -176,6 +176,7 @@ _nc_read_entry_source
 _nc_read_file_entry
 _nc_read_termtype
 _nc_reset_input
+_nc_reset_tparm
 _nc_resolve_uses
 _nc_resolve_uses2
 _nc_retrace_attr_t
diff --git a/package/ncursest.map b/package/ncursest.map
index 6887edf7..a1615b70 100644
--- a/package/ncursest.map
+++ b/package/ncursest.map
@@ -1,4 +1,4 @@
-# $Id: ncursest.map,v 1.51 2021/06/26 20:31:59 tom Exp $
+# $Id: ncursest.map,v 1.52 2021/08/19 23:49:21 tom Exp $
 # script for shared library symbol-versioning using ld
 #
 # This file was generated by ncu-mapsyms
@@ -489,6 +489,7 @@ NCURSES_TINFO_6.2.20200212 {
 
 NCURSES_TINFO_6.2.current {
 	global:
+		_nc_reset_tparm;
 		_nc_safe_fopen;
 		_nc_safe_open3;
 		_nc_tiparm;
diff --git a/package/ncursest.spec b/package/ncursest.spec
index d1c5781f..185d2489 100644
--- a/package/ncursest.spec
+++ b/package/ncursest.spec
@@ -1,7 +1,7 @@
 Summary: Curses library with POSIX thread support.
 Name: ncursest6
 Version: 6.2
-Release: 20210814
+Release: 20210821
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{version}-%{release}.tgz
diff --git a/package/ncursest.sym b/package/ncursest.sym
index 53964f7b..f50ce3d0 100644
--- a/package/ncursest.sym
+++ b/package/ncursest.sym
@@ -1,4 +1,4 @@
-# $Id: ncursest.sym,v 1.40 2021/06/26 20:36:37 tom Exp $
+# $Id: ncursest.sym,v 1.41 2021/08/19 23:50:26 tom Exp $
 # script for shared library symbol-visibility using libtool
 #
 # This file was generated by ncu-mapsyms
@@ -183,6 +183,7 @@ _nc_read_entry_source
 _nc_read_file_entry
 _nc_read_termtype
 _nc_reset_input
+_nc_reset_tparm
 _nc_resolve_uses
 _nc_resolve_uses2
 _nc_retrace_attr_t
diff --git a/package/ncursestw.map b/package/ncursestw.map
index 84b8ad30..7da7c882 100644
--- a/package/ncursestw.map
+++ b/package/ncursestw.map
@@ -1,4 +1,4 @@
-# $Id: ncursestw.map,v 1.54 2021/06/26 20:31:59 tom Exp $
+# $Id: ncursestw.map,v 1.55 2021/08/19 23:49:21 tom Exp $
 # script for shared library symbol-versioning using ld
 #
 # This file was generated by ncu-mapsyms
@@ -495,6 +495,7 @@ NCURSES_TINFO_6.2.20200212 {
 
 NCURSES_TINFO_6.2.current {
 	global:
+		_nc_reset_tparm;
 		_nc_tiparm;
 		_nc_safe_fopen;
 		_nc_safe_open3;
diff --git a/package/ncursestw.sym b/package/ncursestw.sym
index 2322b690..1668f409 100644
--- a/package/ncursestw.sym
+++ b/package/ncursestw.sym
@@ -1,4 +1,4 @@
-# $Id: ncursestw.sym,v 1.40 2021/06/26 20:31:59 tom Exp $
+# $Id: ncursestw.sym,v 1.41 2021/08/19 23:50:26 tom Exp $
 # script for shared library symbol-visibility using libtool
 #
 # This file was generated by ncu-mapsyms
@@ -183,6 +183,7 @@ _nc_read_entry_source
 _nc_read_file_entry
 _nc_read_termtype
 _nc_reset_input
+_nc_reset_tparm
 _nc_resolve_uses
 _nc_resolve_uses2
 _nc_retrace_attr_t
diff --git a/package/ncursesw.map b/package/ncursesw.map
index 5d214cde..94383b3c 100644
--- a/package/ncursesw.map
+++ b/package/ncursesw.map
@@ -1,4 +1,4 @@
-# $Id: ncursesw.map,v 1.57 2021/06/26 20:31:59 tom Exp $
+# $Id: ncursesw.map,v 1.58 2021/08/19 23:49:21 tom Exp $
 # script for shared library symbol-versioning using ld
 #
 # This file was generated by ncu-mapsyms
@@ -489,6 +489,7 @@ NCURSES_TINFO_6.2.20200212 {
 
 NCURSES_TINFO_6.2.current {
 	global:
+		_nc_reset_tparm;
 		_nc_tiparm;
 		_nc_safe_fopen;
 		_nc_safe_open3;
diff --git a/package/ncursesw.sym b/package/ncursesw.sym
index 6fbc2368..a17fd794 100644
--- a/package/ncursesw.sym
+++ b/package/ncursesw.sym
@@ -1,4 +1,4 @@
-# $Id: ncursesw.sym,v 1.39 2021/06/26 20:31:59 tom Exp $
+# $Id: ncursesw.sym,v 1.40 2021/08/19 23:50:26 tom Exp $
 # script for shared library symbol-visibility using libtool
 #
 # This file was generated by ncu-mapsyms
@@ -172,6 +172,7 @@ _nc_read_entry_source
 _nc_read_file_entry
 _nc_read_termtype
 _nc_reset_input
+_nc_reset_tparm
 _nc_resolve_uses
 _nc_resolve_uses2
 _nc_retrace_attr_t
diff --git a/progs/dump_entry.c b/progs/dump_entry.c
index 9c0c8155..68cf32bc 100644
--- a/progs/dump_entry.c
+++ b/progs/dump_entry.c
@@ -40,7 +40,7 @@
 #include 		/* this C file is generated */
 #include 	/* so is this */
 
-MODULE_ID("$Id: dump_entry.c,v 1.187 2021/06/12 22:06:55 tom Exp $")
+MODULE_ID("$Id: dump_entry.c,v 1.188 2021/08/15 20:00:48 tom Exp $")
 
 #define DISCARD(string) string = ABSENT_STRING
 #define PRINTF (void) printf
@@ -85,7 +85,7 @@ static int indent = 8;
 /* cover various ports and variants of terminfo */
 #define V_ALLCAPS	0	/* all capabilities (SVr4, XSI, ncurses) */
 #define V_SVR1		1	/* SVR1, Ultrix */
-#define V_HPUX		2	/* HP/UX */
+#define V_HPUX		2	/* HP-UX */
 #define V_AIX		3	/* AIX */
 #define V_BSD		4	/* BSD */
 
diff --git a/progs/tic.c b/progs/tic.c
index 283201af..4caa6b59 100644
--- a/progs/tic.c
+++ b/progs/tic.c
@@ -49,7 +49,7 @@
 #include 
 #include 
 
-MODULE_ID("$Id: tic.c,v 1.296 2021/06/26 19:44:08 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.301 2021/08/21 00:24:45 tom Exp $")
 
 #define STDIN_NAME ""
 
@@ -458,7 +458,7 @@ open_input(const char *filename, char *alt_file)
 
     if (!strcmp(filename, "-")) {
 	fp = copy_input(stdin, STDIN_NAME, alt_file);
-    } else if (stat(filename, &sb) < 0) {
+    } else if (stat(filename, &sb) == -1) {
 	fprintf(stderr, "%s: %s %s\n", _nc_progname, filename, strerror(errno));
 	ExitProgram(EXIT_FAILURE);
     } else if ((mode = (sb.st_mode & S_IFMT)) == S_IFDIR
@@ -1922,19 +1922,63 @@ is_user_capability(const char *name)
     return result;
 }
 
+static bool
+line_capability(const char *name)
+{
+    bool result = FALSE;
+    static const char *table[] =
+    {
+	"csr",			/* change_scroll_region          */
+	"clear",		/* clear_screen                  */
+	"ed",			/* clr_eos                       */
+	"cwin",			/* create_window                 */
+	"cup",			/* cursor_address                */
+	"cud1",			/* cursor_down                   */
+	"home",			/* cursor_home                   */
+	"mrcup",		/* cursor_mem_address            */
+	"ll",			/* cursor_to_ll                  */
+	"cuu1",			/* cursor_up                     */
+	"dl1",			/* delete_line                   */
+	"hd",			/* down_half_line                */
+	"flash",		/* flash_screen                  */
+	"ff",			/* form_feed                     */
+	"il1",			/* insert_line                   */
+	"nel",			/* newline                       */
+	"dl",			/* parm_delete_line              */
+	"cud",			/* parm_down_cursor              */
+	"indn",			/* parm_index                    */
+	"il",			/* parm_insert_line              */
+	"rin",			/* parm_rindex                   */
+	"cuu",			/* parm_up_cursor                */
+	"mc0",			/* print_screen                  */
+	"vpa",			/* row_address                   */
+	"ind",			/* scroll_forward                */
+	"ri",			/* scroll_reverse                */
+	"hu",			/* up_half_line                  */
+    };
+    size_t n;
+    for (n = 0; n < SIZEOF(table); ++n) {
+	if (!strcmp(name, table[n])) {
+	    result = TRUE;
+	    break;
+	}
+    }
+    return result;
+}
+
 /*
  * Make a quick sanity check for the parameters which are used in the given
  * strings.  If there are no "%p" tokens, then there should be no other "%"
  * markers.
  */
 static void
-check_params(TERMTYPE2 *tp, const char *name, char *value, int extended)
+check_params(TERMTYPE2 *tp, const char *name, const char *value, int extended)
 {
     int expected = expected_params(name);
     int actual = 0;
     int n;
     bool params[1 + NUM_PARM];
-    char *s = value;
+    const char *s = value;
 
 #ifdef set_top_margin_parm
     if (!strcmp(name, "smgbp")
@@ -2000,10 +2044,11 @@ check_params(TERMTYPE2 *tp, const char *name, char *value, int extended)
      * may not have been fully translated.  Also, tparm does its own analysis.
      * Report differences here.
      */
+    _nc_reset_tparm(NULL);
     if (actual >= 0) {
 	char *p_is_s[NUM_PARM];
 	int popcount;
-	int analyzed = _nc_tparm_analyze(value, p_is_s, &popcount);
+	int analyzed = _nc_tparm_analyze(NULL, value, p_is_s, &popcount);
 	if (analyzed < popcount) {
 	    analyzed = popcount;
 	}
@@ -2021,54 +2066,34 @@ check_params(TERMTYPE2 *tp, const char *name, char *value, int extended)
 		_nc_warning("tparm analyzed %d parameters for %s, expected %d",
 			    analyzed, name, actual);
 	    }
+	} else if (expected > 0
+		   && actual == expected
+		   && guess_tparm_type(expected, p_is_s) == Numbers) {
+	    int limit = 1;
+
+	    if (!strcmp(name, "setf")
+		|| !strcmp(name, "setb")
+		|| !strcmp(name, "setaf")
+		|| !strcmp(name, "setab")) {
+		if ((limit = max_colors) > 256)
+		    limit = 256;
+	    } else if (line_capability(name)) {
+		limit = 24;
+	    } else if (is_user_capability(name) < 0) {
+		limit = 80;
+	    }
+	    for (n = 0; n < limit; ++n) {
+		_nc_reset_tparm(NULL);
+		(void) TPARM_9(value, n, n, n, n, n, n, n, n, n);
+		if (_nc_tparm_err)
+		    _nc_warning("problem%s in tparm(%s, %d, ...)",
+				(_nc_tparm_err == 1) ? "" : "s",
+				name, n);
+	    }
 	}
     }
 }
 
-static bool
-line_capability(const char *name)
-{
-    bool result = FALSE;
-    static const char *table[] =
-    {
-	"csr",			/* change_scroll_region          */
-	"clear",		/* clear_screen                  */
-	"ed",			/* clr_eos                       */
-	"cwin",			/* create_window                 */
-	"cup",			/* cursor_address                */
-	"cud1",			/* cursor_down                   */
-	"home",			/* cursor_home                   */
-	"mrcup",		/* cursor_mem_address            */
-	"ll",			/* cursor_to_ll                  */
-	"cuu1",			/* cursor_up                     */
-	"dl1",			/* delete_line                   */
-	"hd",			/* down_half_line                */
-	"flash",		/* flash_screen                  */
-	"ff",			/* form_feed                     */
-	"il1",			/* insert_line                   */
-	"nel",			/* newline                       */
-	"dl",			/* parm_delete_line              */
-	"cud",			/* parm_down_cursor              */
-	"indn",			/* parm_index                    */
-	"il",			/* parm_insert_line              */
-	"rin",			/* parm_rindex                   */
-	"cuu",			/* parm_up_cursor                */
-	"mc0",			/* print_screen                  */
-	"vpa",			/* row_address                   */
-	"ind",			/* scroll_forward                */
-	"ri",			/* scroll_reverse                */
-	"hu",			/* up_half_line                  */
-    };
-    size_t n;
-    for (n = 0; n < SIZEOF(table); ++n) {
-	if (!strcmp(name, table[n])) {
-	    result = TRUE;
-	    break;
-	}
-    }
-    return result;
-}
-
 /*
  * Check for DEC VT100 private mode for reverse video.
  */
@@ -2206,8 +2231,9 @@ check_1_infotocap(const char *name, NCURSES_CONST char *value, int count)
 	next += strlen(next) + 1;
     }
 
+    _nc_reset_tparm(NULL);
     expect = tparm_type(name);
-    nparam = _nc_tparm_analyze(value, p_is_s, &ignored);
+    nparam = _nc_tparm_analyze(NULL, value, p_is_s, &ignored);
     actual = guess_tparm_type(nparam, p_is_s);
 
     if (expect != actual) {
@@ -2215,6 +2241,7 @@ check_1_infotocap(const char *name, NCURSES_CONST char *value, int count)
 	actual = Other;
     }
 
+    _nc_reset_tparm(NULL);
     switch (actual) {
     case Num_Str:
 	result = TPARM_2(value, numbers[1], strings[2]);
@@ -2403,8 +2430,8 @@ check_infotocap(TERMTYPE2 *tp, int i, const char *value)
 	    || !strcmp(name, "setb")
 	    || !strcmp(name, "setaf")
 	    || !strcmp(name, "setab")) {
-	    if ((limit = max_colors) > 16)
-		limit = 16;
+	    if ((limit = max_colors) > 256)
+		limit = 256;
 	}
 	for (count = 0; count < limit; ++count) {
 	    char *ti_check = check_1_infotocap(name, ti_value, count);
diff --git a/progs/tput.c b/progs/tput.c
index 027fab9c..fe82d472 100644
--- a/progs/tput.c
+++ b/progs/tput.c
@@ -47,7 +47,7 @@
 #include 
 #include 
 
-MODULE_ID("$Id: tput.c,v 1.90 2021/04/18 17:18:19 tom Exp $")
+MODULE_ID("$Id: tput.c,v 1.91 2021/08/21 00:24:45 tom Exp $")
 
 #define PUTS(s)		fputs(s, stdout)
 
@@ -278,7 +278,7 @@ tput_cmd(int fd, TTY * saved_settings, bool opt_x, int argc, char *argv[])
 	    case Other:
 		/* FALLTHRU */
 	    default:
-		(void) _nc_tparm_analyze(s, p_is_s, &ignored);
+		(void) _nc_tparm_analyze(NULL, s, p_is_s, &ignored);
 #define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
 		s = TPARM_9(s,
 			    myParam(1),
diff --git a/test/ditto.c b/test/ditto.c
index aecd342c..fdc8611a 100644
--- a/test/ditto.c
+++ b/test/ditto.c
@@ -30,7 +30,7 @@
 /*
  * Author: Thomas E. Dickey (1998-on)
  *
- * $Id: ditto.c,v 1.51 2021/04/17 17:39:43 tom Exp $
+ * $Id: ditto.c,v 1.52 2021/08/15 20:07:11 tom Exp $
  *
  * The program illustrates how to set up multiple screens from a single
  * program.
@@ -182,7 +182,7 @@ open_tty(char *path)
 #else
     struct stat sb;
 
-    if (stat(path, &sb) < 0)
+    if (stat(path, &sb) == -1)
 	failed(path);
     if ((sb.st_mode & S_IFMT) != S_IFCHR) {
 	errno = ENOTTY;
-- 
2.45.0