Base version of ncurses-5.7 library
diff --git a/ncurses/Makefile.in b/ncurses/Makefile.in
new file mode 100644
index 0000000..558f79f
--- /dev/null
+++ b/ncurses/Makefile.in
@@ -0,0 +1,284 @@
+# $Id: Makefile.in,v 1.113 2008/10/18 14:11:54 tom Exp $
+##############################################################################
+# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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.                                                             #
+##############################################################################
+#
+# Author: Thomas E. Dickey 1996-on
+#
+# Makefile for ncurses source code.
+#
+# This makes the following:
+#	programs
+#	includes
+#	libraries (normal/debug/profile/shared)
+#
+# The variable 'srcdir' refers to the source-distribution, and can be set with
+# the configure script by "--srcdir=DIR".
+#
+# The rules are organized to produce the libraries for the configured models,
+# and the programs with the configured default model.
+
+# turn off _all_ suffix rules; we'll generate our own
+.SUFFIXES:
+
+SHELL		= /bin/sh
+THIS		= Makefile
+
+CF_MFLAGS 	= @cf_cv_makeflags@
+@SET_MAKE@
+
+x		= @EXEEXT@
+o		= .@OBJEXT@
+
+MODEL		= @DFT_LWR_MODEL@
+DESTDIR		= @DESTDIR@
+top_srcdir	= @top_srcdir@
+srcdir		= @srcdir@
+prefix		= @prefix@
+exec_prefix	= @exec_prefix@
+bindir		= @bindir@
+libdir		= @libdir@
+includedir	= @includedir@
+datadir		= @datadir@
+
+LIBTOOL		= @LIBTOOL@
+LIBTOOL_CLEAN	= @LIB_CLEAN@
+LIBTOOL_COMPILE	= @LIB_COMPILE@
+LIBTOOL_LINK	= @LIB_LINK@
+LIBTOOL_INSTALL	= @LIB_INSTALL@
+LIBTOOL_UNINSTALL = @LIB_UNINSTALL@
+
+INSTALL		= @INSTALL@
+INSTALL_LIB	= @INSTALL@ @INSTALL_LIB@
+INSTALL_PROG	= @INSTALL_PROGRAM@
+INSTALL_DATA	= @INSTALL_DATA@
+
+AR		= @AR@
+AR_OPTS		= @AR_OPTS@
+AWK		= @AWK@
+LD		= @LD@
+LN_S		= @LN_S@
+
+CC		= @CC@
+CPP		= @CPP@
+CFLAGS		= @CFLAGS@
+
+INCDIR		= $(srcdir)/../include
+CPPFLAGS	= -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) @CPPFLAGS@
+
+CCFLAGS		= $(CPPFLAGS) $(CFLAGS)
+
+BUILD_CPPFLAGS	= -I../include @BUILD_CPPFLAGS@
+BUILD_CC	= @BUILD_CC@
+BUILD_CCFLAGS	= -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) -I$(INCDIR) $(BUILD_CPPFLAGS) @BUILD_CFLAGS@
+BUILD_LDFLAGS	= @BUILD_LDFLAGS@
+BUILD_LIBS	= @BUILD_LIBS@
+
+# The executables built in this directory are used for generating source that
+# is compiled into the build, or are test-programs that are not installed.
+
+BUILD_EXEEXT	= @BUILD_EXEEXT@
+x		= @PROG_EXT@
+
+CFLAGS_LIBTOOL	= $(CCFLAGS)
+CFLAGS_NORMAL	= $(CCFLAGS)
+CFLAGS_DEBUG	= $(CCFLAGS) @CC_G_OPT@ -DTRACE
+CFLAGS_PROFILE	= $(CCFLAGS) -pg
+CFLAGS_SHARED	= $(CCFLAGS) @CC_SHARED_OPTS@
+
+CFLAGS_DEFAULT	= $(CFLAGS_@DFT_UPR_MODEL@)
+
+LINK		= $(LIBTOOL)
+LDFLAGS		= @LDFLAGS@ @LD_MODEL@ @LIBS@
+
+SHLIB_DIRS	= -L../lib
+SHLIB_LIST	= $(SHLIB_DIRS) @SHLIB_LIST@
+TINFO_LIST	= $(SHLIB_DIRS) @TINFO_LIST@
+TICS_LIST	= $(SHLIB_DIRS) @TICS_LIST@
+
+MK_SHARED_LIB	= @MK_SHARED_LIB@
+
+NCURSES_MAJOR	= @NCURSES_MAJOR@
+NCURSES_MINOR	= @NCURSES_MINOR@
+REL_VERSION	= @cf_cv_rel_version@
+ABI_VERSION	= @cf_cv_abi_version@
+
+RANLIB		= @LIB_PREP@
+
+LIBRARIES	= @LIBS_TO_MAKE@
+
+LINT		= @LINT@
+LINT_OPTS	= @LINT_OPTS@
+LINT_LIBS	= -lncurses @LIBS@
+
+FALLBACK_LIST	= @FALLBACK_LIST@
+
+USE_BIG_STRINGS	= @USE_BIG_STRINGS@
+TERMINFO_CAPS	= $(top_srcdir)/include/@TERMINFO_CAPS@
+
+AUTO_SRC = \
+	./codes.c \
+	./comp_captab.c \
+	./expanded.c \
+	./fallback.c \
+	./lib_gen.c \
+	./lib_keyname.c \
+	./link_test.c \
+	./names.c \
+	./unctrl.c \
+	init_keytry.h \
+	keys.list
+
+TEST_DEPS	= ../lib/@LIB_PREFIX@ncurses@DFT_DEP_SUFFIX@
+TEST_ARGS	= @LDFLAGS_STATIC@ @TEST_ARGS@ @LDFLAGS_SHARED@ 
+TEST_LDFLAGS	= @LD_MODEL@ $(TEST_ARGS) @LIBS@ @LOCAL_LDFLAGS@ @LDFLAGS@
+
+TEST_PROGS = \
+	captoinfo$x \
+	hardscroll$x \
+	link_test$x \
+	hashmap$x \
+	lib_mvcur$x
+
+base	= $(srcdir)/base
+serial	= $(srcdir)/tty
+tinfo	= $(srcdir)/tinfo
+trace	= $(srcdir)/trace
+wide	= $(srcdir)/widechar
+
+################################################################################
+all \
+libs ::		$(AUTO_SRC) ../lib $(LIBRARIES)
+
+sources:	$(AUTO_SRC)
+
+$(DESTDIR)$(bindir) \
+$(DESTDIR)$(libdir) :
+	sh $(srcdir)/../mkdirs.sh $@
+
+../lib : ; mkdir $@
+
+./fallback.c : $(tinfo)/MKfallback.sh
+	sh -e $(tinfo)/MKfallback.sh @TERMINFO@ @TERMINFO_SRC@ $(FALLBACK_LIST) >$@
+
+./lib_gen.c : $(base)/MKlib_gen.sh ../include/curses.h
+	sh -e $(base)/MKlib_gen.sh "$(CPP) $(CPPFLAGS)" "$(AWK)" generated <../include/curses.h >$@
+
+init_keytry.h: make_keys$(BUILD_EXEEXT) keys.list
+	./make_keys$(BUILD_EXEEXT) keys.list > $@
+
+keys.list :	$(tinfo)/MKkeys_list.sh
+	AWK=$(AWK) sh $(tinfo)/MKkeys_list.sh $(TERMINFO_CAPS) | sort >$@
+
+make_keys$(BUILD_EXEEXT) : \
+		$(tinfo)/make_keys.c \
+		names.c
+	$(BUILD_CC) -o $@ $(BUILD_CCFLAGS) $(tinfo)/make_keys.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
+
+make_hash$(BUILD_EXEEXT) : \
+		$(tinfo)/comp_hash.c \
+		../include/hashsize.h
+	$(BUILD_CC) -o $@ $(BUILD_CCFLAGS) -DMAIN_PROGRAM $(tinfo)/comp_hash.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
+
+./expanded.c : $(serial)/MKexpanded.sh
+	sh -e $(serial)/MKexpanded.sh "$(CPP)" $(CPPFLAGS) > $@
+
+./comp_captab.c: \
+		make_hash$(BUILD_EXEEXT) \
+		../include/hashsize.h \
+		$(tinfo)/MKcaptab.sh \
+		$(tinfo)/MKcaptab.awk
+	sh -e $(tinfo)/MKcaptab.sh $(AWK) $(USE_BIG_STRINGS) $(tinfo)/MKcaptab.awk $(srcdir)/../include/@TERMINFO_CAPS@ > $@
+
+./lib_keyname.c: keys.list $(base)/MKkeyname.awk
+	$(AWK) -f $(base)/MKkeyname.awk bigstrings=$(USE_BIG_STRINGS) keys.list > $@
+
+./codes.c: $(tinfo)/MKcodes.awk
+	$(AWK) -f $(tinfo)/MKcodes.awk bigstrings=$(USE_BIG_STRINGS) $(srcdir)/../include/@TERMINFO_CAPS@ >$@
+
+./names.c: $(tinfo)/MKnames.awk
+	$(AWK) -f $(tinfo)/MKnames.awk bigstrings=$(USE_BIG_STRINGS) $(srcdir)/../include/@TERMINFO_CAPS@ >$@
+
+./unctrl.c: $(base)/MKunctrl.awk
+	echo | $(AWK) -f $(base)/MKunctrl.awk bigstrings=$(USE_BIG_STRINGS) >$@
+
+tags:
+	ctags *.[ch] */*.[ch]
+
+@MAKE_UPPER_TAGS@TAGS:
+@MAKE_UPPER_TAGS@	etags *.[ch] */*.[ch]
+
+mostlyclean ::
+	-rm -f core tags TAGS *~ *.bak *.i *.ln *.atac trace
+	-rm -f $(TEST_PROGS)
+
+clean :: mostlyclean
+	-rm -f $(AUTO_SRC)
+	-rm -f make_keys$(BUILD_EXEEXT)
+	-rm -f make_hash$(BUILD_EXEEXT)
+	-rm -rf .libs
+
+distclean :: clean
+	-rm -f Makefile
+
+realclean :: distclean
+
+# These rules are used to allow "make -n" to work on a clean directory-tree
+../include/hashsize.h \
+../include/parametrized.h \
+../include/term.h :
+	cd ../include; $(MAKE) $(CF_MFLAGS)
+
+# These rules build test-programs for the modules that have test-drivers
+test_progs : $(TEST_PROGS)
+
+./link_test.c : $(base)/MKlib_gen.sh ../include/curses.h
+	sh -e $(base)/MKlib_gen.sh "$(CPP) $(CPPFLAGS)" "$(AWK)" implemented <../include/curses.h >$@
+
+captoinfo$x : $(tinfo)/captoinfo.c $(TEST_DEPS)
+	@ECHO_LINK@ $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DMAIN $(tinfo)/captoinfo.c $(TEST_LDFLAGS)
+
+hardscroll$x : $(serial)/hardscroll.c $(TEST_DEPS)
+	@ECHO_LINK@ $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DSCROLLDEBUG $(serial)/hardscroll.c $(TEST_LDFLAGS)
+
+hashmap$x : $(serial)/hashmap.c $(serial)/hardscroll.c $(TEST_DEPS)
+	@ECHO_LINK@ $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DHASHDEBUG $(serial)/hashmap.c $(serial)/hardscroll.c $(TEST_LDFLAGS)
+
+lib_mvcur$x : $(serial)/lib_mvcur.c $(TEST_DEPS) \
+		../@DFT_OBJ_SUBDIR@/dump_entry$o
+	@ECHO_LINK@ $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DNCURSES_TEST -I$(serial)/../../progs $(serial)/lib_mvcur.c ../@DFT_OBJ_SUBDIR@/dump_entry$o $(TEST_LDFLAGS)
+
+link_test$x : ./link_test.c $(TEST_DEPS) \
+		../@DFT_OBJ_SUBDIR@/link_test$o
+	@ECHO_LINK@ $(CC) -o $@ $(CFLAGS_DEFAULT) ../@DFT_OBJ_SUBDIR@/link_test$o $(TEST_LDFLAGS)
+
+../@DFT_OBJ_SUBDIR@/dump_entry$o:
+	cd ../progs && $(MAKE) ../@DFT_OBJ_SUBDIR@/dump_entry$o
+
+###############################################################################
+# The remainder of this file is automatically generated during configuration
+###############################################################################
diff --git a/ncurses/README b/ncurses/README
new file mode 100644
index 0000000..120aa5b
--- /dev/null
+++ b/ncurses/README
@@ -0,0 +1,31 @@
+-------------------------------------------------------------------------------
+-- Copyright (c) 1998-2000,2006 Free Software Foundation, Inc.               --
+--                                                                           --
+-- Permission is hereby granted, free of charge, to any person obtaining a   --
+-- copy of this software and associated documentation files (the             --
+-- "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: README,v 1.9 2006/04/22 22:19:37 tom Exp $
+-------------------------------------------------------------------------------
+For discussion of the package internals, see hackguide.html in the doc/html
+directory.
diff --git a/ncurses/README.IZ b/ncurses/README.IZ
new file mode 100644
index 0000000..78206cd
--- /dev/null
+++ b/ncurses/README.IZ
@@ -0,0 +1,95 @@
+-------------------------------------------------------------------------------
+-- Copyright (c) 2002,2006 Free Software Foundation, Inc.                    --
+--                                                                           --
+-- Permission is hereby granted, free of charge, to any person obtaining a   --
+-- copy of this software and associated documentation files (the             --
+-- "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: README.IZ,v 1.2 2006/04/22 23:13:05 tom Exp $
+---------------------------------------------------------------------
+
+Here is the patch.  I did no testing whatsoever with event watching
+requests present (I need some applications which exersize this before
+this, probably lynx ;-), but the code looks working "the normal way".
+
+I had no way to test that the poll() branch compiles/works...
+
+Here is the API: 
+
+*) two new functions wgetch_events() wgetstrn_event() are introduced,
+   which allow an event-watch specification given as the last argument;
+
+*) if the last argument is NULL, they behave as wgetch() and
+   wgetstrn() (TESTED!);
+
+*) the event specification is a pointer to _nc_eventlist, which
+   contains bookkeeping elements (count and the summary of results),
+   and an array of pointers to _nc_event;
+
+*) each _nc_event is a typed union, with two types supported "as
+   shipped": _NC_EVENT_TIMEOUT_MSEC, _NC_EVENT_FILE.  For
+   _NC_EVENT_FILE the fields are fd, flag, and the output field.
+
+*) The only supported flag "as shipped" is _NC_EVENT_FILE_READABLE.
+   If the file was found readable, the return field is set to this,
+   otherwise to 0;
+
+*) If these functions return KEY_EVENT, this means that the return
+   fields in both the _nc_eventlist and _nc_event structures make
+   sense.  The field result_flags of _nc_eventlist may have a
+   combination of bits _NC_EVENT_TIMEOUT_MSEC and _NC_EVENT_FILE_READABLE
+   set;
+
+*) The timeout_msec field of _NC_EVENT_TIMEOUT_MSEC _nc_event's is
+   updated on return, even if the return is not KEY_EVENT.  However,
+   the change in the value represents only the amount of time spent in
+   waiting for events, not the amount of time spent bookkeeping;
+
+*) the return KEY_EVENT of wgetstrn_event() means that the output
+   string includes the user input typed so far, but the user did not have
+   a chance to press ENTER (or whatever).  This call should be
+   repeated (with "shifted" pointer to a buffer, of course) to
+   complete the input;
+
+*) The presence of this extension can be checked via inspecting
+   #ifdef NCURSES_EVENT_VERSION.  This symbol is not defined on BeOS,
+   since there is no support for this on BeOS.
+
+Known issues:  calls interrupted by KEY_EVENT reset the ESCDELAY
+timer.  This is not entirely new, since other synthetic events behave
+the same (see "if (ch >= KEY_MIN)" branch of kgetch()).  However,
+KEY_EVENT may be generated in a continuous stream (say, when
+downloading a file), thus this may be more important than with other
+synthetic keys.  An additional field in window structure which keeps
+timestamp of the first raw key in the queue may be needed to
+circumvent this.
+
+Another possible issue: KEY_EVENT has a preference over a user input,
+so a stream of KEY_EVENT's can make input hard.  Maybe use
+result_flags as in input parameter too, which specifies whether the
+user input should have higher precedence?
+
+Also: I took an opportunity to document kgetch() better.
+
+Enjoy,
+Ilya
diff --git a/ncurses/SigAction.h b/ncurses/SigAction.h
new file mode 100644
index 0000000..5dfde64
--- /dev/null
+++ b/ncurses/SigAction.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ * $Id: SigAction.h,v 1.8 2005/08/06 20:05:32 tom Exp $
+ *
+ * This file exists to handle non-POSIX systems which don't have <unistd.h>,
+ * and usually no sigaction() nor <termios.h>
+ */
+
+#ifndef _SIGACTION_H
+#define _SIGACTION_H
+
+#ifndef HAVE_SIGACTION
+#define HAVE_SIGACTION 0
+#endif
+
+#ifndef HAVE_SIGVEC
+#define HAVE_SIGVEC 0
+#endif
+
+#if HAVE_SIGACTION
+
+#if !HAVE_TYPE_SIGACTION
+typedef struct sigaction sigaction_t;
+#endif
+
+#else	/* !HAVE_SIGACTION */
+
+#if HAVE_SIGVEC
+
+#undef  SIG_BLOCK
+#define SIG_BLOCK       00
+
+#undef  SIG_UNBLOCK
+#define SIG_UNBLOCK     01
+
+#undef  SIG_SETMASK
+#define SIG_SETMASK     02
+
+ 	/*
+	 * <bsd/signal.h> is in the Linux 1.2.8 + gcc 2.7.0 configuration,
+	 * and is useful for testing this header file.
+	 */
+#if HAVE_BSD_SIGNAL_H
+#include <bsd/signal.h>
+#endif
+
+typedef struct sigvec sigaction_t;
+
+#define sigset_t _nc_sigset_t
+typedef unsigned long sigset_t;
+
+#undef  sa_mask
+#define sa_mask sv_mask
+#undef  sa_handler
+#define sa_handler sv_handler
+#undef  sa_flags
+#define sa_flags sv_flags
+
+#undef  sigaction
+#define sigaction   _nc_sigaction
+#undef  sigprocmask
+#define sigprocmask _nc_sigprocmask
+#undef  sigemptyset
+#define sigemptyset _nc_sigemptyset
+#undef  sigsuspend
+#define sigsuspend  _nc_sigsuspend
+#undef  sigdelset
+#define sigdelset   _nc_sigdelset
+#undef  sigaddset
+#define sigaddset   _nc_sigaddset
+
+/* tty/lib_tstp.c is the only user */
+#include <base/sigaction.c>
+
+#endif /* HAVE_SIGVEC */
+#endif /* HAVE_SIGACTION */
+#endif /* !defined(_SIGACTION_H) */
diff --git a/ncurses/base/MKkeyname.awk b/ncurses/base/MKkeyname.awk
new file mode 100644
index 0000000..b35ba2a
--- /dev/null
+++ b/ncurses/base/MKkeyname.awk
@@ -0,0 +1,161 @@
+# $Id: MKkeyname.awk,v 1.40 2008/07/12 18:40:00 tom Exp $
+##############################################################################
+# Copyright (c) 1999-2007,2008 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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.                                                             #
+##############################################################################
+BEGIN {
+	print "/* generated by MKkeyname.awk */"
+	print ""
+	print "#include <curses.priv.h>"
+	print "#include <tic.h>"
+	print "#include <term_entry.h>"
+	print ""
+	first = 1;
+}
+
+/^[^#]/ {
+		if (bigstrings) {
+			if (first)  {
+				print "struct kn { short offset; int code; };"
+				print "static const struct kn _nc_key_names[] = {"
+			}
+			printf "\t{ %d, %s },\n", offset, $1
+			offset += length($1) + 1
+			names = names"\n\t\""$1"\\0\""
+		} else {
+			if (first) {
+				print "struct kn { const char *name; int code; };"
+				print "static const struct kn _nc_key_names[] = {"
+			}
+			printf "\t{ \"%s\", %s },\n", $1, $1;
+		}
+		first = 0;
+	}
+
+END {
+	if (bigstrings) {
+		printf "\t{ -1, 0 }};\n"
+		print ""
+		print "static const char key_names[] = "names";"
+	} else {
+		printf "\t{ 0, 0 }};\n"
+	}
+	print ""
+	print "#define SIZEOF_TABLE 256"
+	print "#define MyTable _nc_globals.keyname_table"
+	print ""
+	print "NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *sp, int c)"
+	print "{"
+	print "	int i;"
+	print "	char name[20];"
+	print "	char *p;"
+	print "	NCURSES_CONST char *result = 0;"
+	print ""
+	print "	if (c == -1) {"
+	print "		result = \"-1\";"
+	print "	} else {"
+	if (bigstrings) {
+		print "		for (i = 0; _nc_key_names[i].offset != -1; i++) {"
+		print "			if (_nc_key_names[i].code == c) {"
+		print "				result = (NCURSES_CONST char *)key_names + _nc_key_names[i].offset;"
+		print "				break;"
+		print "			}"
+		print "		}"
+	} else {
+		print "		for (i = 0; _nc_key_names[i].name != 0; i++) {"
+		print "			if (_nc_key_names[i].code == c) {"
+		print "				result = (NCURSES_CONST char *)_nc_key_names[i].name;"
+		print "				break;"
+		print "			}"
+		print "		}"
+	}
+	print ""
+	print "		if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {"
+	print "			if (MyTable == 0)"
+	print "				MyTable = typeCalloc(char *, SIZEOF_TABLE);"
+	print "			if (MyTable != 0) {"
+	print "				if (MyTable[c] == 0) {"
+	print "					int cc = c;"
+	print "					p = name;"
+	print "					if (cc >= 128 && (sp == 0 || sp->_use_meta)) {"
+	print "						strcpy(p, \"M-\");"
+	print "						p += 2;"
+	print "						cc -= 128;"
+	print "					}"
+	print "					if (cc < 32)"
+	print "						sprintf(p, \"^%c\", cc + '@');"
+	print "					else if (cc == 127)"
+	print "						strcpy(p, \"^?\");"
+	print "					else"
+	print "						sprintf(p, \"%c\", cc);"
+	print "					MyTable[c] = strdup(name);"
+	print "				}"
+	print "				result = MyTable[c];"
+	print "			}"
+	print "#if NCURSES_EXT_FUNCS && NCURSES_XNAMES"
+	print "		} else if (result == 0 && cur_term != 0) {"
+	print "			int j, k;"
+	print "			char * bound;"
+	print "			TERMTYPE *tp = &(cur_term->type);"
+	print "			int save_trace = _nc_tracing;"
+	print ""
+	print "			_nc_tracing = 0;	/* prevent recursion via keybound() */"
+	print "			for (j = 0; (bound = keybound(c, j)) != 0; ++j) {"
+	print "				for(k = STRCOUNT; k < (int) NUM_STRINGS(tp);  k++) {"
+	print "					if (tp->Strings[k] != 0 && !strcmp(bound, tp->Strings[k])) {"
+	print "						result = ExtStrname(tp, k, strnames);"
+	print "						break;"
+	print "					}"
+	print "				}"
+	print "				free(bound);"
+	print "				if (result != 0)"
+	print "					break;"
+	print "			}"
+	print "			_nc_tracing = save_trace;"
+	print "#endif"
+	print "		}"
+	print "	}"
+	print "	return result;"
+	print "}"
+	print ""
+	print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)"
+	print "{"
+	print "\treturn _nc_keyname(SP, c);"
+	print "}"
+	print ""
+	print "#if NO_LEAKS"
+	print "void _nc_keyname_leaks(void)"
+	print "{"
+	print "	int j;"
+	print "	if (MyTable != 0) {"
+	print "		for (j = 0; j < SIZEOF_TABLE; ++j) {"
+	print "			FreeIfNeeded(MyTable[j]);"
+	print "		}"
+	print "		FreeAndNull(MyTable);"
+	print "	}"
+	print "}"
+	print "#endif /* NO_LEAKS */"
+}
diff --git a/ncurses/base/MKlib_gen.sh b/ncurses/base/MKlib_gen.sh
new file mode 100755
index 0000000..a984e85
--- /dev/null
+++ b/ncurses/base/MKlib_gen.sh
@@ -0,0 +1,429 @@
+#!/bin/sh
+#
+# MKlib_gen.sh -- generate sources from curses.h macro definitions
+#
+# ($Id: MKlib_gen.sh,v 1.34 2008/08/30 19:20:50 tom Exp $)
+#
+##############################################################################
+# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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.                                                             #
+##############################################################################
+#
+# The XSI Curses standard requires all curses entry points to exist as
+# functions, even though many definitions would normally be shadowed
+# by macros.  Rather than hand-hack all that code, we actually
+# generate functions from the macros.
+#
+# This script accepts a file of prototypes on standard input.  It discards
+# any that don't have a `generated' comment attached. It then parses each
+# prototype (relying on the fact that none of the macros take function
+# pointer or array arguments) and generates C source from it.
+#
+# Here is what the pipeline stages are doing:
+#
+# 1. sed: extract prototypes of generated functions
+# 2. sed: decorate prototypes with generated arguments a1. a2,...z
+# 3. awk: generate the calls with args matching the formals
+# 4. sed: prefix function names in prototypes so the preprocessor won't expand
+#         them.
+# 5. cpp: macro-expand the file so the macro calls turn into C calls
+# 6. awk: strip the expansion junk off the front and add the new header
+# 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef
+#
+
+# keep the editing independent of locale:
+if test "${LANGUAGE+set}"    = set; then LANGUAGE=C;    export LANGUAGE;    fi
+if test "${LANG+set}"        = set; then LANG=C;        export LANG;        fi
+if test "${LC_ALL+set}"      = set; then LC_ALL=C;      export LC_ALL;      fi
+if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
+if test "${LC_CTYPE+set}"    = set; then LC_CTYPE=C;    export LC_CTYPE;    fi
+if test "${LC_COLLATE+set}"  = set; then LC_COLLATE=C;  export LC_COLLATE;  fi
+
+preprocessor="$1 -DNCURSES_INTERNALS -I../include"
+AWK="$2"
+USE="$3"
+
+PID=$$
+ED1=sed1_${PID}.sed
+ED2=sed2_${PID}.sed
+ED3=sed3_${PID}.sed
+ED4=sed4_${PID}.sed
+AW1=awk1_${PID}.awk
+AW2=awk2_${PID}.awk
+TMP=gen__${PID}.c
+trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0 1 2 5 15
+
+ALL=$USE
+if test "$USE" = implemented ; then
+	CALL="call_"
+	cat >$ED1 <<EOF1
+/^extern.*implemented/{
+	h
+	s/^.*implemented:\([^ 	*]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
+	g
+	s/^extern \([^;]*\);.*/\1/p
+	g
+	s/^.*implemented:\([^ 	*]*\).*/P_POUNDCendif/p
+}
+/^extern.*generated/{
+	h
+	s/^.*generated:\([^ 	*]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
+	g
+	s/^extern \([^;]*\);.*/\1/p
+	g
+	s/^.*generated:\([^ 	*]*\).*/P_POUNDCendif/p
+}
+EOF1
+else
+	CALL=""
+	cat >$ED1 <<EOF1
+/^extern.*${ALL}/{
+	h
+	s/^.*${ALL}:\([^ 	*]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
+	g
+	s/^extern \([^;]*\);.*/\1/p
+	g
+	s/^.*${ALL}:\([^ 	*]*\).*/P_POUNDCendif/p
+}
+EOF1
+fi
+
+cat >$ED2 <<EOF2
+/^P_/b nc
+/(void)/b nc
+	s/,/ a1% /
+	s/,/ a2% /
+	s/,/ a3% /
+	s/,/ a4% /
+	s/,/ a5% /
+	s/,/ a6% /
+	s/,/ a7% /
+	s/,/ a8% /
+	s/,/ a9% /
+	s/,/ a10% /
+	s/,/ a11% /
+	s/,/ a12% /
+	s/,/ a13% /
+	s/,/ a14% /
+	s/,/ a15% /
+	s/*/ * /g
+	s/%/ , /g
+	s/)/ z)/
+	s/\.\.\. z)/...)/
+:nc
+	s/(/ ( /
+	s/)/ )/
+EOF2
+
+cat >$ED3 <<EOF3
+/^P_/{
+	s/^P_POUNDCif_/#if /
+	s/^P_POUNDCendif/#endif/
+	s/^P_//
+	b done
+}
+	s/		*/ /g
+	s/  */ /g
+	s/ ,/,/g
+	s/( /(/g
+	s/ )/)/g
+	s/ gen_/ /
+	s/^M_/#undef /
+	s/^[ 	]*@[ 	]*@[ 	]*/	/
+:done
+EOF3
+
+if test "$USE" = generated ; then
+cat >$ED4 <<EOF
+	s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) \2 (\3)/
+EOF
+else
+cat >$ED4 <<EOF
+/^\(.*\) \(.*\) (\(.*\))\$/ {
+	h
+	s/^\(.*\) \(.*\) (\(.*\))\$/extern \1 call_\2 (\3);/
+	p
+	g
+	s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/
+	}
+EOF
+fi
+
+cat >$AW1 <<\EOF1
+BEGIN	{
+		skip=0;
+	}
+/^P_POUNDCif/ {
+		print "\n"
+		print $0
+		skip=0;
+}
+/^P_POUNDCendif/ {
+		print $0
+		skip=1;
+}
+$0 !~ /^P_/ {
+	if (skip)
+		print "\n"
+	skip=1;
+
+	first=$1
+	for (i = 1; i <= NF; i++) {
+		if ( $i != "NCURSES_CONST" ) {
+			first = i;
+			break;
+		}
+	}
+	second = first + 1;
+	if ( $first == "chtype" ) {
+		returnType = "Char";
+	} else if ( $first == "SCREEN" ) {
+		returnType = "SP";
+	} else if ( $first == "WINDOW" ) {
+		returnType = "Win";
+	} else if ( $first == "attr_t" || $second == "attrset" || $second == "standout" || $second == "standend" || $second == "wattrset" || $second == "wstandout" || $second == "wstandend" ) {
+		returnType = "Attr";
+	} else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
+		returnType = "Bool";
+	} else if ( $second == "*" ) {
+		returnType = "Ptr";
+	} else {
+		returnType = "Code";
+	}
+	myfunc = second;
+	for (i = second; i <= NF; i++) {
+		if ($i != "*") {
+			myfunc = i;
+			break;
+		}
+	}
+	if (using == "generated") {
+		print "M_" $myfunc
+	}
+	print $0;
+	print "{";
+	argcount = 1;
+	check = NF - 1;
+	if ($check == "void")
+		argcount = 0;
+	if (argcount != 0) {
+		for (i = 1; i <= NF; i++)
+			if ($i == ",")
+				argcount++;
+	}
+
+	# suppress trace-code for functions that we cannot do properly here,
+	# since they return data.
+	dotrace = 1;
+	if ($myfunc ~ /innstr/)
+		dotrace = 0;
+	if ($myfunc ~ /innwstr/)
+		dotrace = 0;
+
+	# workaround functions that we do not parse properly
+	if ($myfunc ~ /ripoffline/) {
+		dotrace = 0;
+		argcount = 2;
+	}
+	if ($myfunc ~ /wunctrl/) {
+		dotrace = 0;
+	}
+
+	call = "@@T((T_CALLED(\""
+	args = ""
+	comma = ""
+	num = 0;
+	pointer = 0;
+	va_list = 0;
+	varargs = 0;
+	argtype = ""
+	for (i = myfunc; i <= NF; i++) {
+		ch = $i;
+		if ( ch == "*" )
+			pointer = 1;
+		else if ( ch == "va_list" )
+			va_list = 1;
+		else if ( ch == "..." )
+			varargs = 1;
+		else if ( ch == "char" )
+			argtype = "char";
+		else if ( ch == "int" )
+			argtype = "int";
+		else if ( ch == "short" )
+			argtype = "short";
+		else if ( ch == "chtype" )
+			argtype = "chtype";
+		else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" )
+			argtype = "attr";
+
+		if ( ch == "," || ch == ")" ) {
+			if (va_list) {
+				call = call "%s"
+			} else if (varargs) {
+				call = call "%s"
+			} else if (pointer) {
+				if ( argtype == "char" ) {
+					call = call "%s"
+					comma = comma "_nc_visbuf2(" num ","
+					pointer = 0;
+				} else
+					call = call "%p"
+			} else if (argcount != 0) {
+				if ( argtype == "int" || argtype == "short" ) {
+					call = call "%d"
+					argtype = ""
+				} else if ( argtype != "" ) {
+					call = call "%s"
+					comma = comma "_trace" argtype "2(" num ","
+				} else {
+					call = call "%#lx"
+					comma = comma "(long)"
+				}
+			}
+			if (ch == ",") {
+				args = args comma "a" ++num;
+			} else if ( argcount != 0 ) {
+				if ( va_list ) {
+					args = args comma "\"va_list\""
+				} else if ( varargs ) {
+					args = args comma "\"...\""
+				} else {
+					args = args comma "z"
+				}
+			}
+			call = call ch
+			if (pointer == 0 && argcount != 0 && argtype != "" )
+				args = args ")"
+			if (args != "")
+				comma = ", "
+			pointer = 0;
+			argtype = ""
+		}
+		if ( i == 2 || ch == "(" )
+			call = call ch
+	}
+	call = call "\")"
+	if (args != "")
+		call = call ", " args
+	call = call ")); "
+
+	if (dotrace)
+		printf "%s", call
+
+	if (match($0, "^void"))
+		call = ""
+	else if (dotrace)
+		call = sprintf("return%s( ", returnType);
+	else
+		call = "@@return ";
+
+	call = call $myfunc "(";
+	for (i = 1; i < argcount; i++) {
+		if (i != 1)
+			call = call ", ";
+		call = call "a" i;
+	}
+	if ( argcount != 0 && $check != "..." ) {
+		if (argcount != 1)
+			call = call ", ";
+		call = call "z";
+	}
+	if (!match($0, "^void"))
+		call = call ") ";
+	if (dotrace)
+		call = call ")";
+	print call ";"
+
+	if (match($0, "^void"))
+		print "@@returnVoid;"
+	print "}";
+}
+EOF1
+
+cat >$AW2 <<EOF1
+BEGIN		{
+		print "/*"
+		print " * DO NOT EDIT THIS FILE BY HAND!"
+		printf " * It is generated by $0 %s.\n", "$USE"
+		if ( "$USE" == "generated" ) {
+			print " *"
+			print " * This is a file of trivial functions generated from macro"
+			print " * definitions in curses.h to satisfy the XSI Curses requirement"
+			print " * that every macro also exist as a callable function."
+			print " *"
+			print " * It will never be linked unless you call one of the entry"
+			print " * points with its normal macro definition disabled.  In that"
+			print " * case, if you have no shared libraries, it will indirectly"
+			print " * pull most of the rest of the library into your link image."
+		}
+		print " */"
+		print "#define NCURSES_ATTR_T int"
+		print "#include <curses.priv.h>"
+		print ""
+		}
+/^DECLARATIONS/	{start = 1; next;}
+		{if (start) print \$0;}
+END		{
+		if ( "$USE" != "generated" ) {
+			print "int main(void) { return 0; }"
+		}
+		}
+EOF1
+
+cat >$TMP <<EOF
+#include <ncurses_cfg.h>
+#undef NCURSES_NOMACROS
+#include <curses.h>
+
+DECLARATIONS
+
+EOF
+
+sed -n -f $ED1 \
+| sed -e 's/NCURSES_EXPORT(\(.*\)) \(.*\) (\(.*\))/\1 \2(\3)/' \
+| sed -f $ED2 \
+| $AWK -f $AW1 using=$USE \
+| sed \
+	-e 's/ [ ]*$//g' \
+	-e 's/^\([a-zA-Z_][a-zA-Z_]*[ *]*\)/\1 gen_/' \
+	-e 's/gen_$//' \
+	-e 's/  / /g' >>$TMP
+
+$preprocessor $TMP 2>/dev/null \
+| sed \
+	-e 's/  / /g' \
+	-e 's/^ //' \
+	-e 's/_Bool/NCURSES_BOOL/g' \
+| $AWK -f $AW2 \
+| sed -f $ED3 \
+| sed \
+	-e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/	return \1;/' \
+	-e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/	return \1;/' \
+	-e 's/gen_//' \
+	-e 's/^[ 	]*#/#/' \
+	-e '/#ident/d' \
+	-e '/#line/d' \
+| sed -f $ED4
diff --git a/ncurses/base/MKunctrl.awk b/ncurses/base/MKunctrl.awk
new file mode 100644
index 0000000..36fbeec
--- /dev/null
+++ b/ncurses/base/MKunctrl.awk
@@ -0,0 +1,192 @@
+# $Id: MKunctrl.awk,v 1.23 2008/10/04 21:40:24 tom Exp $
+##############################################################################
+# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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.                                                             #
+##############################################################################
+#
+# Author: Thomas E. Dickey (1997-on)
+#
+
+BEGIN	{
+		print "/* generated by MKunctrl.awk */"
+		print ""
+		print "#include <curses.priv.h>"
+		print "#include <ctype.h>"
+		print ""
+		print "#if USE_WIDEC_SUPPORT"
+		print "#if HAVE_WCTYPE_H"
+		print "#include <wctype.h>"
+		print "#endif"
+		print "#endif"
+		print ""
+		print "#undef unctrl"
+		print ""
+	}
+END	{
+		print "NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *sp, chtype ch)"
+		print "{"
+
+		blob=""
+		offset=0
+		if (bigstrings) {
+			printf "static const short unctrl_table[] = {"
+		} else {
+			printf "static const char* const unctrl_table[] = {"
+		}
+		for ( ch = 0; ch < 256; ch++ ) {
+			gap = ","
+			part=""
+			if ((ch % 8) == 0) {
+				printf "\n    "
+				if (ch != 0)
+					blob = blob "\""
+				blob = blob "\n    \""
+			}
+			if (bigstrings)
+				printf "%4d%s", offset, gap;
+			if (ch < 32) {
+				part = sprintf ("^\\%03o", ch + 64);
+				offset = offset + 3;
+			} else if (ch == 127) {
+				part = "^?";
+				offset = offset + 3;
+			} else if (ch >= 128 && ch < 160) {
+				part = sprintf("~\\%03o", ch - 64);
+				offset = offset + 3;
+			} else if (ch == 255) {
+				part = "~?";
+				offset = offset + 3;
+			} else if (ch >= 160) {
+				part = sprintf("M-\\%03o", ch - 128);
+				offset = offset + 4;
+			} else {
+				gap = gap " "
+				part = sprintf("\\%03o", ch);
+				offset = offset + 2;
+			}
+			if (ch == 255)
+				gap = "\n"
+			else if (((ch + 1) % 8) != 0)
+				gap = gap " "
+			if (bigstrings) {
+				blob = blob part "\\0";
+			} else {
+				printf "\"%s\"%s", part, gap
+			}
+		}
+		print "};"
+		blob = blob "\"";
+
+		print ""
+		printf "#if NCURSES_EXT_FUNCS\n";
+		if (bigstrings) {
+			blob = blob "\n/* printable values in 128-255 range */"
+			printf "static const short unctrl_c1[] = {"
+		} else {
+			printf "static const char* const unctrl_c1[] = {"
+		}
+		for ( ch = 128; ch < 256; ch++ ) {
+			gap = ","
+			if ((ch % 8) == 0) {
+				if (ch != 128)
+					blob = blob "\""
+				printf "\n    "
+				blob = blob "\n    \""
+			}
+			if (bigstrings) {
+				printf "%4d%s", offset, gap;
+				part = sprintf("\\%03o\\0", ch);
+				blob = blob part
+				offset = offset + 2;
+				if (((ch + 1) % 8) != 0)
+					gap = gap " "
+			} else {
+				if (ch >= 128) {
+					printf "\"\\%03o\"", ch
+					gap = gap " "
+				}
+				if (ch == 255)
+					gap = "\n"
+				else if (((ch + 1) % 8) != 0)
+					gap = gap " "
+				printf "%s", gap
+			}
+		}
+		print "};"
+		print "#endif /* NCURSES_EXT_FUNCS */"
+		blob = blob "\"\n"
+
+		print ""
+		if (bigstrings) {
+			print "static const char unctrl_blob[] = "blob";"
+			print ""
+			stringname = "unctrl_blob + unctrl"
+		} else {
+			stringname = "unctrl"
+		}
+		print  "\tint check = ChCharOf(ch);"
+		print  "\tconst char *result;"
+		print  ""
+		print  "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
+		print  "#if NCURSES_EXT_FUNCS"
+		print  "\t\tif ((sp != 0)"
+		print  "\t\t && (sp->_legacy_coding > 1)"
+		print  "\t\t && (check >= 128)"
+		print  "\t\t && (check < 160))"
+		printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
+		print  "\t\telse"
+		print  "#if USE_WIDEC_SUPPORT"
+		print  "\t\tif ((check >= 160)"
+		print  "\t\t && (check < 256)"
+		print  "\t\t && ((sp != 0)"
+		print  "\t\t  && ((sp->_legacy_coding > 0)"
+		print  "\t\t   || (sp->_legacy_coding == 0"
+		print  "\t\t       && (isprint(check) || iswprint(check))))))"
+		printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
+		print  "\t\telse"
+		print  "#else"
+		print  "\t\tif ((check >= 160)"
+		print  "\t\t && (check < 256)"
+		print  "\t\t && ((sp != 0)"
+		print  "\t\t  && ((sp->_legacy_coding > 0)"
+		print  "\t\t   || (sp->_legacy_coding == 0"
+		print  "\t\t       && isprint(check)))))"
+		printf "\t\t\tresult = %s_c1[check - 128];\n", stringname;
+		print  "\t\telse"
+		print  "#endif /* USE_WIDEC_SUPPORT */"
+		print  "#endif /* NCURSES_EXT_FUNCS */"
+		printf "\t\t\tresult = %s_table[check];\n", stringname;
+		print  "\t} else {"
+		print  "\t\tresult = 0;"
+		print  "\t}"
+		print  "\treturn (NCURSES_CONST char *)result;"
+		print  "}"
+		print  ""
+		print  "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)"
+		print  "{"
+		print  "\treturn _nc_unctrl(SP, ch);"
+		print  "}"
+	}
diff --git a/ncurses/base/README b/ncurses/base/README
new file mode 100644
index 0000000..4677e42
--- /dev/null
+++ b/ncurses/base/README
@@ -0,0 +1,35 @@
+-------------------------------------------------------------------------------
+-- Copyright (c) 1998,2006 Free Software Foundation, Inc.                    --
+--                                                                           --
+-- Permission is hereby granted, free of charge, to any person obtaining a   --
+-- copy of this software and associated documentation files (the             --
+-- "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: README,v 1.2 2006/04/22 22:19:37 tom Exp $
+-------------------------------------------------------------------------------
+
+The functions in this directory are the generic (not device-specific) modules
+of ncurses.
+
+As a rule, these modules should not depend directly on term.h references and
+associated terminfo function and variables.
diff --git a/ncurses/base/define_key.c b/ncurses/base/define_key.c
new file mode 100644
index 0000000..3d5815f
--- /dev/null
+++ b/ncurses/base/define_key.c
@@ -0,0 +1,70 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                    1997-on                     *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: define_key.c,v 1.13 2006/12/30 23:23:31 tom Exp $")
+
+NCURSES_EXPORT(int)
+define_key(const char *str, int keycode)
+{
+    int code = ERR;
+
+    T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
+    if (SP == 0) {
+	code = ERR;
+    } else if (keycode > 0) {
+	unsigned ukey = (unsigned) keycode;
+
+	if (str != 0) {
+	    define_key(str, 0);
+	} else if (has_key(keycode)) {
+	    while (_nc_remove_key(&(SP->_keytry), ukey))
+		code = OK;
+	}
+	if (str != 0) {
+	    if (key_defined(str) == 0) {
+		if (_nc_add_to_try(&(SP->_keytry), str, ukey) == OK) {
+		    code = OK;
+		} else {
+		    code = ERR;
+		}
+	    } else {
+		code = ERR;
+	    }
+	}
+    } else {
+	while (_nc_remove_string(&(SP->_keytry), str))
+	    code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/key_defined.c b/ncurses/base/key_defined.c
new file mode 100644
index 0000000..759ad82
--- /dev/null
+++ b/ncurses/base/key_defined.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 2003,2006 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey, 2003                                          *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: key_defined.c,v 1.6 2006/12/30 23:22:55 tom Exp $")
+
+static int
+find_definition(TRIES * tree, const char *str)
+{
+    TRIES *ptr;
+    int result = OK;
+
+    if (str != 0 && *str != '\0') {
+	for (ptr = tree; ptr != 0; ptr = ptr->sibling) {
+	    if (UChar(*str) == UChar(ptr->ch)) {
+		if (str[1] == '\0' && ptr->child != 0) {
+		    result = ERR;
+		} else if ((result = find_definition(ptr->child, str + 1))
+			   == OK) {
+		    result = ptr->value;
+		} else if (str[1] == '\0') {
+		    result = ERR;
+		}
+	    }
+	    if (result != OK)
+		break;
+	}
+    }
+    return (result);
+}
+
+/*
+ * Returns the keycode associated with the given string.  If none is found,
+ * return OK.  If the string is only a prefix to other strings, return ERR.
+ * Otherwise, return the keycode's value (neither OK/ERR).
+ */
+NCURSES_EXPORT(int)
+key_defined(const char *str)
+{
+    int code = ERR;
+
+    T((T_CALLED("key_defined(%s)"), _nc_visbuf(str)));
+    if (SP != 0 && str != 0) {
+	code = find_definition(SP->_keytry, str);
+    }
+
+    returnCode(code);
+}
diff --git a/ncurses/base/keybound.c b/ncurses/base/keybound.c
new file mode 100644
index 0000000..2995714
--- /dev/null
+++ b/ncurses/base/keybound.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                 1999-on                        *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: keybound.c,v 1.7 2006/06/17 18:19:24 tom Exp $")
+
+/*
+ * Returns the count'th string definition which is associated with the
+ * given keycode.  The result is malloc'd, must be freed by the caller.
+ */
+NCURSES_EXPORT(char *)
+keybound(int code, int count)
+{
+    char *result = 0;
+
+    T((T_CALLED("keybound(%d,%d)"), code, count));
+    if (SP != 0 && code >= 0) {
+	result = _nc_expand_try(SP->_keytry, (unsigned) code, &count, 0);
+    }
+    returnPtr(result);
+}
diff --git a/ncurses/base/keyok.c b/ncurses/base/keyok.c
new file mode 100644
index 0000000..ad8988c
--- /dev/null
+++ b/ncurses/base/keyok.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey            1997-on                             *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: keyok.c,v 1.7 2006/12/30 16:22:33 tom Exp $")
+
+/*
+ * Enable (or disable) ncurses' interpretation of a keycode by adding (or
+ * removing) the corresponding 'tries' entry.
+ *
+ * Do this by storing a second tree of tries, which records the disabled keys. 
+ * The simplest way to copy is to make a function that returns the string (with
+ * nulls set to 0200), then use that to reinsert the string into the
+ * corresponding tree.
+ */
+
+NCURSES_EXPORT(int)
+keyok(int c, bool flag)
+{
+    int code = ERR;
+    int count = 0;
+    char *s;
+
+    T((T_CALLED("keyok(%d,%d)"), c, flag));
+    if (c >= 0) {
+	unsigned ch = (unsigned) c;
+	if (flag) {
+	    while ((s = _nc_expand_try(SP->_key_ok, ch, &count, 0)) != 0
+		   && _nc_remove_key(&(SP->_key_ok), ch)) {
+		code = _nc_add_to_try(&(SP->_keytry), s, ch);
+		free(s);
+		count = 0;
+		if (code != OK)
+		    break;
+	    }
+	} else {
+	    while ((s = _nc_expand_try(SP->_keytry, ch, &count, 0)) != 0
+		   && _nc_remove_key(&(SP->_keytry), ch)) {
+		code = _nc_add_to_try(&(SP->_key_ok), s, ch);
+		free(s);
+		count = 0;
+		if (code != OK)
+		    break;
+	    }
+	}
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/legacy_coding.c b/ncurses/base/legacy_coding.c
new file mode 100644
index 0000000..1c2f160
--- /dev/null
+++ b/ncurses/base/legacy_coding.c
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * Copyright (c) 2005 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: legacy_coding.c,v 1.2 2005/12/17 23:38:17 tom Exp $")
+
+NCURSES_EXPORT(int)
+use_legacy_coding(int level)
+{
+    int result = ERR;
+
+    T((T_CALLED("use_legacy_coding(%d)"), level));
+    if (level >= 0 && level <= 2 && SP != 0) {
+	result = SP->_legacy_coding;
+	SP->_legacy_coding = level;
+    }
+    returnCode(result);
+}
diff --git a/ncurses/base/lib_addch.c b/ncurses/base/lib_addch.c
new file mode 100644
index 0000000..20a97a0
--- /dev/null
+++ b/ncurses/base/lib_addch.c
@@ -0,0 +1,548 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/*
+**	lib_addch.c
+**
+**	The routine waddch().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_addch.c,v 1.113 2008/08/16 19:20:04 tom Exp $")
+
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+
+/*
+ * Ugly microtweaking alert.  Everything from here to end of module is
+ * likely to be speed-critical -- profiling data sure says it is!
+ * Most of the important screen-painting functions are shells around
+ * waddch().  So we make every effort to reduce function-call overhead
+ * by inlining stuff, even at the cost of making wrapped copies for
+ * export.  Also we supply some internal versions that don't call the
+ * window sync hook, for use by string-put functions.
+ */
+
+/* Return bit mask for clearing color pair number if given ch has color */
+#define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0))
+
+static NCURSES_INLINE NCURSES_CH_T
+render_char(WINDOW *win, NCURSES_CH_T ch)
+/* compute a rendition of the given char correct for the current context */
+{
+    attr_t a = WINDOW_ATTRS(win);
+    int pair = GetPair(ch);
+
+    if (ISBLANK(ch)
+	&& AttrOf(ch) == A_NORMAL
+	&& pair == 0) {
+	/* color/pair in attrs has precedence over bkgrnd */
+	ch = win->_nc_bkgd;
+	SetAttr(ch, a | AttrOf(win->_nc_bkgd));
+	if ((pair = GET_WINDOW_PAIR(win)) == 0)
+	    pair = GetPair(win->_nc_bkgd);
+	SetPair(ch, pair);
+    } else {
+	/* color in attrs has precedence over bkgrnd */
+	a |= AttrOf(win->_nc_bkgd) & COLOR_MASK(a);
+	/* color in ch has precedence */
+	if (pair == 0) {
+	    if ((pair = GET_WINDOW_PAIR(win)) == 0)
+		pair = GetPair(win->_nc_bkgd);
+	}
+#if 0
+	if (pair > 255) {
+	    NCURSES_CH_T fixme = ch;
+	    SetPair(fixme, pair);
+	}
+#endif
+	AddAttr(ch, (a & COLOR_MASK(AttrOf(ch))));
+	SetPair(ch, pair);
+    }
+
+    TR(TRACE_VIRTPUT,
+       ("render_char bkg %s (%d), attrs %s (%d) -> ch %s (%d)",
+	_tracech_t2(1, CHREF(win->_nc_bkgd)),
+	GetPair(win->_nc_bkgd),
+	_traceattr(WINDOW_ATTRS(win)),
+	GET_WINDOW_PAIR(win),
+	_tracech_t2(3, CHREF(ch)),
+	GetPair(ch)));
+
+    return (ch);
+}
+
+NCURSES_EXPORT(NCURSES_CH_T)
+_nc_render(WINDOW *win, NCURSES_CH_T ch)
+/* make render_char() visible while still allowing us to inline it below */
+{
+    return render_char(win, ch);
+}
+
+/* check if position is legal; if not, return error */
+#ifndef NDEBUG			/* treat this like an assertion */
+#define CHECK_POSITION(win, x, y) \
+	if (y > win->_maxy \
+	 || x > win->_maxx \
+	 || y < 0 \
+	 || x < 0) { \
+		TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \
+				   "(_maxx = %d, _maxy = %d)", win, x, y, \
+				   win->_maxx, win->_maxy)); \
+		return(ERR); \
+	}
+#else
+#define CHECK_POSITION(win, x, y)	/* nothing */
+#endif
+
+static bool
+newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T * ypos)
+{
+    bool result = FALSE;
+
+    if (*ypos >= win->_regtop && *ypos == win->_regbottom) {
+	*ypos = win->_regbottom;
+	result = TRUE;
+    } else {
+	*ypos += 1;
+    }
+    return result;
+}
+
+/*
+ * The _WRAPPED flag is useful only for telling an application that we've just
+ * wrapped the cursor.  We don't do anything with this flag except set it when
+ * wrapping, and clear it whenever we move the cursor.  If we try to wrap at
+ * the lower-right corner of a window, we cannot move the cursor (since that
+ * wouldn't be legal).  So we return an error (which is what SVr4 does). 
+ * Unlike SVr4, we can successfully add a character to the lower-right corner
+ * (Solaris 2.6 does this also, however).
+ */
+static int
+wrap_to_next_line(WINDOW *win)
+{
+    win->_flags |= _WRAPPED;
+    if (newline_forces_scroll(win, &(win->_cury))) {
+	win->_curx = win->_maxx;
+	if (!win->_scroll)
+	    return (ERR);
+	scroll(win);
+    }
+    win->_curx = 0;
+    return (OK);
+}
+
+#if USE_WIDEC_SUPPORT
+static int waddch_literal(WINDOW *, NCURSES_CH_T);
+/*
+ * Fill the given number of cells with blanks using the current background
+ * rendition.  This saves/restores the current x-position.
+ */
+static void
+fill_cells(WINDOW *win, int count)
+{
+    NCURSES_CH_T blank = blankchar;
+    int save_x = win->_curx;
+    int save_y = win->_cury;
+
+    while (count-- > 0) {
+	if (waddch_literal(win, blank) == ERR)
+	    break;
+    }
+    win->_curx = save_x;
+    win->_cury = save_y;
+}
+#endif
+
+/*
+ * Build up the bytes for a multibyte character, returning the length when
+ * complete (a positive number), -1 for error and -2 for incomplete.
+ */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(int)
+_nc_build_wch(WINDOW *win, ARG_CH_T ch)
+{
+    char *buffer = WINDOW_EXT(win, addch_work);
+    int len;
+    int x = win->_curx;
+    int y = win->_cury;
+    mbstate_t state;
+    wchar_t result;
+
+    if ((WINDOW_EXT(win, addch_used) != 0) &&
+	(WINDOW_EXT(win, addch_x) != x ||
+	 WINDOW_EXT(win, addch_y) != y)) {
+	/* discard the incomplete multibyte character */
+	WINDOW_EXT(win, addch_used) = 0;
+	TR(TRACE_VIRTPUT,
+	   ("Alert discarded multibyte on move (%d,%d) -> (%d,%d)",
+	    WINDOW_EXT(win, addch_y), WINDOW_EXT(win, addch_x),
+	    y, x));
+    }
+    WINDOW_EXT(win, addch_x) = x;
+    WINDOW_EXT(win, addch_y) = y;
+
+    init_mb(state);
+    buffer[WINDOW_EXT(win, addch_used)] = (char) CharOf(CHDEREF(ch));
+    WINDOW_EXT(win, addch_used) += 1;
+    buffer[WINDOW_EXT(win, addch_used)] = '\0';
+    if ((len = mbrtowc(&result,
+		       buffer,
+		       WINDOW_EXT(win, addch_used), &state)) > 0) {
+	attr_t attrs = AttrOf(CHDEREF(ch));
+	if_EXT_COLORS(int pair = GetPair(CHDEREF(ch)));
+	SetChar(CHDEREF(ch), result, attrs);
+	if_EXT_COLORS(SetPair(CHDEREF(ch), pair));
+	WINDOW_EXT(win, addch_used) = 0;
+    } else if (len == -1) {
+	/*
+	 * An error occurred.  We could either discard everything,
+	 * or assume that the error was in the previous input.
+	 * Try the latter.
+	 */
+	TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error"));
+	/* handle this with unctrl() */
+	WINDOW_EXT(win, addch_used) = 0;
+    }
+    return len;
+}
+#endif /* USE_WIDEC_SUPPORT */
+
+static
+#if !USE_WIDEC_SUPPORT		/* cannot be inline if it is recursive */
+NCURSES_INLINE
+#endif
+int
+waddch_literal(WINDOW *win, NCURSES_CH_T ch)
+{
+    int x;
+    int y;
+    struct ldat *line;
+
+    x = win->_curx;
+    y = win->_cury;
+
+    CHECK_POSITION(win, x, y);
+
+    ch = render_char(win, ch);
+
+    line = win->_line + y;
+
+    CHANGED_CELL(line, x);
+
+    /*
+     * Build up multibyte characters until we have a wide-character.
+     */
+    if_WIDEC({
+	if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) {
+	    int len = _nc_build_wch(win, CHREF(ch));
+
+	    if (len >= -1) {
+		/* handle EILSEQ */
+		if (is8bits(CharOf(ch))) {
+		    const char *s = unctrl((chtype) CharOf(ch));
+		    if (s[1] != 0) {
+			return waddstr(win, s);
+		    }
+		}
+		if (len == -1)
+		    return waddch(win, ' ');
+	    } else {
+		return OK;
+	    }
+	}
+    });
+
+    /*
+     * Non-spacing characters are added to the current cell.
+     *
+     * Spacing characters that are wider than one column require some display
+     * adjustments.
+     */
+    if_WIDEC({
+	int len = wcwidth(CharOf(ch));
+	int i;
+	int j;
+	wchar_t *chars;
+
+	if (len == 0) {		/* non-spacing */
+	    if ((x > 0 && y >= 0)
+		|| (win->_maxx >= 0 && win->_cury >= 1)) {
+		if (x > 0 && y >= 0)
+		    chars = (win->_line[y].text[x - 1].chars);
+		else
+		    chars = (win->_line[y - 1].text[win->_maxx].chars);
+		for (i = 0; i < CCHARW_MAX; ++i) {
+		    if (chars[i] == 0) {
+			TR(TRACE_VIRTPUT,
+			   ("added non-spacing %d: %x",
+			    x, (int) CharOf(ch)));
+			chars[i] = CharOf(ch);
+			break;
+		    }
+		}
+	    }
+	    goto testwrapping;
+	} else if (len > 1) {	/* multi-column characters */
+	    /*
+	     * Check if the character will fit on the current line.  If it does
+	     * not fit, fill in the remainder of the line with blanks.  and
+	     * move to the next line.
+	     */
+	    if (len > win->_maxx + 1) {
+		TR(TRACE_VIRTPUT, ("character will not fit"));
+		return ERR;
+	    } else if (x + len > win->_maxx + 1) {
+		int count = win->_maxx + 1 - x;
+		TR(TRACE_VIRTPUT, ("fill %d remaining cells", count));
+		fill_cells(win, count);
+		if (wrap_to_next_line(win) == ERR)
+		    return ERR;
+		x = win->_curx;
+		y = win->_cury;
+	    }
+	    /*
+	     * Check for cells which are orphaned by adding this character, set
+	     * those to blanks.
+	     *
+	     * FIXME: this actually could fill j-i cells, more complicated to
+	     * setup though.
+	     */
+	    for (i = 0; i < len; ++i) {
+		if (isWidecBase(win->_line[y].text[x + i])) {
+		    break;
+		} else if (isWidecExt(win->_line[y].text[x + i])) {
+		    for (j = i; x + j <= win->_maxx; ++j) {
+			if (!isWidecExt(win->_line[y].text[x + j])) {
+			    TR(TRACE_VIRTPUT, ("fill %d orphan cells", j));
+			    fill_cells(win, j);
+			    break;
+			}
+		    }
+		    break;
+		}
+	    }
+	    /*
+	     * Finally, add the cells for this character.
+	     */
+	    for (i = 0; i < len; ++i) {
+		NCURSES_CH_T value = ch;
+		SetWidecExt(value, i);
+		TR(TRACE_VIRTPUT, ("multicolumn %d:%d (%d,%d)",
+				   i + 1, len,
+				   win->_begy + y, win->_begx + x));
+		line->text[x] = value;
+		CHANGED_CELL(line, x);
+		++x;
+	    }
+	    goto testwrapping;
+	}
+    });
+
+    /*
+     * Single-column characters.
+     */
+    line->text[x++] = ch;
+    /*
+     * This label is used only for wide-characters.
+     */
+    if_WIDEC(
+  testwrapping:
+    );
+
+    TR(TRACE_VIRTPUT, ("cell (%ld, %ld..%d) = %s",
+		       (long) win->_cury, (long) win->_curx, x - 1,
+		       _tracech_t(CHREF(ch))));
+
+    if (x > win->_maxx) {
+	return wrap_to_next_line(win);
+    }
+    win->_curx = x;
+    return OK;
+}
+
+static NCURSES_INLINE int
+waddch_nosync(WINDOW *win, const NCURSES_CH_T ch)
+/* the workhorse function -- add a character to the given window */
+{
+    NCURSES_SIZE_T x, y;
+    chtype t = CharOf(ch);
+    const char *s = unctrl(t);
+
+    /*
+     * If we are using the alternate character set, forget about locale.
+     * Otherwise, if unctrl() returns a single-character or the locale
+     * claims the code is printable, treat it that way.
+     */
+    if ((AttrOf(ch) & A_ALTCHARSET)
+	|| (
+#if USE_WIDEC_SUPPORT
+	       (SP != 0 && SP->_legacy_coding) &&
+#endif
+	       s[1] == 0
+	)
+	|| (
+	       isprint(t)
+#if USE_WIDEC_SUPPORT
+	       || ((SP == 0 || !SP->_legacy_coding) &&
+		   (WINDOW_EXT(win, addch_used)
+		    || !_nc_is_charable(CharOf(ch))))
+#endif
+	))
+	return waddch_literal(win, ch);
+
+    /*
+     * Handle carriage control and other codes that are not printable, or are
+     * known to expand to more than one character according to unctrl().
+     */
+    x = win->_curx;
+    y = win->_cury;
+
+    switch (t) {
+    case '\t':
+	x += (TABSIZE - (x % TABSIZE));
+
+	/*
+	 * Space-fill the tab on the bottom line so that we'll get the
+	 * "correct" cursor position.
+	 */
+	if ((!win->_scroll && (y == win->_regbottom))
+	    || (x <= win->_maxx)) {
+	    NCURSES_CH_T blank = blankchar;
+	    AddAttr(blank, AttrOf(ch));
+	    while (win->_curx < x) {
+		if (waddch_literal(win, blank) == ERR)
+		    return (ERR);
+	    }
+	    break;
+	} else {
+	    wclrtoeol(win);
+	    win->_flags |= _WRAPPED;
+	    if (newline_forces_scroll(win, &y)) {
+		x = win->_maxx;
+		if (win->_scroll) {
+		    scroll(win);
+		    x = 0;
+		}
+	    } else {
+		x = 0;
+	    }
+	}
+	break;
+    case '\n':
+	wclrtoeol(win);
+	if (newline_forces_scroll(win, &y)) {
+	    if (win->_scroll)
+		scroll(win);
+	    else
+		return (ERR);
+	}
+	/* FALLTHRU */
+    case '\r':
+	x = 0;
+	win->_flags &= ~_WRAPPED;
+	break;
+    case '\b':
+	if (x == 0)
+	    return (OK);
+	x--;
+	win->_flags &= ~_WRAPPED;
+	break;
+    default:
+	while (*s) {
+	    NCURSES_CH_T sch;
+	    SetChar(sch, *s++, AttrOf(ch));
+	    if_EXT_COLORS(SetPair(sch, GetPair(ch)));
+	    if (waddch_literal(win, sch) == ERR)
+		return ERR;
+	}
+	return (OK);
+    }
+
+    win->_curx = x;
+    win->_cury = y;
+
+    return (OK);
+}
+
+NCURSES_EXPORT(int)
+_nc_waddch_nosync(WINDOW *win, const NCURSES_CH_T c)
+/* export copy of waddch_nosync() so the string-put functions can use it */
+{
+    return (waddch_nosync(win, c));
+}
+
+/*
+ * The versions below call _nc_synchook().  We wanted to avoid this in the
+ * version exported for string puts; they'll call _nc_synchook once at end
+ * of run.
+ */
+
+/* These are actual entry points */
+
+NCURSES_EXPORT(int)
+waddch(WINDOW *win, const chtype ch)
+{
+    int code = ERR;
+    NCURSES_CH_T wch;
+    SetChar2(wch, ch);
+
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win,
+				      _tracechtype(ch)));
+
+    if (win && (waddch_nosync(win, wch) != ERR)) {
+	_nc_synchook(win);
+	code = OK;
+    }
+
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+    return (code);
+}
+
+NCURSES_EXPORT(int)
+wechochar(WINDOW *win, const chtype ch)
+{
+    int code = ERR;
+    NCURSES_CH_T wch;
+    SetChar2(wch, ch);
+
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win,
+				      _tracechtype(ch)));
+
+    if (win && (waddch_nosync(win, wch) != ERR)) {
+	bool save_immed = win->_immed;
+	win->_immed = TRUE;
+	_nc_synchook(win);
+	win->_immed = save_immed;
+	code = OK;
+    }
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+    return (code);
+}
diff --git a/ncurses/base/lib_addstr.c b/ncurses/base/lib_addstr.c
new file mode 100644
index 0000000..4e3a040
--- /dev/null
+++ b/ncurses/base/lib_addstr.c
@@ -0,0 +1,245 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *                                                                          *
+ *  Rewritten 2001-2004 to support wide-characters by                       *
+ *	Sven Verdoolaege                                                    *
+ *	Thomas Dickey                                                       *
+ ****************************************************************************/
+
+/*
+**	lib_addstr.c
+*
+**	The routines waddnstr(), waddchnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_addstr.c,v 1.48 2007/10/13 19:56:57 tom Exp $")
+
+NCURSES_EXPORT(int)
+waddnstr(WINDOW *win, const char *astr, int n)
+{
+    const char *str = astr;
+    int code = ERR;
+
+    T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbufn(astr, n), n));
+
+    if (win && (str != 0)) {
+	TR(TRACE_VIRTPUT | TRACE_ATTRS,
+	   ("... current %s", _traceattr(WINDOW_ATTRS(win))));
+	code = OK;
+	if (n < 0)
+	    n = (int) strlen(astr);
+
+	TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
+	while ((n-- > 0) && (*str != '\0')) {
+	    NCURSES_CH_T ch;
+	    TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str)));
+	    SetChar(ch, UChar(*str++), A_NORMAL);
+	    if (_nc_waddch_nosync(win, ch) == ERR) {
+		code = ERR;
+		break;
+	    }
+	}
+	_nc_synchook(win);
+    }
+    TR(TRACE_VIRTPUT, ("waddnstr returns %d", code));
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+waddchnstr(WINDOW *win, const chtype *astr, int n)
+{
+    NCURSES_SIZE_T y, x;
+    int code = OK;
+    int i;
+    struct ldat *line;
+
+    T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n));
+
+    if (!win)
+	returnCode(ERR);
+
+    y = win->_cury;
+    x = win->_curx;
+    if (n < 0) {
+	const chtype *str;
+	n = 0;
+	for (str = (const chtype *) astr; *str != 0; str++)
+	    n++;
+    }
+    if (n > win->_maxx - x + 1)
+	n = win->_maxx - x + 1;
+    if (n == 0)
+	returnCode(code);
+
+    line = &(win->_line[y]);
+    for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) {
+	SetChar2(line->text[i + x], astr[i]);
+    }
+    CHANGED_RANGE(line, x, x + n - 1);
+
+    _nc_synchook(win);
+    returnCode(code);
+}
+
+#if USE_WIDEC_SUPPORT
+
+NCURSES_EXPORT(int)
+_nc_wchstrlen(const cchar_t *s)
+{
+    int result = 0;
+    while (CharOf(s[result]) != L'\0') {
+	result++;
+    }
+    return result;
+}
+
+NCURSES_EXPORT(int)
+wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
+{
+    static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+    NCURSES_SIZE_T y;
+    NCURSES_SIZE_T x;
+    int code = OK;
+    struct ldat *line;
+    int i, j, start, len, end;
+
+    T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n));
+
+    if (!win)
+	returnCode(ERR);
+
+    y = win->_cury;
+    x = win->_curx;
+    if (n < 0) {
+	n = _nc_wchstrlen(astr);
+    }
+    if (n > win->_maxx - x + 1)
+	n = win->_maxx - x + 1;
+    if (n == 0)
+	returnCode(code);
+
+    line = &(win->_line[y]);
+    start = x;
+    end = x + n - 1;
+
+    /*
+     * Reset orphaned cells of multi-column characters that extend up to the
+     * new string's location to blanks.
+     */
+    if (x > 0 && isWidecExt(line->text[x])) {
+	for (i = 0; i <= x; ++i) {
+	    if (!isWidecExt(line->text[x - i])) {
+		/* must be isWidecBase() */
+		start -= i;
+		while (i > 0) {
+		    line->text[x - i--] = _nc_render(win, blank);
+		}
+		break;
+	    }
+	}
+    }
+
+    /*
+     * Copy the new string to the window.
+     */
+    for (i = 0; i < n && CharOf(astr[i]) != L'\0' && x <= win->_maxx; ++i) {
+	if (isWidecExt(astr[i]))
+	    continue;
+
+	len = wcwidth(CharOf(astr[i]));
+
+	if (x + len - 1 <= win->_maxx) {
+	    line->text[x] = _nc_render(win, astr[i]);
+	    if (len > 1) {
+		for (j = 0; j < len; ++j) {
+		    if (j != 0) {
+			line->text[x + j] = line->text[x];
+		    }
+		    SetWidecExt(line->text[x + j], j);
+		}
+	    }
+	    x += len;
+	    end += len - 1;
+	} else {
+	    break;
+	}
+    }
+
+    /*
+     * Set orphaned cells of multi-column characters which lie after the new
+     * string to blanks.
+     */
+    while (x <= win->_maxx && isWidecExt(line->text[x])) {
+	line->text[x] = _nc_render(win, blank);
+	++end;
+	++x;
+    }
+    CHANGED_RANGE(line, start, end);
+
+    _nc_synchook(win);
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+waddnwstr(WINDOW *win, const wchar_t *str, int n)
+{
+    int code = ERR;
+
+    T((T_CALLED("waddnwstr(%p,%s,%d)"), win, _nc_viswbufn(str, n), n));
+
+    if (win && (str != 0)) {
+	TR(TRACE_VIRTPUT | TRACE_ATTRS,
+	   ("... current %s", _traceattr(WINDOW_ATTRS(win))));
+	code = OK;
+	if (n < 0)
+	    n = (int) wcslen(str);
+
+	TR(TRACE_VIRTPUT, ("str is not null, length = %d", n));
+	while ((n-- > 0) && (*str != L('\0'))) {
+	    NCURSES_CH_T ch;
+	    TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str));
+	    SetChar(ch, *str++, A_NORMAL);
+	    if (wadd_wch(win, &ch) == ERR) {
+		code = ERR;
+		break;
+	    }
+	}
+	_nc_synchook(win);
+    }
+    TR(TRACE_VIRTPUT, ("waddnwstr returns %d", code));
+    returnCode(code);
+}
+
+#endif
diff --git a/ncurses/base/lib_beep.c b/ncurses/base/lib_beep.c
new file mode 100644
index 0000000..b478f25
--- /dev/null
+++ b/ncurses/base/lib_beep.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	beep.c
+ *
+ *	The routine beep().
+ *
+ */
+
+#include <curses.priv.h>
+#include <term.h>		/* beep, flash */
+
+MODULE_ID("$Id: lib_beep.c,v 1.10 2005/04/09 15:20:04 tom Exp $")
+
+/*
+ *	beep()
+ *
+ *	Sound the current terminal's audible bell if it has one.   If not,
+ *	flash the screen if possible.
+ *
+ */
+
+NCURSES_EXPORT(int)
+beep(void)
+{
+    int res = ERR;
+
+    T((T_CALLED("beep()")));
+
+    /* FIXME: should make sure that we are not in altchar mode */
+    if (cur_term == 0) {
+	res = ERR;
+    } else if (bell) {
+	TPUTS_TRACE("bell");
+	res = putp(bell);
+	_nc_flush();
+    } else if (flash_screen) {
+	TPUTS_TRACE("flash_screen");
+	res = putp(flash_screen);
+	_nc_flush();
+    }
+
+    returnCode(res);
+}
diff --git a/ncurses/base/lib_bkgd.c b/ncurses/base/lib_bkgd.c
new file mode 100644
index 0000000..c99e0c5
--- /dev/null
+++ b/ncurses/base/lib_bkgd.c
@@ -0,0 +1,156 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Juergen Pfeifer                         1997                    *
+ *     and: Sven Verdoolaege                        2000                    *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_bkgd.c,v 1.36 2008/03/23 00:09:14 tom Exp $")
+
+/*
+ * Set the window's background information.
+ */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(void)
+#else
+static NCURSES_INLINE void
+#endif
+wbkgrndset(WINDOW *win, const ARG_CH_T ch)
+{
+    T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch)));
+
+    if (win) {
+	attr_t off = AttrOf(win->_nc_bkgd);
+	attr_t on = AttrOf(CHDEREF(ch));
+
+	toggle_attr_off(WINDOW_ATTRS(win), off);
+	toggle_attr_on(WINDOW_ATTRS(win), on);
+
+#if NCURSES_EXT_COLORS
+	{
+	    int pair;
+
+	    if ((pair = GetPair(win->_nc_bkgd)) != 0)
+		SET_WINDOW_PAIR(win, 0);
+	    if ((pair = GetPair(CHDEREF(ch))) != 0)
+		SET_WINDOW_PAIR(win, pair);
+	}
+#endif
+
+	if (CharOf(CHDEREF(ch)) == L('\0')) {
+	    SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch)));
+	    if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch))));
+	} else {
+	    win->_nc_bkgd = CHDEREF(ch);
+	}
+#if USE_WIDEC_SUPPORT
+	/*
+	 * If we're compiled for wide-character support, _bkgrnd is the
+	 * preferred location for the background information since it stores
+	 * more than _bkgd.  Update _bkgd each time we modify _bkgrnd, so the
+	 * macro getbkgd() will work.
+	 */
+	{
+	    cchar_t wch;
+	    int tmp;
+
+	    wgetbkgrnd(win, &wch);
+	    tmp = _nc_to_char((wint_t) CharOf(wch));
+
+	    win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp)
+			  | (AttrOf(wch) & ALL_BUT_COLOR)
+			  | COLOR_PAIR(GET_WINDOW_PAIR(win)));
+	}
+#endif
+    }
+    returnVoid;
+}
+
+NCURSES_EXPORT(void)
+wbkgdset(WINDOW *win, chtype ch)
+{
+    NCURSES_CH_T wch;
+    SetChar2(wch, ch);
+    wbkgrndset(win, CHREF(wch));
+}
+
+/*
+ * Set the window's background information and apply it to each cell.
+ */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(int)
+#else
+static NCURSES_INLINE int
+#undef wbkgrnd
+#endif
+wbkgrnd(WINDOW *win, const ARG_CH_T ch)
+{
+    int code = ERR;
+    int x, y;
+    NCURSES_CH_T new_bkgd = CHDEREF(ch);
+
+    T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch)));
+
+    if (win) {
+	NCURSES_CH_T old_bkgrnd;
+	wgetbkgrnd(win, &old_bkgrnd);
+
+	wbkgrndset(win, CHREF(new_bkgd));
+	wattrset(win, AttrOf(win->_nc_bkgd));
+
+	for (y = 0; y <= win->_maxy; y++) {
+	    for (x = 0; x <= win->_maxx; x++) {
+		if (CharEq(win->_line[y].text[x], old_bkgrnd)) {
+		    win->_line[y].text[x] = win->_nc_bkgd;
+		} else {
+		    NCURSES_CH_T wch = win->_line[y].text[x];
+		    RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT)));
+		    win->_line[y].text[x] = _nc_render(win, wch);
+		}
+	    }
+	}
+	touchwin(win);
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wbkgd(WINDOW *win, chtype ch)
+{
+    NCURSES_CH_T wch;
+    SetChar2(wch, ch);
+    return wbkgrnd(win, CHREF(wch));
+}
diff --git a/ncurses/base/lib_box.c b/ncurses/base/lib_box.c
new file mode 100644
index 0000000..d6cfc6c
--- /dev/null
+++ b/ncurses/base/lib_box.c
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Sven Verdoolaege                        2001                    *
+ ****************************************************************************/
+
+/*
+**	lib_box.c
+**
+**	The routine wborder().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_box.c,v 1.22 2005/11/26 15:39:42 tom Exp $")
+
+#if USE_WIDEC_SUPPORT
+static NCURSES_INLINE chtype
+_my_render(WINDOW *win, chtype ch)
+{
+    NCURSES_CH_T wch;
+    SetChar2(wch, ch);
+    wch = _nc_render(win, wch);
+    return CharOf(wch) | AttrOf(wch);
+}
+#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _my_render(win, (ch == 0) ? def : ch)
+#else
+#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _nc_render(win, (ch == 0) ? def : ch)
+#endif
+
+NCURSES_EXPORT(int)
+wborder(WINDOW *win,
+	chtype ls, chtype rs,
+	chtype ts, chtype bs,
+	chtype tl, chtype tr,
+	chtype bl, chtype br)
+{
+    NCURSES_SIZE_T i;
+    NCURSES_SIZE_T endx, endy;
+    chtype wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
+
+    T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
+       win,
+       _tracechtype2(1, ls),
+       _tracechtype2(2, rs),
+       _tracechtype2(3, ts),
+       _tracechtype2(4, bs),
+       _tracechtype2(5, tl),
+       _tracechtype2(6, tr),
+       _tracechtype2(7, bl),
+       _tracechtype2(8, br)));
+
+    if (!win)
+	returnCode(ERR);
+
+    RENDER_WITH_DEFAULT(ls, ACS_VLINE);
+    RENDER_WITH_DEFAULT(rs, ACS_VLINE);
+    RENDER_WITH_DEFAULT(ts, ACS_HLINE);
+    RENDER_WITH_DEFAULT(bs, ACS_HLINE);
+    RENDER_WITH_DEFAULT(tl, ACS_ULCORNER);
+    RENDER_WITH_DEFAULT(tr, ACS_URCORNER);
+    RENDER_WITH_DEFAULT(bl, ACS_LLCORNER);
+    RENDER_WITH_DEFAULT(br, ACS_LRCORNER);
+
+    T(("using %s, %s, %s, %s, %s, %s, %s, %s",
+       _tracechtype2(1, wls),
+       _tracechtype2(2, wrs),
+       _tracechtype2(3, wts),
+       _tracechtype2(4, wbs),
+       _tracechtype2(5, wtl),
+       _tracechtype2(6, wtr),
+       _tracechtype2(7, wbl),
+       _tracechtype2(8, wbr)));
+
+    endx = win->_maxx;
+    endy = win->_maxy;
+
+    for (i = 0; i <= endx; i++) {
+	SetChar2(win->_line[0].text[i], wts);
+	SetChar2(win->_line[endy].text[i], wbs);
+    }
+    win->_line[endy].firstchar = win->_line[0].firstchar = 0;
+    win->_line[endy].lastchar = win->_line[0].lastchar = endx;
+
+    for (i = 0; i <= endy; i++) {
+	SetChar2(win->_line[i].text[0], wls);
+	SetChar2(win->_line[i].text[endx], wrs);
+	win->_line[i].firstchar = 0;
+	win->_line[i].lastchar = endx;
+    }
+    SetChar2(win->_line[0].text[0], wtl);
+    SetChar2(win->_line[0].text[endx], wtr);
+    SetChar2(win->_line[endy].text[0], wbl);
+    SetChar2(win->_line[endy].text[endx], wbr);
+
+    _nc_synchook(win);
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_chgat.c b/ncurses/base/lib_chgat.c
new file mode 100644
index 0000000..89eefa7
--- /dev/null
+++ b/ncurses/base/lib_chgat.c
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Sven Verdoolaege                        2001                    *
+ *     and: Thomas E. Dickey                        2005                    *
+ ****************************************************************************/
+
+/*
+**	lib_chgat.c
+**
+**	The routine wchgat().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_chgat.c,v 1.7 2006/07/15 22:07:11 tom Exp $")
+
+NCURSES_EXPORT(int)
+wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED)
+{
+    int i;
+
+    T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color));
+
+    if (win) {
+	struct ldat *line = &(win->_line[win->_cury]);
+
+	toggle_attr_on(attr, COLOR_PAIR(color));
+
+	for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) {
+	    SetAttr(line->text[i], attr);
+	    SetPair(line->text[i], color);
+	    CHANGED_CELL(line, i);
+	}
+
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_clear.c b/ncurses/base/lib_clear.c
new file mode 100644
index 0000000..e0b4edf
--- /dev/null
+++ b/ncurses/base/lib_clear.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_clear.c
+**
+**	The routine wclear().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clear.c,v 1.7 2000/12/10 02:43:26 tom Exp $")
+
+NCURSES_EXPORT(int)
+wclear(WINDOW *win)
+{
+    int code = ERR;
+
+    T((T_CALLED("wclear(%p)"), win));
+
+    if ((code = werase(win)) != ERR)
+	win->_clear = TRUE;
+
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_clearok.c b/ncurses/base/lib_clearok.c
new file mode 100644
index 0000000..9b56bd1
--- /dev/null
+++ b/ncurses/base/lib_clearok.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_clearok.c
+**
+**	The routine clearok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clearok.c,v 1.4 2000/12/10 02:43:26 tom Exp $")
+
+NCURSES_EXPORT(int)
+clearok(WINDOW *win, bool flag)
+{
+    T((T_CALLED("clearok(%p,%d)"), win, flag));
+
+    if (win) {
+	win->_clear = flag;
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_clrbot.c b/ncurses/base/lib_clrbot.c
new file mode 100644
index 0000000..df196e8
--- /dev/null
+++ b/ncurses/base/lib_clrbot.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_clrbot.c
+**
+**	The routine wclrtobot().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clrbot.c,v 1.20 2006/10/14 20:43:31 tom Exp $")
+
+NCURSES_EXPORT(int)
+wclrtobot(WINDOW *win)
+{
+    int code = ERR;
+
+    T((T_CALLED("wclrtobot(%p)"), win));
+
+    if (win) {
+	NCURSES_SIZE_T y;
+	NCURSES_SIZE_T startx = win->_curx;
+	NCURSES_CH_T blank = win->_nc_bkgd;
+
+	T(("clearing from y = %ld to y = %ld with maxx =  %ld",
+	   (long) win->_cury, (long) win->_maxy, (long) win->_maxx));
+
+	for (y = win->_cury; y <= win->_maxy; y++) {
+	    struct ldat *line = &(win->_line[y]);
+	    NCURSES_CH_T *ptr = &(line->text[startx]);
+	    NCURSES_CH_T *end = &(line->text[win->_maxx]);
+
+	    CHANGED_TO_EOL(line, startx, win->_maxx);
+
+	    while (ptr <= end)
+		*ptr++ = blank;
+
+	    startx = 0;
+	}
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_clreol.c b/ncurses/base/lib_clreol.c
new file mode 100644
index 0000000..c46ebd9
--- /dev/null
+++ b/ncurses/base/lib_clreol.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc.         *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_clreol.c
+**
+**	The routine wclrtoeol().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_clreol.c,v 1.21 2001/12/19 01:06:04 tom Exp $")
+
+NCURSES_EXPORT(int)
+wclrtoeol(WINDOW *win)
+{
+    int code = ERR;
+
+    T((T_CALLED("wclrtoeol(%p)"), win));
+
+    if (win) {
+	NCURSES_CH_T blank;
+	NCURSES_CH_T *ptr, *end;
+	struct ldat *line;
+	NCURSES_SIZE_T y = win->_cury;
+	NCURSES_SIZE_T x = win->_curx;
+
+	/*
+	 * If we have just wrapped the cursor, the clear applies to the
+	 * new line, unless we are at the lower right corner.
+	 */
+	if ((win->_flags & _WRAPPED) != 0
+	    && y < win->_maxy) {
+	    win->_flags &= ~_WRAPPED;
+	}
+
+	/*
+	 * There's no point in clearing if we're not on a legal
+	 * position, either.
+	 */
+	if ((win->_flags & _WRAPPED) != 0
+	    || y > win->_maxy
+	    || x > win->_maxx)
+	    returnCode(ERR);
+
+	blank = win->_nc_bkgd;
+	line = &win->_line[y];
+	CHANGED_TO_EOL(line, x, win->_maxx);
+
+	ptr = &(line->text[x]);
+	end = &(line->text[win->_maxx]);
+
+	while (ptr <= end)
+	    *ptr++ = blank;
+
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_color.c b/ncurses/base/lib_color.c
new file mode 100644
index 0000000..9cae495
--- /dev/null
+++ b/ncurses/base/lib_color.c
@@ -0,0 +1,593 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/* lib_color.c
+ *
+ * Handles color emulation of SYS V curses
+ */
+
+#include <curses.priv.h>
+
+#include <term.h>
+#include <tic.h>
+
+MODULE_ID("$Id: lib_color.c,v 1.85 2007/04/07 17:07:28 tom Exp $")
+
+/*
+ * These should be screen structure members.  They need to be globals for
+ * historical reasons.  So we assign them in start_color() and also in
+ * set_term()'s screen-switching logic.
+ */
+#if USE_REENTRANT
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLOR_PAIRS) (void)
+{
+    return SP ? SP->_pair_count : -1;
+}
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLORS) (void)
+{
+    return SP ? SP->_color_count : -1;
+}
+#else
+NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
+NCURSES_EXPORT_VAR(int) COLORS = 0;
+#endif
+
+#define DATA(r,g,b) {r,g,b, 0,0,0, 0}
+
+#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
+
+#define MAX_PALETTE	8
+
+#define OkColorHi(n)	(((n) < COLORS) && ((n) < max_colors))
+#define InPalette(n)	((n) >= 0 && (n) < MAX_PALETTE)
+
+/*
+ * Given a RGB range of 0..1000, we'll normally set the individual values
+ * to about 2/3 of the maximum, leaving full-range for bold/bright colors.
+ */
+#define RGB_ON  680
+#define RGB_OFF 0
+/* *INDENT-OFF* */
+static const color_t cga_palette[] =
+{
+    /*  R               G               B */
+    DATA(RGB_OFF,	RGB_OFF,	RGB_OFF),	/* COLOR_BLACK */
+    DATA(RGB_ON,	RGB_OFF,	RGB_OFF),	/* COLOR_RED */
+    DATA(RGB_OFF,	RGB_ON,		RGB_OFF),	/* COLOR_GREEN */
+    DATA(RGB_ON,	RGB_ON,		RGB_OFF),	/* COLOR_YELLOW */
+    DATA(RGB_OFF,	RGB_OFF,	RGB_ON),	/* COLOR_BLUE */
+    DATA(RGB_ON,	RGB_OFF,	RGB_ON),	/* COLOR_MAGENTA */
+    DATA(RGB_OFF,	RGB_ON,		RGB_ON),	/* COLOR_CYAN */
+    DATA(RGB_ON,	RGB_ON,		RGB_ON),	/* COLOR_WHITE */
+};
+
+static const color_t hls_palette[] =
+{
+    /*  	H       L       S */
+    DATA(	0,	0,	0),		/* COLOR_BLACK */
+    DATA(	120,	50,	100),		/* COLOR_RED */
+    DATA(	240,	50,	100),		/* COLOR_GREEN */
+    DATA(	180,	50,	100),		/* COLOR_YELLOW */
+    DATA(	330,	50,	100),		/* COLOR_BLUE */
+    DATA(	60,	50,	100),		/* COLOR_MAGENTA */
+    DATA(	300,	50,	100),		/* COLOR_CYAN */
+    DATA(	0,	50,	100),		/* COLOR_WHITE */
+};
+/* *INDENT-ON* */
+
+#if NCURSES_EXT_FUNCS
+/*
+ * These are called from _nc_do_color(), which in turn is called from
+ * vidattr - so we have to assume that SP may be null.
+ */
+static int
+default_fg(void)
+{
+    return (SP != 0) ? SP->_default_fg : COLOR_WHITE;
+}
+
+static int
+default_bg(void)
+{
+    return SP != 0 ? SP->_default_bg : COLOR_BLACK;
+}
+#else
+#define default_fg() COLOR_WHITE
+#define default_bg() COLOR_BLACK
+#endif
+
+/*
+ * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
+ * to maintain compatibility with a pre-ANSI scheme.  The same scheme is
+ * also used in the FreeBSD syscons.
+ */
+static int
+toggled_colors(int c)
+{
+    if (c < 16) {
+	static const int table[] =
+	{0, 4, 2, 6, 1, 5, 3, 7,
+	 8, 12, 10, 14, 9, 13, 11, 15};
+	c = table[c];
+    }
+    return c;
+}
+
+static void
+set_background_color(int bg, int (*outc) (int))
+{
+    if (set_a_background) {
+	TPUTS_TRACE("set_a_background");
+	tputs(TPARM_1(set_a_background, bg), 1, outc);
+    } else {
+	TPUTS_TRACE("set_background");
+	tputs(TPARM_1(set_background, toggled_colors(bg)), 1, outc);
+    }
+}
+
+static void
+set_foreground_color(int fg, int (*outc) (int))
+{
+    if (set_a_foreground) {
+	TPUTS_TRACE("set_a_foreground");
+	tputs(TPARM_1(set_a_foreground, fg), 1, outc);
+    } else {
+	TPUTS_TRACE("set_foreground");
+	tputs(TPARM_1(set_foreground, toggled_colors(fg)), 1, outc);
+    }
+}
+
+static void
+init_color_table(void)
+{
+    const color_t *tp;
+    int n;
+
+    tp = (hue_lightness_saturation) ? hls_palette : cga_palette;
+    for (n = 0; n < COLORS; n++) {
+	if (InPalette(n)) {
+	    SP->_color_table[n] = tp[n];
+	} else {
+	    SP->_color_table[n] = tp[n % MAX_PALETTE];
+	    if (hue_lightness_saturation) {
+		SP->_color_table[n].green = 100;
+	    } else {
+		if (SP->_color_table[n].red)
+		    SP->_color_table[n].red = 1000;
+		if (SP->_color_table[n].green)
+		    SP->_color_table[n].green = 1000;
+		if (SP->_color_table[n].blue)
+		    SP->_color_table[n].blue = 1000;
+	    }
+	}
+    }
+}
+
+/*
+ * Reset the color pair, e.g., to whatever color pair 0 is.
+ */
+static bool
+reset_color_pair(void)
+{
+    bool result = FALSE;
+
+    if (orig_pair != 0) {
+	TPUTS_TRACE("orig_pair");
+	putp(orig_pair);
+	result = TRUE;
+    }
+    return result;
+}
+
+/*
+ * Reset color pairs and definitions.  Actually we do both more to accommodate
+ * badly-written terminal descriptions than for the relatively rare case where
+ * someone has changed the color definitions.
+ */
+bool
+_nc_reset_colors(void)
+{
+    int result = FALSE;
+
+    T((T_CALLED("_nc_reset_colors()")));
+    if (SP->_color_defs > 0)
+	SP->_color_defs = -(SP->_color_defs);
+
+    if (reset_color_pair())
+	result = TRUE;
+    if (orig_colors != 0) {
+	TPUTS_TRACE("orig_colors");
+	putp(orig_colors);
+	result = TRUE;
+    }
+    returnBool(result);
+}
+
+NCURSES_EXPORT(int)
+start_color(void)
+{
+    int result = ERR;
+
+    T((T_CALLED("start_color()")));
+
+    if (SP == 0) {
+	result = ERR;
+    } else if (SP->_coloron) {
+	result = OK;
+    } else {
+
+	if (reset_color_pair() != TRUE) {
+	    set_foreground_color(default_fg(), _nc_outch);
+	    set_background_color(default_bg(), _nc_outch);
+	}
+
+	if (max_pairs > 0 && max_colors > 0) {
+	    SP->_pair_count = max_pairs;
+	    SP->_color_count = max_colors;
+#if !USE_REENTRANT
+	    COLOR_PAIRS = max_pairs;
+	    COLORS = max_colors;
+#endif
+
+	    if ((SP->_color_pairs = TYPE_CALLOC(colorpair_t,
+						max_pairs)) != 0) {
+		if ((SP->_color_table = TYPE_CALLOC(color_t,
+						    max_colors)) != 0) {
+		    SP->_color_pairs[0] = PAIR_OF(default_fg(), default_bg());
+		    init_color_table();
+
+		    T(("started color: COLORS = %d, COLOR_PAIRS = %d",
+		       COLORS, COLOR_PAIRS));
+
+		    SP->_coloron = 1;
+		    result = OK;
+		} else if (SP->_color_pairs != 0) {
+		    FreeAndNull(SP->_color_pairs);
+		}
+	    }
+	} else {
+	    result = OK;
+	}
+    }
+    returnCode(result);
+}
+
+/* This function was originally written by Daniel Weaver <danw@znyx.com> */
+static void
+rgb2hls(short r, short g, short b, short *h, short *l, short *s)
+/* convert RGB to HLS system */
+{
+    short min, max, t;
+
+    if ((min = g < r ? g : r) > b)
+	min = b;
+    if ((max = g > r ? g : r) < b)
+	max = b;
+
+    /* calculate lightness */
+    *l = (min + max) / 20;
+
+    if (min == max) {		/* black, white and all shades of gray */
+	*h = 0;
+	*s = 0;
+	return;
+    }
+
+    /* calculate saturation */
+    if (*l < 50)
+	*s = ((max - min) * 100) / (max + min);
+    else
+	*s = ((max - min) * 100) / (2000 - max - min);
+
+    /* calculate hue */
+    if (r == max)
+	t = 120 + ((g - b) * 60) / (max - min);
+    else if (g == max)
+	t = 240 + ((b - r) * 60) / (max - min);
+    else
+	t = 360 + ((r - g) * 60) / (max - min);
+
+    *h = t % 360;
+}
+
+/*
+ * Extension (1997/1/18) - Allow negative f/b values to set default color
+ * values.
+ */
+NCURSES_EXPORT(int)
+init_pair(short pair, short f, short b)
+{
+    colorpair_t result;
+
+    T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b));
+
+    if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron)
+	returnCode(ERR);
+#if NCURSES_EXT_FUNCS
+    if (SP->_default_color) {
+	if (f < 0)
+	    f = COLOR_DEFAULT;
+	if (b < 0)
+	    b = COLOR_DEFAULT;
+	if (!OkColorHi(f) && !isDefaultColor(f))
+	    returnCode(ERR);
+	if (!OkColorHi(b) && !isDefaultColor(b))
+	    returnCode(ERR);
+    } else
+#endif
+    {
+	if ((f < 0) || !OkColorHi(f)
+	    || (b < 0) || !OkColorHi(b)
+	    || (pair < 1))
+	    returnCode(ERR);
+    }
+
+    /*
+     * When a pair's content is changed, replace its colors (if pair was
+     * initialized before a screen update is performed replacing original
+     * pair colors with the new ones).
+     */
+    result = PAIR_OF(f, b);
+    if (SP->_color_pairs[pair] != 0
+	&& SP->_color_pairs[pair] != result) {
+	int y, x;
+
+	for (y = 0; y <= curscr->_maxy; y++) {
+	    struct ldat *ptr = &(curscr->_line[y]);
+	    bool changed = FALSE;
+	    for (x = 0; x <= curscr->_maxx; x++) {
+		if (GetPair(ptr->text[x]) == pair) {
+		    /* Set the old cell to zero to ensure it will be
+		       updated on the next doupdate() */
+		    SetChar(ptr->text[x], 0, 0);
+		    CHANGED_CELL(ptr, x);
+		    changed = TRUE;
+		}
+	    }
+	    if (changed)
+		_nc_make_oldhash(y);
+	}
+    }
+    SP->_color_pairs[pair] = result;
+    if (GET_SCREEN_PAIR(SP) == pair)
+	SET_SCREEN_PAIR(SP, (chtype) (~0));	/* force attribute update */
+
+    if (initialize_pair && InPalette(f) && InPalette(b)) {
+	const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette;
+
+	TR(TRACE_ATTRS,
+	   ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
+	    pair,
+	    tp[f].red, tp[f].green, tp[f].blue,
+	    tp[b].red, tp[b].green, tp[b].blue));
+
+	TPUTS_TRACE("initialize_pair");
+	putp(TPARM_7(initialize_pair,
+		     pair,
+		     tp[f].red, tp[f].green, tp[f].blue,
+		     tp[b].red, tp[b].green, tp[b].blue));
+    }
+
+    returnCode(OK);
+}
+
+#define okRGB(n) ((n) >= 0 && (n) <= 1000)
+
+NCURSES_EXPORT(int)
+init_color(short color, short r, short g, short b)
+{
+    int result = ERR;
+
+    T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b));
+
+    if (initialize_color != NULL
+	&& SP != 0
+	&& SP->_coloron
+	&& (color >= 0 && OkColorHi(color))
+	&& (okRGB(r) && okRGB(g) && okRGB(b))) {
+
+	SP->_color_table[color].init = 1;
+	SP->_color_table[color].r = r;
+	SP->_color_table[color].g = g;
+	SP->_color_table[color].b = b;
+
+	if (hue_lightness_saturation) {
+	    rgb2hls(r, g, b,
+		    &SP->_color_table[color].red,
+		    &SP->_color_table[color].green,
+		    &SP->_color_table[color].blue);
+	} else {
+	    SP->_color_table[color].red = r;
+	    SP->_color_table[color].green = g;
+	    SP->_color_table[color].blue = b;
+	}
+
+	TPUTS_TRACE("initialize_color");
+	putp(TPARM_4(initialize_color, color, r, g, b));
+	SP->_color_defs = max(color + 1, SP->_color_defs);
+	result = OK;
+    }
+    returnCode(result);
+}
+
+NCURSES_EXPORT(bool)
+can_change_color(void)
+{
+    T((T_CALLED("can_change_color()")));
+    returnCode((can_change != 0) ? TRUE : FALSE);
+}
+
+NCURSES_EXPORT(bool)
+has_colors(void)
+{
+    T((T_CALLED("has_colors()")));
+    returnCode((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
+		&& (((set_foreground != NULL)
+		     && (set_background != NULL))
+		    || ((set_a_foreground != NULL)
+			&& (set_a_background != NULL))
+		    || set_color_pair)) ? TRUE : FALSE);
+}
+
+NCURSES_EXPORT(int)
+color_content(short color, short *r, short *g, short *b)
+{
+    int result;
+
+    T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b));
+    if (color < 0 || !OkColorHi(color) || SP == 0 || !SP->_coloron) {
+	result = ERR;
+    } else {
+	NCURSES_COLOR_T c_r = SP->_color_table[color].red;
+	NCURSES_COLOR_T c_g = SP->_color_table[color].green;
+	NCURSES_COLOR_T c_b = SP->_color_table[color].blue;
+
+	if (r)
+	    *r = c_r;
+	if (g)
+	    *g = c_g;
+	if (b)
+	    *b = c_b;
+
+	TR(TRACE_ATTRS, ("...color_content(%d,%d,%d,%d)",
+			 color, c_r, c_g, c_b));
+	result = OK;
+    }
+    returnCode(result);
+}
+
+NCURSES_EXPORT(int)
+pair_content(short pair, short *f, short *b)
+{
+    int result;
+
+    T((T_CALLED("pair_content(%d,%p,%p)"), pair, f, b));
+
+    if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron) {
+	result = ERR;
+    } else {
+	NCURSES_COLOR_T fg = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK);
+	NCURSES_COLOR_T bg = (SP->_color_pairs[pair] & C_MASK);
+
+#if NCURSES_EXT_FUNCS
+	if (fg == COLOR_DEFAULT)
+	    fg = -1;
+	if (bg == COLOR_DEFAULT)
+	    bg = -1;
+#endif
+
+	if (f)
+	    *f = fg;
+	if (b)
+	    *b = bg;
+
+	TR(TRACE_ATTRS, ("...pair_content(%d,%d,%d)", pair, fg, bg));
+	result = OK;
+    }
+    returnCode(result);
+}
+
+NCURSES_EXPORT(void)
+_nc_do_color(short old_pair, short pair, bool reverse, int (*outc) (int))
+{
+    NCURSES_COLOR_T fg = COLOR_DEFAULT;
+    NCURSES_COLOR_T bg = COLOR_DEFAULT;
+    NCURSES_COLOR_T old_fg, old_bg;
+
+    if (pair < 0 || pair >= COLOR_PAIRS) {
+	return;
+    } else if (pair != 0) {
+	if (set_color_pair) {
+	    TPUTS_TRACE("set_color_pair");
+	    tputs(TPARM_1(set_color_pair, pair), 1, outc);
+	    return;
+	} else if (SP != 0) {
+	    pair_content((short) pair, &fg, &bg);
+	}
+    }
+
+    if (old_pair >= 0
+	&& SP != 0
+	&& pair_content(old_pair, &old_fg, &old_bg) != ERR) {
+	if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
+	    || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
+#if NCURSES_EXT_FUNCS
+	    /*
+	     * A minor optimization - but extension.  If "AX" is specified in
+	     * the terminal description, treat it as screen's indicator of ECMA
+	     * SGR 39 and SGR 49, and assume the two sequences are independent.
+	     */
+	    if (SP->_has_sgr_39_49
+		&& isDefaultColor(old_bg)
+		&& !isDefaultColor(old_fg)) {
+		tputs("\033[39m", 1, outc);
+	    } else if (SP->_has_sgr_39_49
+		       && isDefaultColor(old_fg)
+		       && !isDefaultColor(old_bg)) {
+		tputs("\033[49m", 1, outc);
+	    } else
+#endif
+		reset_color_pair();
+	}
+    } else {
+	reset_color_pair();
+	if (old_pair < 0)
+	    return;
+    }
+
+#if NCURSES_EXT_FUNCS
+    if (isDefaultColor(fg))
+	fg = default_fg();
+    if (isDefaultColor(bg))
+	bg = default_bg();
+#endif
+
+    if (reverse) {
+	NCURSES_COLOR_T xx = fg;
+	fg = bg;
+	bg = xx;
+    }
+
+    TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
+		     fg, bg));
+
+    if (!isDefaultColor(fg)) {
+	set_foreground_color(fg, outc);
+    }
+    if (!isDefaultColor(bg)) {
+	set_background_color(bg, outc);
+    }
+}
diff --git a/ncurses/base/lib_colorset.c b/ncurses/base/lib_colorset.c
new file mode 100644
index 0000000..a973c53
--- /dev/null
+++ b/ncurses/base/lib_colorset.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Juergen Pfeifer,  1998                                          *
+ *     and: Thomas E. Dickey, 2005                                          *
+ ****************************************************************************/
+
+/*
+**	lib_colorset.c
+**
+**	The routine wcolor_set().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_colorset.c,v 1.11 2005/01/29 21:40:51 tom Exp $")
+
+NCURSES_EXPORT(int)
+wcolor_set(WINDOW *win, short color_pair_number, void *opts)
+{
+    T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number));
+    if (win
+	&& !opts
+	&& (color_pair_number >= 0)
+	&& (color_pair_number < COLOR_PAIRS)) {
+	TR(TRACE_ATTRS, ("... current %ld", (long) GET_WINDOW_PAIR(win)));
+	SET_WINDOW_PAIR(win, color_pair_number);
+	if_EXT_COLORS(win->_color = color_pair_number);
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_delch.c b/ncurses/base/lib_delch.c
new file mode 100644
index 0000000..0c30f2d
--- /dev/null
+++ b/ncurses/base/lib_delch.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_delch.c
+**
+**	The routine wdelch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_delch.c,v 1.12 2001/12/19 01:06:09 tom Exp $")
+
+NCURSES_EXPORT(int)
+wdelch(WINDOW *win)
+{
+    int code = ERR;
+
+    T((T_CALLED("wdelch(%p)"), win));
+
+    if (win) {
+	NCURSES_CH_T blank = win->_nc_bkgd;
+	struct ldat *line = &(win->_line[win->_cury]);
+	NCURSES_CH_T *end = &(line->text[win->_maxx]);
+	NCURSES_CH_T *temp2 = &(line->text[win->_curx + 1]);
+	NCURSES_CH_T *temp1 = temp2 - 1;
+
+	CHANGED_TO_EOL(line, win->_curx, win->_maxx);
+	while (temp1 < end)
+	    *temp1++ = *temp2++;
+
+	*temp1 = blank;
+
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_delwin.c b/ncurses/base/lib_delwin.c
new file mode 100644
index 0000000..b92c403
--- /dev/null
+++ b/ncurses/base/lib_delwin.c
@@ -0,0 +1,86 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_delwin.c
+**
+**	The routine delwin().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_delwin.c,v 1.17 2008/06/07 14:10:56 tom Exp $")
+
+static bool
+cannot_delete(WINDOW *win)
+{
+    WINDOWLIST *p;
+    bool result = TRUE;
+
+    for (each_window(p)) {
+	if (&(p->win) == win) {
+	    result = FALSE;
+	} else if ((p->win._flags & _SUBWIN) != 0
+		   && p->win._parent == win) {
+	    result = TRUE;
+	    break;
+	}
+    }
+    return result;
+}
+
+NCURSES_EXPORT(int)
+delwin(WINDOW *win)
+{
+    int result = ERR;
+
+    T((T_CALLED("delwin(%p)"), win));
+
+    if (_nc_try_global(curses) == 0) {
+	if (win == 0
+	    || cannot_delete(win)) {
+	    result = ERR;
+	} else {
+
+	    if (win->_flags & _SUBWIN)
+		touchwin(win->_parent);
+	    else if (curscr != 0)
+		touchwin(curscr);
+
+	    result = _nc_freewin(win);
+	}
+	_nc_unlock_global(curses);
+    }
+    returnCode(result);
+}
diff --git a/ncurses/base/lib_dft_fgbg.c b/ncurses/base/lib_dft_fgbg.c
new file mode 100644
index 0000000..8953c14
--- /dev/null
+++ b/ncurses/base/lib_dft_fgbg.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_dft_fgbg.c,v 1.18 2005/11/26 20:03:38 tom Exp $")
+
+/*
+ * Modify the behavior of color-pair 0 so that the library doesn't assume that
+ * it is white on black.  This is an extension to XSI curses.
+ */
+NCURSES_EXPORT(int)
+use_default_colors(void)
+{
+    T((T_CALLED("use_default_colors()")));
+    returnCode(assume_default_colors(-1, -1));
+}
+
+/*
+ * Modify the behavior of color-pair 0 so that the library assumes that it
+ * is something specific, possibly not white on black.
+ */
+NCURSES_EXPORT(int)
+assume_default_colors(int fg, int bg)
+{
+    T((T_CALLED("assume_default_colors(%d,%d)"), fg, bg));
+
+    if (!orig_pair && !orig_colors)
+	returnCode(ERR);
+
+    if (initialize_pair)	/* don't know how to handle this */
+	returnCode(ERR);
+
+    SP->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
+    SP->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
+    SP->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : (fg & C_MASK);
+    SP->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : (bg & C_MASK);
+    if (SP->_color_pairs != 0) {
+	bool save = SP->_default_color;
+	SP->_default_color = TRUE;
+	init_pair(0, (short) fg, (short) bg);
+	SP->_default_color = save;
+    }
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_echo.c b/ncurses/base/lib_echo.c
new file mode 100644
index 0000000..df44713
--- /dev/null
+++ b/ncurses/base/lib_echo.c
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	echo.c
+ *
+ *	Routines:
+ *		echo()
+ *		noecho()
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_echo.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+echo(void)
+{
+    T((T_CALLED("echo()")));
+    SP->_echo = TRUE;
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+noecho(void)
+{
+    T((T_CALLED("noecho()")));
+    SP->_echo = FALSE;
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_endwin.c b/ncurses/base/lib_endwin.c
new file mode 100644
index 0000000..6666287
--- /dev/null
+++ b/ncurses/base/lib_endwin.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_endwin.c
+**
+**	The routine endwin().
+**
+*/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_endwin.c,v 1.19 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+endwin(void)
+{
+    T((T_CALLED("endwin()")));
+
+    if (SP) {
+	SP->_endwin = TRUE;
+	SP->_mouse_wrap(SP);
+	_nc_screen_wrap();
+	_nc_mvcur_wrap();	/* wrap up cursor addressing */
+	returnCode(reset_shell_mode());
+    }
+
+    returnCode(ERR);
+}
diff --git a/ncurses/base/lib_erase.c b/ncurses/base/lib_erase.c
new file mode 100644
index 0000000..2566e8b
--- /dev/null
+++ b/ncurses/base/lib_erase.c
@@ -0,0 +1,92 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_erase.c
+**
+**	The routine werase().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_erase.c,v 1.16 2005/10/30 00:36:36 tom Exp $")
+
+NCURSES_EXPORT(int)
+werase(WINDOW *win)
+{
+    int code = ERR;
+    int y;
+    NCURSES_CH_T blank;
+    NCURSES_CH_T *sp, *end, *start;
+
+    T((T_CALLED("werase(%p)"), win));
+
+    if (win) {
+	blank = win->_nc_bkgd;
+	for (y = 0; y <= win->_maxy; y++) {
+	    start = win->_line[y].text;
+	    end = &start[win->_maxx];
+
+	    /*
+	     * If this is a derived window, we have to handle the case where
+	     * a multicolumn character extends into the window that we are
+	     * erasing.
+	     */
+	    if_WIDEC({
+		if (isWidecExt(start[0])) {
+		    int x = (win->_parent != 0) ? (win->_begx) : 0;
+		    while (x-- > 0) {
+			if (isWidecBase(start[-1])) {
+			    --start;
+			    break;
+			}
+			--start;
+		    }
+		}
+	    });
+
+	    for (sp = start; sp <= end; sp++)
+		*sp = blank;
+
+	    win->_line[y].firstchar = 0;
+	    win->_line[y].lastchar = win->_maxx;
+	}
+	win->_curx = win->_cury = 0;
+	win->_flags &= ~_WRAPPED;
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_flash.c b/ncurses/base/lib_flash.c
new file mode 100644
index 0000000..a6b022a
--- /dev/null
+++ b/ncurses/base/lib_flash.c
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	flash.c
+ *
+ *	The routine flash().
+ *
+ */
+
+#include <curses.priv.h>
+#include <term.h>		/* beep, flash */
+
+MODULE_ID("$Id: lib_flash.c,v 1.6 2000/12/10 02:43:27 tom Exp $")
+
+/*
+ *	flash()
+ *
+ *	Flash the current terminal's screen if possible.   If not,
+ *	sound the audible bell if one exists.
+ *
+ */
+
+NCURSES_EXPORT(int)
+flash(void)
+{
+    int res = ERR;
+
+    T((T_CALLED("flash()")));
+
+    /* FIXME: should make sure that we are not in altchar mode */
+    if (flash_screen) {
+	TPUTS_TRACE("flash_screen");
+	res = putp(flash_screen);
+	_nc_flush();
+    } else if (bell) {
+	TPUTS_TRACE("bell");
+	res = putp(bell);
+	_nc_flush();
+    }
+
+    returnCode(res);
+}
diff --git a/ncurses/base/lib_freeall.c b/ncurses/base/lib_freeall.c
new file mode 100644
index 0000000..5640265
--- /dev/null
+++ b/ncurses/base/lib_freeall.c
@@ -0,0 +1,157 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                    1996-on                     *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term_entry.h>
+#include <tic.h>
+
+#if HAVE_NC_FREEALL
+
+#if HAVE_LIBDBMALLOC
+extern int malloc_errfd;	/* FIXME */
+#endif
+
+MODULE_ID("$Id: lib_freeall.c,v 1.54 2008/09/27 13:09:57 tom Exp $")
+
+/*
+ * Free all ncurses data.  This is used for testing only (there's no practical
+ * use for it as an extension).
+ */
+NCURSES_EXPORT(void)
+_nc_freeall(void)
+{
+    WINDOWLIST *p, *q;
+    static va_list empty_va;
+
+    T((T_CALLED("_nc_freeall()")));
+#if NO_LEAKS
+    if (SP != 0) {
+	if (SP->_oldnum_list != 0) {
+	    FreeAndNull(SP->_oldnum_list);
+	}
+	if (SP->_panelHook.destroy != 0) {
+	    SP->_panelHook.destroy(SP->_panelHook.stdscr_pseudo_panel);
+	}
+    }
+#endif
+    if (SP != 0) {
+	_nc_lock_global(curses);
+
+	while (_nc_windows != 0) {
+	    bool deleted = FALSE;
+
+	    /* Delete only windows that're not a parent */
+	    for (each_window(p)) {
+		bool found = FALSE;
+
+		for (each_window(q)) {
+		    if ((p != q)
+			&& (q->win._flags & _SUBWIN)
+			&& (&(p->win) == q->win._parent)) {
+			found = TRUE;
+			break;
+		    }
+		}
+
+		if (!found) {
+		    if (delwin(&(p->win)) != ERR)
+			deleted = TRUE;
+		    break;
+		}
+	    }
+
+	    /*
+	     * Don't continue to loop if the list is trashed.
+	     */
+	    if (!deleted)
+		break;
+	}
+	delscreen(SP);
+	_nc_unlock_global(curses);
+    }
+    if (cur_term != 0)
+	del_curterm(cur_term);
+
+    (void) _nc_printf_string(0, empty_va);
+#ifdef TRACE
+    (void) _nc_trace_buf(-1, 0);
+#endif
+#if USE_WIDEC_SUPPORT
+    FreeIfNeeded(_nc_wacs);
+#endif
+    _nc_leaks_tinfo();
+
+#if HAVE_LIBDBMALLOC
+    malloc_dump(malloc_errfd);
+#elif HAVE_LIBDMALLOC
+#elif HAVE_LIBMPATROL
+    __mp_summary();
+#elif HAVE_PURIFY
+    purify_all_inuse();
+#endif
+    returnVoid;
+}
+
+NCURSES_EXPORT(void)
+_nc_free_and_exit(int code)
+{
+    char *last_setbuf = (SP != 0) ? SP->_setbuf : 0;
+
+    _nc_freeall();
+#ifdef TRACE
+    trace(0);			/* close trace file, freeing its setbuf */
+    {
+	static va_list fake;
+	free(_nc_varargs("?", fake));
+    }
+#endif
+    fclose(stdout);
+    FreeIfNeeded(last_setbuf);
+    exit(code);
+}
+
+#else
+NCURSES_EXPORT(void)
+_nc_freeall(void)
+{
+}
+
+NCURSES_EXPORT(void)
+_nc_free_and_exit(int code)
+{
+    if (SP)
+	delscreen(SP);
+    if (cur_term != 0)
+	del_curterm(cur_term);
+    exit(code);
+}
+#endif
diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c
new file mode 100644
index 0000000..a3812be
--- /dev/null
+++ b/ncurses/base/lib_getch.c
@@ -0,0 +1,664 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_getch.c
+**
+**	The routine getch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_getch.c,v 1.99 2008/09/20 19:46:13 tom Exp $")
+
+#include <fifo_defs.h>
+
+#if USE_REENTRANT
+#define GetEscdelay(sp) (sp)->_ESCDELAY
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(ESCDELAY) (void)
+{
+    return SP ? GetEscdelay(SP) : 1000;
+}
+#else
+#define GetEscdelay(sp) ESCDELAY
+NCURSES_EXPORT_VAR(int)
+ESCDELAY = 1000;		/* max interval betw. chars in funkeys, in millisecs */
+#endif
+
+#if NCURSES_EXT_FUNCS
+NCURSES_EXPORT(int)
+set_escdelay(int value)
+{
+    int code = OK;
+#if USE_REENTRANT
+    if (SP) {
+	SP->_ESCDELAY = value;
+    } else {
+	code = ERR;
+    }
+#else
+    ESCDELAY = value;
+#endif
+    return code;
+}
+#endif
+
+static int
+_nc_use_meta(WINDOW *win)
+{
+    SCREEN *sp = _nc_screen_of(win);
+    return (sp ? sp->_use_meta : 0);
+}
+
+#ifdef NCURSES_WGETCH_EVENTS
+#define TWAIT_MASK 7
+#else
+#define TWAIT_MASK 3
+#endif
+
+/*
+ * Check for mouse activity, returning nonzero if we find any.
+ */
+static int
+check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    int rc;
+
+#if USE_SYSMOUSE
+    if ((sp->_mouse_type == M_SYSMOUSE)
+	&& (sp->_sysmouse_head < sp->_sysmouse_tail)) {
+	return 2;
+    }
+#endif
+    rc = _nc_timed_wait(sp, TWAIT_MASK, delay, (int *) 0 EVENTLIST_2nd(evl));
+#if USE_SYSMOUSE
+    if ((sp->_mouse_type == M_SYSMOUSE)
+	&& (sp->_sysmouse_head < sp->_sysmouse_tail)
+	&& (rc == 0)
+	&& (errno == EINTR)) {
+	rc |= 2;
+    }
+#endif
+    return rc;
+}
+
+static NCURSES_INLINE int
+fifo_peek(SCREEN *sp)
+{
+    int ch = sp->_fifo[peek];
+    TR(TRACE_IEVENT, ("peeking at %d", peek));
+
+    p_inc();
+    return ch;
+}
+
+static NCURSES_INLINE int
+fifo_pull(SCREEN *sp)
+{
+    int ch;
+    ch = sp->_fifo[head];
+    TR(TRACE_IEVENT, ("pulling %s from %d", _nc_tracechar(sp, ch), head));
+
+    if (peek == head) {
+	h_inc();
+	peek = head;
+    } else
+	h_inc();
+
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_IEVENT)) {
+	_nc_fifo_dump(sp);
+	_nc_unlock_global(tracef);
+    }
+#endif
+    return ch;
+}
+
+static NCURSES_INLINE int
+fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    int n;
+    int ch = 0;
+    int mask = 0;
+
+    (void) mask;
+    if (tail == -1)
+	return ERR;
+
+#ifdef HIDE_EINTR
+  again:
+    errno = 0;
+#endif
+
+#ifdef NCURSES_WGETCH_EVENTS
+    if (evl
+#if USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
+	|| (sp->_mouse_fd >= 0)
+#endif
+	) {
+	mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl));
+    } else
+	mask = 0;
+
+    if (mask & 4) {
+	T(("fifo_push: ungetch KEY_EVENT"));
+	_nc_ungetch(sp, KEY_EVENT);
+	return KEY_EVENT;
+    }
+#elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
+    if (sp->_mouse_fd >= 0) {
+	mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl));
+    }
+#endif
+
+#if USE_GPM_SUPPORT || USE_EMX_MOUSE
+    if ((sp->_mouse_fd >= 0) && (mask & 2)) {
+	sp->_mouse_event(sp);
+	ch = KEY_MOUSE;
+	n = 1;
+    } else
+#endif
+#if USE_SYSMOUSE
+	if ((sp->_mouse_type == M_SYSMOUSE)
+	    && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
+	sp->_mouse_event(sp);
+	ch = KEY_MOUSE;
+	n = 1;
+    } else if ((sp->_mouse_type == M_SYSMOUSE)
+	       && (mask <= 0) && errno == EINTR) {
+	sp->_mouse_event(sp);
+	ch = KEY_MOUSE;
+	n = 1;
+    } else
+#endif
+    {				/* Can block... */
+	unsigned char c2 = 0;
+	n = read(sp->_ifd, &c2, 1);
+	ch = c2;
+    }
+
+#ifdef HIDE_EINTR
+    /*
+     * Under System V curses with non-restarting signals, getch() returns
+     * with value ERR when a handled signal keeps it from completing.
+     * If signals restart system calls, OTOH, the signal is invisible
+     * except to its handler.
+     *
+     * We don't want this difference to show.  This piece of code
+     * tries to make it look like we always have restarting signals.
+     */
+    if (n <= 0 && errno == EINTR)
+	goto again;
+#endif
+
+    if ((n == -1) || (n == 0)) {
+	TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", sp->_ifd, n, errno));
+	ch = ERR;
+    }
+    TR(TRACE_IEVENT, ("read %d characters", n));
+
+    sp->_fifo[tail] = ch;
+    sp->_fifohold = 0;
+    if (head == -1)
+	head = peek = tail;
+    t_inc();
+    TR(TRACE_IEVENT, ("pushed %s at %d", _nc_tracechar(sp, ch), tail));
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_IEVENT)) {
+	_nc_fifo_dump(sp);
+	_nc_unlock_global(tracef);
+    }
+#endif
+    return ch;
+}
+
+static NCURSES_INLINE void
+fifo_clear(SCREEN *sp)
+{
+    memset(sp->_fifo, 0, sizeof(sp->_fifo));
+    head = -1;
+    tail = peek = 0;
+}
+
+static int kgetch(SCREEN *EVENTLIST_2nd(_nc_eventlist * evl));
+
+static void
+recur_wrefresh(WINDOW *win)
+{
+#ifdef USE_PTHREADS
+    SCREEN *sp = _nc_screen_of(win);
+    if (_nc_use_pthreads && sp != SP) {
+	SCREEN *save_SP;
+
+	/* temporarily switch to the window's screen to check/refresh */
+	_nc_lock_global(curses);
+	save_SP = SP;
+	_nc_set_screen(sp);
+	recur_wrefresh(win);
+	_nc_set_screen(save_SP);
+	_nc_unlock_global(curses);
+    } else
+#endif
+	if ((is_wintouched(win) || (win->_flags & _HASMOVED))
+	    && !(win->_flags & _ISPAD)) {
+	wrefresh(win);
+    }
+}
+
+static int
+recur_wgetnstr(WINDOW *win, char *buf)
+{
+    SCREEN *sp = _nc_screen_of(win);
+    int rc;
+
+    if (sp != 0) {
+#ifdef USE_PTHREADS
+	if (_nc_use_pthreads && sp != SP) {
+	    SCREEN *save_SP;
+
+	    /* temporarily switch to the window's screen to get cooked input */
+	    _nc_lock_global(curses);
+	    save_SP = SP;
+	    _nc_set_screen(sp);
+	    rc = recur_wgetnstr(win, buf);
+	    _nc_set_screen(save_SP);
+	    _nc_unlock_global(curses);
+	} else
+#endif
+	{
+	    sp->_called_wgetch = TRUE;
+	    rc = wgetnstr(win, buf, MAXCOLUMNS);
+	    sp->_called_wgetch = FALSE;
+	}
+    } else {
+	rc = ERR;
+    }
+    return rc;
+}
+
+NCURSES_EXPORT(int)
+_nc_wgetch(WINDOW *win,
+	   unsigned long *result,
+	   int use_meta
+	   EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    SCREEN *sp;
+    int ch;
+#ifdef NCURSES_WGETCH_EVENTS
+    long event_delay = -1;
+#endif
+
+    T((T_CALLED("_nc_wgetch(%p)"), win));
+
+    *result = 0;
+
+    sp = _nc_screen_of(win);
+    if (win == 0 || sp == 0) {
+	returnCode(ERR);
+    }
+
+    if (cooked_key_in_fifo()) {
+	recur_wrefresh(win);
+	*result = fifo_pull(sp);
+	returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
+    }
+#ifdef NCURSES_WGETCH_EVENTS
+    if (evl && (evl->count == 0))
+	evl = NULL;
+    event_delay = _nc_eventlist_timeout(evl);
+#endif
+
+    /*
+     * Handle cooked mode.  Grab a string from the screen,
+     * stuff its contents in the FIFO queue, and pop off
+     * the first character to return it.
+     */
+    if (head == -1 &&
+	!sp->_notty &&
+	!sp->_raw &&
+	!sp->_cbreak &&
+	!sp->_called_wgetch) {
+	char buf[MAXCOLUMNS], *bufp;
+	int rc;
+
+	TR(TRACE_IEVENT, ("filling queue in cooked mode"));
+
+	rc = recur_wgetnstr(win, buf);
+
+	/* ungetch in reverse order */
+#ifdef NCURSES_WGETCH_EVENTS
+	if (rc != KEY_EVENT)
+#endif
+	    _nc_ungetch(sp, '\n');
+	for (bufp = buf + strlen(buf); bufp > buf; bufp--)
+	    _nc_ungetch(sp, bufp[-1]);
+
+#ifdef NCURSES_WGETCH_EVENTS
+	/* Return it first */
+	if (rc == KEY_EVENT) {
+	    *result = rc;
+	} else
+#endif
+	    *result = fifo_pull(sp);
+	returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
+    }
+
+    if (win->_use_keypad != sp->_keypad_on)
+	_nc_keypad(sp, win->_use_keypad);
+
+    recur_wrefresh(win);
+
+    if (win->_notimeout || (win->_delay >= 0) || (sp->_cbreak > 1)) {
+	if (head == -1) {	/* fifo is empty */
+	    int delay;
+	    int rc;
+
+	    TR(TRACE_IEVENT, ("timed delay in wgetch()"));
+	    if (sp->_cbreak > 1)
+		delay = (sp->_cbreak - 1) * 100;
+	    else
+		delay = win->_delay;
+
+#ifdef NCURSES_WGETCH_EVENTS
+	    if (event_delay >= 0 && delay > event_delay)
+		delay = event_delay;
+#endif
+
+	    TR(TRACE_IEVENT, ("delay is %d milliseconds", delay));
+
+	    rc = check_mouse_activity(sp, delay EVENTLIST_2nd(evl));
+
+#ifdef NCURSES_WGETCH_EVENTS
+	    if (rc & 4) {
+		*result = KEY_EVENT;
+		returnCode(KEY_CODE_YES);
+	    }
+#endif
+	    if (!rc) {
+		returnCode(ERR);
+	    }
+	}
+	/* else go on to read data available */
+    }
+
+    if (win->_use_keypad) {
+	/*
+	 * This is tricky.  We only want to get special-key
+	 * events one at a time.  But we want to accumulate
+	 * mouse events until either (a) the mouse logic tells
+	 * us it's picked up a complete gesture, or (b)
+	 * there's a detectable time lapse after one.
+	 *
+	 * Note: if the mouse code starts failing to compose
+	 * press/release events into clicks, you should probably
+	 * increase the wait with mouseinterval().
+	 */
+	int runcount = 0;
+	int rc;
+
+	do {
+	    ch = kgetch(sp EVENTLIST_2nd(evl));
+	    if (ch == KEY_MOUSE) {
+		++runcount;
+		if (sp->_mouse_inline(sp))
+		    break;
+	    }
+	    if (sp->_maxclick < 0)
+		break;
+	} while
+	    (ch == KEY_MOUSE
+	     && (((rc = check_mouse_activity(sp, sp->_maxclick
+					     EVENTLIST_2nd(evl))) != 0
+		  && !(rc & 4))
+		 || !sp->_mouse_parse(sp, runcount)));
+#ifdef NCURSES_WGETCH_EVENTS
+	if ((rc & 4) && !ch == KEY_EVENT) {
+	    _nc_ungetch(sp, ch);
+	    ch = KEY_EVENT;
+	}
+#endif
+	if (runcount > 0 && ch != KEY_MOUSE) {
+#ifdef NCURSES_WGETCH_EVENTS
+	    /* mouse event sequence ended by an event, report event */
+	    if (ch == KEY_EVENT) {
+		_nc_ungetch(sp, KEY_MOUSE);	/* FIXME This interrupts a gesture... */
+	    } else
+#endif
+	    {
+		/* mouse event sequence ended by keystroke, store keystroke */
+		_nc_ungetch(sp, ch);
+		ch = KEY_MOUSE;
+	    }
+	}
+    } else {
+	if (head == -1)
+	    fifo_push(sp EVENTLIST_2nd(evl));
+	ch = fifo_pull(sp);
+    }
+
+    if (ch == ERR) {
+#if USE_SIZECHANGE
+	if (_nc_handle_sigwinch(sp)) {
+	    _nc_update_screensize(sp);
+	    /* resizeterm can push KEY_RESIZE */
+	    if (cooked_key_in_fifo()) {
+		*result = fifo_pull(sp);
+		returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
+	    }
+	}
+#endif
+	returnCode(ERR);
+    }
+
+    /*
+     * If echo() is in effect, display the printable version of the
+     * key on the screen.  Carriage return and backspace are treated
+     * specially by Solaris curses:
+     *
+     * If carriage return is defined as a function key in the
+     * terminfo, e.g., kent, then Solaris may return either ^J (or ^M
+     * if nonl() is set) or KEY_ENTER depending on the echo() mode. 
+     * We echo before translating carriage return based on nonl(),
+     * since the visual result simply moves the cursor to column 0.
+     *
+     * Backspace is a different matter.  Solaris curses does not
+     * translate it to KEY_BACKSPACE if kbs=^H.  This does not depend
+     * on the stty modes, but appears to be a hardcoded special case.
+     * This is a difference from ncurses, which uses the terminfo entry.
+     * However, we provide the same visual result as Solaris, moving the
+     * cursor to the left.
+     */
+    if (sp->_echo && !(win->_flags & _ISPAD)) {
+	chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch;
+	if (backup < KEY_MIN)
+	    wechochar(win, backup);
+    }
+
+    /*
+     * Simulate ICRNL mode
+     */
+    if ((ch == '\r') && sp->_nl)
+	ch = '\n';
+
+    /* Strip 8th-bit if so desired.  We do this only for characters that
+     * are in the range 128-255, to provide compatibility with terminals
+     * that display only 7-bit characters.  Note that 'ch' may be a
+     * function key at this point, so we mustn't strip _those_.
+     */
+    if (!use_meta)
+	if ((ch < KEY_MIN) && (ch & 0x80))
+	    ch &= 0x7f;
+
+    T(("wgetch returning : %s", _nc_tracechar(sp, ch)));
+
+    *result = ch;
+    returnCode(ch >= KEY_MIN ? KEY_CODE_YES : OK);
+}
+
+#ifdef NCURSES_WGETCH_EVENTS
+NCURSES_EXPORT(int)
+wgetch_events(WINDOW *win, _nc_eventlist * evl)
+{
+    int code;
+    unsigned long value;
+
+    T((T_CALLED("wgetch_events(%p,%p)"), win, evl));
+    code = _nc_wgetch(win,
+		      &value,
+		      _nc_use_meta(win)
+		      EVENTLIST_2nd(evl));
+    if (code != ERR)
+	code = value;
+    returnCode(code);
+}
+#endif
+
+NCURSES_EXPORT(int)
+wgetch(WINDOW *win)
+{
+    int code;
+    unsigned long value;
+
+    T((T_CALLED("wgetch(%p)"), win));
+    code = _nc_wgetch(win,
+		      &value,
+		      _nc_use_meta(win)
+		      EVENTLIST_2nd((_nc_eventlist *) 0));
+    if (code != ERR)
+	code = value;
+    returnCode(code);
+}
+
+/*
+**      int
+**      kgetch()
+**
+**      Get an input character, but take care of keypad sequences, returning
+**      an appropriate code when one matches the input.  After each character
+**      is received, set an alarm call based on ESCDELAY.  If no more of the
+**      sequence is received by the time the alarm goes off, pass through
+**      the sequence gotten so far.
+**
+**	This function must be called when there are no cooked keys in queue.
+**	(that is head==-1 || peek==head)
+**
+*/
+
+static int
+kgetch(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    TRIES *ptr;
+    int ch = 0;
+    int timeleft = GetEscdelay(sp);
+
+    TR(TRACE_IEVENT, ("kgetch() called"));
+
+    ptr = sp->_keytry;
+
+    for (;;) {
+	if (cooked_key_in_fifo() && sp->_fifo[head] >= KEY_MIN) {
+	    break;
+	} else if (!raw_key_in_fifo()) {
+	    ch = fifo_push(sp EVENTLIST_2nd(evl));
+	    if (ch == ERR) {
+		peek = head;	/* the keys stay uninterpreted */
+		return ERR;
+	    }
+#ifdef NCURSES_WGETCH_EVENTS
+	    else if (ch == KEY_EVENT) {
+		peek = head;	/* the keys stay uninterpreted */
+		return fifo_pull(sp);	/* Remove KEY_EVENT from the queue */
+	    }
+#endif
+	}
+
+	ch = fifo_peek(sp);
+	if (ch >= KEY_MIN) {
+	    /* If not first in queue, somebody put this key there on purpose in
+	     * emergency.  Consider it higher priority than the unfinished
+	     * keysequence we are parsing.
+	     */
+	    peek = head;
+	    /* assume the key is the last in fifo */
+	    t_dec();		/* remove the key */
+	    return ch;
+	}
+
+	TR(TRACE_IEVENT, ("ch: %s", _nc_tracechar(sp, (unsigned char) ch)));
+	while ((ptr != NULL) && (ptr->ch != (unsigned char) ch))
+	    ptr = ptr->sibling;
+
+	if (ptr == NULL) {
+	    TR(TRACE_IEVENT, ("ptr is null"));
+	    break;
+	}
+	TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d",
+			  ptr, ptr->ch, ptr->value));
+
+	if (ptr->value != 0) {	/* sequence terminated */
+	    TR(TRACE_IEVENT, ("end of sequence"));
+	    if (peek == tail)
+		fifo_clear(sp);
+	    else
+		head = peek;
+	    return (ptr->value);
+	}
+
+	ptr = ptr->child;
+
+	if (!raw_key_in_fifo()) {
+	    int rc;
+
+	    TR(TRACE_IEVENT, ("waiting for rest of sequence"));
+	    rc = check_mouse_activity(sp, timeleft EVENTLIST_2nd(evl));
+#ifdef NCURSES_WGETCH_EVENTS
+	    if (rc & 4) {
+		TR(TRACE_IEVENT, ("interrupted by a user event"));
+		/* FIXME Should have preserved remainder timeleft for reuse... */
+		peek = head;	/* Restart interpreting later */
+		return KEY_EVENT;
+	    }
+#endif
+	    if (!rc) {
+		TR(TRACE_IEVENT, ("ran out of time"));
+		break;
+	    }
+	}
+    }
+    ch = fifo_pull(sp);
+    peek = head;
+    return ch;
+}
diff --git a/ncurses/base/lib_getstr.c b/ncurses/base/lib_getstr.c
new file mode 100644
index 0000000..b17df03
--- /dev/null
+++ b/ncurses/base/lib_getstr.c
@@ -0,0 +1,225 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_getstr.c
+**
+**	The routine wgetstr().
+**
+*/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_getstr.c,v 1.27 2008/08/16 19:20:04 tom Exp $")
+
+/*
+ * This wipes out the last character, no matter whether it was a tab, control
+ * or other character, and handles reverse wraparound.
+ */
+static char *
+WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed)
+{
+    if (last > first) {
+	*--last = '\0';
+	if (echoed) {
+	    int y1 = win->_cury;
+	    int x1 = win->_curx;
+
+	    wmove(win, y, x);
+	    waddstr(win, first);
+	    getyx(win, y, x);
+	    while (win->_cury < y1
+		   || (win->_cury == y1 && win->_curx < x1))
+		waddch(win, (chtype) ' ');
+
+	    wmove(win, y, x);
+	}
+    }
+    return last;
+}
+
+NCURSES_EXPORT(int)
+wgetnstr_events(WINDOW *win,
+		char *str,
+		int maxlen,
+		EVENTLIST_1st(_nc_eventlist * evl))
+{
+    SCREEN *sp = _nc_screen_of(win);
+    TTY buf;
+    bool oldnl, oldecho, oldraw, oldcbreak;
+    char erasec;
+    char killc;
+    char *oldstr;
+    int ch;
+    int y, x;
+
+    T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen));
+
+    if (!win)
+	returnCode(ERR);
+
+    _nc_get_tty_mode(&buf);
+
+    oldnl = sp->_nl;
+    oldecho = sp->_echo;
+    oldraw = sp->_raw;
+    oldcbreak = sp->_cbreak;
+    nl();
+    noecho();
+    noraw();
+    cbreak();
+
+    erasec = erasechar();
+    killc = killchar();
+
+    oldstr = str;
+    getyx(win, y, x);
+
+    if (is_wintouched(win) || (win->_flags & _HASMOVED))
+	wrefresh(win);
+
+    while ((ch = wgetch_events(win, evl)) != ERR) {
+	/*
+	 * Some terminals (the Wyse-50 is the most common) generate
+	 * a \n from the down-arrow key.  With this logic, it's the
+	 * user's choice whether to set kcud=\n for wgetch();
+	 * terminating *getstr() with \n should work either way.
+	 */
+	if (ch == '\n'
+	    || ch == '\r'
+	    || ch == KEY_DOWN
+	    || ch == KEY_ENTER) {
+	    if (oldecho == TRUE
+		&& win->_cury == win->_maxy
+		&& win->_scroll)
+		wechochar(win, (chtype) '\n');
+	    break;
+	}
+#ifdef KEY_EVENT
+	if (ch == KEY_EVENT)
+	    break;
+#endif
+#ifdef KEY_RESIZE
+	if (ch == KEY_RESIZE)
+	    break;
+#endif
+	if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
+	    if (str > oldstr) {
+		str = WipeOut(win, y, x, oldstr, str, oldecho);
+	    }
+	} else if (ch == killc) {
+	    while (str > oldstr) {
+		str = WipeOut(win, y, x, oldstr, str, oldecho);
+	    }
+	} else if (ch >= KEY_MIN
+		   || (maxlen >= 0 && str - oldstr >= maxlen)) {
+	    beep();
+	} else {
+	    *str++ = (char) ch;
+	    if (oldecho == TRUE) {
+		int oldy = win->_cury;
+		if (waddch(win, (chtype) ch) == ERR) {
+		    /*
+		     * We can't really use the lower-right
+		     * corner for input, since it'll mess
+		     * up bookkeeping for erases.
+		     */
+		    win->_flags &= ~_WRAPPED;
+		    waddch(win, (chtype) ' ');
+		    str = WipeOut(win, y, x, oldstr, str, oldecho);
+		    continue;
+		} else if (win->_flags & _WRAPPED) {
+		    /*
+		     * If the last waddch forced a wrap &
+		     * scroll, adjust our reference point
+		     * for erasures.
+		     */
+		    if (win->_scroll
+			&& oldy == win->_maxy
+			&& win->_cury == win->_maxy) {
+			if (--y <= 0) {
+			    y = 0;
+			}
+		    }
+		    win->_flags &= ~_WRAPPED;
+		}
+		wrefresh(win);
+	    }
+	}
+    }
+
+    win->_curx = 0;
+    win->_flags &= ~_WRAPPED;
+    if (win->_cury < win->_maxy)
+	win->_cury++;
+    wrefresh(win);
+
+    /* Restore with a single I/O call, to fix minor asymmetry between
+     * raw/noraw, etc.
+     */
+    sp->_nl = oldnl;
+    sp->_echo = oldecho;
+    sp->_raw = oldraw;
+    sp->_cbreak = oldcbreak;
+
+    _nc_set_tty_mode(&buf);
+
+    *str = '\0';
+    if (ch == ERR)
+	returnCode(ch);
+
+    T(("wgetnstr returns %s", _nc_visbuf(oldstr)));
+
+#ifdef KEY_EVENT
+    if (ch == KEY_EVENT)
+	returnCode(ch);
+#endif
+#ifdef KEY_RESIZE
+    if (ch == KEY_RESIZE)
+	returnCode(ch);
+#endif
+
+    returnCode(OK);
+}
+
+#ifdef NCURSES_WGETCH_EVENTS
+NCURSES_EXPORT(int)
+wgetnstr(WINDOW *win, char *str, int maxlen)
+{
+    returnCode(wgetnstr_events(win,
+			       str,
+			       maxlen,
+			       EVENTLIST_1st((_nc_eventlist *) 0)));
+}
+#endif
diff --git a/ncurses/base/lib_hline.c b/ncurses/base/lib_hline.c
new file mode 100644
index 0000000..2ef2cc5
--- /dev/null
+++ b/ncurses/base/lib_hline.c
@@ -0,0 +1,80 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_hline.c
+**
+**	The routine whline().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_hline.c,v 1.11 2006/03/11 21:52:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+whline(WINDOW *win, chtype ch, int n)
+{
+    int code = ERR;
+    NCURSES_SIZE_T start;
+    NCURSES_SIZE_T end;
+
+    T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n));
+
+    if (win) {
+	struct ldat *line = &(win->_line[win->_cury]);
+	NCURSES_CH_T wch;
+
+	start = win->_curx;
+	end = start + n - 1;
+	if (end > win->_maxx)
+	    end = win->_maxx;
+
+	CHANGED_RANGE(line, start, end);
+
+	if (ch == 0)
+	    SetChar2(wch, ACS_HLINE);
+	else
+	    SetChar2(wch, ch);
+	wch = _nc_render(win, wch);
+
+	while (end >= start) {
+	    line->text[end] = wch;
+	    end--;
+	}
+
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_immedok.c b/ncurses/base/lib_immedok.c
new file mode 100644
index 0000000..87988b6
--- /dev/null
+++ b/ncurses/base/lib_immedok.c
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_immedok.c
+**
+**	The routine immedok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_immedok.c,v 1.4 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(void)
+immedok(WINDOW *win, bool flag)
+{
+    T((T_CALLED("immedok(%p,%d)"), win, flag));
+
+    if (win)
+	win->_immed = flag;
+
+    returnVoid;
+}
diff --git a/ncurses/base/lib_inchstr.c b/ncurses/base/lib_inchstr.c
new file mode 100644
index 0000000..6ff0168
--- /dev/null
+++ b/ncurses/base/lib_inchstr.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_inchstr.c
+**
+**	The routine winchnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_inchstr.c,v 1.10 2001/06/02 23:37:58 skimo Exp $")
+
+NCURSES_EXPORT(int)
+winchnstr(WINDOW *win, chtype * str, int n)
+{
+    int i = 0;
+
+    T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n));
+
+    if (!str)
+	returnCode(0);
+
+    if (win) {
+	for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++)
+	    str[i] =
+		CharOf(win->_line[win->_cury].text[win->_curx + i]) |
+		AttrOf(win->_line[win->_cury].text[win->_curx + i]);
+    }
+    str[i] = (chtype) 0;
+
+    returnCode(i);
+}
diff --git a/ncurses/base/lib_initscr.c b/ncurses/base/lib_initscr.c
new file mode 100644
index 0000000..b2fef0c
--- /dev/null
+++ b/ncurses/base/lib_initscr.c
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-2003               *
+ ****************************************************************************/
+
+/*
+**	lib_initscr.c
+**
+**	The routines initscr(), and termname().
+**
+*/
+
+#include <curses.priv.h>
+
+#if HAVE_SYS_TERMIO_H
+#include <sys/termio.h>		/* needed for ISC */
+#endif
+
+MODULE_ID("$Id: lib_initscr.c,v 1.38 2008/08/16 21:20:48 Werner.Fink Exp $")
+
+NCURSES_EXPORT(WINDOW *)
+initscr(void)
+{
+    WINDOW *result;
+
+    NCURSES_CONST char *name;
+
+    START_TRACE();
+    T((T_CALLED("initscr()")));
+
+    _nc_init_pthreads();
+    _nc_lock_global(curses);
+
+    /* Portable applications must not call initscr() more than once */
+    if (!_nc_globals.init_screen) {
+	_nc_globals.init_screen = TRUE;
+
+	if ((name = getenv("TERM")) == 0
+	    || *name == '\0')
+	    name = "unknown";
+#ifdef __CYGWIN__
+	/*
+	 * 2002/9/21
+	 * Work around a bug in Cygwin.  Full-screen subprocesses run from
+	 * bash, in turn spawned from another full-screen process, will dump
+	 * core when attempting to write to stdout.  Opening /dev/tty
+	 * explicitly seems to fix the problem.
+	 */
+	if (isatty(fileno(stdout))) {
+	    FILE *fp = fopen("/dev/tty", "w");
+	    if (fp != 0 && isatty(fileno(fp))) {
+		fclose(stdout);
+		dup2(fileno(fp), STDOUT_FILENO);
+		stdout = fdopen(STDOUT_FILENO, "w");
+	    }
+	}
+#endif
+	if (newterm(name, stdout, stdin) == 0) {
+	    fprintf(stderr, "Error opening terminal: %s.\n", name);
+	    exit(EXIT_FAILURE);
+	}
+
+	/* def_shell_mode - done in newterm/_nc_setupscreen */
+	def_prog_mode();
+    }
+    result = stdscr;
+    _nc_unlock_global(curses);
+
+    returnWin(result);
+}
diff --git a/ncurses/base/lib_insch.c b/ncurses/base/lib_insch.c
new file mode 100644
index 0000000..9166ea5
--- /dev/null
+++ b/ncurses/base/lib_insch.c
@@ -0,0 +1,155 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Sven Verdoolaege                                                *
+ *     and: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+**	lib_insch.c
+**
+**	The routine winsch().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_insch.c,v 1.25 2008/02/03 00:14:37 tom Exp $")
+
+/*
+ * Insert the given character, updating the current location to simplify
+ * inserting a string.
+ */
+NCURSES_EXPORT(int)
+_nc_insert_ch(WINDOW *win, chtype ch)
+{
+    int code = OK;
+    NCURSES_CH_T wch;
+    int count;
+    NCURSES_CONST char *s;
+
+    switch (ch) {
+    case '\t':
+	for (count = (TABSIZE - (win->_curx % TABSIZE)); count > 0; count--) {
+	    if ((code = _nc_insert_ch(win, ' ')) != OK)
+		break;
+	}
+	break;
+    case '\n':
+    case '\r':
+    case '\b':
+	SetChar2(wch, ch);
+	_nc_waddch_nosync(win, wch);
+	break;
+    default:
+	if (
+#if USE_WIDEC_SUPPORT
+	       WINDOW_EXT(win, addch_used) == 0 &&
+#endif
+	       is8bits(ChCharOf(ch)) &&
+	       isprint(ChCharOf(ch))) {
+	    if (win->_curx <= win->_maxx) {
+		struct ldat *line = &(win->_line[win->_cury]);
+		NCURSES_CH_T *end = &(line->text[win->_curx]);
+		NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
+		NCURSES_CH_T *temp2 = temp1 - 1;
+
+		SetChar2(wch, ch);
+
+		CHANGED_TO_EOL(line, win->_curx, win->_maxx);
+		while (temp1 > end)
+		    *temp1-- = *temp2--;
+
+		*temp1 = _nc_render(win, wch);
+		win->_curx++;
+	    }
+	} else if (is8bits(ChCharOf(ch)) && iscntrl(ChCharOf(ch))) {
+	    s = unctrl(ChCharOf(ch));
+	    while (*s != '\0') {
+		code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
+		if (code != OK)
+		    break;
+		++s;
+	    }
+	}
+#if USE_WIDEC_SUPPORT
+	else {
+	    /*
+	     * Handle multibyte characters here
+	     */
+	    SetChar2(wch, ch);
+	    wch = _nc_render(win, wch);
+	    count = _nc_build_wch(win, &wch);
+	    if (count > 0) {
+		code = wins_wch(win, &wch);
+	    } else if (count == -1) {
+		/* handle EILSEQ */
+		if (is8bits(ch)) {
+		    s = unctrl(ChCharOf(ch));
+		    while (*s != '\0') {
+			code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
+			if (code != OK)
+			    break;
+			++s;
+		    }
+		} else {
+		    code = ERR;
+		}
+	    }
+	}
+#endif
+	break;
+    }
+    return code;
+}
+
+NCURSES_EXPORT(int)
+winsch(WINDOW *win, chtype c)
+{
+    NCURSES_SIZE_T oy;
+    NCURSES_SIZE_T ox;
+    int code = ERR;
+
+    T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c)));
+
+    if (win != 0) {
+	oy = win->_cury;
+	ox = win->_curx;
+
+	code = _nc_insert_ch(win, c);
+
+	win->_curx = ox;
+	win->_cury = oy;
+	_nc_synchook(win);
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_insdel.c b/ncurses/base/lib_insdel.c
new file mode 100644
index 0000000..342c654
--- /dev/null
+++ b/ncurses/base/lib_insdel.c
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_insdel.c
+**
+**	The routine winsdelln(win, n).
+**  positive n insert n lines above current line
+**  negative n delete n lines starting from current line
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_insdel.c,v 1.12 2003/07/26 22:40:06 tom Exp $")
+
+NCURSES_EXPORT(int)
+winsdelln(WINDOW *win, int n)
+{
+    int code = ERR;
+
+    T((T_CALLED("winsdelln(%p,%d)"), win, n));
+
+    if (win) {
+	if (n != 0) {
+	    _nc_scroll_window(win, -n, win->_cury, win->_maxy,
+			      win->_nc_bkgd);
+	    _nc_synchook(win);
+	}
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_insnstr.c b/ncurses/base/lib_insnstr.c
new file mode 100644
index 0000000..b6ddfde
--- /dev/null
+++ b/ncurses/base/lib_insnstr.c
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * Copyright (c) 2004 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+**	lib_insnstr.c
+**
+**	The routine winsnstr().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_insnstr.c,v 1.1 2004/02/28 23:44:56 tom Exp $")
+
+NCURSES_EXPORT(int)
+winsnstr(WINDOW *win, const char *s, int n)
+{
+    int code = ERR;
+    NCURSES_SIZE_T oy;
+    NCURSES_SIZE_T ox;
+    const unsigned char *str = (const unsigned char *) s;
+    const unsigned char *cp;
+
+    T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbufn(s, n), n));
+
+    if (win != 0 && str != 0) {
+	oy = win->_cury;
+	ox = win->_curx;
+	for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
+	    _nc_insert_ch(win, (chtype) UChar(*cp));
+	}
+	win->_curx = ox;
+	win->_cury = oy;
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_instr.c b/ncurses/base/lib_instr.c
new file mode 100644
index 0000000..3fb2949
--- /dev/null
+++ b/ncurses/base/lib_instr.c
@@ -0,0 +1,112 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_instr.c
+**
+**	The routine winnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_instr.c,v 1.16 2007/07/21 20:18:10 tom Exp $")
+
+NCURSES_EXPORT(int)
+winnstr(WINDOW *win, char *str, int n)
+{
+    int i = 0, row, col;
+
+    T((T_CALLED("winnstr(%p,%p,%d)"), win, str, n));
+
+    if (!str)
+	returnCode(0);
+
+    if (win) {
+	getyx(win, row, col);
+
+	if (n < 0)
+	    n = win->_maxx - win->_curx + 1;
+
+	for (; i < n;) {
+#if USE_WIDEC_SUPPORT
+	    cchar_t *cell = &(win->_line[row].text[col]);
+	    wchar_t *wch;
+	    attr_t attrs;
+	    short pair;
+	    int n2;
+	    bool done = FALSE;
+	    mbstate_t state;
+	    size_t i3, n3;
+	    char *tmp;
+
+	    if (!isWidecExt(*cell)) {
+		n2 = getcchar(cell, 0, 0, 0, 0);
+		if (n2 > 0
+		    && (wch = typeCalloc(wchar_t, (unsigned) n2 + 1)) != 0) {
+		    if (getcchar(cell, wch, &attrs, &pair, 0) == OK) {
+
+			init_mb(state);
+			n3 = wcstombs(0, wch, 0);
+			if (isEILSEQ(n3) || (n3 == 0)) {
+			    ;
+			} else if ((int) (n3 + i) > n) {
+			    done = TRUE;
+			} else if ((tmp = typeCalloc(char, n3 + 10)) == 0) {
+			    done = TRUE;
+			} else {
+			    init_mb(state);
+			    wcstombs(tmp, wch, n3);
+			    for (i3 = 0; i3 < n3; ++i3)
+				str[i++] = tmp[i3];
+			    free(tmp);
+			}
+		    }
+		    free(wch);
+		    if (done)
+			break;
+		}
+	    }
+#else
+	    str[i++] = (char) CharOf(win->_line[row].text[col]);
+#endif
+	    if (++col > win->_maxx) {
+		break;
+	    }
+	}
+    }
+    str[i] = '\0';		/* SVr4 does not seem to count the null */
+    T(("winnstr returns %s", _nc_visbuf(str)));
+    returnCode(i);
+}
diff --git a/ncurses/base/lib_isendwin.c b/ncurses/base/lib_isendwin.c
new file mode 100644
index 0000000..b337d97
--- /dev/null
+++ b/ncurses/base/lib_isendwin.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_endwin.c
+**
+**	The routine endwin().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_isendwin.c,v 1.6 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(bool)
+isendwin(void)
+{
+    if (SP == NULL)
+	return FALSE;
+    return SP->_endwin;
+}
diff --git a/ncurses/base/lib_leaveok.c b/ncurses/base/lib_leaveok.c
new file mode 100644
index 0000000..17d095d
--- /dev/null
+++ b/ncurses/base/lib_leaveok.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_leaveok.c
+**
+**	The routine leaveok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_leaveok.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+leaveok(WINDOW *win, bool flag)
+{
+    T((T_CALLED("leaveok(%p,%d)"), win, flag));
+
+    if (win) {
+	win->_leaveok = flag;
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c
new file mode 100644
index 0000000..95f29aa
--- /dev/null
+++ b/ncurses/base/lib_mouse.c
@@ -0,0 +1,1435 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ * This module is intended to encapsulate ncurses's interface to pointing
+ * devices.
+ *
+ * The primary method used is xterm's internal mouse-tracking facility.
+ * Additional methods depend on the platform:
+ *	Alessandro Rubini's GPM server (Linux)
+ *	sysmouse (FreeBSD)
+ *	special-purpose mouse interface for OS/2 EMX.
+ *
+ * Notes for implementors of new mouse-interface methods:
+ *
+ * The code is logically split into a lower level that accepts event reports
+ * in a device-dependent format and an upper level that parses mouse gestures
+ * and filters events.  The mediating data structure is a circular queue of
+ * MEVENT structures.
+ *
+ * Functionally, the lower level's job is to pick up primitive events and
+ * put them on the circular queue.  This can happen in one of two ways:
+ * either (a) _nc_mouse_event() detects a series of incoming mouse reports
+ * and queues them, or (b) code in lib_getch.c detects the kmous prefix in
+ * the keyboard input stream and calls _nc_mouse_inline to queue up a series
+ * of adjacent mouse reports.
+ *
+ * In either case, _nc_mouse_parse() should be called after the series is
+ * accepted to parse the digested mouse reports (low-level MEVENTs) into
+ * a gesture (a high-level or composite MEVENT).
+ *
+ * Don't be too shy about adding new event types or modifiers, if you can find
+ * room for them in the 32-bit mask.  The API is written so that users get
+ * feedback on which theoretical event types they won't see when they call
+ * mousemask. There's one bit per button (the RESERVED_EVENT bit) not being
+ * used yet, and a couple of bits open at the high end.
+ */
+
+#ifdef __EMX__
+#  include <io.h>
+#  define  INCL_DOS
+#  define  INCL_VIO
+#  define  INCL_KBD
+#  define  INCL_MOU
+#  define  INCL_DOSPROCESS
+#  include <os2.h>		/* Need to include before the others */
+#endif
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_mouse.c,v 1.102 2008/10/18 21:48:55 tom Exp $")
+
+#include <term.h>
+#include <tic.h>
+
+#if USE_GPM_SUPPORT
+#include <linux/keyboard.h>	/* defines KG_* macros */
+
+#ifdef HAVE_LIBDL
+/* use dynamic loader to avoid linkage dependency */
+#include <dlfcn.h>
+
+#ifdef RTLD_NOW
+#define my_RTLD RTLD_NOW
+#else
+#ifdef RTLD_LAZY
+#define my_RTLD RTLD_LAZY
+#else
+make an error
+#endif
+#endif				/* RTLD_NOW */
+#endif				/* HAVE_LIBDL */
+
+#endif				/* USE_GPM_SUPPORT */
+
+#if USE_SYSMOUSE
+#undef buttons			/* symbol conflict in consio.h */
+#undef mouse_info		/* symbol conflict in consio.h */
+#include <osreldate.h>
+#if (__FreeBSD_version >= 400017)
+#include <sys/consio.h>
+#include <sys/fbio.h>
+#else
+#include <machine/console.h>
+#endif
+#endif				/* use_SYSMOUSE */
+
+#define MY_TRACE TRACE_ICALLS|TRACE_IEVENT
+
+#define	MASK_RELEASE(x)		NCURSES_MOUSE_MASK(x, 001)
+#define	MASK_PRESS(x)		NCURSES_MOUSE_MASK(x, 002)
+#define	MASK_CLICK(x)		NCURSES_MOUSE_MASK(x, 004)
+#define	MASK_DOUBLE_CLICK(x)	NCURSES_MOUSE_MASK(x, 010)
+#define	MASK_TRIPLE_CLICK(x)	NCURSES_MOUSE_MASK(x, 020)
+#define	MASK_RESERVED_EVENT(x)	NCURSES_MOUSE_MASK(x, 040)
+
+#if NCURSES_MOUSE_VERSION == 1
+#define BUTTON_CLICKED        (BUTTON1_CLICKED        | BUTTON2_CLICKED        | BUTTON3_CLICKED        | BUTTON4_CLICKED)
+#define BUTTON_PRESSED        (BUTTON1_PRESSED        | BUTTON2_PRESSED        | BUTTON3_PRESSED        | BUTTON4_PRESSED)
+#define BUTTON_RELEASED       (BUTTON1_RELEASED       | BUTTON2_RELEASED       | BUTTON3_RELEASED       | BUTTON4_RELEASED)
+#define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED)
+#define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED)
+#define MAX_BUTTONS  4
+#else
+#define BUTTON_CLICKED        (BUTTON1_CLICKED        | BUTTON2_CLICKED        | BUTTON3_CLICKED        | BUTTON4_CLICKED        | BUTTON5_CLICKED)
+#define BUTTON_PRESSED        (BUTTON1_PRESSED        | BUTTON2_PRESSED        | BUTTON3_PRESSED        | BUTTON4_PRESSED        | BUTTON5_PRESSED)
+#define BUTTON_RELEASED       (BUTTON1_RELEASED       | BUTTON2_RELEASED       | BUTTON3_RELEASED       | BUTTON4_RELEASED       | BUTTON5_RELEASED)
+#define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED | BUTTON5_DOUBLE_CLICKED)
+#define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED | BUTTON5_TRIPLE_CLICKED)
+#define MAX_BUTTONS  5
+#endif
+
+#define INVALID_EVENT	-1
+#define NORMAL_EVENT	0
+
+#if USE_GPM_SUPPORT
+
+#ifndef LIBGPM_SONAME
+#define LIBGPM_SONAME "libgpm.so"
+#endif
+
+#define GET_DLSYM(name) (my_##name = (TYPE_##name) dlsym(SP->_dlopen_gpm, #name))
+
+#endif				/* USE_GPM_SUPPORT */
+
+static bool _nc_mouse_parse(SCREEN *, int);
+static void _nc_mouse_resume(SCREEN *);
+static void _nc_mouse_wrap(SCREEN *);
+
+/* maintain a circular list of mouse events */
+
+#define FirstEV(sp)	((sp)->_mouse_events)
+#define LastEV(sp)	((sp)->_mouse_events + EV_MAX - 1)
+
+#undef  NEXT
+#define NEXT(ep)	((ep >= LastEV(sp)) \
+			 ? FirstEV(sp) \
+			 : ep + 1)
+
+#undef  PREV
+#define PREV(ep)	((ep <= FirstEV(sp)) \
+			 ? LastEV(sp) \
+			 : ep - 1)
+
+#define IndexEV(sp, ep)	(ep - FirstEV(sp))
+
+#define RunParams(sp, eventp, runp) \
+		(long) IndexEV(sp, runp), \
+		(long) (IndexEV(sp, eventp) + (EV_MAX - 1)) % EV_MAX
+
+#ifdef TRACE
+static void
+_trace_slot(SCREEN *sp, const char *tag)
+{
+    MEVENT *ep;
+
+    _tracef(tag);
+
+    for (ep = FirstEV(sp); ep <= LastEV(sp); ep++)
+	_tracef("mouse event queue slot %ld = %s",
+		(long) IndexEV(sp, ep),
+		_nc_tracemouse(sp, ep));
+}
+#endif
+
+#if USE_EMX_MOUSE
+
+#  define TOP_ROW          0
+#  define LEFT_COL         0
+
+#  define M_FD(sp) sp->_mouse_fd
+
+static void
+write_event(SCREEN *sp, int down, int button, int x, int y)
+{
+    char buf[6];
+    unsigned long ignore;
+
+    strncpy(buf, key_mouse, 3);	/* should be "\033[M" */
+    buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40);
+    buf[4] = ' ' + x - LEFT_COL + 1;
+    buf[5] = ' ' + y - TOP_ROW + 1;
+    DosWrite(sp->_emxmouse_wfd, buf, 6, &ignore);
+}
+
+static void
+mouse_server(unsigned long param)
+{
+    SCREEN *sp = (SCREEN *) param;
+    unsigned short fWait = MOU_WAIT;
+    /* NOPTRRECT mourt = { 0,0,24,79 }; */
+    MOUEVENTINFO mouev;
+    HMOU hmou;
+    unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN;
+    int nbuttons = 3;
+    int oldstate = 0;
+    char err[80];
+    unsigned long rc;
+
+    /* open the handle for the mouse */
+    if (MouOpen(NULL, &hmou) == 0) {
+	rc = MouSetEventMask(&mask, hmou);
+	if (rc) {		/* retry with 2 buttons */
+	    mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN;
+	    rc = MouSetEventMask(&mask, hmou);
+	    nbuttons = 2;
+	}
+	if (rc == 0 && MouDrawPtr(hmou) == 0) {
+	    for (;;) {
+		/* sit and wait on the event queue */
+		rc = MouReadEventQue(&mouev, &fWait, hmou);
+		if (rc) {
+		    sprintf(err, "Error reading mouse queue, rc=%lu.\r\n", rc);
+		    break;
+		}
+		if (!sp->_emxmouse_activated)
+		    goto finish;
+
+		/*
+		 * OS/2 numbers a 3-button mouse inconsistently from other
+		 * platforms:
+		 *      1 = left
+		 *      2 = right
+		 *      3 = middle.
+		 */
+		if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN)
+		    write_event(sp, mouev.fs & MOUSE_BN1_DOWN,
+				sp->_emxmouse_buttons[1], mouev.col, mouev.row);
+		if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN)
+		    write_event(sp, mouev.fs & MOUSE_BN2_DOWN,
+				sp->_emxmouse_buttons[3], mouev.col, mouev.row);
+		if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN)
+		    write_event(sp, mouev.fs & MOUSE_BN3_DOWN,
+				sp->_emxmouse_buttons[2], mouev.col, mouev.row);
+
+	      finish:
+		oldstate = mouev.fs;
+	    }
+	} else
+	    sprintf(err, "Error setting event mask, buttons=%d, rc=%lu.\r\n",
+		    nbuttons, rc);
+
+	DosWrite(2, err, strlen(err), &rc);
+	MouClose(hmou);
+    }
+    DosExit(EXIT_THREAD, 0L);
+}
+
+#endif /* USE_EMX_MOUSE */
+
+#if USE_SYSMOUSE
+static void
+sysmouse_server(SCREEN *sp)
+{
+    struct mouse_info the_mouse;
+    MEVENT *work;
+
+    the_mouse.operation = MOUSE_GETINFO;
+    if (sp != 0
+	&& sp->_mouse_fd >= 0
+	&& sp->_sysmouse_tail < FIFO_SIZE
+	&& ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
+
+	if (sp->_sysmouse_head > sp->_sysmouse_tail) {
+	    sp->_sysmouse_tail = 0;
+	    sp->_sysmouse_head = 0;
+	}
+	work = &(sp->_sysmouse_fifo[sp->_sysmouse_tail]);
+	memset(work, 0, sizeof(*work));
+	work->id = NORMAL_EVENT;	/* there's only one mouse... */
+
+	sp->_sysmouse_old_buttons = sp->_sysmouse_new_buttons;
+	sp->_sysmouse_new_buttons = the_mouse.u.data.buttons & 0x7;
+
+	if (sp->_sysmouse_new_buttons) {
+	    if (sp->_sysmouse_new_buttons & 1)
+		work->bstate |= BUTTON1_PRESSED;
+	    if (sp->_sysmouse_new_buttons & 2)
+		work->bstate |= BUTTON2_PRESSED;
+	    if (sp->_sysmouse_new_buttons & 4)
+		work->bstate |= BUTTON3_PRESSED;
+	} else {
+	    if (sp->_sysmouse_old_buttons & 1)
+		work->bstate |= BUTTON1_RELEASED;
+	    if (sp->_sysmouse_old_buttons & 2)
+		work->bstate |= BUTTON2_RELEASED;
+	    if (sp->_sysmouse_old_buttons & 4)
+		work->bstate |= BUTTON3_RELEASED;
+	}
+
+	/* for cosmetic bug in syscons.c on FreeBSD 3.[34] */
+	the_mouse.operation = MOUSE_HIDE;
+	ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+	the_mouse.operation = MOUSE_SHOW;
+	ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+
+	/*
+	 * We're only interested if the button is pressed or released.
+	 * FIXME: implement continuous event-tracking.
+	 */
+	if (sp->_sysmouse_new_buttons != sp->_sysmouse_old_buttons) {
+	    sp->_sysmouse_tail += 1;
+	}
+	work->x = the_mouse.u.data.x / sp->_sysmouse_char_width;
+	work->y = the_mouse.u.data.y / sp->_sysmouse_char_height;
+    }
+}
+
+static void
+handle_sysmouse(int sig GCC_UNUSED)
+{
+    sysmouse_server(SP);
+}
+#endif /* USE_SYSMOUSE */
+
+static void
+init_xterm_mouse(SCREEN *sp)
+{
+    sp->_mouse_type = M_XTERM;
+    sp->_mouse_xtermcap = tigetstr("XM");
+    if (!VALID_STRING(sp->_mouse_xtermcap))
+	sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
+}
+
+static void
+enable_xterm_mouse(SCREEN *sp, int enable)
+{
+#if USE_EMX_MOUSE
+    sp->_emxmouse_activated = enable;
+#else
+    putp(TPARM_1(sp->_mouse_xtermcap, enable));
+#endif
+    sp->_mouse_active = enable;
+}
+
+#if USE_GPM_SUPPORT
+static bool
+allow_gpm_mouse(void)
+{
+    bool result = FALSE;
+
+    /* GPM does printf's without checking if stdout is a terminal */
+    if (isatty(fileno(stdout))) {
+	char *list = getenv("NCURSES_GPM_TERMS");
+	char *env = getenv("TERM");
+	if (list != 0) {
+	    if (env != 0) {
+		result = _nc_name_match(list, env, "|:");
+	    }
+	} else {
+	    /* GPM checks the beginning of the $TERM variable to decide if it
+	     * should pass xterm events through.  There is no real advantage in
+	     * allowing GPM to do this.  Recent versions relax that check, and
+	     * pretend that GPM can work with any terminal having the kmous
+	     * capability.  Perhaps that works for someone.  If so, they can
+	     * set the environment variable (above).
+	     */
+	    if (env != 0 && strstr(env, "linux") != 0) {
+		result = TRUE;
+	    }
+	}
+    }
+    return result;
+}
+
+#ifdef HAVE_LIBDL
+static void
+unload_gpm_library(SCREEN *sp)
+{
+    if (SP->_dlopen_gpm != 0) {
+	T(("unload GPM library"));
+	sp->_mouse_gpm_loaded = FALSE;
+	sp->_mouse_fd = -1;
+	dlclose(sp->_dlopen_gpm);
+	sp->_dlopen_gpm = 0;
+    }
+}
+
+static void
+load_gpm_library(SCREEN *sp)
+{
+    sp->_mouse_gpm_found = FALSE;
+    if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) {
+	if (GET_DLSYM(gpm_fd) == 0 ||
+	    GET_DLSYM(Gpm_Open) == 0 ||
+	    GET_DLSYM(Gpm_Close) == 0 ||
+	    GET_DLSYM(Gpm_GetEvent) == 0) {
+	    T(("GPM initialization failed: %s", dlerror()));
+	    unload_gpm_library(sp);
+	} else {
+	    sp->_mouse_gpm_found = TRUE;
+	    sp->_mouse_gpm_loaded = TRUE;
+	}
+    }
+}
+#endif
+
+static bool
+enable_gpm_mouse(SCREEN *sp, bool enable)
+{
+    bool result;
+
+    T((T_CALLED("enable_gpm_mouse(%d)"), enable));
+
+    if (enable && !sp->_mouse_active) {
+#ifdef HAVE_LIBDL
+	if (sp->_mouse_gpm_found && !sp->_mouse_gpm_loaded) {
+	    load_gpm_library(sp);
+	}
+#endif
+	if (sp->_mouse_gpm_loaded) {
+	    /* GPM: initialize connection to gpm server */
+	    sp->_mouse_gpm_connect.eventMask = GPM_DOWN | GPM_UP;
+	    sp->_mouse_gpm_connect.defaultMask =
+		(unsigned short) (~(sp->_mouse_gpm_connect.eventMask | GPM_HARD));
+	    sp->_mouse_gpm_connect.minMod = 0;
+	    sp->_mouse_gpm_connect.maxMod =
+		(unsigned short) (~((1 << KG_SHIFT) |
+				    (1 << KG_SHIFTL) |
+				    (1 << KG_SHIFTR)));
+	    /*
+	     * Note: GPM hardcodes \E[?1001s and \E[?1000h during its open.
+	     * The former is recognized by wscons (SunOS), and the latter by
+	     * xterm.  Those will not show up in ncurses' traces.
+	     */
+	    result = (my_Gpm_Open(&sp->_mouse_gpm_connect, 0) >= 0);
+	} else {
+	    result = FALSE;
+	}
+	sp->_mouse_active = result;
+	T(("GPM open %s", result ? "succeeded" : "failed"));
+    } else {
+	if (!enable && sp->_mouse_active) {
+	    /* GPM: close connection to gpm server */
+	    my_Gpm_Close();
+	    sp->_mouse_active = FALSE;
+	    T(("GPM closed"));
+	}
+	result = enable;
+    }
+#ifdef HAVE_LIBDL
+    if (!result) {
+	unload_gpm_library(sp);
+    }
+#endif
+    returnBool(result);
+}
+#endif /* USE_GPM_SUPPORT */
+
+#define xterm_kmous "\033[M"
+
+static void
+initialize_mousetype(SCREEN *sp)
+{
+    T((T_CALLED("initialize_mousetype()")));
+
+    /* Try gpm first, because gpm may be configured to run in xterm */
+#if USE_GPM_SUPPORT
+    if (allow_gpm_mouse()) {
+	if (!sp->_mouse_gpm_loaded) {
+#ifdef HAVE_LIBDL
+	    load_gpm_library(sp);
+#else /* !HAVE_LIBDL */
+	    sp->_mouse_gpm_found = TRUE;
+	    sp->_mouse_gpm_loaded = TRUE;
+#endif
+	}
+
+	/*
+	 * The gpm_fd file-descriptor may be negative (xterm).  So we have to
+	 * maintain our notion of whether the mouse connection is active
+	 * without testing the file-descriptor.
+	 */
+	if (sp->_mouse_gpm_found && enable_gpm_mouse(sp, TRUE)) {
+	    sp->_mouse_type = M_GPM;
+	    sp->_mouse_fd = *(my_gpm_fd);
+	    T(("GPM mouse_fd %d", sp->_mouse_fd));
+	    returnVoid;
+	}
+    }
+#endif /* USE_GPM_SUPPORT */
+
+    /* OS/2 VIO */
+#if USE_EMX_MOUSE
+    if (!sp->_emxmouse_thread
+	&& strstr(cur_term->type.term_names, "xterm") == 0
+	&& key_mouse) {
+	int handles[2];
+
+	if (pipe(handles) < 0) {
+	    perror("mouse pipe error");
+	    returnVoid;
+	} else {
+	    int rc;
+
+	    if (!sp->_emxmouse_buttons[0]) {
+		char *s = getenv("MOUSE_BUTTONS_123");
+
+		sp->_emxmouse_buttons[0] = 1;
+		if (s && strlen(s) >= 3) {
+		    sp->_emxmouse_buttons[1] = s[0] - '0';
+		    sp->_emxmouse_buttons[2] = s[1] - '0';
+		    sp->_emxmouse_buttons[3] = s[2] - '0';
+		} else {
+		    sp->_emxmouse_buttons[1] = 1;
+		    sp->_emxmouse_buttons[2] = 3;
+		    sp->_emxmouse_buttons[3] = 2;
+		}
+	    }
+	    sp->_emxmouse_wfd = handles[1];
+	    M_FD(sp) = handles[0];
+	    /* Needed? */
+	    setmode(handles[0], O_BINARY);
+	    setmode(handles[1], O_BINARY);
+	    /* Do not use CRT functions, we may single-threaded. */
+	    rc = DosCreateThread((unsigned long *) &sp->_emxmouse_thread,
+				 mouse_server, (long) sp, 0, 8192);
+	    if (rc) {
+		printf("mouse thread error %d=%#x", rc, rc);
+	    } else {
+		sp->_mouse_type = M_XTERM;
+	    }
+	    returnVoid;
+	}
+    }
+#endif /* USE_EMX_MOUSE */
+
+#if USE_SYSMOUSE
+    {
+	struct mouse_info the_mouse;
+	char *the_device = 0;
+
+	if (isatty(sp->_ifd))
+	    the_device = ttyname(sp->_ifd);
+	if (the_device == 0)
+	    the_device = "/dev/tty";
+
+	sp->_mouse_fd = open(the_device, O_RDWR);
+
+	if (sp->_mouse_fd >= 0) {
+	    /*
+	     * sysmouse does not have a usable user interface for obtaining
+	     * mouse events.  The logical way to proceed (reading data on a
+	     * stream) only works if one opens the device as root.  Even in
+	     * that mode, careful examination shows we lose events
+	     * occasionally.  The interface provided for user programs is to
+	     * establish a signal handler.  really.
+	     *
+	     * Take over SIGUSR2 for this purpose since SIGUSR1 is more
+	     * likely to be used by an application.  getch() will have to
+	     * handle the misleading EINTR's.
+	     */
+	    signal(SIGUSR2, SIG_IGN);
+	    the_mouse.operation = MOUSE_MODE;
+	    the_mouse.u.mode.mode = 0;
+	    the_mouse.u.mode.signal = SIGUSR2;
+	    if (ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
+		signal(SIGUSR2, handle_sysmouse);
+		the_mouse.operation = MOUSE_SHOW;
+		ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+
+#if defined(FBIO_MODEINFO) || defined(CONS_MODEINFO)	/* FreeBSD > 2.x */
+		{
+#ifndef FBIO_GETMODE		/* FreeBSD 3.x */
+#define FBIO_GETMODE    CONS_GET
+#define FBIO_MODEINFO   CONS_MODEINFO
+#endif /* FBIO_GETMODE */
+		    video_info_t the_video;
+
+		    if (ioctl(sp->_mouse_fd,
+			      FBIO_GETMODE,
+			      &the_video.vi_mode) != -1
+			&& ioctl(sp->_mouse_fd,
+				 FBIO_MODEINFO,
+				 &the_video) != -1) {
+			sp->_sysmouse_char_width = the_video.vi_cwidth;
+			sp->_sysmouse_char_height = the_video.vi_cheight;
+		    }
+		}
+#endif /* defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) */
+
+		if (sp->_sysmouse_char_width <= 0)
+		    sp->_sysmouse_char_width = 8;
+		if (sp->_sysmouse_char_height <= 0)
+		    sp->_sysmouse_char_height = 16;
+		sp->_mouse_type = M_SYSMOUSE;
+		returnVoid;
+	    }
+	}
+    }
+#endif /* USE_SYSMOUSE */
+
+    /* we know how to recognize mouse events under "xterm" */
+    if (key_mouse != 0) {
+	if (!strcmp(key_mouse, xterm_kmous)
+	    || strstr(cur_term->type.term_names, "xterm") != 0) {
+	    init_xterm_mouse(sp);
+	}
+    } else if (strstr(cur_term->type.term_names, "xterm") != 0) {
+	if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
+	    init_xterm_mouse(sp);
+    }
+    returnVoid;
+}
+
+static bool
+_nc_mouse_init(SCREEN *sp)
+/* initialize the mouse */
+{
+    bool result = FALSE;
+    int i;
+
+    if (sp != 0) {
+	if (!sp->_mouse_initialized) {
+	    sp->_mouse_initialized = TRUE;
+
+	    TR(MY_TRACE, ("_nc_mouse_init() called"));
+
+	    sp->_mouse_eventp = FirstEV(sp);
+	    for (i = 0; i < EV_MAX; i++)
+		sp->_mouse_events[i].id = INVALID_EVENT;
+
+	    initialize_mousetype(sp);
+
+	    T(("_nc_mouse_init() set mousetype to %d", sp->_mouse_type));
+	}
+	result = sp->_mouse_initialized;
+    }
+    return result;
+}
+
+/*
+ * Query to see if there is a pending mouse event.  This is called from
+ * fifo_push() in lib_getch.c
+ */
+static bool
+_nc_mouse_event(SCREEN *sp GCC_UNUSED)
+{
+    MEVENT *eventp = sp->_mouse_eventp;
+    bool result = FALSE;
+
+    (void) eventp;
+
+    switch (sp->_mouse_type) {
+    case M_XTERM:
+	/* xterm: never have to query, mouse events are in the keyboard stream */
+#if USE_EMX_MOUSE
+	{
+	    char kbuf[3];
+
+	    int i, res = read(M_FD(sp), &kbuf, 3);	/* Eat the prefix */
+	    if (res != 3)
+		printf("Got %d chars instead of 3 for prefix.\n", res);
+	    for (i = 0; i < res; i++) {
+		if (kbuf[i] != key_mouse[i])
+		    printf("Got char %d instead of %d for prefix.\n",
+			   (int) kbuf[i], (int) key_mouse[i]);
+	    }
+	    result = TRUE;
+	}
+#endif /* USE_EMX_MOUSE */
+	break;
+
+#if USE_GPM_SUPPORT
+    case M_GPM:
+	{
+	    /* query server for event, return TRUE if we find one */
+	    Gpm_Event ev;
+
+	    if (my_Gpm_GetEvent(&ev) == 1) {
+		/* there's only one mouse... */
+		eventp->id = NORMAL_EVENT;
+
+		eventp->bstate = 0;
+		switch (ev.type & 0x0f) {
+		case (GPM_DOWN):
+		    if (ev.buttons & GPM_B_LEFT)
+			eventp->bstate |= BUTTON1_PRESSED;
+		    if (ev.buttons & GPM_B_MIDDLE)
+			eventp->bstate |= BUTTON2_PRESSED;
+		    if (ev.buttons & GPM_B_RIGHT)
+			eventp->bstate |= BUTTON3_PRESSED;
+		    break;
+		case (GPM_UP):
+		    if (ev.buttons & GPM_B_LEFT)
+			eventp->bstate |= BUTTON1_RELEASED;
+		    if (ev.buttons & GPM_B_MIDDLE)
+			eventp->bstate |= BUTTON2_RELEASED;
+		    if (ev.buttons & GPM_B_RIGHT)
+			eventp->bstate |= BUTTON3_RELEASED;
+		    break;
+		default:
+		    break;
+		}
+
+		eventp->x = ev.x - 1;
+		eventp->y = ev.y - 1;
+		eventp->z = 0;
+
+		/* bump the next-free pointer into the circular list */
+		sp->_mouse_eventp = eventp = NEXT(eventp);
+		result = TRUE;
+	    }
+	}
+	break;
+#endif
+
+#if USE_SYSMOUSE
+    case M_SYSMOUSE:
+	if (sp->_sysmouse_head < sp->_sysmouse_tail) {
+	    *eventp = sp->_sysmouse_fifo[sp->_sysmouse_head];
+
+	    /*
+	     * Point the fifo-head to the next possible location.  If there
+	     * are none, reset the indices.  This may be interrupted by the
+	     * signal handler, doing essentially the same reset.
+	     */
+	    sp->_sysmouse_head += 1;
+	    if (sp->_sysmouse_head == sp->_sysmouse_tail) {
+		sp->_sysmouse_tail = 0;
+		sp->_sysmouse_head = 0;
+	    }
+
+	    /* bump the next-free pointer into the circular list */
+	    sp->_mouse_eventp = eventp = NEXT(eventp);
+	    result = TRUE;
+	}
+	break;
+#endif /* USE_SYSMOUSE */
+
+    case M_NONE:
+	break;
+    }
+
+    return result;		/* true if we found an event */
+}
+
+static bool
+_nc_mouse_inline(SCREEN *sp)
+/* mouse report received in the keyboard stream -- parse its info */
+{
+    int b;
+    bool result = FALSE;
+    MEVENT *eventp = sp->_mouse_eventp;
+
+    TR(MY_TRACE, ("_nc_mouse_inline() called"));
+
+    if (sp->_mouse_type == M_XTERM) {
+	unsigned char kbuf[4];
+	mmask_t prev;
+	size_t grabbed;
+	int res;
+
+	/* This code requires that your xterm entry contain the kmous
+	 * capability and that it be set to the \E[M documented in the
+	 * Xterm Control Sequences reference.  This is how we
+	 * arrange for mouse events to be reported via a KEY_MOUSE
+	 * return value from wgetch().  After this value is received,
+	 * _nc_mouse_inline() gets called and is immediately
+	 * responsible for parsing the mouse status information
+	 * following the prefix.
+	 *
+	 * The following quotes from the ctrlseqs.ms document in the
+	 * X distribution, describing the X mouse tracking feature:
+	 *
+	 * Parameters for all mouse tracking escape sequences
+	 * generated by xterm encode numeric parameters in a single
+	 * character as value+040.  For example, !  is 1.
+	 *
+	 * On button press or release, xterm sends ESC [ M CbCxCy.
+	 * The low two bits of Cb encode button information: 0=MB1
+	 * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.  The
+	 * upper bits encode what modifiers were down when the
+	 * button was pressed and are added together.  4=Shift,
+	 * 8=Meta, 16=Control.  Cx and Cy are the x and y coordinates
+	 * of the mouse event.  The upper left corner is (1,1).
+	 *
+	 * (End quote)  By the time we get here, we've eaten the
+	 * key prefix.  FYI, the loop below is necessary because
+	 * mouse click info isn't guaranteed to present as a
+	 * single clist item.
+	 *
+	 * Wheel mice may return buttons 4 and 5 when the wheel is turned.
+	 * We encode those as button presses.
+	 */
+	for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) {
+
+	    /* For VIO mouse we add extra bit 64 to disambiguate button-up. */
+#if USE_EMX_MOUSE
+	    res = read(M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3);
+#else
+	    res = read(sp->_ifd, kbuf + grabbed, 3 - grabbed);
+#endif
+	    if (res == -1)
+		break;
+	}
+	kbuf[3] = '\0';
+
+	TR(TRACE_IEVENT,
+	   ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
+
+	/* there's only one mouse... */
+	eventp->id = NORMAL_EVENT;
+
+	/* processing code goes here */
+	eventp->bstate = 0;
+	prev = PREV(eventp)->bstate;
+
+#if USE_EMX_MOUSE
+#define PRESS_POSITION(n) \
+	eventp->bstate = MASK_PRESS(n); \
+	if (kbuf[0] & 0x40) \
+	    eventp->bstate = MASK_RELEASE(n)
+#else
+#define PRESS_POSITION(n) \
+	eventp->bstate = (mmask_t) (prev & MASK_PRESS(n) \
+				    ? REPORT_MOUSE_POSITION \
+				    : MASK_PRESS(n))
+#endif
+
+	switch (kbuf[0] & 0x3) {
+	case 0x0:
+	    if (kbuf[0] & 64)
+		eventp->bstate = MASK_PRESS(4);
+	    else
+		PRESS_POSITION(1);
+	    break;
+
+	case 0x1:
+#if NCURSES_MOUSE_VERSION == 2
+	    if (kbuf[0] & 64)
+		eventp->bstate = MASK_PRESS(5);
+	    else
+#endif
+		PRESS_POSITION(2);
+	    break;
+
+	case 0x2:
+	    PRESS_POSITION(3);
+	    break;
+
+	case 0x3:
+	    /*
+	     * Release events aren't reported for individual buttons, just for
+	     * the button set as a whole.  However, because there are normally
+	     * no mouse events under xterm that intervene between press and
+	     * release, we can infer the button actually released by looking at
+	     * the previous event.
+	     */
+	    if (prev & (BUTTON_PRESSED | BUTTON_RELEASED)) {
+		eventp->bstate = BUTTON_RELEASED;
+		for (b = 1; b <= MAX_BUTTONS; ++b) {
+		    if (!(prev & MASK_PRESS(b)))
+			eventp->bstate &= ~MASK_RELEASE(b);
+		}
+	    } else {
+		/*
+		 * XFree86 xterm will return a stream of release-events to
+		 * let the application know where the mouse is going, if the
+		 * private mode 1002 or 1003 is enabled.
+		 */
+		eventp->bstate = REPORT_MOUSE_POSITION;
+	    }
+	    break;
+	}
+	result = (eventp->bstate & REPORT_MOUSE_POSITION) ? TRUE : FALSE;
+
+	if (kbuf[0] & 4) {
+	    eventp->bstate |= BUTTON_SHIFT;
+	}
+	if (kbuf[0] & 8) {
+	    eventp->bstate |= BUTTON_ALT;
+	}
+	if (kbuf[0] & 16) {
+	    eventp->bstate |= BUTTON_CTRL;
+	}
+
+	eventp->x = (kbuf[1] - ' ') - 1;
+	eventp->y = (kbuf[2] - ' ') - 1;
+	TR(MY_TRACE,
+	   ("_nc_mouse_inline: primitive mouse-event %s has slot %ld",
+	    _nc_tracemouse(sp, eventp),
+	    (long) IndexEV(sp, eventp)));
+
+	/* bump the next-free pointer into the circular list */
+	sp->_mouse_eventp = NEXT(eventp);
+#if 0				/* this return would be needed for QNX's mods to lib_getch.c */
+	return (TRUE);
+#endif
+    }
+
+    return (result);
+}
+
+static void
+mouse_activate(SCREEN *sp, bool on)
+{
+    if (!on && !sp->_mouse_initialized)
+	return;
+
+    if (!_nc_mouse_init(sp))
+	return;
+
+    if (on) {
+
+	switch (sp->_mouse_type) {
+	case M_XTERM:
+#if NCURSES_EXT_FUNCS
+	    keyok(KEY_MOUSE, on);
+#endif
+	    TPUTS_TRACE("xterm mouse initialization");
+	    enable_xterm_mouse(sp, 1);
+	    break;
+#if USE_GPM_SUPPORT
+	case M_GPM:
+	    if (enable_gpm_mouse(sp, TRUE)) {
+		sp->_mouse_fd = *(my_gpm_fd);
+		T(("GPM mouse_fd %d", sp->_mouse_fd));
+	    }
+	    break;
+#endif
+#if USE_SYSMOUSE
+	case M_SYSMOUSE:
+	    signal(SIGUSR2, handle_sysmouse);
+	    sp->_mouse_active = TRUE;
+	    break;
+#endif
+	case M_NONE:
+	    return;
+	}
+	/* Make runtime binding to cut down on object size of applications that
+	 * do not use the mouse (e.g., 'clear').
+	 */
+	sp->_mouse_event = _nc_mouse_event;
+	sp->_mouse_inline = _nc_mouse_inline;
+	sp->_mouse_parse = _nc_mouse_parse;
+	sp->_mouse_resume = _nc_mouse_resume;
+	sp->_mouse_wrap = _nc_mouse_wrap;
+    } else {
+
+	switch (sp->_mouse_type) {
+	case M_XTERM:
+	    TPUTS_TRACE("xterm mouse deinitialization");
+	    enable_xterm_mouse(sp, 0);
+	    break;
+#if USE_GPM_SUPPORT
+	case M_GPM:
+	    enable_gpm_mouse(sp, FALSE);
+	    break;
+#endif
+#if USE_SYSMOUSE
+	case M_SYSMOUSE:
+	    signal(SIGUSR2, SIG_IGN);
+	    sp->_mouse_active = FALSE;
+	    break;
+#endif
+	case M_NONE:
+	    return;
+	}
+    }
+    _nc_flush();
+}
+
+/**************************************************************************
+ *
+ * Device-independent code
+ *
+ **************************************************************************/
+
+static bool
+_nc_mouse_parse(SCREEN *sp, int runcount)
+/* parse a run of atomic mouse events into a gesture */
+{
+    MEVENT *eventp = sp->_mouse_eventp;
+    MEVENT *ep, *runp, *next, *prev = PREV(eventp);
+    int n;
+    int b;
+    bool merge;
+
+    TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount));
+
+    /*
+     * When we enter this routine, the event list next-free pointer
+     * points just past a run of mouse events that we know were separated
+     * in time by less than the critical click interval. The job of this
+     * routine is to collapse this run into a single higher-level event
+     * or gesture.
+     *
+     * We accomplish this in two passes.  The first pass merges press/release
+     * pairs into click events.  The second merges runs of click events into
+     * double or triple-click events.
+     *
+     * It's possible that the run may not resolve to a single event (for
+     * example, if the user quadruple-clicks).  If so, leading events
+     * in the run are ignored.
+     *
+     * Note that this routine is independent of the format of the specific
+     * format of the pointing-device's reports.  We can use it to parse
+     * gestures on anything that reports press/release events on a per-
+     * button basis, as long as the device-dependent mouse code puts stuff
+     * on the queue in MEVENT format.
+     */
+    if (runcount == 1) {
+	TR(MY_TRACE,
+	   ("_nc_mouse_parse: returning simple mouse event %s at slot %ld",
+	    _nc_tracemouse(sp, prev),
+	    (long) IndexEV(sp, prev)));
+	return (prev->id >= NORMAL_EVENT)
+	    ? ((prev->bstate & sp->_mouse_mask) ? TRUE : FALSE)
+	    : FALSE;
+    }
+
+    /* find the start of the run */
+    runp = eventp;
+    for (n = runcount; n > 0; n--) {
+	runp = PREV(runp);
+    }
+
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_IEVENT)) {
+	_trace_slot(sp, "before mouse press/release merge:");
+	_tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+		RunParams(sp, eventp, runp),
+		runcount);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    /* first pass; merge press/release pairs */
+    do {
+	merge = FALSE;
+	for (ep = runp; (next = NEXT(ep)) != eventp; ep = next) {
+
+#define MASK_CHANGED(x) (!(ep->bstate & MASK_PRESS(x)) \
+		      == !(next->bstate & MASK_RELEASE(x)))
+
+	    if (ep->x == next->x && ep->y == next->y
+		&& (ep->bstate & BUTTON_PRESSED)
+		&& MASK_CHANGED(1)
+		&& MASK_CHANGED(2)
+		&& MASK_CHANGED(3)
+		&& MASK_CHANGED(4)
+#if NCURSES_MOUSE_VERSION == 2
+		&& MASK_CHANGED(5)
+#endif
+		) {
+		for (b = 1; b <= MAX_BUTTONS; ++b) {
+		    if ((sp->_mouse_mask & MASK_CLICK(b))
+			&& (ep->bstate & MASK_PRESS(b))) {
+			ep->bstate &= ~MASK_PRESS(b);
+			ep->bstate |= MASK_CLICK(b);
+			merge = TRUE;
+		    }
+		}
+		if (merge)
+		    next->id = INVALID_EVENT;
+	    }
+	}
+    } while
+	(merge);
+
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_IEVENT)) {
+	_trace_slot(sp, "before mouse click merge:");
+	_tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+		RunParams(sp, eventp, runp),
+		runcount);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    /*
+     * Second pass; merge click runs.  At this point, click events are
+     * each followed by one invalid event. We merge click events
+     * forward in the queue.
+     *
+     * NOTE: There is a problem with this design!  If the application
+     * allows enough click events to pile up in the circular queue so
+     * they wrap around, it will cheerfully merge the newest forward
+     * into the oldest, creating a bogus doubleclick and confusing
+     * the queue-traversal logic rather badly.  Generally this won't
+     * happen, because calling getmouse() marks old events invalid and
+     * ineligible for merges.  The true solution to this problem would
+     * be to timestamp each MEVENT and perform the obvious sanity check,
+     * but the timer element would have to have sub-second resolution,
+     * which would get us into portability trouble.
+     */
+    do {
+	MEVENT *follower;
+
+	merge = FALSE;
+	for (ep = runp; (next = NEXT(ep)) != eventp; ep = next)
+	    if (ep->id != INVALID_EVENT) {
+		if (next->id != INVALID_EVENT)
+		    continue;
+		follower = NEXT(next);
+		if (follower->id == INVALID_EVENT)
+		    continue;
+
+		/* merge click events forward */
+		if ((ep->bstate & BUTTON_CLICKED)
+		    && (follower->bstate & BUTTON_CLICKED)) {
+		    for (b = 1; b <= MAX_BUTTONS; ++b) {
+			if ((sp->_mouse_mask & MASK_DOUBLE_CLICK(b))
+			    && (follower->bstate & MASK_CLICK(b))) {
+			    follower->bstate &= ~MASK_CLICK(b);
+			    follower->bstate |= MASK_DOUBLE_CLICK(b);
+			    merge = TRUE;
+			}
+		    }
+		    if (merge)
+			ep->id = INVALID_EVENT;
+		}
+
+		/* merge double-click events forward */
+		if ((ep->bstate & BUTTON_DOUBLE_CLICKED)
+		    && (follower->bstate & BUTTON_CLICKED)) {
+		    for (b = 1; b <= MAX_BUTTONS; ++b) {
+			if ((sp->_mouse_mask & MASK_TRIPLE_CLICK(b))
+			    && (follower->bstate & MASK_CLICK(b))) {
+			    follower->bstate &= ~MASK_CLICK(b);
+			    follower->bstate |= MASK_TRIPLE_CLICK(b);
+			    merge = TRUE;
+			}
+		    }
+		    if (merge)
+			ep->id = INVALID_EVENT;
+		}
+	    }
+    } while
+	(merge);
+
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_IEVENT)) {
+	_trace_slot(sp, "before mouse event queue compaction:");
+	_tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+		RunParams(sp, eventp, runp),
+		runcount);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    /*
+     * Now try to throw away trailing events flagged invalid, or that
+     * don't match the current event mask.
+     */
+    for (; runcount; prev = PREV(eventp), runcount--)
+	if (prev->id == INVALID_EVENT || !(prev->bstate & sp->_mouse_mask)) {
+	    sp->_mouse_eventp = eventp = prev;
+	}
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_IEVENT)) {
+	_trace_slot(sp, "after mouse event queue compaction:");
+	_tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+		RunParams(sp, eventp, runp),
+		runcount);
+	_nc_unlock_global(tracef);
+    }
+    for (ep = runp; ep != eventp; ep = NEXT(ep))
+	if (ep->id != INVALID_EVENT)
+	    TR(MY_TRACE,
+	       ("_nc_mouse_parse: returning composite mouse event %s at slot %ld",
+		_nc_tracemouse(sp, ep),
+		(long) IndexEV(sp, ep)));
+#endif /* TRACE */
+
+    /* after all this, do we have a valid event? */
+    return (PREV(eventp)->id != INVALID_EVENT);
+}
+
+static void
+_nc_mouse_wrap(SCREEN *sp)
+/* release mouse -- called by endwin() before shellout/exit */
+{
+    TR(MY_TRACE, ("_nc_mouse_wrap() called"));
+
+    switch (sp->_mouse_type) {
+    case M_XTERM:
+	if (sp->_mouse_mask)
+	    mouse_activate(sp, FALSE);
+	break;
+#if USE_GPM_SUPPORT
+	/* GPM: pass all mouse events to next client */
+    case M_GPM:
+	if (sp->_mouse_mask)
+	    mouse_activate(sp, FALSE);
+	break;
+#endif
+#if USE_SYSMOUSE
+    case M_SYSMOUSE:
+	mouse_activate(sp, FALSE);
+	break;
+#endif
+    case M_NONE:
+	break;
+    }
+}
+
+static void
+_nc_mouse_resume(SCREEN *sp)
+/* re-connect to mouse -- called by doupdate() after shellout */
+{
+    TR(MY_TRACE, ("_nc_mouse_resume() called"));
+
+    switch (sp->_mouse_type) {
+    case M_XTERM:
+	/* xterm: re-enable reporting */
+	if (sp->_mouse_mask)
+	    mouse_activate(sp, TRUE);
+	break;
+
+#if USE_GPM_SUPPORT
+    case M_GPM:
+	/* GPM: reclaim our event set */
+	if (sp->_mouse_mask)
+	    mouse_activate(sp, TRUE);
+	break;
+#endif
+
+#if USE_SYSMOUSE
+    case M_SYSMOUSE:
+	mouse_activate(sp, TRUE);
+	break;
+#endif
+    case M_NONE:
+	break;
+    }
+}
+
+/**************************************************************************
+ *
+ * Mouse interface entry points for the API
+ *
+ **************************************************************************/
+
+static int
+_nc_getmouse(SCREEN *sp, MEVENT * aevent)
+{
+    T((T_CALLED("getmouse(%p)"), aevent));
+
+    if ((aevent != 0) && (sp != 0) && (sp->_mouse_type != M_NONE)) {
+	MEVENT *eventp = sp->_mouse_eventp;
+	/* compute the current-event pointer */
+	MEVENT *prev = PREV(eventp);
+
+	/* copy the event we find there */
+	*aevent = *prev;
+
+	TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
+			  _nc_tracemouse(sp, prev),
+			  (long) IndexEV(sp, prev)));
+
+	prev->id = INVALID_EVENT;	/* so the queue slot becomes free */
+	returnCode(OK);
+    }
+    returnCode(ERR);
+}
+
+/* grab a copy of the current mouse event */
+NCURSES_EXPORT(int)
+getmouse(MEVENT * aevent)
+{
+    return _nc_getmouse(SP, aevent);
+}
+
+static int
+_nc_ungetmouse(SCREEN *sp, MEVENT * aevent)
+{
+    int result = ERR;
+
+    T((T_CALLED("ungetmouse(%p)"), aevent));
+
+    if (aevent != 0 && sp != 0) {
+	MEVENT *eventp = sp->_mouse_eventp;
+
+	/* stick the given event in the next-free slot */
+	*eventp = *aevent;
+
+	/* bump the next-free pointer into the circular list */
+	sp->_mouse_eventp = NEXT(eventp);
+
+	/* push back the notification event on the keyboard queue */
+	result = _nc_ungetch(sp, KEY_MOUSE);
+    }
+    returnCode(result);
+}
+
+/* enqueue a synthesized mouse event to be seen by the next wgetch() */
+NCURSES_EXPORT(int)
+ungetmouse(MEVENT * aevent)
+{
+    return _nc_ungetmouse(SP, aevent);
+}
+
+NCURSES_EXPORT(mmask_t)
+mousemask(mmask_t newmask, mmask_t * oldmask)
+/* set the mouse event mask */
+{
+    mmask_t result = 0;
+
+    T((T_CALLED("mousemask(%#lx,%p)"), (unsigned long) newmask, oldmask));
+
+    if (SP != 0) {
+	if (oldmask)
+	    *oldmask = SP->_mouse_mask;
+
+	if (newmask || SP->_mouse_initialized) {
+	    _nc_mouse_init(SP);
+	    if (SP->_mouse_type != M_NONE) {
+		result = newmask &
+		    (REPORT_MOUSE_POSITION
+		     | BUTTON_ALT
+		     | BUTTON_CTRL
+		     | BUTTON_SHIFT
+		     | BUTTON_PRESSED
+		     | BUTTON_RELEASED
+		     | BUTTON_CLICKED
+		     | BUTTON_DOUBLE_CLICKED
+		     | BUTTON_TRIPLE_CLICKED);
+
+		mouse_activate(SP, (bool) (result != 0));
+
+		SP->_mouse_mask = result;
+	    }
+	}
+    }
+    returnBits(result);
+}
+
+NCURSES_EXPORT(bool)
+wenclose(const WINDOW *win, int y, int x)
+/* check to see if given window encloses given screen location */
+{
+    bool result = FALSE;
+
+    T((T_CALLED("wenclose(%p,%d,%d)"), win, y, x));
+
+    if (win != 0) {
+	y -= win->_yoffset;
+	result = ((win->_begy <= y &&
+		   win->_begx <= x &&
+		   (win->_begx + win->_maxx) >= x &&
+		   (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
+    }
+    returnBool(result);
+}
+
+NCURSES_EXPORT(int)
+mouseinterval(int maxclick)
+/* set the maximum mouse interval within which to recognize a click */
+{
+    int oldval;
+
+    T((T_CALLED("mouseinterval(%d)"), maxclick));
+
+    if (SP != 0) {
+	oldval = SP->_maxclick;
+	if (maxclick >= 0)
+	    SP->_maxclick = maxclick;
+    } else {
+	oldval = DEFAULT_MAXCLICK;
+    }
+
+    returnCode(oldval);
+}
+
+/* This may be used by other routines to ask for the existence of mouse
+   support */
+NCURSES_EXPORT(int)
+_nc_has_mouse(void)
+{
+    return (SP->_mouse_type == M_NONE ? 0 : 1);
+}
+
+NCURSES_EXPORT(bool)
+wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen)
+{
+    bool result = FALSE;
+
+    T((T_CALLED("wmouse_trafo(%p,%p,%p,%d)"), win, pY, pX, to_screen));
+
+    if (win && pY && pX) {
+	int y = *pY;
+	int x = *pX;
+
+	if (to_screen) {
+	    y += win->_begy + win->_yoffset;
+	    x += win->_begx;
+	    if (wenclose(win, y, x))
+		result = TRUE;
+	} else {
+	    if (wenclose(win, y, x)) {
+		y -= (win->_begy + win->_yoffset);
+		x -= win->_begx;
+		result = TRUE;
+	    }
+	}
+	if (result) {
+	    *pX = x;
+	    *pY = y;
+	}
+    }
+    returnBool(result);
+}
diff --git a/ncurses/base/lib_move.c b/ncurses/base/lib_move.c
new file mode 100644
index 0000000..652c44d
--- /dev/null
+++ b/ncurses/base/lib_move.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2004 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_move.c
+**
+**	The routine wmove().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_move.c,v 1.12 2004/12/04 21:50:07 tom Exp $")
+
+NCURSES_EXPORT(int)
+wmove(WINDOW *win, int y, int x)
+{
+    T((T_CALLED("wmove(%p,%d,%d)"), win, y, x));
+
+    if (LEGALYX(win, y, x)) {
+	win->_curx = (NCURSES_SIZE_T) x;
+	win->_cury = (NCURSES_SIZE_T) y;
+
+	win->_flags &= ~_WRAPPED;
+	win->_flags |= _HASMOVED;
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_mvwin.c b/ncurses/base/lib_mvwin.c
new file mode 100644
index 0000000..e4dad4a
--- /dev/null
+++ b/ncurses/base/lib_mvwin.c
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_mvwin.c
+**
+**	The routine mvwin().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_mvwin.c,v 1.14 2006/02/25 22:53:46 tom Exp $")
+
+NCURSES_EXPORT(int)
+mvwin(WINDOW *win, int by, int bx)
+{
+    T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx));
+
+    if (!win || (win->_flags & _ISPAD))
+	returnCode(ERR);
+
+    /*
+     * mvwin() should only modify the indices.  See test/demo_menus.c and
+     * test/movewindow.c for examples.
+     */
+#if 0
+    /* Copying subwindows is allowed, but it is expensive... */
+    if (win->_flags & _SUBWIN) {
+	int err = ERR;
+	WINDOW *parent = win->_parent;
+	if (parent) {		/* Now comes the complicated and costly part, you should really
+				 * try to avoid to move subwindows. Because a subwindow shares
+				 * the text buffers with its parent, one can't do a simple
+				 * memmove of the text buffers. One has to create a copy, then
+				 * to relocate the subwindow and then to do a copy.
+				 */
+	    if ((by - parent->_begy == win->_pary) &&
+		(bx - parent->_begx == win->_parx))
+		err = OK;	/* we don't actually move */
+	    else {
+		WINDOW *clone = dupwin(win);
+		if (clone) {
+		    /* now we have the clone, so relocate win */
+
+		    werase(win);	/* Erase the original place     */
+		    /* fill with parents background */
+		    wbkgrnd(win, CHREF(parent->_nc_bkgd));
+		    wsyncup(win);	/* Tell the parent(s)           */
+
+		    err = mvderwin(win,
+				   by - parent->_begy,
+				   bx - parent->_begx);
+		    if (err != ERR) {
+			err = copywin(clone, win,
+				      0, 0, 0, 0, win->_maxy, win->_maxx, 0);
+			if (ERR != err)
+			    wsyncup(win);
+		    }
+		    if (ERR == delwin(clone))
+			err = ERR;
+		}
+	    }
+	}
+	returnCode(err);
+    }
+#endif
+
+    if (by + win->_maxy > screen_lines - 1
+	|| bx + win->_maxx > screen_columns - 1
+	|| by < 0
+	|| bx < 0)
+	returnCode(ERR);
+
+    /*
+     * Whether or not the window is moved, touch the window's contents so
+     * that a following call to 'wrefresh()' will paint the window at the
+     * new location.  This ensures that if the caller has refreshed another
+     * window at the same location, that this one will be displayed.
+     */
+    win->_begy = by;
+    win->_begx = bx;
+    returnCode(touchwin(win));
+}
diff --git a/ncurses/base/lib_newterm.c b/ncurses/base/lib_newterm.c
new file mode 100644
index 0000000..05982b8
--- /dev/null
+++ b/ncurses/base/lib_newterm.c
@@ -0,0 +1,235 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_newterm.c
+**
+**	The newterm() function.
+**
+*/
+
+#include <curses.priv.h>
+
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+#include <term.h>		/* clear_screen, cup & friends, cur_term */
+#include <tic.h>
+
+MODULE_ID("$Id: lib_newterm.c,v 1.73 2008/08/16 21:20:48 Werner.Fink Exp $")
+
+#ifndef ONLCR			/* Allows compilation under the QNX 4.2 OS */
+#define ONLCR 0
+#endif
+
+/*
+ * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not
+ * restored during the curses session.  The library simulates echo in software.
+ * (The behavior is unspecified if the application enables hardware echo).
+ *
+ * The newterm function also initializes terminal settings, and since initscr
+ * is supposed to behave as if it calls newterm, we do it here.
+ */
+static NCURSES_INLINE int
+_nc_initscr(void)
+{
+    int result = ERR;
+
+    /* for extended XPG4 conformance requires cbreak() at this point */
+    /* (SVr4 curses does this anyway) */
+    if (cbreak() == OK) {
+	TTY buf;
+
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	buf.c_lflag &= ~(ECHO | ECHONL);
+	buf.c_iflag &= ~(ICRNL | INLCR | IGNCR);
+	buf.c_oflag &= ~(ONLCR);
+#elif HAVE_SGTTY_H
+	buf.sg_flags &= ~(ECHO | CRMOD);
+#else
+	memset(&buf, 0, sizeof(buf));
+#endif
+	if ((result = _nc_set_tty_mode(&buf)) == OK)
+	    cur_term->Nttyb = buf;
+    }
+    return result;
+}
+
+/*
+ * filter() has to be called before either initscr() or newterm(), so there is
+ * apparently no way to make this flag apply to some terminals and not others,
+ * aside from possibly delaying a filter() call until some terminals have been
+ * initialized.
+ */
+NCURSES_EXPORT(void)
+filter(void)
+{
+    START_TRACE();
+    T((T_CALLED("filter")));
+    _nc_prescreen.filter_mode = TRUE;
+    returnVoid;
+}
+
+#if NCURSES_EXT_FUNCS
+/*
+ * An extension, allowing the application to open a new screen without
+ * requiring it to also be filtered.
+ */
+NCURSES_EXPORT(void)
+nofilter(void)
+{
+    START_TRACE();
+    T((T_CALLED("nofilter")));
+    _nc_prescreen.filter_mode = FALSE;
+    returnVoid;
+}
+#endif
+
+NCURSES_EXPORT(SCREEN *)
+newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
+{
+    int value;
+    int errret;
+    SCREEN *current;
+    SCREEN *result = 0;
+    TERMINAL *its_term;
+
+    START_TRACE();
+    T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp));
+
+    _nc_init_pthreads();
+    _nc_lock_global(curses);
+
+    current = SP;
+    its_term = (SP ? SP->_term : 0);
+
+    /* this loads the capability entry, then sets LINES and COLS */
+    if (setupterm(name, fileno(ofp), &errret) != ERR) {
+	int slk_format = _nc_globals.slk_format;
+
+	/*
+	 * This actually allocates the screen structure, and saves the original
+	 * terminal settings.
+	 */
+	_nc_set_screen(0);
+
+	/* allow user to set maximum escape delay from the environment */
+	if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
+	    set_escdelay(value);
+	}
+
+	if (_nc_setupscreen(LINES,
+			    COLS,
+			    ofp,
+			    _nc_prescreen.filter_mode,
+			    slk_format) == ERR) {
+	    _nc_set_screen(current);
+	    result = 0;
+	} else {
+	    assert(SP != 0);
+	    /*
+	     * In setupterm() we did a set_curterm(), but it was before we set
+	     * SP.  So the "current" screen's terminal pointer was overwritten
+	     * with a different terminal.  Later, in _nc_setupscreen(), we set
+	     * SP and the terminal pointer in the new screen.
+	     *
+	     * Restore the terminal-pointer for the pre-existing screen, if
+	     * any.
+	     */
+	    if (current)
+		current->_term = its_term;
+
+	    /* if the terminal type has real soft labels, set those up */
+	    if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format))
+		_nc_slk_initialize(stdscr, COLS);
+
+	    SP->_ifd = fileno(ifp);
+	    typeahead(fileno(ifp));
+#ifdef TERMIOS
+	    SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
+			     !(cur_term->Ottyb.c_iflag & ISTRIP));
+#else
+	    SP->_use_meta = FALSE;
+#endif
+	    SP->_endwin = FALSE;
+
+	    /*
+	     * Check whether we can optimize scrolling under dumb terminals in
+	     * case we do not have any of these capabilities, scrolling
+	     * optimization will be useless.
+	     */
+	    SP->_scrolling = ((scroll_forward && scroll_reverse) ||
+			      ((parm_rindex ||
+				parm_insert_line ||
+				insert_line) &&
+			       (parm_index ||
+				parm_delete_line ||
+				delete_line)));
+
+	    baudrate();		/* sets a field in the SP structure */
+
+	    SP->_keytry = 0;
+
+	    /*
+	     * Check for mismatched graphic-rendition capabilities.  Most SVr4
+	     * terminfo trees contain entries that have rmul or rmso equated to
+	     * sgr0 (Solaris curses copes with those entries).  We do this only
+	     * for curses, since many termcap applications assume that
+	     * smso/rmso and smul/rmul are paired, and will not function
+	     * properly if we remove rmso or rmul.  Curses applications
+	     * shouldn't be looking at this detail.
+	     */
+#define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
+	    SP->_use_rmso = SGR0_TEST(exit_standout_mode);
+	    SP->_use_rmul = SGR0_TEST(exit_underline_mode);
+
+	    /* compute movement costs so we can do better move optimization */
+	    _nc_mvcur_init();
+
+	    /* initialize terminal to a sane state */
+	    _nc_screen_init();
+
+	    /* Initialize the terminal line settings. */
+	    _nc_initscr();
+
+	    _nc_signal_handler(TRUE);
+
+	    result = SP;
+	}
+    }
+    _nc_unlock_global(curses);
+    returnSP(result);
+}
diff --git a/ncurses/base/lib_newwin.c b/ncurses/base/lib_newwin.c
new file mode 100644
index 0000000..587e83a
--- /dev/null
+++ b/ncurses/base/lib_newwin.c
@@ -0,0 +1,338 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_newwin.c
+**
+**	The routines newwin(), subwin() and their dependent
+**
+*/
+
+#include <curses.priv.h>
+#include <stddef.h>
+
+MODULE_ID("$Id: lib_newwin.c,v 1.52 2008/06/07 13:58:09 tom Exp $")
+
+#define window_is(name) ((sp)->_##name == win)
+
+#if USE_REENTRANT
+#define remove_window(name) \
+		sp->_##name = 0
+#else
+#define remove_window(name) \
+		sp->_##name = 0; \
+		if (win == name) \
+		    name = 0
+#endif
+
+static void
+remove_window_from_screen(WINDOW *win)
+{
+    SCREEN *sp;
+
+    for (each_screen(sp)) {
+	if (window_is(curscr)) {
+	    remove_window(curscr);
+	    break;
+	} else if (window_is(stdscr)) {
+	    remove_window(stdscr);
+	    break;
+	} else if (window_is(newscr)) {
+	    remove_window(newscr);
+	    break;
+	}
+    }
+}
+
+NCURSES_EXPORT(int)
+_nc_freewin(WINDOW *win)
+{
+    WINDOWLIST *p, *q;
+    int i;
+    int result = ERR;
+
+    T((T_CALLED("_nc_freewin(%p)"), win));
+
+    if (win != 0) {
+	if (_nc_try_global(curses) == 0) {
+	    q = 0;
+	    for (each_window(p)) {
+		if (&(p->win) == win) {
+		    remove_window_from_screen(win);
+		    if (q == 0)
+			_nc_windows = p->next;
+		    else
+			q->next = p->next;
+
+		    if (!(win->_flags & _SUBWIN)) {
+			for (i = 0; i <= win->_maxy; i++)
+			    FreeIfNeeded(win->_line[i].text);
+		    }
+		    free(win->_line);
+		    free(p);
+
+		    result = OK;
+		    T(("...deleted win=%p", win));
+		    break;
+		}
+		q = p;
+	    }
+	    _nc_unlock_global(curses);
+	}
+    }
+    returnCode(result);
+}
+
+NCURSES_EXPORT(WINDOW *)
+newwin(int num_lines, int num_columns, int begy, int begx)
+{
+    WINDOW *win;
+    NCURSES_CH_T *ptr;
+    int i;
+
+    T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx));
+
+    if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0)
+	returnWin(0);
+
+    if (num_lines == 0)
+	num_lines = SP->_lines_avail - begy;
+    if (num_columns == 0)
+	num_columns = screen_columns - begx;
+
+    if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0)
+	returnWin(0);
+
+    for (i = 0; i < num_lines; i++) {
+	win->_line[i].text = typeCalloc(NCURSES_CH_T, (unsigned) num_columns);
+	if (win->_line[i].text == 0) {
+	    (void) _nc_freewin(win);
+	    returnWin(0);
+	}
+	for (ptr = win->_line[i].text;
+	     ptr < win->_line[i].text + num_columns;
+	     ptr++)
+	    SetChar(*ptr, BLANK_TEXT, BLANK_ATTR);
+    }
+
+    returnWin(win);
+}
+
+NCURSES_EXPORT(WINDOW *)
+derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
+{
+    WINDOW *win;
+    int i;
+    int flags = _SUBWIN;
+
+    T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns,
+       begy, begx));
+
+    /*
+     * make sure window fits inside the original one
+     */
+    if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0)
+	returnWin(0);
+    if (begy + num_lines > orig->_maxy + 1
+	|| begx + num_columns > orig->_maxx + 1)
+	returnWin(0);
+
+    if (num_lines == 0)
+	num_lines = orig->_maxy + 1 - begy;
+
+    if (num_columns == 0)
+	num_columns = orig->_maxx + 1 - begx;
+
+    if (orig->_flags & _ISPAD)
+	flags |= _ISPAD;
+
+    if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
+			   orig->_begx + begx, flags)) == 0)
+	returnWin(0);
+
+    win->_pary = begy;
+    win->_parx = begx;
+    WINDOW_ATTRS(win) = WINDOW_ATTRS(orig);
+    win->_nc_bkgd = orig->_nc_bkgd;
+
+    for (i = 0; i < num_lines; i++)
+	win->_line[i].text = &orig->_line[begy++].text[begx];
+
+    win->_parent = orig;
+
+    returnWin(win);
+}
+
+NCURSES_EXPORT(WINDOW *)
+subwin(WINDOW *w, int l, int c, int y, int x)
+{
+    T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), w, l, c, y, x));
+    T(("parent has begy = %ld, begx = %ld", (long) w->_begy, (long) w->_begx));
+
+    returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx));
+}
+
+static bool
+dimension_limit(int value)
+{
+    NCURSES_SIZE_T test = value;
+    return (test == value && value > 0);
+}
+
+NCURSES_EXPORT(WINDOW *)
+_nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
+{
+    int i;
+    WINDOWLIST *wp;
+    WINDOW *win;
+    bool is_pad = (flags & _ISPAD);
+
+    T((T_CALLED("_nc_makenew(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx));
+
+    if (SP == 0)
+	returnWin(0);
+
+    if (!dimension_limit(num_lines) || !dimension_limit(num_columns))
+	returnWin(0);
+
+    if ((wp = typeCalloc(WINDOWLIST, 1)) == 0)
+	returnWin(0);
+
+    win = &(wp->win);
+
+    if ((win->_line = typeCalloc(struct ldat, ((unsigned) num_lines))) == 0) {
+	free(win);
+	returnWin(0);
+    }
+
+    _nc_lock_global(curses);
+
+    win->_curx = 0;
+    win->_cury = 0;
+    win->_maxy = num_lines - 1;
+    win->_maxx = num_columns - 1;
+    win->_begy = begy;
+    win->_begx = begx;
+    win->_yoffset = SP->_topstolen;
+
+    win->_flags = flags;
+    WINDOW_ATTRS(win) = A_NORMAL;
+    SetChar(win->_nc_bkgd, BLANK_TEXT, BLANK_ATTR);
+
+    win->_clear = is_pad ? FALSE : (num_lines == screen_lines
+				    && num_columns == screen_columns);
+    win->_idlok = FALSE;
+    win->_idcok = TRUE;
+    win->_scroll = FALSE;
+    win->_leaveok = FALSE;
+    win->_use_keypad = FALSE;
+    win->_delay = -1;
+    win->_immed = FALSE;
+    win->_sync = 0;
+    win->_parx = -1;
+    win->_pary = -1;
+    win->_parent = 0;
+
+    win->_regtop = 0;
+    win->_regbottom = num_lines - 1;
+
+    win->_pad._pad_y = -1;
+    win->_pad._pad_x = -1;
+    win->_pad._pad_top = -1;
+    win->_pad._pad_bottom = -1;
+    win->_pad._pad_left = -1;
+    win->_pad._pad_right = -1;
+
+    for (i = 0; i < num_lines; i++) {
+	/*
+	 * This used to do
+	 *
+	 * win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE;
+	 *
+	 * which marks the whole window unchanged.  That's how
+	 * SVr1 curses did it, but SVr4 curses marks the whole new
+	 * window changed.
+	 *
+	 * With the old SVr1-like code, say you have stdscr full of
+	 * characters, then create a new window with newwin(),
+	 * then do a printw(win, "foo        ");, the trailing spaces are
+	 * completely ignored by the following refreshes.  So, you
+	 * get "foojunkjunk" on the screen instead of "foo        " as
+	 * you actually intended.
+	 *
+	 * SVr4 doesn't do this.  Instead the spaces are actually written.
+	 * So that's how we want ncurses to behave.
+	 */
+	win->_line[i].firstchar = 0;
+	win->_line[i].lastchar = num_columns - 1;
+
+	if_USE_SCROLL_HINTS(win->_line[i].oldindex = i);
+    }
+
+    if (!is_pad && (begx + num_columns == screen_columns)) {
+	win->_flags |= _ENDLINE;
+
+	if (begx == 0 && num_lines == screen_lines && begy == 0)
+	    win->_flags |= _FULLWIN;
+
+	if (begy + num_lines == screen_lines)
+	    win->_flags |= _SCROLLWIN;
+    }
+
+    wp->next = _nc_windows;
+    wp->screen = SP;
+    _nc_windows = wp;
+
+    T((T_CREATE("window %p"), win));
+
+    _nc_unlock_global(curses);
+    returnWin(win);
+}
+
+/*
+ * wgetch() and other functions with a WINDOW* parameter may use a SCREEN*
+ * internally, and it is useful to allow those to be invoked without switching
+ * SCREEN's, e.g., for multi-threaded applications.
+ */
+NCURSES_EXPORT(SCREEN *)
+_nc_screen_of(WINDOW *win)
+{
+    SCREEN *sp = 0;
+
+    if (win != 0) {
+	WINDOWLIST *wp = (WINDOWLIST *) win;
+	sp = wp->screen;
+    }
+    return (sp);
+}
diff --git a/ncurses/base/lib_nl.c b/ncurses/base/lib_nl.c
new file mode 100644
index 0000000..32515da
--- /dev/null
+++ b/ncurses/base/lib_nl.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	nl.c
+ *
+ *	Routines:
+ *		nl()
+ *		nonl()
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_nl.c,v 1.8 2000/12/10 02:43:27 tom Exp $")
+
+#ifdef __EMX__
+#include <io.h>
+#endif
+
+NCURSES_EXPORT(int)
+nl(void)
+{
+    T((T_CALLED("nl()")));
+
+    SP->_nl = TRUE;
+
+#ifdef __EMX__
+    _nc_flush();
+    _fsetmode(NC_OUTPUT, "t");
+#endif
+
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+nonl(void)
+{
+    T((T_CALLED("nonl()")));
+
+    SP->_nl = FALSE;
+
+#ifdef __EMX__
+    _nc_flush();
+    _fsetmode(NC_OUTPUT, "b");
+#endif
+
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_overlay.c b/ncurses/base/lib_overlay.c
new file mode 100644
index 0000000..669e8e7
--- /dev/null
+++ b/ncurses/base/lib_overlay.c
@@ -0,0 +1,206 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_overlay.c
+**
+**	The routines overlay(), copywin(), and overwrite().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_overlay.c,v 1.27 2008/06/07 23:30:34 tom Exp $")
+
+static int
+overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
+{
+    int rc = ERR;
+    int sx1, sy1, sx2, sy2;
+    int dx1, dy1, dx2, dy2;
+    int sminrow, smincol;
+    int dminrow, dmincol;
+    int dmaxrow, dmaxcol;
+
+    T((T_CALLED("overlap(%p,%p,%d)"), src, dst, flag));
+
+    if (src != 0 && dst != 0) {
+	_nc_lock_global(curses);
+
+	T(("src : begy %ld, begx %ld, maxy %ld, maxx %ld",
+	   (long) src->_begy,
+	   (long) src->_begx,
+	   (long) src->_maxy,
+	   (long) src->_maxx));
+	T(("dst : begy %ld, begx %ld, maxy %ld, maxx %ld",
+	   (long) dst->_begy,
+	   (long) dst->_begx,
+	   (long) dst->_maxy,
+	   (long) dst->_maxx));
+
+	sx1 = src->_begx;
+	sy1 = src->_begy;
+	sx2 = sx1 + src->_maxx;
+	sy2 = sy1 + src->_maxy;
+
+	dx1 = dst->_begx;
+	dy1 = dst->_begy;
+	dx2 = dx1 + dst->_maxx;
+	dy2 = dy1 + dst->_maxy;
+
+	if (dx2 >= sx1 && dx1 <= sx2 && dy2 >= sy1 && dy1 <= sy2) {
+	    sminrow = max(sy1, dy1) - sy1;
+	    smincol = max(sx1, dx1) - sx1;
+	    dminrow = max(sy1, dy1) - dy1;
+	    dmincol = max(sx1, dx1) - dx1;
+	    dmaxrow = min(sy2, dy2) - dy1;
+	    dmaxcol = min(sx2, dx2) - dx1;
+
+	    rc = copywin(src, dst,
+			 sminrow, smincol,
+			 dminrow, dmincol,
+			 dmaxrow, dmaxcol,
+			 flag);
+	}
+	_nc_unlock_global(curses);
+    }
+    returnCode(rc);
+}
+
+/*
+**
+**	overlay(win1, win2)
+**
+**
+**	overlay() writes the overlapping area of win1 behind win2
+**	on win2 non-destructively.
+**
+**/
+
+NCURSES_EXPORT(int)
+overlay(const WINDOW *win1, WINDOW *win2)
+{
+    T((T_CALLED("overlay(%p,%p)"), win1, win2));
+    returnCode(overlap(win1, win2, TRUE));
+}
+
+/*
+**
+**	overwrite(win1, win2)
+**
+**
+**	overwrite() writes the overlapping area of win1 behind win2
+**	on win2 destructively.
+**
+**/
+
+NCURSES_EXPORT(int)
+overwrite(const WINDOW *win1, WINDOW *win2)
+{
+    T((T_CALLED("overwrite(%p,%p)"), win1, win2));
+    returnCode(overlap(win1, win2, FALSE));
+}
+
+NCURSES_EXPORT(int)
+copywin(const WINDOW *src, WINDOW *dst,
+	int sminrow, int smincol,
+	int dminrow, int dmincol,
+	int dmaxrow, int dmaxcol,
+	int over)
+{
+    int rc = ERR;
+    int sx, sy, dx, dy;
+    bool touched;
+    attr_t bk;
+    attr_t mask;
+
+    T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
+       src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
+
+    if (src && dst) {
+	_nc_lock_global(curses);
+
+	bk = AttrOf(dst->_nc_bkgd);
+	mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0);
+
+	/* make sure rectangle exists in source */
+	if ((sminrow + dmaxrow - dminrow) <= (src->_maxy + 1) &&
+	    (smincol + dmaxcol - dmincol) <= (src->_maxx + 1)) {
+
+	    T(("rectangle exists in source"));
+
+	    /* make sure rectangle fits in destination */
+	    if (dmaxrow <= dst->_maxy && dmaxcol <= dst->_maxx) {
+
+		T(("rectangle fits in destination"));
+
+		for (dy = dminrow, sy = sminrow;
+		     dy <= dmaxrow;
+		     sy++, dy++) {
+
+		    touched = FALSE;
+		    for (dx = dmincol, sx = smincol;
+			 dx <= dmaxcol;
+			 sx++, dx++) {
+			if (over) {
+			    if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
+				(!CharEq(dst->_line[dy].text[dx],
+					 src->_line[sy].text[sx]))) {
+				dst->_line[dy].text[dx] =
+				    src->_line[sy].text[sx];
+				SetAttr(dst->_line[dy].text[dx],
+					((AttrOf(src->_line[sy].text[sx]) &
+					  mask) | bk));
+				touched = TRUE;
+			    }
+			} else {
+			    if (!CharEq(dst->_line[dy].text[dx],
+					src->_line[sy].text[sx])) {
+				dst->_line[dy].text[dx] =
+				    src->_line[sy].text[sx];
+				touched = TRUE;
+			    }
+			}
+		    }
+		    if (touched) {
+			touchline(dst, dminrow, (dmaxrow - dminrow + 1));
+		    }
+		}
+		T(("finished copywin"));
+		rc = OK;
+	    }
+	}
+	_nc_unlock_global(curses);
+    }
+    returnCode(rc);
+}
diff --git a/ncurses/base/lib_pad.c b/ncurses/base/lib_pad.c
new file mode 100644
index 0000000..6cad9c5
--- /dev/null
+++ b/ncurses/base/lib_pad.c
@@ -0,0 +1,322 @@
+/****************************************************************************
+ * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ * lib_pad.c
+ * newpad	-- create a new pad
+ * pnoutrefresh -- refresh a pad, no update
+ * pechochar	-- add a char to a pad and refresh
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_pad.c,v 1.41 2006/10/14 20:47:13 tom Exp $")
+
+NCURSES_EXPORT(WINDOW *)
+newpad(int l, int c)
+{
+    WINDOW *win;
+    NCURSES_CH_T *ptr;
+    int i;
+
+    T((T_CALLED("newpad(%d, %d)"), l, c));
+
+    if (l <= 0 || c <= 0)
+	returnWin(0);
+
+    if ((win = _nc_makenew(l, c, 0, 0, _ISPAD)) == NULL)
+	returnWin(0);
+
+    for (i = 0; i < l; i++) {
+	if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX);
+	if ((win->_line[i].text = typeCalloc(NCURSES_CH_T, ((size_t) c))) == 0) {
+	    (void) _nc_freewin(win);
+	    returnWin(0);
+	}
+	for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ptr++)
+	    SetChar(*ptr, BLANK_TEXT, BLANK_ATTR);
+    }
+
+    returnWin(win);
+}
+
+NCURSES_EXPORT(WINDOW *)
+subpad(WINDOW *orig, int l, int c, int begy, int begx)
+{
+    WINDOW *win = (WINDOW *) 0;
+
+    T((T_CALLED("subpad(%d, %d)"), l, c));
+
+    if (orig) {
+	if (!(orig->_flags & _ISPAD)
+	    || ((win = derwin(orig, l, c, begy, begx)) == NULL))
+	    returnWin(0);
+    }
+    returnWin(win);
+}
+
+NCURSES_EXPORT(int)
+prefresh(WINDOW *win,
+	 int pminrow,
+	 int pmincol,
+	 int sminrow,
+	 int smincol,
+	 int smaxrow,
+	 int smaxcol)
+{
+    T((T_CALLED("prefresh()")));
+    if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow,
+		     smaxcol) != ERR
+	&& doupdate() != ERR) {
+	returnCode(OK);
+    }
+    returnCode(ERR);
+}
+
+NCURSES_EXPORT(int)
+pnoutrefresh(WINDOW *win,
+	     int pminrow,
+	     int pmincol,
+	     int sminrow,
+	     int smincol,
+	     int smaxrow,
+	     int smaxcol)
+{
+    NCURSES_SIZE_T i, j;
+    NCURSES_SIZE_T m, n;
+    NCURSES_SIZE_T pmaxrow;
+    NCURSES_SIZE_T pmaxcol;
+
+#if USE_SCROLL_HINTS
+    const int my_len = 2;	/* parameterize the threshold for hardscroll */
+    NCURSES_SIZE_T displaced;
+    bool wide;
+#endif
+
+    T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"),
+       win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol));
+
+    if (win == 0)
+	returnCode(ERR);
+
+    if (!(win->_flags & _ISPAD))
+	returnCode(ERR);
+
+    /* negative values are interpreted as zero */
+    if (pminrow < 0)
+	pminrow = 0;
+    if (pmincol < 0)
+	pmincol = 0;
+    if (sminrow < 0)
+	sminrow = 0;
+    if (smincol < 0)
+	smincol = 0;
+
+    pmaxrow = pminrow + smaxrow - sminrow;
+    pmaxcol = pmincol + smaxcol - smincol;
+
+    T((" pminrow + smaxrow - sminrow %ld, win->_maxy %ld",
+       (long) pmaxrow, (long) win->_maxy));
+    T((" pmincol + smaxcol - smincol %ld, win->_maxx %ld",
+       (long) pmaxcol, (long) win->_maxx));
+
+    /*
+     * Trim the caller's screen size back to the actual limits.
+     */
+    if (pmaxrow > win->_maxy) {
+	smaxrow -= (pmaxrow - win->_maxy);
+	pmaxrow = pminrow + smaxrow - sminrow;
+    }
+    if (pmaxcol > win->_maxx) {
+	smaxcol -= (pmaxcol - win->_maxx);
+	pmaxcol = pmincol + smaxcol - smincol;
+    }
+
+    if (smaxrow >= screen_lines
+	|| smaxcol >= screen_columns
+	|| sminrow > smaxrow
+	|| smincol > smaxcol)
+	returnCode(ERR);
+
+    T(("pad being refreshed"));
+
+#if USE_SCROLL_HINTS
+    if (win->_pad._pad_y >= 0) {
+	displaced = pminrow - win->_pad._pad_y
+	    - (sminrow - win->_pad._pad_top);
+	T(("pad being shifted by %d line(s)", displaced));
+    } else
+	displaced = 0;
+#endif
+
+    /*
+     * For pure efficiency, we'd want to transfer scrolling information
+     * from the pad to newscr whenever the window is wide enough that
+     * its update will dominate the cost of the update for the horizontal
+     * band of newscr that it occupies.  Unfortunately, this threshold
+     * tends to be complex to estimate, and in any case scrolling the
+     * whole band and rewriting the parts outside win's image would look
+     * really ugly.  So.  What we do is consider the pad "wide" if it
+     * either (a) occupies the whole width of newscr, or (b) occupies
+     * all but at most one column on either vertical edge of the screen
+     * (this caters to fussy people who put boxes around full-screen
+     * windows).  Note that changing this formula will not break any code,
+     * merely change the costs of various update cases.
+     */
+#if USE_SCROLL_HINTS
+    wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len));
+#endif
+
+    for (i = pminrow, m = sminrow + win->_yoffset;
+	 i <= pmaxrow && m <= newscr->_maxy;
+	 i++, m++) {
+	register struct ldat *nline = &newscr->_line[m];
+	register struct ldat *oline = &win->_line[i];
+	for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) {
+	    NCURSES_CH_T ch = oline->text[j];
+#if USE_WIDEC_SUPPORT
+	    /*
+	     * Special case for leftmost character of the displayed area.
+	     * Only half of a double-width character may be visible.
+	     */
+	    if (j == pmincol
+		&& j > 0
+		&& isWidecExt(ch)) {
+		SetChar(ch, L(' '), AttrOf(oline->text[j - 1]));
+	    }
+#endif
+	    if (!CharEq(ch, nline->text[n])) {
+		nline->text[n] = ch;
+		CHANGED_CELL(nline, n);
+	    }
+	}
+
+#if USE_SCROLL_HINTS
+	if (wide) {
+	    int nind = m + displaced;
+	    if (oline->oldindex < 0
+		|| nind < sminrow
+		|| nind > smaxrow) {
+		nind = _NEWINDEX;
+	    } else if (displaced) {
+		register struct ldat *pline = &curscr->_line[nind];
+		for (j = 0; j <= my_len; j++) {
+		    int k = newscr->_maxx - j;
+		    if (pline->text[j] != nline->text[j]
+			|| pline->text[k] != nline->text[k]) {
+			nind = _NEWINDEX;
+			break;
+		    }
+		}
+	    }
+
+	    nline->oldindex = nind;
+	}
+#endif /* USE_SCROLL_HINTS */
+	oline->firstchar = oline->lastchar = _NOCHANGE;
+	if_USE_SCROLL_HINTS(oline->oldindex = i);
+    }
+
+    /*
+     * Clean up debris from scrolling or resizing the pad, so we do not
+     * accidentally pick up the index value during the next call to this
+     * procedure.  The only rows that should have an index value are those
+     * that are displayed during this cycle.
+     */
+#if USE_SCROLL_HINTS
+    for (i = pminrow - 1; (i >= 0) && (win->_line[i].oldindex >= 0); i--)
+	win->_line[i].oldindex = _NEWINDEX;
+    for (i = pmaxrow + 1; (i <= win->_maxy)
+	 && (win->_line[i].oldindex >= 0); i++)
+	win->_line[i].oldindex = _NEWINDEX;
+#endif
+
+    win->_begx = smincol;
+    win->_begy = sminrow;
+
+    if (win->_clear) {
+	win->_clear = FALSE;
+	newscr->_clear = TRUE;
+    }
+
+    /*
+     * Use the pad's current position, if it will be visible.
+     * If not, don't do anything; it's not an error.
+     */
+    if (win->_leaveok == FALSE
+	&& win->_cury >= pminrow
+	&& win->_curx >= pmincol
+	&& win->_cury <= pmaxrow
+	&& win->_curx <= pmaxcol) {
+	newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset;
+	newscr->_curx = win->_curx - pmincol + win->_begx;
+    }
+    newscr->_leaveok = win->_leaveok;
+    win->_flags &= ~_HASMOVED;
+
+    /*
+     * Update our cache of the line-numbers that we displayed from the pad.
+     * We will use this on subsequent calls to this function to derive
+     * values to stuff into 'oldindex[]' -- for scrolling optimization.
+     */
+    win->_pad._pad_y = pminrow;
+    win->_pad._pad_x = pmincol;
+    win->_pad._pad_top = sminrow;
+    win->_pad._pad_left = smincol;
+    win->_pad._pad_bottom = smaxrow;
+    win->_pad._pad_right = smaxcol;
+
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+pechochar(WINDOW *pad, const chtype ch)
+{
+    T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch)));
+
+    if (pad == 0)
+	returnCode(ERR);
+
+    if (!(pad->_flags & _ISPAD))
+	returnCode(wechochar(pad, ch));
+
+    waddch(pad, ch);
+    prefresh(pad, pad->_pad._pad_y,
+	     pad->_pad._pad_x,
+	     pad->_pad._pad_top,
+	     pad->_pad._pad_left,
+	     pad->_pad._pad_bottom,
+	     pad->_pad._pad_right);
+
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_printw.c b/ncurses/base/lib_printw.c
new file mode 100644
index 0000000..62ae921
--- /dev/null
+++ b/ncurses/base/lib_printw.c
@@ -0,0 +1,138 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ ****************************************************************************/
+
+/*
+**	lib_printw.c
+**
+**	The routines printw(), wprintw() and friends.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_printw.c,v 1.18 2006/12/17 19:21:39 tom Exp $")
+
+NCURSES_EXPORT(int)
+printw(const char *fmt,...)
+{
+    va_list argp;
+    int code;
+
+#ifdef TRACE
+    va_start(argp, fmt);
+    T((T_CALLED("printw(%s%s)"),
+       _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+    va_end(argp);
+#endif
+
+    va_start(argp, fmt);
+    code = vwprintw(stdscr, fmt, argp);
+    va_end(argp);
+
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wprintw(WINDOW *win, const char *fmt,...)
+{
+    va_list argp;
+    int code;
+
+#ifdef TRACE
+    va_start(argp, fmt);
+    T((T_CALLED("wprintw(%p,%s%s)"),
+       win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+    va_end(argp);
+#endif
+
+    va_start(argp, fmt);
+    code = vwprintw(win, fmt, argp);
+    va_end(argp);
+
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+mvprintw(int y, int x, const char *fmt,...)
+{
+    va_list argp;
+    int code;
+
+#ifdef TRACE
+    va_start(argp, fmt);
+    T((T_CALLED("mvprintw(%d,%d,%s%s)"),
+       y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+    va_end(argp);
+#endif
+
+    if ((code = move(y, x)) != ERR) {
+	va_start(argp, fmt);
+	code = vwprintw(stdscr, fmt, argp);
+	va_end(argp);
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+mvwprintw(WINDOW *win, int y, int x, const char *fmt,...)
+{
+    va_list argp;
+    int code;
+
+#ifdef TRACE
+    va_start(argp, fmt);
+    T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
+       y, x, win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
+    va_end(argp);
+#endif
+
+    if ((code = wmove(win, y, x)) != ERR) {
+	va_start(argp, fmt);
+	code = vwprintw(win, fmt, argp);
+	va_end(argp);
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+vwprintw(WINDOW *win, const char *fmt, va_list argp)
+{
+    char *buf;
+    int code = ERR;
+
+    T((T_CALLED("vwprintw(%p,%s,va_list)"), win, _nc_visbuf(fmt)));
+
+    if ((buf = _nc_printf_string(fmt, argp)) != 0) {
+	code = waddstr(win, buf);
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_redrawln.c b/ncurses/base/lib_redrawln.c
new file mode 100644
index 0000000..6b0905f
--- /dev/null
+++ b/ncurses/base/lib_redrawln.c
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ ****************************************************************************/
+
+/*
+ *	lib_redrawln.c
+ *
+ *	The routine wredrawln().
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_redrawln.c,v 1.12 2007/10/13 20:08:56 tom Exp $")
+
+NCURSES_EXPORT(int)
+wredrawln(WINDOW *win, int beg, int num)
+{
+    int i;
+    int end;
+    size_t len;
+
+    T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num));
+
+    if (win == 0)
+	returnCode(ERR);
+
+    if (beg < 0)
+	beg = 0;
+
+    if (touchline(win, beg, num) == ERR)
+	returnCode(ERR);
+
+    if (touchline(curscr, beg + win->_begy, num) == ERR)
+	returnCode(ERR);
+
+    end = beg + num;
+    if (end > curscr->_maxy + 1)
+	end = curscr->_maxy + 1;
+    if (end > win->_maxy + 1)
+	end = win->_maxy + 1;
+
+    len = (win->_maxx + 1);
+    if (len > (size_t) (curscr->_maxx + 1))
+	len = (size_t) (curscr->_maxx + 1);
+    len *= sizeof(curscr->_line[0].text[0]);
+
+    for (i = beg; i < end; i++) {
+	int crow = i + win->_begy;
+
+	memset(curscr->_line[crow].text + win->_begx, 0, len);
+	_nc_make_oldhash(crow);
+    }
+
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_refresh.c b/ncurses/base/lib_refresh.c
new file mode 100644
index 0000000..2a9cafb
--- /dev/null
+++ b/ncurses/base/lib_refresh.c
@@ -0,0 +1,288 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	lib_refresh.c
+ *
+ *	The routines wrefresh() and wnoutrefresh().
+ *
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_refresh.c,v 1.41 2007/09/29 20:39:34 tom Exp $")
+
+NCURSES_EXPORT(int)
+wrefresh(WINDOW *win)
+{
+    int code;
+
+    T((T_CALLED("wrefresh(%p)"), win));
+
+    if (win == 0) {
+	code = ERR;
+    } else if (win == curscr) {
+	curscr->_clear = TRUE;
+	code = doupdate();
+    } else if ((code = wnoutrefresh(win)) == OK) {
+	if (win->_clear)
+	    newscr->_clear = TRUE;
+	code = doupdate();
+	/*
+	 * Reset the clearok() flag in case it was set for the special
+	 * case in hardscroll.c (if we don't reset it here, we'll get 2
+	 * refreshes because the flag is copied from stdscr to newscr).
+	 * Resetting the flag shouldn't do any harm, anyway.
+	 */
+	win->_clear = FALSE;
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wnoutrefresh(WINDOW *win)
+{
+    NCURSES_SIZE_T limit_x;
+    NCURSES_SIZE_T src_row, src_col;
+    NCURSES_SIZE_T begx;
+    NCURSES_SIZE_T begy;
+    NCURSES_SIZE_T dst_row, dst_col;
+#if USE_SCROLL_HINTS
+    bool wide;
+#endif
+
+    T((T_CALLED("wnoutrefresh(%p)"), win));
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_UPDATE)) {
+	_tracedump("...win", win);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    /*
+     * This function will break badly if we try to refresh a pad.
+     */
+    if ((win == 0)
+	|| (win->_flags & _ISPAD))
+	returnCode(ERR);
+
+    /* put them here so "win == 0" won't break our code */
+    begx = win->_begx;
+    begy = win->_begy;
+
+    newscr->_nc_bkgd = win->_nc_bkgd;
+    WINDOW_ATTRS(newscr) = WINDOW_ATTRS(win);
+
+    /* merge in change information from all subwindows of this window */
+    wsyncdown(win);
+
+#if USE_SCROLL_HINTS
+    /*
+     * For pure efficiency, we'd want to transfer scrolling information
+     * from the window to newscr whenever the window is wide enough that
+     * its update will dominate the cost of the update for the horizontal
+     * band of newscr that it occupies.  Unfortunately, this threshold
+     * tends to be complex to estimate, and in any case scrolling the
+     * whole band and rewriting the parts outside win's image would look
+     * really ugly.  So.  What we do is consider the window "wide" if it
+     * either (a) occupies the whole width of newscr, or (b) occupies
+     * all but at most one column on either vertical edge of the screen
+     * (this caters to fussy people who put boxes around full-screen
+     * windows).  Note that changing this formula will not break any code,
+     * merely change the costs of various update cases.
+     */
+    wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
+#endif
+
+    win->_flags &= ~_HASMOVED;
+
+    /*
+     * Microtweaking alert!  This double loop is one of the genuine
+     * hot spots in the code.  Even gcc doesn't seem to do enough
+     * common-subexpression chunking to make it really tense,
+     * so we'll force the issue.
+     */
+
+    /* limit(dst_col) */
+    limit_x = win->_maxx;
+    /* limit(src_col) */
+    if (limit_x > newscr->_maxx - begx)
+	limit_x = newscr->_maxx - begx;
+
+    for (src_row = 0, dst_row = begy + win->_yoffset;
+	 src_row <= win->_maxy && dst_row <= newscr->_maxy;
+	 src_row++, dst_row++) {
+	register struct ldat *nline = &newscr->_line[dst_row];
+	register struct ldat *oline = &win->_line[src_row];
+
+	if (oline->firstchar != _NOCHANGE) {
+	    int last_src = oline->lastchar;
+
+	    if (last_src > limit_x)
+		last_src = limit_x;
+
+	    src_col = oline->firstchar;
+	    dst_col = src_col + begx;
+
+	    if_WIDEC({
+		register int j;
+
+		/*
+		 * Ensure that we will copy complete multi-column characters
+		 * on the left-boundary.
+		 */
+		if (isWidecExt(oline->text[src_col])) {
+		    j = 1 + dst_col - WidecExt(oline->text[src_col]);
+		    if (j < 0)
+			j = 0;
+		    if (dst_col > j) {
+			src_col -= (dst_col - j);
+			dst_col = j;
+		    }
+		}
+
+		/*
+		 * Ensure that we will copy complete multi-column characters
+		 * on the right-boundary.
+		 */
+		j = last_src;
+		if (WidecExt(oline->text[j])) {
+		    ++j;
+		    while (j <= limit_x) {
+			if (isWidecBase(oline->text[j])) {
+			    break;
+			} else {
+			    last_src = j;
+			}
+			++j;
+		    }
+		}
+	    });
+
+	    if_WIDEC({
+		static cchar_t blank = BLANK;
+		int last_dst = begx + ((last_src < win->_maxx)
+				       ? last_src
+				       : win->_maxx);
+		int fix_left = dst_col;
+		int fix_right = last_dst;
+		register int j;
+
+		/*
+		 * Check for boundary cases where we may overwrite part of a
+		 * multi-column character.  For those, wipe the remainder of
+		 * the character to blanks.
+		 */
+		j = dst_col;
+		if (isWidecExt(nline->text[j])) {
+		    /*
+		     * On the left, we only care about multi-column characters
+		     * that extend into the changed region.
+		     */
+		    fix_left = 1 + j - WidecExt(nline->text[j]);
+		    if (fix_left < 0)
+			fix_left = 0;	/* only if cell is corrupt */
+		}
+
+		j = last_dst;
+		if (WidecExt(nline->text[j]) != 0) {
+		    /*
+		     * On the right, any multi-column character is a problem,
+		     * unless it happens to be contained in the change, and
+		     * ending at the right boundary of the change.  The
+		     * computation for 'fix_left' accounts for the left-side of
+		     * this character.  Find the end of the character.
+		     */
+		    ++j;
+		    while (j <= newscr->_maxx && isWidecExt(nline->text[j])) {
+			fix_right = j++;
+		    }
+		}
+
+		/*
+		 * The analysis is simpler if we do the clearing afterwards.
+		 * Do that now.
+		 */
+		if (fix_left < dst_col || fix_right > last_dst) {
+		    for (j = fix_left; j <= fix_right; ++j) {
+			nline->text[j] = blank;
+			CHANGED_CELL(nline, j);
+		    }
+		}
+	    });
+
+	    /*
+	     * Copy the changed text.
+	     */
+	    for (; src_col <= last_src; src_col++, dst_col++) {
+		if (!CharEq(oline->text[src_col], nline->text[dst_col])) {
+		    nline->text[dst_col] = oline->text[src_col];
+		    CHANGED_CELL(nline, dst_col);
+		}
+	    }
+
+	}
+#if USE_SCROLL_HINTS
+	if (wide) {
+	    int oind = oline->oldindex;
+
+	    nline->oldindex = ((oind == _NEWINDEX)
+			       ? _NEWINDEX
+			       : (begy + oind + win->_yoffset));
+	}
+#endif /* USE_SCROLL_HINTS */
+
+	oline->firstchar = oline->lastchar = _NOCHANGE;
+	if_USE_SCROLL_HINTS(oline->oldindex = src_row);
+    }
+
+    if (win->_clear) {
+	win->_clear = FALSE;
+	newscr->_clear = TRUE;
+    }
+
+    if (!win->_leaveok) {
+	newscr->_cury = win->_cury + win->_begy + win->_yoffset;
+	newscr->_curx = win->_curx + win->_begx;
+    }
+    newscr->_leaveok = win->_leaveok;
+
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_UPDATE)) {
+	_tracedump("newscr", newscr);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_restart.c b/ncurses/base/lib_restart.c
new file mode 100644
index 0000000..da770d4
--- /dev/null
+++ b/ncurses/base/lib_restart.c
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ * Terminfo-only terminal setup routines:
+ *
+ *		int restartterm(const char *, int, int *)
+ */
+
+#include <curses.priv.h>
+
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+#include <term.h>		/* lines, columns, cur_term */
+
+MODULE_ID("$Id: lib_restart.c,v 1.10 2008/06/21 17:31:22 tom Exp $")
+
+NCURSES_EXPORT(int)
+restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
+{
+    int result;
+
+    T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret));
+
+    if (setupterm(termp, filenum, errret) != OK) {
+	result = ERR;
+    } else if (SP != 0) {
+	int saveecho = SP->_echo;
+	int savecbreak = SP->_cbreak;
+	int saveraw = SP->_raw;
+	int savenl = SP->_nl;
+
+	if (saveecho)
+	    echo();
+	else
+	    noecho();
+
+	if (savecbreak) {
+	    cbreak();
+	    noraw();
+	} else if (saveraw) {
+	    nocbreak();
+	    raw();
+	} else {
+	    nocbreak();
+	    noraw();
+	}
+	if (savenl)
+	    nl();
+	else
+	    nonl();
+
+	reset_prog_mode();
+
+#if USE_SIZECHANGE
+	_nc_update_screensize(SP);
+#endif
+
+	result = OK;
+    } else {
+	result = ERR;
+    }
+    returnCode(result);
+}
diff --git a/ncurses/base/lib_scanw.c b/ncurses/base/lib_scanw.c
new file mode 100644
index 0000000..b8a5a22
--- /dev/null
+++ b/ncurses/base/lib_scanw.c
@@ -0,0 +1,106 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_scanw.c
+**
+**	The routines scanw(), wscanw() and friends.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scanw.c,v 1.11 2001/06/30 23:39:41 tom Exp $")
+
+NCURSES_EXPORT(int)
+vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp)
+{
+    char buf[BUFSIZ];
+
+    if (wgetnstr(win, buf, sizeof(buf) - 1) == ERR)
+	return (ERR);
+
+    return (vsscanf(buf, fmt, argp));
+}
+
+NCURSES_EXPORT(int)
+scanw(NCURSES_CONST char *fmt,...)
+{
+    int code;
+    va_list ap;
+
+    T(("scanw(\"%s\",...) called", fmt));
+
+    va_start(ap, fmt);
+    code = vwscanw(stdscr, fmt, ap);
+    va_end(ap);
+    return (code);
+}
+
+NCURSES_EXPORT(int)
+wscanw(WINDOW *win, NCURSES_CONST char *fmt,...)
+{
+    int code;
+    va_list ap;
+
+    T(("wscanw(%p,\"%s\",...) called", win, fmt));
+
+    va_start(ap, fmt);
+    code = vwscanw(win, fmt, ap);
+    va_end(ap);
+    return (code);
+}
+
+NCURSES_EXPORT(int)
+mvscanw(int y, int x, NCURSES_CONST char *fmt,...)
+{
+    int code;
+    va_list ap;
+
+    va_start(ap, fmt);
+    code = (move(y, x) == OK) ? vwscanw(stdscr, fmt, ap) : ERR;
+    va_end(ap);
+    return (code);
+}
+
+NCURSES_EXPORT(int)
+mvwscanw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt,...)
+{
+    int code;
+    va_list ap;
+
+    va_start(ap, fmt);
+    code = (wmove(win, y, x) == OK) ? vwscanw(win, fmt, ap) : ERR;
+    va_end(ap);
+    return (code);
+}
diff --git a/ncurses/base/lib_screen.c b/ncurses/base/lib_screen.c
new file mode 100644
index 0000000..4aa58ea
--- /dev/null
+++ b/ncurses/base/lib_screen.c
@@ -0,0 +1,220 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996 on                 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_screen.c,v 1.31 2008/08/16 19:05:37 tom Exp $")
+
+#define MAX_SIZE 0x3fff		/* 16k is big enough for a window or pad */
+
+NCURSES_EXPORT(WINDOW *)
+getwin(FILE *filep)
+{
+    WINDOW tmp, *nwin;
+    int n;
+
+    T((T_CALLED("getwin(%p)"), filep));
+
+    clearerr(filep);
+    (void) fread(&tmp, sizeof(WINDOW), 1, filep);
+    if (ferror(filep)
+	|| tmp._maxy == 0
+	|| tmp._maxy > MAX_SIZE
+	|| tmp._maxx == 0
+	|| tmp._maxx > MAX_SIZE)
+	returnWin(0);
+
+    if (tmp._flags & _ISPAD) {
+	nwin = newpad(tmp._maxy + 1, tmp._maxx + 1);
+    } else {
+	nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0);
+    }
+
+    /*
+     * We deliberately do not restore the _parx, _pary, or _parent
+     * fields, because the window hierarchy within which they
+     * made sense is probably gone.
+     */
+    if (nwin != 0) {
+	nwin->_curx = tmp._curx;
+	nwin->_cury = tmp._cury;
+	nwin->_maxy = tmp._maxy;
+	nwin->_maxx = tmp._maxx;
+	nwin->_begy = tmp._begy;
+	nwin->_begx = tmp._begx;
+	nwin->_yoffset = tmp._yoffset;
+	nwin->_flags = tmp._flags & ~(_SUBWIN);
+
+	WINDOW_ATTRS(nwin) = WINDOW_ATTRS(&tmp);
+	nwin->_nc_bkgd = tmp._nc_bkgd;
+
+	nwin->_notimeout = tmp._notimeout;
+	nwin->_clear = tmp._clear;
+	nwin->_leaveok = tmp._leaveok;
+	nwin->_idlok = tmp._idlok;
+	nwin->_idcok = tmp._idcok;
+	nwin->_immed = tmp._immed;
+	nwin->_scroll = tmp._scroll;
+	nwin->_sync = tmp._sync;
+	nwin->_use_keypad = tmp._use_keypad;
+	nwin->_delay = tmp._delay;
+
+	nwin->_regtop = tmp._regtop;
+	nwin->_regbottom = tmp._regbottom;
+
+	if (tmp._flags & _ISPAD)
+	    nwin->_pad = tmp._pad;
+
+	for (n = 0; n <= nwin->_maxy; n++) {
+	    clearerr(filep);
+	    (void) fread(nwin->_line[n].text,
+			 sizeof(NCURSES_CH_T),
+			 (size_t) (nwin->_maxx + 1),
+			 filep);
+	    if (ferror(filep)) {
+		delwin(nwin);
+		returnWin(0);
+	    }
+	}
+	touchwin(nwin);
+    }
+    returnWin(nwin);
+}
+
+NCURSES_EXPORT(int)
+putwin(WINDOW *win, FILE *filep)
+{
+    int code = ERR;
+    int n;
+
+    T((T_CALLED("putwin(%p,%p)"), win, filep));
+
+    if (win != 0) {
+	size_t len = (size_t) (win->_maxx + 1);
+
+	clearerr(filep);
+	if (fwrite(win, sizeof(WINDOW), 1, filep) != 1
+	    || ferror(filep))
+	      returnCode(code);
+
+	for (n = 0; n <= win->_maxy; n++) {
+	    if (fwrite(win->_line[n].text,
+		       sizeof(NCURSES_CH_T), len, filep) != len
+		|| ferror(filep)) {
+		returnCode(code);
+	    }
+	}
+	code = OK;
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+scr_restore(const char *file)
+{
+    FILE *fp = 0;
+
+    T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file)));
+
+    if (_nc_access(file, R_OK) < 0
+	|| (fp = fopen(file, "rb")) == 0) {
+	returnCode(ERR);
+    } else {
+	delwin(newscr);
+	SP->_newscr = getwin(fp);
+#if !USE_REENTRANT
+	newscr = SP->_newscr;
+#endif
+	(void) fclose(fp);
+	returnCode(OK);
+    }
+}
+
+NCURSES_EXPORT(int)
+scr_dump(const char *file)
+{
+    FILE *fp = 0;
+
+    T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
+
+    if (_nc_access(file, W_OK) < 0
+	|| (fp = fopen(file, "wb")) == 0) {
+	returnCode(ERR);
+    } else {
+	(void) putwin(newscr, fp);
+	(void) fclose(fp);
+	returnCode(OK);
+    }
+}
+
+NCURSES_EXPORT(int)
+scr_init(const char *file)
+{
+    FILE *fp = 0;
+
+    T((T_CALLED("scr_init(%s)"), _nc_visbuf(file)));
+
+    if (exit_ca_mode && non_rev_rmcup)
+	returnCode(ERR);
+
+    if (_nc_access(file, R_OK) < 0
+	|| (fp = fopen(file, "rb")) == 0) {
+	returnCode(ERR);
+    } else {
+	delwin(curscr);
+	SP->_curscr = getwin(fp);
+#if !USE_REENTRANT
+	curscr = SP->_curscr;
+#endif
+	(void) fclose(fp);
+	returnCode(OK);
+    }
+}
+
+NCURSES_EXPORT(int)
+scr_set(const char *file)
+{
+    T((T_CALLED("scr_set(%s)"), _nc_visbuf(file)));
+
+    if (scr_init(file) == ERR) {
+	returnCode(ERR);
+    } else {
+	delwin(newscr);
+	SP->_newscr = dupwin(curscr);
+#if !USE_REENTRANT
+	newscr = SP->_newscr;
+#endif
+	returnCode(OK);
+    }
+}
diff --git a/ncurses/base/lib_scroll.c b/ncurses/base/lib_scroll.c
new file mode 100644
index 0000000..ac85bd5
--- /dev/null
+++ b/ncurses/base/lib_scroll.c
@@ -0,0 +1,150 @@
+/****************************************************************************
+ * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 1996-2003                                      *
+ *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_scroll.c
+**
+**	The routine wscrl(win, n).
+**  positive n scroll the window up (ie. move lines down)
+**  negative n scroll the window down (ie. move lines up)
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scroll.c,v 1.26 2006/10/14 20:46:08 tom Exp $")
+
+NCURSES_EXPORT(void)
+_nc_scroll_window(WINDOW *win,
+		  int const n,
+		  NCURSES_SIZE_T const top,
+		  NCURSES_SIZE_T const bottom,
+		  NCURSES_CH_T blank)
+{
+    int limit;
+    int line;
+    int j;
+    size_t to_copy = (size_t) (sizeof(NCURSES_CH_T) * (win->_maxx + 1));
+
+    TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %ld, %ld)",
+		    win, n, (long) top, (long) bottom));
+
+    if (top < 0
+	|| bottom < top
+	|| bottom > win->_maxy) {
+	TR(TRACE_MOVE, ("nothing to scroll"));
+	return;
+    }
+
+    /*
+     * This used to do a line-text pointer-shuffle instead of text copies.
+     * That (a) doesn't work when the window is derived and doesn't have
+     * its own storage, (b) doesn't save you a lot on modern machines
+     * anyway.  Your typical memcpy implementations are coded in
+     * assembler using a tight BLT loop; for the size of copies we're
+     * talking here, the total execution time is dominated by the one-time
+     * setup cost.  So there is no point in trying to be excessively
+     * clever -- esr.
+     */
+
+    /* shift n lines downwards */
+    if (n < 0) {
+	limit = top - n;
+	for (line = bottom; line >= limit && line >= 0; line--) {
+	    TR(TRACE_MOVE, ("...copying %d to %d", line + n, line));
+	    memcpy(win->_line[line].text,
+		   win->_line[line + n].text,
+		   to_copy);
+	    if_USE_SCROLL_HINTS(win->_line[line].oldindex =
+				win->_line[line + n].oldindex);
+	}
+	for (line = top; line < limit && line <= win->_maxy; line++) {
+	    TR(TRACE_MOVE, ("...filling %d", line));
+	    for (j = 0; j <= win->_maxx; j++)
+		win->_line[line].text[j] = blank;
+	    if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX);
+	}
+    }
+
+    /* shift n lines upwards */
+    if (n > 0) {
+	limit = bottom - n;
+	for (line = top; line <= limit && line <= win->_maxy; line++) {
+	    memcpy(win->_line[line].text,
+		   win->_line[line + n].text,
+		   to_copy);
+	    if_USE_SCROLL_HINTS(win->_line[line].oldindex =
+				win->_line[line + n].oldindex);
+	}
+	for (line = bottom; line > limit && line >= 0; line--) {
+	    for (j = 0; j <= win->_maxx; j++)
+		win->_line[line].text[j] = blank;
+	    if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX);
+	}
+    }
+    touchline(win, top, bottom - top + 1);
+
+    if_WIDEC({
+	if (WINDOW_EXT(win, addch_used) != 0) {
+	    int next = WINDOW_EXT(win, addch_y) + n;
+	    if (next < 0 || next > win->_maxy) {
+		TR(TRACE_VIRTPUT,
+		   ("Alert discarded multibyte on scroll"));
+		WINDOW_EXT(win, addch_y) = 0;
+	    } else {
+		TR(TRACE_VIRTPUT, ("scrolled working position to %d,%d",
+				   WINDOW_EXT(win, addch_y),
+				   WINDOW_EXT(win, addch_x)));
+		WINDOW_EXT(win, addch_y) = next;
+	    }
+	}
+    })
+}
+
+NCURSES_EXPORT(int)
+wscrl(WINDOW *win, int n)
+{
+    T((T_CALLED("wscrl(%p,%d)"), win, n));
+
+    if (!win || !win->_scroll) {
+	TR(TRACE_MOVE, ("...scrollok is false"));
+	returnCode(ERR);
+    }
+
+    if (n != 0) {
+	_nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd);
+	_nc_synchook(win);
+    }
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_scrollok.c b/ncurses/base/lib_scrollok.c
new file mode 100644
index 0000000..f6b3025
--- /dev/null
+++ b/ncurses/base/lib_scrollok.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_scrollok.c
+**
+**	The routine scrollok.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scrollok.c,v 1.4 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+scrollok(WINDOW *win, bool flag)
+{
+    T((T_CALLED("scrollok(%p,%d)"), win, flag));
+
+    if (win) {
+	win->_scroll = flag;
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_scrreg.c b/ncurses/base/lib_scrreg.c
new file mode 100644
index 0000000..c85d60f
--- /dev/null
+++ b/ncurses/base/lib_scrreg.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_scrreg.c
+**
+**	The routine wsetscrreg().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_scrreg.c,v 1.10 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+wsetscrreg(WINDOW *win, int top, int bottom)
+{
+    T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom));
+
+    if (win &&
+	top >= 0 && top <= win->_maxy &&
+	bottom >= 0 && bottom <= win->_maxy &&
+	bottom > top) {
+	win->_regtop = (NCURSES_SIZE_T) top;
+	win->_regbottom = (NCURSES_SIZE_T) bottom;
+
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_set_term.c b/ncurses/base/lib_set_term.c
new file mode 100644
index 0000000..aff432b
--- /dev/null
+++ b/ncurses/base/lib_set_term.c
@@ -0,0 +1,647 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_set_term.c
+**
+**	The routine set_term().
+**
+*/
+
+#include <curses.priv.h>
+
+#include <term.h>		/* cur_term */
+#include <tic.h>
+
+MODULE_ID("$Id: lib_set_term.c,v 1.117 2008/08/04 18:11:12 tom Exp $")
+
+NCURSES_EXPORT(SCREEN *)
+set_term(SCREEN *screenp)
+{
+    SCREEN *oldSP;
+    SCREEN *newSP;
+
+    T((T_CALLED("set_term(%p)"), screenp));
+
+    _nc_lock_global(curses);
+
+    oldSP = SP;
+    _nc_set_screen(screenp);
+    newSP = SP;
+
+    if (newSP != 0) {
+	set_curterm(newSP->_term);
+#if !USE_REENTRANT
+	curscr = newSP->_curscr;
+	newscr = newSP->_newscr;
+	stdscr = newSP->_stdscr;
+	COLORS = newSP->_color_count;
+	COLOR_PAIRS = newSP->_pair_count;
+#endif
+    } else {
+	set_curterm(0);
+#if !USE_REENTRANT
+	curscr = 0;
+	newscr = 0;
+	stdscr = 0;
+	COLORS = 0;
+	COLOR_PAIRS = 0;
+#endif
+    }
+
+    _nc_unlock_global(curses);
+
+    T((T_RETURN("%p"), oldSP));
+    return (oldSP);
+}
+
+static void
+_nc_free_keytry(TRIES * kt)
+{
+    if (kt != 0) {
+	_nc_free_keytry(kt->child);
+	_nc_free_keytry(kt->sibling);
+	free(kt);
+    }
+}
+
+static bool
+delink_screen(SCREEN *sp)
+{
+    SCREEN *last = 0;
+    SCREEN *temp;
+    bool result = FALSE;
+
+    for (each_screen(temp)) {
+	if (temp == sp) {
+	    if (last)
+		last = sp->_next_screen;
+	    else
+		_nc_screen_chain = sp->_next_screen;
+	    result = TRUE;
+	    break;
+	}
+	last = temp;
+    }
+    return result;
+}
+
+/*
+ * Free the storage associated with the given SCREEN sp.
+ */
+NCURSES_EXPORT(void)
+delscreen(SCREEN *sp)
+{
+    int i;
+
+    T((T_CALLED("delscreen(%p)"), sp));
+
+    _nc_lock_global(curses);
+    if (delink_screen(sp)) {
+
+	(void) _nc_freewin(sp->_curscr);
+	(void) _nc_freewin(sp->_newscr);
+	(void) _nc_freewin(sp->_stdscr);
+
+	if (sp->_slk != 0) {
+	    if (sp->_slk->ent != 0) {
+		for (i = 0; i < sp->_slk->labcnt; ++i) {
+		    FreeIfNeeded(sp->_slk->ent[i].ent_text);
+		    FreeIfNeeded(sp->_slk->ent[i].form_text);
+		}
+		free(sp->_slk->ent);
+	    }
+	    free(sp->_slk);
+	    sp->_slk = 0;
+	}
+
+	_nc_free_keytry(sp->_keytry);
+	sp->_keytry = 0;
+
+	_nc_free_keytry(sp->_key_ok);
+	sp->_key_ok = 0;
+
+	FreeIfNeeded(sp->_current_attr);
+
+	FreeIfNeeded(sp->_color_table);
+	FreeIfNeeded(sp->_color_pairs);
+
+	FreeIfNeeded(sp->oldhash);
+	FreeIfNeeded(sp->newhash);
+	FreeIfNeeded(sp->hashtab);
+
+	FreeIfNeeded(sp->_acs_map);
+	FreeIfNeeded(sp->_screen_acs_map);
+
+	/*
+	 * If the associated output stream has been closed, we can discard the
+	 * set-buffer.  Limit the error check to EBADF, since fflush may fail
+	 * for other reasons than trying to operate upon a closed stream.
+	 */
+	if (sp->_ofp != 0
+	    && sp->_setbuf != 0
+	    && fflush(sp->_ofp) != 0
+	    && errno == EBADF) {
+	    free(sp->_setbuf);
+	}
+
+	del_curterm(sp->_term);
+	free(sp);
+
+	/*
+	 * If this was the current screen, reset everything that the
+	 * application might try to use (except cur_term, which may have
+	 * multiple references in different screens).
+	 */
+	if (sp == SP) {
+#if !USE_REENTRANT
+	    curscr = 0;
+	    newscr = 0;
+	    stdscr = 0;
+	    COLORS = 0;
+	    COLOR_PAIRS = 0;
+#endif
+	    _nc_set_screen(0);
+	}
+    }
+    _nc_unlock_global(curses);
+
+    returnVoid;
+}
+
+static bool
+no_mouse_event(SCREEN *sp GCC_UNUSED)
+{
+    return FALSE;
+}
+
+static bool
+no_mouse_inline(SCREEN *sp GCC_UNUSED)
+{
+    return FALSE;
+}
+
+static bool
+no_mouse_parse(SCREEN *sp GCC_UNUSED, int code GCC_UNUSED)
+{
+    return TRUE;
+}
+
+static void
+no_mouse_resume(SCREEN *sp GCC_UNUSED)
+{
+}
+
+static void
+no_mouse_wrap(SCREEN *sp GCC_UNUSED)
+{
+}
+
+#if NCURSES_EXT_FUNCS && USE_COLORFGBG
+static char *
+extract_fgbg(char *src, int *result)
+{
+    char *dst = 0;
+    long value = strtol(src, &dst, 0);
+
+    if (dst == 0) {
+	dst = src;
+    } else if (value >= 0) {
+	*result = value;
+    }
+    while (*dst != 0 && *dst != ';')
+	dst++;
+    if (*dst == ';')
+	dst++;
+    return dst;
+}
+#endif
+
+/* OS-independent screen initializations */
+NCURSES_EXPORT(int)
+_nc_setupscreen(int slines GCC_UNUSED,
+		int scolumns GCC_UNUSED,
+		FILE *output,
+		bool filtered,
+		int slk_format)
+{
+    char *env;
+    int bottom_stolen = 0;
+    bool support_cookies = USE_XMC_SUPPORT;
+    ripoff_t *rop;
+
+    T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
+       slines, scolumns, output, filtered, slk_format));
+
+    assert(SP == 0);		/* has been reset in newterm() ! */
+    if (!_nc_alloc_screen()
+	|| ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0)
+	|| ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) {
+	returnCode(ERR);
+    }
+
+    T(("created SP %p", SP));
+    SP->_next_screen = _nc_screen_chain;
+    _nc_screen_chain = SP;
+
+    if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0)
+	returnCode(ERR);
+
+    /*
+     * We should always check the screensize, just in case.
+     */
+    _nc_get_screensize(SP, &slines, &scolumns);
+    SET_LINES(slines);
+    SET_COLS(scolumns);
+    T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));
+
+    SP->_filtered = filtered;
+
+    /* implement filter mode */
+    if (filtered) {
+	slines = 1;
+	SET_LINES(slines);
+	clear_screen = 0;
+	cursor_down = parm_down_cursor = 0;
+	cursor_address = 0;
+	cursor_up = parm_up_cursor = 0;
+	row_address = 0;
+
+	cursor_home = carriage_return;
+	T(("filter screensize %dx%d", LINES, COLS));
+    }
+#ifdef __DJGPP__
+    T(("setting output mode to binary"));
+    fflush(output);
+    setmode(output, O_BINARY);
+#endif
+    _nc_set_buffer(output, TRUE);
+    SP->_term = cur_term;
+    SP->_lines = slines;
+    SP->_lines_avail = slines;
+    SP->_columns = scolumns;
+    SP->_cursrow = -1;
+    SP->_curscol = -1;
+    SP->_nl = TRUE;
+    SP->_raw = FALSE;
+    SP->_cbreak = 0;
+    SP->_echo = TRUE;
+    SP->_fifohead = -1;
+    SP->_endwin = TRUE;
+    SP->_ofp = output;
+    SP->_cursor = -1;		/* cannot know real cursor shape */
+
+    SetNoPadding(SP);
+
+#if NCURSES_EXT_FUNCS
+    SP->_default_color = FALSE;
+    SP->_has_sgr_39_49 = FALSE;
+
+    /*
+     * Set our assumption of the terminal's default foreground and background
+     * colors.  The curs_color man-page states that we can assume that the
+     * background is black.  The origin of this assumption appears to be
+     * terminals that displayed colored text, but no colored backgrounds, e.g.,
+     * the first colored terminals around 1980.  More recent ones with better
+     * technology can display not only colored backgrounds, but all
+     * combinations.  So a terminal might be something other than "white" on
+     * black (green/black looks monochrome too), but black on white or even
+     * on ivory.
+     *
+     * White-on-black is the simplest thing to use for monochrome.  Almost
+     * all applications that use color paint both text and background, so
+     * the distinction is moot.  But a few do not - which is why we leave this
+     * configurable (a better solution is to use assume_default_colors() for
+     * the rare applications that do require that sort of appearance, since
+     * is appears that more users expect to be able to make a white-on-black
+     * or black-on-white display under control of the application than not).
+     */
+#ifdef USE_ASSUMED_COLOR
+    SP->_default_fg = COLOR_WHITE;
+    SP->_default_bg = COLOR_BLACK;
+#else
+    SP->_default_fg = C_MASK;
+    SP->_default_bg = C_MASK;
+#endif
+
+    /*
+     * Allow those assumed/default color assumptions to be overridden at
+     * runtime:
+     */
+    if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) {
+	int fg, bg;
+	char sep1, sep2;
+	int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2);
+	if (count >= 1) {
+	    SP->_default_fg = (fg >= 0 && fg < max_colors) ? fg : C_MASK;
+	    if (count >= 3) {
+		SP->_default_bg = (bg >= 0 && bg < max_colors) ? bg : C_MASK;
+	    }
+	    TR(TRACE_CHARPUT | TRACE_MOVE,
+	       ("from environment assumed fg=%d, bg=%d",
+		SP->_default_fg,
+		SP->_default_bg));
+	}
+    }
+#if USE_COLORFGBG
+    /*
+     * If rxvt's $COLORFGBG variable is set, use it to specify the assumed
+     * default colors.  Note that rxvt (mis)uses bold colors, equating a bold
+     * color to that value plus 8.  We'll only use the non-bold color for now -
+     * decide later if it is worth having default attributes as well.
+     */
+    if (getenv("COLORFGBG") != 0) {
+	char *p = getenv("COLORFGBG");
+	TR(TRACE_CHARPUT | TRACE_MOVE, ("decoding COLORFGBG %s", p));
+	p = extract_fgbg(p, &(SP->_default_fg));
+	p = extract_fgbg(p, &(SP->_default_bg));
+	if (*p)			/* assume rxvt was compiled with xpm support */
+	    p = extract_fgbg(p, &(SP->_default_bg));
+	TR(TRACE_CHARPUT | TRACE_MOVE, ("decoded fg=%d, bg=%d",
+					SP->_default_fg, SP->_default_bg));
+	if (SP->_default_fg >= max_colors) {
+	    if (set_a_foreground != ABSENT_STRING
+		&& !strcmp(set_a_foreground, "\033[3%p1%dm")) {
+		set_a_foreground = "\033[3%?%p1%{8}%>%t9%e%p1%d%;m";
+	    } else {
+		SP->_default_fg %= max_colors;
+	    }
+	}
+	if (SP->_default_bg >= max_colors) {
+	    if (set_a_background != ABSENT_STRING
+		&& !strcmp(set_a_background, "\033[4%p1%dm")) {
+		set_a_background = "\033[4%?%p1%{8}%>%t9%e%p1%d%;m";
+	    } else {
+		SP->_default_bg %= max_colors;
+	    }
+	}
+    }
+#endif
+#endif /* NCURSES_EXT_FUNCS */
+
+    SP->_maxclick = DEFAULT_MAXCLICK;
+    SP->_mouse_event = no_mouse_event;
+    SP->_mouse_inline = no_mouse_inline;
+    SP->_mouse_parse = no_mouse_parse;
+    SP->_mouse_resume = no_mouse_resume;
+    SP->_mouse_wrap = no_mouse_wrap;
+    SP->_mouse_fd = -1;
+
+    /*
+     * If we've no magic cookie support, we suppress attributes that xmc would
+     * affect, i.e., the attributes that affect the rendition of a space.
+     */
+    SP->_ok_attributes = termattrs();
+    if (has_colors()) {
+	SP->_ok_attributes |= A_COLOR;
+    }
+#if USE_XMC_SUPPORT
+    /*
+     * If we have no magic-cookie support compiled-in, or if it is suppressed
+     * in the environment, reset the support-flag.
+     */
+    if (magic_cookie_glitch >= 0) {
+	if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
+	    support_cookies = FALSE;
+	}
+    }
+#endif
+
+    if (!support_cookies && magic_cookie_glitch >= 0) {
+	T(("will disable attributes to work w/o magic cookies"));
+    }
+
+    if (magic_cookie_glitch > 0) {	/* tvi, wyse */
+
+	SP->_xmc_triggers = SP->_ok_attributes & (
+						     A_STANDOUT |
+						     A_UNDERLINE |
+						     A_REVERSE |
+						     A_BLINK |
+						     A_DIM |
+						     A_BOLD |
+						     A_INVIS |
+						     A_PROTECT
+	    );
+#if 0
+	/*
+	 * We "should" treat colors as an attribute.  The wyse350 (and its
+	 * clones) appear to be the only ones that have both colors and magic
+	 * cookies.
+	 */
+	if (has_colors()) {
+	    SP->_xmc_triggers |= A_COLOR;
+	}
+#endif
+	SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~(A_BOLD);
+
+	T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
+	/*
+	 * Supporting line-drawing may be possible.  But make the regular
+	 * video attributes work first.
+	 */
+	acs_chars = ABSENT_STRING;
+	ena_acs = ABSENT_STRING;
+	enter_alt_charset_mode = ABSENT_STRING;
+	exit_alt_charset_mode = ABSENT_STRING;
+#if USE_XMC_SUPPORT
+	/*
+	 * To keep the cookie support simple, suppress all of the optimization
+	 * hooks except for clear_screen and the cursor addressing.
+	 */
+	if (support_cookies) {
+	    clr_eol = ABSENT_STRING;
+	    clr_eos = ABSENT_STRING;
+	    set_attributes = ABSENT_STRING;
+	}
+#endif
+    } else if (magic_cookie_glitch == 0) {	/* hpterm */
+    }
+
+    /*
+     * If magic cookies are not supported, cancel the strings that set
+     * video attributes.
+     */
+    if (!support_cookies && magic_cookie_glitch >= 0) {
+	magic_cookie_glitch = ABSENT_NUMERIC;
+	set_attributes = ABSENT_STRING;
+	enter_blink_mode = ABSENT_STRING;
+	enter_bold_mode = ABSENT_STRING;
+	enter_dim_mode = ABSENT_STRING;
+	enter_reverse_mode = ABSENT_STRING;
+	enter_standout_mode = ABSENT_STRING;
+	enter_underline_mode = ABSENT_STRING;
+    }
+
+    /* initialize normal acs before wide, since we use mapping in the latter */
+#if !USE_WIDEC_SUPPORT
+    if (_nc_unicode_locale() && _nc_locale_breaks_acs(cur_term)) {
+	acs_chars = NULL;
+	ena_acs = NULL;
+	enter_alt_charset_mode = NULL;
+	exit_alt_charset_mode = NULL;
+	set_attributes = NULL;
+    }
+#endif
+    _nc_init_acs();
+#if USE_WIDEC_SUPPORT
+    _nc_init_wacs();
+
+    SP->_screen_acs_fix = (_nc_unicode_locale()
+			   && _nc_locale_breaks_acs(cur_term));
+#endif
+    env = _nc_get_locale();
+    SP->_legacy_coding = ((env == 0)
+			  || !strcmp(env, "C")
+			  || !strcmp(env, "POSIX"));
+    T(("legacy-coding %d", SP->_legacy_coding));
+
+    _nc_idcok = TRUE;
+    _nc_idlok = FALSE;
+
+    SP->oldhash = 0;
+    SP->newhash = 0;
+
+    T(("creating newscr"));
+    if ((SP->_newscr = newwin(slines, scolumns, 0, 0)) == 0)
+	returnCode(ERR);
+
+    T(("creating curscr"));
+    if ((SP->_curscr = newwin(slines, scolumns, 0, 0)) == 0)
+	returnCode(ERR);
+
+#if !USE_REENTRANT
+    newscr = SP->_newscr;
+    curscr = SP->_curscr;
+#endif
+#if USE_SIZECHANGE
+    SP->_resize = resizeterm;
+#endif
+
+    newscr->_clear = TRUE;
+    curscr->_clear = FALSE;
+
+    def_shell_mode();
+    def_prog_mode();
+
+    for (rop = ripoff_stack;
+	 rop != ripoff_sp && (rop - ripoff_stack) < N_RIPS;
+	 rop++) {
+
+	/* If we must simulate soft labels, grab off the line to be used.
+	   We assume that we must simulate, if it is none of the standard
+	   formats (4-4 or 3-2-3) for which there may be some hardware
+	   support. */
+	if (rop->hook == _nc_slk_initialize)
+	    if (!(num_labels <= 0 || !SLK_STDFMT(slk_format)))
+		continue;
+	if (rop->hook) {
+	    int count;
+	    WINDOW *w;
+
+	    count = (rop->line < 0) ? -rop->line : rop->line;
+	    T(("ripping off %i lines at %s", count,
+	       ((rop->line < 0)
+		? "bottom"
+		: "top")));
+
+	    w = newwin(count, scolumns,
+		       ((rop->line < 0)
+			? SP->_lines_avail - count
+			: 0),
+		       0);
+	    if (w) {
+		rop->win = w;
+		rop->hook(w, scolumns);
+	    } else {
+		returnCode(ERR);
+	    }
+	    if (rop->line < 0)
+		bottom_stolen += count;
+	    else
+		SP->_topstolen += count;
+	    SP->_lines_avail -= count;
+	}
+    }
+    /* reset the stack */
+    ripoff_sp = ripoff_stack;
+
+    T(("creating stdscr"));
+    assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines);
+    if ((SP->_stdscr = newwin(SP->_lines_avail, scolumns, 0, 0)) == 0)
+	returnCode(ERR);
+
+    SET_LINES(SP->_lines_avail);
+#if !USE_REENTRANT
+    stdscr = SP->_stdscr;
+#endif
+
+    returnCode(OK);
+}
+
+/*
+ * The internal implementation interprets line as the number of lines to rip
+ * off from the top or bottom.
+ */
+NCURSES_EXPORT(int)
+_nc_ripoffline(int line, int (*init) (WINDOW *, int))
+{
+    T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init));
+
+    if (line != 0) {
+
+	if (ripoff_sp == 0)
+	    ripoff_sp = ripoff_stack;
+	if (ripoff_sp >= ripoff_stack + N_RIPS)
+	    returnCode(ERR);
+
+	ripoff_sp->line = line;
+	ripoff_sp->hook = init;
+	ripoff_sp++;
+    }
+
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+ripoffline(int line, int (*init) (WINDOW *, int))
+{
+    START_TRACE();
+    T((T_CALLED("ripoffline(%d,%p)"), line, init));
+
+    if (line == 0)
+	returnCode(OK);
+
+    returnCode(_nc_ripoffline((line < 0) ? -1 : 1, init));
+}
diff --git a/ncurses/base/lib_slk.c b/ncurses/base/lib_slk.c
new file mode 100644
index 0000000..662f7e4
--- /dev/null
+++ b/ncurses/base/lib_slk.c
@@ -0,0 +1,191 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Authors:                                                                *
+ *          Gerhard Fuernkranz                      1993 (original)         *
+ *          Zeyd M. Ben-Halim                       1992,1995 (sic)         *
+ *          Eric S. Raymond                                                 *
+ *          Juergen Pfeifer                         1996-on                 *
+ *          Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+ *	lib_slk.c
+ *	Soft key routines.
+ */
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <term.h>		/* num_labels, label_*, plab_norm */
+
+MODULE_ID("$Id: lib_slk.c,v 1.35 2008/09/27 14:07:33 juergen Exp $")
+
+/*
+ * Free any memory related to soft labels, return an error.
+ */
+static int
+slk_failed(void)
+{
+    if (SP->_slk) {
+	FreeIfNeeded(SP->_slk->ent);
+	free(SP->_slk);
+	SP->_slk = (SLK *) 0;
+    }
+    return ERR;
+}
+
+/*
+ * Initialize soft labels.
+ * Called from newterm()
+ */
+NCURSES_EXPORT(int)
+_nc_slk_initialize(WINDOW *stwin, int cols)
+{
+    int i, x;
+    int res = OK;
+    unsigned max_length;
+
+    T((T_CALLED("_nc_slk_initialize()")));
+
+    if (SP->_slk) {		/* we did this already, so simply return */
+	returnCode(OK);
+    } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0)
+	returnCode(ERR);
+
+    SP->_slk->ent = NULL;
+
+    /*
+     * If we use colors, vidputs() will suppress video attributes that conflict
+     * with colors.  In that case, we're still guaranteed that "reverse" would
+     * work.
+     */
+    if ((no_color_video & 1) == 0)
+	SetAttr(SP->_slk->attr, A_STANDOUT);
+    else
+	SetAttr(SP->_slk->attr, A_REVERSE);
+
+    SP->_slk->maxlab = ((num_labels > 0)
+			? num_labels
+			: MAX_SKEY(_nc_globals.slk_format));
+    SP->_slk->maxlen = ((num_labels > 0)
+			? label_width * label_height
+			: MAX_SKEY_LEN(_nc_globals.slk_format));
+    SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_globals.slk_format))
+			? MAX_SKEY(_nc_globals.slk_format)
+			: SP->_slk->maxlab);
+
+    if (SP->_slk->maxlen <= 0
+	|| SP->_slk->labcnt <= 0
+	|| (SP->_slk->ent = typeCalloc(slk_ent,
+				       (unsigned) SP->_slk->labcnt)) == NULL)
+	returnCode(slk_failed());
+
+    max_length = SP->_slk->maxlen;
+    for (i = 0; i < SP->_slk->labcnt; i++) {
+	size_t used = max_length + 1;
+
+	if ((SP->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used)) == 0)
+	    returnCode(slk_failed());
+	memset(SP->_slk->ent[i].ent_text, 0, used);
+
+	if ((SP->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used)) == 0)
+	    returnCode(slk_failed());
+	memset(SP->_slk->ent[i].form_text, 0, used);
+
+	memset(SP->_slk->ent[i].form_text, ' ', max_length);
+	SP->_slk->ent[i].visible = (char) (i < SP->_slk->maxlab);
+    }
+    if (_nc_globals.slk_format >= 3) {	/* PC style */
+	int gap = (cols - 3 * (3 + 4 * max_length)) / 2;
+
+	if (gap < 1)
+	    gap = 1;
+
+	for (i = x = 0; i < SP->_slk->maxlab; i++) {
+	    SP->_slk->ent[i].ent_x = x;
+	    x += max_length;
+	    x += (i == 3 || i == 7) ? gap : 1;
+	}
+    } else {
+	if (_nc_globals.slk_format == 2) {	/* 4-4 */
+	    int gap = cols - (SP->_slk->maxlab * max_length) - 6;
+
+	    if (gap < 1)
+		gap = 1;
+	    for (i = x = 0; i < SP->_slk->maxlab; i++) {
+		SP->_slk->ent[i].ent_x = x;
+		x += max_length;
+		x += (i == 3) ? gap : 1;
+	    }
+	} else {
+	    if (_nc_globals.slk_format == 1) {	/* 1 -> 3-2-3 */
+		int gap = (cols - (SP->_slk->maxlab * max_length) - 5)
+		/ 2;
+
+		if (gap < 1)
+		    gap = 1;
+		for (i = x = 0; i < SP->_slk->maxlab; i++) {
+		    SP->_slk->ent[i].ent_x = x;
+		    x += max_length;
+		    x += (i == 2 || i == 4) ? gap : 1;
+		}
+	    } else
+		returnCode(slk_failed());
+	}
+    }
+    SP->_slk->dirty = TRUE;
+    if ((SP->_slk->win = stwin) == NULL) {
+	returnCode(slk_failed());
+    }
+
+    /* We now reset the format so that the next newterm has again
+     * per default no SLK keys and may call slk_init again to
+     * define a new layout. (juergen 03-Mar-1999)
+     */
+    SP->slk_format = _nc_globals.slk_format;
+    _nc_globals.slk_format = 0;
+    returnCode(res);
+}
+
+/*
+ * Restore the soft labels on the screen.
+ */
+NCURSES_EXPORT(int)
+slk_restore(void)
+{
+    T((T_CALLED("slk_restore()")));
+
+    if (SP->_slk == NULL)
+	return (ERR);
+    SP->_slk->hidden = FALSE;
+    SP->_slk->dirty = TRUE;
+
+    returnCode(slk_refresh());
+}
diff --git a/ncurses/base/lib_slkatr_set.c b/ncurses/base/lib_slkatr_set.c
new file mode 100644
index 0000000..f83616b
--- /dev/null
+++ b/ncurses/base/lib_slkatr_set.c
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author:  Juergen Pfeifer, 1998                                          *
+ *     and:  Thomas E. Dickey 2005                                          *
+ ****************************************************************************/
+
+/*
+ *	lib_slkatr_set.c
+ *	Soft key routines.
+ *	Set the label's attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatr_set.c,v 1.10 2005/01/28 21:11:53 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attr_set(const attr_t attr, short color_pair_number, void *opts)
+{
+    T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number));
+
+    if (SP != 0 && SP->_slk != 0 && !opts &&
+	color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) {
+	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
+	SetAttr(SP->_slk->attr, attr);
+	if (color_pair_number > 0) {
+	    SetPair(SP->_slk->attr, color_pair_number);
+	}
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkatrof.c b/ncurses/base/lib_slkatrof.c
new file mode 100644
index 0000000..14b4c3b
--- /dev/null
+++ b/ncurses/base/lib_slkatrof.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author:  Juergen Pfeifer, 1997                                          *
+ *     and:  Thomas E. Dickey 2005                                          *
+ ****************************************************************************/
+
+/*
+ *	lib_slkatrof.c
+ *	Soft key routines.
+ *      Switch off labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatrof.c,v 1.8 2005/01/08 23:01:32 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attroff(const chtype attr)
+{
+    T((T_CALLED("slk_attroff(%s)"), _traceattr(attr)));
+
+    if (SP != 0 && SP->_slk != 0) {
+	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
+	RemAttr(SP->_slk->attr, attr);
+	if ((attr & A_COLOR) != 0) {
+	    SetPair(SP->_slk->attr, 0);
+	}
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkatron.c b/ncurses/base/lib_slkatron.c
new file mode 100644
index 0000000..90add86
--- /dev/null
+++ b/ncurses/base/lib_slkatron.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author:  Juergen Pfeifer, 1997                                          *
+ *     and:  Thomas E. Dickey 2005                                          *
+ ****************************************************************************/
+
+/*
+ *	lib_slkatron.c
+ *	Soft key routines.
+ *      Switch on labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatron.c,v 1.8 2005/01/08 23:02:01 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attron(const chtype attr)
+{
+    T((T_CALLED("slk_attron(%s)"), _traceattr(attr)));
+
+    if (SP != 0 && SP->_slk != 0) {
+	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
+	AddAttr(SP->_slk->attr, attr);
+	if ((attr & A_COLOR) != 0) {
+	    SetPair(SP->_slk->attr, PAIR_NUMBER(attr));
+	}
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkatrset.c b/ncurses/base/lib_slkatrset.c
new file mode 100644
index 0000000..8da9981
--- /dev/null
+++ b/ncurses/base/lib_slkatrset.c
@@ -0,0 +1,53 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author:  Juergen Pfeifer, 1997                                          *
+ *     and:  Thomas E. Dickey 2005                                          *
+ ****************************************************************************/
+
+/*
+ *	lib_slkatrset.c
+ *	Soft key routines.
+ *      Set the labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkatrset.c,v 1.7 2005/01/08 21:46:47 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_attrset(const chtype attr)
+{
+    T((T_CALLED("slk_attrset(%s)"), _traceattr(attr)));
+
+    if (SP != 0 && SP->_slk != 0) {
+	SetAttr(SP->_slk->attr, attr);
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkattr.c b/ncurses/base/lib_slkattr.c
new file mode 100644
index 0000000..da82ee5
--- /dev/null
+++ b/ncurses/base/lib_slkattr.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author:  Juergen Pfeifer, 1997                                          *
+ *     and:  Thomas E. Dickey 2005                                          *
+ ****************************************************************************/
+
+/*
+ *	lib_slkattr.c
+ *	Soft key routines.
+ *      Fetch the labels attributes
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkattr.c,v 1.6 2005/01/08 21:44:28 tom Exp $")
+
+NCURSES_EXPORT(attr_t)
+slk_attr(void)
+{
+    T((T_CALLED("slk_attr()")));
+
+    if (SP != 0 && SP->_slk != 0) {
+	attr_t result = AttrOf(SP->_slk->attr) & ALL_BUT_COLOR;
+	int pair = GetPair(SP->_slk->attr);
+
+	result |= COLOR_PAIR(pair);
+	returnAttr(result);
+    } else
+	returnAttr(0);
+}
diff --git a/ncurses/base/lib_slkclear.c b/ncurses/base/lib_slkclear.c
new file mode 100644
index 0000000..946ceea
--- /dev/null
+++ b/ncurses/base/lib_slkclear.c
@@ -0,0 +1,66 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Juergen Pfeifer                         1996-1999               *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	lib_slkclear.c
+ *	Soft key routines.
+ *      Remove soft labels from the screen.
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkclear.c,v 1.10 2007/12/29 17:51:47 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_clear(void)
+{
+    int rc = ERR;
+
+    T((T_CALLED("slk_clear()")));
+
+    if (SP != NULL && SP->_slk != NULL) {
+	SP->_slk->hidden = TRUE;
+	/* For simulated SLK's it looks much more natural to
+	   inherit those attributes from the standard screen */
+	SP->_slk->win->_nc_bkgd = stdscr->_nc_bkgd;
+	WINDOW_ATTRS(SP->_slk->win) = WINDOW_ATTRS(stdscr);
+	if (SP->_slk->win == stdscr) {
+	    rc = OK;
+	} else {
+	    werase(SP->_slk->win);
+	    rc = wrefresh(SP->_slk->win);
+	}
+    }
+    returnCode(rc);
+}
diff --git a/ncurses/base/lib_slkcolor.c b/ncurses/base/lib_slkcolor.c
new file mode 100644
index 0000000..b677b65
--- /dev/null
+++ b/ncurses/base/lib_slkcolor.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author:  Juergen Pfeifer, 1998                                          *
+ *     and:  Thomas E. Dickey 2005                                          *
+ ****************************************************************************/
+
+/*
+ *	lib_slkcolor.c
+ *	Soft key routines.
+ *	Set the label's color
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkcolor.c,v 1.12 2005/01/28 21:11:53 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_color(short color_pair_number)
+{
+    T((T_CALLED("slk_color(%d)"), color_pair_number));
+
+    if (SP != 0 && SP->_slk != 0 &&
+	color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) {
+	TR(TRACE_ATTRS, ("... current is %s", _tracech_t(CHREF(SP->_slk->attr))));
+	SetPair(SP->_slk->attr, color_pair_number);
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_slkinit.c b/ncurses/base/lib_slkinit.c
new file mode 100644
index 0000000..c440109
--- /dev/null
+++ b/ncurses/base/lib_slkinit.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	lib_slkinit.c
+ *	Soft key routines.
+ *      Initialize soft labels.  Called by the user before initscr().
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slkinit.c,v 1.7 2008/01/12 20:23:39 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_init(int format)
+{
+    int code = ERR;
+
+    T((T_CALLED("slk_init(%d)"), format));
+    if (format >= 0 && format <= 3 && !_nc_globals.slk_format) {
+	_nc_globals.slk_format = 1 + format;
+	code = _nc_ripoffline(-SLK_LINES(_nc_globals.slk_format), _nc_slk_initialize);
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_slklab.c b/ncurses/base/lib_slklab.c
new file mode 100644
index 0000000..42bb4ac
--- /dev/null
+++ b/ncurses/base/lib_slklab.c
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	lib_slklab.c
+ *	Soft key routines.
+ *      Fetch the label text.
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slklab.c,v 1.7 2003/03/29 22:53:48 tom Exp $")
+
+NCURSES_EXPORT(char *)
+slk_label(int n)
+{
+    T((T_CALLED("slk_label(%d)"), n));
+
+    if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt)
+	returnPtr(0);
+    returnPtr(SP->_slk->ent[n - 1].ent_text);
+}
diff --git a/ncurses/base/lib_slkrefr.c b/ncurses/base/lib_slkrefr.c
new file mode 100644
index 0000000..cb1beba
--- /dev/null
+++ b/ncurses/base/lib_slkrefr.c
@@ -0,0 +1,144 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Juergen Pfeifer                         1996-on                 *
+ *     and: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+ *	lib_slkrefr.c
+ *	Write SLK window to the (virtual) screen.
+ */
+#include <curses.priv.h>
+#include <term.h>		/* num_labels, label_*, plab_norm */
+
+MODULE_ID("$Id: lib_slkrefr.c,v 1.17 2008/09/27 14:07:53 juergen Exp $")
+
+/*
+ * Paint the info line for the PC style SLK emulation.
+ */
+static void
+slk_paint_info(WINDOW *win)
+{
+    SCREEN *sp = _nc_screen_of(win);
+
+    if (win && sp && (sp->slk_format == 4)) {
+	int i;
+
+	mvwhline(win, 0, 0, 0, getmaxx(win));
+	wmove(win, 0, 0);
+
+	for (i = 0; i < sp->_slk->maxlab; i++) {
+	    mvwprintw(win, 0, sp->_slk->ent[i].ent_x, "F%d", i + 1);
+	}
+    }
+}
+
+/*
+ * Write the soft labels to the soft-key window.
+ */
+static void
+slk_intern_refresh(SLK * slk)
+{
+    int i;
+    int fmt = SP->slk_format;
+
+    for (i = 0; i < slk->labcnt; i++) {
+	if (slk->dirty || slk->ent[i].dirty) {
+	    if (slk->ent[i].visible) {
+		if (num_labels > 0 && SLK_STDFMT(fmt)) {
+		    if (i < num_labels) {
+			TPUTS_TRACE("plab_norm");
+			putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
+		    }
+		} else {
+		    if (fmt == 4)
+			slk_paint_info(slk->win);
+		    wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
+		    if (SP->_slk) {
+			wattrset(slk->win, AttrOf(SP->_slk->attr));
+		    }
+		    waddstr(slk->win, slk->ent[i].form_text);
+		    /* if we simulate SLK's, it's looking much more
+		       natural to use the current ATTRIBUTE also
+		       for the label window */
+		    wattrset(slk->win, WINDOW_ATTRS(stdscr));
+		}
+	    }
+	    slk->ent[i].dirty = FALSE;
+	}
+    }
+    slk->dirty = FALSE;
+
+    if (num_labels > 0) {
+	if (slk->hidden) {
+	    TPUTS_TRACE("label_off");
+	    putp(label_off);
+	} else {
+	    TPUTS_TRACE("label_on");
+	    putp(label_on);
+	}
+    }
+}
+
+/*
+ * Refresh the soft labels.
+ */
+NCURSES_EXPORT(int)
+slk_noutrefresh(void)
+{
+    T((T_CALLED("slk_noutrefresh()")));
+
+    if (SP == NULL || SP->_slk == NULL)
+	returnCode(ERR);
+    if (SP->_slk->hidden)
+	returnCode(OK);
+    slk_intern_refresh(SP->_slk);
+
+    returnCode(wnoutrefresh(SP->_slk->win));
+}
+
+/*
+ * Refresh the soft labels.
+ */
+NCURSES_EXPORT(int)
+slk_refresh(void)
+{
+    T((T_CALLED("slk_refresh()")));
+
+    if (SP == NULL || SP->_slk == NULL)
+	returnCode(ERR);
+    if (SP->_slk->hidden)
+	returnCode(OK);
+    slk_intern_refresh(SP->_slk);
+
+    returnCode(wrefresh(SP->_slk->win));
+}
diff --git a/ncurses/base/lib_slkset.c b/ncurses/base/lib_slkset.c
new file mode 100644
index 0000000..e19f88e
--- /dev/null
+++ b/ncurses/base/lib_slkset.c
@@ -0,0 +1,149 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Juergen Pfeifer                                                 *
+ *     and: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+ *	lib_slkset.c
+ *      Set soft label text.
+ */
+#include <curses.priv.h>
+#include <ctype.h>
+
+#if USE_WIDEC_SUPPORT
+#if HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
+#endif
+
+MODULE_ID("$Id: lib_slkset.c,v 1.17 2007/10/13 20:08:46 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_set(int i, const char *astr, int format)
+{
+    SLK *slk;
+    int offset;
+    int numchrs;
+    int numcols;
+    int limit;
+    const char *str = astr;
+    const char *p;
+
+    T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format));
+
+    if (SP == 0
+	|| (slk = SP->_slk) == 0
+	|| i < 1
+	|| i > slk->labcnt
+	|| format < 0
+	|| format > 2)
+	returnCode(ERR);
+    if (str == NULL)
+	str = "";
+    --i;			/* Adjust numbering of labels */
+
+    limit = MAX_SKEY_LEN(SP->slk_format);
+    while (isspace(UChar(*str)))
+	str++;			/* skip over leading spaces  */
+    p = str;
+
+#if USE_WIDEC_SUPPORT
+    numcols = 0;
+    while (*p != 0) {
+	mbstate_t state;
+	wchar_t wc;
+	size_t need;
+
+	init_mb(state);
+	need = mbrtowc(0, p, strlen(p), &state);
+	if (need == (size_t) -1)
+	    break;
+	mbrtowc(&wc, p, need, &state);
+	if (!iswprint((wint_t) wc))
+	    break;
+	if (wcwidth(wc) + numcols > limit)
+	    break;
+	numcols += wcwidth(wc);
+	p += need;
+    }
+    numchrs = (p - str);
+#else
+    while (isprint(UChar(*p)))
+	p++;			/* The first non-print stops */
+
+    numcols = (p - str);
+    if (numcols > limit)
+	numcols = limit;
+    numchrs = numcols;
+#endif
+
+    FreeIfNeeded(slk->ent[i].ent_text);
+    if ((slk->ent[i].ent_text = strdup(str)) == 0)
+	returnCode(ERR);
+    slk->ent[i].ent_text[numchrs] = '\0';
+
+    if ((slk->ent[i].form_text = (char *) _nc_doalloc(slk->ent[i].form_text,
+						      (unsigned) (limit +
+								  numchrs + 1))
+	) == 0)
+	returnCode(ERR);
+
+    switch (format) {
+    default:
+    case 0:			/* left-justified */
+	offset = 0;
+	break;
+    case 1:			/* centered */
+	offset = (limit - numcols) / 2;
+	break;
+    case 2:			/* right-justified */
+	offset = limit - numcols;
+	break;
+    }
+    if (offset <= 0)
+	offset = 0;
+    else
+	memset(slk->ent[i].form_text, ' ', (unsigned) offset);
+
+    memcpy(slk->ent[i].form_text + offset,
+	   slk->ent[i].ent_text,
+	   (unsigned) numchrs);
+
+    if (offset < limit) {
+	memset(slk->ent[i].form_text + offset + numchrs,
+	       ' ',
+	       (unsigned) (limit - (offset + numcols)));
+    }
+
+    slk->ent[i].form_text[numchrs - numcols + limit] = 0;
+    slk->ent[i].dirty = TRUE;
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_slktouch.c b/ncurses/base/lib_slktouch.c
new file mode 100644
index 0000000..5eb5df3
--- /dev/null
+++ b/ncurses/base/lib_slktouch.c
@@ -0,0 +1,53 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	lib_slktouch.c
+ *	Soft key routines.
+ *      Force the code to believe that the soft keys have been changed.
+ */
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_slktouch.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_touch(void)
+{
+    T((T_CALLED("slk_touch()")));
+
+    if (SP == NULL || SP->_slk == NULL)
+	returnCode(ERR);
+    SP->_slk->dirty = TRUE;
+
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_touch.c b/ncurses/base/lib_touch.c
new file mode 100644
index 0000000..2ac21f2
--- /dev/null
+++ b/ncurses/base/lib_touch.c
@@ -0,0 +1,91 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_touch.c
+**
+**	   The routines	untouchwin(),
+**			wtouchln(),
+**			is_linetouched()
+**			is_wintouched().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_touch.c,v 1.9 2000/12/10 02:43:27 tom Exp $")
+
+NCURSES_EXPORT(bool)
+is_linetouched(WINDOW *win, int line)
+{
+    T((T_CALLED("is_linetouched(%p,%d)"), win, line));
+
+    /* XSI doesn't define any error */
+    if (!win || (line > win->_maxy) || (line < 0))
+	returnCode((bool) ERR);
+
+    returnCode(win->_line[line].firstchar != _NOCHANGE ? TRUE : FALSE);
+}
+
+NCURSES_EXPORT(bool)
+is_wintouched(WINDOW *win)
+{
+    int i;
+
+    T((T_CALLED("is_wintouched(%p)"), win));
+
+    if (win)
+	for (i = 0; i <= win->_maxy; i++)
+	    if (win->_line[i].firstchar != _NOCHANGE)
+		returnCode(TRUE);
+    returnCode(FALSE);
+}
+
+NCURSES_EXPORT(int)
+wtouchln(WINDOW *win, int y, int n, int changed)
+{
+    int i;
+
+    T((T_CALLED("wtouchln(%p,%d,%d,%d)"), win, y, n, changed));
+
+    if (!win || (n < 0) || (y < 0) || (y > win->_maxy))
+	returnCode(ERR);
+
+    for (i = y; i < y + n; i++) {
+	if (i > win->_maxy)
+	    break;
+	win->_line[i].firstchar = changed ? 0 : _NOCHANGE;
+	win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE;
+    }
+    returnCode(OK);
+}
diff --git a/ncurses/base/lib_ungetch.c b/ncurses/base/lib_ungetch.c
new file mode 100644
index 0000000..8742f86
--- /dev/null
+++ b/ncurses/base/lib_ungetch.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_ungetch.c
+**
+**	The routine ungetch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_ungetch.c,v 1.11 2008/05/31 16:44:54 tom Exp $")
+
+#include <fifo_defs.h>
+
+#ifdef TRACE
+NCURSES_EXPORT(void)
+_nc_fifo_dump(SCREEN *sp)
+{
+    int i;
+    T(("head = %d, tail = %d, peek = %d", head, tail, peek));
+    for (i = 0; i < 10; i++)
+	T(("char %d = %s", i, _nc_tracechar(sp, sp->_fifo[i])));
+}
+#endif /* TRACE */
+
+NCURSES_EXPORT(int)
+_nc_ungetch(SCREEN *sp, int ch)
+{
+    int rc = ERR;
+
+    if (tail != -1) {
+	if (head == -1) {
+	    head = 0;
+	    t_inc();
+	    peek = tail;	/* no raw keys */
+	} else
+	    h_dec();
+
+	sp->_fifo[head] = ch;
+	T(("ungetch %s ok", _nc_tracechar(sp, ch)));
+#ifdef TRACE
+	if (USE_TRACEF(TRACE_IEVENT)) {
+	    _nc_fifo_dump(sp);
+	    _nc_unlock_global(tracef);
+	}
+#endif
+	rc = OK;
+    }
+    return rc;
+}
+
+NCURSES_EXPORT(int)
+ungetch(int ch)
+{
+    T((T_CALLED("ungetch(%s)"), _nc_tracechar(SP, ch)));
+    returnCode(_nc_ungetch(SP, ch));
+}
diff --git a/ncurses/base/lib_vline.c b/ncurses/base/lib_vline.c
new file mode 100644
index 0000000..1a2537e
--- /dev/null
+++ b/ncurses/base/lib_vline.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_vline.c
+**
+**	The routine wvline().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_vline.c,v 1.10 2006/03/11 21:52:19 tom Exp $")
+
+NCURSES_EXPORT(int)
+wvline(WINDOW *win, chtype ch, int n)
+{
+    int code = ERR;
+    NCURSES_SIZE_T row, col;
+    NCURSES_SIZE_T end;
+
+    T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n));
+
+    if (win) {
+	NCURSES_CH_T wch;
+	row = win->_cury;
+	col = win->_curx;
+	end = row + n - 1;
+	if (end > win->_maxy)
+	    end = win->_maxy;
+
+	if (ch == 0)
+	    SetChar2(wch, ACS_VLINE);
+	else
+	    SetChar2(wch, ch);
+	wch = _nc_render(win, wch);
+
+	while (end >= row) {
+	    struct ldat *line = &(win->_line[end]);
+	    line->text[col] = wch;
+	    CHANGED_CELL(line, col);
+	    end--;
+	}
+
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/base/lib_wattroff.c b/ncurses/base/lib_wattroff.c
new file mode 100644
index 0000000..bf2020e
--- /dev/null
+++ b/ncurses/base/lib_wattroff.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_wattroff.c
+**
+**	The routine wattr_off().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_wattroff.c,v 1.9 2006/05/27 19:30:33 tom Exp $")
+
+NCURSES_EXPORT(int)
+wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
+{
+    T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at)));
+    if (win) {
+	T(("... current %s (%d)",
+	   _traceattr(WINDOW_ATTRS(win)),
+	   GET_WINDOW_PAIR(win)));
+
+	if_EXT_COLORS({
+	    if (at & A_COLOR)
+		win->_color = 0;
+	});
+	toggle_attr_off(WINDOW_ATTRS(win), at);
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_wattron.c b/ncurses/base/lib_wattron.c
new file mode 100644
index 0000000..2e17d96
--- /dev/null
+++ b/ncurses/base/lib_wattron.c
@@ -0,0 +1,64 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_wattron.c
+**
+**	The routines wattr_on().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_wattron.c,v 1.9 2006/05/27 19:30:46 tom Exp $")
+
+NCURSES_EXPORT(int)
+wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
+{
+    T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at)));
+    if (win != 0) {
+	T(("... current %s (%d)",
+	   _traceattr(WINDOW_ATTRS(win)),
+	   GET_WINDOW_PAIR(win)));
+
+	if_EXT_COLORS({
+	    if (at & A_COLOR)
+		win->_color = PAIR_NUMBER(at);
+	});
+	toggle_attr_on(WINDOW_ATTRS(win), at);
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
diff --git a/ncurses/base/lib_winch.c b/ncurses/base/lib_winch.c
new file mode 100644
index 0000000..18da9c5
--- /dev/null
+++ b/ncurses/base/lib_winch.c
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1998                        *
+ ****************************************************************************/
+
+/*
+**	lib_winch.c
+**
+**	The routine winch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_winch.c,v 1.5 2001/06/02 23:42:08 skimo Exp $")
+
+NCURSES_EXPORT(chtype)
+winch(WINDOW *win)
+{
+    T((T_CALLED("winch(%p)"), win));
+    if (win != 0) {
+	returnChar(CharOf(win->_line[win->_cury].text[win->_curx]) |
+		   AttrOf(win->_line[win->_cury].text[win->_curx]));
+    } else {
+	returnChar(0);
+    }
+}
diff --git a/ncurses/base/lib_window.c b/ncurses/base/lib_window.c
new file mode 100644
index 0000000..a3236e2
--- /dev/null
+++ b/ncurses/base/lib_window.c
@@ -0,0 +1,250 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_window.c
+**
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_window.c,v 1.25 2008/06/07 14:12:56 tom Exp $")
+
+NCURSES_EXPORT(void)
+_nc_synchook(WINDOW *win)
+/* hook to be called after each window change */
+{
+    if (win->_immed)
+	wrefresh(win);
+    if (win->_sync)
+	wsyncup(win);
+}
+
+NCURSES_EXPORT(int)
+mvderwin(WINDOW *win, int y, int x)
+/* move a derived window */
+{
+    WINDOW *orig;
+    int i;
+
+    T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x));
+
+    if (win && (orig = win->_parent)) {
+	if (win->_parx == x && win->_pary == y)
+	    returnCode(OK);
+	if (x < 0 || y < 0)
+	    returnCode(ERR);
+	if ((x + getmaxx(win) > getmaxx(orig)) ||
+	    (y + getmaxy(win) > getmaxy(orig)))
+	    returnCode(ERR);
+    } else
+	returnCode(ERR);
+    wsyncup(win);
+    win->_parx = x;
+    win->_pary = y;
+    for (i = 0; i < getmaxy(win); i++)
+	win->_line[i].text = &(orig->_line[y++].text[x]);
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+syncok(WINDOW *win, bool bf)
+/* enable/disable automatic wsyncup() on each change to window */
+{
+    T((T_CALLED("syncok(%p,%d)"), win, bf));
+
+    if (win) {
+	win->_sync = bf;
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
+
+NCURSES_EXPORT(void)
+wsyncup(WINDOW *win)
+/* mark changed every cell in win's ancestors that is changed in win */
+/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...)      */
+{
+    WINDOW *wp;
+
+    T((T_CALLED("wsyncup(%p)"), win));
+    if (win && win->_parent) {
+	for (wp = win; wp->_parent; wp = wp->_parent) {
+	    int y;
+	    WINDOW *pp = wp->_parent;
+
+	    assert((wp->_pary <= pp->_maxy) &&
+		   ((wp->_pary + wp->_maxy) <= pp->_maxy));
+
+	    for (y = 0; y <= wp->_maxy; y++) {
+		int left = wp->_line[y].firstchar;
+		if (left >= 0) {	/* line is touched */
+		    struct ldat *line = &(pp->_line[wp->_pary + y]);
+		    /* left & right character in parent window coordinates */
+		    int right = wp->_line[y].lastchar + wp->_parx;
+		    left += wp->_parx;
+
+		    CHANGED_RANGE(line, left, right);
+		}
+	    }
+	}
+    }
+    returnVoid;
+}
+
+NCURSES_EXPORT(void)
+wsyncdown(WINDOW *win)
+/* mark changed every cell in win that is changed in any of its ancestors */
+/* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...)           */
+{
+    T((T_CALLED("wsyncdown(%p)"), win));
+
+    if (win && win->_parent) {
+	WINDOW *pp = win->_parent;
+	int y;
+
+	/* This recursion guarantees, that the changes are propagated down-
+	   wards from the root to our direct parent. */
+	wsyncdown(pp);
+
+	/* and now we only have to propagate the changes from our direct
+	   parent, if there are any. */
+	assert((win->_pary <= pp->_maxy) &&
+	       ((win->_pary + win->_maxy) <= pp->_maxy));
+
+	for (y = 0; y <= win->_maxy; y++) {
+	    if (pp->_line[win->_pary + y].firstchar >= 0) {	/* parent changed */
+		struct ldat *line = &(win->_line[y]);
+		/* left and right character in child coordinates */
+		int left = pp->_line[win->_pary + y].firstchar - win->_parx;
+		int right = pp->_line[win->_pary + y].lastchar - win->_parx;
+		/* The change may be outside the child's range */
+		if (left < 0)
+		    left = 0;
+		if (right > win->_maxx)
+		    right = win->_maxx;
+		CHANGED_RANGE(line, left, right);
+	    }
+	}
+    }
+    returnVoid;
+}
+
+NCURSES_EXPORT(void)
+wcursyncup(WINDOW *win)
+/* sync the cursor in all derived windows to its value in the base window */
+{
+    WINDOW *wp;
+
+    T((T_CALLED("wcursyncup(%p)"), win));
+    for (wp = win; wp && wp->_parent; wp = wp->_parent) {
+	wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx);
+    }
+    returnVoid;
+}
+
+NCURSES_EXPORT(WINDOW *)
+dupwin(WINDOW *win)
+/* make an exact duplicate of the given window */
+{
+    WINDOW *nwin = 0;
+    size_t linesize;
+    int i;
+
+    T((T_CALLED("dupwin(%p)"), win));
+
+    if (win != 0) {
+
+	_nc_lock_global(curses);
+	if (win->_flags & _ISPAD) {
+	    nwin = newpad(win->_maxy + 1,
+			  win->_maxx + 1);
+	} else {
+	    nwin = newwin(win->_maxy + 1,
+			  win->_maxx + 1,
+			  win->_begy,
+			  win->_begx);
+	}
+
+	if (nwin != 0) {
+
+	    nwin->_curx = win->_curx;
+	    nwin->_cury = win->_cury;
+	    nwin->_maxy = win->_maxy;
+	    nwin->_maxx = win->_maxx;
+	    nwin->_begy = win->_begy;
+	    nwin->_begx = win->_begx;
+	    nwin->_yoffset = win->_yoffset;
+
+	    nwin->_flags = win->_flags & ~_SUBWIN;
+	    /* Due to the use of newwin(), the clone is not a subwindow.
+	     * The text is really copied into the clone.
+	     */
+
+	    WINDOW_ATTRS(nwin) = WINDOW_ATTRS(win);
+	    nwin->_nc_bkgd = win->_nc_bkgd;
+
+	    nwin->_notimeout = win->_notimeout;
+	    nwin->_clear = win->_clear;
+	    nwin->_leaveok = win->_leaveok;
+	    nwin->_scroll = win->_scroll;
+	    nwin->_idlok = win->_idlok;
+	    nwin->_idcok = win->_idcok;
+	    nwin->_immed = win->_immed;
+	    nwin->_sync = win->_sync;
+	    nwin->_use_keypad = win->_use_keypad;
+	    nwin->_delay = win->_delay;
+
+	    nwin->_parx = 0;
+	    nwin->_pary = 0;
+	    nwin->_parent = (WINDOW *) 0;
+	    /* See above: the clone isn't a subwindow! */
+
+	    nwin->_regtop = win->_regtop;
+	    nwin->_regbottom = win->_regbottom;
+
+	    if (win->_flags & _ISPAD)
+		nwin->_pad = win->_pad;
+
+	    linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T);
+	    for (i = 0; i <= nwin->_maxy; i++) {
+		memcpy(nwin->_line[i].text, win->_line[i].text, linesize);
+		nwin->_line[i].firstchar = win->_line[i].firstchar;
+		nwin->_line[i].lastchar = win->_line[i].lastchar;
+	    }
+	}
+	_nc_unlock_global(curses);
+    }
+    returnWin(nwin);
+}
diff --git a/ncurses/base/memmove.c b/ncurses/base/memmove.c
new file mode 100644
index 0000000..093ad72
--- /dev/null
+++ b/ncurses/base/memmove.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: memmove.c,v 1.5 2007/08/11 17:12:43 tom Exp $")
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1998                        *
+ ****************************************************************************/
+
+#if USE_MY_MEMMOVE
+#define DST ((char *)s1)
+#define SRC ((const char *)s2)
+NCURSES_EXPORT(void *)
+_nc_memmove(void *s1, const void *s2, size_t n)
+{
+    if (n != 0) {
+	if ((DST + n > SRC) && (SRC + n > DST)) {
+	    static char *bfr;
+	    static size_t length;
+	    register size_t j;
+	    if (length < n) {
+		length = (n * 3) / 2;
+		bfr = typeRealloc(char, length, bfr);
+	    }
+	    for (j = 0; j < n; j++)
+		bfr[j] = SRC[j];
+	    s2 = bfr;
+	}
+	while (n-- != 0)
+	    DST[n] = SRC[n];
+    }
+    return s1;
+}
+#else
+extern
+NCURSES_EXPORT(void)
+_nc_memmove(void);		/* quiet's gcc warning */
+NCURSES_EXPORT(void)
+_nc_memmove(void)
+{
+}				/* nonempty for strict ANSI compilers */
+#endif /* USE_MY_MEMMOVE */
diff --git a/ncurses/base/nc_panel.c b/ncurses/base/nc_panel.c
new file mode 100644
index 0000000..59bfbbe
--- /dev/null
+++ b/ncurses/base/nc_panel.c
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: nc_panel.c,v 1.4 2000/12/10 02:43:28 tom Exp $")
+
+NCURSES_EXPORT(struct panelhook *)
+_nc_panelhook(void)
+{
+    return (SP ? &(SP->_panelHook) : NULL);
+}
diff --git a/ncurses/base/resizeterm.c b/ncurses/base/resizeterm.c
new file mode 100644
index 0000000..a94cfc3
--- /dev/null
+++ b/ncurses/base/resizeterm.c
@@ -0,0 +1,455 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+ * This is an extension to the curses library.  It provides callers with a hook
+ * into the NCURSES data to resize windows, primarily for use by programs
+ * running in an X Window terminal (e.g., xterm).  I abstracted this module
+ * from my application library for NCURSES because it must be compiled with
+ * the private data structures -- T.Dickey 1995/7/4.
+ */
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: resizeterm.c,v 1.34 2008/06/07 13:58:40 tom Exp $")
+
+#define stolen_lines (screen_lines - SP->_lines_avail)
+
+/*
+ * If we're trying to be reentrant, do not want any local statics.
+ */
+#if USE_REENTRANT
+#define EXTRA_ARGS ,     CurLines,     CurCols
+#define EXTRA_DCLS , int CurLines, int CurCols
+#else
+static int current_lines;
+static int current_cols;
+#define CurLines current_lines
+#define CurCols  current_cols
+#define EXTRA_ARGS		/* nothing */
+#define EXTRA_DCLS		/* nothing */
+#endif
+
+#ifdef TRACE
+static void
+show_window_sizes(const char *name)
+{
+    WINDOWLIST *wp;
+
+    _nc_lock_global(curses);
+    _tracef("%s resizing: %2d x %2d (%2d x %2d)", name, LINES, COLS,
+	    screen_lines, screen_columns);
+    for (each_window(wp)) {
+	_tracef("  window %p is %2ld x %2ld at %2ld,%2ld",
+		&(wp->win),
+		(long) wp->win._maxy + 1,
+		(long) wp->win._maxx + 1,
+		(long) wp->win._begy,
+		(long) wp->win._begx);
+    }
+    _nc_unlock_global(curses);
+}
+#endif
+
+/*
+ * Return true if the given dimensions do not match the internal terminal
+ * structure's size.
+ */
+NCURSES_EXPORT(bool)
+is_term_resized(int ToLines, int ToCols)
+{
+    T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols));
+    returnCode(ToLines > 0
+	       && ToCols > 0
+	       && (ToLines != screen_lines
+		   || ToCols != screen_columns));
+}
+
+/*
+ */
+static ripoff_t *
+ripped_window(WINDOW *win)
+{
+    ripoff_t *result = 0;
+    ripoff_t *rop;
+
+    if (win != 0) {
+	for (each_ripoff(rop)) {
+	    if (rop->win == win && rop->line != 0) {
+		result = rop;
+		break;
+	    }
+	}
+    }
+    return result;
+}
+
+/*
+ * Returns the number of lines from the bottom for the beginning of a ripped
+ * off window.
+ */
+static int
+ripped_bottom(WINDOW *win)
+{
+    int result = 0;
+    ripoff_t *rop;
+
+    if (win != 0) {
+	for (each_ripoff(rop)) {
+	    if (rop->line < 0) {
+		result -= rop->line;
+		if (rop->win == win) {
+		    break;
+		}
+	    }
+	}
+    }
+    return result;
+}
+
+/*
+ * Return the number of levels of child-windows under the current window.
+ */
+static int
+child_depth(WINDOW *cmp)
+{
+    int depth = 0;
+
+    if (cmp != 0) {
+	WINDOWLIST *wp;
+
+	for (each_window(wp)) {
+	    WINDOW *tst = &(wp->win);
+	    if (tst->_parent == cmp) {
+		depth = 1 + child_depth(tst);
+		break;
+	    }
+	}
+    }
+    return depth;
+}
+
+/*
+ * Return the number of levels of parent-windows above the current window.
+ */
+static int
+parent_depth(WINDOW *cmp)
+{
+    int depth = 0;
+
+    if (cmp != 0) {
+	WINDOW *tst;
+	while ((tst = cmp->_parent) != 0) {
+	    ++depth;
+	    cmp = tst;
+	}
+    }
+    return depth;
+}
+
+/*
+ * FIXME: must adjust position so it's within the parent!
+ */
+static int
+adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
+{
+    int result;
+    int bottom = CurLines + SP->_topstolen - stolen;
+    int myLines = win->_maxy + 1;
+    int myCols = win->_maxx + 1;
+    ripoff_t *rop = ripped_window(win);
+
+    T((T_CALLED("adjust_window(%p,%d,%d)%s depth %d/%d currently %ldx%ld at %ld,%ld"),
+       win, ToLines, ToCols,
+       (rop != 0) ? " (rip)" : "",
+       parent_depth(win),
+       child_depth(win),
+       (long) getmaxy(win), (long) getmaxx(win),
+       (long) getbegy(win) + win->_yoffset, (long) getbegx(win)));
+
+    if (rop != 0 && rop->line < 0) {
+	/*
+	 * If it is a ripped-off window at the bottom of the screen, simply
+	 * move it to the same relative position.
+	 */
+	win->_begy = ToLines - ripped_bottom(win) - 0 - win->_yoffset;
+    } else if (win->_begy >= bottom) {
+	/*
+	 * If it is below the bottom of the new screen, move up by the same
+	 * amount that the screen shrank.
+	 */
+	win->_begy += (ToLines - CurLines);
+    } else {
+	if (myLines == (CurLines - stolen)
+	    && ToLines != CurLines) {
+	    myLines = ToLines - stolen;
+	} else if (myLines == CurLines
+		   && ToLines != CurLines) {
+	    myLines = ToLines;
+	}
+    }
+
+    if (myLines > ToLines) {
+	myLines = ToLines;
+    }
+
+    if (myCols > ToCols)
+	myCols = ToCols;
+
+    if (myCols == CurCols
+	&& ToCols != CurCols)
+	myCols = ToCols;
+
+    result = wresize(win, myLines, myCols);
+    returnCode(result);
+}
+
+/*
+ * If we're decreasing size, recursively search for windows that have no
+ * children, decrease those to fit, then decrease the containing window, etc.
+ */
+static int
+decrease_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
+{
+    bool found;
+    int depth = 0;
+    WINDOWLIST *wp;
+
+    T((T_CALLED("decrease_size(%d, %d)"), ToLines, ToCols));
+
+    do {
+	found = FALSE;
+	TR(TRACE_UPDATE, ("decreasing size of windows to %dx%d, depth=%d",
+			  ToLines, ToCols, depth));
+	for (each_window(wp)) {
+	    WINDOW *win = &(wp->win);
+
+	    if (!(win->_flags & _ISPAD)) {
+		if (child_depth(win) == depth) {
+		    found = TRUE;
+		    if (adjust_window(win, ToLines, ToCols,
+				      stolen EXTRA_ARGS) != OK)
+			returnCode(ERR);
+		}
+	    }
+	}
+	++depth;
+    } while (found);
+    returnCode(OK);
+}
+
+/*
+ * If we're increasing size, recursively search for windows that have no
+ * parent, increase those to fit, then increase the contained window, etc.
+ */
+static int
+increase_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
+{
+    bool found;
+    int depth = 0;
+    WINDOWLIST *wp;
+
+    T((T_CALLED("increase_size(%d, %d)"), ToLines, ToCols));
+
+    do {
+	found = FALSE;
+	TR(TRACE_UPDATE, ("increasing size of windows to %dx%d, depth=%d",
+			  ToLines, ToCols, depth));
+	for (each_window(wp)) {
+	    WINDOW *win = &(wp->win);
+
+	    if (!(win->_flags & _ISPAD)) {
+		if (parent_depth(win) == depth) {
+		    found = TRUE;
+		    if (adjust_window(win, ToLines, ToCols,
+				      stolen EXTRA_ARGS) != OK)
+			returnCode(ERR);
+		}
+	    }
+	}
+	++depth;
+    } while (found);
+    returnCode(OK);
+}
+
+/*
+ * This function reallocates NCURSES window structures, with no side-effects
+ * such as ungetch().
+ */
+NCURSES_EXPORT(int)
+resize_term(int ToLines, int ToCols)
+{
+    int result = OK EXTRA_ARGS;
+    int was_stolen;
+
+    T((T_CALLED("resize_term(%d,%d) old(%d,%d)"),
+       ToLines, ToCols,
+       screen_lines, screen_columns));
+
+    if (SP == 0) {
+	returnCode(ERR);
+    }
+
+    _nc_lock_global(curses);
+
+    was_stolen = (screen_lines - SP->_lines_avail);
+    if (is_term_resized(ToLines, ToCols)) {
+	int myLines = CurLines = screen_lines;
+	int myCols = CurCols = screen_columns;
+
+#ifdef TRACE
+	if (USE_TRACEF(TRACE_UPDATE)) {
+	    show_window_sizes("before");
+	    _nc_unlock_global(tracef);
+	}
+#endif
+	if (ToLines > screen_lines) {
+	    increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS);
+	    CurLines = myLines;
+	    CurCols = myCols;
+	}
+
+	if (ToCols > screen_columns) {
+	    increase_size(myLines, myCols = ToCols, was_stolen EXTRA_ARGS);
+	    CurLines = myLines;
+	    CurCols = myCols;
+	}
+
+	if (ToLines < myLines ||
+	    ToCols < myCols) {
+	    decrease_size(ToLines, ToCols, was_stolen EXTRA_ARGS);
+	}
+
+	screen_lines = lines = ToLines;
+	screen_columns = columns = ToCols;
+
+	SP->_lines_avail = lines - was_stolen;
+
+	if (SP->oldhash) {
+	    FreeAndNull(SP->oldhash);
+	}
+	if (SP->newhash) {
+	    FreeAndNull(SP->newhash);
+	}
+#ifdef TRACE
+	if (USE_TRACEF(TRACE_UPDATE)) {
+	    SET_LINES(ToLines - was_stolen);
+	    SET_COLS(ToCols);
+	    show_window_sizes("after");
+	    _nc_unlock_global(tracef);
+	}
+#endif
+    }
+
+    /*
+     * Always update LINES, to allow for call from lib_doupdate.c which
+     * needs to have the count adjusted by the stolen (ripped off) lines.
+     */
+    SET_LINES(ToLines - was_stolen);
+    SET_COLS(ToCols);
+
+    _nc_unlock_global(curses);
+
+    returnCode(result);
+}
+
+/*
+ * This function reallocates NCURSES window structures.  It is invoked in
+ * response to a SIGWINCH interrupt.  Other user-defined windows may also need
+ * to be reallocated.
+ *
+ * Because this performs memory allocation, it should not (in general) be
+ * invoked directly from the signal handler.
+ */
+NCURSES_EXPORT(int)
+resizeterm(int ToLines, int ToCols)
+{
+    int result = ERR;
+
+    T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
+       ToLines, ToCols,
+       screen_lines, screen_columns));
+
+    if (SP != 0) {
+	result = OK;
+	SP->_sig_winch = FALSE;
+
+	if (is_term_resized(ToLines, ToCols)) {
+#if USE_SIGWINCH
+	    ripoff_t *rop;
+	    bool slk_visible = (SP != 0
+				&& SP->_slk != 0
+				&& !(SP->_slk->hidden));
+
+	    if (slk_visible) {
+		slk_clear();
+	    }
+#endif
+	    result = resize_term(ToLines, ToCols);
+
+#if USE_SIGWINCH
+	    _nc_ungetch(SP, KEY_RESIZE);	/* so application can know this */
+	    clearok(curscr, TRUE);	/* screen contents are unknown */
+
+	    /* ripped-off lines are a special case: if we did not lengthen
+	     * them, we haven't moved them either.  repaint them, too.
+	     *
+	     * for the rest - stdscr and other windows - the client has to
+	     * decide which to repaint, since without panels, ncurses does
+	     * not know which are really on top.
+	     */
+	    for (each_ripoff(rop)) {
+		if (rop->win != stdscr
+		    && rop->win != 0
+		    && rop->line < 0) {
+
+		    if (rop->hook != _nc_slk_initialize) {
+			touchwin(rop->win);
+			wnoutrefresh(rop->win);
+		    }
+		}
+	    }
+
+	    /* soft-keys are a special case: we _know_ how to repaint them */
+	    if (slk_visible) {
+		slk_restore();
+		slk_touch();
+
+		slk_refresh();
+	    }
+#endif
+	}
+    }
+
+    returnCode(result);
+}
diff --git a/ncurses/base/safe_sprintf.c b/ncurses/base/safe_sprintf.c
new file mode 100644
index 0000000..8fc5d89
--- /dev/null
+++ b/ncurses/base/safe_sprintf.c
@@ -0,0 +1,264 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: safe_sprintf.c,v 1.20 2007/04/21 22:28:06 tom Exp $")
+
+#if USE_SAFE_SPRINTF
+
+typedef enum {
+    Flags, Width, Prec, Type, Format
+} PRINTF;
+
+#define VA_INTGR(type) ival = va_arg(ap, type)
+#define VA_FLOAT(type) fval = va_arg(ap, type)
+#define VA_POINT(type) pval = (void *)va_arg(ap, type)
+
+/*
+ * Scan a variable-argument list for printf to determine the number of
+ * characters that would be emitted.
+ */
+static int
+_nc_printf_length(const char *fmt, va_list ap)
+{
+    size_t length = BUFSIZ;
+    char *buffer;
+    char *format;
+    int len = 0;
+    size_t fmt_len;
+    char fmt_arg[BUFSIZ];
+
+    if (fmt == 0 || *fmt == '\0')
+	return 0;
+    fmt_len = strlen(fmt) + 1;
+    if ((format = typeMalloc(char, fmt_len)) == 0)
+	  return -1;
+    if ((buffer = typeMalloc(char, length)) == 0) {
+	free(format);
+	return -1;
+    }
+
+    while (*fmt != '\0') {
+	if (*fmt == '%') {
+	    static char dummy[] = "";
+	    PRINTF state = Flags;
+	    char *pval = dummy;	/* avoid const-cast */
+	    double fval = 0.0;
+	    int done = FALSE;
+	    int ival = 0;
+	    int prec = -1;
+	    int type = 0;
+	    int used = 0;
+	    int width = -1;
+	    size_t f = 0;
+
+	    format[f++] = *fmt;
+	    while (*++fmt != '\0' && len >= 0 && !done) {
+		format[f++] = *fmt;
+
+		if (isdigit(UChar(*fmt))) {
+		    int num = *fmt - '0';
+		    if (state == Flags && num != 0)
+			state = Width;
+		    if (state == Width) {
+			if (width < 0)
+			    width = 0;
+			width = (width * 10) + num;
+		    } else if (state == Prec) {
+			if (prec < 0)
+			    prec = 0;
+			prec = (prec * 10) + num;
+		    }
+		} else if (*fmt == '*') {
+		    VA_INTGR(int);
+		    if (state == Flags)
+			state = Width;
+		    if (state == Width) {
+			width = ival;
+		    } else if (state == Prec) {
+			prec = ival;
+		    }
+		    sprintf(fmt_arg, "%d", ival);
+		    fmt_len += strlen(fmt_arg);
+		    if ((format = realloc(format, fmt_len)) == 0) {
+			return -1;
+		    }
+		    strcpy(&format[--f], fmt_arg);
+		    f = strlen(format);
+		} else if (isalpha(UChar(*fmt))) {
+		    done = TRUE;
+		    switch (*fmt) {
+		    case 'Z':	/* FALLTHRU */
+		    case 'h':	/* FALLTHRU */
+		    case 'l':	/* FALLTHRU */
+			done = FALSE;
+			type = *fmt;
+			break;
+		    case 'i':	/* FALLTHRU */
+		    case 'd':	/* FALLTHRU */
+		    case 'u':	/* FALLTHRU */
+		    case 'x':	/* FALLTHRU */
+		    case 'X':	/* FALLTHRU */
+			if (type == 'l')
+			    VA_INTGR(long);
+			else if (type == 'Z')
+			    VA_INTGR(size_t);
+			else
+			    VA_INTGR(int);
+			used = 'i';
+			break;
+		    case 'f':	/* FALLTHRU */
+		    case 'e':	/* FALLTHRU */
+		    case 'E':	/* FALLTHRU */
+		    case 'g':	/* FALLTHRU */
+		    case 'G':	/* FALLTHRU */
+			VA_FLOAT(double);
+			used = 'f';
+			break;
+		    case 'c':
+			VA_INTGR(int);
+			used = 'i';
+			break;
+		    case 's':
+			VA_POINT(char *);
+			if (prec < 0)
+			    prec = strlen(pval);
+			if (prec > (int) length) {
+			    length = length + prec;
+			    buffer = typeRealloc(char, length, buffer);
+			    if (buffer == 0) {
+				free(format);
+				return -1;
+			    }
+			}
+			used = 'p';
+			break;
+		    case 'p':
+			VA_POINT(void *);
+			used = 'p';
+			break;
+		    case 'n':
+			VA_POINT(int *);
+			used = 0;
+			break;
+		    default:
+			break;
+		    }
+		} else if (*fmt == '.') {
+		    state = Prec;
+		} else if (*fmt == '%') {
+		    done = TRUE;
+		    used = 'p';
+		}
+	    }
+	    format[f] = '\0';
+	    switch (used) {
+	    case 'i':
+		sprintf(buffer, format, ival);
+		break;
+	    case 'f':
+		sprintf(buffer, format, fval);
+		break;
+	    default:
+		sprintf(buffer, format, pval);
+		break;
+	    }
+	    len += (int) strlen(buffer);
+	} else {
+	    fmt++;
+	    len++;
+	}
+    }
+
+    free(buffer);
+    free(format);
+    return len;
+}
+#endif
+
+#define my_buffer _nc_globals.safeprint_buf
+#define my_length _nc_globals.safeprint_used
+
+/*
+ * Wrapper for vsprintf that allocates a buffer big enough to hold the result.
+ */
+NCURSES_EXPORT(char *)
+_nc_printf_string(const char *fmt, va_list ap)
+{
+    char *result = 0;
+
+    if (fmt != 0) {
+#if USE_SAFE_SPRINTF
+	int len = _nc_printf_length(fmt, ap);
+
+	if ((int) my_length < len + 1) {
+	    my_length = 2 * (len + 1);
+	    my_buffer = typeRealloc(char, my_length, my_buffer);
+	}
+	if (my_buffer != 0) {
+	    *my_buffer = '\0';
+	    if (len >= 0) {
+		vsprintf(my_buffer, fmt, ap);
+	    }
+	    result = my_buffer;
+	}
+#else
+#define MyCols _nc_globals.safeprint_cols
+#define MyRows _nc_globals.safeprint_rows
+
+	if (screen_lines > MyRows || screen_columns > MyCols) {
+	    if (screen_lines > MyRows)
+		MyRows = screen_lines;
+	    if (screen_columns > MyCols)
+		MyCols = screen_columns;
+	    my_length = (MyRows * (MyCols + 1)) + 1;
+	    my_buffer = typeRealloc(char, my_length, my_buffer);
+	}
+
+	if (my_buffer != 0) {
+# if HAVE_VSNPRINTF
+	    vsnprintf(my_buffer, my_length, fmt, ap);	/* GNU extension */
+# else
+	    vsprintf(my_buffer, fmt, ap);	/* ANSI */
+# endif
+	    result = my_buffer;
+	}
+#endif
+    } else if (my_buffer != 0) {	/* see _nc_freeall() */
+	free(my_buffer);
+	my_buffer = 0;
+	my_length = 0;
+    }
+    return result;
+}
diff --git a/ncurses/base/sigaction.c b/ncurses/base/sigaction.c
new file mode 100644
index 0000000..36442e0
--- /dev/null
+++ b/ncurses/base/sigaction.c
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-2003               *
+ ****************************************************************************/
+
+/* This file provides sigaction() emulation using sigvec() */
+/* Use only if this is non POSIX system */
+
+MODULE_ID("$Id: sigaction.c,v 1.14 2003/12/07 01:06:52 tom Exp $")
+
+static int
+_nc_sigaction(int sig, sigaction_t * sigact, sigaction_t * osigact)
+{
+    return sigvec(sig, sigact, osigact);
+}
+
+static int
+_nc_sigemptyset(sigset_t * mask)
+{
+    *mask = 0;
+    return 0;
+}
+
+static int
+_nc_sigprocmask(int mode, sigset_t * mask, sigset_t * omask)
+{
+    sigset_t current = sigsetmask(0);
+
+    if (omask)
+	*omask = current;
+
+    if (mode == SIG_BLOCK)
+	current |= *mask;
+    else if (mode == SIG_UNBLOCK)
+	current &= ~*mask;
+    else if (mode == SIG_SETMASK)
+	current = *mask;
+
+    sigsetmask(current);
+    return 0;
+}
+
+static int
+_nc_sigaddset(sigset_t * mask, int sig)
+{
+    *mask |= sigmask(sig);
+    return 0;
+}
+
+/* not used in lib_tstp.c */
+#if 0
+static int
+_nc_sigsuspend(sigset_t * mask)
+{
+    return sigpause(*mask);
+}
+
+static int
+_nc_sigdelset(sigset_t * mask, int sig)
+{
+    *mask &= ~sigmask(sig);
+    return 0;
+}
+
+static int
+_nc_sigismember(sigset_t * mask, int sig)
+{
+    return (*mask & sigmask(sig)) != 0;
+}
+#endif
diff --git a/ncurses/base/tries.c b/ncurses/base/tries.c
new file mode 100644
index 0000000..c4263c7
--- /dev/null
+++ b/ncurses/base/tries.c
@@ -0,0 +1,143 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ ****************************************************************************/
+
+/*
+**	tries.c
+**
+**	Functions to manage the tree of partial-completions for keycodes.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: tries.c,v 1.27 2008/08/16 19:22:55 tom Exp $")
+
+/*
+ * Expand a keycode into the string that it corresponds to, returning null if
+ * no match was found, otherwise allocating a string of the result.
+ */
+NCURSES_EXPORT(char *)
+_nc_expand_try(TRIES * tree, unsigned code, int *count, size_t len)
+{
+    TRIES *ptr = tree;
+    char *result = 0;
+
+    if (code != 0) {
+	while (ptr != 0) {
+	    if ((result = _nc_expand_try(ptr->child, code, count, len + 1))
+		!= 0) {
+		break;
+	    }
+	    if (ptr->value == code) {
+		*count -= 1;
+		if (*count == -1) {
+		    result = typeCalloc(char, len + 2);
+		    break;
+		}
+	    }
+	    ptr = ptr->sibling;
+	}
+    }
+    if (result != 0) {
+	if (ptr != 0 && (result[len] = (char) ptr->ch) == 0)
+	    *((unsigned char *) (result + len)) = 128;
+#ifdef TRACE
+	if (len == 0 && USE_TRACEF(TRACE_MAXIMUM)) {
+	    _tracef("expand_key %s %s", _nc_tracechar(SP, code), _nc_visbuf(result));
+	    _nc_unlock_global(tracef);
+	}
+#endif
+    }
+    return result;
+}
+
+/*
+ * Remove a code from the specified tree, freeing the unused nodes.  Returns
+ * true if the code was found/removed.
+ */
+NCURSES_EXPORT(int)
+_nc_remove_key(TRIES ** tree, unsigned code)
+{
+    T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code));
+
+    if (code == 0)
+	returnCode(FALSE);
+
+    while (*tree != 0) {
+	if (_nc_remove_key(&(*tree)->child, code)) {
+	    returnCode(TRUE);
+	}
+	if ((*tree)->value == code) {
+	    if ((*tree)->child) {
+		/* don't cut the whole sub-tree */
+		(*tree)->value = 0;
+	    } else {
+		TRIES *to_free = *tree;
+		*tree = (*tree)->sibling;
+		free(to_free);
+	    }
+	    returnCode(TRUE);
+	}
+	tree = &(*tree)->sibling;
+    }
+    returnCode(FALSE);
+}
+
+/*
+ * Remove a string from the specified tree, freeing the unused nodes.  Returns
+ * true if the string was found/removed.
+ */
+NCURSES_EXPORT(int)
+_nc_remove_string(TRIES ** tree, const char *string)
+{
+    T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string)));
+
+    if (string == 0 || *string == 0)
+	returnCode(FALSE);
+
+    while (*tree != 0) {
+	if (UChar((*tree)->ch) == UChar(*string)) {
+	    if (string[1] != 0)
+		returnCode(_nc_remove_string(&(*tree)->child, string + 1));
+	    if ((*tree)->child == 0) {
+		TRIES *to_free = *tree;
+		*tree = (*tree)->sibling;
+		free(to_free);
+		returnCode(TRUE);
+	    } else {
+		returnCode(FALSE);
+	    }
+	}
+	tree = &(*tree)->sibling;
+    }
+    returnCode(FALSE);
+}
diff --git a/ncurses/base/use_window.c b/ncurses/base/use_window.c
new file mode 100644
index 0000000..f6408c3
--- /dev/null
+++ b/ncurses/base/use_window.c
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * Copyright (c) 2007,2008 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *     Author: Thomas E. Dickey                        2007                 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: use_window.c,v 1.8 2008/06/07 14:13:46 tom Exp $")
+
+NCURSES_EXPORT(int)
+use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data)
+{
+    int code = OK;
+
+    T((T_CALLED("use_window(%p,%p,%p)"), win, func, data));
+    _nc_lock_global(curses);
+    code = func(win, data);
+    _nc_unlock_global(curses);
+
+    returnCode(code);
+}
diff --git a/ncurses/base/version.c b/ncurses/base/version.c
new file mode 100644
index 0000000..ef83967
--- /dev/null
+++ b/ncurses/base/version.c
@@ -0,0 +1,42 @@
+/****************************************************************************
+ * Copyright (c) 1999-2004,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1999                        *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: version.c,v 1.6 2005/01/02 01:23:54 tom Exp $")
+
+NCURSES_EXPORT(const char *)
+curses_version(void)
+{
+    T((T_CALLED("curses_version()")));
+    returnCPtr("ncurses " NCURSES_VERSION_STRING);
+}
diff --git a/ncurses/base/vsscanf.c b/ncurses/base/vsscanf.c
new file mode 100644
index 0000000..e6253c3
--- /dev/null
+++ b/ncurses/base/vsscanf.c
@@ -0,0 +1,356 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  State-machine fallback written by Thomas E. Dickey 2002                 *
+ ****************************************************************************/
+
+/*
+ * This function is needed to support vwscanw
+ */
+
+#include <curses.priv.h>
+
+#if !HAVE_VSSCANF
+
+MODULE_ID("$Id: vsscanf.c,v 1.18 2004/04/03 20:27:02 tom Exp $")
+
+#if !(HAVE_VFSCANF || HAVE__DOSCAN)
+
+#include <ctype.h>
+
+#define L_SQUARE '['
+#define R_SQUARE ']'
+
+typedef enum {
+    cUnknown
+    ,cError			/* anything that isn't ANSI */
+    ,cAssigned
+    ,cChar
+    ,cInt
+    ,cFloat
+    ,cDouble
+    ,cPointer
+    ,cLong
+    ,cShort
+    ,cRange
+    ,cString
+} ChunkType;
+
+typedef enum {
+    oUnknown
+    ,oShort
+    ,oLong
+} OtherType;
+
+typedef enum {
+    sUnknown
+    ,sPercent			/* last was '%' beginning a format */
+    ,sNormal			/* ...somewhere in the middle */
+    ,sLeft			/* last was left square bracket beginning a range */
+    ,sRange			/* ...somewhere in the middle */
+    ,sFinal			/* last finished a format */
+} ScanState;
+
+static ChunkType
+final_ch(int ch, OtherType other)
+{
+    ChunkType result = cUnknown;
+
+    switch (ch) {
+    case 'c':
+	if (other == oUnknown)
+	    result = cChar;
+	else
+	    result = cError;
+	break;
+    case 'd':
+    case 'i':
+    case 'X':
+    case 'x':
+	switch (other) {
+	case oUnknown:
+	    result = cInt;
+	    break;
+	case oShort:
+	    result = cShort;
+	    break;
+	case oLong:
+	    result = cLong;
+	    break;
+	}
+	break;
+    case 'E':
+    case 'e':
+    case 'f':
+    case 'g':
+	switch (other) {
+	case oUnknown:
+	    result = cFloat;
+	    break;
+	case oShort:
+	    result = cError;
+	    break;
+	case oLong:
+	    result = cDouble;
+	    break;
+	}
+	break;
+    case 'n':
+	if (other == oUnknown)
+	    result = cAssigned;
+	else
+	    result = cError;
+	break;
+    case 'p':
+	if (other == oUnknown)
+	    result = cPointer;
+	else
+	    result = cError;
+	break;
+    case 's':
+	if (other == oUnknown)
+	    result = cString;
+	else
+	    result = cError;
+	break;
+    }
+    return result;
+}
+
+static OtherType
+other_ch(int ch)
+{
+    OtherType result = oUnknown;
+    switch (ch) {
+    case 'h':
+	result = oShort;
+	break;
+    case 'l':
+	result = oLong;
+	break;
+    }
+    return result;
+}
+#endif
+
+/*VARARGS2*/
+NCURSES_EXPORT(int)
+vsscanf(const char *str, const char *format, va_list ap)
+{
+#if HAVE_VFSCANF || HAVE__DOSCAN
+    /*
+     * This code should work on anything descended from AT&T SVr1.
+     */
+    FILE strbuf;
+
+    strbuf._flag = _IOREAD;
+    strbuf._ptr = strbuf._base = (unsigned char *) str;
+    strbuf._cnt = strlen(str);
+    strbuf._file = _NFILE;
+
+#if HAVE_VFSCANF
+    return (vfscanf(&strbuf, format, ap));
+#else
+    return (_doscan(&strbuf, format, ap));
+#endif
+#else
+    static int can_convert = -1;
+
+    int assigned = 0;
+    int consumed = 0;
+
+    T((T_CALLED("vsscanf(%s,%s,...)"),
+       _nc_visbuf2(1, str),
+       _nc_visbuf2(2, format)));
+
+    /*
+     * This relies on having a working "%n" format conversion.  Check if it
+     * works.  Only very old C libraries do not support it.
+     *
+     * FIXME: move this check into the configure script.
+     */
+    if (can_convert < 0) {
+	int check1;
+	int check2;
+	if (sscanf("123", "%d%n", &check1, &check2) > 0
+	    && check1 == 123
+	    && check2 == 3) {
+	    can_convert = 1;
+	} else {
+	    can_convert = 0;
+	}
+    }
+
+    if (can_convert) {
+	size_t len_fmt = strlen(format) + 32;
+	char *my_fmt = malloc(len_fmt);
+	ChunkType chunk, ctest;
+	OtherType other, otest;
+	ScanState state;
+	unsigned n;
+	int eaten;
+	void *pointer;
+
+	if (my_fmt != 0) {
+	    /*
+	     * Split the original format into chunks, adding a "%n" to the end
+	     * of each (except of course if it used %n), and use that
+	     * information to decide where to start scanning the next chunk.
+	     *
+	     * FIXME:  does %n count bytes or characters?  If the latter, this
+	     * will require further work for multibyte strings.
+	     */
+	    while (*format != '\0') {
+		/* find a chunk */
+		state = sUnknown;
+		chunk = cUnknown;
+		other = oUnknown;
+		pointer = 0;
+		for (n = 0; format[n] != 0 && state != sFinal; ++n) {
+		    my_fmt[n] = format[n];
+		    switch (state) {
+		    case sUnknown:
+			if (format[n] == '%')
+			    state = sPercent;
+			break;
+		    case sPercent:
+			if (format[n] == '%') {
+			    state = sUnknown;
+			} else if (format[n] == L_SQUARE) {
+			    state = sLeft;
+			} else {
+			    state = sNormal;
+			    --n;
+			}
+			break;
+		    case sLeft:
+			state = sRange;
+			if (format[n] == '^') {
+			    ++n;
+			    my_fmt[n] = format[n];
+			}
+			break;
+		    case sRange:
+			if (format[n] == R_SQUARE) {
+			    state = sFinal;
+			    chunk = cRange;
+			}
+			break;
+		    case sNormal:
+			if (format[n] == '*') {
+			    state = sUnknown;
+			} else {
+			    if ((ctest = final_ch(format[n], other)) != cUnknown) {
+				state = sFinal;
+				chunk = ctest;
+			    } else if ((otest = other_ch(format[n])) != oUnknown) {
+				other = otest;
+			    } else if (isalpha(UChar(format[n]))) {
+				state = sFinal;
+				chunk = cError;
+			    }
+			}
+			break;
+		    case sFinal:
+			break;
+		    }
+		}
+		my_fmt[n] = '\0';
+		format += n;
+
+		if (chunk == cUnknown
+		    || chunk == cError) {
+		    if (assigned == 0)
+			assigned = EOF;
+		    break;
+		}
+
+		/* add %n, if the format was not that */
+		if (chunk != cAssigned) {
+		    strcat(my_fmt, "%n");
+		}
+
+		switch (chunk) {
+		case cAssigned:
+		    strcat(my_fmt, "%n");
+		    pointer = &eaten;
+		    break;
+		case cInt:
+		    pointer = va_arg(ap, int *);
+		    break;
+		case cShort:
+		    pointer = va_arg(ap, short *);
+		    break;
+		case cFloat:
+		    pointer = va_arg(ap, float *);
+		    break;
+		case cDouble:
+		    pointer = va_arg(ap, double *);
+		    break;
+		case cLong:
+		    pointer = va_arg(ap, long *);
+		    break;
+		case cPointer:
+		    pointer = va_arg(ap, void *);
+		    break;
+		case cChar:
+		case cRange:
+		case cString:
+		    pointer = va_arg(ap, char *);
+		    break;
+		case cError:
+		case cUnknown:
+		    break;
+		}
+		/* do the conversion */
+		T(("...converting chunk #%d type %d(%s,%s)",
+		   assigned + 1, chunk,
+		   _nc_visbuf2(1, str + consumed),
+		   _nc_visbuf2(2, my_fmt)));
+		if (sscanf(str + consumed, my_fmt, pointer, &eaten) > 0)
+		    consumed += eaten;
+		else
+		    break;
+		++assigned;
+	    }
+	    free(my_fmt);
+	}
+    }
+    returnCode(assigned);
+#endif
+}
+#else
+extern
+NCURSES_EXPORT(void)
+_nc_vsscanf(void);		/* quiet's gcc warning */
+NCURSES_EXPORT(void)
+_nc_vsscanf(void)
+{
+}				/* nonempty for strict ANSI compilers */
+#endif /* !HAVE_VSSCANF */
diff --git a/ncurses/base/wresize.c b/ncurses/base/wresize.c
new file mode 100644
index 0000000..f46085a
--- /dev/null
+++ b/ncurses/base/wresize.c
@@ -0,0 +1,246 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 1996-2002                                      *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: wresize.c,v 1.29 2008/06/07 13:59:01 tom Exp $")
+
+static int
+cleanup_lines(struct ldat *data, int length)
+{
+    while (--length >= 0)
+	free(data[length].text);
+    free(data);
+    return ERR;
+}
+
+/*
+ * If we have reallocated the ldat structs, we will have to repair pointers
+ * used in subwindows.
+ */
+static void
+repair_subwindows(WINDOW *cmp)
+{
+    WINDOWLIST *wp;
+    struct ldat *pline = cmp->_line;
+    int row;
+
+    _nc_lock_global(curses);
+
+    for (each_window(wp)) {
+	WINDOW *tst = &(wp->win);
+
+	if (tst->_parent == cmp) {
+
+	    if (tst->_pary > cmp->_maxy)
+		tst->_pary = cmp->_maxy;
+	    if (tst->_parx > cmp->_maxx)
+		tst->_parx = cmp->_maxx;
+
+	    if (tst->_maxy + tst->_pary > cmp->_maxy)
+		tst->_maxy = cmp->_maxy - tst->_pary;
+	    if (tst->_maxx + tst->_parx > cmp->_maxx)
+		tst->_maxx = cmp->_maxx - tst->_parx;
+
+	    for (row = 0; row <= tst->_maxy; ++row) {
+		tst->_line[row].text = &pline[tst->_pary + row].text[tst->_parx];
+	    }
+	    repair_subwindows(tst);
+	}
+    }
+    _nc_unlock_global(curses);
+}
+
+/*
+ * Reallocate a curses WINDOW struct to either shrink or grow to the specified
+ * new lines/columns.  If it grows, the new character cells are filled with
+ * blanks.  The application is responsible for repainting the blank area.
+ */
+NCURSES_EXPORT(int)
+wresize(WINDOW *win, int ToLines, int ToCols)
+{
+    int col, row, size_x, size_y;
+    struct ldat *pline;
+    struct ldat *new_lines = 0;
+
+#ifdef TRACE
+    T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols));
+    if (win) {
+	TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)",
+			  (long) win->_begy, (long) win->_begx,
+			  (long) win->_maxy, (long) win->_maxx,
+			  (long) win->_regtop, (long) win->_regbottom));
+	if (USE_TRACEF(TRACE_UPDATE)) {
+	    _tracedump("...before", win);
+	    _nc_unlock_global(tracef);
+	}
+    }
+#endif
+
+    if (!win || --ToLines < 0 || --ToCols < 0)
+	returnCode(ERR);
+
+    size_x = win->_maxx;
+    size_y = win->_maxy;
+
+    if (ToLines == size_y
+	&& ToCols == size_x)
+	returnCode(OK);
+
+    if ((win->_flags & _SUBWIN)) {
+	/*
+	 * Check if the new limits will fit into the parent window's size.  If
+	 * not, do not resize.  We could adjust the location of the subwindow,
+	 * but the application may not like that.
+	 */
+	if (win->_pary + ToLines > win->_parent->_maxy
+	    || win->_parx + ToCols > win->_parent->_maxx) {
+	    returnCode(ERR);
+	}
+	pline = win->_parent->_line;
+    } else {
+	pline = 0;
+    }
+
+    /*
+     * Allocate new memory as needed.  Do the allocations without modifying
+     * the original window, in case an allocation fails.  Always allocate
+     * (at least temporarily) the array pointing to the individual lines.
+     */
+    new_lines = typeCalloc(struct ldat, (unsigned) (ToLines + 1));
+    if (new_lines == 0)
+	returnCode(ERR);
+
+    /*
+     * For each line in the target, allocate or adjust pointers for the
+     * corresponding text, depending on whether this is a window or a
+     * subwindow.
+     */
+    for (row = 0; row <= ToLines; ++row) {
+	int begin = (row > size_y) ? 0 : (size_x + 1);
+	int end = ToCols;
+	NCURSES_CH_T *s;
+
+	if (!(win->_flags & _SUBWIN)) {
+	    if (row <= size_y) {
+		if (ToCols != size_x) {
+		    if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
+			returnCode(cleanup_lines(new_lines, row));
+		    for (col = 0; col <= ToCols; ++col) {
+			s[col] = (col <= size_x
+				  ? win->_line[row].text[col]
+				  : win->_nc_bkgd);
+		    }
+		} else {
+		    s = win->_line[row].text;
+		}
+	    } else {
+		if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
+		    returnCode(cleanup_lines(new_lines, row));
+		for (col = 0; col <= ToCols; ++col)
+		    s[col] = win->_nc_bkgd;
+	    }
+	} else {
+	    s = &pline[win->_pary + row].text[win->_parx];
+	}
+
+	if_USE_SCROLL_HINTS(new_lines[row].oldindex = row);
+	if (row <= size_y) {
+	    new_lines[row].firstchar = win->_line[row].firstchar;
+	    new_lines[row].lastchar = win->_line[row].lastchar;
+	}
+	if ((ToCols != size_x) || (row > size_y)) {
+	    if (end >= begin) {	/* growing */
+		if (new_lines[row].firstchar < begin)
+		    new_lines[row].firstchar = begin;
+	    } else {		/* shrinking */
+		new_lines[row].firstchar = 0;
+	    }
+	    new_lines[row].lastchar = ToCols;
+	}
+	new_lines[row].text = s;
+    }
+
+    /*
+     * Dispose of unwanted memory.
+     */
+    if (!(win->_flags & _SUBWIN)) {
+	if (ToCols == size_x) {
+	    for (row = ToLines + 1; row <= size_y; row++) {
+		free(win->_line[row].text);
+	    }
+	} else {
+	    for (row = 0; row <= size_y; row++) {
+		free(win->_line[row].text);
+	    }
+	}
+    }
+
+    free(win->_line);
+    win->_line = new_lines;
+
+    /*
+     * Finally, adjust the parameters showing screen size and cursor
+     * position:
+     */
+    win->_maxx = ToCols;
+    win->_maxy = ToLines;
+
+    if (win->_regtop > win->_maxy)
+	win->_regtop = win->_maxy;
+    if (win->_regbottom > win->_maxy
+	|| win->_regbottom == size_y)
+	win->_regbottom = win->_maxy;
+
+    if (win->_curx > win->_maxx)
+	win->_curx = win->_maxx;
+    if (win->_cury > win->_maxy)
+	win->_cury = win->_maxy;
+
+    /*
+     * Check for subwindows of this one, and readjust pointers to our text,
+     * if needed.
+     */
+    repair_subwindows(win);
+
+#ifdef TRACE
+    TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)",
+		      (long) win->_begy, (long) win->_begx,
+		      (long) win->_maxy, (long) win->_maxx,
+		      (long) win->_regtop, (long) win->_regbottom));
+    if (USE_TRACEF(TRACE_UPDATE)) {
+	_tracedump("...after:", win);
+	_nc_unlock_global(tracef);
+    }
+#endif
+    returnCode(OK);
+}
diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h
new file mode 100644
index 0000000..29e1319
--- /dev/null
+++ b/ncurses/curses.priv.h
@@ -0,0 +1,1722 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+
+/*
+ * $Id: curses.priv.h,v 1.394 2008/10/04 21:37:45 tom Exp $
+ *
+ *	curses.priv.h
+ *
+ *	Header file for curses library objects which are private to
+ *	the library.
+ *
+ */
+
+#ifndef CURSES_PRIV_H
+#define CURSES_PRIV_H 1
+
+#include <ncurses_dll.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ncurses_cfg.h>
+
+#if USE_RCS_IDS
+#define MODULE_ID(id) static const char Ident[] = id;
+#else
+#define MODULE_ID(id) /*nothing*/
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#if HAVE_SYS_BSDTYPES_H
+#include <sys/bsdtypes.h>	/* needed for ISC */
+#endif
+
+#if HAVE_LIMITS_H
+# include <limits.h>
+#elif HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <errno.h>
+
+#ifndef PATH_MAX
+# if defined(_POSIX_PATH_MAX)
+#  define PATH_MAX _POSIX_PATH_MAX
+# elif defined(MAXPATHLEN)
+#  define PATH_MAX MAXPATHLEN
+# else
+#  define PATH_MAX 255	/* the Posix minimum path-size */
+# endif
+#endif
+
+#if DECL_ERRNO
+extern int errno;
+#endif
+
+#include <nc_panel.h>
+
+/* Some systems have a broken 'select()', but workable 'poll()'.  Use that */
+#if HAVE_WORKING_POLL
+#define USE_FUNC_POLL 1
+#if HAVE_POLL_H
+#include <poll.h>
+#else
+#include <sys/poll.h>
+#endif
+#else
+#define USE_FUNC_POLL 0
+#endif
+
+/* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
+#include <signal.h>
+
+/* Alessandro Rubini's GPM (general-purpose mouse) */
+#if HAVE_LIBGPM && HAVE_GPM_H
+#define USE_GPM_SUPPORT 1
+#else
+#define USE_GPM_SUPPORT 0
+#endif
+
+/* QNX mouse support */
+#if defined(__QNX__) && !defined(__QNXNTO__)
+#define USE_QNX_MOUSE 1
+#else
+#define USE_QNX_MOUSE 0
+#endif
+
+/* EMX mouse support */
+#ifdef __EMX__
+#define USE_EMX_MOUSE 1
+#else
+#define USE_EMX_MOUSE 0
+#endif
+
+#define DEFAULT_MAXCLICK 166
+#define EV_MAX		8	/* size of mouse circular event queue */
+
+/*
+ * If we don't have signals to support it, don't add a sigwinch handler.
+ * In any case, resizing is an extended feature.  Use it if we've got it.
+ */
+#if !NCURSES_EXT_FUNCS
+#undef HAVE_SIZECHANGE
+#define HAVE_SIZECHANGE 0
+#endif
+
+#if HAVE_SIZECHANGE && USE_SIGWINCH && defined(SIGWINCH)
+#define USE_SIZECHANGE 1
+#else
+#define USE_SIZECHANGE 0
+#undef USE_SIGWINCH
+#define USE_SIGWINCH 0
+#endif
+
+/*
+ * If desired, one can configure this, disabling environment variables that
+ * point to custom terminfo/termcap locations.
+ */
+#ifdef USE_ROOT_ENVIRON
+#define use_terminfo_vars() 1
+#else
+#define use_terminfo_vars() _nc_env_access()
+extern NCURSES_EXPORT(int) _nc_env_access (void);
+#endif
+
+/*
+ * Not all platforms have memmove; some have an equivalent bcopy.  (Some may
+ * have neither).
+ */
+#if USE_OK_BCOPY
+#define memmove(d,s,n) bcopy(s,d,n)
+#elif USE_MY_MEMMOVE
+#define memmove(d,s,n) _nc_memmove(d,s,n)
+extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
+#endif
+
+/*
+ * Scroll hints are useless when hashmap is used
+ */
+#if !USE_SCROLL_HINTS
+#if !USE_HASHMAP
+#define USE_SCROLL_HINTS 1
+#else
+#define USE_SCROLL_HINTS 0
+#endif
+#endif
+
+#if USE_SCROLL_HINTS
+#define if_USE_SCROLL_HINTS(stmt) stmt
+#else
+#define if_USE_SCROLL_HINTS(stmt) /*nothing*/
+#endif
+
+/*
+ * Note:  ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
+ * when we're throwing control codes at the screen at high volume.  To see
+ * this, re-enable USE_HARD_TABS and run worm for a while.  Other systems
+ * probably don't want to define this either due to uncertainties about tab
+ * delays and expansion in raw mode.
+ */
+
+#define TRIES struct tries
+typedef TRIES {
+	TRIES    *child;            /* ptr to child.  NULL if none          */
+	TRIES    *sibling;          /* ptr to sibling.  NULL if none        */
+	unsigned char    ch;        /* character at this node               */
+	unsigned short   value;     /* code of string so far.  0 if none.   */
+#undef TRIES
+} TRIES;
+
+/*
+ * Common/troublesome character definitions
+ */
+#define StringOf(ch) {ch, 0}
+
+#define L_BRACE '{'
+#define R_BRACE '}'
+#define S_QUOTE '\''
+#define D_QUOTE '"'
+
+#define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
+
+/*
+ * Structure for palette tables
+ */
+
+typedef struct
+{
+    short red, green, blue;	/* what color_content() returns */
+    short r, g, b;		/* params to init_color() */
+    int init;			/* true if we called init_color() */
+}
+color_t;
+
+#define MAXCOLUMNS    135
+#define MAXLINES      66
+#define FIFO_SIZE     MAXCOLUMNS+2  /* for nocbreak mode input */
+
+#define ACS_LEN       128
+
+#define WINDOWLIST struct _win_list
+
+#if USE_WIDEC_SUPPORT
+#define _nc_bkgd    _bkgrnd
+#else
+#undef _XOPEN_SOURCE_EXTENDED
+#define _nc_bkgd    _bkgd
+#define wgetbkgrnd(win, wch)	*wch = win->_bkgd
+#define wbkgrnd	    wbkgd
+#endif
+
+#undef NCURSES_OPAQUE
+#define NCURSES_INTERNALS 1
+#define NCURSES_OPAQUE 0
+
+#include <curses.h>	/* we'll use -Ipath directive to get the right one! */
+#include <term.h>
+#include <term_entry.h>
+#include <nc_tparm.h>
+
+#if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT
+#define if_EXT_COLORS(stmt)	stmt
+#define NetPair(value,p)	(value).ext_color = (p), \
+				AttrOf(value) &= ALL_BUT_COLOR, \
+				AttrOf(value) |= (A_COLOR & COLOR_PAIR((p > 255) ? 255 : p))
+#define SetPair(value,p)	(value).ext_color = (p)
+#define GetPair(value)		(value).ext_color
+#define unColor(n)		(AttrOf(n) & ALL_BUT_COLOR)
+#define GET_WINDOW_PAIR(w)	(w)->_color
+#define SET_WINDOW_PAIR(w,p)	(w)->_color = (p)
+#define SameAttrOf(a,b)		(AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b))
+#define VIDATTR(attr, pair)	vid_attr(attr, pair, 0)
+#else
+#define if_EXT_COLORS(stmt)	/* nothing */
+#define SetPair(value,p)	RemAttr(value, A_COLOR), \
+				SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p)))
+#define GetPair(value)		PAIR_NUMBER(AttrOf(value))
+#define unColor(n)		(AttrOf(n) & ALL_BUT_COLOR)
+#define GET_WINDOW_PAIR(w)	PAIR_NUMBER(WINDOW_ATTRS(w))
+#define SET_WINDOW_PAIR(w,p)	WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \
+				WINDOW_ATTRS(w) |= (A_COLOR & COLOR_PAIR(p))
+#define SameAttrOf(a,b)		(AttrOf(a) == AttrOf(b))
+#define VIDATTR(attr, pair)	vidattr(attr)
+#endif
+
+#if NCURSES_NO_PADDING
+#define GetNoPadding(sp)	((sp) ? (sp)->_no_padding : _nc_prescreen._no_padding)
+#define SetNoPadding(sp)	_nc_set_no_padding(sp)
+extern NCURSES_EXPORT(void) _nc_set_no_padding(SCREEN *);
+#else
+#define GetNoPadding(sp)	FALSE
+#define SetNoPadding(sp)	/*nothing*/
+#endif
+
+#define WINDOW_ATTRS(w)		((w)->_attrs)
+
+#define SCREEN_ATTRS(s)		(*((s)->_current_attr))
+#define GET_SCREEN_PAIR(s)	GetPair(SCREEN_ATTRS(s))
+#define SET_SCREEN_PAIR(s,p)	SetPair(SCREEN_ATTRS(s), p)
+
+#if USE_REENTRANT
+NCURSES_EXPORT(int *) _nc_ptr_Lines (void);
+NCURSES_EXPORT(int *) _nc_ptr_Cols (void);
+#define ptrLines() (SP ? &(SP->_LINES) : &(_nc_prescreen._LINES))
+#define ptrCols()  (SP ? &(SP->_COLS)  : &(_nc_prescreen._COLS))
+#define SET_LINES(value) *_nc_ptr_Lines() = value
+#define SET_COLS(value)  *_nc_ptr_Cols() = value
+#else
+#define ptrLines() &LINES
+#define ptrCols()  &COLS
+#define SET_LINES(value) LINES = value
+#define SET_COLS(value)  COLS = value
+#endif
+
+#define TR_MUTEX(data) _tracef("%s@%d: me:%08lX COUNT:%2u/%2d/%6d/%2d/%s%9u: " #data, \
+	    __FILE__, __LINE__, \
+	    (unsigned long) (pthread_self()), \
+	    data.__data.__lock, \
+	    data.__data.__count, \
+	    data.__data.__owner, \
+	    data.__data.__kind, \
+	    (data.__data.__nusers > 5) ? " OOPS " : "", \
+	    data.__data.__nusers)
+#define TR_GLOBAL_MUTEX(name) TR_MUTEX(_nc_globals.mutex_##name)
+
+#ifdef USE_PTHREADS
+
+#if USE_REENTRANT
+#include <pthread.h>
+extern NCURSES_EXPORT(void) _nc_init_pthreads(void);
+extern NCURSES_EXPORT(void) _nc_mutex_init(pthread_mutex_t *);
+extern NCURSES_EXPORT(int) _nc_mutex_lock(pthread_mutex_t *);
+extern NCURSES_EXPORT(int) _nc_mutex_trylock(pthread_mutex_t *);
+extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *);
+#define _nc_lock_global(name)	_nc_mutex_lock(&_nc_globals.mutex_##name)
+#define _nc_try_global(name)    _nc_mutex_trylock(&_nc_globals.mutex_##name)
+#define _nc_unlock_global(name)	_nc_mutex_unlock(&_nc_globals.mutex_##name)
+
+#else
+#error POSIX threads requires --enable-reentrant option
+#endif
+
+#if USE_WEAK_SYMBOLS
+#if defined(__GNUC__)
+#  if defined __USE_ISOC99
+#    define _cat_pragma(exp)	_Pragma(#exp)
+#    define _weak_pragma(exp)	_cat_pragma(weak name)
+#  else
+#    define _weak_pragma(exp)
+#  endif
+#  define _declare(name)	__extension__ extern __typeof__(name) name
+#  define weak_symbol(name)	_weak_pragma(name) _declare(name) __attribute__((weak))
+#endif
+#endif
+
+#ifdef USE_PTHREADS
+#  if USE_WEAK_SYMBOLS
+weak_symbol(pthread_sigmask);
+weak_symbol(pthread_self);
+weak_symbol(pthread_equal);
+weak_symbol(pthread_mutex_init);
+weak_symbol(pthread_mutex_lock);
+weak_symbol(pthread_mutex_unlock);
+weak_symbol(pthread_mutex_trylock);
+weak_symbol(pthread_mutexattr_settype);
+weak_symbol(pthread_mutexattr_init);
+extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
+#    undef  sigprocmask
+#    define sigprocmask _nc_sigprocmask
+#  endif
+#endif
+
+#if HAVE_NANOSLEEP
+#undef HAVE_NANOSLEEP
+#define HAVE_NANOSLEEP 0	/* nanosleep suspends all threads */
+#endif
+
+#else /* !USE_PTHREADS */
+
+#define _nc_init_pthreads()	/* nothing */
+#define _nc_mutex_init(obj)	/* nothing */
+
+#define _nc_lock_global(name)	/* nothing */
+#define _nc_try_global(name)    0
+#define _nc_unlock_global(name)	/* nothing */
+
+#endif /* USE_PTHREADS */
+
+#if HAVE_GETTIMEOFDAY
+# define PRECISE_GETTIME 1
+# define TimeType struct timeval
+#else
+# define PRECISE_GETTIME 0
+# define TimeType time_t
+#endif
+
+/*
+ * Definitions for color pairs
+ */
+typedef unsigned colorpair_t;	/* type big enough to store PAIR_OF() */
+#define C_SHIFT 9		/* we need more bits than there are colors */
+#define C_MASK			((1 << C_SHIFT) - 1)
+#define PAIR_OF(fg, bg)		((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
+#define isDefaultColor(c)	((c) >= COLOR_DEFAULT || (c) < 0)
+
+#define COLOR_DEFAULT		C_MASK
+
+#if defined(USE_TERMLIB) && !defined(NEED_NCURSES_CH_T)
+
+#undef NCURSES_CH_T		/* this is not a termlib feature */
+#define NCURSES_CH_T void	/* ...but we need a pointer in SCREEN */
+
+#endif	/* USE_TERMLIB */
+
+#ifndef USE_TERMLIB
+struct ldat
+{
+	NCURSES_CH_T	*text;		/* text of the line */
+	NCURSES_SIZE_T	firstchar;	/* first changed character in the line */
+	NCURSES_SIZE_T	lastchar;	/* last changed character in the line */
+	NCURSES_SIZE_T	oldindex;	/* index of the line at last update */
+};
+#endif	/* USE_TERMLIB */
+
+typedef enum {
+	M_XTERM	= -1		/* use xterm's mouse tracking? */
+	,M_NONE = 0		/* no mouse device */
+#if USE_GPM_SUPPORT
+	,M_GPM			/* use GPM */
+#endif
+#if USE_SYSMOUSE
+	,M_SYSMOUSE		/* FreeBSD sysmouse on console */
+#endif
+} MouseType;
+
+/*
+ * Structures for scrolling.
+ */
+
+typedef struct {
+	unsigned long hashval;
+	int oldcount, newcount;
+	int oldindex, newindex;
+} HASHMAP;
+
+/*
+ * Structures for soft labels.
+ */
+
+struct _SLK;
+
+#ifndef USE_TERMLIB
+
+typedef struct
+{
+	char *ent_text;		/* text for the label */
+	char *form_text;	/* formatted text (left/center/...) */
+	int ent_x;		/* x coordinate of this field */
+	char dirty;		/* this label has changed */
+	char visible;		/* field is visible */
+} slk_ent;
+
+typedef struct _SLK {
+	char dirty;		/* all labels have changed */
+	char hidden;		/* soft labels are hidden */
+	WINDOW *win;
+	slk_ent *ent;
+	short  maxlab;		/* number of available labels */
+	short  labcnt;		/* number of allocated labels */
+	short  maxlen;		/* length of labels */
+	NCURSES_CH_T attr;	/* soft label attribute */
+} 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 <gpm.h>
+
+#ifdef HAVE_LIBDL
+/* link dynamically to GPM */
+typedef int *TYPE_gpm_fd;
+typedef int (*TYPE_Gpm_Open) (Gpm_Connect *, int);
+typedef int (*TYPE_Gpm_Close) (void);
+typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *);
+
+#define my_gpm_fd       SP->_mouse_gpm_fd
+#define my_Gpm_Open     SP->_mouse_Gpm_Open
+#define my_Gpm_Close    SP->_mouse_Gpm_Close
+#define my_Gpm_GetEvent SP->_mouse_Gpm_GetEvent
+#else
+/* link statically to GPM */
+#define my_gpm_fd       &gpm_fd
+#define my_Gpm_Open     Gpm_Open
+#define my_Gpm_Close    Gpm_Close
+#define my_Gpm_GetEvent Gpm_GetEvent
+#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
+
+/*
+ * 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 {
+#ifdef TRACE
+	const char	*tname;
+#endif
+	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];
+} 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
+ * preserve mixed-case names.
+ */
+#if MIXEDCASE_FILENAMES
+#define LEAF_FMT "%c"
+#else
+#define LEAF_FMT "%02x"
+#endif
+
+/*
+ * TRACEMSE_FMT is no longer than 80 columns, there are 5 numbers that
+ * could at most have 10 digits, and the mask contains no more than 32 bits
+ * with each bit representing less than 15 characters.  Usually the whole
+ * string is less than 80 columns, but this buffer size is an absolute
+ * limit.
+ */
+#define TRACEMSE_MAX	(80 + (5 * 10) + (32 * 15))
+#define TRACEMSE_FMT	"id %2d  at (%2d, %2d, %2d) state %4lx = {" /* } */
+
+/*
+ * Global data which is not specific to a screen.
+ */
+typedef struct {
+	SIG_ATOMIC_T	have_sigwinch;
+	SIG_ATOMIC_T	cleanup_nested;
+
+	bool		init_signals;
+	bool		init_screen;
+
+	const 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		slk_format;
+
+	char		*safeprint_buf;
+	size_t		safeprint_used;
+
+	TGETENT_CACHE	tgetent_cache[TGETENT_MAX];
+	int		tgetent_index;
+	long		tgetent_sequence;
+
+	WINDOWLIST	*_nc_windowlist;
+#define _nc_windows	_nc_globals._nc_windowlist
+
+#if USE_HOME_TERMINFO
+	char		*home_terminfo;
+#endif
+
+#if !USE_SAFE_SPRINTF
+	int		safeprint_cols;
+	int		safeprint_rows;
+#endif
+
+#ifdef TRACE
+	bool		init_trace;
+	char		trace_fname[PATH_MAX];
+	int		trace_level;
+	FILE		*trace_fp;
+
+	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;
+
+#endif	/* TRACE */
+
+#ifdef USE_PTHREADS
+	pthread_mutex_t	mutex_curses;
+	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
+#endif
+} NCURSES_GLOBALS;
+
+extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
+
+#define N_RIPS 5
+
+/*
+ * 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 {
+	bool		use_env;
+	bool		filter_mode;
+	attr_t		previous_attr;
+	ripoff_t	rippedoff[N_RIPS];
+	ripoff_t	*rsp;
+	TPARM_STATE	tparm_state;
+	TTY		*saved_tty;	/* savetty/resetty information	    */
+#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;
+	TERMINAL	*_cur_term;
+#ifdef TRACE
+	long		_outchars;
+	const char	*_tputs_trace;
+#endif
+#endif
+} NCURSES_PRESCREEN;
+
+#define ripoff_sp	_nc_prescreen.rsp
+#define ripoff_stack	_nc_prescreen.rippedoff
+
+extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
+
+/*
+ * The SCREEN structure.
+ */
+
+struct screen {
+	int		_ifd;		/* input file ptr for screen	    */
+	FILE		*_ofp;		/* output file ptr for screen	    */
+	char		*_setbuf;	/* buffered I/O for output	    */
+	bool		_filtered;	/* filter() was called		    */
+	bool		_buffered;	/* setvbuf uses _setbuf data	    */
+	int		_checkfd;	/* filedesc for typeahead check	    */
+	TERMINAL	*_term;		/* terminal type information	    */
+	TTY		_saved_tty;	/* savetty/resetty information	    */
+	NCURSES_SIZE_T	_lines;		/* screen lines			    */
+	NCURSES_SIZE_T	_columns;	/* screen columns		    */
+
+	NCURSES_SIZE_T	_lines_avail;	/* lines available for stdscr	    */
+	NCURSES_SIZE_T	_topstolen;	/* lines stolen from top	    */
+
+	WINDOW		*_curscr;	/* current screen		    */
+	WINDOW		*_newscr;	/* virtual screen to be updated to  */
+	WINDOW		*_stdscr;	/* screen's full-window context	    */
+
+	TRIES		*_keytry;	/* "Try" for use with keypad mode   */
+	TRIES		*_key_ok;	/* Disabled keys via keyok(,FALSE)  */
+	bool		_tried;		/* keypad mode was initialized	    */
+	bool		_keypad_on;	/* keypad mode is currently on	    */
+
+	bool		_called_wgetch;	/* check for recursion in wgetch()  */
+	int		_fifo[FIFO_SIZE];	/* input push-back buffer   */
+	short		_fifohead,	/* head of fifo queue		    */
+			_fifotail,	/* tail of fifo queue		    */
+			_fifopeek,	/* where to peek for next char	    */
+			_fifohold;	/* set if breakout marked	    */
+
+	int		_endwin;	/* are we out of window mode?	    */
+	NCURSES_CH_T	*_current_attr; /* holds current attributes set	    */
+	int		_coloron;	/* is color enabled?		    */
+	int		_color_defs;	/* are colors modified		    */
+	int		_cursor;	/* visibility of the cursor	    */
+	int		_cursrow;	/* physical cursor row		    */
+	int		_curscol;	/* physical cursor column	    */
+	bool		_notty;		/* true if we cannot switch non-tty */
+	int		_nl;		/* True if NL -> CR/NL is on	    */
+	int		_raw;		/* True if in raw mode		    */
+	int		_cbreak;	/* 1 if in cbreak mode		    */
+					/* > 1 if in halfdelay mode	    */
+	int		_echo;		/* True if echo on		    */
+	int		_use_meta;	/* use the meta key?		    */
+	struct _SLK	*_slk;		/* ptr to soft key struct / NULL    */
+	int		slk_format;	/* selected format for this screen  */
+	/* cursor movement costs; units are 10ths of milliseconds */
+#if NCURSES_NO_PADDING
+	bool		_no_padding;	/* flag to set if padding disabled  */
+#endif
+	int		_char_padding;	/* cost of character put	    */
+	int		_cr_cost;	/* cost of (carriage_return)	    */
+	int		_cup_cost;	/* cost of (cursor_address)	    */
+	int		_home_cost;	/* cost of (cursor_home)	    */
+	int		_ll_cost;	/* cost of (cursor_to_ll)	    */
+#if USE_HARD_TABS
+	int		_ht_cost;	/* cost of (tab)		    */
+	int		_cbt_cost;	/* cost of (backtab)		    */
+#endif /* USE_HARD_TABS */
+	int		_cub1_cost;	/* cost of (cursor_left)	    */
+	int		_cuf1_cost;	/* cost of (cursor_right)	    */
+	int		_cud1_cost;	/* cost of (cursor_down)	    */
+	int		_cuu1_cost;	/* cost of (cursor_up)		    */
+	int		_cub_cost;	/* cost of (parm_cursor_left)	    */
+	int		_cuf_cost;	/* cost of (parm_cursor_right)	    */
+	int		_cud_cost;	/* cost of (parm_cursor_down)	    */
+	int		_cuu_cost;	/* cost of (parm_cursor_up)	    */
+	int		_hpa_cost;	/* cost of (column_address)	    */
+	int		_vpa_cost;	/* cost of (row_address)	    */
+	/* used in tty_update.c, must be chars */
+	int		_ed_cost;	/* cost of (clr_eos)		    */
+	int		_el_cost;	/* cost of (clr_eol)		    */
+	int		_el1_cost;	/* cost of (clr_bol)		    */
+	int		_dch1_cost;	/* cost of (delete_character)	    */
+	int		_ich1_cost;	/* cost of (insert_character)	    */
+	int		_dch_cost;	/* cost of (parm_dch)		    */
+	int		_ich_cost;	/* cost of (parm_ich)		    */
+	int		_ech_cost;	/* cost of (erase_chars)	    */
+	int		_rep_cost;	/* cost of (repeat_char)	    */
+	int		_hpa_ch_cost;	/* cost of (column_address)	    */
+	int		_cup_ch_cost;	/* cost of (cursor_address)	    */
+	int		_cuf_ch_cost;	/* cost of (parm_cursor_right)	    */
+	int		_inline_cost;	/* cost of inline-move		    */
+	int		_smir_cost;	/* cost of (enter_insert_mode)	    */
+	int		_rmir_cost;	/* cost of (exit_insert_mode)	    */
+	int		_ip_cost;	/* cost of (insert_padding)	    */
+	/* used in lib_mvcur.c */
+	char *		_address_cursor;
+	/* used in tty_update.c */
+	int		_scrolling;	/* 1 if terminal's smart enough to  */
+
+	/* used in lib_color.c */
+	color_t		*_color_table;	/* screen's color palette	     */
+	int		_color_count;	/* count of colors in palette	     */
+	colorpair_t	*_color_pairs;	/* screen's color pair list	     */
+	int		_pair_count;	/* count of color pairs		     */
+#if NCURSES_EXT_FUNCS
+	bool		_default_color; /* use default colors		     */
+	bool		_has_sgr_39_49; /* has ECMA default color support    */
+	int		_default_fg;	/* assumed default foreground	     */
+	int		_default_bg;	/* assumed default background	     */
+#endif
+	chtype		_ok_attributes; /* valid attributes for terminal     */
+	chtype		_xmc_suppress;	/* attributes to suppress if xmc     */
+	chtype		_xmc_triggers;	/* attributes to process if xmc	     */
+	chtype *	_acs_map;	/* the real alternate-charset map    */
+	bool *		_screen_acs_map;
+
+
+	/* used in lib_vidattr.c */
+	bool		_use_rmso;	/* true if we may use 'rmso'	     */
+	bool		_use_rmul;	/* true if we may use 'rmul'	     */
+
+	/*
+	 * These data correspond to the state of the idcok() and idlok()
+	 * functions.  A caveat is in order here:  the XSI and SVr4
+	 * documentation specify that these functions apply to the window which
+	 * is given as an argument.  However, ncurses implements this logic
+	 * only for the newscr/curscr update process, _not_ per-window.
+	 */
+	bool		_nc_sp_idlok;
+	bool		_nc_sp_idcok;
+#define _nc_idlok SP->_nc_sp_idlok
+#define _nc_idcok SP->_nc_sp_idcok
+
+	/*
+	 * These are the data that support the mouse interface.
+	 */
+	bool		_mouse_initialized;
+	MouseType	_mouse_type;
+	int		_maxclick;
+	bool		(*_mouse_event) (SCREEN *);
+	bool		(*_mouse_inline)(SCREEN *);
+	bool		(*_mouse_parse) (SCREEN *, int);
+	void		(*_mouse_resume)(SCREEN *);
+	void		(*_mouse_wrap)	(SCREEN *);
+	int		_mouse_fd;	/* file-descriptor, if any */
+	bool		_mouse_active;	/* true if initialized */
+	mmask_t		_mouse_mask;
+	NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */
+	MEVENT		_mouse_events[EV_MAX];	/* hold the last mouse event seen */
+	MEVENT		*_mouse_eventp;	/* next free slot in event queue */
+
+#if USE_GPM_SUPPORT
+	bool		_mouse_gpm_loaded;
+	bool		_mouse_gpm_found;
+#ifdef HAVE_LIBDL
+	void		*_dlopen_gpm;
+	TYPE_gpm_fd	_mouse_gpm_fd;
+	TYPE_Gpm_Open	_mouse_Gpm_Open;
+	TYPE_Gpm_Close	_mouse_Gpm_Close;
+	TYPE_Gpm_GetEvent _mouse_Gpm_GetEvent;
+#endif
+	Gpm_Connect	_mouse_gpm_connect;
+#endif /* USE_GPM_SUPPORT */
+
+#if USE_EMX_MOUSE
+	int		_emxmouse_wfd;
+	int		_emxmouse_thread;
+	int		_emxmouse_activated;
+	char		_emxmouse_buttons[4];
+#endif
+
+#if USE_SYSMOUSE
+	MEVENT		_sysmouse_fifo[FIFO_SIZE];
+	int		_sysmouse_head;
+	int		_sysmouse_tail;
+	int		_sysmouse_char_width;	/* character width */
+	int		_sysmouse_char_height;	/* character height */
+	int		_sysmouse_old_buttons;
+	int		_sysmouse_new_buttons;
+#endif
+
+	/*
+	 * This supports automatic resizing
+	 */
+#if USE_SIZECHANGE
+	int		(*_resize)(int,int);
+#endif
+
+	/*
+	 * These are data that support the proper handling of the panel stack on an
+	 * per screen basis.
+	 */
+	struct panelhook _panelHook;
+
+	bool		_sig_winch;
+	SCREEN		*_next_screen;
+
+	/* hashes for old and new lines */
+	unsigned long	*oldhash, *newhash;
+	HASHMAP		*hashtab;
+	int		hashtab_len;
+	int		*_oldnum_list;
+	int		_oldnum_size;
+
+	bool		_cleanup;	/* cleanup after int/quit signal */
+	int		(*_outch)(int); /* output handler if not putc */
+
+	int		_legacy_coding;	/* see use_legacy_coding() */
+
+#if USE_REENTRANT
+	char		_ttytype[NAMESIZE];
+	int		_ESCDELAY;
+	int		_TABSIZE;
+	int		_LINES;
+	int		_COLS;
+#ifdef TRACE
+	long		_outchars;
+	const char	*_tputs_trace;
+#endif
+#endif
+
+#ifdef TRACE
+	char		tracechr_buf[40];
+	char		tracemse_buf[TRACEMSE_MAX];
+#endif
+	/*
+	 * ncurses/ncursesw are the same up to this point.
+	 */
+#if USE_WIDEC_SUPPORT
+	/* recent versions of 'screen' have partially-working support for
+	 * UTF-8, but do not permit ACS at the same time (see tty_update.c).
+	 */
+	bool		_screen_acs_fix;
+#endif
+};
+
+extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
+extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
+
+	WINDOWLIST {
+	WINDOW	win;		/* first, so WINDOW_EXT() works */
+	WINDOWLIST *next;
+	SCREEN *screen;		/* screen containing the window */
+#ifdef _XOPEN_SOURCE_EXTENDED
+	char addch_work[(MB_LEN_MAX * 9) + 1];
+	unsigned addch_used;	/* number of bytes in addch_work[] */
+	int addch_x;		/* x-position for addch_work[] */
+	int addch_y;		/* y-position for addch_work[] */
+#endif
+};
+
+#define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
+
+/* usually in <limits.h> */
+#ifndef UCHAR_MAX
+#define UCHAR_MAX 255
+#endif
+
+/* The terminfo source is assumed to be 7-bit ASCII */
+#define is7bits(c)	((unsigned)(c) < 128)
+
+/* Checks for isprint() should be done on 8-bit characters (non-wide) */
+#define is8bits(c)	((unsigned)(c) <= UCHAR_MAX)
+
+#ifndef min
+#define min(a,b)	((a) > (b)  ?  (b)  :  (a))
+#endif
+
+#ifndef max
+#define max(a,b)	((a) < (b)  ?  (b)  :  (a))
+#endif
+
+/* usually in <unistd.h> */
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
+
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+#ifndef R_OK
+#define	R_OK	4		/* Test for read permission.  */
+#endif
+#ifndef W_OK
+#define	W_OK	2		/* Test for write permission.  */
+#endif
+#ifndef X_OK
+#define	X_OK	1		/* Test for execute permission.  */
+#endif
+#ifndef F_OK
+#define	F_OK	0		/* Test for existence.  */
+#endif
+
+#if HAVE_FCNTL_H
+#include <fcntl.h>		/* may define O_BINARY	*/
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#ifdef TRACE
+#if USE_REENTRANT
+#define COUNT_OUTCHARS(n) _nc_count_outchars(n);
+#else
+#define COUNT_OUTCHARS(n) _nc_outchars += (n);
+#endif
+#else
+#define COUNT_OUTCHARS(n) /* nothing */
+#endif
+
+#define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars)
+
+#define UChar(c)	((unsigned char)(c))
+#define ChCharOf(c)	((c) & (chtype)A_CHARTEXT)
+#define ChAttrOf(c)	((c) & (chtype)A_ATTRIBUTES)
+
+#ifndef MB_LEN_MAX
+#define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
+#endif
+
+#if USE_WIDEC_SUPPORT /* { */
+#define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ))
+
+#define init_mb(state)	memset(&state, 0, sizeof(state))
+
+#if NCURSES_EXT_COLORS
+#define NulColor	, 0
+#else
+#define NulColor	/* nothing */
+#endif
+
+#define NulChar		0,0,0,0	/* FIXME: see CCHARW_MAX */
+#define CharOf(c)	((c).chars[0])
+#define AttrOf(c)	((c).attr)
+
+#define AddAttr(c,a)	AttrOf(c) |=  ((a) & A_ATTRIBUTES)
+#define RemAttr(c,a)	AttrOf(c) &= ~((a) & A_ATTRIBUTES)
+#define SetAttr(c,a)	AttrOf(c) =   ((a) & A_ATTRIBUTES) | WidecExt(c)
+
+#define NewChar2(c,a)	{ a, { c, NulChar } NulColor }
+#define NewChar(ch)	NewChar2(ChCharOf(ch), ChAttrOf(ch))
+
+#if CCHARW_MAX == 5
+#define CharEq(a,b)	(((a).attr == (b).attr) \
+		       && (a).chars[0] == (b).chars[0] \
+		       && (a).chars[1] == (b).chars[1] \
+		       && (a).chars[2] == (b).chars[2] \
+		       && (a).chars[3] == (b).chars[3] \
+		       && (a).chars[4] == (b).chars[4] \
+			if_EXT_COLORS(&& (a).ext_color == (b).ext_color))
+#else
+#define CharEq(a,b)	(!memcmp(&(a), &(b), sizeof(a)))
+#endif
+
+#define SetChar(ch,c,a) do {							    \
+			    NCURSES_CH_T *_cp = &ch;				    \
+			    memset(_cp, 0, sizeof(ch));				    \
+			    _cp->chars[0] = (c);					    \
+			    _cp->attr = (a);					    \
+			    if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a)));		    \
+			} while (0)
+#define CHREF(wch)	(&wch)
+#define CHDEREF(wch)	(*wch)
+#define ARG_CH_T	NCURSES_CH_T *
+#define CARG_CH_T	const NCURSES_CH_T *
+#define PUTC_DATA	char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
+			mbstate_t PUT_st; wchar_t PUTC_ch
+#define PUTC_INIT	init_mb (PUT_st)
+#define PUTC(ch,b)	do { if(!isWidecExt(ch)) {				    \
+			if (Charable(ch)) {					    \
+			    fputc(CharOf(ch), b);				    \
+			    COUNT_OUTCHARS(1);					    \
+			} else {						    \
+			    PUTC_INIT;						    \
+			    for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {	    \
+				PUTC_ch = (ch).chars[PUTC_i];			    \
+				if (PUTC_ch == L'\0')				    \
+				    break;					    \
+				PUTC_n = wcrtomb(PUTC_buf,			    \
+						 (ch).chars[PUTC_i], &PUT_st);	    \
+				if (PUTC_n <= 0) {				    \
+				    if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
+					putc(PUTC_ch,b);			    \
+				    break;					    \
+				}						    \
+				fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b);	    \
+			    }							    \
+			    COUNT_OUTCHARS(PUTC_i);				    \
+			} } } while (0)
+
+#define BLANK		NewChar2(' ', WA_NORMAL)
+#define ZEROS		NewChar2('\0', WA_NORMAL)
+#define ISBLANK(ch)	((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
+
+	/*
+	 * Wide characters cannot be represented in the A_CHARTEXT mask of
+	 * attr_t's but an application might have set a narrow character there.
+	 * But even in that case, it would only be a printable character, or
+	 * zero.  Otherwise we can use those bits to tell if a cell is the
+	 * first or extension part of a wide character.
+	 */
+#define WidecExt(ch)	(AttrOf(ch) & A_CHARTEXT)
+#define isWidecBase(ch)	(WidecExt(ch) == 1)
+#define isWidecExt(ch)	(WidecExt(ch) > 1 && WidecExt(ch) < 32)
+#define SetWidecExt(dst, ext)	AttrOf(dst) &= ~A_CHARTEXT,		\
+				AttrOf(dst) |= (ext + 1)
+
+#define if_WIDEC(code)  code
+#define Charable(ch)	((SP != 0 && SP->_legacy_coding)		\
+			 || (AttrOf(ch) & A_ALTCHARSET)			\
+			 || (!isWidecExt(ch) &&				\
+			     (ch).chars[1] == L'\0' &&			\
+			     _nc_is_charable(CharOf(ch))))
+
+#define L(ch)		L ## ch
+#else /* }{ */
+#define CharOf(c)	ChCharOf(c)
+#define AttrOf(c)	ChAttrOf(c)
+#define AddAttr(c,a)	c |= (a)
+#define RemAttr(c,a)	c &= ~((a) & A_ATTRIBUTES)
+#define SetAttr(c,a)	c = ((c) & ~A_ATTRIBUTES) | (a)
+#define NewChar(ch)	(ch)
+#define NewChar2(c,a)	((c) | (a))
+#define CharEq(a,b)	((a) == (b))
+#define SetChar(ch,c,a)	ch = (c) | (a)
+#define CHREF(wch)	wch
+#define CHDEREF(wch)	wch
+#define ARG_CH_T	NCURSES_CH_T
+#define CARG_CH_T	NCURSES_CH_T
+#define PUTC_DATA	int data = 0
+#define PUTC(ch,b)	do { data = CharOf(ch); putc(data,b); } while (0)
+
+#define BLANK		(' '|A_NORMAL)
+#define ZEROS		('\0'|A_NORMAL)
+#define ISBLANK(ch)	(CharOf(ch) == ' ')
+
+#define isWidecExt(ch)	(0)
+#define if_WIDEC(code) /* nothing */
+
+#define L(ch)		ch
+#endif /* } */
+
+#define AttrOfD(ch)	AttrOf(CHDEREF(ch))
+#define CharOfD(ch)	CharOf(CHDEREF(ch))
+#define SetChar2(wch,ch)    SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
+
+#define BLANK_ATTR	A_NORMAL
+#define BLANK_TEXT	L(' ')
+
+#define CHANGED     -1
+
+#define LEGALYX(w, y, x) \
+	      ((w) != 0 && \
+		((x) >= 0 && (x) <= (w)->_maxx && \
+		 (y) >= 0 && (y) <= (w)->_maxy))
+
+#define CHANGED_CELL(line,col) \
+	if (line->firstchar == _NOCHANGE) \
+		line->firstchar = line->lastchar = col; \
+	else if ((col) < line->firstchar) \
+		line->firstchar = col; \
+	else if ((col) > line->lastchar) \
+		line->lastchar = col
+
+#define CHANGED_RANGE(line,start,end) \
+	if (line->firstchar == _NOCHANGE \
+	 || line->firstchar > (start)) \
+		line->firstchar = start; \
+	if (line->lastchar == _NOCHANGE \
+	 || line->lastchar < (end)) \
+		line->lastchar = end
+
+#define CHANGED_TO_EOL(line,start,end) \
+	if (line->firstchar == _NOCHANGE \
+	 || line->firstchar > (start)) \
+		line->firstchar = start; \
+	line->lastchar = end
+
+#define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
+
+#define FreeIfNeeded(p)  if ((p) != 0) free(p)
+
+/* FreeAndNull() is not a comma-separated expression because some compilers
+ * do not accept a mixture of void with values.
+ */
+#define FreeAndNull(p)   free(p); p = 0
+
+#include <nc_alloc.h>
+
+/*
+ * TTY bit definition for converting tabs to spaces.
+ */
+#ifdef TAB3
+# define OFLAGS_TABS TAB3	/* POSIX specifies TAB3 */
+#else
+# ifdef XTABS
+#  define OFLAGS_TABS XTABS	/* XTABS is usually the "same" */
+# else
+#  ifdef OXTABS
+#   define OFLAGS_TABS OXTABS	/* the traditional BSD equivalent */
+#  else
+#   define OFLAGS_TABS 0
+#  endif
+# endif
+#endif
+
+/*
+ * Standardize/simplify common loops
+ */
+#define each_screen(p) p = _nc_screen_chain; p != 0; p = (p)->_next_screen
+#define each_window(p) p = _nc_windows; p != 0; p = (p)->next
+#define each_ripoff(p) p = ripoff_stack; (p - ripoff_stack) < N_RIPS; ++p
+
+/*
+ * Prefixes for call/return points of library function traces.  We use these to
+ * instrument the public functions so that the traces can be easily transformed
+ * into regression scripts.
+ */
+#define T_CALLED(fmt) "called {" fmt
+#define T_CREATE(fmt) "create :" fmt
+#define T_RETURN(fmt) "return }" fmt
+
+#ifdef TRACE
+
+#if USE_REENTRANT
+#define TPUTS_TRACE(s)	_nc_set_tputs_trace(s);
+#else
+#define TPUTS_TRACE(s)	_nc_tputs_trace = s;
+#endif
+
+#define START_TRACE() \
+	if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
+	    int t = _nc_getenv_num("NCURSES_TRACE"); \
+	    if (t >= 0) \
+		trace((unsigned) t); \
+	}
+
+/*
+ * Many of the _tracef() calls use static buffers; lock the trace state before
+ * trying to fill them.
+ */
+#if USE_REENTRANT
+#define USE_TRACEF(mask) _nc_use_tracef(mask)
+extern NCURSES_EXPORT(int)	_nc_use_tracef (unsigned);
+extern NCURSES_EXPORT(void)	_nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2);
+#else
+#define USE_TRACEF(mask) (_nc_tracing & (mask))
+#define _nc_locked_tracef _tracef
+#endif
+
+#define TR(n, a)	if (USE_TRACEF(n)) _nc_locked_tracef a
+#define T(a)		TR(TRACE_CALLS, a)
+#define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
+
+#define returnAttr(code)	TRACE_RETURN(code,attr_t)
+#define returnBits(code)	TRACE_RETURN(code,unsigned)
+#define returnBool(code)	TRACE_RETURN(code,bool)
+#define returnCPtr(code)	TRACE_RETURN(code,cptr)
+#define returnCVoidPtr(code)	TRACE_RETURN(code,cvoid_ptr)
+#define returnChar(code)	TRACE_RETURN(code,chtype)
+#define returnCode(code)	TRACE_RETURN(code,int)
+#define returnPtr(code)		TRACE_RETURN(code,ptr)
+#define returnSP(code)		TRACE_RETURN(code,sp)
+#define returnVoid		T((T_RETURN(""))); return
+#define returnVoidPtr(code)	TRACE_RETURN(code,void_ptr)
+#define returnWin(code)		TRACE_RETURN(code,win)
+
+extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (NCURSES_BOOL);
+extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
+extern NCURSES_EXPORT(SCREEN *)         _nc_retrace_sp (SCREEN *);
+extern NCURSES_EXPORT(WINDOW *)         _nc_retrace_win (WINDOW *);
+extern NCURSES_EXPORT(attr_t)           _nc_retrace_attr_t (attr_t);
+extern NCURSES_EXPORT(char *)           _nc_retrace_ptr (char *);
+extern NCURSES_EXPORT(char *)           _nc_trace_ttymode(TTY *tty);
+extern NCURSES_EXPORT(char *)           _nc_varargs (const char *, va_list);
+extern NCURSES_EXPORT(chtype)           _nc_retrace_chtype (chtype);
+extern NCURSES_EXPORT(const char *)     _nc_altcharset_name(attr_t, chtype);
+extern NCURSES_EXPORT(const char *)     _nc_retrace_cptr (const char *);
+extern NCURSES_EXPORT(int)              _nc_retrace_int (int);
+extern NCURSES_EXPORT(unsigned)         _nc_retrace_unsigned (unsigned);
+extern NCURSES_EXPORT(void *)           _nc_retrace_void_ptr (void *);
+extern NCURSES_EXPORT(void)             _nc_fifo_dump (SCREEN *);
+
+#if USE_REENTRANT
+NCURSES_WRAPPED_VAR(long, _nc_outchars);
+NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace);
+#define _nc_outchars       NCURSES_PUBLIC_VAR(_nc_outchars())
+#define _nc_tputs_trace    NCURSES_PUBLIC_VAR(_nc_tputs_trace())
+extern NCURSES_EXPORT(void)		_nc_set_tputs_trace (const char *);
+extern NCURSES_EXPORT(void)		_nc_count_outchars (long);
+#else
+extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
+extern NCURSES_EXPORT_VAR(long)         _nc_outchars;
+#endif
+
+extern NCURSES_EXPORT_VAR(unsigned)     _nc_tracing;
+
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
+extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
+#endif
+
+extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int);
+extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
+
+#else /* !TRACE */
+
+#define START_TRACE() /* nothing */
+
+#define T(a)
+#define TR(n, a)
+#define TPUTS_TRACE(s)
+
+#define returnAttr(code)	return code
+#define returnBits(code)	return code
+#define returnBool(code)	return code
+#define returnCPtr(code)	return code
+#define returnCVoidPtr(code)	return code
+#define returnChar(code)	return code
+#define returnCode(code)	return code
+#define returnPtr(code)		return code
+#define returnSP(code)		return code
+#define returnVoid		return
+#define returnVoidPtr(code)	return code
+#define returnWin(code)		return code
+
+#endif /* TRACE/!TRACE */
+
+/*
+ * Return-codes for tgetent() and friends.
+ */
+#define TGETENT_YES  1		/* entry is found */
+#define TGETENT_NO   0		/* entry is not found */
+#define TGETENT_ERR -1		/* an error occurred */
+
+extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
+extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
+
+#define EMPTY_MODULE(name) \
+extern	NCURSES_EXPORT(void) name (void); \
+	NCURSES_EXPORT(void) name (void) { }
+
+#define ALL_BUT_COLOR ((chtype)~(A_COLOR))
+#define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
+#define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
+
+#define toggle_attr_on(S,at) {\
+   if (PAIR_NUMBER(at) > 0) {\
+      (S) = ((S) & ALL_BUT_COLOR) | (at);\
+   } else {\
+      (S) |= (at);\
+   }\
+   TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
+
+
+#define toggle_attr_off(S,at) {\
+   if (PAIR_NUMBER(at) > 0) {\
+      (S) &= ~(at|A_COLOR);\
+   } else {\
+      (S) &= ~(at);\
+   }\
+   TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
+
+#define DelCharCost(count) \
+		((parm_dch != 0) \
+		? SP->_dch_cost \
+		: ((delete_character != 0) \
+			? (SP->_dch1_cost * count) \
+			: INFINITY))
+
+#define InsCharCost(count) \
+		((parm_ich != 0) \
+		? SP->_ich_cost \
+		: ((enter_insert_mode && exit_insert_mode) \
+		  ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
+		  : ((insert_character != 0) \
+		    ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
+		    : INFINITY)))
+
+#if USE_XMC_SUPPORT
+#define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \
+				attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \
+				VIDATTR(AttrOf(c), GetPair(c)); \
+				if (magic_cookie_glitch > 0 \
+				 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
+					T(("%s @%d before glitch %d,%d", \
+						__FILE__, __LINE__, \
+						SP->_cursrow, \
+						SP->_curscol)); \
+					_nc_do_xmc_glitch(chg); \
+				} \
+			}
+#else
+#define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
+				VIDATTR(AttrOf(c), GetPair(c));
+#endif
+
+/*
+ * Macros to make additional parameter to implement wgetch_events()
+ */
+#ifdef NCURSES_WGETCH_EVENTS
+#define EVENTLIST_0th(param) param
+#define EVENTLIST_1st(param) param
+#define EVENTLIST_2nd(param) , param
+#else
+#define EVENTLIST_0th(param) void
+#define EVENTLIST_1st(param) /* nothing */
+#define EVENTLIST_2nd(param) /* nothing */
+#endif
+
+#if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
+
+#undef  toggle_attr_on
+#define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
+extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
+
+#undef  toggle_attr_off
+#define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
+extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
+
+#undef  DelCharCost
+#define DelCharCost(count) _nc_DelCharCost(count)
+extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
+
+#undef  InsCharCost
+#define InsCharCost(count) _nc_InsCharCost(count)
+extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
+
+#undef  UpdateAttrs
+#define UpdateAttrs(c) _nc_UpdateAttrs(c)
+extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
+
+#else
+
+extern NCURSES_EXPORT(void) _nc_expanded (void);
+
+#endif
+
+#if !NCURSES_EXT_FUNCS
+#define set_escdelay(value) ESCDELAY = value
+#endif
+
+#if !HAVE_GETCWD
+#define getcwd(buf,len) getwd(buf)
+#endif
+
+/* charable.c */
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
+extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
+extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
+#endif
+
+/* comp_captab.c */
+typedef struct {
+	short	nte_name;	/* offset of name to hash on */
+	int	nte_type;	/* BOOLEAN, NUMBER or STRING */
+	short	nte_index;	/* index of associated variable in its array */
+	short	nte_link;	/* index in table of next hash, or -1 */
+} name_table_data;
+
+typedef struct
+{
+	short	from;
+	short	to;
+	short	source;
+} alias_table_data;
+
+/* doupdate.c */
+#if USE_XMC_SUPPORT
+extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
+#endif
+
+/* hardscroll.c */
+#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
+extern NCURSES_EXPORT(void) _nc_linedump (void);
+#endif
+
+/* lib_acs.c */
+extern NCURSES_EXPORT(void) _nc_init_acs (void);	/* corresponds to traditional 'init_acs()' */
+extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int);  /* used by 'tack' program */
+
+/* lib_addch.c */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
+#endif
+
+/* lib_addstr.c */
+#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
+extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
+#endif
+
+/* lib_color.c */
+extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
+
+/* lib_getch.c */
+extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
+
+/* lib_insch.c */
+extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
+
+/* lib_mvcur.c */
+#define INFINITY	1000000	/* cost: too high to use */
+
+extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
+extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
+extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
+
+extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
+
+extern NCURSES_EXPORT(void) _nc_screen_init (void);
+extern NCURSES_EXPORT(void) _nc_screen_resume (void);
+extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
+
+/* lib_mouse.c */
+extern NCURSES_EXPORT(int) _nc_has_mouse (void);
+
+/* lib_mvcur.c */
+#define INFINITY	1000000	/* cost: too high to use */
+#define BAUDBYTE	9	/* 9 = 7 bits + 1 parity + 1 stop */
+
+/* lib_setup.c */
+extern NCURSES_EXPORT(char *) _nc_get_locale(void);
+extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
+extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *);
+extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool);
+extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *);
+
+/* lib_tstp.c */
+#if USE_SIGWINCH
+extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *);
+#else
+#define _nc_handle_sigwinch(a) /* nothing */
+#endif
+
+/* lib_ungetch.c */
+extern NCURSES_EXPORT(int) _nc_ungetch (SCREEN *, int);
+
+/* lib_wacs.c */
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(void) _nc_init_wacs(void);
+#endif
+
+typedef struct {
+    char *s_head;	/* beginning of the string (may be null) */
+    char *s_tail;	/* end of the string (may be null) */
+    size_t s_size;	/* current remaining size available */
+    size_t s_init;	/* total size available */
+} string_desc;
+
+/* strings.c */
+extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
+extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
+extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
+extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
+extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
+
+#if !HAVE_STRSTR
+#define strstr _nc_strstr
+extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
+#endif
+
+/* safe_sprintf.c */
+extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list);
+
+/* tries.c */
+extern NCURSES_EXPORT(int) _nc_add_to_try (TRIES **, const char *, unsigned);
+extern NCURSES_EXPORT(char *) _nc_expand_try (TRIES *, unsigned, int *, size_t);
+extern NCURSES_EXPORT(int) _nc_remove_key (TRIES **, unsigned);
+extern NCURSES_EXPORT(int) _nc_remove_string (TRIES **, const char *);
+
+/* elsewhere ... */
+extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry (ENTRY *, TERMTYPE *);
+extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *, int);
+extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
+extern NCURSES_EXPORT(SCREEN *) _nc_screen_of (WINDOW *);
+extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
+extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
+extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
+extern NCURSES_EXPORT(char *) _nc_tracechar (SCREEN *, int);
+extern NCURSES_EXPORT(char *) _nc_tracemouse (SCREEN *, MEVENT const *);
+extern NCURSES_EXPORT(int) _nc_access (const char *, int);
+extern NCURSES_EXPORT(int) _nc_baudrate (int);
+extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
+extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
+extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, bool);
+extern NCURSES_EXPORT(int) _nc_ospeed (int);
+extern NCURSES_EXPORT(int) _nc_outch (int);
+extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const);
+extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int);
+extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
+extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, int (*)(int));
+extern NCURSES_EXPORT(void) _nc_flush (void);
+extern NCURSES_EXPORT(void) _nc_free_and_exit (int);
+extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *);
+extern NCURSES_EXPORT(void) _nc_freeall (void);
+extern NCURSES_EXPORT(void) _nc_hash_map (void);
+extern NCURSES_EXPORT(void) _nc_init_keytry (SCREEN *);
+extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
+extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
+extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
+extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
+extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
+extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
+extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
+extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *);
+
+#if NO_LEAKS
+extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
+extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
+extern NCURSES_EXPORT(void) _nc_codes_leaks(void);
+extern NCURSES_EXPORT(void) _nc_comp_captab_leaks(void);
+extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
+extern NCURSES_EXPORT(void) _nc_keyname_leaks(void);
+extern NCURSES_EXPORT(void) _nc_names_leaks(void);
+extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
+#endif
+
+#ifndef USE_TERMLIB
+extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
+extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
+extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T);
+#endif
+
+#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
+extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
+#endif
+
+#if USE_SIZECHANGE
+extern NCURSES_EXPORT(void) _nc_update_screensize (SCREEN *);
+#endif
+
+#if HAVE_RESIZETERM
+extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
+#else
+#define _nc_resize_margins(wp) /* nothing */
+#endif
+
+#ifdef NCURSES_WGETCH_EVENTS
+extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
+#else
+#define wgetch_events(win, evl) wgetch(win)
+#define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
+#endif
+
+/*
+ * Not everyone has vsscanf(), but we'd like to use it for scanw().
+ */
+#if !HAVE_VSSCANF
+extern int vsscanf(const char *str, const char *format, va_list __arg);
+#endif
+
+/* scroll indices */
+extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
+
+#define USE_SETBUF_0 0
+
+#define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
+
+#define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout)
+
+/*
+ * On systems with a broken linker, define 'SP' as a function to force the
+ * linker to pull in the data-only module with 'SP'.
+ */
+#if BROKEN_LINKER
+#define SP _nc_screen()
+extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
+extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
+extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
+#else
+/* current screen is private data; avoid possible linking conflicts too */
+extern NCURSES_EXPORT_VAR(SCREEN *) SP;
+#define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
+#define _nc_set_screen(sp) SP = sp
+#endif
+
+/*
+ * We don't want to use the lines or columns capabilities internally, because
+ * if the application is running multiple screens under X, it's quite possible
+ * they could all have type xterm but have different sizes!  So...
+ */
+#define screen_lines	SP->_lines
+#define screen_columns	SP->_columns
+
+extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
+
+/*
+ * Some constants related to SLK's
+ */
+#define MAX_SKEY_OLD	   8	/* count of soft keys */
+#define MAX_SKEY_LEN_OLD   8	/* max length of soft key text */
+#define MAX_SKEY_PC       12    /* This is what most PC's have */
+#define MAX_SKEY_LEN_PC    5
+
+/* Macro to check whether or not we use a standard format */
+#define SLK_STDFMT(fmt) (fmt < 3)
+/* Macro to determine height of label window */
+#define SLK_LINES(fmt)  (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
+
+#define MAX_SKEY(fmt)     (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
+#define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
+
+extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
+
+/*
+ * Common error messages
+ */
+#define MSG_NO_MEMORY "Out of memory"
+#define MSG_NO_INPUTS "Premature EOF"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CURSES_PRIV_H */
diff --git a/ncurses/fifo_defs.h b/ncurses/fifo_defs.h
new file mode 100644
index 0000000..fa9ae22
--- /dev/null
+++ b/ncurses/fifo_defs.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ * Common macros for lib_getch.c, lib_ungetch.c
+ *
+ * $Id: fifo_defs.h,v 1.6 2008/06/28 15:52:32 tom Exp $
+ */
+
+#ifndef FIFO_DEFS_H
+#define FIFO_DEFS_H 1
+
+#define head	sp->_fifohead
+#define tail	sp->_fifotail
+/* peek points to next uninterpreted character */
+#define peek	sp->_fifopeek
+
+#define h_inc() { head == FIFO_SIZE-1 ? head = 0 : head++; if (head == tail) head = -1, tail = 0;}
+#define h_dec() { head == 0 ? head = FIFO_SIZE-1 : head--; if (head == tail) tail = -1;}
+#define t_inc() { tail == FIFO_SIZE-1 ? tail = 0 : tail++; if (tail == head) tail = -1;}
+#define t_dec() { tail == 0 ? tail = FIFO_SIZE-1 : tail--; if (head == tail) fifo_clear(sp);}
+#define p_inc() { peek == FIFO_SIZE-1 ? peek = 0 : peek++;}
+
+#define cooked_key_in_fifo()	((head != -1) && (peek != head))
+#define raw_key_in_fifo()	((head != -1) && (peek != tail))
+
+#undef HIDE_EINTR
+
+#endif /* FIFO_DEFS_H */
diff --git a/ncurses/llib-lncurses b/ncurses/llib-lncurses
new file mode 100644
index 0000000..cc0e366
--- /dev/null
+++ b/ncurses/llib-lncurses
@@ -0,0 +1,3436 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 1996-2008                                      *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tty/hardscroll.c */
+
+#include <curses.priv.h>
+
+#undef _nc_oldnums
+int	*_nc_oldnums;
+
+#undef _nc_scroll_optimize
+void	_nc_scroll_optimize(void)
+		{ /* void */ }
+
+#undef _nc_linedump
+void	_nc_linedump(void)
+		{ /* void */ }
+
+/* ./tty/hashmap.c */
+
+#include <term.h>
+
+#undef _nc_hash_map
+void	_nc_hash_map(void)
+		{ /* void */ }
+
+#undef _nc_make_oldhash
+void	_nc_make_oldhash(
+		int	i)
+		{ /* void */ }
+
+#undef _nc_scroll_oldhash
+void	_nc_scroll_oldhash(
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
+/* ./base/lib_addch.c */
+
+#include <ctype.h>
+
+#undef _nc_render
+chtype	_nc_render(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(chtype *)0); }
+
+#undef _nc_waddch_nosync
+int	_nc_waddch_nosync(
+		WINDOW	*win, 
+		const chtype c)
+		{ return(*(int *)0); }
+
+#undef waddch
+int	waddch(
+		WINDOW	*win, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+#undef wechochar
+int	wechochar(
+		WINDOW	*win, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_addstr.c */
+
+#undef waddnstr
+int	waddnstr(
+		WINDOW	*win, 
+		const char *astr, 
+		int	n)
+		{ return(*(int *)0); }
+
+#undef waddchnstr
+int	waddchnstr(
+		WINDOW	*win, 
+		const chtype *astr, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_beep.c */
+
+#undef beep
+int	beep(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_bkgd.c */
+
+#undef wbkgdset
+void	wbkgdset(
+		WINDOW	*win, 
+		chtype	ch)
+		{ /* void */ }
+
+#undef wbkgd
+int	wbkgd(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_box.c */
+
+#undef wborder
+int	wborder(
+		WINDOW	*win, 
+		chtype	ls, 
+		chtype	rs, 
+		chtype	ts, 
+		chtype	bs, 
+		chtype	tl, 
+		chtype	tr, 
+		chtype	bl, 
+		chtype	br)
+		{ return(*(int *)0); }
+
+/* ./base/lib_chgat.c */
+
+#undef wchgat
+int	wchgat(
+		WINDOW	*win, 
+		int	n, 
+		attr_t	attr, 
+		short	color, 
+		const void *opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clear.c */
+
+#undef wclear
+int	wclear(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clearok.c */
+
+#undef clearok
+int	clearok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clrbot.c */
+
+#undef wclrtobot
+int	wclrtobot(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clreol.c */
+
+#undef wclrtoeol
+int	wclrtoeol(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_color.c */
+
+#include <tic.h>
+
+#undef COLOR_PAIRS
+int	COLOR_PAIRS;
+#undef COLORS
+int	COLORS;
+
+#undef _nc_reset_colors
+NCURSES_BOOL _nc_reset_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef start_color
+int	start_color(void)
+		{ return(*(int *)0); }
+
+#undef init_pair
+int	init_pair(
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef init_color
+int	init_color(
+		short	color, 
+		short	r, 
+		short	g, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef can_change_color
+NCURSES_BOOL can_change_color(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_colors
+NCURSES_BOOL has_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef color_content
+int	color_content(
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef pair_content
+int	pair_content(
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef _nc_do_color
+void	_nc_do_color(
+		short	old_pair, 
+		short	pair, 
+		NCURSES_BOOL reverse, 
+		int	(*outc)(
+		int	p1))
+		{ /* void */ }
+
+/* ./base/lib_colorset.c */
+
+#undef wcolor_set
+int	wcolor_set(
+		WINDOW	*win, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_delch.c */
+
+#undef wdelch
+int	wdelch(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_delwin.c */
+
+#undef delwin
+int	delwin(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_echo.c */
+
+#undef echo
+int	echo(void)
+		{ return(*(int *)0); }
+
+#undef noecho
+int	noecho(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_endwin.c */
+
+#undef endwin
+int	endwin(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_erase.c */
+
+#undef werase
+int	werase(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_flash.c */
+
+#undef flash
+int	flash(void)
+		{ return(*(int *)0); }
+
+/* ./lib_gen.c */
+
+#undef addch
+int	addch(
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef addchnstr
+int	addchnstr(
+		const chtype *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef addchstr
+int	addchstr(
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef addnstr
+int	addnstr(
+		const char *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef addstr
+int	addstr(
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef attroff
+int	attroff(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attron
+int	attron(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attrset
+int	attrset(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attr_get
+int	attr_get(
+		attr_t	*a1, 
+		short	*a2, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_off
+int	attr_off(
+		attr_t	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_on
+int	attr_on(
+		attr_t	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_set
+int	attr_set(
+		attr_t	a1, 
+		short	a2, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef bkgd
+int	bkgd(
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef bkgdset
+void	bkgdset(
+		chtype	z)
+		{ /* void */ }
+
+#undef border
+int	border(
+		chtype	a1, 
+		chtype	a2, 
+		chtype	a3, 
+		chtype	a4, 
+		chtype	a5, 
+		chtype	a6, 
+		chtype	a7, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef box
+int	box(
+		WINDOW	*a1, 
+		chtype	a2, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef chgat
+int	chgat(
+		int	a1, 
+		attr_t	a2, 
+		short	a3, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef clear
+int	clear(void)
+		{ return(*(int *)0); }
+
+#undef clrtobot
+int	clrtobot(void)
+		{ return(*(int *)0); }
+
+#undef clrtoeol
+int	clrtoeol(void)
+		{ return(*(int *)0); }
+
+#undef color_set
+int	color_set(
+		short	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef COLOR_PAIR
+int	COLOR_PAIR(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef delch
+int	delch(void)
+		{ return(*(int *)0); }
+
+#undef deleteln
+int	deleteln(void)
+		{ return(*(int *)0); }
+
+#undef echochar
+int	echochar(
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef erase
+int	erase(void)
+		{ return(*(int *)0); }
+
+#undef getbkgd
+chtype	getbkgd(
+		WINDOW	*z)
+		{ return(*(chtype *)0); }
+
+#undef getch
+int	getch(void)
+		{ return(*(int *)0); }
+
+#undef getnstr
+int	getnstr(
+		char	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef getstr
+int	getstr(
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef hline
+int	hline(
+		chtype	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef inch
+chtype	inch(void)
+		{ return(*(chtype *)0); }
+
+#undef inchnstr
+int	inchnstr(
+		chtype	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef inchstr
+int	inchstr(
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef innstr
+int	innstr(
+		char	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insch
+int	insch(
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef insdelln
+int	insdelln(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insertln
+int	insertln(void)
+		{ return(*(int *)0); }
+
+#undef insnstr
+int	insnstr(
+		const char *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insstr
+int	insstr(
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef instr
+int	instr(
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef move
+int	move(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddch
+int	mvaddch(
+		int	a1, 
+		int	a2, 
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef mvaddchnstr
+int	mvaddchnstr(
+		int	a1, 
+		int	a2, 
+		const chtype *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddchstr
+int	mvaddchstr(
+		int	a1, 
+		int	a2, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef mvaddnstr
+int	mvaddnstr(
+		int	a1, 
+		int	a2, 
+		const char *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddstr
+int	mvaddstr(
+		int	a1, 
+		int	a2, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvchgat
+int	mvchgat(
+		int	a1, 
+		int	a2, 
+		int	a3, 
+		attr_t	a4, 
+		short	a5, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef mvdelch
+int	mvdelch(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetch
+int	mvgetch(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetnstr
+int	mvgetnstr(
+		int	a1, 
+		int	a2, 
+		char	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetstr
+int	mvgetstr(
+		int	a1, 
+		int	a2, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvhline
+int	mvhline(
+		int	a1, 
+		int	a2, 
+		chtype	a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinch
+chtype	mvinch(
+		int	a1, 
+		int	z)
+		{ return(*(chtype *)0); }
+
+#undef mvinchnstr
+int	mvinchnstr(
+		int	a1, 
+		int	a2, 
+		chtype	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinchstr
+int	mvinchstr(
+		int	a1, 
+		int	a2, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef mvinnstr
+int	mvinnstr(
+		int	a1, 
+		int	a2, 
+		char	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinsch
+int	mvinsch(
+		int	a1, 
+		int	a2, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef mvinsnstr
+int	mvinsnstr(
+		int	a1, 
+		int	a2, 
+		const char *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinsstr
+int	mvinsstr(
+		int	a1, 
+		int	a2, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvinstr
+int	mvinstr(
+		int	a1, 
+		int	a2, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvvline
+int	mvvline(
+		int	a1, 
+		int	a2, 
+		chtype	a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddch
+int	mvwaddch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef mvwaddchnstr
+int	mvwaddchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddchstr
+int	mvwaddchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef mvwaddnstr
+int	mvwaddnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddstr
+int	mvwaddstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvwchgat
+int	mvwchgat(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		int	a4, 
+		attr_t	a5, 
+		short	a6, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef mvwdelch
+int	mvwdelch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetch
+int	mvwgetch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetnstr
+int	mvwgetnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetstr
+int	mvwgetstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvwhline
+int	mvwhline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinch
+chtype	mvwinch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(chtype *)0); }
+
+#undef mvwinchnstr
+int	mvwinchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinchstr
+int	mvwinchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef mvwinnstr
+int	mvwinnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsch
+int	mvwinsch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsnstr
+int	mvwinsnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsstr
+int	mvwinsstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvwinstr
+int	mvwinstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvwvline
+int	mvwvline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef PAIR_NUMBER
+int	PAIR_NUMBER(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef redrawwin
+int	redrawwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef refresh
+int	refresh(void)
+		{ return(*(int *)0); }
+
+#undef scrl
+int	scrl(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef scroll
+int	scroll(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef setscrreg
+int	setscrreg(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef standout
+int	standout(void)
+		{ return(*(int *)0); }
+
+#undef standend
+int	standend(void)
+		{ return(*(int *)0); }
+
+#undef timeout
+void	timeout(
+		int	z)
+		{ /* void */ }
+
+#undef touchline
+int	touchline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef touchwin
+int	touchwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef untouchwin
+int	untouchwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef vline
+int	vline(
+		chtype	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef vw_printw
+int	vw_printw(
+		WINDOW	*a1, 
+		const char *a2, 
+		va_list	z)
+		{ return(*(int *)0); }
+
+#undef vw_scanw
+int	vw_scanw(
+		WINDOW	*a1, 
+		char	*a2, 
+		va_list	z)
+		{ return(*(int *)0); }
+
+#undef waddchstr
+int	waddchstr(
+		WINDOW	*a1, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef waddstr
+int	waddstr(
+		WINDOW	*a1, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef wattron
+int	wattron(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattroff
+int	wattroff(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattrset
+int	wattrset(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattr_get
+int	wattr_get(
+		WINDOW	*a1, 
+		attr_t	*a2, 
+		short	*a3, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef wattr_set
+int	wattr_set(
+		WINDOW	*a1, 
+		attr_t	a2, 
+		short	a3, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef wdeleteln
+int	wdeleteln(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef wgetstr
+int	wgetstr(
+		WINDOW	*a1, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef winchstr
+int	winchstr(
+		WINDOW	*a1, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef winsertln
+int	winsertln(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef winsstr
+int	winsstr(
+		WINDOW	*a1, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef winstr
+int	winstr(
+		WINDOW	*a1, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef wstandout
+int	wstandout(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef wstandend
+int	wstandend(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef getattrs
+int	getattrs(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getcurx
+int	getcurx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getcury
+int	getcury(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getbegx
+int	getbegx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getbegy
+int	getbegy(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getmaxx
+int	getmaxx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getmaxy
+int	getmaxy(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getparx
+int	getparx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getpary
+int	getpary(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef wgetparent
+WINDOW	*wgetparent(
+		const WINDOW *z)
+		{ return(*(WINDOW **)0); }
+
+#undef is_cleared
+NCURSES_BOOL is_cleared(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_idcok
+NCURSES_BOOL is_idcok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_idlok
+NCURSES_BOOL is_idlok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_immedok
+NCURSES_BOOL is_immedok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_keypad
+NCURSES_BOOL is_keypad(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_leaveok
+NCURSES_BOOL is_leaveok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_nodelay
+NCURSES_BOOL is_nodelay(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_notimeout
+NCURSES_BOOL is_notimeout(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_scrollok
+NCURSES_BOOL is_scrollok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_syncok
+NCURSES_BOOL is_syncok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef wgetscrreg
+int	wgetscrreg(
+		const WINDOW *a1, 
+		int	*a2, 
+		int	*z)
+		{ return(*(int *)0); }
+
+#undef mouse_trafo
+NCURSES_BOOL mouse_trafo(
+		int	*a1, 
+		int	*a2, 
+		NCURSES_BOOL z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_getch.c */
+
+#include <fifo_defs.h>
+
+#undef ESCDELAY
+int	ESCDELAY;
+
+#undef set_escdelay
+int	set_escdelay(
+		int	value)
+		{ return(*(int *)0); }
+
+#undef _nc_wgetch
+int	_nc_wgetch(
+		WINDOW	*win, 
+		unsigned long *result, 
+		int	use_meta)
+		{ return(*(int *)0); }
+
+#undef wgetch
+int	wgetch(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_getstr.c */
+
+#undef wgetnstr
+int	wgetnstr(
+		WINDOW	*win, 
+		char	*str, 
+		int	maxlen)
+		{ return(*(int *)0); }
+
+/* ./base/lib_hline.c */
+
+#undef whline
+int	whline(
+		WINDOW	*win, 
+		chtype	ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_immedok.c */
+
+#undef immedok
+void	immedok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ /* void */ }
+
+/* ./base/lib_inchstr.c */
+
+#undef winchnstr
+int	winchnstr(
+		WINDOW	*win, 
+		chtype	*str, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_initscr.c */
+
+#undef initscr
+WINDOW	*initscr(void)
+		{ return(*(WINDOW **)0); }
+
+/* ./base/lib_insch.c */
+
+#undef _nc_insert_ch
+int	_nc_insert_ch(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(int *)0); }
+
+#undef winsch
+int	winsch(
+		WINDOW	*win, 
+		chtype	c)
+		{ return(*(int *)0); }
+
+/* ./base/lib_insdel.c */
+
+#undef winsdelln
+int	winsdelln(
+		WINDOW	*win, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_insnstr.c */
+
+#undef winsnstr
+int	winsnstr(
+		WINDOW	*win, 
+		const char *s, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_instr.c */
+
+#undef winnstr
+int	winnstr(
+		WINDOW	*win, 
+		char	*str, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_isendwin.c */
+
+#undef isendwin
+NCURSES_BOOL isendwin(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_leaveok.c */
+
+#undef leaveok
+int	leaveok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_mouse.c */
+
+#undef getmouse
+int	getmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef ungetmouse
+int	ungetmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef mousemask
+mmask_t	mousemask(
+		mmask_t	newmask, 
+		mmask_t	*oldmask)
+		{ return(*(mmask_t *)0); }
+
+#undef wenclose
+NCURSES_BOOL wenclose(
+		const WINDOW *win, 
+		int	y, 
+		int	x)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef mouseinterval
+int	mouseinterval(
+		int	maxclick)
+		{ return(*(int *)0); }
+
+#undef _nc_has_mouse
+int	_nc_has_mouse(void)
+		{ return(*(int *)0); }
+
+#undef wmouse_trafo
+NCURSES_BOOL wmouse_trafo(
+		const WINDOW *win, 
+		int	*pY, 
+		int	*pX, 
+		NCURSES_BOOL to_screen)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_move.c */
+
+#undef wmove
+int	wmove(
+		WINDOW	*win, 
+		int	y, 
+		int	x)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_mvcur.c */
+
+#undef _nc_msec_cost
+int	_nc_msec_cost(
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur_resume
+void	_nc_mvcur_resume(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_init
+void	_nc_mvcur_init(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_wrap
+void	_nc_mvcur_wrap(void)
+		{ /* void */ }
+
+#undef mvcur
+int	mvcur(
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef _nc_optimize_enable
+int	_nc_optimize_enable;
+
+/* ./base/lib_mvwin.c */
+
+#undef mvwin
+int	mvwin(
+		WINDOW	*win, 
+		int	by, 
+		int	bx)
+		{ return(*(int *)0); }
+
+/* ./base/lib_newterm.c */
+
+#undef filter
+void	filter(void)
+		{ /* void */ }
+
+#undef nofilter
+void	nofilter(void)
+		{ /* void */ }
+
+#undef newterm
+SCREEN	*newterm(
+		char	*name, 
+		FILE	*ofp, 
+		FILE	*ifp)
+		{ return(*(SCREEN **)0); }
+
+/* ./base/lib_newwin.c */
+
+#undef _nc_freewin
+int	_nc_freewin(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+#undef newwin
+WINDOW	*newwin(
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef derwin
+WINDOW	*derwin(
+		WINDOW	*orig, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef subwin
+WINDOW	*subwin(
+		WINDOW	*w, 
+		int	l, 
+		int	c, 
+		int	y, 
+		int	x)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_makenew
+WINDOW	*_nc_makenew(
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx, 
+		int	flags)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+/* ./base/lib_nl.c */
+
+#undef nl
+int	nl(void)
+		{ return(*(int *)0); }
+
+#undef nonl
+int	nonl(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_overlay.c */
+
+#undef overlay
+int	overlay(
+		const WINDOW *win1, 
+		WINDOW	*win2)
+		{ return(*(int *)0); }
+
+#undef overwrite
+int	overwrite(
+		const WINDOW *win1, 
+		WINDOW	*win2)
+		{ return(*(int *)0); }
+
+#undef copywin
+int	copywin(
+		const WINDOW *src, 
+		WINDOW	*dst, 
+		int	sminrow, 
+		int	smincol, 
+		int	dminrow, 
+		int	dmincol, 
+		int	dmaxrow, 
+		int	dmaxcol, 
+		int	over)
+		{ return(*(int *)0); }
+
+/* ./base/lib_pad.c */
+
+#undef newpad
+WINDOW	*newpad(
+		int	l, 
+		int	c)
+		{ return(*(WINDOW **)0); }
+
+#undef subpad
+WINDOW	*subpad(
+		WINDOW	*orig, 
+		int	l, 
+		int	c, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef prefresh
+int	prefresh(
+		WINDOW	*win, 
+		int	pminrow, 
+		int	pmincol, 
+		int	sminrow, 
+		int	smincol, 
+		int	smaxrow, 
+		int	smaxcol)
+		{ return(*(int *)0); }
+
+#undef pnoutrefresh
+int	pnoutrefresh(
+		WINDOW	*win, 
+		int	pminrow, 
+		int	pmincol, 
+		int	sminrow, 
+		int	smincol, 
+		int	smaxrow, 
+		int	smaxcol)
+		{ return(*(int *)0); }
+
+#undef pechochar
+int	pechochar(
+		WINDOW	*pad, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_printw.c */
+
+#undef printw
+int	printw(
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef wprintw
+int	wprintw(
+		WINDOW	*win, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvprintw
+int	mvprintw(
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvwprintw
+int	mvwprintw(
+		WINDOW	*win, 
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef vwprintw
+int	vwprintw(
+		WINDOW	*win, 
+		const char *fmt, 
+		va_list	argp)
+		{ return(*(int *)0); }
+
+/* ./base/lib_redrawln.c */
+
+#undef wredrawln
+int	wredrawln(
+		WINDOW	*win, 
+		int	beg, 
+		int	num)
+		{ return(*(int *)0); }
+
+/* ./base/lib_refresh.c */
+
+#undef wrefresh
+int	wrefresh(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+#undef wnoutrefresh
+int	wnoutrefresh(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_restart.c */
+
+#undef restartterm
+int	restartterm(
+		char	*termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scanw.c */
+
+#undef vwscanw
+int	vwscanw(
+		WINDOW	*win, 
+		char	*fmt, 
+		va_list	argp)
+		{ return(*(int *)0); }
+
+#undef scanw
+int	scanw(
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef wscanw
+int	wscanw(
+		WINDOW	*win, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvscanw
+int	mvscanw(
+		int	y, 
+		int	x, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvwscanw
+int	mvwscanw(
+		WINDOW	*win, 
+		int	y, 
+		int	x, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+/* ./base/lib_screen.c */
+
+#undef getwin
+WINDOW	*getwin(
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
+#undef putwin
+int	putwin(
+		WINDOW	*win, 
+		FILE	*filep)
+		{ return(*(int *)0); }
+
+#undef scr_restore
+int	scr_restore(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_dump
+int	scr_dump(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_init
+int	scr_init(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_set
+int	scr_set(
+		const char *file)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scroll.c */
+
+#undef _nc_scroll_window
+void	_nc_scroll_window(
+		WINDOW	*win, 
+		int const n, 
+		short const top, 
+		short const bottom, 
+		chtype	blank)
+		{ /* void */ }
+
+#undef wscrl
+int	wscrl(
+		WINDOW	*win, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scrollok.c */
+
+#undef scrollok
+int	scrollok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scrreg.c */
+
+#undef wsetscrreg
+int	wsetscrreg(
+		WINDOW	*win, 
+		int	top, 
+		int	bottom)
+		{ return(*(int *)0); }
+
+/* ./base/lib_set_term.c */
+
+#undef set_term
+SCREEN	*set_term(
+		SCREEN	*screenp)
+		{ return(*(SCREEN **)0); }
+
+#undef delscreen
+void	delscreen(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_setupscreen
+int	_nc_setupscreen(
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		NCURSES_BOOL filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
+#undef _nc_ripoffline
+int	_nc_ripoffline(
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+#undef ripoffline
+int	ripoffline(
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+/* ./base/lib_slk.c */
+
+#undef _nc_slk_initialize
+int	_nc_slk_initialize(
+		WINDOW	*stwin, 
+		int	cols)
+		{ return(*(int *)0); }
+
+#undef slk_restore
+int	slk_restore(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatr_set.c */
+
+#undef slk_attr_set
+int	slk_attr_set(
+		const attr_t attr, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatrof.c */
+
+#undef slk_attroff
+int	slk_attroff(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatron.c */
+
+#undef slk_attron
+int	slk_attron(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatrset.c */
+
+#undef slk_attrset
+int	slk_attrset(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkattr.c */
+
+#undef slk_attr
+attr_t	slk_attr(void)
+		{ return(*(attr_t *)0); }
+
+/* ./base/lib_slkclear.c */
+
+#undef slk_clear
+int	slk_clear(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkcolor.c */
+
+#undef slk_color
+int	slk_color(
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkinit.c */
+
+#undef slk_init
+int	slk_init(
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slklab.c */
+
+#undef slk_label
+char	*slk_label(
+		int	n)
+		{ return(*(char **)0); }
+
+/* ./base/lib_slkrefr.c */
+
+#undef slk_noutrefresh
+int	slk_noutrefresh(void)
+		{ return(*(int *)0); }
+
+#undef slk_refresh
+int	slk_refresh(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkset.c */
+
+#undef slk_set
+int	slk_set(
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slktouch.c */
+
+#undef slk_touch
+int	slk_touch(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_touch.c */
+
+#undef is_linetouched
+NCURSES_BOOL is_linetouched(
+		WINDOW	*win, 
+		int	line)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_wintouched
+NCURSES_BOOL is_wintouched(
+		WINDOW	*win)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef wtouchln
+int	wtouchln(
+		WINDOW	*win, 
+		int	y, 
+		int	n, 
+		int	changed)
+		{ return(*(int *)0); }
+
+/* ./trace/lib_tracedmp.c */
+
+#undef _tracedump
+void	_tracedump(
+		const char *name, 
+		WINDOW	*win)
+		{ /* void */ }
+
+/* ./trace/lib_tracemse.c */
+
+#undef _nc_tracemouse
+char	*_nc_tracemouse(
+		SCREEN	*sp, 
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+#undef _tracemouse
+char	*_tracemouse(
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+/* ./tty/lib_tstp.c */
+
+#include <SigAction.h>
+
+#undef _nc_signal_handler
+void	_nc_signal_handler(
+		NCURSES_BOOL enable)
+		{ /* void */ }
+
+/* ./base/lib_ungetch.c */
+
+#undef _nc_fifo_dump
+void	_nc_fifo_dump(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_ungetch
+int	_nc_ungetch(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef ungetch
+int	ungetch(
+		int	ch)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_vidattr.c */
+
+#undef vidputs
+int	vidputs(
+		chtype	newmode, 
+		int	(*outc)(
+		int	p1))
+		{ return(*(int *)0); }
+
+#undef vidattr
+int	vidattr(
+		chtype	newmode)
+		{ return(*(int *)0); }
+
+#undef termattrs
+chtype	termattrs(void)
+		{ return(*(chtype *)0); }
+
+/* ./base/lib_vline.c */
+
+#undef wvline
+int	wvline(
+		WINDOW	*win, 
+		chtype	ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_wattroff.c */
+
+#undef wattr_off
+int	wattr_off(
+		WINDOW	*win, 
+		attr_t	at, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_wattron.c */
+
+#undef wattr_on
+int	wattr_on(
+		WINDOW	*win, 
+		attr_t	at, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_winch.c */
+
+#undef winch
+chtype	winch(
+		WINDOW	*win)
+		{ return(*(chtype *)0); }
+
+/* ./base/lib_window.c */
+
+#undef _nc_synchook
+void	_nc_synchook(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef mvderwin
+int	mvderwin(
+		WINDOW	*win, 
+		int	y, 
+		int	x)
+		{ return(*(int *)0); }
+
+#undef syncok
+int	syncok(
+		WINDOW	*win, 
+		NCURSES_BOOL bf)
+		{ return(*(int *)0); }
+
+#undef wsyncup
+void	wsyncup(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef wsyncdown
+void	wsyncdown(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef wcursyncup
+void	wcursyncup(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef dupwin
+WINDOW	*dupwin(
+		WINDOW	*win)
+		{ return(*(WINDOW **)0); }
+
+/* ./base/nc_panel.c */
+
+#undef _nc_panelhook
+struct panelhook *_nc_panelhook(void)
+		{ return(*(struct panelhook **)0); }
+
+/* ./base/safe_sprintf.c */
+
+#undef _nc_printf_string
+char	*_nc_printf_string(
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+/* ./tty/tty_update.c */
+
+#include <sys/time.h>
+#include <sys/times.h>
+
+#undef doupdate
+int	doupdate(void)
+		{ return(*(int *)0); }
+
+#undef _nc_scrolln
+int	_nc_scrolln(
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
+#undef _nc_screen_resume
+void	_nc_screen_resume(void)
+		{ /* void */ }
+
+#undef _nc_screen_init
+void	_nc_screen_init(void)
+		{ /* void */ }
+
+#undef _nc_screen_wrap
+void	_nc_screen_wrap(void)
+		{ /* void */ }
+
+#undef _nc_do_xmc_glitch
+void	_nc_do_xmc_glitch(
+		attr_t	previous)
+		{ /* void */ }
+
+/* ./trace/varargs.c */
+
+typedef enum {
+    atUnknown = 0, atInteger, atFloat, atPoint, atString
+} ARGTYPE;
+
+#undef _nc_varargs
+char	*_nc_varargs(
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+/* ./base/memmove.c */
+
+#undef _nc_memmove
+void	_nc_memmove(void)
+		{ /* void */ }
+
+/* ./base/vsscanf.c */
+
+#undef _nc_vsscanf
+void	_nc_vsscanf(void)
+		{ /* void */ }
+
+/* ./base/lib_freeall.c */
+
+#include <term_entry.h>
+
+#undef _nc_freeall
+void	_nc_freeall(void)
+		{ /* void */ }
+
+#undef _nc_free_and_exit
+void	_nc_free_and_exit(
+		int	code)
+		{ /* void */ }
+
+/* ./expanded.c */
+
+#undef _nc_toggle_attr_on
+void	_nc_toggle_attr_on(
+		attr_t	*S, 
+		attr_t	at)
+		{ /* void */ }
+
+#undef _nc_toggle_attr_off
+void	_nc_toggle_attr_off(
+		attr_t	*S, 
+		attr_t	at)
+		{ /* void */ }
+
+#undef _nc_DelCharCost
+int	_nc_DelCharCost(
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_InsCharCost
+int	_nc_InsCharCost(
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_UpdateAttrs
+void	_nc_UpdateAttrs(
+		chtype	c)
+		{ /* void */ }
+
+/* ./base/legacy_coding.c */
+
+#undef use_legacy_coding
+int	use_legacy_coding(
+		int	level)
+		{ return(*(int *)0); }
+
+/* ./base/lib_dft_fgbg.c */
+
+#undef use_default_colors
+int	use_default_colors(void)
+		{ return(*(int *)0); }
+
+#undef assume_default_colors
+int	assume_default_colors(
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_print.c */
+
+#undef mcprint
+int	mcprint(
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
+/* ./base/resizeterm.c */
+
+#undef is_term_resized
+NCURSES_BOOL is_term_resized(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef resize_term
+int	resize_term(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+#undef resizeterm
+int	resizeterm(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+/* ./trace/trace_xnames.c */
+
+#undef _nc_trace_xnames
+void	_nc_trace_xnames(
+		TERMTYPE *tp)
+		{ /* void */ }
+
+/* ./tinfo/use_screen.c */
+
+#undef use_screen
+int	use_screen(
+		SCREEN	*screen, 
+		NCURSES_SCREEN_CB func, 
+		void	*data)
+		{ return(*(int *)0); }
+
+/* ./base/use_window.c */
+
+#undef use_window
+int	use_window(
+		WINDOW	*win, 
+		NCURSES_WINDOW_CB func, 
+		void	*data)
+		{ return(*(int *)0); }
+
+/* ./base/wresize.c */
+
+#undef wresize
+int	wresize(
+		WINDOW	*win, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+/* ./tinfo/access.c */
+
+#include <sys/stat.h>
+#include <nc_alloc.h>
+
+#undef _nc_rootname
+char	*_nc_rootname(
+		char	*path)
+		{ return(*(char **)0); }
+
+#undef _nc_is_abs_path
+NCURSES_BOOL _nc_is_abs_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_pathlast
+unsigned _nc_pathlast(
+		const char *path)
+		{ return(*(unsigned *)0); }
+
+#undef _nc_basename
+char	*_nc_basename(
+		char	*path)
+		{ return(*(char **)0); }
+
+#undef _nc_access
+int	_nc_access(
+		const char *path, 
+		int	mode)
+		{ return(*(int *)0); }
+
+#undef _nc_is_dir_path
+NCURSES_BOOL _nc_is_dir_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_is_file_path
+NCURSES_BOOL _nc_is_file_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_env_access
+int	_nc_env_access(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/add_tries.c */
+
+#undef _nc_add_to_try
+int	_nc_add_to_try(
+		TRIES	**tree, 
+		const char *str, 
+		unsigned code)
+		{ return(*(int *)0); }
+
+/* ./tinfo/alloc_ttype.c */
+
+#undef _nc_align_termtype
+void	_nc_align_termtype(
+		TERMTYPE *to, 
+		TERMTYPE *from)
+		{ /* void */ }
+
+#undef _nc_copy_termtype
+void	_nc_copy_termtype(
+		TERMTYPE *dst, 
+		TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef boolcodes
+char	*const boolcodes[] = {0};
+#undef numcodes
+char	*const numcodes[] = {0};
+#undef strcodes
+char	*const strcodes[] = {0};
+
+/* ./tinfo/comp_error.c */
+#undef _nc_suppress_warnings
+NCURSES_BOOL _nc_suppress_warnings;
+#undef _nc_curr_line
+int	_nc_curr_line;
+#undef _nc_curr_col
+int	_nc_curr_col;
+
+#undef _nc_get_source
+const char *_nc_get_source(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_set_source
+void	_nc_set_source(
+		const char *const name)
+		{ /* void */ }
+
+#undef _nc_set_type
+void	_nc_set_type(
+		const char *const name)
+		{ /* void */ }
+
+#undef _nc_get_type
+void	_nc_get_type(
+		char	*name)
+		{ /* void */ }
+
+#undef _nc_warning
+void	_nc_warning(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_err_abort
+void	_nc_err_abort(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_syserr_abort
+void	_nc_syserr_abort(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+/* ./tinfo/db_iterator.c */
+
+#undef _nc_tic_dir
+const char *_nc_tic_dir(
+		const char *path)
+		{ return(*(const char **)0); }
+
+#undef _nc_keep_tic_dir
+void	_nc_keep_tic_dir(
+		const char *path)
+		{ /* void */ }
+
+#undef _nc_last_db
+void	_nc_last_db(void)
+		{ /* void */ }
+
+#undef _nc_next_db
+const char *_nc_next_db(
+		DBDIRS	*state, 
+		int	*offset)
+		{ return(*(const char **)0); }
+
+#undef _nc_first_db
+void	_nc_first_db(
+		DBDIRS	*state, 
+		int	*offset)
+		{ /* void */ }
+
+/* ./tinfo/doalloc.c */
+
+#undef _nc_doalloc
+void	*_nc_doalloc(
+		void	*oldp, 
+		size_t	amount)
+		{ return(*(void **)0); }
+
+/* ./tinfo/entries.c */
+
+#undef _nc_head
+ENTRY	*_nc_head;
+#undef _nc_tail
+ENTRY	*_nc_tail;
+
+#undef _nc_free_entry
+void	_nc_free_entry(
+		ENTRY	*headp, 
+		TERMTYPE *tterm)
+		{ /* void */ }
+
+#undef _nc_free_entries
+void	_nc_free_entries(
+		ENTRY	*headp)
+		{ /* void */ }
+
+#undef _nc_delink_entry
+ENTRY	*_nc_delink_entry(
+		ENTRY	*headp, 
+		TERMTYPE *tterm)
+		{ return(*(ENTRY **)0); }
+
+#undef _nc_leaks_tinfo
+void	_nc_leaks_tinfo(void)
+		{ /* void */ }
+
+/* ./fallback.c */
+
+#undef _nc_fallback
+const TERMTYPE *_nc_fallback(
+		const char *name)
+		{ return(*(const TERMTYPE **)0); }
+
+/* ./tinfo/free_ttype.c */
+
+#undef _nc_free_termtype
+void	_nc_free_termtype(
+		TERMTYPE *ptr)
+		{ /* void */ }
+
+#undef _nc_user_definable
+NCURSES_BOOL _nc_user_definable;
+
+#undef use_extended_names
+int	use_extended_names(
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/getenv_num.c */
+
+#undef _nc_getenv_num
+int	_nc_getenv_num(
+		const char *name)
+		{ return(*(int *)0); }
+
+/* ./tinfo/home_terminfo.c */
+
+#undef _nc_home_terminfo
+char	*_nc_home_terminfo(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/init_keytry.c */
+
+#if 0
+
+#include <init_keytry.h>
+
+#undef _nc_tinfo_fkeys
+const struct tinfo_fkeys _nc_tinfo_fkeys[] = {0};
+
+#endif
+
+#undef _nc_init_keytry
+void	_nc_init_keytry(
+		SCREEN	*sp)
+		{ /* void */ }
+
+/* ./tinfo/lib_acs.c */
+
+#undef acs_map
+chtype	acs_map[128];
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+#include <termcap.h>
+
+struct speed {
+    int s; 
+    int sp; 
+};
+
+#undef _nc_baudrate
+int	_nc_baudrate(
+		int	OSpeed)
+		{ return(*(int *)0); }
+
+#undef _nc_ospeed
+int	_nc_ospeed(
+		int	BaudRate)
+		{ return(*(int *)0); }
+
+#undef baudrate
+int	baudrate(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_cur_term.c */
+
+#undef cur_term
+TERMINAL *cur_term;
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm
+int	del_curterm(
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_data.c */
+
+#undef stdscr
+WINDOW	*stdscr;
+#undef curscr
+WINDOW	*curscr;
+#undef newscr
+WINDOW	*newscr;
+#undef _nc_screen_chain
+SCREEN	*_nc_screen_chain;
+#undef SP
+SCREEN	*SP;
+#undef _nc_globals
+NCURSES_GLOBALS _nc_globals;
+#undef _nc_prescreen
+NCURSES_PRESCREEN _nc_prescreen;
+
+/* ./tinfo/lib_has_cap.c */
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef _nc_keyname
+char	*_nc_keyname(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(char **)0); }
+
+#undef keyname
+char	*keyname(
+		int	c)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#include <time.h>
+
+#undef napms
+int	napms(
+		int	ms)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_options.c */
+
+#undef idlok
+int	idlok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef idcok
+void	idcok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ /* void */ }
+
+#undef halfdelay
+int	halfdelay(
+		int	t)
+		{ return(*(int *)0); }
+
+#undef nodelay
+int	nodelay(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef notimeout
+int	notimeout(
+		WINDOW	*win, 
+		NCURSES_BOOL f)
+		{ return(*(int *)0); }
+
+#undef wtimeout
+void	wtimeout(
+		WINDOW	*win, 
+		int	delay)
+		{ /* void */ }
+
+#undef keypad
+int	keypad(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef meta
+int	meta(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush
+int	intrflush(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_setup.c */
+
+#include <locale.h>
+#include <sys/ioctl.h>
+#include <langinfo.h>
+
+#undef ttytype
+char	ttytype[256];
+#undef LINES
+int	LINES;
+#undef COLS
+int	COLS;
+#undef TABSIZE
+int	TABSIZE;
+
+#undef set_tabsize
+int	set_tabsize(
+		int	value)
+		{ return(*(int *)0); }
+
+#undef _nc_handle_sigwinch
+int	_nc_handle_sigwinch(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef _nc_get_screensize
+void	_nc_get_screensize(
+		SCREEN	*sp, 
+		int	*linep, 
+		int	*colp)
+		{ /* void */ }
+
+#undef _nc_update_screensize
+void	_nc_update_screensize(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_get_locale
+char	*_nc_get_locale(void)
+		{ return(*(char **)0); }
+
+#undef _nc_unicode_locale
+int	_nc_unicode_locale(void)
+		{ return(*(int *)0); }
+
+#undef _nc_locale_breaks_acs
+int	_nc_locale_breaks_acs(
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
+#undef _nc_setupterm
+int	_nc_setupterm(
+		char	*tname, 
+		int	Filedes, 
+		int	*errret, 
+		NCURSES_BOOL reuse)
+		{ return(*(int *)0); }
+
+#undef setupterm
+int	setupterm(
+		char	*tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#if 0
+
+#include <capdefaults.c>
+
+#endif
+
+#undef tgetflag
+int	tgetflag(
+		char	*id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		char	*id)
+		{ return(*(int *)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		char	*id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname
+char	*termname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tgoto.c */
+
+#undef tgoto
+char	*tgoto(
+		const char *string, 
+		int	x, 
+		int	y)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_ti.c */
+
+#undef tigetflag
+int	tigetflag(
+		char	*str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		char	*str)
+		{ return(*(int *)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		char	*str)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tparm.c */
+
+#undef _nc_tparm_err
+int	_nc_tparm_err;
+
+#undef _nc_tparm_analyze
+int	_nc_tparm_analyze(
+		const char *string, 
+		char	*p_is_s[9], 
+		int	*popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		char	*string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+NCURSES_OSPEED	ospeed;
+#undef _nc_nulls_sent
+int	_nc_nulls_sent;
+
+#undef _nc_set_no_padding
+void	_nc_set_no_padding(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs
+int	tputs(
+		const char *string, 
+		int	affcnt, 
+		int	(*outc)(
+		int	p1))
+		{ return(*(int *)0); }
+
+/* ./trace/lib_trace.c */
+
+#undef _nc_tracing
+unsigned _nc_tracing;
+#undef _nc_tputs_trace
+const char *_nc_tputs_trace = {0};
+#undef _nc_outchars
+long	_nc_outchars;
+
+#undef trace
+void	trace(
+		const unsigned int tracelevel)
+		{ /* void */ }
+
+#undef _tracef
+void	_tracef(
+		const char *fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_retrace_bool
+NCURSES_BOOL _nc_retrace_bool(
+		NCURSES_BOOL code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_int
+int	_nc_retrace_int(
+		int	code)
+		{ return(*(int *)0); }
+
+#undef _nc_retrace_unsigned
+unsigned _nc_retrace_unsigned(
+		unsigned code)
+		{ return(*(unsigned *)0); }
+
+#undef _nc_retrace_ptr
+char	*_nc_retrace_ptr(
+		char	*code)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_cptr
+const char *_nc_retrace_cptr(
+		const char *code)
+		{ return(*(const char **)0); }
+
+#undef _nc_retrace_cvoid_ptr
+void	*_nc_retrace_cvoid_ptr(
+		void	*code)
+		{ return(*(void **)0); }
+
+#undef _nc_retrace_void_ptr
+void	*_nc_retrace_void_ptr(
+		void	*code)
+		{ return(*(void **)0); }
+
+#undef _nc_retrace_sp
+SCREEN	*_nc_retrace_sp(
+		SCREEN	*code)
+		{ return(*(SCREEN **)0); }
+
+#undef _nc_retrace_win
+WINDOW	*_nc_retrace_win(
+		WINDOW	*code)
+		{ return(*(WINDOW **)0); }
+
+/* ./trace/lib_traceatr.c */
+
+#undef _traceattr2
+char	*_traceattr2(
+		int	bufnum, 
+		chtype	newmode)
+		{ return(*(char **)0); }
+
+#undef _traceattr
+char	*_traceattr(
+		attr_t	newmode)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_attr_t
+attr_t	_nc_retrace_attr_t(
+		attr_t	code)
+		{ return(*(attr_t *)0); }
+
+#undef _nc_altcharset_name
+const char *_nc_altcharset_name(
+		attr_t	attr, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef _tracechtype2
+char	*_tracechtype2(
+		int	bufnum, 
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef _tracechtype
+char	*_tracechtype(
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_chtype
+chtype	_nc_retrace_chtype(
+		chtype	code)
+		{ return(*(chtype *)0); }
+
+/* ./trace/lib_tracebits.c */
+
+typedef struct {
+    unsigned int val;
+    const char *name;
+} BITNAMES;
+
+#undef _nc_trace_ttymode
+char	*_nc_trace_ttymode(
+		struct termios *tty)
+		{ return(*(char **)0); }
+
+#undef _nc_tracebits
+char	*_nc_tracebits(void)
+		{ return(*(char **)0); }
+
+/* ./trace/lib_tracechr.c */
+
+#undef _nc_tracechar
+char	*_nc_tracechar(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(char **)0); }
+
+#undef _tracechar
+char	*_tracechar(
+		int	ch)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_ttyflags.c */
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode
+int	_nc_set_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty
+int	resetty(void)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_twait.c */
+
+#undef _nc_timed_wait
+int	_nc_timed_wait(
+		SCREEN	*sp, 
+		int	mode, 
+		int	milliseconds, 
+		int	*timeleft)
+		{ return(*(int *)0); }
+
+/* ./tinfo/name_match.c */
+
+#undef _nc_first_name
+char	*_nc_first_name(
+		const char *const sp)
+		{ return(*(char **)0); }
+
+#undef _nc_name_match
+int	_nc_name_match(
+		const char *const namelst, 
+		const char *const name, 
+		const char *const delim)
+		{ return(*(int *)0); }
+
+/* ./names.c */
+
+#undef boolnames
+char	*const boolnames[] = {0};
+#undef boolfnames
+char	*const boolfnames[] = {0};
+#undef numnames
+char	*const numnames[] = {0};
+#undef numfnames
+char	*const numfnames[] = {0};
+#undef strnames
+char	*const strnames[] = {0};
+#undef strfnames
+char	*const strfnames[] = {0};
+
+/* ./tinfo/read_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_read_termtype
+int	_nc_read_termtype(
+		TERMTYPE *ptr, 
+		char	*buffer, 
+		int	limit)
+		{ return(*(int *)0); }
+
+#undef _nc_read_file_entry
+int	_nc_read_file_entry(
+		const char *const filename, 
+		TERMTYPE *ptr)
+		{ return(*(int *)0); }
+
+#undef _nc_read_entry
+int	_nc_read_entry(
+		const char *const name, 
+		char	*const filename, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/read_termcap.c */
+
+#include <sys/types.h>
+
+#undef _nc_read_termcap_entry
+int	_nc_read_termcap_entry(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/setbuf.c */
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		NCURSES_BOOL buffered)
+		{ /* void */ }
+
+/* ./tinfo/strings.c */
+
+#undef _nc_str_init
+string_desc *_nc_str_init(
+		string_desc *dst, 
+		char	*src, 
+		size_t	len)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_str_null
+string_desc *_nc_str_null(
+		string_desc *dst, 
+		size_t	len)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_str_copy
+string_desc *_nc_str_copy(
+		string_desc *dst, 
+		string_desc *src)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_safe_strcat
+NCURSES_BOOL _nc_safe_strcat(
+		string_desc *dst, 
+		const char *src)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_safe_strcpy
+NCURSES_BOOL _nc_safe_strcpy(
+		string_desc *dst, 
+		const char *src)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./trace/trace_buf.c */
+
+#undef _nc_trace_buf
+char	*_nc_trace_buf(
+		int	bufnum, 
+		size_t	want)
+		{ return(*(char **)0); }
+
+#undef _nc_trace_bufcat
+char	*_nc_trace_bufcat(
+		int	bufnum, 
+		const char *value)
+		{ return(*(char **)0); }
+
+/* ./trace/trace_tries.c */
+
+#undef _nc_trace_tries
+void	_nc_trace_tries(
+		TRIES	*tree)
+		{ /* void */ }
+
+/* ./base/tries.c */
+
+#undef _nc_expand_try
+char	*_nc_expand_try(
+		TRIES	*tree, 
+		unsigned code, 
+		int	*count, 
+		size_t	len)
+		{ return(*(char **)0); }
+
+#undef _nc_remove_key
+int	_nc_remove_key(
+		TRIES	**tree, 
+		unsigned code)
+		{ return(*(int *)0); }
+
+#undef _nc_remove_string
+int	_nc_remove_string(
+		TRIES	**tree, 
+		const char *string)
+		{ return(*(int *)0); }
+
+/* ./tinfo/trim_sgr0.c */
+
+#undef _nc_trim_sgr0
+char	*_nc_trim_sgr0(
+		TERMTYPE *tp)
+		{ return(*(char **)0); }
+
+/* ./unctrl.c */
+
+#undef _nc_unctrl
+char	*_nc_unctrl(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef unctrl
+char	*unctrl(
+		chtype	ch)
+		{ return(*(char **)0); }
+
+/* ./trace/visbuf.c */
+
+#undef _nc_visbuf2
+const char *_nc_visbuf2(
+		int	bufnum, 
+		const char *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_visbuf
+const char *_nc_visbuf(
+		const char *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_visbufn
+const char *_nc_visbufn(
+		const char *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+#undef _nc_viscbuf2
+const char *_nc_viscbuf2(
+		int	bufnum, 
+		const chtype *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+#undef _nc_viscbuf
+const char *_nc_viscbuf(
+		const chtype *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/alloc_entry.c */
+
+#undef _nc_init_entry
+void	_nc_init_entry(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#undef _nc_copy_entry
+ENTRY	*_nc_copy_entry(
+		ENTRY	*oldp)
+		{ return(*(ENTRY **)0); }
+
+#undef _nc_save_str
+char	*_nc_save_str(
+		const char *const string)
+		{ return(*(char **)0); }
+
+#undef _nc_wrap_entry
+void	_nc_wrap_entry(
+		ENTRY	*const ep, 
+		NCURSES_BOOL copy_strings)
+		{ /* void */ }
+
+#undef _nc_merge_entry
+void	_nc_merge_entry(
+		TERMTYPE *const to, 
+		TERMTYPE *const from)
+		{ /* void */ }
+
+/* ./tinfo/captoinfo.c */
+
+#undef _nc_captoinfo
+char	*_nc_captoinfo(
+		const char *cap, 
+		const char *s, 
+		int const parameterized)
+		{ return(*(char **)0); }
+
+#undef _nc_infotocap
+char	*_nc_infotocap(
+		const char *cap, 
+		const char *str, 
+		int const parameterized)
+		{ return(*(char **)0); }
+
+/* ./comp_captab.c */
+
+#include <hashsize.h>
+
+#undef _nc_get_table
+const struct name_table_entry *_nc_get_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct name_table_entry **)0); }
+
+#undef _nc_get_hash_table
+const short *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const short **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+/* ./tinfo/comp_expand.c */
+
+#undef _nc_tic_expand
+char	*_nc_tic_expand(
+		const char *srcp, 
+		NCURSES_BOOL tic_format, 
+		int	numbers)
+		{ return(*(char **)0); }
+
+/* ./tinfo/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const short *hash_table)
+		{ return(*(struct name_table_entry const **)0); }
+
+#undef _nc_find_type_entry
+struct name_table_entry const *_nc_find_type_entry(
+		const char *string, 
+		int	type, 
+		const struct name_table_entry *table)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./tinfo/comp_parse.c */
+
+#undef _nc_check_termtype2
+void	(*_nc_check_termtype2)(
+		TERMTYPE *p1, 
+		NCURSES_BOOL p2);
+#undef _nc_check_termtype
+void	(*_nc_check_termtype)(
+		TERMTYPE *p1);
+
+#undef _nc_entry_match
+NCURSES_BOOL _nc_entry_match(
+		char	*n1, 
+		char	*n2)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_read_entry_source
+void	_nc_read_entry_source(
+		FILE	*fp, 
+		char	*buf, 
+		int	literal, 
+		NCURSES_BOOL silent, 
+		NCURSES_BOOL (*hook)(
+		ENTRY	*p1))
+		{ /* void */ }
+
+#undef _nc_resolve_uses2
+int	_nc_resolve_uses2(
+		NCURSES_BOOL fullresolve, 
+		NCURSES_BOOL literal)
+		{ return(*(int *)0); }
+
+#undef _nc_resolve_uses
+int	_nc_resolve_uses(
+		NCURSES_BOOL fullresolve)
+		{ return(*(int *)0); }
+
+/* ./tinfo/comp_scan.c */
+
+#undef _nc_syntax
+int	_nc_syntax;
+#undef _nc_curr_file_pos
+long	_nc_curr_file_pos;
+#undef _nc_comment_start
+long	_nc_comment_start;
+#undef _nc_comment_end
+long	_nc_comment_end;
+#undef _nc_start_line
+long	_nc_start_line;
+#undef _nc_curr_token
+struct token _nc_curr_token;
+#undef _nc_disable_period
+NCURSES_BOOL _nc_disable_period;
+
+#undef _nc_reset_input
+void	_nc_reset_input(
+		FILE	*fp, 
+		char	*buf)
+		{ /* void */ }
+
+#undef _nc_get_token
+int	_nc_get_token(
+		NCURSES_BOOL silent)
+		{ return(*(int *)0); }
+
+#undef _nc_trans_string
+int	_nc_trans_string(
+		char	*ptr, 
+		char	*last)
+		{ return(*(int *)0); }
+
+#undef _nc_push_token
+void	_nc_push_token(
+		int	tokclass)
+		{ /* void */ }
+
+#undef _nc_panic_mode
+void	_nc_panic_mode(
+		char	ch)
+		{ /* void */ }
+
+/* ./tinfo/parse_entry.c */
+
+#undef _nc_parse_entry
+int	_nc_parse_entry(
+		struct entry *entryp, 
+		int	literal, 
+		NCURSES_BOOL silent)
+		{ return(*(int *)0); }
+
+#undef _nc_capcmp
+int	_nc_capcmp(
+		const char *s, 
+		const char *t)
+		{ return(*(int *)0); }
+
+typedef struct {
+    const char *from;
+    const char *to;
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		char	*dir)
+		{ /* void */ }
+
+#undef _nc_write_entry
+void	_nc_write_entry(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#undef _nc_tic_written
+int	_nc_tic_written(void)
+		{ return(*(int *)0); }
+
+/* ./base/define_key.c */
+
+#undef define_key
+int	define_key(
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+/* ./tinfo/hashed_db.c */
+
+#undef _nc_hashed_db
+void	_nc_hashed_db(void)
+		{ /* void */ }
+
+/* ./base/key_defined.c */
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok
+int	keyok(
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/version.c */
+
+#undef curses_version
+const char *curses_version(void)
+		{ return(*(const char **)0); }
diff --git a/ncurses/llib-lncursest b/ncurses/llib-lncursest
new file mode 100644
index 0000000..d29ef60
--- /dev/null
+++ b/ncurses/llib-lncursest
@@ -0,0 +1,3527 @@
+/****************************************************************************
+ * Copyright (c) 2008 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 2008                                           *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tty/hardscroll.c */
+
+#include <curses.priv.h>
+
+#undef _nc_oldnums
+int	*_nc_oldnums;
+
+#undef _nc_scroll_optimize
+void	_nc_scroll_optimize(void)
+		{ /* void */ }
+
+#undef _nc_linedump
+void	_nc_linedump(void)
+		{ /* void */ }
+
+/* ./tty/hashmap.c */
+
+#include <term.h>
+
+#undef _nc_hash_map
+void	_nc_hash_map(void)
+		{ /* void */ }
+
+#undef _nc_make_oldhash
+void	_nc_make_oldhash(
+		int	i)
+		{ /* void */ }
+
+#undef _nc_scroll_oldhash
+void	_nc_scroll_oldhash(
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
+/* ./base/lib_addch.c */
+
+#include <ctype.h>
+
+#undef _nc_render
+chtype	_nc_render(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(chtype *)0); }
+
+#undef _nc_waddch_nosync
+int	_nc_waddch_nosync(
+		WINDOW	*win, 
+		const chtype c)
+		{ return(*(int *)0); }
+
+#undef waddch
+int	waddch(
+		WINDOW	*win, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+#undef wechochar
+int	wechochar(
+		WINDOW	*win, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_addstr.c */
+
+#undef waddnstr
+int	waddnstr(
+		WINDOW	*win, 
+		const char *astr, 
+		int	n)
+		{ return(*(int *)0); }
+
+#undef waddchnstr
+int	waddchnstr(
+		WINDOW	*win, 
+		const chtype *astr, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_beep.c */
+
+#undef beep
+int	beep(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_bkgd.c */
+
+#undef wbkgdset
+void	wbkgdset(
+		WINDOW	*win, 
+		chtype	ch)
+		{ /* void */ }
+
+#undef wbkgd
+int	wbkgd(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_box.c */
+
+#undef wborder
+int	wborder(
+		WINDOW	*win, 
+		chtype	ls, 
+		chtype	rs, 
+		chtype	ts, 
+		chtype	bs, 
+		chtype	tl, 
+		chtype	tr, 
+		chtype	bl, 
+		chtype	br)
+		{ return(*(int *)0); }
+
+/* ./base/lib_chgat.c */
+
+#undef wchgat
+int	wchgat(
+		WINDOW	*win, 
+		int	n, 
+		attr_t	attr, 
+		short	color, 
+		const void *opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clear.c */
+
+#undef wclear
+int	wclear(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clearok.c */
+
+#undef clearok
+int	clearok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clrbot.c */
+
+#undef wclrtobot
+int	wclrtobot(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clreol.c */
+
+#undef wclrtoeol
+int	wclrtoeol(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_color.c */
+
+#include <tic.h>
+
+#undef _nc_COLOR_PAIRS
+int	_nc_COLOR_PAIRS(void)
+		{ return(*(int *)0); }
+
+#undef _nc_COLORS
+int	_nc_COLORS(void)
+		{ return(*(int *)0); }
+
+#undef _nc_reset_colors
+NCURSES_BOOL _nc_reset_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef start_color
+int	start_color(void)
+		{ return(*(int *)0); }
+
+#undef init_pair
+int	init_pair(
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef init_color
+int	init_color(
+		short	color, 
+		short	r, 
+		short	g, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef can_change_color
+NCURSES_BOOL can_change_color(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_colors
+NCURSES_BOOL has_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef color_content
+int	color_content(
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef pair_content
+int	pair_content(
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef _nc_do_color
+void	_nc_do_color(
+		short	old_pair, 
+		short	pair, 
+		NCURSES_BOOL reverse, 
+		int	(*outc)(
+		int	p1))
+		{ /* void */ }
+
+/* ./base/lib_colorset.c */
+
+#undef wcolor_set
+int	wcolor_set(
+		WINDOW	*win, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_delch.c */
+
+#undef wdelch
+int	wdelch(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_delwin.c */
+
+#undef delwin
+int	delwin(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_echo.c */
+
+#undef echo
+int	echo(void)
+		{ return(*(int *)0); }
+
+#undef noecho
+int	noecho(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_endwin.c */
+
+#undef endwin
+int	endwin(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_erase.c */
+
+#undef werase
+int	werase(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_flash.c */
+
+#undef flash
+int	flash(void)
+		{ return(*(int *)0); }
+
+/* ./lib_gen.c */
+
+#undef addch
+int	addch(
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef addchnstr
+int	addchnstr(
+		const chtype *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef addchstr
+int	addchstr(
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef addnstr
+int	addnstr(
+		const char *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef addstr
+int	addstr(
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef attroff
+int	attroff(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attron
+int	attron(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attrset
+int	attrset(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attr_get
+int	attr_get(
+		attr_t	*a1, 
+		short	*a2, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_off
+int	attr_off(
+		attr_t	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_on
+int	attr_on(
+		attr_t	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_set
+int	attr_set(
+		attr_t	a1, 
+		short	a2, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef bkgd
+int	bkgd(
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef bkgdset
+void	bkgdset(
+		chtype	z)
+		{ /* void */ }
+
+#undef border
+int	border(
+		chtype	a1, 
+		chtype	a2, 
+		chtype	a3, 
+		chtype	a4, 
+		chtype	a5, 
+		chtype	a6, 
+		chtype	a7, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef box
+int	box(
+		WINDOW	*a1, 
+		chtype	a2, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef chgat
+int	chgat(
+		int	a1, 
+		attr_t	a2, 
+		short	a3, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef clear
+int	clear(void)
+		{ return(*(int *)0); }
+
+#undef clrtobot
+int	clrtobot(void)
+		{ return(*(int *)0); }
+
+#undef clrtoeol
+int	clrtoeol(void)
+		{ return(*(int *)0); }
+
+#undef color_set
+int	color_set(
+		short	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef COLOR_PAIR
+int	COLOR_PAIR(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef delch
+int	delch(void)
+		{ return(*(int *)0); }
+
+#undef deleteln
+int	deleteln(void)
+		{ return(*(int *)0); }
+
+#undef echochar
+int	echochar(
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef erase
+int	erase(void)
+		{ return(*(int *)0); }
+
+#undef getbkgd
+chtype	getbkgd(
+		WINDOW	*z)
+		{ return(*(chtype *)0); }
+
+#undef getch
+int	getch(void)
+		{ return(*(int *)0); }
+
+#undef getnstr
+int	getnstr(
+		char	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef getstr
+int	getstr(
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef hline
+int	hline(
+		chtype	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef inch
+chtype	inch(void)
+		{ return(*(chtype *)0); }
+
+#undef inchnstr
+int	inchnstr(
+		chtype	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef inchstr
+int	inchstr(
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef innstr
+int	innstr(
+		char	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insch
+int	insch(
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef insdelln
+int	insdelln(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insertln
+int	insertln(void)
+		{ return(*(int *)0); }
+
+#undef insnstr
+int	insnstr(
+		const char *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insstr
+int	insstr(
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef instr
+int	instr(
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef move
+int	move(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddch
+int	mvaddch(
+		int	a1, 
+		int	a2, 
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef mvaddchnstr
+int	mvaddchnstr(
+		int	a1, 
+		int	a2, 
+		const chtype *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddchstr
+int	mvaddchstr(
+		int	a1, 
+		int	a2, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef mvaddnstr
+int	mvaddnstr(
+		int	a1, 
+		int	a2, 
+		const char *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddstr
+int	mvaddstr(
+		int	a1, 
+		int	a2, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvchgat
+int	mvchgat(
+		int	a1, 
+		int	a2, 
+		int	a3, 
+		attr_t	a4, 
+		short	a5, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef mvdelch
+int	mvdelch(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetch
+int	mvgetch(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetnstr
+int	mvgetnstr(
+		int	a1, 
+		int	a2, 
+		char	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetstr
+int	mvgetstr(
+		int	a1, 
+		int	a2, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvhline
+int	mvhline(
+		int	a1, 
+		int	a2, 
+		chtype	a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinch
+chtype	mvinch(
+		int	a1, 
+		int	z)
+		{ return(*(chtype *)0); }
+
+#undef mvinchnstr
+int	mvinchnstr(
+		int	a1, 
+		int	a2, 
+		chtype	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinchstr
+int	mvinchstr(
+		int	a1, 
+		int	a2, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef mvinnstr
+int	mvinnstr(
+		int	a1, 
+		int	a2, 
+		char	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinsch
+int	mvinsch(
+		int	a1, 
+		int	a2, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef mvinsnstr
+int	mvinsnstr(
+		int	a1, 
+		int	a2, 
+		const char *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinsstr
+int	mvinsstr(
+		int	a1, 
+		int	a2, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvinstr
+int	mvinstr(
+		int	a1, 
+		int	a2, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvvline
+int	mvvline(
+		int	a1, 
+		int	a2, 
+		chtype	a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddch
+int	mvwaddch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef mvwaddchnstr
+int	mvwaddchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddchstr
+int	mvwaddchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef mvwaddnstr
+int	mvwaddnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddstr
+int	mvwaddstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvwchgat
+int	mvwchgat(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		int	a4, 
+		attr_t	a5, 
+		short	a6, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef mvwdelch
+int	mvwdelch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetch
+int	mvwgetch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetnstr
+int	mvwgetnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetstr
+int	mvwgetstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvwhline
+int	mvwhline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinch
+chtype	mvwinch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(chtype *)0); }
+
+#undef mvwinchnstr
+int	mvwinchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinchstr
+int	mvwinchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef mvwinnstr
+int	mvwinnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsch
+int	mvwinsch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsnstr
+int	mvwinsnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsstr
+int	mvwinsstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvwinstr
+int	mvwinstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvwvline
+int	mvwvline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef PAIR_NUMBER
+int	PAIR_NUMBER(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef redrawwin
+int	redrawwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef refresh
+int	refresh(void)
+		{ return(*(int *)0); }
+
+#undef scrl
+int	scrl(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef scroll
+int	scroll(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef setscrreg
+int	setscrreg(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef standout
+int	standout(void)
+		{ return(*(int *)0); }
+
+#undef standend
+int	standend(void)
+		{ return(*(int *)0); }
+
+#undef timeout
+void	timeout(
+		int	z)
+		{ /* void */ }
+
+#undef touchline
+int	touchline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef touchwin
+int	touchwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef untouchwin
+int	untouchwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef vline
+int	vline(
+		chtype	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef vw_printw
+int	vw_printw(
+		WINDOW	*a1, 
+		const char *a2, 
+		va_list	z)
+		{ return(*(int *)0); }
+
+#undef vw_scanw
+int	vw_scanw(
+		WINDOW	*a1, 
+		char	*a2, 
+		va_list	z)
+		{ return(*(int *)0); }
+
+#undef waddchstr
+int	waddchstr(
+		WINDOW	*a1, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef waddstr
+int	waddstr(
+		WINDOW	*a1, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef wattron
+int	wattron(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattroff
+int	wattroff(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattrset
+int	wattrset(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattr_get
+int	wattr_get(
+		WINDOW	*a1, 
+		attr_t	*a2, 
+		short	*a3, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef wattr_set
+int	wattr_set(
+		WINDOW	*a1, 
+		attr_t	a2, 
+		short	a3, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef wdeleteln
+int	wdeleteln(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef wgetstr
+int	wgetstr(
+		WINDOW	*a1, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef winchstr
+int	winchstr(
+		WINDOW	*a1, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef winsertln
+int	winsertln(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef winsstr
+int	winsstr(
+		WINDOW	*a1, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef winstr
+int	winstr(
+		WINDOW	*a1, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef wstandout
+int	wstandout(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef wstandend
+int	wstandend(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef getattrs
+int	getattrs(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getcurx
+int	getcurx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getcury
+int	getcury(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getbegx
+int	getbegx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getbegy
+int	getbegy(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getmaxx
+int	getmaxx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getmaxy
+int	getmaxy(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getparx
+int	getparx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getpary
+int	getpary(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef wgetparent
+WINDOW	*wgetparent(
+		const WINDOW *z)
+		{ return(*(WINDOW **)0); }
+
+#undef is_cleared
+NCURSES_BOOL is_cleared(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_idcok
+NCURSES_BOOL is_idcok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_idlok
+NCURSES_BOOL is_idlok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_immedok
+NCURSES_BOOL is_immedok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_keypad
+NCURSES_BOOL is_keypad(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_leaveok
+NCURSES_BOOL is_leaveok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_nodelay
+NCURSES_BOOL is_nodelay(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_notimeout
+NCURSES_BOOL is_notimeout(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_scrollok
+NCURSES_BOOL is_scrollok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_syncok
+NCURSES_BOOL is_syncok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef wgetscrreg
+int	wgetscrreg(
+		const WINDOW *a1, 
+		int	*a2, 
+		int	*z)
+		{ return(*(int *)0); }
+
+#undef mouse_trafo
+NCURSES_BOOL mouse_trafo(
+		int	*a1, 
+		int	*a2, 
+		NCURSES_BOOL z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_getch.c */
+
+#include <fifo_defs.h>
+
+#undef _nc_ESCDELAY
+int	_nc_ESCDELAY(void)
+		{ return(*(int *)0); }
+
+#undef set_escdelay
+int	set_escdelay(
+		int	value)
+		{ return(*(int *)0); }
+
+#undef _nc_wgetch
+int	_nc_wgetch(
+		WINDOW	*win, 
+		unsigned long *result, 
+		int	use_meta)
+		{ return(*(int *)0); }
+
+#undef wgetch
+int	wgetch(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_getstr.c */
+
+#undef wgetnstr
+int	wgetnstr(
+		WINDOW	*win, 
+		char	*str, 
+		int	maxlen)
+		{ return(*(int *)0); }
+
+/* ./base/lib_hline.c */
+
+#undef whline
+int	whline(
+		WINDOW	*win, 
+		chtype	ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_immedok.c */
+
+#undef immedok
+void	immedok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ /* void */ }
+
+/* ./base/lib_inchstr.c */
+
+#undef winchnstr
+int	winchnstr(
+		WINDOW	*win, 
+		chtype	*str, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_initscr.c */
+
+#undef initscr
+WINDOW	*initscr(void)
+		{ return(*(WINDOW **)0); }
+
+/* ./base/lib_insch.c */
+
+#undef _nc_insert_ch
+int	_nc_insert_ch(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(int *)0); }
+
+#undef winsch
+int	winsch(
+		WINDOW	*win, 
+		chtype	c)
+		{ return(*(int *)0); }
+
+/* ./base/lib_insdel.c */
+
+#undef winsdelln
+int	winsdelln(
+		WINDOW	*win, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_insnstr.c */
+
+#undef winsnstr
+int	winsnstr(
+		WINDOW	*win, 
+		const char *s, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_instr.c */
+
+#undef winnstr
+int	winnstr(
+		WINDOW	*win, 
+		char	*str, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_isendwin.c */
+
+#undef isendwin
+NCURSES_BOOL isendwin(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_leaveok.c */
+
+#undef leaveok
+int	leaveok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_mouse.c */
+
+#undef getmouse
+int	getmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef ungetmouse
+int	ungetmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef mousemask
+mmask_t	mousemask(
+		mmask_t	newmask, 
+		mmask_t	*oldmask)
+		{ return(*(mmask_t *)0); }
+
+#undef wenclose
+NCURSES_BOOL wenclose(
+		const WINDOW *win, 
+		int	y, 
+		int	x)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef mouseinterval
+int	mouseinterval(
+		int	maxclick)
+		{ return(*(int *)0); }
+
+#undef _nc_has_mouse
+int	_nc_has_mouse(void)
+		{ return(*(int *)0); }
+
+#undef wmouse_trafo
+NCURSES_BOOL wmouse_trafo(
+		const WINDOW *win, 
+		int	*pY, 
+		int	*pX, 
+		NCURSES_BOOL to_screen)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_move.c */
+
+#undef wmove
+int	wmove(
+		WINDOW	*win, 
+		int	y, 
+		int	x)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_mvcur.c */
+
+#undef _nc_msec_cost
+int	_nc_msec_cost(
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur_resume
+void	_nc_mvcur_resume(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_init
+void	_nc_mvcur_init(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_wrap
+void	_nc_mvcur_wrap(void)
+		{ /* void */ }
+
+#undef mvcur
+int	mvcur(
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef _nc_optimize_enable
+int	_nc_optimize_enable;
+
+/* ./base/lib_mvwin.c */
+
+#undef mvwin
+int	mvwin(
+		WINDOW	*win, 
+		int	by, 
+		int	bx)
+		{ return(*(int *)0); }
+
+/* ./base/lib_newterm.c */
+
+#undef filter
+void	filter(void)
+		{ /* void */ }
+
+#undef nofilter
+void	nofilter(void)
+		{ /* void */ }
+
+#undef newterm
+SCREEN	*newterm(
+		char	*name, 
+		FILE	*ofp, 
+		FILE	*ifp)
+		{ return(*(SCREEN **)0); }
+
+/* ./base/lib_newwin.c */
+
+#undef _nc_freewin
+int	_nc_freewin(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+#undef newwin
+WINDOW	*newwin(
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef derwin
+WINDOW	*derwin(
+		WINDOW	*orig, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef subwin
+WINDOW	*subwin(
+		WINDOW	*w, 
+		int	l, 
+		int	c, 
+		int	y, 
+		int	x)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_makenew
+WINDOW	*_nc_makenew(
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx, 
+		int	flags)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+/* ./base/lib_nl.c */
+
+#undef nl
+int	nl(void)
+		{ return(*(int *)0); }
+
+#undef nonl
+int	nonl(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_overlay.c */
+
+#undef overlay
+int	overlay(
+		const WINDOW *win1, 
+		WINDOW	*win2)
+		{ return(*(int *)0); }
+
+#undef overwrite
+int	overwrite(
+		const WINDOW *win1, 
+		WINDOW	*win2)
+		{ return(*(int *)0); }
+
+#undef copywin
+int	copywin(
+		const WINDOW *src, 
+		WINDOW	*dst, 
+		int	sminrow, 
+		int	smincol, 
+		int	dminrow, 
+		int	dmincol, 
+		int	dmaxrow, 
+		int	dmaxcol, 
+		int	over)
+		{ return(*(int *)0); }
+
+/* ./base/lib_pad.c */
+
+#undef newpad
+WINDOW	*newpad(
+		int	l, 
+		int	c)
+		{ return(*(WINDOW **)0); }
+
+#undef subpad
+WINDOW	*subpad(
+		WINDOW	*orig, 
+		int	l, 
+		int	c, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef prefresh
+int	prefresh(
+		WINDOW	*win, 
+		int	pminrow, 
+		int	pmincol, 
+		int	sminrow, 
+		int	smincol, 
+		int	smaxrow, 
+		int	smaxcol)
+		{ return(*(int *)0); }
+
+#undef pnoutrefresh
+int	pnoutrefresh(
+		WINDOW	*win, 
+		int	pminrow, 
+		int	pmincol, 
+		int	sminrow, 
+		int	smincol, 
+		int	smaxrow, 
+		int	smaxcol)
+		{ return(*(int *)0); }
+
+#undef pechochar
+int	pechochar(
+		WINDOW	*pad, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_printw.c */
+
+#undef printw
+int	printw(
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef wprintw
+int	wprintw(
+		WINDOW	*win, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvprintw
+int	mvprintw(
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvwprintw
+int	mvwprintw(
+		WINDOW	*win, 
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef vwprintw
+int	vwprintw(
+		WINDOW	*win, 
+		const char *fmt, 
+		va_list	argp)
+		{ return(*(int *)0); }
+
+/* ./base/lib_redrawln.c */
+
+#undef wredrawln
+int	wredrawln(
+		WINDOW	*win, 
+		int	beg, 
+		int	num)
+		{ return(*(int *)0); }
+
+/* ./base/lib_refresh.c */
+
+#undef wrefresh
+int	wrefresh(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+#undef wnoutrefresh
+int	wnoutrefresh(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_restart.c */
+
+#undef restartterm
+int	restartterm(
+		char	*termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scanw.c */
+
+#undef vwscanw
+int	vwscanw(
+		WINDOW	*win, 
+		char	*fmt, 
+		va_list	argp)
+		{ return(*(int *)0); }
+
+#undef scanw
+int	scanw(
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef wscanw
+int	wscanw(
+		WINDOW	*win, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvscanw
+int	mvscanw(
+		int	y, 
+		int	x, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvwscanw
+int	mvwscanw(
+		WINDOW	*win, 
+		int	y, 
+		int	x, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+/* ./base/lib_screen.c */
+
+#undef getwin
+WINDOW	*getwin(
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
+#undef putwin
+int	putwin(
+		WINDOW	*win, 
+		FILE	*filep)
+		{ return(*(int *)0); }
+
+#undef scr_restore
+int	scr_restore(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_dump
+int	scr_dump(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_init
+int	scr_init(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_set
+int	scr_set(
+		const char *file)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scroll.c */
+
+#undef _nc_scroll_window
+void	_nc_scroll_window(
+		WINDOW	*win, 
+		int const n, 
+		int const top, 
+		int const bottom, 
+		chtype	blank)
+		{ /* void */ }
+
+#undef wscrl
+int	wscrl(
+		WINDOW	*win, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scrollok.c */
+
+#undef scrollok
+int	scrollok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scrreg.c */
+
+#undef wsetscrreg
+int	wsetscrreg(
+		WINDOW	*win, 
+		int	top, 
+		int	bottom)
+		{ return(*(int *)0); }
+
+/* ./base/lib_set_term.c */
+
+#undef set_term
+SCREEN	*set_term(
+		SCREEN	*screenp)
+		{ return(*(SCREEN **)0); }
+
+#undef delscreen
+void	delscreen(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_setupscreen
+int	_nc_setupscreen(
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		NCURSES_BOOL filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
+#undef _nc_ripoffline
+int	_nc_ripoffline(
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+#undef ripoffline
+int	ripoffline(
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+/* ./base/lib_slk.c */
+
+#undef _nc_slk_initialize
+int	_nc_slk_initialize(
+		WINDOW	*stwin, 
+		int	cols)
+		{ return(*(int *)0); }
+
+#undef slk_restore
+int	slk_restore(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatr_set.c */
+
+#undef slk_attr_set
+int	slk_attr_set(
+		const attr_t attr, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatrof.c */
+
+#undef slk_attroff
+int	slk_attroff(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatron.c */
+
+#undef slk_attron
+int	slk_attron(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatrset.c */
+
+#undef slk_attrset
+int	slk_attrset(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkattr.c */
+
+#undef slk_attr
+attr_t	slk_attr(void)
+		{ return(*(attr_t *)0); }
+
+/* ./base/lib_slkclear.c */
+
+#undef slk_clear
+int	slk_clear(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkcolor.c */
+
+#undef slk_color
+int	slk_color(
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkinit.c */
+
+#undef slk_init
+int	slk_init(
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slklab.c */
+
+#undef slk_label
+char	*slk_label(
+		int	n)
+		{ return(*(char **)0); }
+
+/* ./base/lib_slkrefr.c */
+
+#undef slk_noutrefresh
+int	slk_noutrefresh(void)
+		{ return(*(int *)0); }
+
+#undef slk_refresh
+int	slk_refresh(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkset.c */
+
+#undef slk_set
+int	slk_set(
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slktouch.c */
+
+#undef slk_touch
+int	slk_touch(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_touch.c */
+
+#undef is_linetouched
+NCURSES_BOOL is_linetouched(
+		WINDOW	*win, 
+		int	line)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_wintouched
+NCURSES_BOOL is_wintouched(
+		WINDOW	*win)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef wtouchln
+int	wtouchln(
+		WINDOW	*win, 
+		int	y, 
+		int	n, 
+		int	changed)
+		{ return(*(int *)0); }
+
+/* ./trace/lib_tracedmp.c */
+
+#undef _tracedump
+void	_tracedump(
+		const char *name, 
+		WINDOW	*win)
+		{ /* void */ }
+
+/* ./trace/lib_tracemse.c */
+
+#undef _nc_tracemouse
+char	*_nc_tracemouse(
+		SCREEN	*sp, 
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+#undef _tracemouse
+char	*_tracemouse(
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+/* ./tty/lib_tstp.c */
+
+#include <SigAction.h>
+
+#undef _nc_signal_handler
+void	_nc_signal_handler(
+		NCURSES_BOOL enable)
+		{ /* void */ }
+
+/* ./base/lib_ungetch.c */
+
+#undef _nc_fifo_dump
+void	_nc_fifo_dump(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_ungetch
+int	_nc_ungetch(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef ungetch
+int	ungetch(
+		int	ch)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_vidattr.c */
+
+#undef vidputs
+int	vidputs(
+		chtype	newmode, 
+		int	(*outc)(
+		int	p1))
+		{ return(*(int *)0); }
+
+#undef vidattr
+int	vidattr(
+		chtype	newmode)
+		{ return(*(int *)0); }
+
+#undef termattrs
+chtype	termattrs(void)
+		{ return(*(chtype *)0); }
+
+/* ./base/lib_vline.c */
+
+#undef wvline
+int	wvline(
+		WINDOW	*win, 
+		chtype	ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_wattroff.c */
+
+#undef wattr_off
+int	wattr_off(
+		WINDOW	*win, 
+		attr_t	at, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_wattron.c */
+
+#undef wattr_on
+int	wattr_on(
+		WINDOW	*win, 
+		attr_t	at, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_winch.c */
+
+#undef winch
+chtype	winch(
+		WINDOW	*win)
+		{ return(*(chtype *)0); }
+
+/* ./base/lib_window.c */
+
+#undef _nc_synchook
+void	_nc_synchook(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef mvderwin
+int	mvderwin(
+		WINDOW	*win, 
+		int	y, 
+		int	x)
+		{ return(*(int *)0); }
+
+#undef syncok
+int	syncok(
+		WINDOW	*win, 
+		NCURSES_BOOL bf)
+		{ return(*(int *)0); }
+
+#undef wsyncup
+void	wsyncup(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef wsyncdown
+void	wsyncdown(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef wcursyncup
+void	wcursyncup(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef dupwin
+WINDOW	*dupwin(
+		WINDOW	*win)
+		{ return(*(WINDOW **)0); }
+
+/* ./base/nc_panel.c */
+
+#undef _nc_panelhook
+struct panelhook *_nc_panelhook(void)
+		{ return(*(struct panelhook **)0); }
+
+/* ./base/safe_sprintf.c */
+
+#undef _nc_printf_string
+char	*_nc_printf_string(
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+/* ./tty/tty_update.c */
+
+#include <sys/time.h>
+#include <sys/times.h>
+
+#undef doupdate
+int	doupdate(void)
+		{ return(*(int *)0); }
+
+#undef _nc_scrolln
+int	_nc_scrolln(
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
+#undef _nc_screen_resume
+void	_nc_screen_resume(void)
+		{ /* void */ }
+
+#undef _nc_screen_init
+void	_nc_screen_init(void)
+		{ /* void */ }
+
+#undef _nc_screen_wrap
+void	_nc_screen_wrap(void)
+		{ /* void */ }
+
+#undef _nc_do_xmc_glitch
+void	_nc_do_xmc_glitch(
+		attr_t	previous)
+		{ /* void */ }
+
+/* ./trace/varargs.c */
+
+typedef enum {
+    atUnknown = 0, atInteger, atFloat, atPoint, atString
+} ARGTYPE;
+
+#undef _nc_varargs
+char	*_nc_varargs(
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+/* ./base/memmove.c */
+
+#undef _nc_memmove
+void	_nc_memmove(void)
+		{ /* void */ }
+
+/* ./base/vsscanf.c */
+
+#undef _nc_vsscanf
+void	_nc_vsscanf(void)
+		{ /* void */ }
+
+/* ./base/lib_freeall.c */
+
+#include <term_entry.h>
+
+#undef _nc_freeall
+void	_nc_freeall(void)
+		{ /* void */ }
+
+#undef _nc_free_and_exit
+void	_nc_free_and_exit(
+		int	code)
+		{ /* void */ }
+
+/* ./expanded.c */
+
+#undef _nc_toggle_attr_on
+void	_nc_toggle_attr_on(
+		attr_t	*S, 
+		attr_t	at)
+		{ /* void */ }
+
+#undef _nc_toggle_attr_off
+void	_nc_toggle_attr_off(
+		attr_t	*S, 
+		attr_t	at)
+		{ /* void */ }
+
+#undef _nc_DelCharCost
+int	_nc_DelCharCost(
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_InsCharCost
+int	_nc_InsCharCost(
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_UpdateAttrs
+void	_nc_UpdateAttrs(
+		chtype	c)
+		{ /* void */ }
+
+/* ./base/legacy_coding.c */
+
+#undef use_legacy_coding
+int	use_legacy_coding(
+		int	level)
+		{ return(*(int *)0); }
+
+/* ./base/lib_dft_fgbg.c */
+
+#undef use_default_colors
+int	use_default_colors(void)
+		{ return(*(int *)0); }
+
+#undef assume_default_colors
+int	assume_default_colors(
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_print.c */
+
+#undef mcprint
+int	mcprint(
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
+/* ./base/resizeterm.c */
+
+#undef is_term_resized
+NCURSES_BOOL is_term_resized(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef resize_term
+int	resize_term(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+#undef resizeterm
+int	resizeterm(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+/* ./trace/trace_xnames.c */
+
+#undef _nc_trace_xnames
+void	_nc_trace_xnames(
+		TERMTYPE *tp)
+		{ /* void */ }
+
+/* ./tinfo/use_screen.c */
+
+#undef use_screen
+int	use_screen(
+		SCREEN	*screen, 
+		NCURSES_SCREEN_CB func, 
+		void	*data)
+		{ return(*(int *)0); }
+
+/* ./base/use_window.c */
+
+#undef use_window
+int	use_window(
+		WINDOW	*win, 
+		NCURSES_WINDOW_CB func, 
+		void	*data)
+		{ return(*(int *)0); }
+
+/* ./base/wresize.c */
+
+#undef wresize
+int	wresize(
+		WINDOW	*win, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+/* ./tinfo/access.c */
+
+#include <sys/stat.h>
+#include <nc_alloc.h>
+
+#undef _nc_rootname
+char	*_nc_rootname(
+		char	*path)
+		{ return(*(char **)0); }
+
+#undef _nc_is_abs_path
+NCURSES_BOOL _nc_is_abs_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_pathlast
+unsigned _nc_pathlast(
+		const char *path)
+		{ return(*(unsigned *)0); }
+
+#undef _nc_basename
+char	*_nc_basename(
+		char	*path)
+		{ return(*(char **)0); }
+
+#undef _nc_access
+int	_nc_access(
+		const char *path, 
+		int	mode)
+		{ return(*(int *)0); }
+
+#undef _nc_is_dir_path
+NCURSES_BOOL _nc_is_dir_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_is_file_path
+NCURSES_BOOL _nc_is_file_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_env_access
+int	_nc_env_access(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/add_tries.c */
+
+#undef _nc_add_to_try
+int	_nc_add_to_try(
+		TRIES	**tree, 
+		const char *str, 
+		unsigned code)
+		{ return(*(int *)0); }
+
+/* ./tinfo/alloc_ttype.c */
+
+#undef _nc_align_termtype
+void	_nc_align_termtype(
+		TERMTYPE *to, 
+		TERMTYPE *from)
+		{ /* void */ }
+
+#undef _nc_copy_termtype
+void	_nc_copy_termtype(
+		TERMTYPE *dst, 
+		TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef _nc_boolcodes
+char	*const *_nc_boolcodes(void)
+		{ return(*(char **)0); }
+
+#undef _nc_numcodes
+char	*const *_nc_numcodes(void)
+		{ return(*(char **)0); }
+
+#undef _nc_strcodes
+char	*const *_nc_strcodes(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/comp_error.c */
+
+#undef _nc_suppress_warnings
+NCURSES_BOOL _nc_suppress_warnings;
+#undef _nc_curr_line
+int	_nc_curr_line;
+#undef _nc_curr_col
+int	_nc_curr_col;
+
+#undef _nc_get_source
+const char *_nc_get_source(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_set_source
+void	_nc_set_source(
+		const char *const name)
+		{ /* void */ }
+
+#undef _nc_set_type
+void	_nc_set_type(
+		const char *const name)
+		{ /* void */ }
+
+#undef _nc_get_type
+void	_nc_get_type(
+		char	*name)
+		{ /* void */ }
+
+#undef _nc_warning
+void	_nc_warning(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_err_abort
+void	_nc_err_abort(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_syserr_abort
+void	_nc_syserr_abort(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+/* ./tinfo/db_iterator.c */
+
+#undef _nc_tic_dir
+const char *_nc_tic_dir(
+		const char *path)
+		{ return(*(const char **)0); }
+
+#undef _nc_keep_tic_dir
+void	_nc_keep_tic_dir(
+		const char *path)
+		{ /* void */ }
+
+#undef _nc_last_db
+void	_nc_last_db(void)
+		{ /* void */ }
+
+#undef _nc_next_db
+const char *_nc_next_db(
+		DBDIRS	*state, 
+		int	*offset)
+		{ return(*(const char **)0); }
+
+#undef _nc_first_db
+void	_nc_first_db(
+		DBDIRS	*state, 
+		int	*offset)
+		{ /* void */ }
+
+/* ./tinfo/doalloc.c */
+
+#undef _nc_doalloc
+void	*_nc_doalloc(
+		void	*oldp, 
+		size_t	amount)
+		{ return(*(void **)0); }
+
+/* ./tinfo/entries.c */
+
+#undef _nc_head
+ENTRY	*_nc_head;
+#undef _nc_tail
+ENTRY	*_nc_tail;
+
+#undef _nc_free_entry
+void	_nc_free_entry(
+		ENTRY	*headp, 
+		TERMTYPE *tterm)
+		{ /* void */ }
+
+#undef _nc_free_entries
+void	_nc_free_entries(
+		ENTRY	*headp)
+		{ /* void */ }
+
+#undef _nc_delink_entry
+ENTRY	*_nc_delink_entry(
+		ENTRY	*headp, 
+		TERMTYPE *tterm)
+		{ return(*(ENTRY **)0); }
+
+#undef _nc_leaks_tinfo
+void	_nc_leaks_tinfo(void)
+		{ /* void */ }
+
+/* ./fallback.c */
+
+#undef _nc_fallback
+const TERMTYPE *_nc_fallback(
+		const char *name)
+		{ return(*(const TERMTYPE **)0); }
+
+/* ./tinfo/free_ttype.c */
+
+#undef _nc_free_termtype
+void	_nc_free_termtype(
+		TERMTYPE *ptr)
+		{ /* void */ }
+
+#undef _nc_user_definable
+NCURSES_BOOL _nc_user_definable;
+
+#undef use_extended_names
+int	use_extended_names(
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/getenv_num.c */
+
+#undef _nc_getenv_num
+int	_nc_getenv_num(
+		const char *name)
+		{ return(*(int *)0); }
+
+/* ./tinfo/home_terminfo.c */
+
+#undef _nc_home_terminfo
+char	*_nc_home_terminfo(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/init_keytry.c */
+
+#if 0
+
+#include <init_keytry.h>
+
+#undef _nc_tinfo_fkeys
+const struct tinfo_fkeys _nc_tinfo_fkeys[] = {0};
+
+#endif
+
+#undef _nc_init_keytry
+void	_nc_init_keytry(
+		SCREEN	*sp)
+		{ /* void */ }
+
+/* ./tinfo/lib_acs.c */
+
+#undef _nc_acs_map
+chtype	*_nc_acs_map(void)
+		{ return(*(chtype **)0); }
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+#include <termcap.h>
+
+struct speed {
+    int s; 
+    int sp; 
+};
+
+#undef _nc_baudrate
+int	_nc_baudrate(
+		int	OSpeed)
+		{ return(*(int *)0); }
+
+#undef _nc_ospeed
+int	_nc_ospeed(
+		int	BaudRate)
+		{ return(*(int *)0); }
+
+#undef baudrate
+int	baudrate(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_cur_term.c */
+
+#undef _nc_cur_term
+TERMINAL *_nc_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm
+int	del_curterm(
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_data.c */
+
+#undef _nc_stdscr
+WINDOW	*_nc_stdscr(void)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_curscr
+WINDOW	*_nc_curscr(void)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_newscr
+WINDOW	*_nc_newscr(void)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_screen_chain
+SCREEN	*_nc_screen_chain;
+#undef SP
+SCREEN	*SP;
+#undef _nc_globals
+NCURSES_GLOBALS _nc_globals;
+#undef _nc_prescreen
+NCURSES_PRESCREEN _nc_prescreen;
+
+#undef _nc_init_pthreads
+void	_nc_init_pthreads(void)
+		{ /* void */ }
+
+#undef _nc_mutex_init
+void	_nc_mutex_init(
+		pthread_mutex_t *obj)
+		{ /* void */ }
+
+#undef _nc_mutex_lock
+int	_nc_mutex_lock(
+		pthread_mutex_t *obj)
+		{ return(*(int *)0); }
+
+#undef _nc_mutex_trylock
+int	_nc_mutex_trylock(
+		pthread_mutex_t *obj)
+		{ return(*(int *)0); }
+
+#undef _nc_mutex_unlock
+int	_nc_mutex_unlock(
+		pthread_mutex_t *obj)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_has_cap.c */
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef _nc_keyname
+char	*_nc_keyname(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(char **)0); }
+
+#undef keyname
+char	*keyname(
+		int	c)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#undef napms
+int	napms(
+		int	ms)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_options.c */
+
+#undef idlok
+int	idlok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef idcok
+void	idcok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ /* void */ }
+
+#undef halfdelay
+int	halfdelay(
+		int	t)
+		{ return(*(int *)0); }
+
+#undef nodelay
+int	nodelay(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef notimeout
+int	notimeout(
+		WINDOW	*win, 
+		NCURSES_BOOL f)
+		{ return(*(int *)0); }
+
+#undef wtimeout
+void	wtimeout(
+		WINDOW	*win, 
+		int	delay)
+		{ /* void */ }
+
+#undef keypad
+int	keypad(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef meta
+int	meta(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush
+int	intrflush(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_setup.c */
+
+#include <locale.h>
+#include <sys/ioctl.h>
+#include <langinfo.h>
+
+#undef _nc_ttytype
+char	*_nc_ttytype(void)
+		{ return(*(char **)0); }
+
+#undef _nc_ptr_Lines
+int	*_nc_ptr_Lines(void)
+		{ return(*(int **)0); }
+
+#undef _nc_LINES
+int	_nc_LINES(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Cols
+int	*_nc_ptr_Cols(void)
+		{ return(*(int **)0); }
+
+#undef _nc_COLS
+int	_nc_COLS(void)
+		{ return(*(int *)0); }
+
+#undef _nc_TABSIZE
+int	_nc_TABSIZE(void)
+		{ return(*(int *)0); }
+
+#undef set_tabsize
+int	set_tabsize(
+		int	value)
+		{ return(*(int *)0); }
+
+#undef _nc_handle_sigwinch
+int	_nc_handle_sigwinch(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef _nc_get_screensize
+void	_nc_get_screensize(
+		SCREEN	*sp, 
+		int	*linep, 
+		int	*colp)
+		{ /* void */ }
+
+#undef _nc_update_screensize
+void	_nc_update_screensize(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_get_locale
+char	*_nc_get_locale(void)
+		{ return(*(char **)0); }
+
+#undef _nc_unicode_locale
+int	_nc_unicode_locale(void)
+		{ return(*(int *)0); }
+
+#undef _nc_locale_breaks_acs
+int	_nc_locale_breaks_acs(
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
+#undef _nc_setupterm
+int	_nc_setupterm(
+		char	*tname, 
+		int	Filedes, 
+		int	*errret, 
+		NCURSES_BOOL reuse)
+		{ return(*(int *)0); }
+
+#undef setupterm
+int	setupterm(
+		char	*tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#if 0
+
+#include <capdefaults.c>
+
+#endif
+
+#undef tgetflag
+int	tgetflag(
+		char	*id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		char	*id)
+		{ return(*(int *)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		char	*id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname
+char	*termname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tgoto.c */
+
+#undef tgoto
+char	*tgoto(
+		const char *string, 
+		int	x, 
+		int	y)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_ti.c */
+
+#undef tigetflag
+int	tigetflag(
+		char	*str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		char	*str)
+		{ return(*(int *)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		char	*str)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tparm.c */
+
+#undef _nc_tparm_err
+int	_nc_tparm_err;
+
+#undef _nc_tparm_analyze
+int	_nc_tparm_analyze(
+		const char *string, 
+		char	*p_is_s[9], 
+		int	*popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		char	*string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+NCURSES_OSPEED	ospeed;
+#undef _nc_nulls_sent
+int	_nc_nulls_sent;
+
+#undef _nc_set_no_padding
+void	_nc_set_no_padding(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs
+int	tputs(
+		const char *string, 
+		int	affcnt, 
+		int	(*outc)(
+		int	p1))
+		{ return(*(int *)0); }
+
+/* ./trace/lib_trace.c */
+
+#undef _nc_tracing
+unsigned _nc_tracing;
+
+#undef _nc__nc_tputs_trace
+const char *_nc__nc_tputs_trace(void)
+		{ return(*(const char **)0); }
+
+#undef _nc__nc_outchars
+long	_nc__nc_outchars(void)
+		{ return(*(long *)0); }
+
+#undef _nc_set_tputs_trace
+void	_nc_set_tputs_trace(
+		const char *s)
+		{ /* void */ }
+
+#undef _nc_count_outchars
+void	_nc_count_outchars(
+		long	increment)
+		{ /* void */ }
+
+#undef trace
+void	trace(
+		const unsigned int tracelevel)
+		{ /* void */ }
+
+#undef _tracef
+void	_tracef(
+		const char *fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_retrace_bool
+NCURSES_BOOL _nc_retrace_bool(
+		NCURSES_BOOL code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_int
+int	_nc_retrace_int(
+		int	code)
+		{ return(*(int *)0); }
+
+#undef _nc_retrace_unsigned
+unsigned _nc_retrace_unsigned(
+		unsigned code)
+		{ return(*(unsigned *)0); }
+
+#undef _nc_retrace_ptr
+char	*_nc_retrace_ptr(
+		char	*code)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_cptr
+const char *_nc_retrace_cptr(
+		const char *code)
+		{ return(*(const char **)0); }
+
+#undef _nc_retrace_cvoid_ptr
+void	*_nc_retrace_cvoid_ptr(
+		void	*code)
+		{ return(*(void **)0); }
+
+#undef _nc_retrace_void_ptr
+void	*_nc_retrace_void_ptr(
+		void	*code)
+		{ return(*(void **)0); }
+
+#undef _nc_retrace_sp
+SCREEN	*_nc_retrace_sp(
+		SCREEN	*code)
+		{ return(*(SCREEN **)0); }
+
+#undef _nc_retrace_win
+WINDOW	*_nc_retrace_win(
+		WINDOW	*code)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_use_tracef
+int	_nc_use_tracef(
+		unsigned mask)
+		{ return(*(int *)0); }
+
+#undef _nc_locked_tracef
+void	_nc_locked_tracef(
+		const char *fmt, 
+		...)
+		{ /* void */ }
+
+/* ./trace/lib_traceatr.c */
+
+#undef _traceattr2
+char	*_traceattr2(
+		int	bufnum, 
+		chtype	newmode)
+		{ return(*(char **)0); }
+
+#undef _traceattr
+char	*_traceattr(
+		attr_t	newmode)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_attr_t
+attr_t	_nc_retrace_attr_t(
+		attr_t	code)
+		{ return(*(attr_t *)0); }
+
+#undef _nc_altcharset_name
+const char *_nc_altcharset_name(
+		attr_t	attr, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef _tracechtype2
+char	*_tracechtype2(
+		int	bufnum, 
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef _tracechtype
+char	*_tracechtype(
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_chtype
+chtype	_nc_retrace_chtype(
+		chtype	code)
+		{ return(*(chtype *)0); }
+
+/* ./trace/lib_tracebits.c */
+
+typedef struct {
+    unsigned int val;
+    const char *name;
+} BITNAMES;
+
+#undef _nc_trace_ttymode
+char	*_nc_trace_ttymode(
+		struct termios *tty)
+		{ return(*(char **)0); }
+
+#undef _nc_tracebits
+char	*_nc_tracebits(void)
+		{ return(*(char **)0); }
+
+/* ./trace/lib_tracechr.c */
+
+#undef _nc_tracechar
+char	*_nc_tracechar(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(char **)0); }
+
+#undef _tracechar
+char	*_tracechar(
+		int	ch)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_ttyflags.c */
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode
+int	_nc_set_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty
+int	resetty(void)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_twait.c */
+
+#undef _nc_timed_wait
+int	_nc_timed_wait(
+		SCREEN	*sp, 
+		int	mode, 
+		int	milliseconds, 
+		int	*timeleft)
+		{ return(*(int *)0); }
+
+/* ./tinfo/name_match.c */
+
+#undef _nc_first_name
+char	*_nc_first_name(
+		const char *const sp)
+		{ return(*(char **)0); }
+
+#undef _nc_name_match
+int	_nc_name_match(
+		const char *const namelst, 
+		const char *const name, 
+		const char *const delim)
+		{ return(*(int *)0); }
+
+/* ./names.c */
+
+#undef _nc_boolnames
+char	*const *_nc_boolnames(void)
+		{ return(*(char **)0); }
+
+#undef _nc_boolfnames
+char	*const *_nc_boolfnames(void)
+		{ return(*(char **)0); }
+
+#undef _nc_numnames
+char	*const *_nc_numnames(void)
+		{ return(*(char **)0); }
+
+#undef _nc_numfnames
+char	*const *_nc_numfnames(void)
+		{ return(*(char **)0); }
+
+#undef _nc_strnames
+char	*const *_nc_strnames(void)
+		{ return(*(char **)0); }
+
+#undef _nc_strfnames
+char	*const *_nc_strfnames(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/read_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_read_termtype
+int	_nc_read_termtype(
+		TERMTYPE *ptr, 
+		char	*buffer, 
+		int	limit)
+		{ return(*(int *)0); }
+
+#undef _nc_read_file_entry
+int	_nc_read_file_entry(
+		const char *const filename, 
+		TERMTYPE *ptr)
+		{ return(*(int *)0); }
+
+#undef _nc_read_entry
+int	_nc_read_entry(
+		const char *const name, 
+		char	*const filename, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/read_termcap.c */
+
+#include <sys/types.h>
+
+#undef _nc_read_termcap_entry
+int	_nc_read_termcap_entry(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/setbuf.c */
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		NCURSES_BOOL buffered)
+		{ /* void */ }
+
+/* ./tinfo/strings.c */
+
+#undef _nc_str_init
+string_desc *_nc_str_init(
+		string_desc *dst, 
+		char	*src, 
+		size_t	len)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_str_null
+string_desc *_nc_str_null(
+		string_desc *dst, 
+		size_t	len)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_str_copy
+string_desc *_nc_str_copy(
+		string_desc *dst, 
+		string_desc *src)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_safe_strcat
+NCURSES_BOOL _nc_safe_strcat(
+		string_desc *dst, 
+		const char *src)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_safe_strcpy
+NCURSES_BOOL _nc_safe_strcpy(
+		string_desc *dst, 
+		const char *src)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./trace/trace_buf.c */
+
+#undef _nc_trace_buf
+char	*_nc_trace_buf(
+		int	bufnum, 
+		size_t	want)
+		{ return(*(char **)0); }
+
+#undef _nc_trace_bufcat
+char	*_nc_trace_bufcat(
+		int	bufnum, 
+		const char *value)
+		{ return(*(char **)0); }
+
+/* ./trace/trace_tries.c */
+
+#undef _nc_trace_tries
+void	_nc_trace_tries(
+		TRIES	*tree)
+		{ /* void */ }
+
+/* ./base/tries.c */
+
+#undef _nc_expand_try
+char	*_nc_expand_try(
+		TRIES	*tree, 
+		unsigned code, 
+		int	*count, 
+		size_t	len)
+		{ return(*(char **)0); }
+
+#undef _nc_remove_key
+int	_nc_remove_key(
+		TRIES	**tree, 
+		unsigned code)
+		{ return(*(int *)0); }
+
+#undef _nc_remove_string
+int	_nc_remove_string(
+		TRIES	**tree, 
+		const char *string)
+		{ return(*(int *)0); }
+
+/* ./tinfo/trim_sgr0.c */
+
+#undef _nc_trim_sgr0
+char	*_nc_trim_sgr0(
+		TERMTYPE *tp)
+		{ return(*(char **)0); }
+
+/* ./unctrl.c */
+
+#undef _nc_unctrl
+char	*_nc_unctrl(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef unctrl
+char	*unctrl(
+		chtype	ch)
+		{ return(*(char **)0); }
+
+/* ./trace/visbuf.c */
+
+#undef _nc_visbuf2
+const char *_nc_visbuf2(
+		int	bufnum, 
+		const char *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_visbuf
+const char *_nc_visbuf(
+		const char *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_visbufn
+const char *_nc_visbufn(
+		const char *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+#undef _nc_viscbuf2
+const char *_nc_viscbuf2(
+		int	bufnum, 
+		const chtype *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+#undef _nc_viscbuf
+const char *_nc_viscbuf(
+		const chtype *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/alloc_entry.c */
+
+#undef _nc_init_entry
+void	_nc_init_entry(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#undef _nc_copy_entry
+ENTRY	*_nc_copy_entry(
+		ENTRY	*oldp)
+		{ return(*(ENTRY **)0); }
+
+#undef _nc_save_str
+char	*_nc_save_str(
+		const char *const string)
+		{ return(*(char **)0); }
+
+#undef _nc_wrap_entry
+void	_nc_wrap_entry(
+		ENTRY	*const ep, 
+		NCURSES_BOOL copy_strings)
+		{ /* void */ }
+
+#undef _nc_merge_entry
+void	_nc_merge_entry(
+		TERMTYPE *const to, 
+		TERMTYPE *const from)
+		{ /* void */ }
+
+/* ./tinfo/captoinfo.c */
+
+#undef _nc_captoinfo
+char	*_nc_captoinfo(
+		const char *cap, 
+		const char *s, 
+		int const parameterized)
+		{ return(*(char **)0); }
+
+#undef _nc_infotocap
+char	*_nc_infotocap(
+		const char *cap, 
+		const char *str, 
+		int const parameterized)
+		{ return(*(char **)0); }
+
+/* ./comp_captab.c */
+
+#include <hashsize.h>
+
+#undef _nc_get_table
+const struct name_table_entry *_nc_get_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct name_table_entry **)0); }
+
+#undef _nc_get_hash_table
+const short *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const short **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+/* ./tinfo/comp_expand.c */
+
+#undef _nc_tic_expand
+char	*_nc_tic_expand(
+		const char *srcp, 
+		NCURSES_BOOL tic_format, 
+		int	numbers)
+		{ return(*(char **)0); }
+
+/* ./tinfo/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const short *hash_table)
+		{ return(*(struct name_table_entry const **)0); }
+
+#undef _nc_find_type_entry
+struct name_table_entry const *_nc_find_type_entry(
+		const char *string, 
+		int	type, 
+		const struct name_table_entry *table)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./tinfo/comp_parse.c */
+
+#undef _nc_check_termtype2
+void	(*_nc_check_termtype2)(
+		TERMTYPE *p1, 
+		NCURSES_BOOL p2);
+#undef _nc_check_termtype
+void	(*_nc_check_termtype)(
+		TERMTYPE *p1);
+
+#undef _nc_entry_match
+NCURSES_BOOL _nc_entry_match(
+		char	*n1, 
+		char	*n2)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_read_entry_source
+void	_nc_read_entry_source(
+		FILE	*fp, 
+		char	*buf, 
+		int	literal, 
+		NCURSES_BOOL silent, 
+		NCURSES_BOOL (*hook)(
+		ENTRY	*p1))
+		{ /* void */ }
+
+#undef _nc_resolve_uses2
+int	_nc_resolve_uses2(
+		NCURSES_BOOL fullresolve, 
+		NCURSES_BOOL literal)
+		{ return(*(int *)0); }
+
+#undef _nc_resolve_uses
+int	_nc_resolve_uses(
+		NCURSES_BOOL fullresolve)
+		{ return(*(int *)0); }
+
+/* ./tinfo/comp_scan.c */
+
+#undef _nc_syntax
+int	_nc_syntax;
+#undef _nc_curr_file_pos
+long	_nc_curr_file_pos;
+#undef _nc_comment_start
+long	_nc_comment_start;
+#undef _nc_comment_end
+long	_nc_comment_end;
+#undef _nc_start_line
+long	_nc_start_line;
+#undef _nc_curr_token
+struct token _nc_curr_token;
+#undef _nc_disable_period
+NCURSES_BOOL _nc_disable_period;
+
+#undef _nc_reset_input
+void	_nc_reset_input(
+		FILE	*fp, 
+		char	*buf)
+		{ /* void */ }
+
+#undef _nc_get_token
+int	_nc_get_token(
+		NCURSES_BOOL silent)
+		{ return(*(int *)0); }
+
+#undef _nc_trans_string
+int	_nc_trans_string(
+		char	*ptr, 
+		char	*last)
+		{ return(*(int *)0); }
+
+#undef _nc_push_token
+void	_nc_push_token(
+		int	tokclass)
+		{ /* void */ }
+
+#undef _nc_panic_mode
+void	_nc_panic_mode(
+		char	ch)
+		{ /* void */ }
+
+/* ./tinfo/parse_entry.c */
+
+#undef _nc_parse_entry
+int	_nc_parse_entry(
+		struct entry *entryp, 
+		int	literal, 
+		NCURSES_BOOL silent)
+		{ return(*(int *)0); }
+
+#undef _nc_capcmp
+int	_nc_capcmp(
+		const char *s, 
+		const char *t)
+		{ return(*(int *)0); }
+
+typedef struct {
+    const char *from;
+    const char *to;
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		char	*dir)
+		{ /* void */ }
+
+#undef _nc_write_entry
+void	_nc_write_entry(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#undef _nc_tic_written
+int	_nc_tic_written(void)
+		{ return(*(int *)0); }
+
+/* ./base/define_key.c */
+
+#undef define_key
+int	define_key(
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+/* ./tinfo/hashed_db.c */
+
+#undef _nc_hashed_db
+void	_nc_hashed_db(void)
+		{ /* void */ }
+
+/* ./base/key_defined.c */
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok
+int	keyok(
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/version.c */
+
+#undef curses_version
+const char *curses_version(void)
+		{ return(*(const char **)0); }
diff --git a/ncurses/llib-lncursesw b/ncurses/llib-lncursesw
new file mode 100644
index 0000000..96e7257
--- /dev/null
+++ b/ncurses/llib-lncursesw
@@ -0,0 +1,4215 @@
+/****************************************************************************
+ * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 2001-2008                                      *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tty/hardscroll.c */
+
+#include <curses.priv.h>
+
+#undef _nc_oldnums
+int	*_nc_oldnums;
+
+#undef _nc_scroll_optimize
+void	_nc_scroll_optimize(void)
+		{ /* void */ }
+
+#undef _nc_linedump
+void	_nc_linedump(void)
+		{ /* void */ }
+
+/* ./tty/hashmap.c */
+
+#include <term.h>
+
+#undef _nc_hash_map
+void	_nc_hash_map(void)
+		{ /* void */ }
+
+#undef _nc_make_oldhash
+void	_nc_make_oldhash(
+		int	i)
+		{ /* void */ }
+
+#undef _nc_scroll_oldhash
+void	_nc_scroll_oldhash(
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
+/* ./base/lib_addch.c */
+
+#include <ctype.h>
+
+#undef _nc_render
+cchar_t	_nc_render(
+		WINDOW	*win, 
+		cchar_t	ch)
+		{ return(*(cchar_t *)0); }
+
+#undef _nc_build_wch
+int	_nc_build_wch(
+		WINDOW	*win, 
+		cchar_t	*ch)
+		{ return(*(int *)0); }
+
+#undef _nc_waddch_nosync
+int	_nc_waddch_nosync(
+		WINDOW	*win, 
+		const cchar_t c)
+		{ return(*(int *)0); }
+
+#undef waddch
+int	waddch(
+		WINDOW	*win, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+#undef wechochar
+int	wechochar(
+		WINDOW	*win, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_addstr.c */
+
+#undef waddnstr
+int	waddnstr(
+		WINDOW	*win, 
+		const char *astr, 
+		int	n)
+		{ return(*(int *)0); }
+
+#undef waddchnstr
+int	waddchnstr(
+		WINDOW	*win, 
+		const chtype *astr, 
+		int	n)
+		{ return(*(int *)0); }
+
+#undef _nc_wchstrlen
+int	_nc_wchstrlen(
+		const cchar_t *s)
+		{ return(*(int *)0); }
+
+#undef wadd_wchnstr
+int	wadd_wchnstr(
+		WINDOW	*win, 
+		const cchar_t *astr, 
+		int	n)
+		{ return(*(int *)0); }
+
+#undef waddnwstr
+int	waddnwstr(
+		WINDOW	*win, 
+		const wchar_t *str, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_beep.c */
+
+#undef beep
+int	beep(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_bkgd.c */
+
+#undef wbkgrndset
+void	wbkgrndset(
+		WINDOW	*win, 
+		const cchar_t *ch)
+		{ /* void */ }
+
+#undef wbkgdset
+void	wbkgdset(
+		WINDOW	*win, 
+		chtype	ch)
+		{ /* void */ }
+
+#undef wbkgrnd
+int	wbkgrnd(
+		WINDOW	*win, 
+		const cchar_t *ch)
+		{ return(*(int *)0); }
+
+#undef wbkgd
+int	wbkgd(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_box.c */
+
+#undef wborder
+int	wborder(
+		WINDOW	*win, 
+		chtype	ls, 
+		chtype	rs, 
+		chtype	ts, 
+		chtype	bs, 
+		chtype	tl, 
+		chtype	tr, 
+		chtype	bl, 
+		chtype	br)
+		{ return(*(int *)0); }
+
+/* ./base/lib_chgat.c */
+
+#undef wchgat
+int	wchgat(
+		WINDOW	*win, 
+		int	n, 
+		attr_t	attr, 
+		short	color, 
+		const void *opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clear.c */
+
+#undef wclear
+int	wclear(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clearok.c */
+
+#undef clearok
+int	clearok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clrbot.c */
+
+#undef wclrtobot
+int	wclrtobot(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_clreol.c */
+
+#undef wclrtoeol
+int	wclrtoeol(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_color.c */
+
+#include <tic.h>
+
+#undef COLOR_PAIRS
+int	COLOR_PAIRS;
+#undef COLORS
+int	COLORS;
+
+#undef _nc_reset_colors
+NCURSES_BOOL _nc_reset_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef start_color
+int	start_color(void)
+		{ return(*(int *)0); }
+
+#undef init_pair
+int	init_pair(
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef init_color
+int	init_color(
+		short	color, 
+		short	r, 
+		short	g, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef can_change_color
+NCURSES_BOOL can_change_color(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_colors
+NCURSES_BOOL has_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef color_content
+int	color_content(
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef pair_content
+int	pair_content(
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef _nc_do_color
+void	_nc_do_color(
+		short	old_pair, 
+		short	pair, 
+		NCURSES_BOOL reverse, 
+		int	(*outc)(
+		int	p1))
+		{ /* void */ }
+
+/* ./base/lib_colorset.c */
+
+#undef wcolor_set
+int	wcolor_set(
+		WINDOW	*win, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_delch.c */
+
+#undef wdelch
+int	wdelch(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_delwin.c */
+
+#undef delwin
+int	delwin(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_echo.c */
+
+#undef echo
+int	echo(void)
+		{ return(*(int *)0); }
+
+#undef noecho
+int	noecho(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_endwin.c */
+
+#undef endwin
+int	endwin(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_erase.c */
+
+#undef werase
+int	werase(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_flash.c */
+
+#undef flash
+int	flash(void)
+		{ return(*(int *)0); }
+
+/* ./lib_gen.c */
+
+#undef addch
+int	addch(
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef addchnstr
+int	addchnstr(
+		const chtype *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef addchstr
+int	addchstr(
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef addnstr
+int	addnstr(
+		const char *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef addstr
+int	addstr(
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef attroff
+int	attroff(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attron
+int	attron(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attrset
+int	attrset(
+		NCURSES_ATTR_T	z)
+		{ return(*(int *)0); }
+
+#undef attr_get
+int	attr_get(
+		attr_t	*a1, 
+		short	*a2, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_off
+int	attr_off(
+		attr_t	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_on
+int	attr_on(
+		attr_t	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef attr_set
+int	attr_set(
+		attr_t	a1, 
+		short	a2, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef bkgd
+int	bkgd(
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef bkgdset
+void	bkgdset(
+		chtype	z)
+		{ /* void */ }
+
+#undef border
+int	border(
+		chtype	a1, 
+		chtype	a2, 
+		chtype	a3, 
+		chtype	a4, 
+		chtype	a5, 
+		chtype	a6, 
+		chtype	a7, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef box
+int	box(
+		WINDOW	*a1, 
+		chtype	a2, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef chgat
+int	chgat(
+		int	a1, 
+		attr_t	a2, 
+		short	a3, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef clear
+int	clear(void)
+		{ return(*(int *)0); }
+
+#undef clrtobot
+int	clrtobot(void)
+		{ return(*(int *)0); }
+
+#undef clrtoeol
+int	clrtoeol(void)
+		{ return(*(int *)0); }
+
+#undef color_set
+int	color_set(
+		short	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef COLOR_PAIR
+int	COLOR_PAIR(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef delch
+int	delch(void)
+		{ return(*(int *)0); }
+
+#undef deleteln
+int	deleteln(void)
+		{ return(*(int *)0); }
+
+#undef echochar
+int	echochar(
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef erase
+int	erase(void)
+		{ return(*(int *)0); }
+
+#undef getbkgd
+chtype	getbkgd(
+		WINDOW	*z)
+		{ return(*(chtype *)0); }
+
+#undef getch
+int	getch(void)
+		{ return(*(int *)0); }
+
+#undef getnstr
+int	getnstr(
+		char	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef getstr
+int	getstr(
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef hline
+int	hline(
+		chtype	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef inch
+chtype	inch(void)
+		{ return(*(chtype *)0); }
+
+#undef inchnstr
+int	inchnstr(
+		chtype	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef inchstr
+int	inchstr(
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef innstr
+int	innstr(
+		char	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insch
+int	insch(
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef insdelln
+int	insdelln(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insertln
+int	insertln(void)
+		{ return(*(int *)0); }
+
+#undef insnstr
+int	insnstr(
+		const char *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef insstr
+int	insstr(
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef instr
+int	instr(
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef move
+int	move(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddch
+int	mvaddch(
+		int	a1, 
+		int	a2, 
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef mvaddchnstr
+int	mvaddchnstr(
+		int	a1, 
+		int	a2, 
+		const chtype *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddchstr
+int	mvaddchstr(
+		int	a1, 
+		int	a2, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef mvaddnstr
+int	mvaddnstr(
+		int	a1, 
+		int	a2, 
+		const char *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddstr
+int	mvaddstr(
+		int	a1, 
+		int	a2, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvchgat
+int	mvchgat(
+		int	a1, 
+		int	a2, 
+		int	a3, 
+		attr_t	a4, 
+		short	a5, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef mvdelch
+int	mvdelch(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetch
+int	mvgetch(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetnstr
+int	mvgetnstr(
+		int	a1, 
+		int	a2, 
+		char	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvgetstr
+int	mvgetstr(
+		int	a1, 
+		int	a2, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvhline
+int	mvhline(
+		int	a1, 
+		int	a2, 
+		chtype	a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinch
+chtype	mvinch(
+		int	a1, 
+		int	z)
+		{ return(*(chtype *)0); }
+
+#undef mvinchnstr
+int	mvinchnstr(
+		int	a1, 
+		int	a2, 
+		chtype	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinchstr
+int	mvinchstr(
+		int	a1, 
+		int	a2, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef mvinnstr
+int	mvinnstr(
+		int	a1, 
+		int	a2, 
+		char	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinsch
+int	mvinsch(
+		int	a1, 
+		int	a2, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef mvinsnstr
+int	mvinsnstr(
+		int	a1, 
+		int	a2, 
+		const char *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvinsstr
+int	mvinsstr(
+		int	a1, 
+		int	a2, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvinstr
+int	mvinstr(
+		int	a1, 
+		int	a2, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvvline
+int	mvvline(
+		int	a1, 
+		int	a2, 
+		chtype	a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddch
+int	mvwaddch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype z)
+		{ return(*(int *)0); }
+
+#undef mvwaddchnstr
+int	mvwaddchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddchstr
+int	mvwaddchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef mvwaddnstr
+int	mvwaddnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddstr
+int	mvwaddstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvwchgat
+int	mvwchgat(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		int	a4, 
+		attr_t	a5, 
+		short	a6, 
+		const void *z)
+		{ return(*(int *)0); }
+
+#undef mvwdelch
+int	mvwdelch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetch
+int	mvwgetch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetnstr
+int	mvwgetnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwgetstr
+int	mvwgetstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvwhline
+int	mvwhline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinch
+chtype	mvwinch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(chtype *)0); }
+
+#undef mvwinchnstr
+int	mvwinchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinchstr
+int	mvwinchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef mvwinnstr
+int	mvwinnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsch
+int	mvwinsch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsnstr
+int	mvwinsnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwinsstr
+int	mvwinsstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef mvwinstr
+int	mvwinstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef mvwvline
+int	mvwvline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		chtype	a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef PAIR_NUMBER
+int	PAIR_NUMBER(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef redrawwin
+int	redrawwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef refresh
+int	refresh(void)
+		{ return(*(int *)0); }
+
+#undef scrl
+int	scrl(
+		int	z)
+		{ return(*(int *)0); }
+
+#undef scroll
+int	scroll(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef setscrreg
+int	setscrreg(
+		int	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef slk_attr_off
+int	slk_attr_off(
+		const attr_t a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef slk_attr_on
+int	slk_attr_on(
+		attr_t	a1, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef standout
+int	standout(void)
+		{ return(*(int *)0); }
+
+#undef standend
+int	standend(void)
+		{ return(*(int *)0); }
+
+#undef timeout
+void	timeout(
+		int	z)
+		{ /* void */ }
+
+#undef touchline
+int	touchline(
+		WINDOW	*a1, 
+		int	a2, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef touchwin
+int	touchwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef untouchwin
+int	untouchwin(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef vline
+int	vline(
+		chtype	a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef vw_printw
+int	vw_printw(
+		WINDOW	*a1, 
+		const char *a2, 
+		va_list	z)
+		{ return(*(int *)0); }
+
+#undef vw_scanw
+int	vw_scanw(
+		WINDOW	*a1, 
+		char	*a2, 
+		va_list	z)
+		{ return(*(int *)0); }
+
+#undef waddchstr
+int	waddchstr(
+		WINDOW	*a1, 
+		const chtype *z)
+		{ return(*(int *)0); }
+
+#undef waddstr
+int	waddstr(
+		WINDOW	*a1, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef wattron
+int	wattron(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattroff
+int	wattroff(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattrset
+int	wattrset(
+		WINDOW	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wattr_get
+int	wattr_get(
+		WINDOW	*a1, 
+		attr_t	*a2, 
+		short	*a3, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef wattr_set
+int	wattr_set(
+		WINDOW	*a1, 
+		attr_t	a2, 
+		short	a3, 
+		void	*z)
+		{ return(*(int *)0); }
+
+#undef wdeleteln
+int	wdeleteln(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef wgetstr
+int	wgetstr(
+		WINDOW	*a1, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef winchstr
+int	winchstr(
+		WINDOW	*a1, 
+		chtype	*z)
+		{ return(*(int *)0); }
+
+#undef winsertln
+int	winsertln(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef winsstr
+int	winsstr(
+		WINDOW	*a1, 
+		const char *z)
+		{ return(*(int *)0); }
+
+#undef winstr
+int	winstr(
+		WINDOW	*a1, 
+		char	*z)
+		{ return(*(int *)0); }
+
+#undef wstandout
+int	wstandout(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef wstandend
+int	wstandend(
+		WINDOW	*z)
+		{ return(*(int *)0); }
+
+#undef getattrs
+int	getattrs(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getcurx
+int	getcurx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getcury
+int	getcury(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getbegx
+int	getbegx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getbegy
+int	getbegy(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getmaxx
+int	getmaxx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getmaxy
+int	getmaxy(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getparx
+int	getparx(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef getpary
+int	getpary(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
+#undef wgetparent
+WINDOW	*wgetparent(
+		const WINDOW *z)
+		{ return(*(WINDOW **)0); }
+
+#undef is_cleared
+NCURSES_BOOL is_cleared(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_idcok
+NCURSES_BOOL is_idcok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_idlok
+NCURSES_BOOL is_idlok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_immedok
+NCURSES_BOOL is_immedok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_keypad
+NCURSES_BOOL is_keypad(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_leaveok
+NCURSES_BOOL is_leaveok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_nodelay
+NCURSES_BOOL is_nodelay(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_notimeout
+NCURSES_BOOL is_notimeout(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_scrollok
+NCURSES_BOOL is_scrollok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_syncok
+NCURSES_BOOL is_syncok(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef wgetscrreg
+int	wgetscrreg(
+		const WINDOW *a1, 
+		int	*a2, 
+		int	*z)
+		{ return(*(int *)0); }
+
+#undef add_wch
+int	add_wch(
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef add_wchnstr
+int	add_wchnstr(
+		const cchar_t *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef add_wchstr
+int	add_wchstr(
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef addnwstr
+int	addnwstr(
+		const wchar_t *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef addwstr
+int	addwstr(
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef bkgrnd
+int	bkgrnd(
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef bkgrndset
+void	bkgrndset(
+		const cchar_t *z)
+		{ /* void */ }
+
+#undef border_set
+int	border_set(
+		const cchar_t *a1, 
+		const cchar_t *a2, 
+		const cchar_t *a3, 
+		const cchar_t *a4, 
+		const cchar_t *a5, 
+		const cchar_t *a6, 
+		const cchar_t *a7, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef box_set
+int	box_set(
+		WINDOW	*a1, 
+		const cchar_t *a2, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef echo_wchar
+int	echo_wchar(
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef get_wch
+int	get_wch(
+		wint_t	*z)
+		{ return(*(int *)0); }
+
+#undef get_wstr
+int	get_wstr(
+		wint_t	*z)
+		{ return(*(int *)0); }
+
+#undef getbkgrnd
+int	getbkgrnd(
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef getn_wstr
+int	getn_wstr(
+		wint_t	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef hline_set
+int	hline_set(
+		const cchar_t *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef in_wch
+int	in_wch(
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef in_wchnstr
+int	in_wchnstr(
+		cchar_t	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef in_wchstr
+int	in_wchstr(
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef innwstr
+int	innwstr(
+		wchar_t	*a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef ins_nwstr
+int	ins_nwstr(
+		const wchar_t *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef ins_wch
+int	ins_wch(
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef ins_wstr
+int	ins_wstr(
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef inwstr
+int	inwstr(
+		wchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvadd_wch
+int	mvadd_wch(
+		int	a1, 
+		int	a2, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvadd_wchnstr
+int	mvadd_wchnstr(
+		int	a1, 
+		int	a2, 
+		const cchar_t *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvadd_wchstr
+int	mvadd_wchstr(
+		int	a1, 
+		int	a2, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvaddnwstr
+int	mvaddnwstr(
+		int	a1, 
+		int	a2, 
+		const wchar_t *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvaddwstr
+int	mvaddwstr(
+		int	a1, 
+		int	a2, 
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvget_wch
+int	mvget_wch(
+		int	a1, 
+		int	a2, 
+		wint_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvget_wstr
+int	mvget_wstr(
+		int	a1, 
+		int	a2, 
+		wint_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvgetn_wstr
+int	mvgetn_wstr(
+		int	a1, 
+		int	a2, 
+		wint_t	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvhline_set
+int	mvhline_set(
+		int	a1, 
+		int	a2, 
+		const cchar_t *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvin_wch
+int	mvin_wch(
+		int	a1, 
+		int	a2, 
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvin_wchnstr
+int	mvin_wchnstr(
+		int	a1, 
+		int	a2, 
+		cchar_t	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvin_wchstr
+int	mvin_wchstr(
+		int	a1, 
+		int	a2, 
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvinnwstr
+int	mvinnwstr(
+		int	a1, 
+		int	a2, 
+		wchar_t	*a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvins_nwstr
+int	mvins_nwstr(
+		int	a1, 
+		int	a2, 
+		const wchar_t *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvins_wch
+int	mvins_wch(
+		int	a1, 
+		int	a2, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvins_wstr
+int	mvins_wstr(
+		int	a1, 
+		int	a2, 
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvinwstr
+int	mvinwstr(
+		int	a1, 
+		int	a2, 
+		wchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvvline_set
+int	mvvline_set(
+		int	a1, 
+		int	a2, 
+		const cchar_t *a3, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwadd_wch
+int	mvwadd_wch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvwadd_wchnstr
+int	mvwadd_wchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const cchar_t *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwadd_wchstr
+int	mvwadd_wchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvwaddnwstr
+int	mvwaddnwstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const wchar_t *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwaddwstr
+int	mvwaddwstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvwget_wch
+int	mvwget_wch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		wint_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvwget_wstr
+int	mvwget_wstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		wint_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvwgetn_wstr
+int	mvwgetn_wstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		wint_t	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwhline_set
+int	mvwhline_set(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const cchar_t *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwin_wch
+int	mvwin_wch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvwin_wchnstr
+int	mvwin_wchnstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		cchar_t	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwin_wchstr
+int	mvwin_wchstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvwinnwstr
+int	mvwinnwstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		wchar_t	*a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwins_nwstr
+int	mvwins_nwstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const wchar_t *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef mvwins_wch
+int	mvwins_wch(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvwins_wstr
+int	mvwins_wstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mvwinwstr
+int	mvwinwstr(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		wchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef mvwvline_set
+int	mvwvline_set(
+		WINDOW	*a1, 
+		int	a2, 
+		int	a3, 
+		const cchar_t *a4, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef vline_set
+int	vline_set(
+		const cchar_t *a1, 
+		int	z)
+		{ return(*(int *)0); }
+
+#undef wadd_wchstr
+int	wadd_wchstr(
+		WINDOW	*a1, 
+		const cchar_t *z)
+		{ return(*(int *)0); }
+
+#undef waddwstr
+int	waddwstr(
+		WINDOW	*a1, 
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef wget_wstr
+int	wget_wstr(
+		WINDOW	*a1, 
+		wint_t	*z)
+		{ return(*(int *)0); }
+
+#undef wgetbkgrnd
+int	wgetbkgrnd(
+		WINDOW	*a1, 
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef win_wchstr
+int	win_wchstr(
+		WINDOW	*a1, 
+		cchar_t	*z)
+		{ return(*(int *)0); }
+
+#undef wins_wstr
+int	wins_wstr(
+		WINDOW	*a1, 
+		const wchar_t *z)
+		{ return(*(int *)0); }
+
+#undef mouse_trafo
+NCURSES_BOOL mouse_trafo(
+		int	*a1, 
+		int	*a2, 
+		NCURSES_BOOL z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_getch.c */
+
+#include <fifo_defs.h>
+
+#undef ESCDELAY
+int	ESCDELAY;
+
+#undef set_escdelay
+int	set_escdelay(
+		int	value)
+		{ return(*(int *)0); }
+
+#undef _nc_wgetch
+int	_nc_wgetch(
+		WINDOW	*win, 
+		unsigned long *result, 
+		int	use_meta)
+		{ return(*(int *)0); }
+
+#undef wgetch
+int	wgetch(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_getstr.c */
+
+#undef wgetnstr
+int	wgetnstr(
+		WINDOW	*win, 
+		char	*str, 
+		int	maxlen)
+		{ return(*(int *)0); }
+
+/* ./base/lib_hline.c */
+
+#undef whline
+int	whline(
+		WINDOW	*win, 
+		chtype	ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_immedok.c */
+
+#undef immedok
+void	immedok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ /* void */ }
+
+/* ./base/lib_inchstr.c */
+
+#undef winchnstr
+int	winchnstr(
+		WINDOW	*win, 
+		chtype	*str, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_initscr.c */
+
+#undef initscr
+WINDOW	*initscr(void)
+		{ return(*(WINDOW **)0); }
+
+/* ./base/lib_insch.c */
+
+#undef _nc_insert_ch
+int	_nc_insert_ch(
+		WINDOW	*win, 
+		chtype	ch)
+		{ return(*(int *)0); }
+
+#undef winsch
+int	winsch(
+		WINDOW	*win, 
+		chtype	c)
+		{ return(*(int *)0); }
+
+/* ./base/lib_insdel.c */
+
+#undef winsdelln
+int	winsdelln(
+		WINDOW	*win, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_insnstr.c */
+
+#undef winsnstr
+int	winsnstr(
+		WINDOW	*win, 
+		const char *s, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_instr.c */
+
+#undef winnstr
+int	winnstr(
+		WINDOW	*win, 
+		char	*str, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_isendwin.c */
+
+#undef isendwin
+NCURSES_BOOL isendwin(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_leaveok.c */
+
+#undef leaveok
+int	leaveok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_mouse.c */
+
+#undef getmouse
+int	getmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef ungetmouse
+int	ungetmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef mousemask
+mmask_t	mousemask(
+		mmask_t	newmask, 
+		mmask_t	*oldmask)
+		{ return(*(mmask_t *)0); }
+
+#undef wenclose
+NCURSES_BOOL wenclose(
+		const WINDOW *win, 
+		int	y, 
+		int	x)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef mouseinterval
+int	mouseinterval(
+		int	maxclick)
+		{ return(*(int *)0); }
+
+#undef _nc_has_mouse
+int	_nc_has_mouse(void)
+		{ return(*(int *)0); }
+
+#undef wmouse_trafo
+NCURSES_BOOL wmouse_trafo(
+		const WINDOW *win, 
+		int	*pY, 
+		int	*pX, 
+		NCURSES_BOOL to_screen)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./base/lib_move.c */
+
+#undef wmove
+int	wmove(
+		WINDOW	*win, 
+		int	y, 
+		int	x)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_mvcur.c */
+
+#undef _nc_msec_cost
+int	_nc_msec_cost(
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur_resume
+void	_nc_mvcur_resume(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_init
+void	_nc_mvcur_init(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_wrap
+void	_nc_mvcur_wrap(void)
+		{ /* void */ }
+
+#undef mvcur
+int	mvcur(
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef _nc_optimize_enable
+int	_nc_optimize_enable;
+
+/* ./base/lib_mvwin.c */
+
+#undef mvwin
+int	mvwin(
+		WINDOW	*win, 
+		int	by, 
+		int	bx)
+		{ return(*(int *)0); }
+
+/* ./base/lib_newterm.c */
+
+#undef filter
+void	filter(void)
+		{ /* void */ }
+
+#undef nofilter
+void	nofilter(void)
+		{ /* void */ }
+
+#undef newterm
+SCREEN	*newterm(
+		char	*name, 
+		FILE	*ofp, 
+		FILE	*ifp)
+		{ return(*(SCREEN **)0); }
+
+/* ./base/lib_newwin.c */
+
+#undef _nc_freewin
+int	_nc_freewin(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+#undef newwin
+WINDOW	*newwin(
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef derwin
+WINDOW	*derwin(
+		WINDOW	*orig, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef subwin
+WINDOW	*subwin(
+		WINDOW	*w, 
+		int	l, 
+		int	c, 
+		int	y, 
+		int	x)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_makenew
+WINDOW	*_nc_makenew(
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx, 
+		int	flags)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+/* ./base/lib_nl.c */
+
+#undef nl
+int	nl(void)
+		{ return(*(int *)0); }
+
+#undef nonl
+int	nonl(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_overlay.c */
+
+#undef overlay
+int	overlay(
+		const WINDOW *win1, 
+		WINDOW	*win2)
+		{ return(*(int *)0); }
+
+#undef overwrite
+int	overwrite(
+		const WINDOW *win1, 
+		WINDOW	*win2)
+		{ return(*(int *)0); }
+
+#undef copywin
+int	copywin(
+		const WINDOW *src, 
+		WINDOW	*dst, 
+		int	sminrow, 
+		int	smincol, 
+		int	dminrow, 
+		int	dmincol, 
+		int	dmaxrow, 
+		int	dmaxcol, 
+		int	over)
+		{ return(*(int *)0); }
+
+/* ./base/lib_pad.c */
+
+#undef newpad
+WINDOW	*newpad(
+		int	l, 
+		int	c)
+		{ return(*(WINDOW **)0); }
+
+#undef subpad
+WINDOW	*subpad(
+		WINDOW	*orig, 
+		int	l, 
+		int	c, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
+#undef prefresh
+int	prefresh(
+		WINDOW	*win, 
+		int	pminrow, 
+		int	pmincol, 
+		int	sminrow, 
+		int	smincol, 
+		int	smaxrow, 
+		int	smaxcol)
+		{ return(*(int *)0); }
+
+#undef pnoutrefresh
+int	pnoutrefresh(
+		WINDOW	*win, 
+		int	pminrow, 
+		int	pmincol, 
+		int	sminrow, 
+		int	smincol, 
+		int	smaxrow, 
+		int	smaxcol)
+		{ return(*(int *)0); }
+
+#undef pechochar
+int	pechochar(
+		WINDOW	*pad, 
+		const chtype ch)
+		{ return(*(int *)0); }
+
+/* ./base/lib_printw.c */
+
+#undef printw
+int	printw(
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef wprintw
+int	wprintw(
+		WINDOW	*win, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvprintw
+int	mvprintw(
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvwprintw
+int	mvwprintw(
+		WINDOW	*win, 
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef vwprintw
+int	vwprintw(
+		WINDOW	*win, 
+		const char *fmt, 
+		va_list	argp)
+		{ return(*(int *)0); }
+
+/* ./base/lib_redrawln.c */
+
+#undef wredrawln
+int	wredrawln(
+		WINDOW	*win, 
+		int	beg, 
+		int	num)
+		{ return(*(int *)0); }
+
+/* ./base/lib_refresh.c */
+
+#undef wrefresh
+int	wrefresh(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+#undef wnoutrefresh
+int	wnoutrefresh(
+		WINDOW	*win)
+		{ return(*(int *)0); }
+
+/* ./base/lib_restart.c */
+
+#undef restartterm
+int	restartterm(
+		char	*termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scanw.c */
+
+#undef vwscanw
+int	vwscanw(
+		WINDOW	*win, 
+		char	*fmt, 
+		va_list	argp)
+		{ return(*(int *)0); }
+
+#undef scanw
+int	scanw(
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef wscanw
+int	wscanw(
+		WINDOW	*win, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvscanw
+int	mvscanw(
+		int	y, 
+		int	x, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvwscanw
+int	mvwscanw(
+		WINDOW	*win, 
+		int	y, 
+		int	x, 
+		char	*fmt, 
+		...)
+		{ return(*(int *)0); }
+
+/* ./base/lib_screen.c */
+
+#undef getwin
+WINDOW	*getwin(
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
+#undef putwin
+int	putwin(
+		WINDOW	*win, 
+		FILE	*filep)
+		{ return(*(int *)0); }
+
+#undef scr_restore
+int	scr_restore(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_dump
+int	scr_dump(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_init
+int	scr_init(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_set
+int	scr_set(
+		const char *file)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scroll.c */
+
+#undef _nc_scroll_window
+void	_nc_scroll_window(
+		WINDOW	*win, 
+		int const n, 
+		short const top, 
+		short const bottom, 
+		cchar_t	blank)
+		{ /* void */ }
+
+#undef wscrl
+int	wscrl(
+		WINDOW	*win, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scrollok.c */
+
+#undef scrollok
+int	scrollok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scrreg.c */
+
+#undef wsetscrreg
+int	wsetscrreg(
+		WINDOW	*win, 
+		int	top, 
+		int	bottom)
+		{ return(*(int *)0); }
+
+/* ./base/lib_set_term.c */
+
+#undef set_term
+SCREEN	*set_term(
+		SCREEN	*screenp)
+		{ return(*(SCREEN **)0); }
+
+#undef delscreen
+void	delscreen(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_setupscreen
+int	_nc_setupscreen(
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		NCURSES_BOOL filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
+#undef _nc_ripoffline
+int	_nc_ripoffline(
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+#undef ripoffline
+int	ripoffline(
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+/* ./base/lib_slk.c */
+
+#undef _nc_slk_initialize
+int	_nc_slk_initialize(
+		WINDOW	*stwin, 
+		int	cols)
+		{ return(*(int *)0); }
+
+#undef slk_restore
+int	slk_restore(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatr_set.c */
+
+#undef slk_attr_set
+int	slk_attr_set(
+		const attr_t attr, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatrof.c */
+
+#undef slk_attroff
+int	slk_attroff(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatron.c */
+
+#undef slk_attron
+int	slk_attron(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatrset.c */
+
+#undef slk_attrset
+int	slk_attrset(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkattr.c */
+
+#undef slk_attr
+attr_t	slk_attr(void)
+		{ return(*(attr_t *)0); }
+
+/* ./base/lib_slkclear.c */
+
+#undef slk_clear
+int	slk_clear(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkcolor.c */
+
+#undef slk_color
+int	slk_color(
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkinit.c */
+
+#undef slk_init
+int	slk_init(
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slklab.c */
+
+#undef slk_label
+char	*slk_label(
+		int	n)
+		{ return(*(char **)0); }
+
+/* ./base/lib_slkrefr.c */
+
+#undef slk_noutrefresh
+int	slk_noutrefresh(void)
+		{ return(*(int *)0); }
+
+#undef slk_refresh
+int	slk_refresh(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkset.c */
+
+#include <wctype.h>
+
+#undef slk_set
+int	slk_set(
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slktouch.c */
+
+#undef slk_touch
+int	slk_touch(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_touch.c */
+
+#undef is_linetouched
+NCURSES_BOOL is_linetouched(
+		WINDOW	*win, 
+		int	line)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_wintouched
+NCURSES_BOOL is_wintouched(
+		WINDOW	*win)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef wtouchln
+int	wtouchln(
+		WINDOW	*win, 
+		int	y, 
+		int	n, 
+		int	changed)
+		{ return(*(int *)0); }
+
+/* ./trace/lib_tracedmp.c */
+
+#undef _tracedump
+void	_tracedump(
+		const char *name, 
+		WINDOW	*win)
+		{ /* void */ }
+
+/* ./trace/lib_tracemse.c */
+
+#undef _nc_tracemouse
+char	*_nc_tracemouse(
+		SCREEN	*sp, 
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+#undef _tracemouse
+char	*_tracemouse(
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+/* ./tty/lib_tstp.c */
+
+#include <SigAction.h>
+
+#undef _nc_signal_handler
+void	_nc_signal_handler(
+		NCURSES_BOOL enable)
+		{ /* void */ }
+
+/* ./base/lib_ungetch.c */
+
+#undef _nc_fifo_dump
+void	_nc_fifo_dump(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_ungetch
+int	_nc_ungetch(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef ungetch
+int	ungetch(
+		int	ch)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_vidattr.c */
+
+#undef vidputs
+int	vidputs(
+		chtype	newmode, 
+		int	(*outc)(
+		int	p1))
+		{ return(*(int *)0); }
+
+#undef vidattr
+int	vidattr(
+		chtype	newmode)
+		{ return(*(int *)0); }
+
+#undef termattrs
+chtype	termattrs(void)
+		{ return(*(chtype *)0); }
+
+/* ./base/lib_vline.c */
+
+#undef wvline
+int	wvline(
+		WINDOW	*win, 
+		chtype	ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./base/lib_wattroff.c */
+
+#undef wattr_off
+int	wattr_off(
+		WINDOW	*win, 
+		attr_t	at, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_wattron.c */
+
+#undef wattr_on
+int	wattr_on(
+		WINDOW	*win, 
+		attr_t	at, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./base/lib_winch.c */
+
+#undef winch
+chtype	winch(
+		WINDOW	*win)
+		{ return(*(chtype *)0); }
+
+/* ./base/lib_window.c */
+
+#undef _nc_synchook
+void	_nc_synchook(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef mvderwin
+int	mvderwin(
+		WINDOW	*win, 
+		int	y, 
+		int	x)
+		{ return(*(int *)0); }
+
+#undef syncok
+int	syncok(
+		WINDOW	*win, 
+		NCURSES_BOOL bf)
+		{ return(*(int *)0); }
+
+#undef wsyncup
+void	wsyncup(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef wsyncdown
+void	wsyncdown(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef wcursyncup
+void	wcursyncup(
+		WINDOW	*win)
+		{ /* void */ }
+
+#undef dupwin
+WINDOW	*dupwin(
+		WINDOW	*win)
+		{ return(*(WINDOW **)0); }
+
+/* ./base/nc_panel.c */
+
+#undef _nc_panelhook
+struct panelhook *_nc_panelhook(void)
+		{ return(*(struct panelhook **)0); }
+
+/* ./base/safe_sprintf.c */
+
+#undef _nc_printf_string
+char	*_nc_printf_string(
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+/* ./tty/tty_update.c */
+
+#include <sys/time.h>
+#include <sys/times.h>
+
+#undef doupdate
+int	doupdate(void)
+		{ return(*(int *)0); }
+
+#undef _nc_scrolln
+int	_nc_scrolln(
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
+#undef _nc_screen_resume
+void	_nc_screen_resume(void)
+		{ /* void */ }
+
+#undef _nc_screen_init
+void	_nc_screen_init(void)
+		{ /* void */ }
+
+#undef _nc_screen_wrap
+void	_nc_screen_wrap(void)
+		{ /* void */ }
+
+#undef _nc_do_xmc_glitch
+void	_nc_do_xmc_glitch(
+		attr_t	previous)
+		{ /* void */ }
+
+/* ./trace/varargs.c */
+
+typedef enum {
+    atUnknown = 0, atInteger, atFloat, atPoint, atString
+} ARGTYPE;
+
+#undef _nc_varargs
+char	*_nc_varargs(
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+/* ./base/memmove.c */
+
+#undef _nc_memmove
+void	_nc_memmove(void)
+		{ /* void */ }
+
+/* ./base/vsscanf.c */
+
+#undef _nc_vsscanf
+void	_nc_vsscanf(void)
+		{ /* void */ }
+
+/* ./base/lib_freeall.c */
+
+#include <term_entry.h>
+
+#undef _nc_freeall
+void	_nc_freeall(void)
+		{ /* void */ }
+
+#undef _nc_free_and_exit
+void	_nc_free_and_exit(
+		int	code)
+		{ /* void */ }
+
+/* ./widechar/charable.c */
+
+#undef _nc_is_charable
+NCURSES_BOOL _nc_is_charable(
+		wchar_t	ch)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_to_char
+int	_nc_to_char(
+		wint_t	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_to_widechar
+wint_t	_nc_to_widechar(
+		int	ch)
+		{ return(*(wint_t *)0); }
+
+/* ./widechar/lib_add_wch.c */
+
+#undef wadd_wch
+int	wadd_wch(
+		WINDOW	*win, 
+		const cchar_t *wch)
+		{ return(*(int *)0); }
+
+#undef wecho_wchar
+int	wecho_wchar(
+		WINDOW	*win, 
+		const cchar_t *wch)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_box_set.c */
+
+#undef wborder_set
+int	wborder_set(
+		WINDOW	*win, 
+		const cchar_t *ls, 
+		const cchar_t *rs, 
+		const cchar_t *ts, 
+		const cchar_t *bs, 
+		const cchar_t *tl, 
+		const cchar_t *tr, 
+		const cchar_t *bl, 
+		const cchar_t *br)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_cchar.c */
+
+#undef setcchar
+int	setcchar(
+		cchar_t	*wcval, 
+		const wchar_t *wch, 
+		const attr_t attrs, 
+		short	color_pair, 
+		const void *opts)
+		{ return(*(int *)0); }
+
+#undef getcchar
+int	getcchar(
+		const cchar_t *wcval, 
+		wchar_t	*wch, 
+		attr_t	*attrs, 
+		short	*color_pair, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_erasewchar.c */
+
+#undef erasewchar
+int	erasewchar(
+		wchar_t	*wch)
+		{ return(*(int *)0); }
+
+#undef killwchar
+int	killwchar(
+		wchar_t	*wch)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_get_wch.c */
+
+#undef wget_wch
+int	wget_wch(
+		WINDOW	*win, 
+		wint_t	*result)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_get_wstr.c */
+
+#undef wgetn_wstr
+int	wgetn_wstr(
+		WINDOW	*win, 
+		wint_t	*str, 
+		int	maxlen)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_hline_set.c */
+
+#undef whline_set
+int	whline_set(
+		WINDOW	*win, 
+		const cchar_t *ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_in_wch.c */
+
+#undef win_wch
+int	win_wch(
+		WINDOW	*win, 
+		cchar_t	*wcval)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_in_wchnstr.c */
+
+#undef win_wchnstr
+int	win_wchnstr(
+		WINDOW	*win, 
+		cchar_t	*wchstr, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_ins_wch.c */
+
+#undef wins_wch
+int	wins_wch(
+		WINDOW	*win, 
+		const cchar_t *wch)
+		{ return(*(int *)0); }
+
+#undef wins_nwstr
+int	wins_nwstr(
+		WINDOW	*win, 
+		const wchar_t *wstr, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_inwstr.c */
+
+#undef winnwstr
+int	winnwstr(
+		WINDOW	*win, 
+		wchar_t	*wstr, 
+		int	n)
+		{ return(*(int *)0); }
+
+#undef winwstr
+int	winwstr(
+		WINDOW	*win, 
+		wchar_t	*wstr)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_key_name.c */
+
+#undef key_name
+char	*key_name(
+		wchar_t	c)
+		{ return(*(char **)0); }
+
+/* ./widechar/lib_pecho_wchar.c */
+
+#undef pecho_wchar
+int	pecho_wchar(
+		WINDOW	*pad, 
+		const cchar_t *wch)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_slk_wset.c */
+
+#undef slk_wset
+int	slk_wset(
+		int	i, 
+		const wchar_t *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_unget_wch.c */
+
+#undef _nc_wcrtomb
+size_t	_nc_wcrtomb(
+		char	*target, 
+		wchar_t	source, 
+		mbstate_t *state)
+		{ return(*(size_t *)0); }
+
+#undef unget_wch
+int	unget_wch(
+		const wchar_t wch)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_vid_attr.c */
+
+#undef vid_puts
+int	vid_puts(
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts, 
+		int	(*outc)(
+		int	p1))
+		{ return(*(int *)0); }
+
+#undef vid_attr
+int	vid_attr(
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+#undef term_attrs
+attr_t	term_attrs(void)
+		{ return(*(attr_t *)0); }
+
+/* ./widechar/lib_vline_set.c */
+
+#undef wvline_set
+int	wvline_set(
+		WINDOW	*win, 
+		const cchar_t *ch, 
+		int	n)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_wacs.c */
+
+#undef _nc_wacs
+cchar_t	*_nc_wacs;
+
+#undef _nc_init_wacs
+void	_nc_init_wacs(void)
+		{ /* void */ }
+
+/* ./widechar/lib_wunctrl.c */
+
+#undef wunctrl
+wchar_t	*wunctrl(
+		cchar_t	*wc)
+		{ return(*(wchar_t **)0); }
+
+/* ./expanded.c */
+
+#undef _nc_toggle_attr_on
+void	_nc_toggle_attr_on(
+		attr_t	*S, 
+		attr_t	at)
+		{ /* void */ }
+
+#undef _nc_toggle_attr_off
+void	_nc_toggle_attr_off(
+		attr_t	*S, 
+		attr_t	at)
+		{ /* void */ }
+
+#undef _nc_DelCharCost
+int	_nc_DelCharCost(
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_InsCharCost
+int	_nc_InsCharCost(
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_UpdateAttrs
+void	_nc_UpdateAttrs(
+		cchar_t	c)
+		{ /* void */ }
+
+/* ./base/legacy_coding.c */
+
+#undef use_legacy_coding
+int	use_legacy_coding(
+		int	level)
+		{ return(*(int *)0); }
+
+/* ./base/lib_dft_fgbg.c */
+
+#undef use_default_colors
+int	use_default_colors(void)
+		{ return(*(int *)0); }
+
+#undef assume_default_colors
+int	assume_default_colors(
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_print.c */
+
+#undef mcprint
+int	mcprint(
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
+/* ./base/resizeterm.c */
+
+#undef is_term_resized
+NCURSES_BOOL is_term_resized(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef resize_term
+int	resize_term(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+#undef resizeterm
+int	resizeterm(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+/* ./trace/trace_xnames.c */
+
+#undef _nc_trace_xnames
+void	_nc_trace_xnames(
+		TERMTYPE *tp)
+		{ /* void */ }
+
+/* ./tinfo/use_screen.c */
+
+#undef use_screen
+int	use_screen(
+		SCREEN	*screen, 
+		NCURSES_SCREEN_CB func, 
+		void	*data)
+		{ return(*(int *)0); }
+
+/* ./base/use_window.c */
+
+#undef use_window
+int	use_window(
+		WINDOW	*win, 
+		NCURSES_WINDOW_CB func, 
+		void	*data)
+		{ return(*(int *)0); }
+
+/* ./base/wresize.c */
+
+#undef wresize
+int	wresize(
+		WINDOW	*win, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+/* ./tinfo/access.c */
+
+#include <sys/stat.h>
+#include <nc_alloc.h>
+
+#undef _nc_rootname
+char	*_nc_rootname(
+		char	*path)
+		{ return(*(char **)0); }
+
+#undef _nc_is_abs_path
+NCURSES_BOOL _nc_is_abs_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_pathlast
+unsigned _nc_pathlast(
+		const char *path)
+		{ return(*(unsigned *)0); }
+
+#undef _nc_basename
+char	*_nc_basename(
+		char	*path)
+		{ return(*(char **)0); }
+
+#undef _nc_access
+int	_nc_access(
+		const char *path, 
+		int	mode)
+		{ return(*(int *)0); }
+
+#undef _nc_is_dir_path
+NCURSES_BOOL _nc_is_dir_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_is_file_path
+NCURSES_BOOL _nc_is_file_path(
+		const char *path)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_env_access
+int	_nc_env_access(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/add_tries.c */
+
+#undef _nc_add_to_try
+int	_nc_add_to_try(
+		TRIES	**tree, 
+		const char *str, 
+		unsigned code)
+		{ return(*(int *)0); }
+
+/* ./tinfo/alloc_ttype.c */
+
+#undef _nc_align_termtype
+void	_nc_align_termtype(
+		TERMTYPE *to, 
+		TERMTYPE *from)
+		{ /* void */ }
+
+#undef _nc_copy_termtype
+void	_nc_copy_termtype(
+		TERMTYPE *dst, 
+		TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef boolcodes
+char	*const boolcodes[] = {0};
+#undef numcodes
+char	*const numcodes[] = {0};
+#undef strcodes
+char	*const strcodes[] = {0};
+
+/* ./tinfo/comp_error.c */
+#undef _nc_suppress_warnings
+NCURSES_BOOL _nc_suppress_warnings;
+#undef _nc_curr_line
+int	_nc_curr_line;
+#undef _nc_curr_col
+int	_nc_curr_col;
+
+#undef _nc_get_source
+const char *_nc_get_source(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_set_source
+void	_nc_set_source(
+		const char *const name)
+		{ /* void */ }
+
+#undef _nc_set_type
+void	_nc_set_type(
+		const char *const name)
+		{ /* void */ }
+
+#undef _nc_get_type
+void	_nc_get_type(
+		char	*name)
+		{ /* void */ }
+
+#undef _nc_warning
+void	_nc_warning(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_err_abort
+void	_nc_err_abort(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_syserr_abort
+void	_nc_syserr_abort(
+		const char *const fmt, 
+		...)
+		{ /* void */ }
+
+/* ./tinfo/db_iterator.c */
+
+#undef _nc_tic_dir
+const char *_nc_tic_dir(
+		const char *path)
+		{ return(*(const char **)0); }
+
+#undef _nc_keep_tic_dir
+void	_nc_keep_tic_dir(
+		const char *path)
+		{ /* void */ }
+
+#undef _nc_last_db
+void	_nc_last_db(void)
+		{ /* void */ }
+
+#undef _nc_next_db
+const char *_nc_next_db(
+		DBDIRS	*state, 
+		int	*offset)
+		{ return(*(const char **)0); }
+
+#undef _nc_first_db
+void	_nc_first_db(
+		DBDIRS	*state, 
+		int	*offset)
+		{ /* void */ }
+
+/* ./tinfo/doalloc.c */
+
+#undef _nc_doalloc
+void	*_nc_doalloc(
+		void	*oldp, 
+		size_t	amount)
+		{ return(*(void **)0); }
+
+/* ./tinfo/entries.c */
+
+#undef _nc_head
+ENTRY	*_nc_head;
+#undef _nc_tail
+ENTRY	*_nc_tail;
+
+#undef _nc_free_entry
+void	_nc_free_entry(
+		ENTRY	*headp, 
+		TERMTYPE *tterm)
+		{ /* void */ }
+
+#undef _nc_free_entries
+void	_nc_free_entries(
+		ENTRY	*headp)
+		{ /* void */ }
+
+#undef _nc_delink_entry
+ENTRY	*_nc_delink_entry(
+		ENTRY	*headp, 
+		TERMTYPE *tterm)
+		{ return(*(ENTRY **)0); }
+
+#undef _nc_leaks_tinfo
+void	_nc_leaks_tinfo(void)
+		{ /* void */ }
+
+/* ./fallback.c */
+
+#undef _nc_fallback
+const TERMTYPE *_nc_fallback(
+		const char *name)
+		{ return(*(const TERMTYPE **)0); }
+
+/* ./tinfo/free_ttype.c */
+
+#undef _nc_free_termtype
+void	_nc_free_termtype(
+		TERMTYPE *ptr)
+		{ /* void */ }
+
+#undef _nc_user_definable
+NCURSES_BOOL _nc_user_definable;
+
+#undef use_extended_names
+int	use_extended_names(
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/getenv_num.c */
+
+#undef _nc_getenv_num
+int	_nc_getenv_num(
+		const char *name)
+		{ return(*(int *)0); }
+
+/* ./tinfo/home_terminfo.c */
+
+#undef _nc_home_terminfo
+char	*_nc_home_terminfo(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/init_keytry.c */
+
+#if 0
+
+#include <init_keytry.h>
+
+#undef _nc_tinfo_fkeys
+const struct tinfo_fkeys _nc_tinfo_fkeys[] = {0};
+
+#endif
+
+#undef _nc_init_keytry
+void	_nc_init_keytry(
+		SCREEN	*sp)
+		{ /* void */ }
+
+/* ./tinfo/lib_acs.c */
+
+#undef acs_map
+chtype	acs_map[128];
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+#include <termcap.h>
+
+struct speed {
+    int s; 
+    int sp; 
+};
+
+#undef _nc_baudrate
+int	_nc_baudrate(
+		int	OSpeed)
+		{ return(*(int *)0); }
+
+#undef _nc_ospeed
+int	_nc_ospeed(
+		int	BaudRate)
+		{ return(*(int *)0); }
+
+#undef baudrate
+int	baudrate(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_cur_term.c */
+
+#undef cur_term
+TERMINAL *cur_term;
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm
+int	del_curterm(
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_data.c */
+
+#undef stdscr
+WINDOW	*stdscr;
+#undef curscr
+WINDOW	*curscr;
+#undef newscr
+WINDOW	*newscr;
+#undef _nc_screen_chain
+SCREEN	*_nc_screen_chain;
+#undef SP
+SCREEN	*SP;
+#undef _nc_globals
+NCURSES_GLOBALS _nc_globals;
+#undef _nc_prescreen
+NCURSES_PRESCREEN _nc_prescreen;
+
+/* ./tinfo/lib_has_cap.c */
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef _nc_keyname
+char	*_nc_keyname(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(char **)0); }
+
+#undef keyname
+char	*keyname(
+		int	c)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#include <time.h>
+
+#undef napms
+int	napms(
+		int	ms)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_options.c */
+
+#undef idlok
+int	idlok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef idcok
+void	idcok(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ /* void */ }
+
+#undef halfdelay
+int	halfdelay(
+		int	t)
+		{ return(*(int *)0); }
+
+#undef nodelay
+int	nodelay(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef notimeout
+int	notimeout(
+		WINDOW	*win, 
+		NCURSES_BOOL f)
+		{ return(*(int *)0); }
+
+#undef wtimeout
+void	wtimeout(
+		WINDOW	*win, 
+		int	delay)
+		{ /* void */ }
+
+#undef keypad
+int	keypad(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef meta
+int	meta(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush
+int	intrflush(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_setup.c */
+
+#include <locale.h>
+#include <sys/ioctl.h>
+#include <langinfo.h>
+
+#undef ttytype
+char	ttytype[256];
+#undef LINES
+int	LINES;
+#undef COLS
+int	COLS;
+#undef TABSIZE
+int	TABSIZE;
+
+#undef set_tabsize
+int	set_tabsize(
+		int	value)
+		{ return(*(int *)0); }
+
+#undef _nc_handle_sigwinch
+int	_nc_handle_sigwinch(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef _nc_get_screensize
+void	_nc_get_screensize(
+		SCREEN	*sp, 
+		int	*linep, 
+		int	*colp)
+		{ /* void */ }
+
+#undef _nc_update_screensize
+void	_nc_update_screensize(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_get_locale
+char	*_nc_get_locale(void)
+		{ return(*(char **)0); }
+
+#undef _nc_unicode_locale
+int	_nc_unicode_locale(void)
+		{ return(*(int *)0); }
+
+#undef _nc_locale_breaks_acs
+int	_nc_locale_breaks_acs(
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
+#undef _nc_setupterm
+int	_nc_setupterm(
+		char	*tname, 
+		int	Filedes, 
+		int	*errret, 
+		NCURSES_BOOL reuse)
+		{ return(*(int *)0); }
+
+#undef setupterm
+int	setupterm(
+		char	*tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#if 0
+
+#include <capdefaults.c>
+
+#endif
+
+#undef tgetflag
+int	tgetflag(
+		char	*id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		char	*id)
+		{ return(*(int *)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		char	*id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname
+char	*termname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tgoto.c */
+
+#undef tgoto
+char	*tgoto(
+		const char *string, 
+		int	x, 
+		int	y)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_ti.c */
+
+#undef tigetflag
+int	tigetflag(
+		char	*str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		char	*str)
+		{ return(*(int *)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		char	*str)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tparm.c */
+
+#undef _nc_tparm_err
+int	_nc_tparm_err;
+
+#undef _nc_tparm_analyze
+int	_nc_tparm_analyze(
+		const char *string, 
+		char	*p_is_s[9], 
+		int	*popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		char	*string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+NCURSES_OSPEED	ospeed;
+#undef _nc_nulls_sent
+int	_nc_nulls_sent;
+
+#undef _nc_set_no_padding
+void	_nc_set_no_padding(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs
+int	tputs(
+		const char *string, 
+		int	affcnt, 
+		int	(*outc)(
+		int	p1))
+		{ return(*(int *)0); }
+
+/* ./trace/lib_trace.c */
+
+#undef _nc_tracing
+unsigned _nc_tracing;
+#undef _nc_tputs_trace
+const char *_nc_tputs_trace = {0};
+#undef _nc_outchars
+long	_nc_outchars;
+
+#undef trace
+void	trace(
+		const unsigned int tracelevel)
+		{ /* void */ }
+
+#undef _tracef
+void	_tracef(
+		const char *fmt, 
+		...)
+		{ /* void */ }
+
+#undef _nc_retrace_bool
+NCURSES_BOOL _nc_retrace_bool(
+		NCURSES_BOOL code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_int
+int	_nc_retrace_int(
+		int	code)
+		{ return(*(int *)0); }
+
+#undef _nc_retrace_unsigned
+unsigned _nc_retrace_unsigned(
+		unsigned code)
+		{ return(*(unsigned *)0); }
+
+#undef _nc_retrace_ptr
+char	*_nc_retrace_ptr(
+		char	*code)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_cptr
+const char *_nc_retrace_cptr(
+		const char *code)
+		{ return(*(const char **)0); }
+
+#undef _nc_retrace_cvoid_ptr
+void	*_nc_retrace_cvoid_ptr(
+		void	*code)
+		{ return(*(void **)0); }
+
+#undef _nc_retrace_void_ptr
+void	*_nc_retrace_void_ptr(
+		void	*code)
+		{ return(*(void **)0); }
+
+#undef _nc_retrace_sp
+SCREEN	*_nc_retrace_sp(
+		SCREEN	*code)
+		{ return(*(SCREEN **)0); }
+
+#undef _nc_retrace_win
+WINDOW	*_nc_retrace_win(
+		WINDOW	*code)
+		{ return(*(WINDOW **)0); }
+
+/* ./trace/lib_traceatr.c */
+
+#undef _traceattr2
+char	*_traceattr2(
+		int	bufnum, 
+		chtype	newmode)
+		{ return(*(char **)0); }
+
+#undef _traceattr
+char	*_traceattr(
+		attr_t	newmode)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_attr_t
+attr_t	_nc_retrace_attr_t(
+		attr_t	code)
+		{ return(*(attr_t *)0); }
+
+#undef _nc_altcharset_name
+const char *_nc_altcharset_name(
+		attr_t	attr, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef _tracechtype2
+char	*_tracechtype2(
+		int	bufnum, 
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef _tracechtype
+char	*_tracechtype(
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_chtype
+chtype	_nc_retrace_chtype(
+		chtype	code)
+		{ return(*(chtype *)0); }
+
+#undef _tracecchar_t2
+char	*_tracecchar_t2(
+		int	bufnum, 
+		const cchar_t *ch)
+		{ return(*(char **)0); }
+
+#undef _tracecchar_t
+char	*_tracecchar_t(
+		const cchar_t *ch)
+		{ return(*(char **)0); }
+
+/* ./trace/lib_tracebits.c */
+
+typedef struct {
+    unsigned int val;
+    const char *name;
+} BITNAMES;
+
+#undef _nc_trace_ttymode
+char	*_nc_trace_ttymode(
+		struct termios *tty)
+		{ return(*(char **)0); }
+
+#undef _nc_tracebits
+char	*_nc_tracebits(void)
+		{ return(*(char **)0); }
+
+/* ./trace/lib_tracechr.c */
+
+#undef _nc_tracechar
+char	*_nc_tracechar(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(char **)0); }
+
+#undef _tracechar
+char	*_tracechar(
+		int	ch)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_ttyflags.c */
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode
+int	_nc_set_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty
+int	resetty(void)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_twait.c */
+
+#undef _nc_timed_wait
+int	_nc_timed_wait(
+		SCREEN	*sp, 
+		int	mode, 
+		int	milliseconds, 
+		int	*timeleft)
+		{ return(*(int *)0); }
+
+/* ./tinfo/name_match.c */
+
+#undef _nc_first_name
+char	*_nc_first_name(
+		const char *const sp)
+		{ return(*(char **)0); }
+
+#undef _nc_name_match
+int	_nc_name_match(
+		const char *const namelst, 
+		const char *const name, 
+		const char *const delim)
+		{ return(*(int *)0); }
+
+/* ./names.c */
+
+#undef boolnames
+char	*const boolnames[] = {0};
+#undef boolfnames
+char	*const boolfnames[] = {0};
+#undef numnames
+char	*const numnames[] = {0};
+#undef numfnames
+char	*const numfnames[] = {0};
+#undef strnames
+char	*const strnames[] = {0};
+#undef strfnames
+char	*const strfnames[] = {0};
+
+/* ./tinfo/read_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_read_termtype
+int	_nc_read_termtype(
+		TERMTYPE *ptr, 
+		char	*buffer, 
+		int	limit)
+		{ return(*(int *)0); }
+
+#undef _nc_read_file_entry
+int	_nc_read_file_entry(
+		const char *const filename, 
+		TERMTYPE *ptr)
+		{ return(*(int *)0); }
+
+#undef _nc_read_entry
+int	_nc_read_entry(
+		const char *const name, 
+		char	*const filename, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/read_termcap.c */
+
+#include <sys/types.h>
+
+#undef _nc_read_termcap_entry
+int	_nc_read_termcap_entry(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+/* ./tinfo/setbuf.c */
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		NCURSES_BOOL buffered)
+		{ /* void */ }
+
+/* ./tinfo/strings.c */
+
+#undef _nc_str_init
+string_desc *_nc_str_init(
+		string_desc *dst, 
+		char	*src, 
+		size_t	len)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_str_null
+string_desc *_nc_str_null(
+		string_desc *dst, 
+		size_t	len)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_str_copy
+string_desc *_nc_str_copy(
+		string_desc *dst, 
+		string_desc *src)
+		{ return(*(string_desc **)0); }
+
+#undef _nc_safe_strcat
+NCURSES_BOOL _nc_safe_strcat(
+		string_desc *dst, 
+		const char *src)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_safe_strcpy
+NCURSES_BOOL _nc_safe_strcpy(
+		string_desc *dst, 
+		const char *src)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./trace/trace_buf.c */
+
+#undef _nc_trace_buf
+char	*_nc_trace_buf(
+		int	bufnum, 
+		size_t	want)
+		{ return(*(char **)0); }
+
+#undef _nc_trace_bufcat
+char	*_nc_trace_bufcat(
+		int	bufnum, 
+		const char *value)
+		{ return(*(char **)0); }
+
+/* ./trace/trace_tries.c */
+
+#undef _nc_trace_tries
+void	_nc_trace_tries(
+		TRIES	*tree)
+		{ /* void */ }
+
+/* ./base/tries.c */
+
+#undef _nc_expand_try
+char	*_nc_expand_try(
+		TRIES	*tree, 
+		unsigned code, 
+		int	*count, 
+		size_t	len)
+		{ return(*(char **)0); }
+
+#undef _nc_remove_key
+int	_nc_remove_key(
+		TRIES	**tree, 
+		unsigned code)
+		{ return(*(int *)0); }
+
+#undef _nc_remove_string
+int	_nc_remove_string(
+		TRIES	**tree, 
+		const char *string)
+		{ return(*(int *)0); }
+
+/* ./tinfo/trim_sgr0.c */
+
+#undef _nc_trim_sgr0
+char	*_nc_trim_sgr0(
+		TERMTYPE *tp)
+		{ return(*(char **)0); }
+
+/* ./unctrl.c */
+
+#undef _nc_unctrl
+char	*_nc_unctrl(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(char **)0); }
+
+#undef unctrl
+char	*unctrl(
+		chtype	ch)
+		{ return(*(char **)0); }
+
+/* ./trace/visbuf.c */
+
+#undef _nc_visbuf2
+const char *_nc_visbuf2(
+		int	bufnum, 
+		const char *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_visbuf
+const char *_nc_visbuf(
+		const char *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_visbufn
+const char *_nc_visbufn(
+		const char *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+#undef _nc_viswbuf2
+const char *_nc_viswbuf2(
+		int	bufnum, 
+		const wchar_t *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_viswbuf
+const char *_nc_viswbuf(
+		const wchar_t *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_viswbufn
+const char *_nc_viswbufn(
+		const wchar_t *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+#undef _nc_viswibuf
+const char *_nc_viswibuf(
+		const wint_t *buf)
+		{ return(*(const char **)0); }
+
+#undef _nc_viscbuf2
+const char *_nc_viscbuf2(
+		int	bufnum, 
+		const cchar_t *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+#undef _nc_viscbuf
+const char *_nc_viscbuf(
+		const cchar_t *buf, 
+		int	len)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/alloc_entry.c */
+
+#undef _nc_init_entry
+void	_nc_init_entry(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#undef _nc_copy_entry
+ENTRY	*_nc_copy_entry(
+		ENTRY	*oldp)
+		{ return(*(ENTRY **)0); }
+
+#undef _nc_save_str
+char	*_nc_save_str(
+		const char *const string)
+		{ return(*(char **)0); }
+
+#undef _nc_wrap_entry
+void	_nc_wrap_entry(
+		ENTRY	*const ep, 
+		NCURSES_BOOL copy_strings)
+		{ /* void */ }
+
+#undef _nc_merge_entry
+void	_nc_merge_entry(
+		TERMTYPE *const to, 
+		TERMTYPE *const from)
+		{ /* void */ }
+
+/* ./tinfo/captoinfo.c */
+
+#undef _nc_captoinfo
+char	*_nc_captoinfo(
+		const char *cap, 
+		const char *s, 
+		int const parameterized)
+		{ return(*(char **)0); }
+
+#undef _nc_infotocap
+char	*_nc_infotocap(
+		const char *cap, 
+		const char *str, 
+		int const parameterized)
+		{ return(*(char **)0); }
+
+/* ./comp_captab.c */
+
+#include <hashsize.h>
+
+#undef _nc_get_table
+const struct name_table_entry *_nc_get_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct name_table_entry **)0); }
+
+#undef _nc_get_hash_table
+const short *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const short **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+/* ./tinfo/comp_expand.c */
+
+#undef _nc_tic_expand
+char	*_nc_tic_expand(
+		const char *srcp, 
+		NCURSES_BOOL tic_format, 
+		int	numbers)
+		{ return(*(char **)0); }
+
+/* ./tinfo/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const short *hash_table)
+		{ return(*(struct name_table_entry const **)0); }
+
+#undef _nc_find_type_entry
+struct name_table_entry const *_nc_find_type_entry(
+		const char *string, 
+		int	type, 
+		const struct name_table_entry *table)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./tinfo/comp_parse.c */
+
+#undef _nc_check_termtype2
+void	(*_nc_check_termtype2)(
+		TERMTYPE *p1, 
+		NCURSES_BOOL p2);
+#undef _nc_check_termtype
+void	(*_nc_check_termtype)(
+		TERMTYPE *p1);
+
+#undef _nc_entry_match
+NCURSES_BOOL _nc_entry_match(
+		char	*n1, 
+		char	*n2)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_read_entry_source
+void	_nc_read_entry_source(
+		FILE	*fp, 
+		char	*buf, 
+		int	literal, 
+		NCURSES_BOOL silent, 
+		NCURSES_BOOL (*hook)(
+		ENTRY	*p1))
+		{ /* void */ }
+
+#undef _nc_resolve_uses2
+int	_nc_resolve_uses2(
+		NCURSES_BOOL fullresolve, 
+		NCURSES_BOOL literal)
+		{ return(*(int *)0); }
+
+#undef _nc_resolve_uses
+int	_nc_resolve_uses(
+		NCURSES_BOOL fullresolve)
+		{ return(*(int *)0); }
+
+/* ./tinfo/comp_scan.c */
+
+#undef _nc_syntax
+int	_nc_syntax;
+#undef _nc_curr_file_pos
+long	_nc_curr_file_pos;
+#undef _nc_comment_start
+long	_nc_comment_start;
+#undef _nc_comment_end
+long	_nc_comment_end;
+#undef _nc_start_line
+long	_nc_start_line;
+#undef _nc_curr_token
+struct token _nc_curr_token;
+#undef _nc_disable_period
+NCURSES_BOOL _nc_disable_period;
+
+#undef _nc_reset_input
+void	_nc_reset_input(
+		FILE	*fp, 
+		char	*buf)
+		{ /* void */ }
+
+#undef _nc_get_token
+int	_nc_get_token(
+		NCURSES_BOOL silent)
+		{ return(*(int *)0); }
+
+#undef _nc_trans_string
+int	_nc_trans_string(
+		char	*ptr, 
+		char	*last)
+		{ return(*(int *)0); }
+
+#undef _nc_push_token
+void	_nc_push_token(
+		int	tokclass)
+		{ /* void */ }
+
+#undef _nc_panic_mode
+void	_nc_panic_mode(
+		char	ch)
+		{ /* void */ }
+
+/* ./tinfo/parse_entry.c */
+
+#undef _nc_parse_entry
+int	_nc_parse_entry(
+		struct entry *entryp, 
+		int	literal, 
+		NCURSES_BOOL silent)
+		{ return(*(int *)0); }
+
+#undef _nc_capcmp
+int	_nc_capcmp(
+		const char *s, 
+		const char *t)
+		{ return(*(int *)0); }
+
+typedef struct {
+    const char *from;
+    const char *to;
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		char	*dir)
+		{ /* void */ }
+
+#undef _nc_write_entry
+void	_nc_write_entry(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#undef _nc_tic_written
+int	_nc_tic_written(void)
+		{ return(*(int *)0); }
+
+/* ./base/define_key.c */
+
+#undef define_key
+int	define_key(
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+/* ./tinfo/hashed_db.c */
+
+#undef _nc_hashed_db
+void	_nc_hashed_db(void)
+		{ /* void */ }
+
+/* ./base/key_defined.c */
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok
+int	keyok(
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./base/version.c */
+
+#undef curses_version
+const char *curses_version(void)
+		{ return(*(const char **)0); }
diff --git a/ncurses/modules b/ncurses/modules
new file mode 100644
index 0000000..f28ef81
--- /dev/null
+++ b/ncurses/modules
@@ -0,0 +1,232 @@
+# $Id: modules,v 1.112 2007/09/08 22:03:34 tom Exp $
+##############################################################################
+# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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.                                                             #
+##############################################################################
+#
+# Author: Thomas E. Dickey	1996-on
+#
+
+@ base
+# Library objects
+hardscroll	lib		$(serial)
+hashmap		lib		$(serial)	../include/term.h
+lib_addch	lib		$(base)
+lib_addstr	lib		$(base)
+lib_beep	lib		$(base)		../include/term.h
+lib_bkgd	lib		$(base)
+lib_box 	lib		$(base)
+lib_chgat	lib		$(base)
+lib_clear	lib		$(base)
+lib_clearok	lib		$(base)
+lib_clrbot	lib		$(base)
+lib_clreol	lib		$(base)
+lib_color	lib		$(base)		../include/term.h
+lib_colorset	lib		$(base)
+lib_delch	lib		$(base)
+lib_delwin	lib		$(base)
+lib_echo	lib		$(base)
+lib_endwin	lib		$(base)		../include/term.h
+lib_erase	lib		$(base)
+lib_flash	lib		$(base)		../include/term.h
+lib_gen 	lib		.		../include/curses.h
+lib_getch	lib		$(base)
+lib_getstr	lib		$(base)		../include/term.h
+lib_hline	lib		$(base)
+lib_immedok	lib		$(base)
+lib_inchstr	lib		$(base)
+lib_initscr	lib		$(base)		$(INCDIR)/tic.h
+lib_insch	lib		$(base)
+lib_insdel	lib		$(base)
+lib_insnstr	lib		$(base)
+lib_instr	lib		$(base)
+lib_isendwin	lib		$(base)
+lib_leaveok	lib		$(base)
+lib_mouse	lib		$(base)		../include/term.h
+lib_move	lib		$(base)
+lib_mvcur	lib		$(serial)	../include/term.h $(INCDIR)/tic.h
+lib_mvwin	lib		$(base)
+lib_newterm	lib		$(base)		../include/term.h
+lib_newwin	lib		$(base)
+lib_nl		lib		$(base)
+lib_overlay	lib		$(base)
+lib_pad 	lib		$(base)
+lib_printw	lib		$(base)
+lib_redrawln	lib		$(base)
+lib_refresh	lib		$(base)
+lib_restart	lib		$(base)		../include/term.h
+lib_scanw	lib		$(base)
+lib_screen	lib		$(base)		../include/term.h
+lib_scroll	lib		$(base)
+lib_scrollok	lib		$(base)
+lib_scrreg	lib		$(base)
+lib_set_term	lib		$(base)		../include/term.h
+lib_slk 	lib		$(base)		../include/term.h
+lib_slkatr_set	lib		$(base)
+lib_slkatrof 	lib		$(base)
+lib_slkatron 	lib		$(base)
+lib_slkatrset 	lib		$(base)
+lib_slkattr 	lib		$(base)
+lib_slkclear 	lib		$(base)
+lib_slkcolor 	lib		$(base)
+lib_slkinit 	lib		$(base)
+lib_slklab	lib		$(base)
+lib_slkrefr	lib		$(base)		../include/term.h
+lib_slkset	lib		$(base)
+lib_slktouch	lib		$(base)
+lib_touch	lib		$(base)
+lib_tracedmp	lib		$(trace)
+lib_tracemse	lib		$(trace)
+lib_tstp	lib		$(serial)	$(srcdir)/SigAction.h
+lib_ungetch	lib		$(base)
+lib_vidattr	lib		$(serial)	../include/term.h
+lib_vline	lib		$(base)
+lib_wattroff	lib		$(base)
+lib_wattron	lib		$(base)
+lib_winch	lib		$(base)
+lib_window	lib		$(base)
+link_test 	lib		.		../include/curses.h
+nc_panel	lib		$(base)
+safe_sprintf	lib		$(base)
+tty_update	lib		$(serial)	../include/term.h
+varargs		lib		$(trace)
+
+# Modules for porting
+memmove		lib		$(base)
+vsscanf 	lib		$(base)
+
+# actually an extension, but with its own configure option (--disable-leaks)
+lib_freeall	lib		$(base)
+
+# XSI extensions to the base library (wide-character)
+@ widechar
+charable	lib		$(wide)
+lib_add_wch	lib		$(wide)
+lib_box_set	lib		$(wide)
+lib_cchar	lib		$(wide)
+lib_erasewchar	lib		$(wide)
+lib_get_wch	lib		$(wide)
+lib_get_wstr	lib		$(wide)
+lib_hline_set	lib		$(wide)
+lib_in_wch	lib		$(wide)
+lib_in_wchnstr	lib		$(wide)
+lib_ins_wch	lib		$(wide)
+lib_inwstr	lib		$(wide)
+lib_key_name	lib		$(wide)
+lib_pecho_wchar	lib		$(wide)
+lib_slk_wset	lib		$(wide)
+lib_unget_wch	lib		$(wide)
+lib_vid_attr	lib		$(wide)		../include/term.h
+lib_vline_set	lib		$(wide)
+lib_wacs	lib		$(wide)
+lib_wunctrl	lib		$(wide)
+
+# Extensions to the base library
+@ ext_funcs
+expanded	lib		.
+legacy_coding	lib		$(base)		../include/term.h
+lib_dft_fgbg	lib		$(base)		../include/term.h
+lib_print	lib		$(tinfo)	../include/term.h
+resizeterm	lib		$(base)		../include/term.h
+trace_xnames	lib		$(trace)	../include/term.h $(INCDIR)/term_entry.h
+use_screen	lib		$(tinfo)
+use_window	lib		$(base)
+wresize		lib		$(base)		../include/term.h
+
+# Support for termcap (and tic, etc.), which can be a separate library
+@ termlib
+access		lib		$(tinfo)
+add_tries	lib		$(tinfo)
+alloc_ttype	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+codes		lib		.
+comp_error	lib		$(tinfo)	$(INCDIR)/tic.h
+db_iterator	lib		$(tinfo)	$(INCDIR)/tic.h
+doalloc		lib		$(tinfo)
+entries		lib		$(tinfo)	../include/term.h $(INCDIR)/tic.h
+fallback	lib		.		../include/term.h $(INCDIR)/tic.h
+free_ttype	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+getenv_num	lib		$(tinfo)
+home_terminfo	lib		$(tinfo)
+init_keytry	lib		$(tinfo)	../include/term.h $(INCDIR)/tic.h init_keytry.h
+lib_acs 	lib		$(tinfo)	../include/term.h
+lib_baudrate	lib		$(tinfo)	../include/term.h
+lib_cur_term	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h
+lib_data	lib		$(tinfo)
+lib_has_cap	lib		$(tinfo)	../include/term.h
+lib_kernel	lib		$(tinfo)	../include/term.h
+lib_keyname	lib		.		../include/term.h
+lib_longname	lib		$(tinfo)
+lib_napms	lib		$(tinfo)
+lib_options	lib		$(tinfo)	../include/term.h
+lib_raw 	lib		$(tinfo)	../include/term.h
+lib_setup	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h
+lib_termcap	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h $(INCDIR)/capdefaults.c
+lib_termname	lib		$(tinfo)	$(INCDIR)/tic.h
+lib_tgoto	lib		$(tinfo)	../include/term.h $(INCDIR)/tic.h
+lib_ti		lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+lib_tparm	lib		$(tinfo)	../include/term.h $(INCDIR)/tic.h
+lib_tputs	lib		$(tinfo)	../include/term.h $(INCDIR)/tic.h
+lib_trace	lib		$(trace)	$(INCDIR)/tic.h
+lib_traceatr	lib		$(trace)	../include/term.h
+lib_tracebits	lib		$(trace)	../include/term.h
+lib_tracechr	lib		$(trace)
+lib_ttyflags	lib		$(tinfo)	../include/term.h
+lib_twait	lib		$(serial)
+name_match	lib		$(tinfo)	../include/term.h $(INCDIR)/tic.h
+names		lib		.
+read_entry	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+read_termcap	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+setbuf		lib		$(tinfo)
+strings		lib		$(tinfo)
+trace_buf	lib		$(trace)
+trace_tries	lib		$(trace)
+tries		lib		$(base)
+trim_sgr0	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+unctrl		lib		.
+visbuf		lib		$(trace)	$(INCDIR)/tic.h
+
+# Modules used only for tic, other programs using internal interfaces
+@ ticlib
+alloc_entry	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+captoinfo	lib		$(tinfo)	$(INCDIR)/tic.h
+comp_captab	lib		.		$(INCDIR)/tic.h ../include/term.h ../include/hashsize.h
+comp_expand	lib		$(tinfo)	$(INCDIR)/tic.h
+comp_hash	lib		$(tinfo)	../include/term.h $(INCDIR)/tic.h ../include/hashsize.h
+comp_parse	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+comp_scan	lib		$(tinfo)	$(INCDIR)/tic.h
+parse_entry	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h ../include/parametrized.h $(INCDIR)/capdefaults.c
+write_entry	lib		$(tinfo)	../include/term.h $(INCDIR)/term_entry.h $(INCDIR)/tic.h
+
+# Extensions to the termlib library
+@ ext_tinfo
+define_key	lib		$(base)
+hashed_db	lib		$(tinfo)
+key_defined	lib		$(base)
+keybound	lib		$(base)
+keyok		lib		$(base)
+version		lib		$(base)
+
+# vile:makemode
diff --git a/ncurses/tinfo/MKcaptab.awk b/ncurses/tinfo/MKcaptab.awk
new file mode 100644
index 0000000..56d3d17
--- /dev/null
+++ b/ncurses/tinfo/MKcaptab.awk
@@ -0,0 +1,94 @@
+##############################################################################
+# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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: MKcaptab.awk,v 1.20 2007/08/12 00:26:15 tom Exp $
+function add_string(text) {
+    if (text != "IGNORE") {
+	offsets[num_strings] = offset;
+	offset = offset + length(text) + 1;
+	printf "%s\\0", text;
+    } else {
+	offsets[num_strings] = -1;
+    }
+    num_strings = num_strings + 1;
+    if ((num_strings % 3) == 0) {
+	printf "\\\n";
+    }
+    return offsets[num_strings - 1];
+}
+BEGIN {
+	first = 1;
+	num_aliases = 0;
+	num_strings = 0;
+	offset = 0;
+}
+
+/^[^#]/ {
+	    if (first) {
+		printf "/* generated by MKcaptab.awk %s(%d) */\n", tablename, bigstrings;
+		print ""
+		if (bigstrings) {
+		    printf "static struct alias *_nc_%s_table = 0;\n", tablename;
+		    print "";
+		    printf "static const char %s_text[] = \"\\\n", tablename;
+		} else {
+		    printf "static const struct alias _nc_%s_table[] =\n", tablename;
+		    printf "{\n";
+		}
+		first = 0;
+	    }
+	    if ($1 == tablename) {
+		if ($3 == "IGNORE") {
+		    to = "(char *)NULL";
+		} else {
+		    to = "\"" $3 "\"";
+		}
+		if (bigstrings) {
+		    c1 = add_string($2);
+		    c2 = add_string($3);
+		    c3 = add_string($4);
+		    aliases[num_aliases] = sprintf("\t{%5d, %5d, %5d},\t /* %s */", c1, c2, c3, $5);
+		    num_aliases = num_aliases + 1;
+		} else {
+		    printf "\t{\"%s\", %s, \"%s\"},\t /* %s */\n", $2, to, $4, $5;
+		}
+	    }
+	}
+END	{
+	    if (bigstrings) {
+		printf "\";\n\n";
+		printf "static const alias_table_data %s_data[] = {\n", tablename;
+		for (n = 0; n < num_aliases; ++n) {
+		    printf "%s\n", aliases[n];
+		}
+		printf "};\n\n";
+	    } else {
+		printf "\t{(char *)NULL, (char *)NULL, (char *)NULL}\n";
+		printf "};\n\n";
+	    }
+	}
+# vile:sw=4:
diff --git a/ncurses/tinfo/MKcaptab.sh b/ncurses/tinfo/MKcaptab.sh
new file mode 100755
index 0000000..98c04e8
--- /dev/null
+++ b/ncurses/tinfo/MKcaptab.sh
@@ -0,0 +1,149 @@
+#!/bin/sh
+##############################################################################
+# Copyright (c) 2007 Free Software Foundation, Inc.                          #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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: MKcaptab.sh,v 1.8 2007/08/12 13:13:51 tom Exp $
+AWK=${1-awk}
+OPT1=${2-0}
+OPT2=${3-tinfo/MKcaptab.awk}
+DATA=${4-../include/Caps}
+
+cat <<'EOF'
+/*
+ *	comp_captab.c -- The names of the capabilities indexed via a hash
+ *		         table for the compiler.
+ *
+ */
+
+#include <curses.priv.h>
+#include <tic.h>
+#include <hashsize.h>
+
+EOF
+
+./make_hash 1 info $OPT1 <$DATA
+./make_hash 3 cap  $OPT1 <$DATA
+
+$AWK -f $OPT2 bigstrings=$OPT1 tablename=capalias <$DATA 
+
+$AWK -f $OPT2 bigstrings=$OPT1 tablename=infoalias <$DATA
+
+cat <<EOF
+
+#if $OPT1
+static void
+next_string(const char *strings, unsigned *offset)
+{
+	*offset += strlen(strings + *offset) + 1;
+}
+
+static const struct name_table_entry *
+_nc_build_names(struct name_table_entry **actual,
+		const name_table_data *source,
+		const char *strings)
+{
+	if (*actual == 0) {
+		*actual = typeCalloc(struct name_table_entry, CAPTABSIZE);
+		if (*actual != 0) {
+			unsigned n;
+			unsigned len = 0;
+			for (n = 0; n < CAPTABSIZE; ++n) {
+				(*actual)[n].nte_name = strings + len;
+				(*actual)[n].nte_type = source[n].nte_type;
+				(*actual)[n].nte_index = source[n].nte_index;
+				(*actual)[n].nte_link = source[n].nte_link;
+				next_string(strings, &len);
+			}
+		}
+	}
+	return *actual;
+}
+
+#define add_alias(field) \\
+	if (source[n].field >= 0) { \\
+		(*actual)[n].field = strings + source[n].field; \\
+	}
+
+static const struct alias *
+_nc_build_alias(struct alias **actual,
+		const alias_table_data *source,
+		const char *strings,
+		unsigned tablesize)
+{
+	if (*actual == 0) {
+		*actual = typeCalloc(struct alias, tablesize + 1);
+		if (*actual != 0) {
+			unsigned n;
+			for (n = 0; n < tablesize; ++n) {
+				add_alias(from);
+				add_alias(to);
+				add_alias(source);
+			}
+		}
+	}
+	return *actual;
+}
+
+#define build_names(root) _nc_build_names(&_nc_##root##_table, \\
+					  root##_names_data, \\
+					  root##_names_text)
+#define build_alias(root) _nc_build_alias(&_nc_##root##alias_table, \\
+					  root##alias_data, \\
+					  root##alias_text, \\
+					  SIZEOF(root##alias_data))
+#else
+#define build_names(root) _nc_ ## root ## _table
+#define build_alias(root) _nc_ ## root ## alias_table
+#endif
+
+NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool termcap)
+{
+	return termcap ? build_names(cap) : build_names(info) ;
+}
+
+NCURSES_EXPORT(const short *) _nc_get_hash_table (bool termcap)
+{
+	return termcap ? _nc_cap_hash_table: _nc_info_hash_table ;
+}
+
+NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool termcap)
+{
+	return termcap ? build_alias(cap) : build_alias(info) ;
+}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void) _nc_comp_captab_leaks(void)
+{
+#if $OPT1
+	FreeIfNeeded(_nc_cap_table);
+	FreeIfNeeded(_nc_info_table);
+	FreeIfNeeded(_nc_capalias_table);
+	FreeIfNeeded(_nc_infoalias_table);
+#endif
+}
+#endif /* NO_LEAKS */
+EOF
diff --git a/ncurses/tinfo/MKcodes.awk b/ncurses/tinfo/MKcodes.awk
new file mode 100644
index 0000000..b9ba636
--- /dev/null
+++ b/ncurses/tinfo/MKcodes.awk
@@ -0,0 +1,164 @@
+##############################################################################
+# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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: MKcodes.awk,v 1.5 2008/06/28 23:13:25 tom Exp $
+function large_item(value) {
+	result = sprintf("%d,", offset);
+	offset = offset + length(value) + 1;
+	offcol = offcol + length(result) + 2;
+	if (offcol > 70) {
+		result = result "\n";
+		offcol = 0;
+	} else {
+		result = result " ";
+	}
+	bigstr = bigstr sprintf("\"%s\\0\" ", value);
+	bigcol = bigcol + length(value) + 5;
+	if (bigcol > 70) {
+		bigstr = bigstr "\\\n";
+		bigcol = 0;
+	}
+	return result;
+}
+
+function small_item(value) {
+	return sprintf("\t\t\"%s\",\n", value);
+}
+
+function print_strings(name,value) {
+	printf  "DCL(%s) = {\n", name
+	print  value
+	print  "\t\t(NCURSES_CONST char *)0,"
+	print  "};"
+	print  ""
+}
+
+function print_offsets(name,value) {
+	printf  "static const short _nc_offset_%s[] = {\n", name
+	printf "%s",  value
+	print  "};"
+	print  ""
+	printf "static NCURSES_CONST char ** ptr_%s = 0;\n", name
+	print  ""
+}
+
+BEGIN	{
+		print  "/* This file was generated by MKcodes.awk */"
+		print  ""
+		print  "#include <curses.priv.h>"
+		print  ""
+		print  "#define IT NCURSES_CONST char * const"
+		print  ""
+		offset = 0;
+		offcol = 0;
+		bigcol = 0;
+	}
+
+$1 ~ /^#/		{next;}
+
+$1 == "SKIPWARN"	{next;}
+
+$3 == "bool"	{
+			small_boolcodes = small_boolcodes small_item($4);
+			large_boolcodes = large_boolcodes large_item($4);
+		}
+
+$3 == "num"	{
+			small_numcodes = small_numcodes small_item($4);
+			large_numcodes = large_numcodes large_item($4);
+		}
+
+$3 == "str"	{
+			small_strcodes = small_strcodes small_item($4);
+			large_strcodes = large_strcodes large_item($4);
+		}
+
+END	{
+		print  ""
+		print  "#if BROKEN_LINKER || USE_REENTRANT"
+		print  ""
+		print  "#include <term.h>"
+		print  ""
+		if (bigstrings) {
+			printf "static const char _nc_code_blob[] = \n"
+			printf "%s;\n", bigstr;
+			print_offsets("boolcodes", large_boolcodes);
+			print_offsets("numcodes", large_numcodes);
+			print_offsets("strcodes", large_strcodes);
+			print  ""
+			print  "static IT *"
+			print  "alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)"
+			print  "{"
+			print  "	if (*value == 0) {"
+			print  "		if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {"
+			print  "			unsigned n;"
+			print  "			for (n = 0; n < size; ++n) {"
+			print  "				(*value)[n] = _nc_code_blob + offsets[n];"
+			print  "			}"
+			print  "		}"
+			print  "	}"
+			print  "	return *value;"
+			print  "}"
+			print  ""
+			print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }"
+		} else {
+			print  "#define DCL(it) static IT data##it[]"
+			print  ""
+			print_strings("boolcodes", small_boolcodes);
+			print_strings("numcodes", small_numcodes);
+			print_strings("strcodes", small_strcodes);
+			print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return data##it; }"
+		}
+		print  ""
+		print  "FIX(boolcodes)"
+		print  "FIX(numcodes)"
+		print  "FIX(strcodes)"
+		print  ""
+		print  "#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }"
+		print  ""
+		print  "#if NO_LEAKS"
+		print  "NCURSES_EXPORT(void)"
+		print  "_nc_codes_leaks(void)"
+		print  "{"
+		if (bigstrings) {
+		print  "FREE_FIX(boolcodes)"
+		print  "FREE_FIX(numcodes)"
+		print  "FREE_FIX(strcodes)"
+		}
+		print  "}"
+		print  "#endif"
+		print  ""
+		print  "#else"
+		print  ""
+		print  "#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]"
+		print  ""
+		print_strings("boolcodes", small_boolcodes);
+		print_strings("numcodes", small_numcodes);
+		print_strings("strcodes", small_strcodes);
+		print  ""
+		print  "#endif /* BROKEN_LINKER */"
+	}
diff --git a/ncurses/tinfo/MKfallback.sh b/ncurses/tinfo/MKfallback.sh
new file mode 100755
index 0000000..9feab35
--- /dev/null
+++ b/ncurses/tinfo/MKfallback.sh
@@ -0,0 +1,129 @@
+#!/bin/sh
+##############################################################################
+# Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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: MKfallback.sh,v 1.13 2006/07/15 16:54:20 tom Exp $
+#
+# MKfallback.sh -- create fallback table for entry reads
+#
+# This script generates source code for a custom version of read_entry.c
+# that (instead of reading capabilities for an argument terminal type
+# from an on-disk terminfo tree) tries to match the type with one of a
+# specified list of types generated in.
+#
+
+terminfo_dir=$1
+shift
+
+terminfo_src=$1
+shift
+
+if test $# != 0 ; then
+	tmp_info=tmp_info
+	echo creating temporary terminfo directory... >&2
+
+	TERMINFO=`pwd`/$tmp_info
+	export TERMINFO
+
+	TERMINFO_DIRS=$TERMINFO:$terminfo_dir
+	export TERMINFO_DIRS
+
+	tic -x $terminfo_src >&2
+else
+	tmp_info=
+fi
+
+cat <<EOF
+/*
+ * DO NOT EDIT THIS FILE BY HAND!  It is generated by MKfallback.sh.
+ */
+
+#include <curses.priv.h>
+#include <term.h>
+
+EOF
+
+if [ "$*" ]
+then
+	cat <<EOF
+#include <tic.h>
+
+/* fallback entries for: $* */
+EOF
+	for x in $*
+	do
+		echo "/* $x */"
+		infocmp -E $x
+	done
+
+	cat <<EOF
+static const TERMTYPE fallbacks[$#] =
+{
+EOF
+	comma=""
+	for x in $*
+	do
+		echo "$comma /* $x */"
+		infocmp -e $x
+		comma=","
+	done
+
+	cat <<EOF
+};
+
+EOF
+fi
+
+cat <<EOF
+NCURSES_EXPORT(const TERMTYPE *) _nc_fallback (const char *name GCC_UNUSED)
+{
+EOF
+
+if [ "$*" ]
+then
+	cat <<EOF
+    const TERMTYPE	*tp;
+
+    for (tp = fallbacks;
+	 	tp < fallbacks + sizeof(fallbacks)/sizeof(TERMTYPE);
+	 	tp++)
+	if (_nc_name_match(tp->term_names, name, "|"))
+	    return(tp);
+EOF
+else
+	echo "	/* the fallback list is empty */";
+fi
+
+cat <<EOF
+	return((TERMTYPE *)0);
+}
+EOF
+
+if test -n "$tmp_info" ; then
+	echo removing temporary terminfo directory... >&2
+	rm -rf $tmp_info
+fi
diff --git a/ncurses/tinfo/MKkeys_list.sh b/ncurses/tinfo/MKkeys_list.sh
new file mode 100755
index 0000000..14017b0
--- /dev/null
+++ b/ncurses/tinfo/MKkeys_list.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+# $Id: MKkeys_list.sh,v 1.4 2003/10/25 16:19:54 tom Exp $
+##############################################################################
+# Copyright (c) 2001,2003 Free Software Foundation, Inc.                     #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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.                                                             #
+##############################################################################
+#
+# MKkey_defs.sh -- generate list of function-keys for terminfo database
+#
+# Author: Thomas E. Dickey 2001
+#
+# Extract function-key names from the Caps file
+#
+: ${AWK-awk}
+DATA=${1-../../include/Caps}
+
+data=data$$
+trap 'rm -f $data' 0 1 2 5 15
+sed -e 's/[	][	]*/	/g' < $DATA >$data
+
+cat <<EOF
+# These definitions were generated by $0 $DATA
+KEY_BREAK
+KEY_SRESET
+KEY_RESET
+KEY_RESIZE
+EOF
+
+${AWK-awk} <$data '
+/^#/		{next;}
+/^capalias/	{next;}
+/^infoalias/	{next;}
+
+$5 != "-" {
+		if (substr($5, 1, 4) == "KEY_" ) {
+			printf "%s	%s\n", $5, $1
+	}
+}
+'
diff --git a/ncurses/tinfo/MKnames.awk b/ncurses/tinfo/MKnames.awk
new file mode 100644
index 0000000..7e50744
--- /dev/null
+++ b/ncurses/tinfo/MKnames.awk
@@ -0,0 +1,186 @@
+##############################################################################
+# Copyright (c) 2007,2008 Free Software Foundation, Inc.                     #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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: MKnames.awk,v 1.20 2008/10/11 21:07:56 tom Exp $
+function large_item(value) {
+	result = sprintf("%d,", offset);
+	offset = offset + length(value) + 1;
+	offcol = offcol + length(result) + 2;
+	if (offcol > 70) {
+		result = result "\n";
+		offcol = 0;
+	} else {
+		result = result " ";
+	}
+	bigstr = bigstr sprintf("\"%s\\0\" ", value);
+	bigcol = bigcol + length(value) + 5;
+	if (bigcol > 70) {
+		bigstr = bigstr "\\\n";
+		bigcol = 0;
+	}
+	return result;
+}
+
+function small_item(value) {
+	return sprintf("\t\t\"%s\",\n", value);
+}
+
+function print_strings(name,value) {
+	printf  "DCL(%s) = {\n", name
+	print  value
+	print  "\t\t(NCURSES_CONST char *)0,"
+	print  "};"
+	print  ""
+}
+
+function print_offsets(name,value) {
+	printf  "static const short _nc_offset_%s[] = {\n", name
+	printf "%s",  value
+	print  "};"
+	print  ""
+	printf "static NCURSES_CONST char ** ptr_%s = 0;\n", name
+	print  ""
+}
+
+BEGIN	{
+		print  "/* This file was generated by MKnames.awk */"
+		print  ""
+		print  "#include <curses.priv.h>"
+		print  ""
+		print  "#define IT NCURSES_CONST char * const"
+		print  ""
+		offset = 0;
+		offcol = 0;
+		bigcol = 0;
+	}
+
+$1 ~ /^#/		{next;}
+
+$1 == "SKIPWARN"	{next;}
+
+$3 == "bool"	{
+			small_boolnames = small_boolnames small_item($2);
+			large_boolnames = large_boolnames large_item($2);
+			small_boolfnames = small_boolfnames small_item($1);
+			large_boolfnames = large_boolfnames large_item($1);
+		}
+
+$3 == "num"	{
+			small_numnames = small_numnames small_item($2);
+			large_numnames = large_numnames large_item($2);
+			small_numfnames = small_numfnames small_item($1);
+			large_numfnames = large_numfnames large_item($1);
+		}
+
+$3 == "str"	{
+			small_strnames = small_strnames small_item($2);
+			large_strnames = large_strnames large_item($2);
+			small_strfnames = small_strfnames small_item($1);
+			large_strfnames = large_strfnames large_item($1);
+		}
+
+END	{
+		print  ""
+		print  "#if BROKEN_LINKER || USE_REENTRANT"
+		print  ""
+		print  "#include <term.h>"
+		print  ""
+		if (bigstrings) {
+			printf "static const char _nc_name_blob[] = \n"
+			printf "%s;\n", bigstr;
+			print_offsets("boolfnames", large_boolfnames);
+			print_offsets("boolnames", large_boolnames);
+			print_offsets("numfnames", large_numfnames);
+			print_offsets("numnames", large_numnames);
+			print_offsets("strfnames", large_strfnames);
+			print_offsets("strnames", large_strnames);
+			print  ""
+			print  "static IT *"
+			print  "alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)"
+			print  "{"
+			print  "	if (*value == 0) {"
+			print  "		if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {"
+			print  "			unsigned n;"
+			print  "			for (n = 0; n < size; ++n) {"
+			print  "				(*value)[n] = (NCURSES_CONST char *) _nc_name_blob + offsets[n];"
+			print  "			}"
+			print  "		}"
+			print  "	}"
+			print  "	return *value;"
+			print  "}"
+			print  ""
+			print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }"
+		} else {
+			print  "#define DCL(it) static IT data##it[]"
+			print  ""
+			print_strings("boolnames", small_boolnames);
+			print_strings("boolfnames", small_boolfnames);
+			print_strings("numnames", small_numnames);
+			print_strings("numfnames", small_numfnames);
+			print_strings("strnames", small_strnames);
+			print_strings("strfnames", small_strfnames);
+			print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return data##it; }"
+		}
+		print  ""
+		print  "FIX(boolnames)"
+		print  "FIX(boolfnames)"
+		print  "FIX(numnames)"
+		print  "FIX(numfnames)"
+		print  "FIX(strnames)"
+		print  "FIX(strfnames)"
+		print  ""
+		print  ""
+		print  "#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }"
+		print  ""
+		print  "#if NO_LEAKS"
+		print  "NCURSES_EXPORT(void)"
+		print  "_nc_names_leaks(void)"
+		print  "{"
+		if (bigstrings) {
+		print  "FREE_FIX(boolnames)"
+		print  "FREE_FIX(boolfnames)"
+		print  "FREE_FIX(numnames)"
+		print  "FREE_FIX(numfnames)"
+		print  "FREE_FIX(strnames)"
+		print  "FREE_FIX(strfnames)"
+		}
+		print  "}"
+		print  "#endif"
+		print  ""
+		print  "#else"
+		print  ""
+		print  "#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]"
+		print  ""
+		print_strings("boolnames", small_boolnames);
+		print_strings("boolfnames", small_boolfnames);
+		print_strings("numnames", small_numnames);
+		print_strings("numfnames", small_numfnames);
+		print_strings("strnames", small_strnames);
+		print_strings("strfnames", small_strfnames);
+		print  ""
+		print  "#endif /* BROKEN_LINKER */"
+	}
diff --git a/ncurses/tinfo/README b/ncurses/tinfo/README
new file mode 100644
index 0000000..14c4220
--- /dev/null
+++ b/ncurses/tinfo/README
@@ -0,0 +1,36 @@
+-------------------------------------------------------------------------------
+-- Copyright (c) 1998,2006 Free Software Foundation, Inc.                    --
+--                                                                           --
+-- Permission is hereby granted, free of charge, to any person obtaining a   --
+-- copy of this software and associated documentation files (the             --
+-- "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: README,v 1.2 2006/04/22 22:19:37 tom Exp $
+-------------------------------------------------------------------------------
+
+The files in this directory (tinfo) are those that support the terminfo
+database and interfaces for ncurses.  The terminfo library can be built
+separately, as a lower-level library for ncurses, but usually is bundled.
+
+In addition to the standard documented interfaces, ncurses uses internal
+functions which reside in tinfo to satisfy linkage requirements.
diff --git a/ncurses/tinfo/access.c b/ncurses/tinfo/access.c
new file mode 100644
index 0000000..ce8ccda
--- /dev/null
+++ b/ncurses/tinfo/access.c
@@ -0,0 +1,176 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <sys/stat.h>
+
+#include <tic.h>
+#include <nc_alloc.h>
+
+MODULE_ID("$Id: access.c,v 1.14 2007/11/18 00:57:53 tom Exp $")
+
+#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
+
+NCURSES_EXPORT(char *)
+_nc_rootname(char *path)
+{
+    char *result = _nc_basename(path);
+#if !MIXEDCASE_FILENAMES || defined(PROG_EXT)
+    static char *temp;
+    char *s;
+
+    temp = strdup(result);
+    result = temp;
+#if !MIXEDCASE_FILENAMES
+    for (s = result; *s != '\0'; ++s) {
+	*s = LOWERCASE(*s);
+    }
+#endif
+#if defined(PROG_EXT)
+    if ((s = strrchr(result, '.')) != 0) {
+	if (!strcmp(s, PROG_EXT))
+	    *s = '\0';
+    }
+#endif
+#endif
+    return result;
+}
+
+/*
+ * Check if a string appears to be an absolute pathname.
+ */
+NCURSES_EXPORT(bool)
+_nc_is_abs_path(const char *path)
+{
+#if defined(__EMX__) || defined(__DJGPP__)
+#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \
+		  || (((s)[0] != 0) && ((s)[1] == ':')))
+#else
+#define is_pathname(s) ((s) != 0 && (s)[0] == '/')
+#endif
+    return is_pathname(path);
+}
+
+/*
+ * Return index of the basename
+ */
+NCURSES_EXPORT(unsigned)
+_nc_pathlast(const char *path)
+{
+    const char *test = strrchr(path, '/');
+#ifdef __EMX__
+    if (test == 0)
+	test = strrchr(path, '\\');
+#endif
+    if (test == 0)
+	test = path;
+    else
+	test++;
+    return (test - path);
+}
+
+NCURSES_EXPORT(char *)
+_nc_basename(char *path)
+{
+    return path + _nc_pathlast(path);
+}
+
+NCURSES_EXPORT(int)
+_nc_access(const char *path, int mode)
+{
+    if (access(path, mode) < 0) {
+	if ((mode & W_OK) != 0
+	    && errno == ENOENT
+	    && strlen(path) < PATH_MAX) {
+	    char head[PATH_MAX];
+	    char *leaf = _nc_basename(strcpy(head, path));
+
+	    if (leaf == 0)
+		leaf = head;
+	    *leaf = '\0';
+	    if (head == leaf)
+		(void) strcpy(head, ".");
+
+	    return access(head, R_OK | W_OK | X_OK);
+	}
+	return -1;
+    }
+    return 0;
+}
+
+NCURSES_EXPORT(bool)
+_nc_is_dir_path(const char *path)
+{
+    bool result = FALSE;
+    struct stat sb;
+
+    if (stat(path, &sb) == 0
+	&& (sb.st_mode & S_IFMT) == S_IFDIR) {
+	result = TRUE;
+    }
+    return result;
+}
+
+NCURSES_EXPORT(bool)
+_nc_is_file_path(const char *path)
+{
+    bool result = FALSE;
+    struct stat sb;
+
+    if (stat(path, &sb) == 0
+	&& (sb.st_mode & S_IFMT) == S_IFREG) {
+	result = TRUE;
+    }
+    return result;
+}
+
+#ifndef USE_ROOT_ENVIRON
+/*
+ * Returns true if we allow application to use environment variables that are
+ * used for searching lists of directories, etc.
+ */
+NCURSES_EXPORT(int)
+_nc_env_access(void)
+{
+#if HAVE_ISSETUGID
+    if (issetugid())
+	return FALSE;
+#elif HAVE_GETEUID && HAVE_GETEGID
+    if (getuid() != geteuid()
+	|| getgid() != getegid())
+	return FALSE;
+#endif
+    return getuid() != 0 && geteuid() != 0;	/* ...finally, disallow root */
+}
+#endif
diff --git a/ncurses/tinfo/add_tries.c b/ncurses/tinfo/add_tries.c
new file mode 100644
index 0000000..455d142
--- /dev/null
+++ b/ncurses/tinfo/add_tries.c
@@ -0,0 +1,120 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey            1998-on                             *
+ ****************************************************************************/
+
+/*
+**	add_tries.c
+**
+**	Add keycode/string to tries-tree.
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: add_tries.c,v 1.8 2006/12/30 23:15:26 tom Exp $")
+
+#define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0'
+#define CMP_TRY(a,b) ((a)? (a == b) : (b == 128))
+
+NCURSES_EXPORT(int)
+_nc_add_to_try(TRIES ** tree, const char *str, unsigned code)
+{
+    TRIES *ptr, *savedptr;
+    unsigned const char *txt = (unsigned const char *) str;
+
+    T((T_CALLED("_nc_add_to_try(%p, %s, %u)"), *tree, _nc_visbuf(str), code));
+    if (txt == 0 || *txt == '\0' || code == 0)
+	returnCode(ERR);
+
+    if ((*tree) != 0) {
+	ptr = savedptr = (*tree);
+
+	for (;;) {
+	    unsigned char cmp = *txt;
+
+	    while (!CMP_TRY(ptr->ch, cmp)
+		   && ptr->sibling != 0)
+		ptr = ptr->sibling;
+
+	    if (CMP_TRY(ptr->ch, cmp)) {
+		if (*(++txt) == '\0') {
+		    ptr->value = code;
+		    returnCode(OK);
+		}
+		if (ptr->child != 0)
+		    ptr = ptr->child;
+		else
+		    break;
+	    } else {
+		if ((ptr->sibling = typeCalloc(TRIES, 1)) == 0) {
+		    returnCode(ERR);
+		}
+
+		savedptr = ptr = ptr->sibling;
+		SET_TRY(ptr, txt);
+		ptr->value = 0;
+
+		break;
+	    }
+	}			/* end for (;;) */
+    } else {			/* (*tree) == 0 :: First sequence to be added */
+	savedptr = ptr = (*tree) = typeCalloc(TRIES, 1);
+
+	if (ptr == 0) {
+	    returnCode(ERR);
+	}
+
+	SET_TRY(ptr, txt);
+	ptr->value = 0;
+    }
+
+    /* at this point, we are adding to the try.  ptr->child == 0 */
+
+    while (*txt) {
+	ptr->child = typeCalloc(TRIES, 1);
+
+	ptr = ptr->child;
+
+	if (ptr == 0) {
+	    while ((ptr = savedptr) != 0) {
+		savedptr = ptr->child;
+		free(ptr);
+	    }
+	    returnCode(ERR);
+	}
+
+	SET_TRY(ptr, txt);
+	ptr->value = 0;
+    }
+
+    ptr->value = code;
+    returnCode(OK);
+}
diff --git a/ncurses/tinfo/alloc_entry.c b/ncurses/tinfo/alloc_entry.c
new file mode 100644
index 0000000..4638e99
--- /dev/null
+++ b/ncurses/tinfo/alloc_entry.c
@@ -0,0 +1,299 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ * alloc_entry.c -- allocation functions for terminfo entries
+ *
+ *	_nc_copy_entry()
+ *	_nc_init_entry()
+ *	_nc_merge_entry()
+ *	_nc_save_str()
+ *	_nc_wrap_entry()
+ *
+ */
+
+#include <curses.priv.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: alloc_entry.c,v 1.48 2008/08/16 16:25:31 tom Exp $")
+
+#define ABSENT_OFFSET    -1
+#define CANCELLED_OFFSET -2
+
+#define MAX_STRTAB	4096	/* documented maximum entry size */
+
+static char *stringbuf;		/* buffer for string capabilities */
+static size_t next_free;	/* next free character in stringbuf */
+
+NCURSES_EXPORT(void)
+_nc_init_entry(TERMTYPE *const tp)
+/* initialize a terminal type data block */
+{
+    unsigned i;
+
+#if NO_LEAKS
+    if (tp == 0 && stringbuf != 0) {
+	FreeAndNull(stringbuf);
+	return;
+    }
+#endif
+
+    if (stringbuf == 0)
+	stringbuf = (char *) malloc(MAX_STRTAB);
+
+#if NCURSES_XNAMES
+    tp->num_Booleans = BOOLCOUNT;
+    tp->num_Numbers = NUMCOUNT;
+    tp->num_Strings = STRCOUNT;
+    tp->ext_Booleans = 0;
+    tp->ext_Numbers = 0;
+    tp->ext_Strings = 0;
+#endif
+    if (tp->Booleans == 0)
+	tp->Booleans = typeMalloc(NCURSES_SBOOL, BOOLCOUNT);
+    if (tp->Numbers == 0)
+	tp->Numbers = typeMalloc(short, NUMCOUNT);
+    if (tp->Strings == 0)
+	tp->Strings = typeMalloc(char *, STRCOUNT);
+
+    for_each_boolean(i, tp)
+	tp->Booleans[i] = FALSE;
+
+    for_each_number(i, tp)
+	tp->Numbers[i] = ABSENT_NUMERIC;
+
+    for_each_string(i, tp)
+	tp->Strings[i] = ABSENT_STRING;
+
+    next_free = 0;
+}
+
+NCURSES_EXPORT(ENTRY *)
+_nc_copy_entry(ENTRY * oldp)
+{
+    ENTRY *newp = typeCalloc(ENTRY, 1);
+
+    if (newp != 0) {
+	*newp = *oldp;
+	_nc_copy_termtype(&(newp->tterm), &(oldp->tterm));
+    }
+    return newp;
+}
+
+/* save a copy of string in the string buffer */
+NCURSES_EXPORT(char *)
+_nc_save_str(const char *const string)
+{
+    char *result = 0;
+    size_t old_next_free = next_free;
+    size_t len = strlen(string) + 1;
+
+    if (len == 1 && next_free != 0) {
+	/*
+	 * Cheat a little by making an empty string point to the end of the
+	 * previous string.
+	 */
+	if (next_free < MAX_STRTAB) {
+	    result = (stringbuf + next_free - 1);
+	}
+    } else if (next_free + len < MAX_STRTAB) {
+	strcpy(&stringbuf[next_free], string);
+	DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
+	DEBUG(7, ("at location %d", (int) next_free));
+	next_free += len;
+	result = (stringbuf + old_next_free);
+    } else {
+	_nc_warning("Too much data, some is lost");
+    }
+    return result;
+}
+
+NCURSES_EXPORT(void)
+_nc_wrap_entry(ENTRY * const ep, bool copy_strings)
+/* copy the string parts to allocated storage, preserving pointers to it */
+{
+    int offsets[MAX_ENTRY_SIZE / sizeof(short)];
+    int useoffsets[MAX_USES];
+    unsigned i, n;
+    unsigned nuses = ep->nuses;
+    TERMTYPE *tp = &(ep->tterm);
+
+    if (copy_strings) {
+	next_free = 0;		/* clear static storage */
+
+	/* copy term_names, Strings, uses */
+	tp->term_names = _nc_save_str(tp->term_names);
+	for_each_string(i, tp) {
+	    if (tp->Strings[i] != ABSENT_STRING &&
+		tp->Strings[i] != CANCELLED_STRING) {
+		tp->Strings[i] = _nc_save_str(tp->Strings[i]);
+	    }
+	}
+
+	for (i = 0; i < nuses; i++) {
+	    if (ep->uses[i].name == 0) {
+		ep->uses[i].name = _nc_save_str(ep->uses[i].name);
+	    }
+	}
+
+	free(tp->str_table);
+    }
+
+    assert(tp->term_names >= stringbuf);
+    n = (unsigned) (tp->term_names - stringbuf);
+    for_each_string(i, &(ep->tterm)) {
+	if (i < SIZEOF(offsets)) {
+	    if (tp->Strings[i] == ABSENT_STRING) {
+		offsets[i] = ABSENT_OFFSET;
+	    } else if (tp->Strings[i] == CANCELLED_STRING) {
+		offsets[i] = CANCELLED_OFFSET;
+	    } else {
+		offsets[i] = tp->Strings[i] - stringbuf;
+	    }
+	}
+    }
+
+    for (i = 0; i < nuses; i++) {
+	if (ep->uses[i].name == 0)
+	    useoffsets[i] = ABSENT_OFFSET;
+	else
+	    useoffsets[i] = ep->uses[i].name - stringbuf;
+    }
+
+    if ((tp->str_table = typeMalloc(char, next_free)) == (char *) 0)
+	  _nc_err_abort(MSG_NO_MEMORY);
+    (void) memcpy(tp->str_table, stringbuf, next_free);
+
+    tp->term_names = tp->str_table + n;
+    for_each_string(i, &(ep->tterm)) {
+	if (i < SIZEOF(offsets)) {
+	    if (offsets[i] == ABSENT_OFFSET) {
+		tp->Strings[i] = ABSENT_STRING;
+	    } else if (offsets[i] == CANCELLED_OFFSET) {
+		tp->Strings[i] = CANCELLED_STRING;
+	    } else {
+		tp->Strings[i] = tp->str_table + offsets[i];
+	    }
+	}
+    }
+
+#if NCURSES_XNAMES
+    if (!copy_strings) {
+	if ((n = (unsigned) NUM_EXT_NAMES(tp)) != 0) {
+	    if (n < SIZEOF(offsets)) {
+		unsigned length = 0;
+		for (i = 0; i < n; i++) {
+		    length += strlen(tp->ext_Names[i]) + 1;
+		    offsets[i] = tp->ext_Names[i] - stringbuf;
+		}
+		if ((tp->ext_str_table = typeMalloc(char, length)) == 0)
+		      _nc_err_abort(MSG_NO_MEMORY);
+		for (i = 0, length = 0; i < n; i++) {
+		    tp->ext_Names[i] = tp->ext_str_table + length;
+		    strcpy(tp->ext_Names[i], stringbuf + offsets[i]);
+		    length += strlen(tp->ext_Names[i]) + 1;
+		}
+	    }
+	}
+    }
+#endif
+
+    for (i = 0; i < nuses; i++) {
+	if (useoffsets[i] == ABSENT_OFFSET)
+	    ep->uses[i].name = 0;
+	else
+	    ep->uses[i].name = (tp->str_table + useoffsets[i]);
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from)
+/* merge capabilities from `from' entry into `to' entry */
+{
+    unsigned i;
+
+#if NCURSES_XNAMES
+    _nc_align_termtype(to, from);
+#endif
+    for_each_boolean(i, from) {
+	if (to->Booleans[i] != (char) CANCELLED_BOOLEAN) {
+	    int mergebool = from->Booleans[i];
+
+	    if (mergebool == CANCELLED_BOOLEAN)
+		to->Booleans[i] = FALSE;
+	    else if (mergebool == TRUE)
+		to->Booleans[i] = (char) mergebool;
+	}
+    }
+
+    for_each_number(i, from) {
+	if (to->Numbers[i] != CANCELLED_NUMERIC) {
+	    short mergenum = from->Numbers[i];
+
+	    if (mergenum == CANCELLED_NUMERIC)
+		to->Numbers[i] = ABSENT_NUMERIC;
+	    else if (mergenum != ABSENT_NUMERIC)
+		to->Numbers[i] = mergenum;
+	}
+    }
+
+    /*
+     * Note: the copies of strings this makes don't have their own
+     * storage.  This is OK right now, but will be a problem if we
+     * we ever want to deallocate entries.
+     */
+    for_each_string(i, from) {
+	if (to->Strings[i] != CANCELLED_STRING) {
+	    char *mergestring = from->Strings[i];
+
+	    if (mergestring == CANCELLED_STRING)
+		to->Strings[i] = ABSENT_STRING;
+	    else if (mergestring != ABSENT_STRING)
+		to->Strings[i] = mergestring;
+	}
+    }
+}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_alloc_entry_leaks(void)
+{
+    if (stringbuf != 0) {
+	FreeAndNull(stringbuf);
+    }
+    next_free = 0;
+}
+#endif
diff --git a/ncurses/tinfo/alloc_ttype.c b/ncurses/tinfo/alloc_ttype.c
new file mode 100644
index 0000000..b2b06d1
--- /dev/null
+++ b/ncurses/tinfo/alloc_ttype.c
@@ -0,0 +1,506 @@
+/****************************************************************************
+ * Copyright (c) 1999-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1999-on                     *
+ ****************************************************************************/
+
+/*
+ * align_ttype.c --  functions for TERMTYPE
+ *
+ *	_nc_align_termtype()
+ *	_nc_copy_termtype()
+ *
+ */
+
+#include <curses.priv.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: alloc_ttype.c,v 1.17 2008/10/12 16:12:00 tom Exp $")
+
+#if NCURSES_XNAMES
+/*
+ * Merge the a/b lists into dst.  Both a/b are sorted (see _nc_extend_names()),
+ * so we do not have to worry about order dependencies.
+ */
+static int
+merge_names(char **dst, char **a, int na, char **b, int nb)
+{
+    int n = 0;
+    while (na > 0 && nb > 0) {
+	int cmp = strcmp(*a, *b);
+	if (cmp < 0) {
+	    dst[n++] = *a++;
+	    na--;
+	} else if (cmp > 0) {
+	    dst[n++] = *b++;
+	    nb--;
+	} else if (cmp == 0) {
+	    dst[n++] = *a;
+	    a++, b++;
+	    na--, nb--;
+	}
+    }
+    while (na-- > 0) {
+	dst[n++] = *a++;
+    }
+    while (nb-- > 0) {
+	dst[n++] = *b++;
+    }
+    DEBUG(4, ("merge_names -> %d", n));
+    return n;
+}
+
+static bool
+find_name(char **table, int length, char *name)
+{
+    while (length-- > 0) {
+	if (!strcmp(*table++, name)) {
+	    DEBUG(4, ("found name '%s'", name));
+	    return TRUE;
+	}
+    }
+    DEBUG(4, ("did not find name '%s'", name));
+    return FALSE;
+}
+
+static void
+realign_data(TERMTYPE *to, char **ext_Names,
+	     int ext_Booleans,
+	     int ext_Numbers,
+	     int ext_Strings)
+{
+    int n, m, base;
+    int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings);
+
+    if (to->ext_Booleans != ext_Booleans) {
+	to->num_Booleans += (ext_Booleans - to->ext_Booleans);
+	to->Booleans = typeRealloc(NCURSES_SBOOL, to->num_Booleans, to->Booleans);
+	for (n = to->ext_Booleans - 1,
+	     m = ext_Booleans - 1,
+	     base = to->num_Booleans - (m + 1); m >= 0; m--) {
+	    if (find_name(to->ext_Names, limit, ext_Names[m])) {
+		to->Booleans[base + m] = to->Booleans[base + n--];
+	    } else {
+		to->Booleans[base + m] = FALSE;
+	    }
+	}
+	to->ext_Booleans = ext_Booleans;
+    }
+    if (to->ext_Numbers != ext_Numbers) {
+	to->num_Numbers += (ext_Numbers - to->ext_Numbers);
+	to->Numbers = typeRealloc(short, to->num_Numbers, to->Numbers);
+	for (n = to->ext_Numbers - 1,
+	     m = ext_Numbers - 1,
+	     base = to->num_Numbers - (m + 1); m >= 0; m--) {
+	    if (find_name(to->ext_Names, limit, ext_Names[m + ext_Booleans])) {
+		to->Numbers[base + m] = to->Numbers[base + n--];
+	    } else {
+		to->Numbers[base + m] = ABSENT_NUMERIC;
+	    }
+	}
+	to->ext_Numbers = ext_Numbers;
+    }
+    if (to->ext_Strings != ext_Strings) {
+	to->num_Strings += (ext_Strings - to->ext_Strings);
+	to->Strings = typeRealloc(char *, to->num_Strings, to->Strings);
+	for (n = to->ext_Strings - 1,
+	     m = ext_Strings - 1,
+	     base = to->num_Strings - (m + 1); m >= 0; m--) {
+	    if (find_name(to->ext_Names, limit, ext_Names[m + ext_Booleans + ext_Numbers])) {
+		to->Strings[base + m] = to->Strings[base + n--];
+	    } else {
+		to->Strings[base + m] = ABSENT_STRING;
+	    }
+	}
+	to->ext_Strings = ext_Strings;
+    }
+}
+
+/*
+ * Returns the first index in ext_Names[] for the given token-type
+ */
+static int
+_nc_first_ext_name(TERMTYPE *tp, int token_type)
+{
+    int first;
+
+    switch (token_type) {
+    case BOOLEAN:
+	first = 0;
+	break;
+    case NUMBER:
+	first = tp->ext_Booleans;
+	break;
+    case STRING:
+	first = tp->ext_Booleans + tp->ext_Numbers;
+	break;
+    default:
+	first = 0;
+	break;
+    }
+    return first;
+}
+
+/*
+ * Returns the last index in ext_Names[] for the given token-type
+ */
+static int
+_nc_last_ext_name(TERMTYPE *tp, int token_type)
+{
+    int last;
+
+    switch (token_type) {
+    case BOOLEAN:
+	last = tp->ext_Booleans;
+	break;
+    case NUMBER:
+	last = tp->ext_Booleans + tp->ext_Numbers;
+	break;
+    default:
+    case STRING:
+	last = NUM_EXT_NAMES(tp);
+	break;
+    }
+    return last;
+}
+
+/*
+ * Lookup an entry from extended-names, returning -1 if not found
+ */
+static int
+_nc_find_ext_name(TERMTYPE *tp, char *name, int token_type)
+{
+    unsigned j;
+    unsigned first = _nc_first_ext_name(tp, token_type);
+    unsigned last = _nc_last_ext_name(tp, token_type);
+
+    for (j = first; j < last; j++) {
+	if (!strcmp(name, tp->ext_Names[j])) {
+	    return j;
+	}
+    }
+    return -1;
+}
+
+/*
+ * Translate an index into ext_Names[] into the corresponding index into data
+ * (e.g., Booleans[]).
+ */
+static int
+_nc_ext_data_index(TERMTYPE *tp, int n, int token_type)
+{
+    switch (token_type) {
+    case BOOLEAN:
+	n += (tp->num_Booleans - tp->ext_Booleans);
+	break;
+    case NUMBER:
+	n += (tp->num_Numbers - tp->ext_Numbers)
+	    - (tp->ext_Booleans);
+	break;
+    default:
+    case STRING:
+	n += (tp->num_Strings - tp->ext_Strings)
+	    - (tp->ext_Booleans + tp->ext_Numbers);
+    }
+    return n;
+}
+
+/*
+ * Adjust tables to remove (not free) an extended name and its corresponding
+ * data.
+ */
+static bool
+_nc_del_ext_name(TERMTYPE *tp, char *name, int token_type)
+{
+    int j;
+    int first, last;
+
+    if ((first = _nc_find_ext_name(tp, name, token_type)) >= 0) {
+	last = NUM_EXT_NAMES(tp) - 1;
+	for (j = first; j < last; j++) {
+	    tp->ext_Names[j] = tp->ext_Names[j + 1];
+	}
+	first = _nc_ext_data_index(tp, first, token_type);
+	switch (token_type) {
+	case BOOLEAN:
+	    last = tp->num_Booleans - 1;
+	    for (j = first; j < last; j++)
+		tp->Booleans[j] = tp->Booleans[j + 1];
+	    tp->ext_Booleans -= 1;
+	    tp->num_Booleans -= 1;
+	    break;
+	case NUMBER:
+	    last = tp->num_Numbers - 1;
+	    for (j = first; j < last; j++)
+		tp->Numbers[j] = tp->Numbers[j + 1];
+	    tp->ext_Numbers -= 1;
+	    tp->num_Numbers -= 1;
+	    break;
+	case STRING:
+	    last = tp->num_Strings - 1;
+	    for (j = first; j < last; j++)
+		tp->Strings[j] = tp->Strings[j + 1];
+	    tp->ext_Strings -= 1;
+	    tp->num_Strings -= 1;
+	    break;
+	}
+	return TRUE;
+    }
+    return FALSE;
+}
+
+/*
+ * Adjust tables to insert an extended name, making room for new data.  The
+ * index into the corresponding data array is returned.
+ */
+static int
+_nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type)
+{
+    unsigned first = _nc_first_ext_name(tp, token_type);
+    unsigned last = _nc_last_ext_name(tp, token_type);
+    unsigned total = NUM_EXT_NAMES(tp) + 1;
+    unsigned j, k;
+
+    for (j = first; j < last; j++) {
+	int cmp = strcmp(name, tp->ext_Names[j]);
+	if (cmp == 0)
+	    /* already present */
+	    return _nc_ext_data_index(tp, (int) j, token_type);
+	if (cmp < 0) {
+	    break;
+	}
+    }
+
+    tp->ext_Names = typeRealloc(char *, total, tp->ext_Names);
+    for (k = total - 1; k > j; k--)
+	tp->ext_Names[k] = tp->ext_Names[k - 1];
+    tp->ext_Names[j] = name;
+    j = _nc_ext_data_index(tp, (int) j, token_type);
+
+    switch (token_type) {
+    case BOOLEAN:
+	tp->ext_Booleans += 1;
+	tp->num_Booleans += 1;
+	tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
+	for (k = tp->num_Booleans - 1; k > j; k--)
+	    tp->Booleans[k] = tp->Booleans[k - 1];
+	break;
+    case NUMBER:
+	tp->ext_Numbers += 1;
+	tp->num_Numbers += 1;
+	tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers);
+	for (k = tp->num_Numbers - 1; k > j; k--)
+	    tp->Numbers[k] = tp->Numbers[k - 1];
+	break;
+    case STRING:
+	tp->ext_Strings += 1;
+	tp->num_Strings += 1;
+	tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings);
+	for (k = tp->num_Strings - 1; k > j; k--)
+	    tp->Strings[k] = tp->Strings[k - 1];
+	break;
+    }
+    return j;
+}
+
+/*
+ * Look for strings that are marked cancelled, which happen to be the same name
+ * as a boolean or number.  We'll get this as a special case when we get a
+ * cancellation of a name that is inherited from another entry.
+ */
+static void
+adjust_cancels(TERMTYPE *to, TERMTYPE *from)
+{
+    int first = to->ext_Booleans + to->ext_Numbers;
+    int last = first + to->ext_Strings;
+    int j, k;
+
+    for (j = first; j < last;) {
+	char *name = to->ext_Names[j];
+	unsigned j_str = to->num_Strings - first - to->ext_Strings;
+
+	if (to->Strings[j + j_str] == CANCELLED_STRING) {
+	    if ((k = _nc_find_ext_name(from, to->ext_Names[j], BOOLEAN)) >= 0) {
+		if (_nc_del_ext_name(to, name, STRING)
+		    || _nc_del_ext_name(to, name, NUMBER)) {
+		    k = _nc_ins_ext_name(to, name, BOOLEAN);
+		    to->Booleans[k] = FALSE;
+		} else {
+		    j++;
+		}
+	    } else if ((k = _nc_find_ext_name(from, to->ext_Names[j],
+					      NUMBER)) >= 0) {
+		if (_nc_del_ext_name(to, name, STRING)
+		    || _nc_del_ext_name(to, name, BOOLEAN)) {
+		    k = _nc_ins_ext_name(to, name, NUMBER);
+		    to->Numbers[k] = CANCELLED_NUMERIC;
+		} else {
+		    j++;
+		}
+	    } else if ((k = _nc_find_ext_name(from, to->ext_Names[j],
+					      STRING)) >= 0) {
+		if (_nc_del_ext_name(to, name, NUMBER)
+		    || _nc_del_ext_name(to, name, BOOLEAN)) {
+		    k = _nc_ins_ext_name(to, name, STRING);
+		    to->Strings[k] = CANCELLED_STRING;
+		} else {
+		    j++;
+		}
+	    } else {
+		j++;
+	    }
+	} else {
+	    j++;
+	}
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
+{
+    int na = NUM_EXT_NAMES(to);
+    int nb = NUM_EXT_NAMES(from);
+    int n;
+    bool same;
+    char **ext_Names;
+    int ext_Booleans, ext_Numbers, ext_Strings;
+    bool used_ext_Names = FALSE;
+
+    DEBUG(2, ("align_termtype to(%d:%s), from(%d:%s)", na, to->term_names,
+	      nb, from->term_names));
+
+    if (na != 0 || nb != 0) {
+	if ((na == nb)		/* check if the arrays are equivalent */
+	    &&(to->ext_Booleans == from->ext_Booleans)
+	    && (to->ext_Numbers == from->ext_Numbers)
+	    && (to->ext_Strings == from->ext_Strings)) {
+	    for (n = 0, same = TRUE; n < na; n++) {
+		if (strcmp(to->ext_Names[n], from->ext_Names[n])) {
+		    same = FALSE;
+		    break;
+		}
+	    }
+	    if (same)
+		return;
+	}
+	/*
+	 * This is where we pay for having a simple extension representation. 
+	 * Allocate a new ext_Names array and merge the two ext_Names arrays
+	 * into it, updating to's counts for booleans, etc.  Fortunately we do
+	 * this only for the terminfo compiler (tic) and comparer (infocmp).
+	 */
+	ext_Names = typeMalloc(char *, na + nb);
+
+	if (to->ext_Strings && (from->ext_Booleans + from->ext_Numbers))
+	    adjust_cancels(to, from);
+
+	if (from->ext_Strings && (to->ext_Booleans + to->ext_Numbers))
+	    adjust_cancels(from, to);
+
+	ext_Booleans = merge_names(ext_Names,
+				   to->ext_Names,
+				   to->ext_Booleans,
+				   from->ext_Names,
+				   from->ext_Booleans);
+	ext_Numbers = merge_names(ext_Names + ext_Booleans,
+				  to->ext_Names
+				  + to->ext_Booleans,
+				  to->ext_Numbers,
+				  from->ext_Names
+				  + from->ext_Booleans,
+				  from->ext_Numbers);
+	ext_Strings = merge_names(ext_Names + ext_Numbers + ext_Booleans,
+				  to->ext_Names
+				  + to->ext_Booleans
+				  + to->ext_Numbers,
+				  to->ext_Strings,
+				  from->ext_Names
+				  + from->ext_Booleans
+				  + from->ext_Numbers,
+				  from->ext_Strings);
+	/*
+	 * Now we must reallocate the Booleans, etc., to allow the data to be
+	 * overlaid.
+	 */
+	if (na != (ext_Booleans + ext_Numbers + ext_Strings)) {
+	    realign_data(to, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
+	    FreeIfNeeded(to->ext_Names);
+	    to->ext_Names = ext_Names;
+	    DEBUG(2, ("realigned %d extended names for '%s' (to)",
+		      NUM_EXT_NAMES(to), to->term_names));
+	    used_ext_Names = TRUE;
+	}
+	if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) {
+	    nb = (ext_Booleans + ext_Numbers + ext_Strings);
+	    realign_data(from, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
+	    from->ext_Names = typeRealloc(char *, nb, from->ext_Names);
+	    memcpy(from->ext_Names, ext_Names, sizeof(char *) * nb);
+	    DEBUG(2, ("realigned %d extended names for '%s' (from)",
+		      NUM_EXT_NAMES(from), from->term_names));
+	}
+	if (!used_ext_Names)
+	    free(ext_Names);
+    }
+}
+#endif
+
+NCURSES_EXPORT(void)
+_nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src)
+{
+    unsigned i;
+
+    *dst = *src;		/* ...to copy the sizes and string-tables */
+    dst->Booleans = typeMalloc(NCURSES_SBOOL, NUM_BOOLEANS(dst));
+    dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst));
+    dst->Strings = typeMalloc(char *, NUM_STRINGS(dst));
+
+    /* FIXME: use memcpy for these and similar loops */
+    for_each_boolean(i, dst)
+	dst->Booleans[i] = src->Booleans[i];
+    for_each_number(i, dst)
+	dst->Numbers[i] = src->Numbers[i];
+    for_each_string(i, dst)
+	dst->Strings[i] = src->Strings[i];
+
+    /* FIXME: we probably should also copy str_table and ext_str_table,
+     * but tic and infocmp are not written to exploit that (yet).
+     */
+
+#if NCURSES_XNAMES
+    if ((i = NUM_EXT_NAMES(src)) != 0) {
+	dst->ext_Names = typeMalloc(char *, i);
+	memcpy(dst->ext_Names, src->ext_Names, i * sizeof(char *));
+    } else {
+	dst->ext_Names = 0;
+    }
+#endif
+
+}
diff --git a/ncurses/tinfo/captoinfo.c b/ncurses/tinfo/captoinfo.c
new file mode 100644
index 0000000..93300c1
--- /dev/null
+++ b/ncurses/tinfo/captoinfo.c
@@ -0,0 +1,852 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	captoinfo.c --- conversion between termcap and terminfo formats
+ *
+ *	The captoinfo() code was swiped from Ross Ridge's mytinfo package,
+ *	adapted to fit ncurses by Eric S. Raymond <esr@snark.thyrsus.com>.
+ *
+ *	There is just one entry point:
+ *
+ *	char *_nc_captoinfo(n, s, parameterized)
+ *
+ *	Convert value s for termcap string capability named n into terminfo
+ *	format.
+ *
+ *	This code recognizes all the standard 4.4BSD %-escapes:
+ *
+ *	%%       output `%'
+ *	%d       output value as in printf %d
+ *	%2       output value as in printf %2d
+ *	%3       output value as in printf %3d
+ *	%.       output value as in printf %c
+ *	%+x      add x to value, then do %.
+ *	%>xy     if value > x then add y, no output
+ *	%r       reverse order of two parameters, no output
+ *	%i       increment by one, no output
+ *	%n       exclusive-or all parameters with 0140 (Datamedia 2500)
+ *	%B       BCD (16*(value/10)) + (value%10), no output
+ *	%D       Reverse coding (value - 2*(value%16)), no output (Delta Data).
+ *
+ *	Also, %02 and %03 are accepted as synonyms for %2 and %3.
+ *
+ *	Besides all the standard termcap escapes, this translator understands
+ *	the following extended escapes:
+ *
+ *	used by GNU Emacs termcap libraries
+ *		%a[+*-/=][cp]x	GNU arithmetic.
+ *		%m		xor the first two parameters by 0177
+ *		%b		backup to previous parameter
+ *		%f		skip this parameter
+ *
+ *	used by the University of Waterloo (MFCF) termcap libraries
+ *		%-x	 subtract parameter FROM char x and output it as a char
+ *		%ax	 add the character x to parameter
+ *
+ *	If #define WATERLOO is on, also enable these translations:
+ *
+ *		%sx	 subtract parameter FROM the character x
+ *
+ *	By default, this Waterloo translations are not compiled in, because
+ *	the Waterloo %s conflicts with the way terminfo uses %s in strings for
+ *	function programming.
+ *
+ *	Note the two definitions of %a: the GNU definition is translated if the
+ *	characters after the 'a' are valid for it, otherwise the UW definition
+ *	is translated.
+ */
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <tic.h>
+
+MODULE_ID("$Id: captoinfo.c,v 1.52 2008/08/16 19:24:51 tom Exp $")
+
+#define MAX_PUSHED	16	/* max # args we can push onto the stack */
+
+static int stack[MAX_PUSHED];	/* the stack */
+static int stackptr;		/* the next empty place on the stack */
+static int onstack;		/* the top of stack */
+static int seenm;		/* seen a %m */
+static int seenn;		/* seen a %n */
+static int seenr;		/* seen a %r */
+static int param;		/* current parameter */
+static char *dp;		/* pointer to end of the converted string */
+
+static char *my_string;
+static size_t my_length;
+
+static char *
+init_string(void)
+/* initialize 'my_string', 'my_length' */
+{
+    if (my_string == 0)
+	my_string = typeMalloc(char, my_length = 256);
+    if (my_string == 0)
+	_nc_err_abort(MSG_NO_MEMORY);
+
+    *my_string = '\0';
+    return my_string;
+}
+
+static char *
+save_string(char *d, const char *const s)
+{
+    size_t have = (d - my_string);
+    size_t need = have + strlen(s) + 2;
+    if (need > my_length) {
+	my_string = (char *) realloc(my_string, my_length = (need + need));
+	if (my_string == 0)
+	    _nc_err_abort(MSG_NO_MEMORY);
+	d = my_string + have;
+    }
+    (void) strcpy(d, s);
+    return d + strlen(d);
+}
+
+static NCURSES_INLINE char *
+save_char(char *s, int c)
+{
+    static char temp[2];
+    temp[0] = (char) c;
+    return save_string(s, temp);
+}
+
+static void
+push(void)
+/* push onstack on to the stack */
+{
+    if (stackptr >= MAX_PUSHED)
+	_nc_warning("string too complex to convert");
+    else
+	stack[stackptr++] = onstack;
+}
+
+static void
+pop(void)
+/* pop the top of the stack into onstack */
+{
+    if (stackptr == 0) {
+	if (onstack == 0)
+	    _nc_warning("I'm confused");
+	else
+	    onstack = 0;
+    } else
+	onstack = stack[--stackptr];
+    param++;
+}
+
+static int
+cvtchar(register const char *sp)
+/* convert a character to a terminfo push */
+{
+    unsigned char c = 0;
+    int len;
+
+    switch (*sp) {
+    case '\\':
+	switch (*++sp) {
+	case '\'':
+	case '$':
+	case '\\':
+	case '%':
+	    c = (unsigned char) (*sp);
+	    len = 2;
+	    break;
+	case '\0':
+	    c = '\\';
+	    len = 1;
+	    break;
+	case '0':
+	case '1':
+	case '2':
+	case '3':
+	    len = 1;
+	    while (isdigit(UChar(*sp))) {
+		c = 8 * c + (*sp++ - '0');
+		len++;
+	    }
+	    break;
+	default:
+	    c = (unsigned char) (*sp);
+	    len = 2;
+	    break;
+	}
+	break;
+    case '^':
+	c = (*++sp & 0x1f);
+	len = 2;
+	break;
+    default:
+	c = (unsigned char) (*sp);
+	len = 1;
+    }
+    if (isgraph(c) && c != ',' && c != '\'' && c != '\\' && c != ':') {
+	dp = save_string(dp, "%\'");
+	dp = save_char(dp, c);
+	dp = save_char(dp, '\'');
+    } else {
+	dp = save_string(dp, "%{");
+	if (c > 99)
+	    dp = save_char(dp, c / 100 + '0');
+	if (c > 9)
+	    dp = save_char(dp, ((int) (c / 10)) % 10 + '0');
+	dp = save_char(dp, c % 10 + '0');
+	dp = save_char(dp, '}');
+    }
+    return len;
+}
+
+static void
+getparm(int parm, int n)
+/* push n copies of param on the terminfo stack if not already there */
+{
+    if (seenr) {
+	if (parm == 1)
+	    parm = 2;
+	else if (parm == 2)
+	    parm = 1;
+    }
+    if (onstack == parm) {
+	if (n > 1) {
+	    _nc_warning("string may not be optimal");
+	    dp = save_string(dp, "%Pa");
+	    while (n--) {
+		dp = save_string(dp, "%ga");
+	    }
+	}
+	return;
+    }
+    if (onstack != 0)
+	push();
+
+    onstack = parm;
+
+    while (n--) {
+	dp = save_string(dp, "%p");
+	dp = save_char(dp, '0' + parm);
+    }
+
+    if (seenn && parm < 3) {
+	dp = save_string(dp, "%{96}%^");
+    }
+
+    if (seenm && parm < 3) {
+	dp = save_string(dp, "%{127}%^");
+    }
+}
+
+/*
+ * Convert a termcap string to terminfo format.
+ * 'cap' is the relevant terminfo capability index.
+ * 's' is the string value of the capability.
+ * 'parameterized' tells what type of translations to do:
+ *	% translations if 1
+ *	pad translations if >=0
+ */
+NCURSES_EXPORT(char *)
+_nc_captoinfo(const char *cap, const char *s, int const parameterized)
+{
+    const char *capstart;
+
+    stackptr = 0;
+    onstack = 0;
+    seenm = 0;
+    seenn = 0;
+    seenr = 0;
+    param = 1;
+
+    dp = init_string();
+
+    /* skip the initial padding (if we haven't been told not to) */
+    capstart = 0;
+    if (s == 0)
+	s = "";
+    if (parameterized >= 0 && isdigit(UChar(*s)))
+	for (capstart = s;; s++)
+	    if (!(isdigit(UChar(*s)) || *s == '*' || *s == '.'))
+		break;
+
+    while (*s != '\0') {
+	switch (*s) {
+	case '%':
+	    s++;
+	    if (parameterized < 1) {
+		dp = save_char(dp, '%');
+		break;
+	    }
+	    switch (*s++) {
+	    case '%':
+		dp = save_char(dp, '%');
+		break;
+	    case 'r':
+		if (seenr++ == 1) {
+		    _nc_warning("saw %%r twice in %s", cap);
+		}
+		break;
+	    case 'm':
+		if (seenm++ == 1) {
+		    _nc_warning("saw %%m twice in %s", cap);
+		}
+		break;
+	    case 'n':
+		if (seenn++ == 1) {
+		    _nc_warning("saw %%n twice in %s", cap);
+		}
+		break;
+	    case 'i':
+		dp = save_string(dp, "%i");
+		break;
+	    case '6':
+	    case 'B':
+		getparm(param, 1);
+		dp = save_string(dp, "%{10}%/%{16}%*");
+		getparm(param, 1);
+		dp = save_string(dp, "%{10}%m%+");
+		break;
+	    case '8':
+	    case 'D':
+		getparm(param, 2);
+		dp = save_string(dp, "%{2}%*%-");
+		break;
+	    case '>':
+		getparm(param, 2);
+		/* %?%{x}%>%t%{y}%+%; */
+		dp = save_string(dp, "%?");
+		s += cvtchar(s);
+		dp = save_string(dp, "%>%t");
+		s += cvtchar(s);
+		dp = save_string(dp, "%+%;");
+		break;
+	    case 'a':
+		if ((*s == '=' || *s == '+' || *s == '-'
+		     || *s == '*' || *s == '/')
+		    && (s[1] == 'p' || s[1] == 'c')
+		    && s[2] != '\0') {
+		    int l;
+		    l = 2;
+		    if (*s != '=')
+			getparm(param, 1);
+		    if (s[1] == 'p') {
+			getparm(param + s[2] - '@', 1);
+			if (param != onstack) {
+			    pop();
+			    param--;
+			}
+			l++;
+		    } else
+			l += cvtchar(s + 2);
+		    switch (*s) {
+		    case '+':
+			dp = save_string(dp, "%+");
+			break;
+		    case '-':
+			dp = save_string(dp, "%-");
+			break;
+		    case '*':
+			dp = save_string(dp, "%*");
+			break;
+		    case '/':
+			dp = save_string(dp, "%/");
+			break;
+		    case '=':
+			if (seenr) {
+			    if (param == 1)
+				onstack = 2;
+			    else if (param == 2)
+				onstack = 1;
+			    else
+				onstack = param;
+			} else
+			    onstack = param;
+			break;
+		    }
+		    s += l;
+		    break;
+		}
+		getparm(param, 1);
+		s += cvtchar(s);
+		dp = save_string(dp, "%+");
+		break;
+	    case '+':
+		getparm(param, 1);
+		s += cvtchar(s);
+		dp = save_string(dp, "%+%c");
+		pop();
+		break;
+	    case 's':
+#ifdef WATERLOO
+		s += cvtchar(s);
+		getparm(param, 1);
+		dp = save_string(dp, "%-");
+#else
+		getparm(param, 1);
+		dp = save_string(dp, "%s");
+		pop();
+#endif /* WATERLOO */
+		break;
+	    case '-':
+		s += cvtchar(s);
+		getparm(param, 1);
+		dp = save_string(dp, "%-%c");
+		pop();
+		break;
+	    case '.':
+		getparm(param, 1);
+		dp = save_string(dp, "%c");
+		pop();
+		break;
+	    case '0':		/* not clear any of the historical termcaps did this */
+		if (*s == '3')
+		    goto see03;
+		else if (*s != '2')
+		    goto invalid;
+		/* FALLTHRU */
+	    case '2':
+		getparm(param, 1);
+		dp = save_string(dp, "%2d");
+		pop();
+		break;
+	    case '3':
+	      see03:
+		getparm(param, 1);
+		dp = save_string(dp, "%3d");
+		pop();
+		break;
+	    case 'd':
+		getparm(param, 1);
+		dp = save_string(dp, "%d");
+		pop();
+		break;
+	    case 'f':
+		param++;
+		break;
+	    case 'b':
+		param--;
+		break;
+	    case '\\':
+		dp = save_string(dp, "%\\");
+		break;
+	    default:
+	      invalid:
+		dp = save_char(dp, '%');
+		s--;
+		_nc_warning("unknown %% code %s (%#x) in %s",
+			    unctrl((chtype) *s), UChar(*s), cap);
+		break;
+	    }
+	    break;
+#ifdef REVISIBILIZE
+	case '\\':
+	    dp = save_char(dp, *s++);
+	    dp = save_char(dp, *s++);
+	    break;
+	case '\n':
+	    dp = save_string(dp, "\\n");
+	    s++;
+	    break;
+	case '\t':
+	    dp = save_string(dp, "\\t");
+	    s++;
+	    break;
+	case '\r':
+	    dp = save_string(dp, "\\r");
+	    s++;
+	    break;
+	case '\200':
+	    dp = save_string(dp, "\\0");
+	    s++;
+	    break;
+	case '\f':
+	    dp = save_string(dp, "\\f");
+	    s++;
+	    break;
+	case '\b':
+	    dp = save_string(dp, "\\b");
+	    s++;
+	    break;
+	case ' ':
+	    dp = save_string(dp, "\\s");
+	    s++;
+	    break;
+	case '^':
+	    dp = save_string(dp, "\\^");
+	    s++;
+	    break;
+	case ':':
+	    dp = save_string(dp, "\\:");
+	    s++;
+	    break;
+	case ',':
+	    dp = save_string(dp, "\\,");
+	    s++;
+	    break;
+	default:
+	    if (*s == '\033') {
+		dp = save_string(dp, "\\E");
+		s++;
+	    } else if (*s > 0 && *s < 32) {
+		dp = save_char(dp, '^');
+		dp = save_char(dp, *s + '@');
+		s++;
+	    } else if (*s <= 0 || *s >= 127) {
+		dp = save_char(dp, '\\');
+		dp = save_char(dp, ((*s & 0300) >> 6) + '0');
+		dp = save_char(dp, ((*s & 0070) >> 3) + '0');
+		dp = save_char(dp, (*s & 0007) + '0');
+		s++;
+	    } else
+		dp = save_char(dp, *s++);
+	    break;
+#else
+	default:
+	    dp = save_char(dp, *s++);
+	    break;
+#endif
+	}
+    }
+
+    /*
+     * Now, if we stripped off some leading padding, add it at the end
+     * of the string as mandatory padding.
+     */
+    if (capstart) {
+	dp = save_string(dp, "$<");
+	for (s = capstart;; s++)
+	    if (isdigit(UChar(*s)) || *s == '*' || *s == '.')
+		dp = save_char(dp, *s);
+	    else
+		break;
+	dp = save_string(dp, "/>");
+    }
+
+    (void) save_char(dp, '\0');
+    return (my_string);
+}
+
+/*
+ * Check for an expression that corresponds to "%B" (BCD):
+ *	(parameter / 10) * 16 + (parameter % 10)
+ */
+static int
+bcd_expression(const char *str)
+{
+    /* leave this non-const for HPUX */
+    static char fmt[] = "%%p%c%%{10}%%/%%{16}%%*%%p%c%%{10}%%m%%+";
+    int len = 0;
+    char ch1, ch2;
+
+    if (sscanf(str, fmt, &ch1, &ch2) == 2
+	&& isdigit(UChar(ch1))
+	&& isdigit(UChar(ch2))
+	&& (ch1 == ch2)) {
+	len = 28;
+#ifndef NDEBUG
+	{
+	    char buffer[80];
+	    int tst;
+	    sprintf(buffer, fmt, ch1, ch2);
+	    tst = strlen(buffer) - 1;
+	    assert(len == tst);
+	}
+#endif
+    }
+    return len;
+}
+
+static char *
+save_tc_char(char *bufptr, int c1)
+{
+    char temp[80];
+
+    if (is7bits(c1) && isprint(c1)) {
+	if (c1 == ':' || c1 == '\\')
+	    bufptr = save_char(bufptr, '\\');
+	bufptr = save_char(bufptr, c1);
+    } else {
+	if (c1 == (c1 & 0x1f))	/* iscntrl() returns T on 255 */
+	    (void) strcpy(temp, unctrl((chtype) c1));
+	else
+	    (void) sprintf(temp, "\\%03o", c1);
+	bufptr = save_string(bufptr, temp);
+    }
+    return bufptr;
+}
+
+static char *
+save_tc_inequality(char *bufptr, int c1, int c2)
+{
+    bufptr = save_string(bufptr, "%>");
+    bufptr = save_tc_char(bufptr, c1);
+    bufptr = save_tc_char(bufptr, c2);
+    return bufptr;
+}
+
+/*
+ * Here are the capabilities infotocap assumes it can translate to:
+ *
+ *     %%       output `%'
+ *     %d       output value as in printf %d
+ *     %2       output value as in printf %2d
+ *     %3       output value as in printf %3d
+ *     %.       output value as in printf %c
+ *     %+c      add character c to value, then do %.
+ *     %>xy     if value > x then add y, no output
+ *     %r       reverse order of two parameters, no output
+ *     %i       increment by one, no output
+ *     %n       exclusive-or all parameters with 0140 (Datamedia 2500)
+ *     %B       BCD (16*(value/10)) + (value%10), no output
+ *     %D       Reverse coding (value - 2*(value%16)), no output (Delta Data).
+ *     %m       exclusive-or all parameters with 0177 (not in 4.4BSD)
+ */
+
+/*
+ * Convert a terminfo string to termcap format.  Parameters are as in
+ * _nc_captoinfo().
+ */
+NCURSES_EXPORT(char *)
+_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameterized)
+{
+    int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0;
+    const char *padding;
+    const char *trimmed = 0;
+    char ch1 = 0, ch2 = 0;
+    char *bufptr = init_string();
+    int len;
+    bool syntax_error = FALSE;
+
+    /* we may have to move some trailing mandatory padding up front */
+    padding = str + strlen(str) - 1;
+    if (padding > str && *padding == '>' && *--padding == '/') {
+	--padding;
+	while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*')
+	    padding--;
+	if (padding > str && *padding == '<' && *--padding == '$')
+	    trimmed = padding;
+	padding += 2;
+
+	while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*')
+	    bufptr = save_char(bufptr, *padding++);
+    }
+
+    for (; *str && str != trimmed; str++) {
+	int c1, c2;
+	char *cp = 0;
+
+	if (str[0] == '\\' && (str[1] == '^' || str[1] == ',')) {
+	    bufptr = save_char(bufptr, *++str);
+	} else if (str[0] == '$' && str[1] == '<') {	/* discard padding */
+	    str += 2;
+	    while (isdigit(UChar(*str))
+		   || *str == '.'
+		   || *str == '*'
+		   || *str == '/'
+		   || *str == '>')
+		str++;
+	    --str;
+	} else if (str[0] == '%' && str[1] == '%') {	/* escaped '%' */
+	    bufptr = save_string(bufptr, "%%");
+	    ++str;
+	} else if (*str != '%' || (parameterized < 1)) {
+	    bufptr = save_char(bufptr, *str);
+	} else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) {
+	    str = strchr(str, ';');
+	    bufptr = save_tc_inequality(bufptr, c1, c2);
+	} else if (sscanf(str, "%%?%%{%d}%%>%%t%%'%c'%%+%%;", &c1, &ch2) == 2) {
+	    str = strchr(str, ';');
+	    bufptr = save_tc_inequality(bufptr, c1, c2);
+	} else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1, &c2) == 2) {
+	    str = strchr(str, ';');
+	    bufptr = save_tc_inequality(bufptr, c1, c2);
+	} else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2) {
+	    str = strchr(str, ';');
+	    bufptr = save_tc_inequality(bufptr, c1, c2);
+	} else if ((len = bcd_expression(str)) != 0) {
+	    str += len;
+	    bufptr = save_string(bufptr, "%B");
+	} else if ((sscanf(str, "%%{%d}%%+%%c", &c1) == 1
+		    || sscanf(str, "%%'%c'%%+%%c", &ch1) == 1)
+		   && (cp = strchr(str, '+'))) {
+	    str = cp + 2;
+	    bufptr = save_string(bufptr, "%+");
+
+	    if (ch1)
+		c1 = ch1;
+	    bufptr = save_tc_char(bufptr, c1);
+	}
+	/* FIXME: this "works" for 'delta' */
+	else if (strncmp(str, "%{2}%*%-", 8) == 0) {
+	    str += 7;
+	    bufptr = save_string(bufptr, "%D");
+	} else if (strncmp(str, "%{96}%^", 7) == 0) {
+	    str += 6;
+	    if (saw_m++ == 0) {
+		bufptr = save_string(bufptr, "%n");
+	    }
+	} else if (strncmp(str, "%{127}%^", 8) == 0) {
+	    str += 7;
+	    if (saw_n++ == 0) {
+		bufptr = save_string(bufptr, "%m");
+	    }
+	} else {		/* cm-style format element */
+	    str++;
+	    switch (*str) {
+	    case '%':
+		bufptr = save_char(bufptr, '%');
+		break;
+
+	    case '0':
+	    case '1':
+	    case '2':
+	    case '3':
+	    case '4':
+	    case '5':
+	    case '6':
+	    case '7':
+	    case '8':
+	    case '9':
+		bufptr = save_char(bufptr, '%');
+		while (isdigit(UChar(*str)))
+		    bufptr = save_char(bufptr, *str++);
+		if (strchr("doxX.", *str)) {
+		    if (*str != 'd')	/* termcap doesn't have octal, hex */
+			return 0;
+		}
+		break;
+
+	    case 'd':
+		bufptr = save_string(bufptr, "%d");
+		break;
+
+	    case 'c':
+		bufptr = save_string(bufptr, "%.");
+		break;
+
+		/*
+		 * %s isn't in termcap, but it's convenient to pass it through
+		 * so we can represent things like terminfo pfkey strings in
+		 * termcap notation.
+		 */
+	    case 's':
+		bufptr = save_string(bufptr, "%s");
+		break;
+
+	    case 'p':
+		str++;
+		if (*str == '1')
+		    seenone = 1;
+		else if (*str == '2') {
+		    if (!seenone && !seentwo) {
+			bufptr = save_string(bufptr, "%r");
+			seentwo++;
+		    }
+		} else if (*str >= '3')
+		    return (0);
+		break;
+
+	    case 'i':
+		bufptr = save_string(bufptr, "%i");
+		break;
+
+	    default:
+		bufptr = save_char(bufptr, *str);
+		syntax_error = TRUE;
+		break;
+	    }			/* endswitch (*str) */
+	}			/* endelse (*str == '%') */
+
+	/*
+	 * 'str' always points to the end of what was scanned in this step,
+	 * but that may not be the end of the string.
+	 */
+	assert(str != 0);
+	if (*str == '\0')
+	    break;
+
+    }				/* endwhile (*str) */
+
+    return (syntax_error ? NULL : my_string);
+}
+
+#ifdef MAIN
+
+int curr_line;
+
+int
+main(int argc, char *argv[])
+{
+    int c, tc = FALSE;
+
+    while ((c = getopt(argc, argv, "c")) != EOF)
+	switch (c) {
+	case 'c':
+	    tc = TRUE;
+	    break;
+	}
+
+    curr_line = 0;
+    for (;;) {
+	char buf[BUFSIZ];
+
+	++curr_line;
+	if (fgets(buf, sizeof(buf), stdin) == 0)
+	    break;
+	buf[strlen(buf) - 1] = '\0';
+	_nc_set_source(buf);
+
+	if (tc) {
+	    char *cp = _nc_infotocap("to termcap", buf, 1);
+
+	    if (cp)
+		(void) fputs(cp, stdout);
+	} else
+	    (void) fputs(_nc_captoinfo("to terminfo", buf, 1), stdout);
+	(void) putchar('\n');
+    }
+    return (0);
+}
+#endif /* MAIN */
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_captoinfo_leaks(void)
+{
+    if (my_string != 0) {
+	FreeAndNull(my_string);
+    }
+    my_length = 0;
+}
+#endif
diff --git a/ncurses/tinfo/comp_error.c b/ncurses/tinfo/comp_error.c
new file mode 100644
index 0000000..56c362a
--- /dev/null
+++ b/ncurses/tinfo/comp_error.c
@@ -0,0 +1,153 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	comp_error.c -- Error message routines
+ *
+ */
+
+#include <curses.priv.h>
+
+#include <tic.h>
+
+MODULE_ID("$Id: comp_error.c,v 1.31 2007/04/21 23:38:32 tom Exp $")
+
+NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
+NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
+NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */
+
+#define SourceName	_nc_globals.comp_sourcename
+#define TermType	_nc_globals.comp_termtype
+
+NCURSES_EXPORT(const char *)
+_nc_get_source(void)
+{
+    return SourceName;
+}
+
+NCURSES_EXPORT(void)
+_nc_set_source(const char *const name)
+{
+    SourceName = name;
+}
+
+NCURSES_EXPORT(void)
+_nc_set_type(const char *const name)
+{
+    if (TermType == 0)
+	TermType = typeMalloc(char, MAX_NAME_SIZE + 1);
+    if (TermType != 0) {
+	TermType[0] = '\0';
+	if (name)
+	    strncat(TermType, name, MAX_NAME_SIZE);
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_get_type(char *name)
+{
+#if NO_LEAKS
+    if (name == 0 && TermType != 0) {
+	FreeAndNull(TermType);
+	return;
+    }
+#endif
+    if (name != 0)
+	strcpy(name, TermType != 0 ? TermType : "");
+}
+
+static NCURSES_INLINE void
+where_is_problem(void)
+{
+    fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?");
+    if (_nc_curr_line >= 0)
+	fprintf(stderr, ", line %d", _nc_curr_line);
+    if (_nc_curr_col >= 0)
+	fprintf(stderr, ", col %d", _nc_curr_col);
+    if (TermType != 0 && TermType[0] != '\0')
+	fprintf(stderr, ", terminal '%s'", TermType);
+    fputc(':', stderr);
+    fputc(' ', stderr);
+}
+
+NCURSES_EXPORT(void)
+_nc_warning(const char *const fmt,...)
+{
+    va_list argp;
+
+    if (_nc_suppress_warnings)
+	return;
+
+    where_is_problem();
+    va_start(argp, fmt);
+    vfprintf(stderr, fmt, argp);
+    fprintf(stderr, "\n");
+    va_end(argp);
+}
+
+NCURSES_EXPORT(void)
+_nc_err_abort(const char *const fmt,...)
+{
+    va_list argp;
+
+    where_is_problem();
+    va_start(argp, fmt);
+    vfprintf(stderr, fmt, argp);
+    fprintf(stderr, "\n");
+    va_end(argp);
+    exit(EXIT_FAILURE);
+}
+
+NCURSES_EXPORT(void)
+_nc_syserr_abort(const char *const fmt,...)
+{
+    va_list argp;
+
+    where_is_problem();
+    va_start(argp, fmt);
+    vfprintf(stderr, fmt, argp);
+    fprintf(stderr, "\n");
+    va_end(argp);
+
+    /* If we're debugging, try to show where the problem occurred - this
+     * will dump core.
+     */
+#if defined(TRACE) || !defined(NDEBUG)
+    abort();
+#else
+    /* Dumping core in production code is not a good idea.
+     */
+    exit(EXIT_FAILURE);
+#endif
+}
diff --git a/ncurses/tinfo/comp_expand.c b/ncurses/tinfo/comp_expand.c
new file mode 100644
index 0000000..6e79a92
--- /dev/null
+++ b/ncurses/tinfo/comp_expand.c
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1998                        *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <tic.h>
+
+MODULE_ID("$Id: comp_expand.c,v 1.20 2008/08/16 19:29:42 tom Exp $")
+
+static int
+trailing_spaces(const char *src)
+{
+    while (*src == ' ')
+	src++;
+    return *src == 0;
+}
+
+/* this deals with differences over whether 0x7f and 0x80..0x9f are controls */
+#define REALCTL(s) (UChar(*(s)) < 127 && iscntrl(UChar(*(s))))
+#define REALPRINT(s) (UChar(*(s)) < 127 && isprint(UChar(*(s))))
+
+NCURSES_EXPORT(char *)
+_nc_tic_expand(const char *srcp, bool tic_format, int numbers)
+{
+    static char *buffer;
+    static size_t length;
+
+    int bufp;
+    const char *str = VALID_STRING(srcp) ? srcp : "\0\0";
+    bool islong = (strlen(str) > 3);
+    size_t need = (2 + strlen(str)) * 4;
+    int ch;
+
+#if NO_LEAKS
+    if (srcp == 0) {
+	if (buffer != 0) {
+	    FreeAndNull(buffer);
+	    length = 0;
+	}
+	return 0;
+    }
+#endif
+    if (buffer == 0 || need > length) {
+	if ((buffer = typeRealloc(char, length = need, buffer)) == 0)
+	      return 0;
+    }
+
+    bufp = 0;
+    while ((ch = UChar(*str)) != 0) {
+	if (ch == '%' && REALPRINT(str + 1)) {
+	    buffer[bufp++] = *str++;
+	    /*
+	     * Though the character literals are more compact, most
+	     * terminal descriptions use numbers and are not easy
+	     * to read in character-literal form.
+	     */
+	    switch (numbers) {
+	    case -1:
+		if (str[0] == S_QUOTE
+		    && str[1] != '\\'
+		    && REALPRINT(str + 1)
+		    && str[2] == S_QUOTE) {
+		    sprintf(buffer + bufp, "{%d}", str[1]);
+		    bufp += strlen(buffer + bufp);
+		    str += 2;
+		} else {
+		    buffer[bufp++] = *str;
+		}
+		break;
+		/*
+		 * If we have a "%{number}", try to translate it into
+		 * a "%'char'" form, since that will run a little faster
+		 * when we're interpreting it.  Also, having one form
+		 * for the constant makes it simpler to compare terminal
+		 * descriptions.
+		 */
+	    case 1:
+		if (str[0] == L_BRACE
+		    && isdigit(UChar(str[1]))) {
+		    char *dst = 0;
+		    long value = strtol(str + 1, &dst, 0);
+		    if (dst != 0
+			&& *dst == R_BRACE
+			&& value < 127
+			&& value != '\\'	/* FIXME */
+			&& isprint((int) value)) {
+			ch = (int) value;
+			buffer[bufp++] = S_QUOTE;
+			if (ch == '\\'
+			    || ch == S_QUOTE)
+			    buffer[bufp++] = '\\';
+			buffer[bufp++] = (char) ch;
+			buffer[bufp++] = S_QUOTE;
+			str = dst;
+		    } else {
+			buffer[bufp++] = *str;
+		    }
+		} else {
+		    buffer[bufp++] = *str;
+		}
+		break;
+	    default:
+		buffer[bufp++] = *str;
+		break;
+	    }
+	} else if (ch == 128) {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = '0';
+	} else if (ch == '\033') {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = 'E';
+	} else if (ch == '\\' && tic_format && (str == srcp || str[-1] != '^')) {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = '\\';
+	} else if (ch == ' ' && tic_format && (str == srcp ||
+					       trailing_spaces(str))) {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = 's';
+	} else if ((ch == ',' || ch == ':' || ch == '^') && tic_format) {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = (char) ch;
+	} else if (REALPRINT(str)
+		   && (ch != ','
+		       && ch != ':'
+		       && !(ch == '!' && !tic_format)
+		       && ch != '^'))
+	    buffer[bufp++] = (char) ch;
+#if 0				/* FIXME: this would be more readable (in fact the whole 'islong' logic should be removed) */
+	else if (ch == '\b') {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = 'b';
+	} else if (ch == '\f') {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = 'f';
+	} else if (ch == '\t' && islong) {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = 't';
+	}
+#endif
+	else if (ch == '\r' && (islong || (strlen(srcp) > 2 && str[1] == '\0'))) {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = 'r';
+	} else if (ch == '\n' && islong) {
+	    buffer[bufp++] = '\\';
+	    buffer[bufp++] = 'n';
+	}
+#define UnCtl(c) ((c) + '@')
+	else if (REALCTL(str) && ch != '\\'
+		 && (!islong || isdigit(UChar(str[1])))) {
+	    (void) sprintf(&buffer[bufp], "^%c", UnCtl(ch));
+	    bufp += 2;
+	} else {
+	    (void) sprintf(&buffer[bufp], "\\%03o", ch);
+	    bufp += 4;
+	}
+
+	str++;
+    }
+
+    buffer[bufp] = '\0';
+    return (buffer);
+}
diff --git a/ncurses/tinfo/comp_hash.c b/ncurses/tinfo/comp_hash.c
new file mode 100644
index 0000000..b7fbd06
--- /dev/null
+++ b/ncurses/tinfo/comp_hash.c
@@ -0,0 +1,370 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	comp_hash.c --- Routines to deal with the hashtable of capability
+ *			names.
+ *
+ */
+
+#define USE_TERMLIB 1
+#include <curses.priv.h>
+
+#include <tic.h>
+#include <hashsize.h>
+
+#ifdef MAIN_PROGRAM
+#include <ctype.h>
+#undef  DEBUG
+#define DEBUG(level, params)	/*nothing */
+#endif
+
+MODULE_ID("$Id: comp_hash.c,v 1.36 2008/08/16 17:06:53 tom Exp $")
+
+static int hash_function(const char *);
+
+/*
+ *	_nc_make_hash_table()
+ *
+ *	Takes the entries in table[] and hashes them into hash_table[]
+ *	by name.  There are CAPTABSIZE entries in table[] and HASHTABSIZE
+ *	slots in hash_table[].
+ *
+ */
+
+#ifdef MAIN_PROGRAM
+
+#undef MODULE_ID
+#define MODULE_ID(id)		/*nothing */
+#include <tinfo/doalloc.c>
+
+static void
+_nc_make_hash_table(struct name_table_entry *table,
+		    short *hash_table)
+{
+    short i;
+    int hashvalue;
+    int collisions = 0;
+
+    for (i = 0; i < HASHTABSIZE; i++) {
+	hash_table[i] = -1;
+    }
+    for (i = 0; i < CAPTABSIZE; i++) {
+	hashvalue = hash_function(table[i].nte_name);
+
+	if (hash_table[hashvalue] >= 0)
+	    collisions++;
+
+	if (hash_table[hashvalue] != 0)
+	    table[i].nte_link = hash_table[hashvalue];
+	hash_table[hashvalue] = i;
+    }
+
+    DEBUG(4, ("Hash table complete: %d collisions out of %d entries",
+	      collisions, CAPTABSIZE));
+}
+#endif
+
+/*
+ *	int hash_function(string)
+ *
+ *	Computes the hashing function on the given string.
+ *
+ *	The current hash function is the sum of each consectutive pair
+ *	of characters, taken as two-byte integers, mod HASHTABSIZE.
+ *
+ */
+
+static int
+hash_function(const char *string)
+{
+    long sum = 0;
+
+    DEBUG(9, ("hashing %s", string));
+    while (*string) {
+	sum += (long) (*string + (*(string + 1) << 8));
+	string++;
+    }
+
+    DEBUG(9, ("sum is %ld", sum));
+    return (int) (sum % HASHTABSIZE);
+}
+
+/*
+ *	struct name_table_entry *
+ *	find_entry(string)
+ *
+ *	Finds the entry for the given string in the hash table if present.
+ *	Returns a pointer to the entry in the table or 0 if not found.
+ *
+ */
+
+#ifndef MAIN_PROGRAM
+NCURSES_EXPORT(struct name_table_entry const *)
+_nc_find_entry(const char *string,
+	       const short *hash_table)
+{
+    int hashvalue;
+    struct name_table_entry const *ptr = 0;
+    struct name_table_entry const *real_table;
+
+    hashvalue = hash_function(string);
+
+    if (hash_table[hashvalue] >= 0) {
+	real_table = _nc_get_table(hash_table != _nc_get_hash_table(FALSE));
+	ptr = real_table + hash_table[hashvalue];
+	while (strcmp(ptr->nte_name, string) != 0) {
+	    if (ptr->nte_link < 0)
+		return 0;
+	    ptr = real_table + (ptr->nte_link + hash_table[HASHTABSIZE]);
+	}
+    }
+
+    return (ptr);
+}
+
+/*
+ *	struct name_table_entry *
+ *	find_type_entry(string, type, table)
+ *
+ *	Finds the first entry for the given name with the given type in the
+ *	given table if present (as distinct from find_entry, which finds the
+ *	the last entry regardless of type).  You can use this if you detect
+ *	a name clash.  It's slower, though.  Returns a pointer to the entry
+ *	in the table or 0 if not found.
+ */
+
+NCURSES_EXPORT(struct name_table_entry const *)
+_nc_find_type_entry(const char *string,
+		    int type,
+		    const struct name_table_entry *table)
+{
+    struct name_table_entry const *ptr;
+
+    for (ptr = table; ptr < table + CAPTABSIZE; ptr++) {
+	if (ptr->nte_type == type && strcmp(string, ptr->nte_name) == 0)
+	    return (ptr);
+    }
+
+    return ((struct name_table_entry *) NULL);
+}
+#endif
+
+#ifdef MAIN_PROGRAM
+/*
+ * This filter reads from standard input a list of tab-delimited columns,
+ * (e.g., from Caps.filtered) computes the hash-value of a specified column and
+ * writes the hashed tables to standard output.
+ *
+ * By compiling the hash table at build time, we're able to make the entire
+ * set of terminfo and termcap tables readonly (and also provide some runtime
+ * performance enhancement).
+ */
+
+#define MAX_COLUMNS BUFSIZ	/* this _has_ to be worst-case */
+
+static char **
+parse_columns(char *buffer)
+{
+    static char **list;
+
+    int col = 0;
+
+    if (list == 0 && (list = typeCalloc(char *, MAX_COLUMNS)) == 0)
+	  return (0);
+
+    if (*buffer != '#') {
+	while (*buffer != '\0') {
+	    char *s;
+	    for (s = buffer; (*s != '\0') && !isspace(UChar(*s)); s++)
+		/*EMPTY */ ;
+	    if (s != buffer) {
+		char mark = *s;
+		*s = '\0';
+		if ((s - buffer) > 1
+		    && (*buffer == '"')
+		    && (s[-1] == '"')) {	/* strip the quotes */
+		    assert(s > buffer + 1);
+		    s[-1] = '\0';
+		    buffer++;
+		}
+		list[col] = buffer;
+		col++;
+		if (mark == '\0')
+		    break;
+		while (*++s && isspace(UChar(*s)))
+		    /*EMPTY */ ;
+		buffer = s;
+	    } else
+		break;
+	}
+    }
+    return col ? list : 0;
+}
+
+int
+main(int argc, char **argv)
+{
+    struct name_table_entry *name_table = typeCalloc(struct
+						     name_table_entry, CAPTABSIZE);
+    short *hash_table = typeCalloc(short, HASHTABSIZE);
+    const char *root_name = "";
+    int column = 0;
+    int bigstring = 0;
+    int n;
+    char buffer[BUFSIZ];
+
+    static const char *typenames[] =
+    {"BOOLEAN", "NUMBER", "STRING"};
+
+    short BoolCount = 0;
+    short NumCount = 0;
+    short StrCount = 0;
+
+    /* The first argument is the column-number (starting with 0).
+     * The second is the root name of the tables to generate.
+     */
+    if (argc <= 3
+	|| (column = atoi(argv[1])) <= 0
+	|| (column >= MAX_COLUMNS)
+	|| *(root_name = argv[2]) == 0
+	|| (bigstring = atoi(argv[3])) < 0
+	|| name_table == 0
+	|| hash_table == 0) {
+	fprintf(stderr, "usage: make_hash column root_name bigstring\n");
+	exit(EXIT_FAILURE);
+    }
+
+    /*
+     * Read the table into our arrays.
+     */
+    for (n = 0; (n < CAPTABSIZE) && fgets(buffer, BUFSIZ, stdin);) {
+	char **list, *nlp = strchr(buffer, '\n');
+	if (nlp)
+	    *nlp = '\0';
+	list = parse_columns(buffer);
+	if (list == 0)		/* blank or comment */
+	    continue;
+	name_table[n].nte_link = -1;	/* end-of-hash */
+	name_table[n].nte_name = strdup(list[column]);
+	if (!strcmp(list[2], "bool")) {
+	    name_table[n].nte_type = BOOLEAN;
+	    name_table[n].nte_index = BoolCount++;
+	} else if (!strcmp(list[2], "num")) {
+	    name_table[n].nte_type = NUMBER;
+	    name_table[n].nte_index = NumCount++;
+	} else if (!strcmp(list[2], "str")) {
+	    name_table[n].nte_type = STRING;
+	    name_table[n].nte_index = StrCount++;
+	} else {
+	    fprintf(stderr, "Unknown type: %s\n", list[2]);
+	    exit(EXIT_FAILURE);
+	}
+	n++;
+    }
+    _nc_make_hash_table(name_table, hash_table);
+
+    /*
+     * Write the compiled tables to standard output
+     */
+    if (bigstring) {
+	int len = 0;
+	int nxt;
+
+	printf("static const char %s_names_text[] = \\\n", root_name);
+	for (n = 0; n < CAPTABSIZE; n++) {
+	    nxt = (int) strlen(name_table[n].nte_name) + 5;
+	    if (nxt + len > 72) {
+		printf("\\\n");
+		len = 0;
+	    }
+	    printf("\"%s\\0\" ", name_table[n].nte_name);
+	    len += nxt;
+	}
+	printf(";\n\n");
+
+	len = 0;
+	printf("static name_table_data const %s_names_data[] =\n",
+	       root_name);
+	printf("{\n");
+	for (n = 0; n < CAPTABSIZE; n++) {
+	    printf("\t{ %15d,\t%10s,\t%3d, %3d }%c\n",
+		   len,
+		   typenames[name_table[n].nte_type],
+		   name_table[n].nte_index,
+		   name_table[n].nte_link,
+		   n < CAPTABSIZE - 1 ? ',' : ' ');
+	    len += (int) strlen(name_table[n].nte_name) + 1;
+	}
+	printf("};\n\n");
+	printf("static struct name_table_entry *_nc_%s_table = 0;\n\n", root_name);
+    } else {
+
+	printf("static struct name_table_entry %s _nc_%s_table[] =\n",
+	       bigstring ? "" : "const",
+	       root_name);
+	printf("{\n");
+	for (n = 0; n < CAPTABSIZE; n++) {
+	    sprintf(buffer, "\"%s\"",
+		    name_table[n].nte_name);
+	    printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n",
+		   buffer,
+		   typenames[name_table[n].nte_type],
+		   name_table[n].nte_index,
+		   name_table[n].nte_link,
+		   n < CAPTABSIZE - 1 ? ',' : ' ');
+	}
+	printf("};\n\n");
+    }
+
+    printf("static const short _nc_%s_hash_table[%d] =\n",
+	   root_name,
+	   HASHTABSIZE + 1);
+    printf("{\n");
+    for (n = 0; n < HASHTABSIZE; n++) {
+	printf("\t%3d,\n", hash_table[n]);
+    }
+    printf("\t0\t/* base-of-table */\n");
+    printf("};\n\n");
+
+    printf("#if (BOOLCOUNT!=%d)||(NUMCOUNT!=%d)||(STRCOUNT!=%d)\n",
+	   BoolCount, NumCount, StrCount);
+    printf("#error\t--> term.h and comp_captab.c disagree about the <--\n");
+    printf("#error\t--> numbers of booleans, numbers and/or strings <--\n");
+    printf("#endif\n\n");
+
+    free(hash_table);
+    return EXIT_SUCCESS;
+}
+#endif
diff --git a/ncurses/tinfo/comp_parse.c b/ncurses/tinfo/comp_parse.c
new file mode 100644
index 0000000..3325a0d
--- /dev/null
+++ b/ncurses/tinfo/comp_parse.c
@@ -0,0 +1,491 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	comp_parse.c -- parser driver loop and use handling.
+ *
+ *	_nc_read_entry_source(FILE *, literal, bool, bool (*hook)())
+ *	_nc_resolve_uses2(void)
+ *	_nc_free_entries(void)
+ *
+ *	Use this code by calling _nc_read_entry_source() on as many source
+ *	files as you like (either terminfo or termcap syntax).  If you
+ *	want use-resolution, call _nc_resolve_uses2().  To free the list
+ *	storage, do _nc_free_entries().
+ *
+ */
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: comp_parse.c,v 1.69 2008/08/16 21:58:16 tom Exp $")
+
+static void sanity_check2(TERMTYPE *, bool);
+NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype2) (TERMTYPE *, bool) = sanity_check2;
+
+/* obsolete: 20040705 */
+static void sanity_check(TERMTYPE *);
+NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype) (TERMTYPE *) = sanity_check;
+
+static void
+enqueue(ENTRY * ep)
+/* add an entry to the in-core list */
+{
+    ENTRY *newp = _nc_copy_entry(ep);
+
+    if (newp == 0)
+	_nc_err_abort(MSG_NO_MEMORY);
+
+    newp->last = _nc_tail;
+    _nc_tail = newp;
+
+    newp->next = 0;
+    if (newp->last)
+	newp->last->next = newp;
+}
+
+static char *
+force_bar(char *dst, char *src)
+{
+    if (strchr(src, '|') == 0) {
+	size_t len = strlen(src);
+	if (len > MAX_NAME_SIZE)
+	    len = MAX_NAME_SIZE;
+	(void) strncpy(dst, src, len);
+	(void) strcpy(dst + len, "|");
+	src = dst;
+    }
+    return src;
+}
+
+NCURSES_EXPORT(bool)
+_nc_entry_match(char *n1, char *n2)
+/* do any of the aliases in a pair of terminal names match? */
+{
+    char *pstart, *qstart, *pend, *qend;
+    char nc1[MAX_NAME_SIZE + 2], nc2[MAX_NAME_SIZE + 2];
+
+    n1 = force_bar(nc1, n1);
+    n2 = force_bar(nc2, n2);
+
+    for (pstart = n1; (pend = strchr(pstart, '|')); pstart = pend + 1)
+	for (qstart = n2; (qend = strchr(qstart, '|')); qstart = qend + 1)
+	    if ((pend - pstart == qend - qstart)
+		&& memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0)
+		return (TRUE);
+
+    return (FALSE);
+}
+
+/****************************************************************************
+ *
+ * Entry compiler and resolution logic
+ *
+ ****************************************************************************/
+
+NCURSES_EXPORT(void)
+_nc_read_entry_source(FILE *fp, char *buf,
+		      int literal, bool silent,
+		      bool(*hook) (ENTRY *))
+/* slurp all entries in the given file into core */
+{
+    ENTRY thisentry;
+    bool oldsuppress = _nc_suppress_warnings;
+    int immediate = 0;
+
+    if (silent)
+	_nc_suppress_warnings = TRUE;	/* shut the lexer up, too */
+
+    _nc_reset_input(fp, buf);
+    for (;;) {
+	memset(&thisentry, 0, sizeof(thisentry));
+	if (_nc_parse_entry(&thisentry, literal, silent) == ERR)
+	    break;
+	if (!isalnum(UChar(thisentry.tterm.term_names[0])))
+	    _nc_err_abort("terminal names must start with letter or digit");
+
+	/*
+	 * This can be used for immediate compilation of entries with no "use="
+	 * references to disk.  That avoids consuming a lot of memory when the
+	 * resolution code could fetch entries off disk.
+	 */
+	if (hook != NULLHOOK && (*hook) (&thisentry)) {
+	    immediate++;
+	} else {
+	    enqueue(&thisentry);
+	    /*
+	     * The enqueued entry is copied with _nc_copy_termtype(), so we can
+	     * free some of the data from thisentry, i.e., the arrays.
+	     */
+	    FreeIfNeeded(thisentry.tterm.Booleans);
+	    FreeIfNeeded(thisentry.tterm.Numbers);
+	    FreeIfNeeded(thisentry.tterm.Strings);
+#if NCURSES_XNAMES
+	    FreeIfNeeded(thisentry.tterm.ext_Names);
+#endif
+	}
+    }
+
+    if (_nc_tail) {
+	/* set up the head pointer */
+	for (_nc_head = _nc_tail; _nc_head->last; _nc_head = _nc_head->last)
+	    continue;
+
+	DEBUG(1, ("head = %s", _nc_head->tterm.term_names));
+	DEBUG(1, ("tail = %s", _nc_tail->tterm.term_names));
+    }
+#ifdef TRACE
+    else if (!immediate)
+	DEBUG(1, ("no entries parsed"));
+#endif
+
+    _nc_suppress_warnings = oldsuppress;
+}
+
+NCURSES_EXPORT(int)
+_nc_resolve_uses2(bool fullresolve, bool literal)
+/* try to resolve all use capabilities */
+{
+    ENTRY *qp, *rp, *lastread = 0;
+    bool keepgoing;
+    unsigned i;
+    int unresolved, total_unresolved, multiples;
+
+    DEBUG(2, ("RESOLUTION BEGINNING"));
+
+    /*
+     * Check for multiple occurrences of the same name.
+     */
+    multiples = 0;
+    for_entry_list(qp) {
+	int matchcount = 0;
+
+	for_entry_list(rp) {
+	    if (qp > rp
+		&& _nc_entry_match(qp->tterm.term_names, rp->tterm.term_names)) {
+		matchcount++;
+		if (matchcount == 1) {
+		    (void) fprintf(stderr, "Name collision between %s",
+				   _nc_first_name(qp->tterm.term_names));
+		    multiples++;
+		}
+		if (matchcount >= 1)
+		    (void) fprintf(stderr, " %s", _nc_first_name(rp->tterm.term_names));
+	    }
+	}
+	if (matchcount >= 1)
+	    (void) putc('\n', stderr);
+    }
+    if (multiples > 0)
+	return (FALSE);
+
+    DEBUG(2, ("NO MULTIPLE NAME OCCURRENCES"));
+
+    /*
+     * First resolution stage: compute link pointers corresponding to names.
+     */
+    total_unresolved = 0;
+    _nc_curr_col = -1;
+    for_entry_list(qp) {
+	unresolved = 0;
+	for (i = 0; i < qp->nuses; i++) {
+	    bool foundit;
+	    char *child = _nc_first_name(qp->tterm.term_names);
+	    char *lookfor = qp->uses[i].name;
+	    long lookline = qp->uses[i].line;
+
+	    foundit = FALSE;
+
+	    _nc_set_type(child);
+
+	    /* first, try to resolve from in-core records */
+	    for_entry_list(rp) {
+		if (rp != qp
+		    && _nc_name_match(rp->tterm.term_names, lookfor, "|")) {
+		    DEBUG(2, ("%s: resolving use=%s (in core)",
+			      child, lookfor));
+
+		    qp->uses[i].link = rp;
+		    foundit = TRUE;
+		}
+	    }
+
+	    /* if that didn't work, try to merge in a compiled entry */
+	    if (!foundit) {
+		TERMTYPE thisterm;
+		char filename[PATH_MAX];
+
+		memset(&thisterm, 0, sizeof(thisterm));
+		if (_nc_read_entry(lookfor, filename, &thisterm) == 1) {
+		    DEBUG(2, ("%s: resolving use=%s (compiled)",
+			      child, lookfor));
+
+		    rp = typeMalloc(ENTRY, 1);
+		    if (rp == 0)
+			_nc_err_abort(MSG_NO_MEMORY);
+		    rp->tterm = thisterm;
+		    rp->nuses = 0;
+		    rp->next = lastread;
+		    lastread = rp;
+
+		    qp->uses[i].link = rp;
+		    foundit = TRUE;
+		}
+	    }
+
+	    /* no good, mark this one unresolvable and complain */
+	    if (!foundit) {
+		unresolved++;
+		total_unresolved++;
+
+		_nc_curr_line = lookline;
+		_nc_warning("resolution of use=%s failed", lookfor);
+		qp->uses[i].link = 0;
+	    }
+	}
+    }
+    if (total_unresolved) {
+	/* free entries read in off disk */
+	_nc_free_entries(lastread);
+	return (FALSE);
+    }
+
+    DEBUG(2, ("NAME RESOLUTION COMPLETED OK"));
+
+    /*
+     * OK, at this point all (char *) references in `name' members
+     * have been successfully converted to (ENTRY *) pointers in
+     * `link' members.  Time to do the actual merges.
+     */
+    if (fullresolve) {
+	do {
+	    TERMTYPE merged;
+
+	    keepgoing = FALSE;
+
+	    for_entry_list(qp) {
+		if (qp->nuses > 0) {
+		    DEBUG(2, ("%s: attempting merge",
+			      _nc_first_name(qp->tterm.term_names)));
+		    /*
+		     * If any of the use entries we're looking for is
+		     * incomplete, punt.  We'll catch this entry on a
+		     * subsequent pass.
+		     */
+		    for (i = 0; i < qp->nuses; i++)
+			if (qp->uses[i].link->nuses) {
+			    DEBUG(2, ("%s: use entry %d unresolved",
+				      _nc_first_name(qp->tterm.term_names), i));
+			    goto incomplete;
+			}
+
+		    /*
+		     * First, make sure there is no garbage in the
+		     * merge block.  As a side effect, copy into
+		     * the merged entry the name field and string
+		     * table pointer.
+		     */
+		    _nc_copy_termtype(&merged, &(qp->tterm));
+
+		    /*
+		     * Now merge in each use entry in the proper
+		     * (reverse) order.
+		     */
+		    for (; qp->nuses; qp->nuses--)
+			_nc_merge_entry(&merged,
+					&qp->uses[qp->nuses - 1].link->tterm);
+
+		    /*
+		     * Now merge in the original entry.
+		     */
+		    _nc_merge_entry(&merged, &qp->tterm);
+
+		    /*
+		     * Replace the original entry with the merged one.
+		     */
+		    FreeIfNeeded(qp->tterm.Booleans);
+		    FreeIfNeeded(qp->tterm.Numbers);
+		    FreeIfNeeded(qp->tterm.Strings);
+#if NCURSES_XNAMES
+		    FreeIfNeeded(qp->tterm.ext_Names);
+#endif
+		    qp->tterm = merged;
+		    _nc_wrap_entry(qp, TRUE);
+
+		    /*
+		     * We know every entry is resolvable because name resolution
+		     * didn't bomb.  So go back for another pass.
+		     */
+		    /* FALLTHRU */
+		  incomplete:
+		    keepgoing = TRUE;
+		}
+	    }
+	} while
+	    (keepgoing);
+
+	DEBUG(2, ("MERGES COMPLETED OK"));
+    }
+
+    /*
+     * We'd like to free entries read in off disk at this point, but can't.
+     * The merge_entry() code doesn't copy the strings in the use entries,
+     * it just aliases them.  If this ever changes, do a
+     * free_entries(lastread) here.
+     */
+
+    DEBUG(2, ("RESOLUTION FINISHED"));
+
+    if (fullresolve)
+	if (_nc_check_termtype != 0) {
+	    _nc_curr_col = -1;
+	    for_entry_list(qp) {
+		_nc_curr_line = qp->startline;
+		_nc_set_type(_nc_first_name(qp->tterm.term_names));
+		_nc_check_termtype2(&qp->tterm, literal);
+	    }
+	    DEBUG(2, ("SANITY CHECK FINISHED"));
+	}
+
+    return (TRUE);
+}
+
+/* obsolete: 20040705 */
+NCURSES_EXPORT(int)
+_nc_resolve_uses(bool fullresolve)
+{
+    return _nc_resolve_uses2(fullresolve, FALSE);
+}
+
+/*
+ * This bit of legerdemain turns all the terminfo variable names into
+ * references to locations in the arrays Booleans, Numbers, and Strings ---
+ * precisely what's needed.
+ */
+
+#undef CUR
+#define CUR tp->
+
+static void
+sanity_check2(TERMTYPE *tp, bool literal)
+{
+    if (!PRESENT(exit_attribute_mode)) {
+#ifdef __UNUSED__		/* this casts too wide a net */
+	bool terminal_entry = !strchr(tp->term_names, '+');
+	if (terminal_entry &&
+	    (PRESENT(set_attributes)
+	     || PRESENT(enter_standout_mode)
+	     || PRESENT(enter_underline_mode)
+	     || PRESENT(enter_blink_mode)
+	     || PRESENT(enter_bold_mode)
+	     || PRESENT(enter_dim_mode)
+	     || PRESENT(enter_secure_mode)
+	     || PRESENT(enter_protected_mode)
+	     || PRESENT(enter_reverse_mode)))
+	    _nc_warning("no exit_attribute_mode");
+#endif /* __UNUSED__ */
+	PAIRED(enter_standout_mode, exit_standout_mode);
+	PAIRED(enter_underline_mode, exit_underline_mode);
+    }
+
+    /* we do this check/fix in postprocess_termcap(), but some packagers
+     * prefer to bypass it...
+     */
+    if (!literal) {
+	if (acs_chars == 0
+	    && enter_alt_charset_mode != 0
+	    && exit_alt_charset_mode != 0)
+	    acs_chars = strdup(VT_ACSC);
+	ANDMISSING(enter_alt_charset_mode, acs_chars);
+	ANDMISSING(exit_alt_charset_mode, acs_chars);
+    }
+
+    /* listed in structure-member order of first argument */
+    PAIRED(enter_alt_charset_mode, exit_alt_charset_mode);
+    ANDMISSING(enter_blink_mode, exit_attribute_mode);
+    ANDMISSING(enter_bold_mode, exit_attribute_mode);
+    PAIRED(exit_ca_mode, enter_ca_mode);
+    PAIRED(enter_delete_mode, exit_delete_mode);
+    ANDMISSING(enter_dim_mode, exit_attribute_mode);
+    PAIRED(enter_insert_mode, exit_insert_mode);
+    ANDMISSING(enter_secure_mode, exit_attribute_mode);
+    ANDMISSING(enter_protected_mode, exit_attribute_mode);
+    ANDMISSING(enter_reverse_mode, exit_attribute_mode);
+    PAIRED(from_status_line, to_status_line);
+    PAIRED(meta_off, meta_on);
+
+    PAIRED(prtr_on, prtr_off);
+    PAIRED(save_cursor, restore_cursor);
+    PAIRED(enter_xon_mode, exit_xon_mode);
+    PAIRED(enter_am_mode, exit_am_mode);
+    ANDMISSING(label_off, label_on);
+#ifdef remove_clock
+    PAIRED(display_clock, remove_clock);
+#endif
+    ANDMISSING(set_color_pair, initialize_pair);
+}
+
+/* obsolete: 20040705 */
+static void
+sanity_check(TERMTYPE *tp)
+{
+    sanity_check2(tp, FALSE);
+}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_leaks_tic(void)
+{
+    _nc_alloc_entry_leaks();
+    _nc_captoinfo_leaks();
+    _nc_comp_captab_leaks();
+    _nc_comp_scan_leaks();
+#if BROKEN_LINKER || USE_REENTRANT
+    _nc_names_leaks();
+    _nc_codes_leaks();
+#endif
+    _nc_tic_expand(0, FALSE, 0);
+}
+
+NCURSES_EXPORT(void)
+_nc_free_tic(int code)
+{
+    _nc_leaks_tic();
+    _nc_free_tinfo(code);
+}
+#endif
diff --git a/ncurses/tinfo/comp_scan.c b/ncurses/tinfo/comp_scan.c
new file mode 100644
index 0000000..5ad750f
--- /dev/null
+++ b/ncurses/tinfo/comp_scan.c
@@ -0,0 +1,944 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996 on                 *
+ ****************************************************************************/
+
+/*
+ *	comp_scan.c --- Lexical scanner for terminfo compiler.
+ *
+ *	_nc_reset_input()
+ *	_nc_get_token()
+ *	_nc_panic_mode()
+ *	int _nc_syntax;
+ *	int _nc_curr_line;
+ *	long _nc_curr_file_pos;
+ *	long _nc_comment_start;
+ *	long _nc_comment_end;
+ */
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <term_entry.h>
+#include <tic.h>
+
+MODULE_ID("$Id: comp_scan.c,v 1.83 2008/08/16 19:22:55 tom Exp $")
+
+/*
+ * Maximum length of string capability we'll accept before raising an error.
+ * Yes, there is a real capability in /etc/termcap this long, an "is".
+ */
+#define MAXCAPLEN	600
+
+#define iswhite(ch)	(ch == ' '  ||  ch == '\t')
+
+NCURSES_EXPORT_VAR(int)
+_nc_syntax = 0;			/* termcap or terminfo? */
+NCURSES_EXPORT_VAR(long)
+_nc_curr_file_pos = 0;		/* file offset of current line */
+NCURSES_EXPORT_VAR(long)
+_nc_comment_start = 0;		/* start of comment range before name */
+NCURSES_EXPORT_VAR(long)
+_nc_comment_end = 0;		/* end of comment range before name */
+NCURSES_EXPORT_VAR(long)
+_nc_start_line = 0;		/* start line of current entry */
+
+NCURSES_EXPORT_VAR(struct token)
+_nc_curr_token =
+{
+    0, 0, 0
+};
+
+/*****************************************************************************
+ *
+ * Token-grabbing machinery
+ *
+ *****************************************************************************/
+
+static bool first_column;	/* See 'next_char()' below */
+static bool had_newline;
+static char separator;		/* capability separator */
+static int pushtype;		/* type of pushback token */
+static char *pushname;
+
+#if NCURSES_EXT_FUNCS
+NCURSES_EXPORT_VAR(bool)
+_nc_disable_period = FALSE;	/* used by tic -a option */
+#endif
+
+/*****************************************************************************
+ *
+ * Character-stream handling
+ *
+ *****************************************************************************/
+
+#define LEXBUFSIZ	1024
+
+static char *bufptr;		/* otherwise, the input buffer pointer */
+static char *bufstart;		/* start of buffer so we can compute offsets */
+static FILE *yyin;		/* scanner's input file descriptor */
+
+/*
+ *	_nc_reset_input()
+ *
+ *	Resets the input-reading routines.  Used on initialization,
+ *	or after a seek has been done.  Exactly one argument must be
+ *	non-null.
+ */
+
+NCURSES_EXPORT(void)
+_nc_reset_input(FILE *fp, char *buf)
+{
+    pushtype = NO_PUSHBACK;
+    if (pushname != 0)
+	pushname[0] = '\0';
+    yyin = fp;
+    bufstart = bufptr = buf;
+    _nc_curr_file_pos = 0L;
+    if (fp != 0)
+	_nc_curr_line = 0;
+    _nc_curr_col = 0;
+}
+
+/*
+ *	int last_char()
+ *
+ *	Returns the final nonblank character on the current input buffer
+ */
+static int
+last_char(void)
+{
+    size_t len = strlen(bufptr);
+    while (len--) {
+	if (!isspace(UChar(bufptr[len])))
+	    return bufptr[len];
+    }
+    return 0;
+}
+
+/*
+ *	int next_char()
+ *
+ *	Returns the next character in the input stream.  Comments and leading
+ *	white space are stripped.
+ *
+ *	The global state variable 'firstcolumn' is set TRUE if the character
+ *	returned is from the first column of the input line.
+ *
+ *	The global variable _nc_curr_line is incremented for each new line.
+ *	The global variable _nc_curr_file_pos is set to the file offset of the
+ *	beginning of each line.
+ */
+
+static int
+next_char(void)
+{
+    static char *result;
+    static size_t allocated;
+    int the_char;
+
+    if (!yyin) {
+	if (result != 0) {
+	    FreeAndNull(result);
+	    FreeAndNull(pushname);
+	    allocated = 0;
+	}
+	/*
+	 * An string with an embedded null will truncate the input.  This is
+	 * intentional (we don't read binary files here).
+	 */
+	if (bufptr == 0 || *bufptr == '\0')
+	    return (EOF);
+	if (*bufptr == '\n') {
+	    _nc_curr_line++;
+	    _nc_curr_col = 0;
+	} else if (*bufptr == '\t') {
+	    _nc_curr_col = (_nc_curr_col | 7);
+	}
+    } else if (!bufptr || !*bufptr) {
+	/*
+	 * In theory this could be recoded to do its I/O one character at a
+	 * time, saving the buffer space.  In practice, this turns out to be
+	 * quite hard to get completely right.  Try it and see.  If you
+	 * succeed, don't forget to hack push_back() correspondingly.
+	 */
+	size_t used;
+	size_t len;
+
+	do {
+	    bufstart = 0;
+	    used = 0;
+	    do {
+		if (used + (LEXBUFSIZ / 4) >= allocated) {
+		    allocated += (allocated + LEXBUFSIZ);
+		    result = typeRealloc(char, allocated, result);
+		    if (result == 0)
+			return (EOF);
+		    bufstart = result;
+		}
+		if (used == 0)
+		    _nc_curr_file_pos = ftell(yyin);
+
+		if (fgets(result + used, (int) (allocated - used), yyin) != 0) {
+		    bufstart = result;
+		    if (used == 0) {
+			_nc_curr_line++;
+			_nc_curr_col = 0;
+		    }
+		} else {
+		    if (used != 0)
+			strcat(result, "\n");
+		}
+		if ((bufptr = bufstart) != 0) {
+		    used = strlen(bufptr);
+		    while (iswhite(*bufptr)) {
+			if (*bufptr == '\t') {
+			    _nc_curr_col = (_nc_curr_col | 7) + 1;
+			} else {
+			    _nc_curr_col++;
+			}
+			bufptr++;
+		    }
+
+		    /*
+		     * Treat a trailing <cr><lf> the same as a <newline> so we
+		     * can read files on OS/2, etc.
+		     */
+		    if ((len = strlen(bufptr)) > 1) {
+			if (bufptr[len - 1] == '\n'
+			    && bufptr[len - 2] == '\r') {
+			    len--;
+			    bufptr[len - 1] = '\n';
+			    bufptr[len] = '\0';
+			}
+		    }
+		} else {
+		    return (EOF);
+		}
+	    } while (bufptr[len - 1] != '\n');	/* complete a line */
+	} while (result[0] == '#');	/* ignore comments */
+    } else if (*bufptr == '\t') {
+	_nc_curr_col = (_nc_curr_col | 7);
+    }
+
+    first_column = (bufptr == bufstart);
+    if (first_column)
+	had_newline = FALSE;
+
+    _nc_curr_col++;
+    the_char = *bufptr++;
+    return UChar(the_char);
+}
+
+static void
+push_back(char c)
+/* push a character back onto the input stream */
+{
+    if (bufptr == bufstart)
+	_nc_syserr_abort("Can't backspace off beginning of line");
+    *--bufptr = c;
+    _nc_curr_col--;
+}
+
+static long
+stream_pos(void)
+/* return our current character position in the input stream */
+{
+    return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0));
+}
+
+static bool
+end_of_stream(void)
+/* are we at end of input? */
+{
+    return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0'))
+	    ? TRUE : FALSE);
+}
+
+/* Assume we may be looking at a termcap-style continuation */
+static NCURSES_INLINE int
+eat_escaped_newline(int ch)
+{
+    if (ch == '\\')
+	while ((ch = next_char()) == '\n' || iswhite(ch))
+	    continue;
+    return ch;
+}
+
+#define TOK_BUF_SIZE MAX_ENTRY_SIZE
+
+#define OkToAdd() \
+	((tok_ptr - tok_buf) < (TOK_BUF_SIZE - 2))
+
+#define AddCh(ch) \
+	*tok_ptr++ = (char) ch; \
+	*tok_ptr = '\0'
+
+/*
+ *	int
+ *	get_token()
+ *
+ *	Scans the input for the next token, storing the specifics in the
+ *	global structure 'curr_token' and returning one of the following:
+ *
+ *		NAMES		A line beginning in column 1.  'name'
+ *				will be set to point to everything up to but
+ *				not including the first separator on the line.
+ *		BOOLEAN		An entry consisting of a name followed by
+ *				a separator.  'name' will be set to point to
+ *				the name of the capability.
+ *		NUMBER		An entry of the form
+ *					name#digits,
+ *				'name' will be set to point to the capability
+ *				name and 'valnumber' to the number given.
+ *		STRING		An entry of the form
+ *					name=characters,
+ *				'name' is set to the capability name and
+ *				'valstring' to the string of characters, with
+ *				input translations done.
+ *		CANCEL		An entry of the form
+ *					name@,
+ *				'name' is set to the capability name and
+ *				'valnumber' to -1.
+ *		EOF		The end of the file has been reached.
+ *
+ *	A `separator' is either a comma or a semicolon, depending on whether
+ *	we are in termcap or terminfo mode.
+ *
+ */
+
+NCURSES_EXPORT(int)
+_nc_get_token(bool silent)
+{
+    static const char terminfo_punct[] = "@%&*!#";
+    static char *tok_buf;
+
+    char *after_list;
+    char *after_name;
+    char *numchk;
+    char *tok_ptr;
+    char *s;
+    char numbuf[80];
+    int ch;
+    int dot_flag = FALSE;
+    int type;
+    long number;
+    long token_start;
+    unsigned found;
+#ifdef TRACE
+    int old_line;
+    int old_col;
+#endif
+
+    if (pushtype != NO_PUSHBACK) {
+	int retval = pushtype;
+
+	_nc_set_type(pushname != 0 ? pushname : "");
+	DEBUG(3, ("pushed-back token: `%s', class %d",
+		  _nc_curr_token.tk_name, pushtype));
+
+	pushtype = NO_PUSHBACK;
+	if (pushname != 0)
+	    pushname[0] = '\0';
+
+	/* currtok wasn't altered by _nc_push_token() */
+	return (retval);
+    }
+
+    if (end_of_stream()) {
+	yyin = 0;
+	next_char();		/* frees its allocated memory */
+	if (tok_buf != 0) {
+	    if (_nc_curr_token.tk_name == tok_buf)
+		_nc_curr_token.tk_name = 0;
+	    FreeAndNull(tok_buf);
+	}
+	return (EOF);
+    }
+
+  start_token:
+    token_start = stream_pos();
+    while ((ch = next_char()) == '\n' || iswhite(ch)) {
+	if (ch == '\n')
+	    had_newline = TRUE;
+	continue;
+    }
+
+    ch = eat_escaped_newline(ch);
+
+#ifdef TRACE
+    old_line = _nc_curr_line;
+    old_col = _nc_curr_col;
+#endif
+    if (ch == EOF)
+	type = EOF;
+    else {
+	/* if this is a termcap entry, skip a leading separator */
+	if (separator == ':' && ch == ':')
+	    ch = next_char();
+
+	if (ch == '.'
+#if NCURSES_EXT_FUNCS
+	    && !_nc_disable_period
+#endif
+	    ) {
+	    dot_flag = TRUE;
+	    DEBUG(8, ("dot-flag set"));
+
+	    while ((ch = next_char()) == '.' || iswhite(ch))
+		continue;
+	}
+
+	if (ch == EOF) {
+	    type = EOF;
+	    goto end_of_token;
+	}
+
+	/* have to make some punctuation chars legal for terminfo */
+	if (!isalnum(UChar(ch))
+#if NCURSES_EXT_FUNCS
+	    && !(ch == '.' && _nc_disable_period)
+#endif
+	    && !strchr(terminfo_punct, (char) ch)) {
+	    if (!silent)
+		_nc_warning("Illegal character (expected alphanumeric or %s) - '%s'",
+			    terminfo_punct, unctrl((chtype) ch));
+	    _nc_panic_mode(separator);
+	    goto start_token;
+	}
+
+	if (tok_buf == 0)
+	    tok_buf = typeMalloc(char, TOK_BUF_SIZE);
+
+#ifdef TRACE
+	old_line = _nc_curr_line;
+	old_col = _nc_curr_col;
+#endif
+	tok_ptr = tok_buf;
+	AddCh(ch);
+
+	if (first_column) {
+	    _nc_comment_start = token_start;
+	    _nc_comment_end = _nc_curr_file_pos;
+	    _nc_start_line = _nc_curr_line;
+
+	    _nc_syntax = ERR;
+	    after_name = 0;
+	    after_list = 0;
+	    while ((ch = next_char()) != '\n') {
+		if (ch == EOF) {
+		    _nc_err_abort(MSG_NO_INPUTS);
+		} else if (ch == '|') {
+		    after_list = tok_ptr;
+		    if (after_name == 0)
+			after_name = tok_ptr;
+		} else if (ch == ':' && last_char() != ',') {
+		    _nc_syntax = SYN_TERMCAP;
+		    separator = ':';
+		    break;
+		} else if (ch == ',') {
+		    _nc_syntax = SYN_TERMINFO;
+		    separator = ',';
+		    /*
+		     * If we did not see a '|', then we found a name with no
+		     * aliases or description.
+		     */
+		    if (after_name == 0)
+			break;
+		    /*
+		     * If we see a comma, we assume this is terminfo unless we
+		     * subsequently run into a colon.  But we don't stop
+		     * looking for a colon until hitting a newline.  This
+		     * allows commas to be embedded in description fields of
+		     * either syntax.
+		     */
+		} else
+		    ch = eat_escaped_newline(ch);
+
+		if (OkToAdd()) {
+		    AddCh(ch);
+		} else {
+		    ch = EOF;
+		    break;
+		}
+	    }
+	    *tok_ptr = '\0';
+	    if (_nc_syntax == ERR) {
+		/*
+		 * Grrr...what we ought to do here is barf, complaining that
+		 * the entry is malformed.  But because a couple of name fields
+		 * in the 8.2 termcap file end with |\, we just have to assume
+		 * it's termcap syntax.
+		 */
+		_nc_syntax = SYN_TERMCAP;
+		separator = ':';
+	    } else if (_nc_syntax == SYN_TERMINFO) {
+		/* throw away trailing /, *$/ */
+		for (--tok_ptr;
+		     iswhite(*tok_ptr) || *tok_ptr == ',';
+		     tok_ptr--)
+		    continue;
+		tok_ptr[1] = '\0';
+	    }
+
+	    /*
+	     * This is the soonest we have the terminal name fetched.  Set up
+	     * for following warning messages.  If there's no '|', then there
+	     * is no description.
+	     */
+	    if (after_name != 0) {
+		ch = *after_name;
+		*after_name = '\0';
+		_nc_set_type(tok_buf);
+		*after_name = (char) ch;
+	    }
+
+	    /*
+	     * Compute the boundary between the aliases and the description
+	     * field for syntax-checking purposes.
+	     */
+	    if (after_list != 0) {
+		if (!silent) {
+		    if (*after_list == '\0')
+			_nc_warning("empty longname field");
+		    else if (strchr(after_list, ' ') == 0)
+			_nc_warning("older tic versions may treat the description field as an alias");
+		}
+	    } else {
+		after_list = tok_buf + strlen(tok_buf);
+		DEBUG(1, ("missing description"));
+	    }
+
+	    /*
+	     * Whitespace in a name field other than the long name can confuse
+	     * rdist and some termcap tools.  Slashes are a no-no.  Other
+	     * special characters can be dangerous due to shell expansion.
+	     */
+	    for (s = tok_buf; s < after_list; ++s) {
+		if (isspace(UChar(*s))) {
+		    if (!silent)
+			_nc_warning("whitespace in name or alias field");
+		    break;
+		} else if (*s == '/') {
+		    if (!silent)
+			_nc_warning("slashes aren't allowed in names or aliases");
+		    break;
+		} else if (strchr("$[]!*?", *s)) {
+		    if (!silent)
+			_nc_warning("dubious character `%c' in name or alias field", *s);
+		    break;
+		}
+	    }
+
+	    _nc_curr_token.tk_name = tok_buf;
+	    type = NAMES;
+	} else {
+	    if (had_newline && _nc_syntax == SYN_TERMCAP) {
+		_nc_warning("Missing backslash before newline");
+		had_newline = FALSE;
+	    }
+	    while ((ch = next_char()) != EOF) {
+		if (!isalnum(UChar(ch))) {
+		    if (_nc_syntax == SYN_TERMINFO) {
+			if (ch != '_')
+			    break;
+		    } else {	/* allow ';' for "k;" */
+			if (ch != ';')
+			    break;
+		    }
+		}
+		if (OkToAdd()) {
+		    AddCh(ch);
+		} else {
+		    ch = EOF;
+		    break;
+		}
+	    }
+
+	    *tok_ptr++ = '\0';	/* separate name/value in buffer */
+	    switch (ch) {
+	    case ',':
+	    case ':':
+		if (ch != separator)
+		    _nc_err_abort("Separator inconsistent with syntax");
+		_nc_curr_token.tk_name = tok_buf;
+		type = BOOLEAN;
+		break;
+	    case '@':
+		if ((ch = next_char()) != separator && !silent)
+		    _nc_warning("Missing separator after `%s', have %s",
+				tok_buf, unctrl((chtype) ch));
+		_nc_curr_token.tk_name = tok_buf;
+		type = CANCEL;
+		break;
+
+	    case '#':
+		found = 0;
+		while (isalnum(ch = next_char())) {
+		    numbuf[found++] = (char) ch;
+		    if (found >= sizeof(numbuf) - 1)
+			break;
+		}
+		numbuf[found] = '\0';
+		number = strtol(numbuf, &numchk, 0);
+		if (!silent) {
+		    if (numchk == numbuf)
+			_nc_warning("no value given for `%s'", tok_buf);
+		    if ((*numchk != '\0') || (ch != separator))
+			_nc_warning("Missing separator");
+		}
+		_nc_curr_token.tk_name = tok_buf;
+		_nc_curr_token.tk_valnumber = number;
+		type = NUMBER;
+		break;
+
+	    case '=':
+		ch = _nc_trans_string(tok_ptr, tok_buf + TOK_BUF_SIZE);
+		if (!silent && ch != separator)
+		    _nc_warning("Missing separator");
+		_nc_curr_token.tk_name = tok_buf;
+		_nc_curr_token.tk_valstring = tok_ptr;
+		type = STRING;
+		break;
+
+	    case EOF:
+		type = EOF;
+		break;
+	    default:
+		/* just to get rid of the compiler warning */
+		type = UNDEF;
+		if (!silent)
+		    _nc_warning("Illegal character - '%s'", unctrl((chtype) ch));
+	    }
+	}			/* end else (first_column == FALSE) */
+    }				/* end else (ch != EOF) */
+
+  end_of_token:
+
+#ifdef TRACE
+    if (dot_flag == TRUE)
+	DEBUG(8, ("Commented out "));
+
+    if (_nc_tracing >= DEBUG_LEVEL(8)) {
+	_tracef("parsed %d.%d to %d.%d",
+		old_line, old_col,
+		_nc_curr_line, _nc_curr_col);
+    }
+    if (_nc_tracing >= DEBUG_LEVEL(7)) {
+	switch (type) {
+	case BOOLEAN:
+	    _tracef("Token: Boolean; name='%s'",
+		    _nc_curr_token.tk_name);
+	    break;
+
+	case NUMBER:
+	    _tracef("Token: Number;  name='%s', value=%d",
+		    _nc_curr_token.tk_name,
+		    _nc_curr_token.tk_valnumber);
+	    break;
+
+	case STRING:
+	    _tracef("Token: String;  name='%s', value=%s",
+		    _nc_curr_token.tk_name,
+		    _nc_visbuf(_nc_curr_token.tk_valstring));
+	    break;
+
+	case CANCEL:
+	    _tracef("Token: Cancel; name='%s'",
+		    _nc_curr_token.tk_name);
+	    break;
+
+	case NAMES:
+
+	    _tracef("Token: Names; value='%s'",
+		    _nc_curr_token.tk_name);
+	    break;
+
+	case EOF:
+	    _tracef("Token: End of file");
+	    break;
+
+	default:
+	    _nc_warning("Bad token type");
+	}
+    }
+#endif
+
+    if (dot_flag == TRUE)	/* if commented out, use the next one */
+	type = _nc_get_token(silent);
+
+    DEBUG(3, ("token: `%s', class %d",
+	      ((_nc_curr_token.tk_name != 0)
+	       ? _nc_curr_token.tk_name
+	       : "<null>"),
+	      type));
+
+    return (type);
+}
+
+/*
+ *	char
+ *	trans_string(ptr)
+ *
+ *	Reads characters using next_char() until encountering a separator, nl,
+ *	or end-of-file.  The returned value is the character which caused
+ *	reading to stop.  The following translations are done on the input:
+ *
+ *		^X  goes to  ctrl-X (i.e. X & 037)
+ *		{\E,\n,\r,\b,\t,\f}  go to
+ *			{ESCAPE,newline,carriage-return,backspace,tab,formfeed}
+ *		{\^,\\}  go to  {carat,backslash}
+ *		\ddd (for ddd = up to three octal digits)  goes to the character ddd
+ *
+ *		\e == \E
+ *		\0 == \200
+ *
+ */
+
+NCURSES_EXPORT(int)
+_nc_trans_string(char *ptr, char *last)
+{
+    int count = 0;
+    int number = 0;
+    int i, c;
+    chtype ch, last_ch = '\0';
+    bool ignored = FALSE;
+    bool long_warning = FALSE;
+
+    while ((ch = c = next_char()) != (chtype) separator && c != EOF) {
+	if (ptr >= (last - 1)) {
+	    if (c != EOF) {
+		while ((c = next_char()) != separator && c != EOF) {
+		    ;
+		}
+		ch = c;
+	    }
+	    break;
+	}
+	if ((_nc_syntax == SYN_TERMCAP) && c == '\n')
+	    break;
+	if (ch == '^' && last_ch != '%') {
+	    ch = c = next_char();
+	    if (c == EOF)
+		_nc_err_abort(MSG_NO_INPUTS);
+
+	    if (!(is7bits(ch) && isprint(ch))) {
+		_nc_warning("Illegal ^ character - '%s'", unctrl(ch));
+	    }
+	    if (ch == '?') {
+		*(ptr++) = '\177';
+		if (_nc_tracing)
+		    _nc_warning("Allow ^? as synonym for \\177");
+	    } else {
+		if ((ch &= 037) == 0)
+		    ch = 128;
+		*(ptr++) = (char) (ch);
+	    }
+	} else if (ch == '\\') {
+	    ch = c = next_char();
+	    if (c == EOF)
+		_nc_err_abort(MSG_NO_INPUTS);
+
+	    if (ch >= '0' && ch <= '7') {
+		number = ch - '0';
+		for (i = 0; i < 2; i++) {
+		    ch = c = next_char();
+		    if (c == EOF)
+			_nc_err_abort(MSG_NO_INPUTS);
+
+		    if (c < '0' || c > '7') {
+			if (isdigit(c)) {
+			    _nc_warning("Non-octal digit `%c' in \\ sequence", c);
+			    /* allow the digit; it'll do less harm */
+			} else {
+			    push_back((char) c);
+			    break;
+			}
+		    }
+
+		    number = number * 8 + c - '0';
+		}
+
+		if (number == 0)
+		    number = 0200;
+		*(ptr++) = (char) number;
+	    } else {
+		switch (c) {
+		case 'E':
+		case 'e':
+		    *(ptr++) = '\033';
+		    break;
+
+		case 'a':
+		    *(ptr++) = '\007';
+		    break;
+
+		case 'l':
+		case 'n':
+		    *(ptr++) = '\n';
+		    break;
+
+		case 'r':
+		    *(ptr++) = '\r';
+		    break;
+
+		case 'b':
+		    *(ptr++) = '\010';
+		    break;
+
+		case 's':
+		    *(ptr++) = ' ';
+		    break;
+
+		case 'f':
+		    *(ptr++) = '\014';
+		    break;
+
+		case 't':
+		    *(ptr++) = '\t';
+		    break;
+
+		case '\\':
+		    *(ptr++) = '\\';
+		    break;
+
+		case '^':
+		    *(ptr++) = '^';
+		    break;
+
+		case ',':
+		    *(ptr++) = ',';
+		    break;
+
+		case ':':
+		    *(ptr++) = ':';
+		    break;
+
+		case '\n':
+		    continue;
+
+		default:
+		    _nc_warning("Illegal character '%s' in \\ sequence",
+				unctrl(ch));
+		    /* FALLTHRU */
+		case '|':
+		    *(ptr++) = (char) ch;
+		}		/* endswitch (ch) */
+	    }			/* endelse (ch < '0' ||  ch > '7') */
+	}
+	/* end else if (ch == '\\') */
+	else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) {
+	    /*
+	     * Newlines embedded in a terminfo string are ignored, provided
+	     * that the next line begins with whitespace.
+	     */
+	    ignored = TRUE;
+	} else {
+	    *(ptr++) = (char) ch;
+	}
+
+	if (!ignored) {
+	    if (_nc_curr_col <= 1) {
+		push_back((char) ch);
+		ch = '\n';
+		break;
+	    }
+	    last_ch = ch;
+	    count++;
+	}
+	ignored = FALSE;
+
+	if (count > MAXCAPLEN && !long_warning) {
+	    _nc_warning("Very long string found.  Missing separator?");
+	    long_warning = TRUE;
+	}
+    }				/* end while */
+
+    *ptr = '\0';
+
+    return (ch);
+}
+
+/*
+ *	_nc_push_token()
+ *
+ *	Push a token of given type so that it will be reread by the next
+ *	get_token() call.
+ */
+
+NCURSES_EXPORT(void)
+_nc_push_token(int tokclass)
+{
+    /*
+     * This implementation is kind of bogus, it will fail if we ever do more
+     * than one pushback at a time between get_token() calls.  It relies on the
+     * fact that _nc_curr_token is static storage that nothing but
+     * _nc_get_token() touches.
+     */
+    pushtype = tokclass;
+    if (pushname == 0)
+	pushname = typeMalloc(char, MAX_NAME_SIZE + 1);
+    _nc_get_type(pushname);
+
+    DEBUG(3, ("pushing token: `%s', class %d",
+	      ((_nc_curr_token.tk_name != 0)
+	       ? _nc_curr_token.tk_name
+	       : "<null>"),
+	      pushtype));
+}
+
+/*
+ * Panic mode error recovery - skip everything until a "ch" is found.
+ */
+NCURSES_EXPORT(void)
+_nc_panic_mode(char ch)
+{
+    int c;
+
+    for (;;) {
+	c = next_char();
+	if (c == ch)
+	    return;
+	if (c == EOF)
+	    return;
+    }
+}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_comp_scan_leaks(void)
+{
+    if (pushname != 0) {
+	FreeAndNull(pushname);
+    }
+}
+#endif
diff --git a/ncurses/tinfo/db_iterator.c b/ncurses/tinfo/db_iterator.c
new file mode 100644
index 0000000..fdc2bb0
--- /dev/null
+++ b/ncurses/tinfo/db_iterator.c
@@ -0,0 +1,225 @@
+/****************************************************************************
+ * Copyright (c) 2006,2007 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+ * Iterators for terminal databases.
+ */
+
+#include <curses.priv.h>
+
+#include <tic.h>
+
+MODULE_ID("$Id: db_iterator.c,v 1.6 2007/04/22 00:00:26 tom Exp $")
+
+#define HaveTicDirectory _nc_globals.have_tic_directory
+#define KeepTicDirectory _nc_globals.keep_tic_directory
+#define TicDirectory     _nc_globals.tic_directory
+
+/*
+ * Record the "official" location of the terminfo directory, according to
+ * the place where we're writing to, or the normal default, if not.
+ */
+NCURSES_EXPORT(const char *)
+_nc_tic_dir(const char *path)
+{
+    if (!KeepTicDirectory) {
+	if (path != 0) {
+	    TicDirectory = path;
+	    HaveTicDirectory = TRUE;
+	} else if (!HaveTicDirectory && use_terminfo_vars()) {
+	    char *envp;
+	    if ((envp = getenv("TERMINFO")) != 0)
+		return _nc_tic_dir(envp);
+	}
+    }
+    return TicDirectory;
+}
+
+/*
+ * Special fix to prevent the terminfo directory from being moved after tic
+ * has chdir'd to it.  If we let it be changed, then if $TERMINFO has a
+ * relative path, we'll lose track of the actual directory.
+ */
+NCURSES_EXPORT(void)
+_nc_keep_tic_dir(const char *path)
+{
+    _nc_tic_dir(path);
+    KeepTicDirectory = TRUE;
+}
+
+/*
+ * Process the list of :-separated directories, looking for the terminal type.
+ * We don't use strtok because it does not show us empty tokens.
+ */
+#define ThisDbList	_nc_globals.dbi_list
+#define ThisDbSize	_nc_globals.dbi_size
+
+/*
+ * Cleanup.
+ */
+NCURSES_EXPORT(void)
+_nc_last_db(void)
+{
+    if (ThisDbList != 0) {
+	FreeAndNull(ThisDbList);
+    }
+    ThisDbSize = 0;
+}
+
+/* The TERMINFO_DIRS value, if defined by the configure script, begins with a
+ * ":", which will be interpreted as TERMINFO.
+ */
+static const char *
+next_list_item(const char *source, int *offset)
+{
+    if (source != 0) {
+	FreeIfNeeded(ThisDbList);
+	ThisDbList = strdup(source);
+	ThisDbSize = strlen(source);
+    }
+
+    if (ThisDbList != 0 && ThisDbSize && *offset < ThisDbSize) {
+	static char system_db[] = TERMINFO;
+	char *result = ThisDbList + *offset;
+	char *marker = strchr(result, NCURSES_PATHSEP);
+
+	/*
+	 * Put a null on the marker if a separator was found.  Set the offset
+	 * to the next position after the marker so we can call this function
+	 * again, using the data at the offset.
+	 */
+	if (marker == 0) {
+	    *offset += strlen(result) + 1;
+	    marker = result + *offset;
+	} else {
+	    *marker++ = 0;
+	    *offset = marker - ThisDbList;
+	}
+	if (*result == 0 && result != (ThisDbList + ThisDbSize))
+	    result = system_db;
+	return result;
+    }
+    return 0;
+}
+
+#define NEXT_DBD(var, offset) next_list_item((*offset == 0) ? var : 0, offset)
+
+/*
+ * This is a simple iterator which allows the caller to step through the
+ * possible locations for a terminfo directory.  ncurses uses this to find
+ * terminfo files to read.
+ */
+NCURSES_EXPORT(const char *)
+_nc_next_db(DBDIRS * state, int *offset)
+{
+    const char *result;
+    char *envp;
+
+    while (*state < dbdLAST) {
+	DBDIRS next = (DBDIRS) ((int) (*state) + 1);
+
+	result = 0;
+
+	switch (*state) {
+	case dbdTIC:
+	    if (HaveTicDirectory)
+		result = _nc_tic_dir(0);
+	    break;
+#if USE_DATABASE
+	case dbdEnvOnce:
+	    if (use_terminfo_vars()) {
+		if ((envp = getenv("TERMINFO")) != 0)
+		    result = _nc_tic_dir(envp);
+	    }
+	    break;
+	case dbdHome:
+	    if (use_terminfo_vars()) {
+		result = _nc_home_terminfo();
+	    }
+	    break;
+	case dbdEnvList:
+	    if (use_terminfo_vars()) {
+		if ((result = NEXT_DBD(getenv("TERMINFO_DIRS"), offset)) != 0)
+		    next = *state;
+	    }
+	    break;
+	case dbdCfgList:
+#ifdef TERMINFO_DIRS
+	    if ((result = NEXT_DBD(TERMINFO_DIRS, offset)) != 0)
+		next = *state;
+#endif
+	    break;
+	case dbdCfgOnce:
+#ifndef TERMINFO_DIRS
+	    result = TERMINFO;
+#endif
+	    break;
+#endif /* USE_DATABASE */
+#if USE_TERMCAP
+	case dbdEnvOnce2:
+	    if (use_terminfo_vars()) {
+		if ((envp = getenv("TERMCAP")) != 0)
+		    result = _nc_tic_dir(envp);
+	    }
+	    break;
+	case dbdEnvList2:
+	    if (use_terminfo_vars()) {
+		if ((result = NEXT_DBD(getenv("TERMPATH"), offset)) != 0)
+		    next = *state;
+	    }
+	    break;
+	case dbdCfgList2:
+	    if ((result = NEXT_DBD(TERMPATH, offset)) != 0)
+		next = *state;
+	    break;
+#endif /* USE_TERMCAP */
+	case dbdLAST:
+	    break;
+	}
+	if (*state != next) {
+	    *state = next;
+	    *offset = 0;
+	    _nc_last_db();
+	}
+	if (result != 0) {
+	    return result;
+	}
+    }
+    return 0;
+}
+
+NCURSES_EXPORT(void)
+_nc_first_db(DBDIRS * state, int *offset)
+{
+    *state = dbdTIC;
+    *offset = 0;
+}
diff --git a/ncurses/tinfo/doalloc.c b/ncurses/tinfo/doalloc.c
new file mode 100644
index 0000000..fe2a009
--- /dev/null
+++ b/ncurses/tinfo/doalloc.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1998                        *
+ ****************************************************************************/
+
+/*
+ * Wrapper for malloc/realloc.  Standard implementations allow realloc with
+ * a null pointer, but older libraries may not (e.g., SunOS).
+ *
+ * Also if realloc fails, we discard the old memory to avoid leaks.
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: doalloc.c,v 1.8 2002/08/31 21:48:11 Philippe.Blain Exp $")
+
+NCURSES_EXPORT(void *)
+_nc_doalloc(void *oldp, size_t amount)
+{
+    void *newp;
+
+    if (oldp != 0) {
+	if ((newp = realloc(oldp, amount)) == 0) {
+	    free(oldp);
+	    errno = ENOMEM;	/* just in case 'free' reset */
+	}
+    } else {
+	newp = malloc(amount);
+    }
+    return newp;
+}
+
+#if !HAVE_STRDUP
+NCURSES_EXPORT(char *)
+_nc_strdup(const char *src)
+{
+    char *dst;
+    if (src != 0) {
+	dst = typeMalloc(char, strlen(src) + 1);
+	if (dst != 0) {
+	    (void) strcpy(dst, src);
+	}
+    } else {
+	dst = 0;
+    }
+    return dst;
+}
+#endif
diff --git a/ncurses/tinfo/entries.c b/ncurses/tinfo/entries.c
new file mode 100644
index 0000000..cf2a833
--- /dev/null
+++ b/ncurses/tinfo/entries.c
@@ -0,0 +1,145 @@
+/****************************************************************************
+ * Copyright (c) 2006-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: entries.c,v 1.8 2008/09/27 13:11:10 tom Exp $")
+
+/****************************************************************************
+ *
+ * Entry queue handling
+ *
+ ****************************************************************************/
+/*
+ *  The entry list is a doubly linked list with NULLs terminating the lists:
+ *
+ *	  ---------   ---------   ---------
+ *	  |       |   |       |   |       |   offset
+ *        |-------|   |-------|   |-------|
+ *	  |   ----+-->|   ----+-->|  NULL |   next
+ *	  |-------|   |-------|   |-------|
+ *	  |  NULL |<--+----   |<--+----   |   last
+ *	  ---------   ---------   ---------
+ *	      ^                       ^
+ *	      |                       |
+ *	      |                       |
+ *	   _nc_head                _nc_tail
+ */
+
+NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0;
+NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0;
+
+NCURSES_EXPORT(void)
+_nc_free_entry(ENTRY * headp, TERMTYPE *tterm)
+/* free the allocated storage consumed by the given list entry */
+{
+    ENTRY *ep;
+
+    if ((ep = _nc_delink_entry(headp, tterm)) != 0) {
+	free(ep);
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_free_entries(ENTRY * headp)
+/* free the allocated storage consumed by list entries */
+{
+    (void) headp;		/* unused - _nc_head is altered here! */
+
+    while (_nc_head != 0) {
+	_nc_free_termtype(&(_nc_head->tterm));
+    }
+}
+
+NCURSES_EXPORT(ENTRY *)
+_nc_delink_entry(ENTRY * headp, TERMTYPE *tterm)
+/* delink the allocated storage for the given list entry */
+{
+    ENTRY *ep, *last;
+
+    for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) {
+	if (&(ep->tterm) == tterm) {
+	    if (last != 0) {
+		last->next = ep->next;
+	    }
+	    if (ep == _nc_head) {
+		_nc_head = ep->next;
+	    }
+	    if (ep == _nc_tail) {
+		_nc_tail = last;
+	    }
+	    break;
+	}
+    }
+    return ep;
+}
+
+NCURSES_EXPORT(void)
+_nc_leaks_tinfo(void)
+{
+#if NO_LEAKS
+    char *s;
+#endif
+
+    T((T_CALLED("_nc_free_tinfo()")));
+#if NO_LEAKS
+    _nc_free_tparm();
+    _nc_tgetent_leaks();
+    _nc_free_entries(_nc_head);
+    _nc_get_type(0);
+    _nc_first_name(0);
+    _nc_keyname_leaks();
+#if BROKEN_LINKER || USE_REENTRANT
+    _nc_names_leaks();
+    _nc_codes_leaks();
+    FreeIfNeeded(_nc_prescreen.real_acs_map);
+#endif
+
+    if ((s = _nc_home_terminfo()) != 0)
+	free(s);
+#endif /* NO_LEAKS */
+    returnVoid;
+}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_free_tinfo(int code)
+{
+    _nc_leaks_tinfo();
+    exit(code);
+}
+#endif
diff --git a/ncurses/tinfo/free_ttype.c b/ncurses/tinfo/free_ttype.c
new file mode 100644
index 0000000..fa0fff1
--- /dev/null
+++ b/ncurses/tinfo/free_ttype.c
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                    1999-on                     *
+ ****************************************************************************/
+
+/*
+ * free_ttype.c -- allocation functions for TERMTYPE
+ *
+ *	_nc_free_termtype()
+ *	use_extended_names()
+ *
+ */
+
+#include <curses.priv.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: free_ttype.c,v 1.13 2006/06/25 10:46:02 tom Exp $")
+
+NCURSES_EXPORT(void)
+_nc_free_termtype(TERMTYPE *ptr)
+{
+    T(("_nc_free_termtype(%s)", ptr->term_names));
+
+    FreeIfNeeded(ptr->str_table);
+    FreeIfNeeded(ptr->Booleans);
+    FreeIfNeeded(ptr->Numbers);
+    FreeIfNeeded(ptr->Strings);
+#if NCURSES_XNAMES
+    FreeIfNeeded(ptr->ext_str_table);
+    FreeIfNeeded(ptr->ext_Names);
+#endif
+    memset(ptr, 0, sizeof(TERMTYPE));
+    _nc_free_entry(_nc_head, ptr);
+}
+
+#if NCURSES_XNAMES
+NCURSES_EXPORT_VAR(bool) _nc_user_definable = TRUE;
+
+NCURSES_EXPORT(int)
+use_extended_names(bool flag)
+{
+    int oldflag = _nc_user_definable;
+
+    T((T_CALLED("use_extended_names(%d)"), flag));
+    _nc_user_definable = flag;
+    returnBool(oldflag);
+}
+#endif
diff --git a/ncurses/tinfo/getenv_num.c b/ncurses/tinfo/getenv_num.c
new file mode 100644
index 0000000..a90cc08
--- /dev/null
+++ b/ncurses/tinfo/getenv_num.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1998                        *
+ ****************************************************************************/
+
+/*
+ *	getenv_num.c -- obtain a number from the environment
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: getenv_num.c,v 1.3 2000/12/10 02:55:07 tom Exp $")
+
+NCURSES_EXPORT(int)
+_nc_getenv_num(const char *name)
+{
+    char *dst = 0;
+    char *src = getenv(name);
+    long value;
+
+    if ((src == 0)
+	|| (value = strtol(src, &dst, 0)) < 0
+	|| (dst == src)
+	|| (*dst != '\0')
+	|| (int) value < value)
+	value = -1;
+
+    return (int) value;
+}
diff --git a/ncurses/tinfo/hashed_db.c b/ncurses/tinfo/hashed_db.c
new file mode 100644
index 0000000..3fc04ea
--- /dev/null
+++ b/ncurses/tinfo/hashed_db.c
@@ -0,0 +1,260 @@
+/****************************************************************************
+ * Copyright (c) 2006 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                        2006                    *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <tic.h>
+#include <hashed_db.h>
+
+#if USE_HASHED_DB
+
+MODULE_ID("$Id: hashed_db.c,v 1.13 2006/08/19 19:48:38 tom Exp $")
+
+#if HASHED_DB_API >= 2
+static DBC *cursor;
+#endif
+
+/*
+ * Open the database.
+ */
+NCURSES_EXPORT(DB *)
+_nc_db_open(const char *path, bool modify)
+{
+    DB *result = 0;
+
+#if HASHED_DB_API >= 4
+    db_create(&result, NULL, 0);
+    result->open(result,
+		 NULL,
+		 path,
+		 NULL,
+		 DB_HASH,
+		 modify ? DB_CREATE : DB_RDONLY,
+		 0644);
+#elif HASHED_DB_API >= 3
+    db_create(&result, NULL, 0);
+    result->open(result,
+		 path,
+		 NULL,
+		 DB_HASH,
+		 modify ? DB_CREATE : DB_RDONLY,
+		 0644);
+#elif HASHED_DB_API >= 2
+    int code;
+
+    if ((code = db_open(path,
+			DB_HASH,
+			modify ? DB_CREATE : DB_RDONLY,
+			0644,
+			(DB_ENV *) 0,
+			(DB_INFO *) 0,
+			&result)) != 0) {
+	T(("cannot open %s: %s", path, strerror(code)));
+	result = 0;
+    } else {
+	T(("opened %s", path));
+    }
+#else
+    result = dbopen(path,
+		    modify ? (O_CREAT | O_RDWR) : O_RDONLY,
+		    0644,
+		    DB_HASH,
+		    NULL);
+    if (result != 0) {
+	T(("opened %s", path));
+    }
+#endif
+    return result;
+}
+
+/*
+ * Close the database.  Do not attempt to use the 'db' handle after this call.
+ */
+NCURSES_EXPORT(int)
+_nc_db_close(DB * db)
+{
+    int result;
+
+#if HASHED_DB_API >= 2
+    result = db->close(db, 0);
+#else
+    result = db->close(db);
+#endif
+    return result;
+}
+
+/*
+ * Write a record to the database.
+ *
+ * Returns 0 on success.
+ *
+ * FIXME:  the FreeBSD cap_mkdb program assumes the database could have
+ * duplicates.  There appears to be no good reason for that (review/fix).
+ */
+NCURSES_EXPORT(int)
+_nc_db_put(DB * db, DBT * key, DBT * data)
+{
+    int result;
+#if HASHED_DB_API >= 2
+    /* remove any pre-existing value, since we do not want duplicates */
+    (void) db->del(db, NULL, key, 0);
+    result = db->put(db, NULL, key, data, DB_NOOVERWRITE);
+#else
+    result = db->put(db, key, data, R_NOOVERWRITE);
+#endif
+    return result;
+}
+
+/*
+ * Read a record from the database.
+ *
+ * Returns 0 on success.
+ */
+NCURSES_EXPORT(int)
+_nc_db_get(DB * db, DBT * key, DBT * data)
+{
+    int result;
+
+    memset(data, 0, sizeof(*data));
+#if HASHED_DB_API >= 2
+    result = db->get(db, NULL, key, data, 0);
+#else
+    result = db->get(db, key, data, 0);
+#endif
+    return result;
+}
+
+/*
+ * Read the first record from the database, ignoring order.
+ *
+ * Returns 0 on success.
+ */
+NCURSES_EXPORT(int)
+_nc_db_first(DB * db, DBT * key, DBT * data)
+{
+    int result;
+
+    memset(key, 0, sizeof(*key));
+    memset(data, 0, sizeof(*data));
+#if HASHED_DB_API >= 2
+    if ((result = db->cursor(db, NULL, &cursor, 0)) == 0) {
+	result = cursor->c_get(cursor, key, data, DB_FIRST);
+    }
+#else
+    result = db->seq(db, key, data, 0);
+#endif
+    return result;
+}
+
+/*
+ * Read the next record from the database, ignoring order.
+ *
+ * Returns 0 on success.
+ */
+NCURSES_EXPORT(int)
+_nc_db_next(DB * db, DBT * key, DBT * data)
+{
+    int result;
+
+#if HASHED_DB_API >= 2
+    (void) db;
+    if (cursor != 0) {
+	result = cursor->c_get(cursor, key, data, DB_NEXT);
+    } else {
+	result = -1;
+    }
+#else
+    result = db->seq(db, key, data, 0);
+#endif
+    return result;
+}
+
+/*
+ * Check if a record is a terminfo index record.  Index records are those that
+ * contain only an alias pointing to a list of aliases.
+ */
+NCURSES_EXPORT(bool)
+_nc_db_have_index(DBT * key, DBT * data, char **buffer, int *size)
+{
+    bool result = FALSE;
+    int used = data->size - 1;
+    char *have = (char *) data->data;
+
+    (void) key;
+    if (*have++ == 2) {
+	result = TRUE;
+    }
+    /*
+     * Update params in any case for consistency with _nc_db_have_data().
+     */
+    *buffer = have;
+    *size = used;
+    return result;
+}
+
+/*
+ * Check if a record is the terminfo data record.  Ignore index records, e.g.,
+ * those that contain only an alias pointing to a list of aliases.
+ */
+NCURSES_EXPORT(bool)
+_nc_db_have_data(DBT * key, DBT * data, char **buffer, int *size)
+{
+    bool result = FALSE;
+    int used = data->size - 1;
+    char *have = (char *) data->data;
+
+    if (*have++ == 0) {
+	if (data->size > key->size
+	    && IS_TIC_MAGIC(have)) {
+	    result = TRUE;
+	}
+    }
+    /*
+     * Update params in any case to make it simple to follow a index record
+     * to the data record.
+     */
+    *buffer = have;
+    *size = used;
+    return result;
+}
+
+#else
+
+extern
+NCURSES_EXPORT(void)
+_nc_hashed_db(void);
+
+NCURSES_EXPORT(void)
+_nc_hashed_db(void)
+{
+}
+
+#endif /* USE_HASHED_DB */
diff --git a/ncurses/tinfo/home_terminfo.c b/ncurses/tinfo/home_terminfo.c
new file mode 100644
index 0000000..4521c4a
--- /dev/null
+++ b/ncurses/tinfo/home_terminfo.c
@@ -0,0 +1,67 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+ *	home_terminfo.c -- return the $HOME/.terminfo string, expanded
+ */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+MODULE_ID("$Id: home_terminfo.c,v 1.11 2008/08/03 23:43:11 tom Exp $")
+
+/* ncurses extension...fall back on user's private directory */
+
+#define MyBuffer _nc_globals.home_terminfo
+
+NCURSES_EXPORT(char *)
+_nc_home_terminfo(void)
+{
+    char *result = 0;
+#if USE_HOME_TERMINFO
+    char *home;
+
+    if (use_terminfo_vars()) {
+	if (MyBuffer == 0) {
+	    if ((home = getenv("HOME")) != 0) {
+		unsigned want = (strlen(home) + sizeof(PRIVATE_INFO));
+		MyBuffer = typeMalloc(char, want);
+		if (MyBuffer == 0)
+		    _nc_err_abort(MSG_NO_MEMORY);
+		(void) sprintf(MyBuffer, PRIVATE_INFO, home);
+	    }
+	}
+	result = MyBuffer;
+    }
+#endif
+    return result;
+}
diff --git a/ncurses/tinfo/init_keytry.c b/ncurses/tinfo/init_keytry.c
new file mode 100644
index 0000000..2f6fe4f
--- /dev/null
+++ b/ncurses/tinfo/init_keytry.c
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * Copyright (c) 1999-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <term.h>
+/* keypad_xmit, keypad_local, meta_on, meta_off */
+/* cursor_visible,cursor_normal,cursor_invisible */
+
+#include <tic.h>		/* struct tinfo_fkeys */
+
+#include <term_entry.h>
+
+MODULE_ID("$Id: init_keytry.c,v 1.12 2008/05/24 21:44:51 tom Exp $")
+
+/*
+**      _nc_init_keytry()
+**
+**      Construct the try for the current terminal's keypad keys.
+**
+*/
+
+/*
+ * Internal entrypoints use SCREEN* parameter to obtain capabilities rather
+ * than cur_term.
+ */
+#undef CUR
+#define CUR (sp->_term)->type.
+
+#if	BROKEN_LINKER
+#undef	_nc_tinfo_fkeys
+#endif
+
+/* LINT_PREPRO
+#if 0*/
+#include <init_keytry.h>
+/* LINT_PREPRO
+#endif*/
+
+#if	BROKEN_LINKER
+const struct tinfo_fkeys *
+_nc_tinfo_fkeysf(void)
+{
+    return _nc_tinfo_fkeys;
+}
+#endif
+
+NCURSES_EXPORT(void)
+_nc_init_keytry(SCREEN *sp)
+{
+    size_t n;
+
+    /* The sp->_keytry value is initialized in newterm(), where the sp
+     * structure is created, because we can not tell where keypad() or
+     * mouse_activate() (which will call keyok()) are first called.
+     */
+
+    if (sp != 0) {
+	for (n = 0; _nc_tinfo_fkeys[n].code; n++) {
+	    if (_nc_tinfo_fkeys[n].offset < STRCOUNT) {
+		(void) _nc_add_to_try(&(sp->_keytry),
+				      CUR Strings[_nc_tinfo_fkeys[n].offset],
+				      _nc_tinfo_fkeys[n].code);
+	    }
+	}
+#if NCURSES_XNAMES
+	/*
+	 * Add any of the extended strings to the tries if their name begins
+	 * with 'k', i.e., they follow the convention of other terminfo key
+	 * names.
+	 */
+	{
+	    TERMTYPE *tp = &(sp->_term->type);
+	    for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
+		const char *name = ExtStrname(tp, n, strnames);
+		char *value = tp->Strings[n];
+		if (name != 0
+		    && *name == 'k'
+		    && value != 0
+		    && key_defined(value) == 0) {
+		    (void) _nc_add_to_try(&(sp->_keytry),
+					  value,
+					  n - STRCOUNT + KEY_MAX);
+		}
+	    }
+	}
+#endif
+#ifdef TRACE
+	_nc_trace_tries(sp->_keytry);
+#endif
+    }
+}
diff --git a/ncurses/tinfo/lib_acs.c b/ncurses/tinfo/lib_acs.c
new file mode 100644
index 0000000..919e472
--- /dev/null
+++ b/ncurses/tinfo/lib_acs.c
@@ -0,0 +1,194 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>		/* ena_acs, acs_chars */
+
+MODULE_ID("$Id: lib_acs.c,v 1.36 2008/08/16 19:22:55 tom Exp $")
+
+#if BROKEN_LINKER || USE_REENTRANT
+#define MyBuffer _nc_prescreen.real_acs_map
+NCURSES_EXPORT_VAR(chtype *)
+_nc_acs_map(void)
+{
+    if (MyBuffer == 0)
+	MyBuffer = typeCalloc(chtype, ACS_LEN);
+    return MyBuffer;
+}
+#undef MyBuffer
+#else
+NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
+{
+    0
+};
+#endif
+
+NCURSES_EXPORT(void)
+_nc_init_acs(void)
+{
+    chtype *fake_map = acs_map;
+    chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
+    int j;
+
+    T(("initializing ACS map"));
+
+    /*
+     * If we're using this from curses (rather than terminfo), we are storing
+     * the mapping information in the SCREEN struct so we can decide how to
+     * render it.
+     */
+    if (real_map != fake_map) {
+	for (j = 1; j < ACS_LEN; ++j) {
+	    real_map[j] = 0;
+	    fake_map[j] = A_ALTCHARSET | j;
+	    if (SP)
+		SP->_screen_acs_map[j] = FALSE;
+	}
+    } else {
+	for (j = 1; j < ACS_LEN; ++j) {
+	    real_map[j] = 0;
+	}
+    }
+
+    /*
+     * Initializations for a UNIX-like multi-terminal environment.  Use
+     * ASCII chars and count on the terminfo description to do better.
+     */
+    real_map['l'] = '+';	/* should be upper left corner */
+    real_map['m'] = '+';	/* should be lower left corner */
+    real_map['k'] = '+';	/* should be upper right corner */
+    real_map['j'] = '+';	/* should be lower right corner */
+    real_map['u'] = '+';	/* should be tee pointing left */
+    real_map['t'] = '+';	/* should be tee pointing right */
+    real_map['v'] = '+';	/* should be tee pointing up */
+    real_map['w'] = '+';	/* should be tee pointing down */
+    real_map['q'] = '-';	/* should be horizontal line */
+    real_map['x'] = '|';	/* should be vertical line */
+    real_map['n'] = '+';	/* should be large plus or crossover */
+    real_map['o'] = '~';	/* should be scan line 1 */
+    real_map['s'] = '_';	/* should be scan line 9 */
+    real_map['`'] = '+';	/* should be diamond */
+    real_map['a'] = ':';	/* should be checker board (stipple) */
+    real_map['f'] = '\'';	/* should be degree symbol */
+    real_map['g'] = '#';	/* should be plus/minus */
+    real_map['~'] = 'o';	/* should be bullet */
+    real_map[','] = '<';	/* should be arrow pointing left */
+    real_map['+'] = '>';	/* should be arrow pointing right */
+    real_map['.'] = 'v';	/* should be arrow pointing down */
+    real_map['-'] = '^';	/* should be arrow pointing up */
+    real_map['h'] = '#';	/* should be board of squares */
+    real_map['i'] = '#';	/* should be lantern symbol */
+    real_map['0'] = '#';	/* should be solid square block */
+    /* these defaults were invented for ncurses */
+    real_map['p'] = '-';	/* should be scan line 3 */
+    real_map['r'] = '-';	/* should be scan line 7 */
+    real_map['y'] = '<';	/* should be less-than-or-equal-to */
+    real_map['z'] = '>';	/* should be greater-than-or-equal-to */
+    real_map['{'] = '*';	/* should be greek pi */
+    real_map['|'] = '!';	/* should be not-equal */
+    real_map['}'] = 'f';	/* should be pound-sterling symbol */
+
+    if (ena_acs != NULL) {
+	TPUTS_TRACE("ena_acs");
+	putp(ena_acs);
+    }
+#if NCURSES_EXT_FUNCS
+    /*
+     * Linux console "supports" the "PC ROM" character set by the coincidence
+     * that smpch/rmpch and smacs/rmacs have the same values.  ncurses has
+     * no codepage support (see SCO Merge for an example).  Outside of the
+     * values defined in acsc, there are no definitions for the "PC ROM"
+     * character set (assumed by some applications to be codepage 437), but we
+     * allow those applications to use those codepoints.
+     *
+     * test/blue.c uses this feature.
+     */
+#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
+    if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
+	PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
+	size_t i;
+	for (i = 1; i < ACS_LEN; ++i) {
+	    if (real_map[i] == 0) {
+		real_map[i] = i;
+		if (real_map != fake_map) {
+		    if (SP != 0)
+			SP->_screen_acs_map[i] = TRUE;
+		}
+	    }
+	}
+    }
+#endif
+
+    if (acs_chars != NULL) {
+	size_t i = 0;
+	size_t length = strlen(acs_chars);
+
+	while (i + 1 < length) {
+	    if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
+		real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
+		if (SP != 0)
+		    SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
+	    }
+	    i += 2;
+	}
+    }
+#ifdef TRACE
+    /* Show the equivalent mapping, noting if it does not match the
+     * given attribute, whether by re-ordering or duplication.
+     */
+    if (USE_TRACEF(TRACE_CALLS)) {
+	size_t n, m;
+	char show[ACS_LEN * 2 + 1];
+	for (n = 1, m = 0; n < ACS_LEN; n++) {
+	    if (real_map[n] != 0) {
+		show[m++] = (char) n;
+		show[m++] = (char) ChCharOf(real_map[n]);
+	    }
+	}
+	show[m] = 0;
+	if (acs_chars == NULL || strcmp(acs_chars, show))
+	    _tracef("%s acs_chars %s",
+		    (acs_chars == NULL) ? "NULL" : "READ",
+		    _nc_visbuf(acs_chars));
+	_tracef("%s acs_chars %s",
+		(acs_chars == NULL)
+		? "NULL"
+		: (strcmp(acs_chars, show)
+		   ? "DIFF"
+		   : "SAME"),
+		_nc_visbuf(show));
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+}
diff --git a/ncurses/tinfo/lib_baudrate.c b/ncurses/tinfo/lib_baudrate.c
new file mode 100644
index 0000000..b9cdfda
--- /dev/null
+++ b/ncurses/tinfo/lib_baudrate.c
@@ -0,0 +1,238 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	lib_baudrate.c
+ *
+ */
+
+#include <curses.priv.h>
+#include <term.h>		/* cur_term, pad_char */
+#include <termcap.h>		/* ospeed */
+#if defined(__FreeBSD__)
+#include <sys/param.h>
+#endif
+
+/*
+ * These systems use similar header files, which define B1200 as 1200, etc.,
+ * but can be overridden by defining USE_OLD_TTY so B1200 is 9, which makes all
+ * of the indices up to B115200 fit nicely in a 'short', allowing us to retain
+ * ospeed's type for compatibility.
+ */
+#if (defined(__FreeBSD__) && (__FreeBSD_version < 700000)) || defined(__NetBSD__) || defined(__OpenBSD__)
+#undef B0
+#undef B50
+#undef B75
+#undef B110
+#undef B134
+#undef B150
+#undef B200
+#undef B300
+#undef B600
+#undef B1200
+#undef B1800
+#undef B2400
+#undef B4800
+#undef B9600
+#undef B19200
+#undef EXTA
+#undef B38400
+#undef EXTB
+#undef B57600
+#undef B115200
+#undef B230400
+#undef B460800
+#undef B921600
+#define USE_OLD_TTY
+#include <sys/ttydev.h>
+#else
+#undef USE_OLD_TTY
+#endif /* USE_OLD_TTY */
+
+MODULE_ID("$Id: lib_baudrate.c,v 1.27 2008/06/28 15:19:24 tom Exp $")
+
+/*
+ *	int
+ *	baudrate()
+ *
+ *	Returns the current terminal's baud rate.
+ *
+ */
+
+struct speed {
+    int s;			/* value for 'ospeed' is an index */
+    int sp;			/* the actual speed */
+};
+
+static struct speed const speeds[] =
+{
+    {B0, 0},
+    {B50, 50},
+    {B75, 75},
+    {B110, 110},
+    {B134, 134},
+    {B150, 150},
+    {B200, 200},
+    {B300, 300},
+    {B600, 600},
+    {B1200, 1200},
+    {B1800, 1800},
+    {B2400, 2400},
+    {B4800, 4800},
+    {B9600, 9600},
+#ifdef B19200
+    {B19200, 19200},
+#else
+#ifdef EXTA
+    {EXTA, 19200},
+#endif
+#endif
+#ifdef B38400
+    {B38400, 38400},
+#else
+#ifdef EXTB
+    {EXTB, 38400},
+#endif
+#endif
+#ifdef B57600
+    {B57600, 57600},
+#endif
+#ifdef B115200
+    {B115200, 115200},
+#endif
+#ifdef B230400
+    {B230400, 230400},
+#endif
+#ifdef B460800
+    {B460800, 460800},
+#endif
+#ifdef B921600
+    {B921600, 921600},
+#endif
+};
+
+NCURSES_EXPORT(int)
+_nc_baudrate(int OSpeed)
+{
+#if !USE_REENTRANT
+    static int last_OSpeed;
+    static int last_baudrate;
+#endif
+
+    int result = ERR;
+    unsigned i;
+
+#if !USE_REENTRANT
+    if (OSpeed == last_OSpeed) {
+	result = last_baudrate;
+    }
+#endif
+    if (result == ERR) {
+	if (OSpeed >= 0) {
+	    for (i = 0; i < SIZEOF(speeds); i++) {
+		if (speeds[i].s == OSpeed) {
+		    result = speeds[i].sp;
+		    break;
+		}
+	    }
+	}
+#if !USE_REENTRANT
+	if (OSpeed == last_OSpeed) {
+	    last_OSpeed = OSpeed;
+	    last_baudrate = result;
+	}
+#endif
+    }
+    return (result);
+}
+
+NCURSES_EXPORT(int)
+_nc_ospeed(int BaudRate)
+{
+    int result = 1;
+    unsigned i;
+
+    if (BaudRate >= 0) {
+	for (i = 0; i < SIZEOF(speeds); i++) {
+	    if (speeds[i].sp == BaudRate) {
+		result = speeds[i].s;
+		break;
+	    }
+	}
+    }
+    return (result);
+}
+
+NCURSES_EXPORT(int)
+baudrate(void)
+{
+    int result;
+
+    T((T_CALLED("baudrate()")));
+
+    /*
+     * In debugging, allow the environment symbol to override when we're
+     * redirecting to a file, so we can construct repeatable test-cases
+     * that take into account costs that depend on baudrate.
+     */
+#ifdef TRACE
+    if (!isatty(fileno(SP ? SP->_ofp : stdout))
+	&& getenv("BAUDRATE") != 0) {
+	int ret;
+	if ((ret = _nc_getenv_num("BAUDRATE")) <= 0)
+	    ret = 9600;
+	ospeed = _nc_ospeed(ret);
+	returnCode(ret);
+    }
+#endif
+
+    if (cur_term != 0) {
+#ifdef USE_OLD_TTY
+	result = cfgetospeed(&cur_term->Nttyb);
+	ospeed = _nc_ospeed(result);
+#else /* !USE_OLD_TTY */
+#ifdef TERMIOS
+	ospeed = cfgetospeed(&cur_term->Nttyb);
+#else
+	ospeed = cur_term->Nttyb.sg_ospeed;
+#endif
+	result = _nc_baudrate(ospeed);
+#endif
+	cur_term->_baudrate = result;
+    } else {
+	result = ERR;
+    }
+
+    returnCode(result);
+}
diff --git a/ncurses/tinfo/lib_cur_term.c b/ncurses/tinfo/lib_cur_term.c
new file mode 100644
index 0000000..626578d
--- /dev/null
+++ b/ncurses/tinfo/lib_cur_term.c
@@ -0,0 +1,105 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ ****************************************************************************/
+/*
+ * Module that "owns" the 'cur_term' variable:
+ *
+ *	TERMINAL *set_curterm(TERMINAL *)
+ *	int del_curterm(TERMINAL *)
+ */
+
+#include <curses.priv.h>
+#include <term_entry.h>		/* TTY, cur_term */
+#include <termcap.h>		/* ospeed */
+
+MODULE_ID("$Id: lib_cur_term.c,v 1.18 2008/08/16 19:22:55 tom Exp $")
+
+#undef CUR
+#define CUR termp->type.
+
+#if BROKEN_LINKER || USE_REENTRANT
+NCURSES_EXPORT(TERMINAL *)
+NCURSES_PUBLIC_VAR(cur_term) (void)
+{
+    return (SP != 0 && SP->_term != 0) ? SP->_term : _nc_prescreen._cur_term;
+}
+#else
+NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0;
+#endif
+
+NCURSES_EXPORT(TERMINAL *)
+set_curterm(TERMINAL * termp)
+{
+    TERMINAL *oldterm;
+
+    T((T_CALLED("set_curterm(%p)"), termp));
+
+    _nc_lock_global(curses);
+    oldterm = cur_term;
+    if (SP)
+	SP->_term = termp;
+#if BROKEN_LINKER || USE_REENTRANT
+    _nc_prescreen._cur_term = termp;
+#else
+    cur_term = termp;
+#endif
+    if (termp != 0) {
+	ospeed = _nc_ospeed(termp->_baudrate);
+	if (termp->type.Strings) {
+	    PC = (char) ((pad_char != NULL) ? pad_char[0] : 0);
+	}
+    }
+    _nc_unlock_global(curses);
+
+    T((T_RETURN("%p"), oldterm));
+    return (oldterm);
+}
+
+NCURSES_EXPORT(int)
+del_curterm(TERMINAL * termp)
+{
+    int rc = ERR;
+
+    T((T_CALLED("del_curterm(%p)"), termp));
+
+    _nc_lock_global(curses);
+    if (termp != 0) {
+	_nc_free_termtype(&(termp->type));
+	FreeIfNeeded(termp->_termname);
+	free(termp);
+	if (termp == cur_term)
+	    set_curterm(0);
+	rc = OK;
+    }
+    _nc_unlock_global(curses);
+
+    returnCode(rc);
+}
diff --git a/ncurses/tinfo/lib_data.c b/ncurses/tinfo/lib_data.c
new file mode 100644
index 0000000..e84209d
--- /dev/null
+++ b/ncurses/tinfo/lib_data.c
@@ -0,0 +1,332 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_data.c
+**
+**	Common data that may/may not be allocated, but is referenced globally
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_data.c,v 1.52 2008/08/23 22:16:15 tom Exp $")
+
+/*
+ * OS/2's native linker complains if we don't initialize public data when
+ * constructing a dll (reported by J.J.G.Ripoll).
+ */
+#if USE_REENTRANT
+NCURSES_EXPORT(WINDOW *)
+NCURSES_PUBLIC_VAR(stdscr) (void)
+{
+    return SP ? SP->_stdscr : 0;
+}
+NCURSES_EXPORT(WINDOW *)
+NCURSES_PUBLIC_VAR(curscr) (void)
+{
+    return SP ? SP->_curscr : 0;
+}
+NCURSES_EXPORT(WINDOW *)
+NCURSES_PUBLIC_VAR(newscr) (void)
+{
+    return SP ? SP->_newscr : 0;
+}
+#else
+NCURSES_EXPORT_VAR(WINDOW *) stdscr = 0;
+NCURSES_EXPORT_VAR(WINDOW *) curscr = 0;
+NCURSES_EXPORT_VAR(WINDOW *) newscr = 0;
+#endif
+
+NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0;
+
+/*
+ * The variable 'SP' will be defined as a function on systems that cannot link
+ * data-only modules, since it is used in a lot of places within ncurses and we
+ * cannot guarantee that any application will use any particular function.  We
+ * put the WINDOW variables in this module, because it appears that any
+ * application that uses them will also use 'SP'.
+ *
+ * This module intentionally does not reference other ncurses modules, to avoid
+ * module coupling that increases the size of the executable.
+ */
+#if BROKEN_LINKER
+static SCREEN *my_screen;
+
+NCURSES_EXPORT(SCREEN *)
+_nc_screen(void)
+{
+    return my_screen;
+}
+
+NCURSES_EXPORT(int)
+_nc_alloc_screen(void)
+{
+    return ((my_screen = typeCalloc(SCREEN, 1)) != 0);
+}
+
+NCURSES_EXPORT(void)
+_nc_set_screen(SCREEN *sp)
+{
+    my_screen = sp;
+}
+
+#else
+NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */
+#endif
+/* *INDENT-OFF* */
+#define CHARS_0s { '\0' }
+
+#define TGETENT_0 { 0L, FALSE, NULL, NULL, NULL }
+#define TGETENT_0s { TGETENT_0, TGETENT_0, TGETENT_0, TGETENT_0 }
+
+NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = {
+    0,				/* have_sigwinch */
+    0,				/* cleanup_nested */
+
+    FALSE,			/* init_signals */
+    FALSE,			/* init_screen */
+
+    NULL,			/* comp_sourcename */
+    NULL,			/* comp_termtype */
+
+    FALSE,			/* have_tic_directory */
+    FALSE,			/* keep_tic_directory */
+    TERMINFO,			/* tic_directory */
+
+    NULL,			/* dbi_list */
+    0,				/* dbi_size */
+
+    NULL,			/* first_name */
+    NULL,			/* keyname_table */
+
+    0,				/* slk_format */
+
+    NULL,			/* safeprint_buf */
+    0,				/* safeprint_used */
+
+    TGETENT_0s,			/* tgetent_cache */
+    0,				/* tgetent_index */
+    0,				/* tgetent_sequence */
+
+    0,				/* _nc_windowlist */
+
+#if USE_HOME_TERMINFO
+    NULL,			/* home_terminfo */
+#endif
+
+#if !USE_SAFE_SPRINTF
+    0,				/* safeprint_cols */
+    0,				/* safeprint_rows */
+#endif
+
+#ifdef TRACE
+    FALSE,			/* init_trace */
+    CHARS_0s,			/* trace_fname */
+    0,				/* trace_level */
+    NULL,			/* trace_fp */
+
+    NULL,			/* tracearg_buf */
+    0,				/* tracearg_used */
+
+    NULL,			/* tracebuf_ptr */
+    0,				/* tracebuf_used */
+
+    CHARS_0s,			/* tracechr_buf */
+
+    NULL,			/* tracedmp_buf */
+    0,				/* tracedmp_used */
+
+    NULL,			/* tracetry_buf */
+    0,				/* tracetry_used */
+
+    { CHARS_0s, CHARS_0s },	/* traceatr_color_buf */
+    0,				/* traceatr_color_sel */
+    -1,				/* traceatr_color_last */
+
+#endif /* TRACE */
+#ifdef USE_PTHREADS
+    PTHREAD_MUTEX_INITIALIZER,	/* mutex_curses */
+    PTHREAD_MUTEX_INITIALIZER,	/* mutex_tst_tracef */
+    PTHREAD_MUTEX_INITIALIZER,	/* mutex_tracef */
+    0,				/* nested_tracef */
+    0,				/* use_pthreads */
+#endif
+};
+
+#define STACK_FRAME_0	{ { 0 }, 0 }
+#define STACK_FRAME_0s	{ STACK_FRAME_0 }
+#define NUM_VARS_0s	{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
+
+#define RIPOFF_0	{ 0,0,0 }
+#define RIPOFF_0s	{ RIPOFF_0 }
+
+NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = {
+    TRUE,			/* use_env */
+    FALSE,			/* filter_mode */
+    A_NORMAL,			/* previous_attr */
+    RIPOFF_0s,			/* ripoff */
+    NULL,			/* rsp */
+    {				/* tparm_state */
+#ifdef TRACE
+	NULL,			/* tname */
+#endif
+	NULL,			/* tparam_base */
+
+	STACK_FRAME_0s,		/* stack */
+	0,			/* stack_ptr */
+
+	NULL,			/* out_buff */
+	0,			/* out_size */
+	0,			/* out_used */
+
+	NULL,			/* fmt_buff */
+	0,			/* fmt_size */
+
+	NUM_VARS_0s,		/* dynamic_var */
+	NUM_VARS_0s,		/* static_vars */
+    },
+    NULL,			/* saved_tty */
+#if NCURSES_NO_PADDING
+    FALSE,			/* flag to set if padding disabled  */
+#endif
+#if BROKEN_LINKER || USE_REENTRANT
+    NULL,			/* real_acs_map */
+    0,				/* LINES */
+    0,				/* COLS */
+    0,				/* cur_term */
+#ifdef TRACE
+    0L,				/* _outchars */
+    NULL,			/* _tputs_trace */
+#endif
+#endif
+};
+/* *INDENT-ON* */
+
+/******************************************************************************/
+#ifdef USE_PTHREADS
+static void
+init_global_mutexes(void)
+{
+    static bool initialized = FALSE;
+
+    if (!initialized) {
+	initialized = TRUE;
+	_nc_mutex_init(&_nc_globals.mutex_curses);
+	_nc_mutex_init(&_nc_globals.mutex_tst_tracef);
+	_nc_mutex_init(&_nc_globals.mutex_tracef);
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_init_pthreads(void)
+{
+    if (_nc_use_pthreads)
+	return;
+# if USE_WEAK_SYMBOLS
+    if ((pthread_mutex_init) == 0)
+	return;
+    if ((pthread_mutex_lock) == 0)
+	return;
+    if ((pthread_mutex_unlock) == 0)
+	return;
+    if ((pthread_mutex_trylock) == 0)
+	return;
+    if ((pthread_mutexattr_settype) == 0)
+	return;
+# endif
+    _nc_use_pthreads = 1;
+    init_global_mutexes();
+}
+
+/*
+ * Use recursive mutexes if we have them - they're part of Unix98.
+ * For the cases where we do not, _nc_mutex_trylock() is used to avoid a
+ * deadlock, at the expense of memory leaks and unexpected failures that
+ * may not be handled by typical clients.
+ *
+ * FIXME - need configure check for PTHREAD_MUTEX_RECURSIVE, define it to
+ * PTHREAD_MUTEX_NORMAL if not supported.
+ */
+NCURSES_EXPORT(void)
+_nc_mutex_init(pthread_mutex_t * obj)
+{
+    pthread_mutexattr_t recattr;
+
+    if (_nc_use_pthreads) {
+	pthread_mutexattr_init(&recattr);
+	pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_RECURSIVE);
+	pthread_mutex_init(obj, &recattr);
+    }
+}
+
+NCURSES_EXPORT(int)
+_nc_mutex_lock(pthread_mutex_t * obj)
+{
+    if (_nc_use_pthreads == 0)
+	return 0;
+    return pthread_mutex_lock(obj);
+}
+
+NCURSES_EXPORT(int)
+_nc_mutex_trylock(pthread_mutex_t * obj)
+{
+    if (_nc_use_pthreads == 0)
+	return 0;
+    return pthread_mutex_trylock(obj);
+}
+
+NCURSES_EXPORT(int)
+_nc_mutex_unlock(pthread_mutex_t * obj)
+{
+    if (_nc_use_pthreads == 0)
+	return 0;
+    return pthread_mutex_unlock(obj);
+}
+
+#if USE_WEAK_SYMBOLS
+/*
+ * NB: sigprocmask(2) is global but pthread_sigmask(3p)
+ * only for the calling thread.
+ */
+NCURSES_EXPORT(int)
+_nc_sigprocmask(int how, const sigset_t * newmask, sigset_t * oldmask)
+{
+    if ((pthread_sigmask))
+	return pthread_sigmask(how, newmask, oldmask);
+    else
+	return sigprocmask(how, newmask, oldmask);
+}
+#endif
+#endif /* USE_PTHREADS */
diff --git a/ncurses/tinfo/lib_has_cap.c b/ncurses/tinfo/lib_has_cap.c
new file mode 100644
index 0000000..0dc66bd
--- /dev/null
+++ b/ncurses/tinfo/lib_has_cap.c
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-2003               *
+ ****************************************************************************/
+
+/*
+**	lib_has_cap.c
+**
+**	The routines to query terminal capabilities
+**
+*/
+
+#include <curses.priv.h>
+
+#include <term.h>
+
+MODULE_ID("$Id: lib_has_cap.c,v 1.4 2003/10/25 19:43:55 tom Exp $")
+
+NCURSES_EXPORT(bool)
+has_ic(void)
+{
+    T((T_CALLED("has_ic()")));
+    returnCode(cur_term &&
+	       (insert_character || parm_ich
+		|| (enter_insert_mode && exit_insert_mode))
+	       && (delete_character || parm_dch));
+}
+
+NCURSES_EXPORT(bool)
+has_il(void)
+{
+    T((T_CALLED("has_il()")));
+    returnCode(cur_term
+	       && (insert_line || parm_insert_line)
+	       && (delete_line || parm_delete_line));
+}
diff --git a/ncurses/tinfo/lib_kernel.c b/ncurses/tinfo/lib_kernel.c
new file mode 100644
index 0000000..89dc1e8
--- /dev/null
+++ b/ncurses/tinfo/lib_kernel.c
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey 2002                                           *
+ ****************************************************************************/
+
+/*
+ *	lib_kernel.c
+ *
+ *	Misc. low-level routines:
+ *		erasechar()
+ *		killchar()
+ *		flushinp()
+ *
+ * The baudrate() and delay_output() functions could logically live here,
+ * but are in other modules to reduce the static-link size of programs
+ * that use only these facilities.
+ */
+
+#include <curses.priv.h>
+#include <term.h>		/* cur_term */
+
+MODULE_ID("$Id: lib_kernel.c,v 1.24 2004/05/08 17:11:21 tom Exp $")
+
+static int
+_nc_vdisable(void)
+{
+    int value = -1;
+#if defined(_POSIX_VDISABLE) && HAVE_UNISTD_H
+    value = _POSIX_VDISABLE;
+#endif
+#if defined(_PC_VDISABLE)
+    if (value == -1) {
+	value = fpathconf(0, _PC_VDISABLE);
+	if (value == -1) {
+	    value = 0377;
+	}
+    }
+#elif defined(VDISABLE)
+    if (value == -1)
+	value = VDISABLE;
+#endif
+    return value;
+}
+
+/*
+ *	erasechar()
+ *
+ *	Return erase character as given in cur_term->Ottyb.
+ *
+ */
+
+NCURSES_EXPORT(char)
+erasechar(void)
+{
+    int result = ERR;
+    T((T_CALLED("erasechar()")));
+
+    if (cur_term != 0) {
+#ifdef TERMIOS
+	result = cur_term->Ottyb.c_cc[VERASE];
+	if (result == _nc_vdisable())
+	    result = ERR;
+#else
+	result = cur_term->Ottyb.sg_erase;
+#endif
+    }
+    returnCode(result);
+}
+
+/*
+ *	killchar()
+ *
+ *	Return kill character as given in cur_term->Ottyb.
+ *
+ */
+
+NCURSES_EXPORT(char)
+killchar(void)
+{
+    int result = ERR;
+    T((T_CALLED("killchar()")));
+
+    if (cur_term != 0) {
+#ifdef TERMIOS
+	result = cur_term->Ottyb.c_cc[VKILL];
+	if (result == _nc_vdisable())
+	    result = ERR;
+#else
+	result = cur_term->Ottyb.sg_kill;
+#endif
+    }
+    returnCode(result);
+}
+
+/*
+ *	flushinp()
+ *
+ *	Flush any input on cur_term->Filedes
+ *
+ */
+
+NCURSES_EXPORT(int)
+flushinp(void)
+{
+    T((T_CALLED("flushinp()")));
+
+    if (cur_term != 0) {
+#ifdef TERMIOS
+	tcflush(cur_term->Filedes, TCIFLUSH);
+#else
+	errno = 0;
+	do {
+	    ioctl(cur_term->Filedes, TIOCFLUSH, 0);
+	} while
+	    (errno == EINTR);
+#endif
+	if (SP) {
+	    SP->_fifohead = -1;
+	    SP->_fifotail = 0;
+	    SP->_fifopeek = 0;
+	}
+	returnCode(OK);
+    }
+    returnCode(ERR);
+}
diff --git a/ncurses/tinfo/lib_longname.c b/ncurses/tinfo/lib_longname.c
new file mode 100644
index 0000000..1301ee5
--- /dev/null
+++ b/ncurses/tinfo/lib_longname.c
@@ -0,0 +1,57 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	lib_longname.c
+**
+**	The routine longname().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_longname.c,v 1.9 2000/12/10 02:55:07 tom Exp $")
+
+NCURSES_EXPORT(char *)
+longname(void)
+{
+    char *ptr;
+
+    T((T_CALLED("longname()")));
+
+    for (ptr = ttytype + strlen(ttytype); ptr > ttytype; ptr--)
+	if (*ptr == '|')
+	    returnPtr(ptr + 1);
+
+    returnPtr(ttytype);
+}
diff --git a/ncurses/tinfo/lib_napms.c b/ncurses/tinfo/lib_napms.c
new file mode 100644
index 0000000..417b3b4
--- /dev/null
+++ b/ncurses/tinfo/lib_napms.c
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	lib_napms.c
+ *
+ *	The routine napms.
+ *
+ *	(This file was originally written by Eric Raymond; however except for
+ *	comments, none of the original code remains - T.Dickey).
+ */
+
+#include <curses.priv.h>
+
+#if HAVE_NANOSLEEP
+#include <time.h>
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>		/* needed for MacOS X DP3 */
+#endif
+#endif
+
+MODULE_ID("$Id: lib_napms.c,v 1.17 2008/05/03 21:34:13 tom Exp $")
+
+NCURSES_EXPORT(int)
+napms(int ms)
+{
+    T((T_CALLED("napms(%d)"), ms));
+
+#if HAVE_NANOSLEEP
+    {
+	struct timespec request, remaining;
+	request.tv_sec = ms / 1000;
+	request.tv_nsec = (ms % 1000) * 1000000;
+	while (nanosleep(&request, &remaining) == -1
+	       && errno == EINTR) {
+	    request = remaining;
+	}
+    }
+#else
+    _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
+#endif
+
+    returnCode(OK);
+}
diff --git a/ncurses/tinfo/lib_options.c b/ncurses/tinfo/lib_options.c
new file mode 100644
index 0000000..f3b1485
--- /dev/null
+++ b/ncurses/tinfo/lib_options.c
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_options.c
+**
+**	The routines to handle option setting.
+**
+*/
+
+#include <curses.priv.h>
+
+#include <term.h>
+
+MODULE_ID("$Id: lib_options.c,v 1.58 2008/08/16 21:20:48 Werner.Fink Exp $")
+
+static int _nc_curs_set(SCREEN *, int);
+static int _nc_meta(SCREEN *, bool);
+
+NCURSES_EXPORT(int)
+idlok(WINDOW *win, bool flag)
+{
+    T((T_CALLED("idlok(%p,%d)"), win, flag));
+
+    if (win) {
+	_nc_idlok = win->_idlok = (flag && (has_il() || change_scroll_region));
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
+
+NCURSES_EXPORT(void)
+idcok(WINDOW *win, bool flag)
+{
+    T((T_CALLED("idcok(%p,%d)"), win, flag));
+
+    if (win)
+	_nc_idcok = win->_idcok = (flag && has_ic());
+
+    returnVoid;
+}
+
+NCURSES_EXPORT(int)
+halfdelay(int t)
+{
+    T((T_CALLED("halfdelay(%d)"), t));
+
+    if (t < 1 || t > 255 || SP == 0)
+	returnCode(ERR);
+
+    cbreak();
+    SP->_cbreak = t + 1;
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+nodelay(WINDOW *win, bool flag)
+{
+    T((T_CALLED("nodelay(%p,%d)"), win, flag));
+
+    if (win) {
+	if (flag == TRUE)
+	    win->_delay = 0;
+	else
+	    win->_delay = -1;
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
+
+NCURSES_EXPORT(int)
+notimeout(WINDOW *win, bool f)
+{
+    T((T_CALLED("notimeout(%p,%d)"), win, f));
+
+    if (win) {
+	win->_notimeout = f;
+	returnCode(OK);
+    } else
+	returnCode(ERR);
+}
+
+NCURSES_EXPORT(void)
+wtimeout(WINDOW *win, int delay)
+{
+    T((T_CALLED("wtimeout(%p,%d)"), win, delay));
+
+    if (win) {
+	win->_delay = delay;
+    }
+    returnVoid;
+}
+
+NCURSES_EXPORT(int)
+keypad(WINDOW *win, bool flag)
+{
+    T((T_CALLED("keypad(%p,%d)"), win, flag));
+
+    if (win) {
+	win->_use_keypad = flag;
+	returnCode(_nc_keypad(SP, flag));
+    } else
+	returnCode(ERR);
+}
+
+NCURSES_EXPORT(int)
+meta(WINDOW *win GCC_UNUSED, bool flag)
+{
+    int result;
+
+    /* Ok, we stay relaxed and don't signal an error if win is NULL */
+    T((T_CALLED("meta(%p,%d)"), win, flag));
+    result = _nc_meta(SP, flag);
+    returnCode(result);
+}
+
+/* curs_set() moved here to narrow the kernel interface */
+
+NCURSES_EXPORT(int)
+curs_set(int vis)
+{
+    int result;
+
+    T((T_CALLED("curs_set(%d)"), vis));
+    result = _nc_curs_set(SP, vis);
+    returnCode(result);
+}
+
+NCURSES_EXPORT(int)
+typeahead(int fd)
+{
+    T((T_CALLED("typeahead(%d)"), fd));
+    if (SP != 0) {
+	SP->_checkfd = fd;
+	returnCode(OK);
+    } else {
+	returnCode(ERR);
+    }
+}
+
+/*
+**      has_key()
+**
+**      Return TRUE if the current terminal has the given key
+**
+*/
+
+#if NCURSES_EXT_FUNCS
+static int
+has_key_internal(int keycode, TRIES * tp)
+{
+    if (tp == 0)
+	return (FALSE);
+    else if (tp->value == keycode)
+	return (TRUE);
+    else
+	return (has_key_internal(keycode, tp->child)
+		|| has_key_internal(keycode, tp->sibling));
+}
+
+NCURSES_EXPORT(int)
+has_key(int keycode)
+{
+    T((T_CALLED("has_key(%d)"), keycode));
+    returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE);
+}
+#endif /* NCURSES_EXT_FUNCS */
+
+/*
+ * Internal entrypoints use SCREEN* parameter to obtain capabilities rather
+ * than cur_term.
+ */
+#undef CUR
+#define CUR (sp->_term)->type.
+
+static int
+_nc_putp(const char *name GCC_UNUSED, const char *value)
+{
+    int rc = ERR;
+
+    if (value) {
+	TPUTS_TRACE(name);
+	rc = putp(value);
+    }
+    return rc;
+}
+
+static int
+_nc_putp_flush(const char *name, const char *value)
+{
+    int rc = _nc_putp(name, value);
+    if (rc != ERR) {
+	_nc_flush();
+    }
+    return rc;
+}
+
+/* Turn the keypad on/off
+ *
+ * Note:  we flush the output because changing this mode causes some terminals
+ * to emit different escape sequences for cursor and keypad keys.  If we don't
+ * flush, then the next wgetch may get the escape sequence that corresponds to
+ * the terminal state _before_ switching modes.
+ */
+NCURSES_EXPORT(int)
+_nc_keypad(SCREEN *sp, bool flag)
+{
+    int rc = ERR;
+
+    if (sp != 0) {
+#ifdef USE_PTHREADS
+	/*
+	 * We might have this situation in a multithreaded application that
+	 * has wgetch() reading in more than one thread.  putp() and below
+	 * may use SP explicitly.
+	 */
+	if (_nc_use_pthreads && sp != SP) {
+	    SCREEN *save_sp;
+
+	    /* cannot use use_screen(), since that is not in tinfo library */
+	    _nc_lock_global(curses);
+	    save_sp = SP;
+	    _nc_set_screen(sp);
+	    rc = _nc_keypad(sp, flag);
+	    _nc_set_screen(save_sp);
+	    _nc_unlock_global(curses);
+	} else
+#endif
+	{
+	    if (flag) {
+		(void) _nc_putp_flush("keypad_xmit", keypad_xmit);
+	    } else if (!flag && keypad_local) {
+		(void) _nc_putp_flush("keypad_local", keypad_local);
+	    }
+
+	    if (flag && !sp->_tried) {
+		_nc_init_keytry(sp);
+		sp->_tried = TRUE;
+	    }
+	    sp->_keypad_on = flag;
+	    rc = OK;
+	}
+    }
+    return (rc);
+}
+
+static int
+_nc_curs_set(SCREEN *sp, int vis)
+{
+    int result = ERR;
+
+    T((T_CALLED("curs_set(%d)"), vis));
+    if (sp != 0 && vis >= 0 && vis <= 2) {
+	int cursor = sp->_cursor;
+
+	if (vis == cursor) {
+	    result = cursor;
+	} else {
+	    switch (vis) {
+	    case 2:
+		result = _nc_putp_flush("cursor_visible", cursor_visible);
+		break;
+	    case 1:
+		result = _nc_putp_flush("cursor_normal", cursor_normal);
+		break;
+	    case 0:
+		result = _nc_putp_flush("cursor_invisible", cursor_invisible);
+		break;
+	    }
+	    if (result != ERR)
+		result = (cursor == -1 ? 1 : cursor);
+	    sp->_cursor = vis;
+	}
+    }
+    returnCode(result);
+}
+
+static int
+_nc_meta(SCREEN *sp, bool flag)
+{
+    int result = ERR;
+
+    /* Ok, we stay relaxed and don't signal an error if win is NULL */
+
+    if (SP != 0) {
+	SP->_use_meta = flag;
+
+	if (flag) {
+	    _nc_putp("meta_on", meta_on);
+	} else {
+	    _nc_putp("meta_off", meta_off);
+	}
+	result = OK;
+    }
+    return result;
+}
diff --git a/ncurses/tinfo/lib_print.c b/ncurses/tinfo/lib_print.c
new file mode 100644
index 0000000..975b46d
--- /dev/null
+++ b/ncurses/tinfo/lib_print.c
@@ -0,0 +1,92 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <term.h>
+
+MODULE_ID("$Id: lib_print.c,v 1.16 2006/11/26 00:26:34 tom Exp $")
+
+NCURSES_EXPORT(int)
+mcprint(char *data, int len)
+/* ship binary character data to the printer via mc4/mc5/mc5p */
+{
+    char *mybuf, *switchon;
+    size_t onsize, offsize, res;
+
+    errno = 0;
+    if (!cur_term || (!prtr_non && (!prtr_on || !prtr_off))) {
+	errno = ENODEV;
+	return (ERR);
+    }
+
+    if (prtr_non) {
+	switchon = TPARM_1(prtr_non, len);
+	onsize = strlen(switchon);
+	offsize = 0;
+    } else {
+	switchon = prtr_on;
+	onsize = strlen(prtr_on);
+	offsize = strlen(prtr_off);
+    }
+
+    if (switchon == 0
+	|| (mybuf = typeMalloc(char, onsize + len + offsize + 1)) == 0) {
+	errno = ENOMEM;
+	return (ERR);
+    }
+
+    (void) strcpy(mybuf, switchon);
+    memcpy(mybuf + onsize, data, (unsigned) len);
+    if (offsize)
+	(void) strcpy(mybuf + onsize + len, prtr_off);
+
+    /*
+     * We're relying on the atomicity of UNIX writes here.  The
+     * danger is that output from a refresh() might get interspersed
+     * with the printer data after the write call returns but before the
+     * data has actually been shipped to the terminal.  If the write(2)
+     * operation is truly atomic we're protected from this.
+     */
+    res = write(cur_term->Filedes, mybuf, onsize + len + offsize);
+
+    /*
+     * By giving up our scheduler slot here we increase the odds that the
+     * kernel will ship the contiguous clist items from the last write
+     * immediately.
+     */
+    (void) sleep(0);
+
+    free(mybuf);
+    return (res);
+}
diff --git a/ncurses/tinfo/lib_raw.c b/ncurses/tinfo/lib_raw.c
new file mode 100644
index 0000000..58e7188
--- /dev/null
+++ b/ncurses/tinfo/lib_raw.c
@@ -0,0 +1,296 @@
+/****************************************************************************
+ * Copyright (c) 1998-2002,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey 1998 on                                        *
+ ****************************************************************************/
+
+/*
+ *	raw.c
+ *
+ *	Routines:
+ *		raw()
+ *		cbreak()
+ *		noraw()
+ *		nocbreak()
+ *		qiflush()
+ *		noqiflush()
+ *		intrflush()
+ *
+ */
+
+#include <curses.priv.h>
+#include <term.h>		/* cur_term */
+
+MODULE_ID("$Id: lib_raw.c,v 1.14 2007/09/29 21:50:22 tom Exp $")
+
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+#if HAVE_SYS_TERMIO_H
+#include <sys/termio.h>		/* needed for ISC */
+#endif
+
+#ifdef __EMX__
+#include <io.h>
+#define _nc_setmode(mode) setmode(SP->_ifd, mode)
+#else
+#define _nc_setmode(mode)	/* nothing */
+#endif
+
+#define COOKED_INPUT	(IXON|BRKINT|PARMRK)
+
+#ifdef TRACE
+#define BEFORE(N)	if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s before bits: %s", N, _nc_tracebits())
+#define AFTER(N)	if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s after bits: %s", N, _nc_tracebits())
+#else
+#define BEFORE(s)
+#define AFTER(s)
+#endif /* TRACE */
+
+NCURSES_EXPORT(int)
+raw(void)
+{
+    int result = ERR;
+
+    T((T_CALLED("raw()")));
+
+    if (SP != 0 && cur_term != 0) {
+	TTY buf;
+
+	BEFORE("raw");
+	_nc_setmode(O_BINARY);
+
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
+	buf.c_iflag &= ~(COOKED_INPUT);
+	buf.c_cc[VMIN] = 1;
+	buf.c_cc[VTIME] = 0;
+#else
+	buf.sg_flags |= RAW;
+#endif
+	if ((result = _nc_set_tty_mode(&buf)) == OK) {
+	    SP->_raw = TRUE;
+	    SP->_cbreak = 1;
+	    cur_term->Nttyb = buf;
+	}
+	AFTER("raw");
+    }
+    returnCode(result);
+}
+
+NCURSES_EXPORT(int)
+cbreak(void)
+{
+    int result = ERR;
+
+    T((T_CALLED("cbreak()")));
+
+    if (SP != 0 && cur_term != 0) {
+	TTY buf;
+
+	BEFORE("cbreak");
+	_nc_setmode(O_BINARY);
+
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	buf.c_lflag &= ~ICANON;
+	buf.c_iflag &= ~ICRNL;
+	buf.c_lflag |= ISIG;
+	buf.c_cc[VMIN] = 1;
+	buf.c_cc[VTIME] = 0;
+#else
+	buf.sg_flags |= CBREAK;
+#endif
+	if ((result = _nc_set_tty_mode(&buf)) == OK) {
+	    SP->_cbreak = 1;
+	    cur_term->Nttyb = buf;
+	}
+	AFTER("cbreak");
+    }
+    returnCode(result);
+}
+
+/*
+ * Note:
+ * this implementation may be wrong.  See the comment under intrflush().
+ */
+NCURSES_EXPORT(void)
+qiflush(void)
+{
+    int result = ERR;
+
+    T((T_CALLED("qiflush()")));
+
+    if (cur_term != 0) {
+	TTY buf;
+
+	BEFORE("qiflush");
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	buf.c_lflag &= ~(NOFLSH);
+	result = _nc_set_tty_mode(&buf);
+#else
+	/* FIXME */
+#endif
+	if (result == OK)
+	    cur_term->Nttyb = buf;
+	AFTER("qiflush");
+    }
+    returnVoid;
+}
+
+NCURSES_EXPORT(int)
+noraw(void)
+{
+    int result = ERR;
+
+    T((T_CALLED("noraw()")));
+
+    if (SP != 0 && cur_term != 0) {
+	TTY buf;
+
+	BEFORE("noraw");
+	_nc_setmode(O_TEXT);
+
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	buf.c_lflag |= ISIG | ICANON |
+	    (cur_term->Ottyb.c_lflag & IEXTEN);
+	buf.c_iflag |= COOKED_INPUT;
+#else
+	buf.sg_flags &= ~(RAW | CBREAK);
+#endif
+	if ((result = _nc_set_tty_mode(&buf)) == OK) {
+	    SP->_raw = FALSE;
+	    SP->_cbreak = 0;
+	    cur_term->Nttyb = buf;
+	}
+	AFTER("noraw");
+    }
+    returnCode(result);
+}
+
+NCURSES_EXPORT(int)
+nocbreak(void)
+{
+    int result = ERR;
+
+    T((T_CALLED("nocbreak()")));
+
+    if (SP != 0 && cur_term != 0) {
+	TTY buf;
+
+	BEFORE("nocbreak");
+	_nc_setmode(O_TEXT);
+
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	buf.c_lflag |= ICANON;
+	buf.c_iflag |= ICRNL;
+#else
+	buf.sg_flags &= ~CBREAK;
+#endif
+	if ((result = _nc_set_tty_mode(&buf)) == OK) {
+	    SP->_cbreak = 0;
+	    cur_term->Nttyb = buf;
+	}
+	AFTER("nocbreak");
+    }
+    returnCode(result);
+}
+
+/*
+ * Note:
+ * this implementation may be wrong.  See the comment under intrflush().
+ */
+NCURSES_EXPORT(void)
+noqiflush(void)
+{
+    int result = ERR;
+
+    T((T_CALLED("noqiflush()")));
+
+    if (cur_term != 0) {
+	TTY buf;
+
+	BEFORE("noqiflush");
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	buf.c_lflag |= NOFLSH;
+	result = _nc_set_tty_mode(&buf);
+#else
+	/* FIXME */
+#endif
+	if (result == OK) {
+	    cur_term->Nttyb = buf;
+	}
+	AFTER("noqiflush");
+    }
+    returnVoid;
+}
+
+/*
+ * This call does the same thing as the qiflush()/noqiflush() pair.  We know
+ * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
+ * the match (in the SVr4 man pages) between the language describing NOFLSH in
+ * termio(7) and the language describing qiflush()/noqiflush() in
+ * curs_inopts(3x) is too exact to be coincidence.
+ */
+NCURSES_EXPORT(int)
+intrflush(WINDOW *win GCC_UNUSED, bool flag)
+{
+    int result = ERR;
+
+    T((T_CALLED("intrflush(%d)"), flag));
+
+    if (cur_term != 0) {
+	TTY buf;
+
+	BEFORE("intrflush");
+	buf = cur_term->Nttyb;
+#ifdef TERMIOS
+	if (flag)
+	    buf.c_lflag &= ~(NOFLSH);
+	else
+	    buf.c_lflag |= (NOFLSH);
+	result = _nc_set_tty_mode(&buf);
+#else
+	/* FIXME */
+#endif
+	if (result == OK) {
+	    cur_term->Nttyb = buf;
+	}
+	AFTER("intrflush");
+    }
+    returnCode(result);
+}
diff --git a/ncurses/tinfo/lib_setup.c b/ncurses/tinfo/lib_setup.c
new file mode 100644
index 0000000..8cfaf12
--- /dev/null
+++ b/ncurses/tinfo/lib_setup.c
@@ -0,0 +1,631 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ * Terminal setup routines common to termcap and terminfo:
+ *
+ *		use_env(bool)
+ *		setupterm(char *, int, int *)
+ */
+
+#include <curses.priv.h>
+#include <tic.h>		/* for MAX_NAME_SIZE */
+#include <term_entry.h>
+
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#include <term.h>		/* lines, columns, cur_term */
+
+MODULE_ID("$Id: lib_setup.c,v 1.111 2008/08/03 22:42:33 tom Exp $")
+
+/****************************************************************************
+ *
+ * Terminal size computation
+ *
+ ****************************************************************************/
+
+#if HAVE_SIZECHANGE
+# if !defined(sun) || !TERMIOS
+#  if HAVE_SYS_IOCTL_H
+#   include <sys/ioctl.h>
+#  endif
+# endif
+#endif
+
+#if NEED_PTEM_H
+ /* On SCO, they neglected to define struct winsize in termios.h -- it's only
+  * in termio.h and ptem.h (the former conflicts with other definitions).
+  */
+# include <sys/stream.h>
+# include <sys/ptem.h>
+#endif
+
+#if HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
+
+/*
+ * SCO defines TIOCGSIZE and the corresponding struct.  Other systems (SunOS,
+ * Solaris, IRIX) define TIOCGWINSZ and struct winsize.
+ */
+#ifdef TIOCGSIZE
+# define IOCTL_WINSIZE TIOCGSIZE
+# define STRUCT_WINSIZE struct ttysize
+# define WINSIZE_ROWS(n) (int)n.ts_lines
+# define WINSIZE_COLS(n) (int)n.ts_cols
+#else
+# ifdef TIOCGWINSZ
+#  define IOCTL_WINSIZE TIOCGWINSZ
+#  define STRUCT_WINSIZE struct winsize
+#  define WINSIZE_ROWS(n) (int)n.ws_row
+#  define WINSIZE_COLS(n) (int)n.ws_col
+# endif
+#endif
+
+/*
+ * Reduce explicit use of "cur_term" global variable.
+ */
+#undef CUR
+#define CUR termp->type.
+
+/*
+ * Wrap global variables in this module.
+ */
+#if USE_REENTRANT
+NCURSES_EXPORT(char *)
+NCURSES_PUBLIC_VAR(ttytype) (void)
+{
+    static char empty[] = "";
+    return cur_term ? cur_term->type.term_names : empty;
+}
+NCURSES_EXPORT(int *)
+_nc_ptr_Lines(void)
+{
+    return ptrLines();
+}
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(LINES) (void)
+{
+    return *_nc_ptr_Lines();
+}
+NCURSES_EXPORT(int *)
+_nc_ptr_Cols(void)
+{
+    return ptrCols();
+}
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLS) (void)
+{
+    return *_nc_ptr_Cols();
+}
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(TABSIZE) (void)
+{
+    return SP ? SP->_TABSIZE : 8;
+}
+#else
+NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = "";
+NCURSES_EXPORT_VAR(int) LINES = 0;
+NCURSES_EXPORT_VAR(int) COLS = 0;
+NCURSES_EXPORT_VAR(int) TABSIZE = 0;
+#endif
+
+#if NCURSES_EXT_FUNCS
+NCURSES_EXPORT(int)
+set_tabsize(int value)
+{
+    int code = OK;
+#if USE_REENTRANT
+    if (SP) {
+	SP->_TABSIZE = value;
+    } else {
+	code = ERR;
+    }
+#else
+    TABSIZE = value;
+#endif
+    return code;
+}
+#endif
+
+#if USE_SIGWINCH
+/*
+ * If we have a pending SIGWINCH, set the flag in each screen.
+ */
+NCURSES_EXPORT(int)
+_nc_handle_sigwinch(SCREEN *sp)
+{
+    SCREEN *scan;
+
+    if (_nc_globals.have_sigwinch) {
+	_nc_globals.have_sigwinch = 0;
+
+	for (each_screen(scan)) {
+	    scan->_sig_winch = TRUE;
+	}
+    }
+
+    return (sp ? sp->_sig_winch : 0);
+}
+
+#endif
+
+NCURSES_EXPORT(void)
+use_env(bool f)
+{
+    T((T_CALLED("use_env()")));
+    _nc_prescreen.use_env = f;
+    returnVoid;
+}
+
+NCURSES_EXPORT(void)
+_nc_get_screensize(SCREEN *sp, int *linep, int *colp)
+/* Obtain lines/columns values from the environment and/or terminfo entry */
+{
+    TERMINAL *termp = cur_term;
+    int my_tabsize;
+
+    /* figure out the size of the screen */
+    T(("screen size: terminfo lines = %d columns = %d", lines, columns));
+
+    if (!_nc_prescreen.use_env) {
+	*linep = (int) lines;
+	*colp = (int) columns;
+    } else {			/* usually want to query LINES and COLUMNS from environment */
+	int value;
+
+	*linep = *colp = 0;
+
+	/* first, look for environment variables */
+	if ((value = _nc_getenv_num("LINES")) > 0) {
+	    *linep = value;
+	}
+	if ((value = _nc_getenv_num("COLUMNS")) > 0) {
+	    *colp = value;
+	}
+	T(("screen size: environment LINES = %d COLUMNS = %d", *linep, *colp));
+
+#ifdef __EMX__
+	if (*linep <= 0 || *colp <= 0) {
+	    int screendata[2];
+	    _scrsize(screendata);
+	    *colp = screendata[0];
+	    *linep = screendata[1];
+	    T(("EMX screen size: environment LINES = %d COLUMNS = %d",
+	       *linep, *colp));
+	}
+#endif
+#if HAVE_SIZECHANGE
+	/* if that didn't work, maybe we can try asking the OS */
+	if (*linep <= 0 || *colp <= 0) {
+	    if (isatty(cur_term->Filedes)) {
+		STRUCT_WINSIZE size;
+
+		errno = 0;
+		do {
+		    if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0
+			&& errno != EINTR)
+			goto failure;
+		} while
+		    (errno == EINTR);
+
+		/*
+		 * Solaris lets users override either dimension with an
+		 * environment variable.
+		 */
+		if (*linep <= 0)
+		    *linep = (sp != 0 && sp->_filtered) ? 1 : WINSIZE_ROWS(size);
+		if (*colp <= 0)
+		    *colp = WINSIZE_COLS(size);
+	    }
+	    /* FALLTHRU */
+	  failure:;
+	}
+#endif /* HAVE_SIZECHANGE */
+
+	/* if we can't get dynamic info about the size, use static */
+	if (*linep <= 0) {
+	    *linep = (int) lines;
+	}
+	if (*colp <= 0) {
+	    *colp = (int) columns;
+	}
+
+	/* the ultimate fallback, assume fixed 24x80 size */
+	if (*linep <= 0) {
+	    *linep = 24;
+	}
+	if (*colp <= 0) {
+	    *colp = 80;
+	}
+
+	/*
+	 * Put the derived values back in the screen-size caps, so
+	 * tigetnum() and tgetnum() will do the right thing.
+	 */
+	lines = (short) (*linep);
+	columns = (short) (*colp);
+    }
+
+    T(("screen size is %dx%d", *linep, *colp));
+
+    if (VALID_NUMERIC(init_tabs))
+	my_tabsize = (int) init_tabs;
+    else
+	my_tabsize = 8;
+
+#if USE_REENTRANT
+    if (sp != 0)
+	sp->_TABSIZE = my_tabsize;
+#else
+    TABSIZE = my_tabsize;
+#endif
+    T(("TABSIZE = %d", TABSIZE));
+}
+
+#if USE_SIZECHANGE
+NCURSES_EXPORT(void)
+_nc_update_screensize(SCREEN *sp)
+{
+    TERMINAL *termp = cur_term;
+    int old_lines = lines;
+    int new_lines;
+    int old_cols = columns;
+    int new_cols;
+
+    _nc_get_screensize(sp, &new_lines, &new_cols);
+
+    /*
+     * See is_term_resized() and resizeterm().
+     * We're doing it this way because those functions belong to the upper
+     * ncurses library, while this resides in the lower terminfo library.
+     */
+    if (sp != 0
+	&& sp->_resize != 0) {
+	if ((new_lines != old_lines) || (new_cols != old_cols))
+	    sp->_resize(new_lines, new_cols);
+	sp->_sig_winch = FALSE;
+    }
+}
+#endif
+
+/****************************************************************************
+ *
+ * Terminal setup
+ *
+ ****************************************************************************/
+
+#define ret_error(code, fmt, arg)	if (errret) {\
+					    *errret = code;\
+					    returnCode(ERR);\
+					} else {\
+					    fprintf(stderr, fmt, arg);\
+					    exit(EXIT_FAILURE);\
+					}
+
+#define ret_error0(code, msg)		if (errret) {\
+					    *errret = code;\
+					    returnCode(ERR);\
+					} else {\
+					    fprintf(stderr, msg);\
+					    exit(EXIT_FAILURE);\
+					}
+
+#if USE_DATABASE || USE_TERMCAP
+/*
+ * Return 1 if entry found, 0 if not found, -1 if database not accessible,
+ * just like tgetent().
+ */
+static int
+grab_entry(const char *const tn, TERMTYPE *const tp)
+{
+    char filename[PATH_MAX];
+    int status = _nc_read_entry(tn, filename, tp);
+
+    /*
+     * If we have an entry, force all of the cancelled strings to null
+     * pointers so we don't have to test them in the rest of the library.
+     * (The terminfo compiler bypasses this logic, since it must know if
+     * a string is cancelled, for merging entries).
+     */
+    if (status == TGETENT_YES) {
+	unsigned n;
+	for_each_boolean(n, tp) {
+	    if (!VALID_BOOLEAN(tp->Booleans[n]))
+		tp->Booleans[n] = FALSE;
+	}
+	for_each_string(n, tp) {
+	    if (tp->Strings[n] == CANCELLED_STRING)
+		tp->Strings[n] = ABSENT_STRING;
+	}
+    }
+    return (status);
+}
+#endif
+
+/*
+**	do_prototype()
+**
+**	Take the real command character out of the CC environment variable
+**	and substitute it in for the prototype given in 'command_character'.
+*/
+static void
+do_prototype(TERMINAL * termp)
+{
+    unsigned i;
+    char CC;
+    char proto;
+    char *tmp;
+
+    if ((tmp = getenv("CC")) != 0) {
+	if ((CC = *tmp) != 0) {
+	    proto = *command_character;
+
+	    for_each_string(i, &(termp->type)) {
+		for (tmp = termp->type.Strings[i]; *tmp; tmp++) {
+		    if (*tmp == proto)
+			*tmp = CC;
+		}
+	    }
+	}
+    }
+}
+
+/*
+ * Find the locale which is in effect.
+ */
+NCURSES_EXPORT(char *)
+_nc_get_locale(void)
+{
+    char *env;
+#if HAVE_LOCALE_H
+    /*
+     * This is preferable to using getenv() since it ensures that we are using
+     * the locale which was actually initialized by the application.
+     */
+    env = setlocale(LC_CTYPE, 0);
+#else
+    if (((env = getenv("LC_ALL")) != 0 && *env != '\0')
+	|| ((env = getenv("LC_CTYPE")) != 0 && *env != '\0')
+	|| ((env = getenv("LANG")) != 0 && *env != '\0')) {
+	;
+    }
+#endif
+    T(("_nc_get_locale %s", _nc_visbuf(env)));
+    return env;
+}
+
+/*
+ * Check if we are running in a UTF-8 locale.
+ */
+NCURSES_EXPORT(int)
+_nc_unicode_locale(void)
+{
+    int result = 0;
+#if HAVE_LANGINFO_CODESET
+    char *env = nl_langinfo(CODESET);
+    result = !strcmp(env, "UTF-8");
+    T(("_nc_unicode_locale(%s) ->%d", env, result));
+#else
+    char *env = _nc_get_locale();
+    if (env != 0) {
+	if (strstr(env, ".UTF-8") != 0) {
+	    result = 1;
+	    T(("_nc_unicode_locale(%s) ->%d", env, result));
+	}
+    }
+#endif
+    return result;
+}
+
+#define CONTROL_N(s) ((s) != 0 && strstr(s, "\016") != 0)
+#define CONTROL_O(s) ((s) != 0 && strstr(s, "\017") != 0)
+
+/*
+ * Check for known broken cases where a UTF-8 locale breaks the alternate
+ * character set.
+ */
+NCURSES_EXPORT(int)
+_nc_locale_breaks_acs(TERMINAL * termp)
+{
+    char *env;
+
+    if ((env = getenv("NCURSES_NO_UTF8_ACS")) != 0) {
+	return atoi(env);
+    } else if ((env = getenv("TERM")) != 0) {
+	if (strstr(env, "linux"))
+	    return 1;		/* always broken */
+	if (strstr(env, "screen") != 0
+	    && ((env = getenv("TERMCAP")) != 0
+		&& strstr(env, "screen") != 0)
+	    && strstr(env, "hhII00") != 0) {
+	    if (CONTROL_N(enter_alt_charset_mode) ||
+		CONTROL_O(enter_alt_charset_mode) ||
+		CONTROL_N(set_attributes) ||
+		CONTROL_O(set_attributes))
+		return 1;
+	}
+    }
+    return 0;
+}
+
+/*
+ * This entrypoint is called from tgetent() to allow a special case of reusing
+ * the same TERMINAL data (see comment).
+ */
+NCURSES_EXPORT(int)
+_nc_setupterm(NCURSES_CONST char *tname, int Filedes, int *errret, bool reuse)
+{
+    TERMINAL *termp;
+    int status;
+
+    START_TRACE();
+    T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
+
+    if (tname == 0) {
+	tname = getenv("TERM");
+	if (tname == 0 || *tname == '\0') {
+	    ret_error0(TGETENT_ERR, "TERM environment variable not set.\n");
+	}
+    }
+
+    if (strlen(tname) > MAX_NAME_SIZE) {
+	ret_error(TGETENT_ERR,
+		  "TERM environment must be <= %d characters.\n",
+		  MAX_NAME_SIZE);
+    }
+
+    T(("your terminal name is %s", tname));
+
+    /*
+     * Allow output redirection.  This is what SVr3 does.  If stdout is
+     * directed to a file, screen updates go to standard error.
+     */
+    if (Filedes == STDOUT_FILENO && !isatty(Filedes))
+	Filedes = STDERR_FILENO;
+
+    /*
+     * Check if we have already initialized to use this terminal.  If so, we
+     * do not need to re-read the terminfo entry, or obtain TTY settings.
+     *
+     * This is an improvement on SVr4 curses.  If an application mixes curses
+     * and termcap calls, it may call both initscr and tgetent.  This is not
+     * really a good thing to do, but can happen if someone tries using ncurses
+     * with the readline library.  The problem we are fixing is that when
+     * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
+     * zeroed.  A subsequent call to endwin uses the zeroed terminal settings
+     * rather than the ones saved in initscr.  So we check if cur_term appears
+     * to contain terminal settings for the same output file as our current
+     * call - and copy those terminal settings.  (SVr4 curses does not do this,
+     * however applications that are working around the problem will still work
+     * properly with this feature).
+     */
+    if (reuse
+	&& (termp = cur_term) != 0
+	&& termp->Filedes == Filedes
+	&& termp->_termname != 0
+	&& !strcmp(termp->_termname, tname)
+	&& _nc_name_match(termp->type.term_names, tname, "|")) {
+	T(("reusing existing terminal information and mode-settings"));
+    } else {
+
+	termp = typeCalloc(TERMINAL, 1);
+
+	if (termp == 0) {
+	    ret_error0(TGETENT_ERR,
+		       "Not enough memory to create terminal structure.\n");
+	}
+#if USE_DATABASE || USE_TERMCAP
+	status = grab_entry(tname, &termp->type);
+#else
+	status = TGETENT_NO;
+#endif
+
+	/* try fallback list if entry on disk */
+	if (status != TGETENT_YES) {
+	    const TERMTYPE *fallback = _nc_fallback(tname);
+
+	    if (fallback) {
+		termp->type = *fallback;
+		status = TGETENT_YES;
+	    }
+	}
+
+	if (status != TGETENT_YES) {
+	    del_curterm(termp);
+	    if (status == TGETENT_ERR) {
+		ret_error0(status, "terminals database is inaccessible\n");
+	    } else if (status == TGETENT_NO) {
+		ret_error(status, "'%s': unknown terminal type.\n", tname);
+	    }
+	}
+#if !USE_REENTRANT
+	strncpy(ttytype, termp->type.term_names, NAMESIZE - 1);
+	ttytype[NAMESIZE - 1] = '\0';
+#endif
+
+	termp->Filedes = Filedes;
+	termp->_termname = strdup(tname);
+
+	set_curterm(termp);
+
+	if (command_character && getenv("CC"))
+	    do_prototype(termp);
+
+	/*
+	 * If an application calls setupterm() rather than initscr() or
+	 * newterm(), we will not have the def_prog_mode() call in
+	 * _nc_setupscreen().  Do it now anyway, so we can initialize the
+	 * baudrate.
+	 */
+	if (isatty(Filedes)) {
+	    def_prog_mode();
+	    baudrate();
+	}
+    }
+
+    /*
+     * We should always check the screensize, just in case.
+     */
+    _nc_get_screensize(SP, ptrLines(), ptrCols());
+
+    if (errret)
+	*errret = TGETENT_YES;
+
+    if (generic_type) {
+	ret_error(TGETENT_NO, "'%s': I need something more specific.\n", tname);
+    }
+    if (hard_copy) {
+	ret_error(TGETENT_YES, "'%s': I can't handle hardcopy terminals.\n", tname);
+    }
+    returnCode(OK);
+}
+
+/*
+ *	setupterm(termname, Filedes, errret)
+ *
+ *	Find and read the appropriate object file for the terminal
+ *	Make cur_term point to the structure.
+ */
+NCURSES_EXPORT(int)
+setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
+{
+    return _nc_setupterm(tname, Filedes, errret, FALSE);
+}
diff --git a/ncurses/tinfo/lib_termcap.c b/ncurses/tinfo/lib_termcap.c
new file mode 100644
index 0000000..2d245ff
--- /dev/null
+++ b/ncurses/tinfo/lib_termcap.c
@@ -0,0 +1,291 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ *                                                                          *
+ * some of the code in here was contributed by:                             *
+ * Magnus Bengtsson, d6mbeng@dtek.chalmers.se (Nov'93)                      *
+ * (but it has changed a lot)                                               *
+ ****************************************************************************/
+
+#define __INTERNAL_CAPS_VISIBLE
+#include <curses.priv.h>
+
+#include <termcap.h>
+#include <tic.h>
+#include <ctype.h>
+
+#include <term_entry.h>
+
+MODULE_ID("$Id: lib_termcap.c,v 1.63 2008/08/16 19:22:55 tom Exp $")
+
+NCURSES_EXPORT_VAR(char *) UP = 0;
+NCURSES_EXPORT_VAR(char *) BC = 0;
+
+#define MyCache  _nc_globals.tgetent_cache
+#define CacheInx _nc_globals.tgetent_index
+#define CacheSeq _nc_globals.tgetent_sequence
+
+#define FIX_SGR0 MyCache[CacheInx].fix_sgr0
+#define LAST_TRM MyCache[CacheInx].last_term
+#define LAST_BUF MyCache[CacheInx].last_bufp
+#define LAST_USE MyCache[CacheInx].last_used
+#define LAST_SEQ MyCache[CacheInx].sequence
+
+/***************************************************************************
+ *
+ * tgetent(bufp, term)
+ *
+ * In termcap, this function reads in the entry for terminal `term' into the
+ * buffer pointed to by bufp. It must be called before any of the functions
+ * below are called.
+ * In this terminfo emulation, tgetent() simply calls setupterm() (which
+ * does a bit more than tgetent() in termcap does), and returns its return
+ * value (1 if successful, 0 if no terminal with the given name could be
+ * found, or -1 if no terminal descriptions have been installed on the
+ * system).  The bufp argument is ignored.
+ *
+ ***************************************************************************/
+
+NCURSES_EXPORT(int)
+tgetent(char *bufp, const char *name)
+{
+    int errcode;
+    int n;
+    bool found_cache = FALSE;
+
+    START_TRACE();
+    T((T_CALLED("tgetent()")));
+
+    _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE);
+
+    /*
+     * In general we cannot tell if the fixed sgr0 is still used by the
+     * caller, but if tgetent() is called with the same buffer, that is
+     * good enough, since the previous data would be invalidated by the
+     * current call.
+     *
+     * bufp may be a null pointer, e.g., GNU termcap.  That allocates data,
+     * which is good until the next tgetent() call.  The conventional termcap
+     * is inconvenient because of the fixed buffer size, but because it uses
+     * caller-supplied buffers, can have multiple terminal descriptions in
+     * use at a given time.
+     */
+    for (n = 0; n < TGETENT_MAX; ++n) {
+	bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp);
+	if (same_result) {
+	    CacheInx = n;
+	    if (FIX_SGR0 != 0) {
+		FreeAndNull(FIX_SGR0);
+	    }
+	    /*
+	     * Also free the terminfo data that we loaded (much bigger leak).
+	     */
+	    if (LAST_TRM != 0 && LAST_TRM != cur_term) {
+		TERMINAL *trm = LAST_TRM;
+		del_curterm(LAST_TRM);
+		for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx)
+		    if (LAST_TRM == trm)
+			LAST_TRM = 0;
+		CacheInx = n;
+	    }
+	    found_cache = TRUE;
+	    break;
+	}
+    }
+    if (!found_cache) {
+	int best = 0;
+
+	for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
+	    if (LAST_SEQ < MyCache[best].sequence) {
+		best = CacheInx;
+	    }
+	}
+	CacheInx = best;
+    }
+    LAST_TRM = cur_term;
+    LAST_SEQ = ++CacheSeq;
+
+    PC = 0;
+    UP = 0;
+    BC = 0;
+    FIX_SGR0 = 0;		/* don't free it - application may still use */
+
+    if (errcode == 1) {
+
+	if (cursor_left)
+	    if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0)
+		backspace_if_not_bs = cursor_left;
+
+	/* we're required to export these */
+	if (pad_char != NULL)
+	    PC = pad_char[0];
+	if (cursor_up != NULL)
+	    UP = cursor_up;
+	if (backspace_if_not_bs != NULL)
+	    BC = backspace_if_not_bs;
+
+	if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) {
+	    if (!strcmp(FIX_SGR0, exit_attribute_mode)) {
+		if (FIX_SGR0 != exit_attribute_mode) {
+		    free(FIX_SGR0);
+		}
+		FIX_SGR0 = 0;
+	    }
+	}
+	LAST_BUF = bufp;
+	LAST_USE = TRUE;
+
+	SetNoPadding(SP);
+	(void) baudrate();	/* sets ospeed as a side-effect */
+
+/* LINT_PREPRO
+#if 0*/
+#include <capdefaults.c>
+/* LINT_PREPRO
+#endif*/
+
+    }
+    returnCode(errcode);
+}
+
+/***************************************************************************
+ *
+ * tgetflag(str)
+ *
+ * Look up boolean termcap capability str and return its value (TRUE=1 if
+ * present, FALSE=0 if not).
+ *
+ ***************************************************************************/
+
+NCURSES_EXPORT(int)
+tgetflag(NCURSES_CONST char *id)
+{
+    unsigned i;
+
+    T((T_CALLED("tgetflag(%s)"), id));
+    if (cur_term != 0) {
+	TERMTYPE *tp = &(cur_term->type);
+	for_each_boolean(i, tp) {
+	    const char *capname = ExtBoolname(tp, i, boolcodes);
+	    if (!strncmp(id, capname, 2)) {
+		/* setupterm forces invalid booleans to false */
+		returnCode(tp->Booleans[i]);
+	    }
+	}
+    }
+    returnCode(0);		/* Solaris does this */
+}
+
+/***************************************************************************
+ *
+ * tgetnum(str)
+ *
+ * Look up numeric termcap capability str and return its value, or -1 if
+ * not given.
+ *
+ ***************************************************************************/
+
+NCURSES_EXPORT(int)
+tgetnum(NCURSES_CONST char *id)
+{
+    unsigned i;
+
+    T((T_CALLED("tgetnum(%s)"), id));
+    if (cur_term != 0) {
+	TERMTYPE *tp = &(cur_term->type);
+	for_each_number(i, tp) {
+	    const char *capname = ExtNumname(tp, i, numcodes);
+	    if (!strncmp(id, capname, 2)) {
+		if (!VALID_NUMERIC(tp->Numbers[i]))
+		    returnCode(ABSENT_NUMERIC);
+		returnCode(tp->Numbers[i]);
+	    }
+	}
+    }
+    returnCode(ABSENT_NUMERIC);
+}
+
+/***************************************************************************
+ *
+ * tgetstr(str, area)
+ *
+ * Look up string termcap capability str and return a pointer to its value,
+ * or NULL if not given.
+ *
+ ***************************************************************************/
+
+NCURSES_EXPORT(char *)
+tgetstr(NCURSES_CONST char *id, char **area)
+{
+    unsigned i;
+    char *result = NULL;
+
+    T((T_CALLED("tgetstr(%s,%p)"), id, area));
+    if (cur_term != 0) {
+	TERMTYPE *tp = &(cur_term->type);
+	for_each_string(i, tp) {
+	    const char *capname = ExtStrname(tp, i, strcodes);
+	    if (!strncmp(id, capname, 2)) {
+		result = tp->Strings[i];
+		TR(TRACE_DATABASE, ("found match : %s", _nc_visbuf(result)));
+		/* setupterm forces canceled strings to null */
+		if (VALID_STRING(result)) {
+		    if (result == exit_attribute_mode
+			&& FIX_SGR0 != 0) {
+			result = FIX_SGR0;
+			TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result)));
+		    }
+		    if (area != 0
+			&& *area != 0) {
+			(void) strcpy(*area, result);
+			result = *area;
+			*area += strlen(*area) + 1;
+		    }
+		}
+		break;
+	    }
+	}
+    }
+    returnPtr(result);
+}
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_tgetent_leaks(void)
+{
+    for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
+	FreeIfNeeded(FIX_SGR0);
+	if (LAST_TRM != 0)
+	    del_curterm(LAST_TRM);
+    }
+}
+#endif
diff --git a/ncurses/tinfo/lib_termname.c b/ncurses/tinfo/lib_termname.c
new file mode 100644
index 0000000..713d0be
--- /dev/null
+++ b/ncurses/tinfo/lib_termname.c
@@ -0,0 +1,44 @@
+/****************************************************************************
+ * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_termname.c,v 1.8 2003/12/27 18:23:01 tom Exp $")
+
+NCURSES_EXPORT(char *)
+termname(void)
+{
+    char *name = 0;
+
+    T((T_CALLED("termname()")));
+
+    if (cur_term != 0)
+	name = cur_term->_termname;
+
+    returnPtr(name);
+}
diff --git a/ncurses/tinfo/lib_tgoto.c b/ncurses/tinfo/lib_tgoto.c
new file mode 100644
index 0000000..e07f464
--- /dev/null
+++ b/ncurses/tinfo/lib_tgoto.c
@@ -0,0 +1,203 @@
+/****************************************************************************
+ * Copyright (c) 2000-2006,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <termcap.h>
+
+MODULE_ID("$Id: lib_tgoto.c,v 1.13 2008/08/16 19:29:32 tom Exp $")
+
+#if !PURE_TERMINFO
+static bool
+is_termcap(const char *string)
+{
+    bool result = TRUE;
+
+    if (string == 0 || *string == '\0') {
+	result = FALSE;		/* tparm() handles empty strings */
+    } else {
+	while ((*string != '\0') && result) {
+	    if (*string == '%') {
+		switch (*++string) {
+		case 'p':
+		    result = FALSE;
+		    break;
+		case '\0':
+		    string--;
+		    break;
+		}
+	    } else if (string[0] == '$' && string[1] == '<') {
+		result = FALSE;
+	    }
+	    string++;
+	}
+    }
+    return result;
+}
+
+static char *
+tgoto_internal(const char *string, int x, int y)
+{
+    static char *result;
+    static size_t length;
+
+    int swap_arg;
+    int param[3];
+    size_t used = 0;
+    size_t need = 10;
+    int *value = param;
+    bool need_BC = FALSE;
+
+    if (BC)
+	need += strlen(BC);
+
+    param[0] = y;
+    param[1] = x;
+    param[2] = 0;
+
+    while (*string != 0) {
+	if ((used + need) > length) {
+	    length += (used + need);
+	    if ((result = typeRealloc(char, length, result)) == 0) {
+		length = 0;
+		break;
+	    }
+	}
+	if (*string == '%') {
+	    const char *fmt = 0;
+
+	    switch (*++string) {
+	    case '\0':
+		string--;
+		break;
+	    case 'd':
+		fmt = "%d";
+		break;
+	    case '2':
+		fmt = "%02d";
+		*value %= 100;
+		break;
+	    case '3':
+		fmt = "%03d";
+		*value %= 1000;
+		break;
+	    case '+':
+		*value += UChar(*++string);
+		/* FALLTHRU */
+	    case '.':
+		/*
+		 * Guard against tputs() seeing a truncated string.  The
+		 * termcap documentation refers to a similar fixup for \n
+		 * and \r, but I don't see that it could work -TD
+		 */
+		if (*value == 0) {
+		    if (BC != 0) {
+			*value += 1;
+			need_BC = TRUE;
+		    } else {
+			*value = 0200;	/* tputs will treat this as \0 */
+		    }
+		}
+		result[used++] = (char) *value++;
+		break;
+	    case '%':
+		result[used++] = *string;
+		break;
+	    case 'r':
+		swap_arg = param[0];
+		param[0] = param[1];
+		param[1] = swap_arg;
+		break;
+	    case 'i':
+		param[0] += 1;
+		param[1] += 1;
+		break;
+	    case '>':
+		if (*value > string[1])
+		    *value += string[2];
+		string += 2;
+		break;
+	    case 'n':		/* Datamedia 2500 */
+		param[0] ^= 0140;
+		param[1] ^= 0140;
+		break;
+	    case 'B':		/* BCD */
+		*value = 16 * (*value / 10) + (*value % 10);
+		break;
+	    case 'D':		/* Reverse coding (Delta Data) */
+		*value -= 2 * (*value % 16);
+		break;
+	    }
+	    if (fmt != 0) {
+		sprintf(result + used, fmt, *value++);
+		used += strlen(result + used);
+		fmt = 0;
+	    }
+	    if (value - param > 2) {
+		value = param + 2;
+		*value = 0;
+	    }
+	} else {
+	    result[used++] = *string;
+	}
+	string++;
+    }
+    if (result != 0) {
+	if (need_BC) {
+	    strcpy(result + used, BC);
+	    used += strlen(BC);
+	}
+	result[used] = '\0';
+    }
+    return result;
+}
+#endif
+
+/*
+ * Retained solely for upward compatibility.  Note the intentional reversing of
+ * the last two arguments when invoking tparm().
+ */
+NCURSES_EXPORT(char *)
+tgoto(const char *string, int x, int y)
+{
+    char *result;
+
+    T((T_CALLED("tgoto(%s, %d, %d)"), _nc_visbuf(string), x, y));
+#if !PURE_TERMINFO
+    if (is_termcap(string))
+	result = tgoto_internal(string, x, y);
+    else
+#endif
+	result = TPARM_2((NCURSES_CONST char *) string, y, x);
+    returnPtr(result);
+}
diff --git a/ncurses/tinfo/lib_ti.c b/ncurses/tinfo/lib_ti.c
new file mode 100644
index 0000000..df460f9
--- /dev/null
+++ b/ncurses/tinfo/lib_ti.c
@@ -0,0 +1,103 @@
+/****************************************************************************
+ * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <term_entry.h>
+#include <tic.h>
+
+MODULE_ID("$Id: lib_ti.c,v 1.23 2003/05/24 21:10:28 tom Exp $")
+
+NCURSES_EXPORT(int)
+tigetflag(NCURSES_CONST char *str)
+{
+    unsigned i;
+
+    T((T_CALLED("tigetflag(%s)"), str));
+
+    if (cur_term != 0) {
+	TERMTYPE *tp = &(cur_term->type);
+	for_each_boolean(i, tp) {
+	    const char *capname = ExtBoolname(tp, i, boolnames);
+	    if (!strcmp(str, capname)) {
+		/* setupterm forces invalid booleans to false */
+		returnCode(tp->Booleans[i]);
+	    }
+	}
+    }
+
+    returnCode(ABSENT_BOOLEAN);
+}
+
+NCURSES_EXPORT(int)
+tigetnum(NCURSES_CONST char *str)
+{
+    unsigned i;
+
+    T((T_CALLED("tigetnum(%s)"), str));
+
+    if (cur_term != 0) {
+	TERMTYPE *tp = &(cur_term->type);
+	for_each_number(i, tp) {
+	    const char *capname = ExtNumname(tp, i, numnames);
+	    if (!strcmp(str, capname)) {
+		if (!VALID_NUMERIC(tp->Numbers[i]))
+		    returnCode(ABSENT_NUMERIC);
+		returnCode(tp->Numbers[i]);
+	    }
+	}
+    }
+
+    returnCode(CANCELLED_NUMERIC);	/* Solaris returns a -1 instead */
+}
+
+NCURSES_EXPORT(char *)
+tigetstr(NCURSES_CONST char *str)
+{
+    unsigned i;
+
+    T((T_CALLED("tigetstr(%s)"), str));
+
+    if (cur_term != 0) {
+	TERMTYPE *tp = &(cur_term->type);
+	for_each_string(i, tp) {
+	    const char *capname = ExtStrname(tp, i, strnames);
+	    if (!strcmp(str, capname)) {
+		/* setupterm forces cancelled strings to null */
+		returnPtr(tp->Strings[i]);
+	    }
+	}
+    }
+
+    returnPtr(CANCELLED_STRING);
+}
diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c
new file mode 100644
index 0000000..ba2a840
--- /dev/null
+++ b/ncurses/tinfo/lib_tparm.c
@@ -0,0 +1,795 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey, 1996 on                                       *
+ ****************************************************************************/
+
+/*
+ *	tparm.c
+ *
+ */
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <term.h>
+#include <tic.h>
+
+MODULE_ID("$Id: lib_tparm.c,v 1.76 2008/08/16 19:22:55 tom Exp $")
+
+/*
+ *	char *
+ *	tparm(string, ...)
+ *
+ *	Substitute the given parameters into the given string by the following
+ *	rules (taken from terminfo(5)):
+ *
+ *	     Cursor addressing and other strings  requiring  parame-
+ *	ters in the terminal are described by a parameterized string
+ *	capability, with like escapes %x in  it.   For  example,  to
+ *	address  the  cursor, the cup capability is given, using two
+ *	parameters: the row and column to  address  to.   (Rows  and
+ *	columns  are  numbered  from  zero and refer to the physical
+ *	screen visible to the user, not to any  unseen  memory.)  If
+ *	the terminal has memory relative cursor addressing, that can
+ *	be indicated by
+ *
+ *	     The parameter mechanism uses  a  stack  and  special  %
+ *	codes  to manipulate it.  Typically a sequence will push one
+ *	of the parameters onto the stack and then print it  in  some
+ *	format.  Often more complex operations are necessary.
+ *
+ *	     The % encodings have the following meanings:
+ *
+ *	     %%        outputs `%'
+ *	     %c        print pop() like %c in printf()
+ *	     %s        print pop() like %s in printf()
+ *           %[[:]flags][width[.precision]][doxXs]
+ *                     as in printf, flags are [-+#] and space
+ *                     The ':' is used to avoid making %+ or %-
+ *                     patterns (see below).
+ *
+ *	     %p[1-9]   push ith parm
+ *	     %P[a-z]   set dynamic variable [a-z] to pop()
+ *	     %g[a-z]   get dynamic variable [a-z] and push it
+ *	     %P[A-Z]   set static variable [A-Z] to pop()
+ *	     %g[A-Z]   get static variable [A-Z] and push it
+ *	     %l        push strlen(pop)
+ *	     %'c'      push char constant c
+ *	     %{nn}     push integer constant nn
+ *
+ *	     %+ %- %* %/ %m
+ *	               arithmetic (%m is mod): push(pop() op pop())
+ *	     %& %| %^  bit operations: push(pop() op pop())
+ *	     %= %> %<  logical operations: push(pop() op pop())
+ *	     %A %O     logical and & or operations for conditionals
+ *	     %! %~     unary operations push(op pop())
+ *	     %i        add 1 to first two parms (for ANSI terminals)
+ *
+ *	     %? expr %t thenpart %e elsepart %;
+ *	               if-then-else, %e elsepart is optional.
+ *	               else-if's are possible ala Algol 68:
+ *	               %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e b5 %;
+ *
+ *	For those of the above operators which are binary and not commutative,
+ *	the stack works in the usual way, with
+ *			%gx %gy %m
+ *	resulting in x mod y, not the reverse.
+ */
+
+NCURSES_EXPORT_VAR(int) _nc_tparm_err = 0;
+
+#define TPS(var) _nc_prescreen.tparm_state.var
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_free_tparm(void)
+{
+    if (TPS(out_buff) != 0) {
+	FreeAndNull(TPS(out_buff));
+	TPS(out_size) = 0;
+	TPS(out_used) = 0;
+	FreeAndNull(TPS(fmt_buff));
+	TPS(fmt_size) = 0;
+    }
+}
+#endif
+
+static NCURSES_INLINE void
+get_space(size_t need)
+{
+    need += TPS(out_used);
+    if (need > TPS(out_size)) {
+	TPS(out_size) = need * 2;
+	TPS(out_buff) = typeRealloc(char, TPS(out_size), TPS(out_buff));
+	if (TPS(out_buff) == 0)
+	    _nc_err_abort(MSG_NO_MEMORY);
+    }
+}
+
+static NCURSES_INLINE void
+save_text(const char *fmt, const char *s, int len)
+{
+    size_t s_len = strlen(s);
+    if (len > (int) s_len)
+	s_len = len;
+
+    get_space(s_len + 1);
+
+    (void) sprintf(TPS(out_buff) + TPS(out_used), fmt, s);
+    TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used));
+}
+
+static NCURSES_INLINE void
+save_number(const char *fmt, int number, int len)
+{
+    if (len < 30)
+	len = 30;		/* actually log10(MAX_INT)+1 */
+
+    get_space((unsigned) len + 1);
+
+    (void) sprintf(TPS(out_buff) + TPS(out_used), fmt, number);
+    TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used));
+}
+
+static NCURSES_INLINE void
+save_char(int c)
+{
+    if (c == 0)
+	c = 0200;
+    get_space(1);
+    TPS(out_buff)[TPS(out_used)++] = (char) c;
+}
+
+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++;
+    }
+}
+
+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;
+}
+
+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++;
+    }
+}
+
+static NCURSES_INLINE char *
+spop(void)
+{
+    static char dummy[] = "";	/* avoid const-cast */
+    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;
+}
+
+static NCURSES_INLINE const char *
+parse_format(const char *s, char *format, int *len)
+{
+    *len = 0;
+    if (format != 0) {
+	bool done = FALSE;
+	bool allowminus = FALSE;
+	bool dot = FALSE;
+	bool err = FALSE;
+	char *fmt = format;
+	int my_width = 0;
+	int my_prec = 0;
+	int value = 0;
+
+	*len = 0;
+	*format++ = '%';
+	while (*s != '\0' && !done) {
+	    switch (*s) {
+	    case 'c':		/* FALLTHRU */
+	    case 'd':		/* FALLTHRU */
+	    case 'o':		/* FALLTHRU */
+	    case 'x':		/* FALLTHRU */
+	    case 'X':		/* FALLTHRU */
+	    case 's':
+		*format++ = *s;
+		done = TRUE;
+		break;
+	    case '.':
+		*format++ = *s++;
+		if (dot) {
+		    err = TRUE;
+		} else {	/* value before '.' is the width */
+		    dot = TRUE;
+		    my_width = value;
+		}
+		value = 0;
+		break;
+	    case '#':
+		*format++ = *s++;
+		break;
+	    case ' ':
+		*format++ = *s++;
+		break;
+	    case ':':
+		s++;
+		allowminus = TRUE;
+		break;
+	    case '-':
+		if (allowminus) {
+		    *format++ = *s++;
+		} else {
+		    done = TRUE;
+		}
+		break;
+	    default:
+		if (isdigit(UChar(*s))) {
+		    value = (value * 10) + (*s - '0');
+		    if (value > 10000)
+			err = TRUE;
+		    *format++ = *s++;
+		} else {
+		    done = TRUE;
+		}
+	    }
+	}
+
+	/*
+	 * If we found an error, ignore (and remove) the flags.
+	 */
+	if (err) {
+	    my_width = my_prec = value = 0;
+	    format = fmt;
+	    *format++ = '%';
+	    *format++ = *s;
+	}
+
+	/*
+	 * Any value after '.' is the precision.  If we did not see '.', then
+	 * the value is the width.
+	 */
+	if (dot)
+	    my_prec = value;
+	else
+	    my_width = value;
+
+	*format = '\0';
+	/* return maximum string length in print */
+	*len = (my_width > my_prec) ? my_width : my_prec;
+    }
+    return s;
+}
+
+#define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
+#define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
+
+/*
+ * Analyze the string to see how many parameters we need from the varargs list,
+ * and what their types are.  We will only accept string parameters if they
+ * appear as a %l or %s format following an explicit parameter reference (e.g.,
+ * %p2%s).  All other parameters are numbers.
+ *
+ * 'number' counts coarsely the number of pop's we see in the string, and
+ * 'popcount' shows the highest parameter number in the string.  We would like
+ * to simply use the latter count, but if we are reading termcap strings, there
+ * may be cases that we cannot see the explicit parameter numbers.
+ */
+NCURSES_EXPORT(int)
+_nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount)
+{
+    size_t len2;
+    int i;
+    int lastpop = -1;
+    int len;
+    int number = 0;
+    const char *cp = string;
+    static char dummy[] = "";
+
+    if (cp == 0)
+	return 0;
+
+    if ((len2 = strlen(cp)) > TPS(fmt_size)) {
+	TPS(fmt_size) = len2 + TPS(fmt_size) + 2;
+	TPS(fmt_buff) = typeRealloc(char, TPS(fmt_size), TPS(fmt_buff));
+	if (TPS(fmt_buff) == 0)
+	    return 0;
+    }
+
+    memset(p_is_s, 0, sizeof(p_is_s[0]) * NUM_PARM);
+    *popcount = 0;
+
+    while ((cp - string) < (int) len2) {
+	if (*cp == '%') {
+	    cp++;
+	    cp = parse_format(cp, TPS(fmt_buff), &len);
+	    switch (*cp) {
+	    default:
+		break;
+
+	    case 'd':		/* FALLTHRU */
+	    case 'o':		/* FALLTHRU */
+	    case 'x':		/* FALLTHRU */
+	    case 'X':		/* FALLTHRU */
+	    case 'c':		/* FALLTHRU */
+		if (lastpop <= 0)
+		    number++;
+		lastpop = -1;
+		break;
+
+	    case 'l':
+	    case 's':
+		if (lastpop > 0)
+		    p_is_s[lastpop - 1] = dummy;
+		++number;
+		break;
+
+	    case 'p':
+		cp++;
+		i = (UChar(*cp) - '0');
+		if (i >= 0 && i <= NUM_PARM) {
+		    lastpop = i;
+		    if (lastpop > *popcount)
+			*popcount = lastpop;
+		}
+		break;
+
+	    case 'P':
+		++number;
+		++cp;
+		break;
+
+	    case 'g':
+		cp++;
+		break;
+
+	    case S_QUOTE:
+		cp += 2;
+		lastpop = -1;
+		break;
+
+	    case L_BRACE:
+		cp++;
+		while (isdigit(UChar(*cp))) {
+		    cp++;
+		}
+		break;
+
+	    case '+':
+	    case '-':
+	    case '*':
+	    case '/':
+	    case 'm':
+	    case 'A':
+	    case 'O':
+	    case '&':
+	    case '|':
+	    case '^':
+	    case '=':
+	    case '<':
+	    case '>':
+		lastpop = -1;
+		number += 2;
+		break;
+
+	    case '!':
+	    case '~':
+		lastpop = -1;
+		++number;
+		break;
+
+	    case 'i':
+		/* will add 1 to first (usually two) parameters */
+		break;
+	    }
+	}
+	if (*cp != '\0')
+	    cp++;
+    }
+
+    if (number > NUM_PARM)
+	number = NUM_PARM;
+    return number;
+}
+
+static NCURSES_INLINE char *
+tparam_internal(const char *string, va_list ap)
+{
+    char *p_is_s[NUM_PARM];
+    TPARM_ARG param[NUM_PARM];
+    int popcount;
+    int number;
+    int len;
+    int level;
+    int x, y;
+    int i;
+    const char *cp = string;
+    size_t len2;
+
+    if (cp == NULL)
+	return NULL;
+
+    TPS(out_used) = 0;
+    len2 = strlen(cp);
+
+    /*
+     * Find the highest parameter-number referred to in the format string.
+     * Use this value to limit the number of arguments copied from the
+     * variable-length argument list.
+     */
+    number = _nc_tparm_analyze(cp, p_is_s, &popcount);
+    if (TPS(fmt_buff) == 0)
+	return NULL;
+
+    for (i = 0; i < max(popcount, number); i++) {
+	/*
+	 * A few caps (such as plab_norm) have string-valued parms.
+	 * We'll have to assume that the caller knows the difference, since
+	 * a char* and an int may not be the same size on the stack.  The
+	 * normal prototype for this uses 9 long's, which is consistent with
+	 * our va_arg() usage.
+	 */
+	if (p_is_s[i] != 0) {
+	    p_is_s[i] = va_arg(ap, char *);
+	} else {
+	    param[i] = va_arg(ap, TPARM_ARG);
+	}
+    }
+
+    /*
+     * This is a termcap compatibility hack.  If there are no explicit pop
+     * operations in the string, load the stack in such a way that
+     * successive pops will grab successive parameters.  That will make
+     * the expansion of (for example) \E[%d;%dH work correctly in termcap
+     * style, which means tparam() will expand termcap strings OK.
+     */
+    TPS(stack_ptr) = 0;
+    if (popcount == 0) {
+	popcount = number;
+	for (i = number - 1; i >= 0; i--) {
+	    if (p_is_s[i])
+		spush(p_is_s[i]);
+	    else
+		npush(param[i]);
+	}
+    }
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_CALLS)) {
+	for (i = 0; i < popcount; i++) {
+	    if (p_is_s[i] != 0)
+		save_text(", %s", _nc_visbuf(p_is_s[i]), 0);
+	    else
+		save_number(", %d", param[i], 0);
+	}
+	_tracef(T_CALLED("%s(%s%s)"), TPS(tname), _nc_visbuf(cp), TPS(out_buff));
+	TPS(out_used) = 0;
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    while ((cp - string) < (int) len2) {
+	if (*cp != '%') {
+	    save_char(UChar(*cp));
+	} else {
+	    TPS(tparam_base) = cp++;
+	    cp = parse_format(cp, TPS(fmt_buff), &len);
+	    switch (*cp) {
+	    default:
+		break;
+	    case '%':
+		save_char('%');
+		break;
+
+	    case 'd':		/* FALLTHRU */
+	    case 'o':		/* FALLTHRU */
+	    case 'x':		/* FALLTHRU */
+	    case 'X':		/* FALLTHRU */
+		save_number(TPS(fmt_buff), npop(), len);
+		break;
+
+	    case 'c':		/* FALLTHRU */
+		save_char(npop());
+		break;
+
+	    case 'l':
+		save_number("%d", (int) strlen(spop()), 0);
+		break;
+
+	    case 's':
+		save_text(TPS(fmt_buff), spop(), len);
+		break;
+
+	    case 'p':
+		cp++;
+		i = (UChar(*cp) - '1');
+		if (i >= 0 && i < NUM_PARM) {
+		    if (p_is_s[i])
+			spush(p_is_s[i]);
+		    else
+			npush(param[i]);
+		}
+		break;
+
+	    case 'P':
+		cp++;
+		if (isUPPER(*cp)) {
+		    i = (UChar(*cp) - 'A');
+		    TPS(static_vars)[i] = npop();
+		} else if (isLOWER(*cp)) {
+		    i = (UChar(*cp) - 'a');
+		    TPS(dynamic_var)[i] = npop();
+		}
+		break;
+
+	    case 'g':
+		cp++;
+		if (isUPPER(*cp)) {
+		    i = (UChar(*cp) - 'A');
+		    npush(TPS(static_vars)[i]);
+		} else if (isLOWER(*cp)) {
+		    i = (UChar(*cp) - 'a');
+		    npush(TPS(dynamic_var)[i]);
+		}
+		break;
+
+	    case S_QUOTE:
+		cp++;
+		npush(UChar(*cp));
+		cp++;
+		break;
+
+	    case L_BRACE:
+		number = 0;
+		cp++;
+		while (isdigit(UChar(*cp))) {
+		    number = (number * 10) + (UChar(*cp) - '0');
+		    cp++;
+		}
+		npush(number);
+		break;
+
+	    case '+':
+		npush(npop() + npop());
+		break;
+
+	    case '-':
+		y = npop();
+		x = npop();
+		npush(x - y);
+		break;
+
+	    case '*':
+		npush(npop() * npop());
+		break;
+
+	    case '/':
+		y = npop();
+		x = npop();
+		npush(y ? (x / y) : 0);
+		break;
+
+	    case 'm':
+		y = npop();
+		x = npop();
+		npush(y ? (x % y) : 0);
+		break;
+
+	    case 'A':
+		npush(npop() && npop());
+		break;
+
+	    case 'O':
+		npush(npop() || npop());
+		break;
+
+	    case '&':
+		npush(npop() & npop());
+		break;
+
+	    case '|':
+		npush(npop() | npop());
+		break;
+
+	    case '^':
+		npush(npop() ^ npop());
+		break;
+
+	    case '=':
+		y = npop();
+		x = npop();
+		npush(x == y);
+		break;
+
+	    case '<':
+		y = npop();
+		x = npop();
+		npush(x < y);
+		break;
+
+	    case '>':
+		y = npop();
+		x = npop();
+		npush(x > y);
+		break;
+
+	    case '!':
+		npush(!npop());
+		break;
+
+	    case '~':
+		npush(~npop());
+		break;
+
+	    case 'i':
+		if (p_is_s[0] == 0)
+		    param[0]++;
+		if (p_is_s[1] == 0)
+		    param[1]++;
+		break;
+
+	    case '?':
+		break;
+
+	    case 't':
+		x = npop();
+		if (!x) {
+		    /* scan forward for %e or %; at level zero */
+		    cp++;
+		    level = 0;
+		    while (*cp) {
+			if (*cp == '%') {
+			    cp++;
+			    if (*cp == '?')
+				level++;
+			    else if (*cp == ';') {
+				if (level > 0)
+				    level--;
+				else
+				    break;
+			    } else if (*cp == 'e' && level == 0)
+				break;
+			}
+
+			if (*cp)
+			    cp++;
+		    }
+		}
+		break;
+
+	    case 'e':
+		/* scan forward for a %; at level zero */
+		cp++;
+		level = 0;
+		while (*cp) {
+		    if (*cp == '%') {
+			cp++;
+			if (*cp == '?')
+			    level++;
+			else if (*cp == ';') {
+			    if (level > 0)
+				level--;
+			    else
+				break;
+			}
+		    }
+
+		    if (*cp)
+			cp++;
+		}
+		break;
+
+	    case ';':
+		break;
+
+	    }			/* endswitch (*cp) */
+	}			/* endelse (*cp == '%') */
+
+	if (*cp == '\0')
+	    break;
+
+	cp++;
+    }				/* endwhile (*cp) */
+
+    get_space(1);
+    TPS(out_buff)[TPS(out_used)] = '\0';
+
+    T((T_RETURN("%s"), _nc_visbuf(TPS(out_buff))));
+    return (TPS(out_buff));
+}
+
+#if NCURSES_TPARM_VARARGS
+#define tparm_varargs tparm
+#else
+#define tparm_proto tparm
+#endif
+
+NCURSES_EXPORT(char *)
+tparm_varargs(NCURSES_CONST char *string,...)
+{
+    va_list ap;
+    char *result;
+
+    _nc_tparm_err = 0;
+    va_start(ap, string);
+#ifdef TRACE
+    TPS(tname) = "tparm";
+#endif /* TRACE */
+    result = tparam_internal(string, ap);
+    va_end(ap);
+    return result;
+}
+
+#if !NCURSES_TPARM_VARARGS
+NCURSES_EXPORT(char *)
+tparm_proto(NCURSES_CONST char *string,
+	    TPARM_ARG a1,
+	    TPARM_ARG a2,
+	    TPARM_ARG a3,
+	    TPARM_ARG a4,
+	    TPARM_ARG a5,
+	    TPARM_ARG a6,
+	    TPARM_ARG a7,
+	    TPARM_ARG a8,
+	    TPARM_ARG a9)
+{
+    return tparm_varargs(string, a1, a2, a3, a4, a5, a6, a7, a8, a9);
+}
+#endif /* NCURSES_TPARM_VARARGS */
diff --git a/ncurses/tinfo/lib_tputs.c b/ncurses/tinfo/lib_tputs.c
new file mode 100644
index 0000000..a8b7276
--- /dev/null
+++ b/ncurses/tinfo/lib_tputs.c
@@ -0,0 +1,275 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	tputs.c
+ *		delay_output()
+ *		_nc_outch()
+ *		tputs()
+ *
+ */
+
+#include <curses.priv.h>
+#include <ctype.h>
+#include <term.h>		/* padding_baud_rate, xon_xoff */
+#include <termcap.h>		/* ospeed */
+#include <tic.h>
+
+MODULE_ID("$Id: lib_tputs.c,v 1.66 2008/06/28 13:12:15 tom Exp $")
+
+NCURSES_EXPORT_VAR(char) PC = 0;              /* used by termcap library */
+NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0;        /* used by termcap library */
+
+NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0;   /* used by 'tack' program */
+
+#if NCURSES_NO_PADDING
+NCURSES_EXPORT(void)
+_nc_set_no_padding(SCREEN *sp)
+{
+    bool no_padding = (getenv("NCURSES_NO_PADDING") != 0);
+
+    if (sp)
+	sp->_no_padding = no_padding;
+    else
+	_nc_prescreen._no_padding = no_padding;
+
+    TR(TRACE_CHARPUT | TRACE_MOVE, ("padding will%s be used",
+				    GetNoPadding(sp) ? " not" : ""));
+}
+#endif
+
+static int (*my_outch) (int c) = _nc_outch;
+
+NCURSES_EXPORT(int)
+delay_output(int ms)
+{
+    T((T_CALLED("delay_output(%d)"), ms));
+
+    if (no_pad_char) {
+	_nc_flush();
+	napms(ms);
+    } else {
+	register int nullcount;
+
+	nullcount = (ms * _nc_baudrate(ospeed)) / (BAUDBYTE * 1000);
+	for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
+	    my_outch(PC);
+	if (my_outch == _nc_outch)
+	    _nc_flush();
+    }
+
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(void)
+_nc_flush(void)
+{
+    (void) fflush(NC_OUTPUT);
+}
+
+NCURSES_EXPORT(int)
+_nc_outch(int ch)
+{
+    COUNT_OUTCHARS(1);
+
+    if (SP != 0
+	&& SP->_cleanup) {
+	char tmp = ch;
+	/*
+	 * POSIX says write() is safe in a signal handler, but the
+	 * buffered I/O is not.
+	 */
+	write(fileno(NC_OUTPUT), &tmp, 1);
+    } else {
+	putc(ch, NC_OUTPUT);
+    }
+    return OK;
+}
+
+NCURSES_EXPORT(int)
+putp(const char *string)
+{
+    return tputs(string, 1, _nc_outch);
+}
+
+NCURSES_EXPORT(int)
+tputs(const char *string, int affcnt, int (*outc) (int))
+{
+    bool always_delay;
+    bool normal_delay;
+    int number;
+#if BSD_TPUTS
+    int trailpad;
+#endif /* BSD_TPUTS */
+
+#ifdef TRACE
+    char addrbuf[32];
+
+    if (USE_TRACEF(TRACE_TPUTS)) {
+	if (outc == _nc_outch)
+	    (void) strcpy(addrbuf, "_nc_outch");
+	else
+	    (void) sprintf(addrbuf, "%p", outc);
+	if (_nc_tputs_trace) {
+	    _tracef("tputs(%s = %s, %d, %s) called", _nc_tputs_trace,
+		    _nc_visbuf(string), affcnt, addrbuf);
+	} else {
+	    _tracef("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf);
+	}
+	TPUTS_TRACE(NULL);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    if (!VALID_STRING(string))
+	return ERR;
+
+    if (cur_term == 0) {
+	always_delay = FALSE;
+	normal_delay = TRUE;
+    } else {
+	always_delay = (string == bell) || (string == flash_screen);
+	normal_delay =
+	    !xon_xoff
+	    && padding_baud_rate
+#if NCURSES_NO_PADDING
+	    && !GetNoPadding(SP)
+#endif
+	    && (_nc_baudrate(ospeed) >= padding_baud_rate);
+    }
+
+#if BSD_TPUTS
+    /*
+     * This ugly kluge deals with the fact that some ancient BSD programs
+     * (like nethack) actually do the likes of tputs("50") to get delays.
+     */
+    trailpad = 0;
+    if (isdigit(UChar(*string))) {
+	while (isdigit(UChar(*string))) {
+	    trailpad = trailpad * 10 + (*string - '0');
+	    string++;
+	}
+	trailpad *= 10;
+	if (*string == '.') {
+	    string++;
+	    if (isdigit(UChar(*string))) {
+		trailpad += (*string - '0');
+		string++;
+	    }
+	    while (isdigit(UChar(*string)))
+		string++;
+	}
+
+	if (*string == '*') {
+	    trailpad *= affcnt;
+	    string++;
+	}
+    }
+#endif /* BSD_TPUTS */
+
+    my_outch = outc;		/* redirect delay_output() */
+    while (*string) {
+	if (*string != '$')
+	    (*outc) (*string);
+	else {
+	    string++;
+	    if (*string != '<') {
+		(*outc) ('$');
+		if (*string)
+		    (*outc) (*string);
+	    } else {
+		bool mandatory;
+
+		string++;
+		if ((!isdigit(UChar(*string)) && *string != '.')
+		    || !strchr(string, '>')) {
+		    (*outc) ('$');
+		    (*outc) ('<');
+		    continue;
+		}
+
+		number = 0;
+		while (isdigit(UChar(*string))) {
+		    number = number * 10 + (*string - '0');
+		    string++;
+		}
+		number *= 10;
+		if (*string == '.') {
+		    string++;
+		    if (isdigit(UChar(*string))) {
+			number += (*string - '0');
+			string++;
+		    }
+		    while (isdigit(UChar(*string)))
+			string++;
+		}
+
+		mandatory = FALSE;
+		while (*string == '*' || *string == '/') {
+		    if (*string == '*') {
+			number *= affcnt;
+			string++;
+		    } else {	/* if (*string == '/') */
+			mandatory = TRUE;
+			string++;
+		    }
+		}
+
+		if (number > 0
+		    && (always_delay
+			|| normal_delay
+			|| mandatory))
+		    delay_output(number / 10);
+
+	    }			/* endelse (*string == '<') */
+	}			/* endelse (*string == '$') */
+
+	if (*string == '\0')
+	    break;
+
+	string++;
+    }
+
+#if BSD_TPUTS
+    /*
+     * Emit any BSD-style prefix padding that we've accumulated now.
+     */
+    if (trailpad > 0
+	&& (always_delay || normal_delay))
+	delay_output(trailpad / 10);
+#endif /* BSD_TPUTS */
+
+    my_outch = _nc_outch;
+    return OK;
+}
diff --git a/ncurses/tinfo/lib_ttyflags.c b/ncurses/tinfo/lib_ttyflags.c
new file mode 100644
index 0000000..a2b38a3
--- /dev/null
+++ b/ncurses/tinfo/lib_ttyflags.c
@@ -0,0 +1,220 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/*
+ *		def_prog_mode()
+ *		def_shell_mode()
+ *		reset_prog_mode()
+ *		reset_shell_mode()
+ *		savetty()
+ *		resetty()
+ */
+
+#include <curses.priv.h>
+#include <term.h>		/* cur_term */
+
+MODULE_ID("$Id: lib_ttyflags.c,v 1.18 2008/08/03 22:10:44 tom Exp $")
+
+NCURSES_EXPORT(int)
+_nc_get_tty_mode(TTY * buf)
+{
+    int result = OK;
+
+    if (buf == 0) {
+	result = ERR;
+    } else {
+	if (cur_term == 0) {
+	    result = ERR;
+	} else {
+	    for (;;) {
+		if (GET_TTY(cur_term->Filedes, buf) != 0) {
+		    if (errno == EINTR)
+			continue;
+		    result = ERR;
+		}
+		break;
+	    }
+	}
+
+	if (result == ERR)
+	    memset(buf, 0, sizeof(*buf));
+
+	TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
+			cur_term ? cur_term->Filedes : -1,
+			_nc_trace_ttymode(buf)));
+    }
+    return (result);
+}
+
+NCURSES_EXPORT(int)
+_nc_set_tty_mode(TTY * buf)
+{
+    int result = OK;
+
+    if (buf == 0) {
+	result = ERR;
+    } else {
+	if (cur_term == 0) {
+	    result = ERR;
+	} else {
+	    for (;;) {
+		if (SET_TTY(cur_term->Filedes, buf) != 0) {
+		    if (errno == EINTR)
+			continue;
+		    if ((errno == ENOTTY) && (SP != 0))
+			SP->_notty = TRUE;
+		    result = ERR;
+		}
+		break;
+	    }
+	}
+	TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
+			cur_term ? cur_term->Filedes : -1,
+			_nc_trace_ttymode(buf)));
+    }
+    return (result);
+}
+
+NCURSES_EXPORT(int)
+def_shell_mode(void)
+{
+    int rc = ERR;
+
+    T((T_CALLED("def_shell_mode()")));
+
+    if (cur_term != 0) {
+	/*
+	 * If XTABS was on, remove the tab and backtab capabilities.
+	 */
+	if (_nc_get_tty_mode(&cur_term->Ottyb) == OK) {
+#ifdef TERMIOS
+	    if (cur_term->Ottyb.c_oflag & OFLAGS_TABS)
+		tab = back_tab = NULL;
+#else
+	    if (cur_term->Ottyb.sg_flags & XTABS)
+		tab = back_tab = NULL;
+#endif
+	    rc = OK;
+	}
+    }
+    returnCode(rc);
+}
+
+NCURSES_EXPORT(int)
+def_prog_mode(void)
+{
+    int rc = ERR;
+
+    T((T_CALLED("def_prog_mode()")));
+
+    if (cur_term != 0) {
+	/*
+	 * Turn off the XTABS bit in the tty structure if it was on.
+	 */
+	if (_nc_get_tty_mode(&cur_term->Nttyb) == OK) {
+#ifdef TERMIOS
+	    cur_term->Nttyb.c_oflag &= ~OFLAGS_TABS;
+#else
+	    cur_term->Nttyb.sg_flags &= ~XTABS;
+#endif
+	    rc = OK;
+	}
+    }
+    returnCode(rc);
+}
+
+NCURSES_EXPORT(int)
+reset_prog_mode(void)
+{
+    T((T_CALLED("reset_prog_mode()")));
+
+    if (cur_term != 0) {
+	if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) {
+	    if (SP) {
+		if (SP->_keypad_on)
+		    _nc_keypad(SP, TRUE);
+		NC_BUFFERED(TRUE);
+	    }
+	    returnCode(OK);
+	}
+    }
+    returnCode(ERR);
+}
+
+NCURSES_EXPORT(int)
+reset_shell_mode(void)
+{
+    T((T_CALLED("reset_shell_mode()")));
+
+    if (cur_term != 0) {
+	if (SP) {
+	    _nc_keypad(SP, FALSE);
+	    _nc_flush();
+	    NC_BUFFERED(FALSE);
+	}
+	returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
+    }
+    returnCode(ERR);
+}
+
+static TTY *
+saved_tty(void)
+{
+    TTY *result = 0;
+
+    if (SP != 0) {
+	result = &(SP->_saved_tty);
+    } else {
+	if (_nc_prescreen.saved_tty == 0) {
+	    _nc_prescreen.saved_tty = typeCalloc(TTY, 1);
+	}
+	result = _nc_prescreen.saved_tty;
+    }
+    return result;
+}
+
+/*
+**	savetty()  and  resetty()
+**
+*/
+
+NCURSES_EXPORT(int)
+savetty(void)
+{
+    T((T_CALLED("savetty()")));
+
+    returnCode(_nc_get_tty_mode(saved_tty()));
+}
+
+NCURSES_EXPORT(int)
+resetty(void)
+{
+    T((T_CALLED("resetty()")));
+
+    returnCode(_nc_set_tty_mode(saved_tty()));
+}
diff --git a/ncurses/tinfo/make_keys.c b/ncurses/tinfo/make_keys.c
new file mode 100644
index 0000000..c084f87
--- /dev/null
+++ b/ncurses/tinfo/make_keys.c
@@ -0,0 +1,148 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                    1997-on                     *
+ ****************************************************************************/
+
+/*
+ * This replaces an awk script which translated keys.list into keys.tries by
+ * making the output show the indices into the TERMTYPE Strings array.  Doing
+ * it that way lets us cut down on the size of the init_keytry() function.
+ */
+
+#define USE_TERMLIB 1
+#include <curses.priv.h>
+
+MODULE_ID("$Id: make_keys.c,v 1.14 2008/08/03 21:57:22 tom Exp $")
+
+#include <names.c>
+
+#define UNKNOWN (SIZEOF(strnames) + SIZEOF(strfnames))
+
+static size_t
+lookup(const char *name)
+{
+    size_t n;
+    bool found = FALSE;
+    for (n = 0; strnames[n] != 0; n++) {
+	if (!strcmp(name, strnames[n])) {
+	    found = TRUE;
+	    break;
+	}
+    }
+    if (!found) {
+	for (n = 0; strfnames[n] != 0; n++) {
+	    if (!strcmp(name, strfnames[n])) {
+		found = TRUE;
+		break;
+	    }
+	}
+    }
+    return found ? n : UNKNOWN;
+}
+
+static void
+make_keys(FILE *ifp, FILE *ofp)
+{
+    char buffer[BUFSIZ];
+    char from[256];
+    char to[256];
+    int maxlen = 16;
+    int scanned;
+
+    while (fgets(buffer, sizeof(buffer), ifp) != 0) {
+	if (*buffer == '#')
+	    continue;
+
+	to[sizeof(to) - 1] = '\0';
+	from[sizeof(from) - 1] = '\0';
+
+	scanned = sscanf(buffer, "%255s %255s", to, from);
+	if (scanned == 2) {
+	    int code = lookup(from);
+	    if (code == UNKNOWN)
+		continue;
+	    if ((int) strlen(from) > maxlen)
+		maxlen = strlen(from);
+	    fprintf(ofp, "\t{ %4d, %-*.*s },\t/* %s */\n",
+		    code,
+		    maxlen, maxlen,
+		    to,
+		    from);
+	}
+    }
+}
+
+static void
+write_list(FILE *ofp, const char **list)
+{
+    while (*list != 0)
+	fprintf(ofp, "%s\n", *list++);
+}
+
+int
+main(int argc, char *argv[])
+{
+    static const char *prefix[] =
+    {
+	"#ifndef NCU_KEYS_H",
+	"#define NCU_KEYS_H 1",
+	"",
+	"/* This file was generated by MAKE_KEYS */",
+	"",
+	"#if BROKEN_LINKER",
+	"static",
+	"#endif",
+	"const struct tinfo_fkeys _nc_tinfo_fkeys[] = {",
+	0
+    };
+    static const char *suffix[] =
+    {
+	"\t{ 0, 0} };",
+	"",
+	"#endif /* NCU_KEYS_H */",
+	0
+    };
+
+    write_list(stdout, prefix);
+    if (argc > 1) {
+	int n;
+	for (n = 1; n < argc; n++) {
+	    FILE *fp = fopen(argv[n], "r");
+	    if (fp != 0) {
+		make_keys(fp, stdout);
+		fclose(fp);
+	    }
+	}
+    } else {
+	make_keys(stdin, stdout);
+    }
+    write_list(stdout, suffix);
+    return EXIT_SUCCESS;
+}
diff --git a/ncurses/tinfo/name_match.c b/ncurses/tinfo/name_match.c
new file mode 100644
index 0000000..d576901
--- /dev/null
+++ b/ncurses/tinfo/name_match.c
@@ -0,0 +1,111 @@
+/****************************************************************************
+ * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                    1999-on                     *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>
+#include <tic.h>
+
+MODULE_ID("$Id: name_match.c,v 1.17 2008/08/03 19:49:33 tom Exp $")
+
+/*
+ *	_nc_first_name(char *names)
+ *
+ *	Extract the primary name from a compiled entry.
+ */
+#define FirstName _nc_globals.first_name
+
+NCURSES_EXPORT(char *)
+_nc_first_name(const char *const sp)
+/* get the first name from the given name list */
+{
+    unsigned n;
+
+#if NO_LEAKS
+    if (sp == 0) {
+	if (FirstName != 0)
+	    FreeAndNull(FirstName);
+    } else
+#endif
+    {
+	if (FirstName == 0)
+	    FirstName = typeMalloc(char, MAX_NAME_SIZE + 1);
+
+	if (FirstName != 0) {
+	    for (n = 0; n < MAX_NAME_SIZE; n++) {
+		if ((FirstName[n] = sp[n]) == '\0'
+		    || (FirstName[n] == '|'))
+		    break;
+	    }
+	    FirstName[n] = '\0';
+	}
+    }
+    return (FirstName);
+}
+
+/*
+ *	int _nc_name_match(namelist, name, delim)
+ *
+ *	Is the given name matched in namelist?
+ */
+
+NCURSES_EXPORT(int)
+_nc_name_match(const char *const namelst, const char *const name, const char *const delim)
+{
+    const char *s, *d, *t;
+    int code, found;
+
+    if ((s = namelst) != 0) {
+	while (*s != '\0') {
+	    for (d = name; *d != '\0'; d++) {
+		if (*s != *d)
+		    break;
+		s++;
+	    }
+	    found = FALSE;
+	    for (code = TRUE; *s != '\0'; code = FALSE, s++) {
+		for (t = delim; *t != '\0'; t++) {
+		    if (*s == *t) {
+			found = TRUE;
+			break;
+		    }
+		}
+		if (found)
+		    break;
+	    }
+	    if (code && *d == '\0')
+		return code;
+	    if (*s++ == 0)
+		break;
+	}
+    }
+    return FALSE;
+}
diff --git a/ncurses/tinfo/parse_entry.c b/ncurses/tinfo/parse_entry.c
new file mode 100644
index 0000000..cf7a5f4
--- /dev/null
+++ b/ncurses/tinfo/parse_entry.c
@@ -0,0 +1,997 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	parse_entry.c -- compile one terminfo or termcap entry
+ *
+ *	Get an exact in-core representation of an entry.  Don't
+ *	try to resolve use or tc capabilities, that is someone
+ *	else's job.  Depends on the lexical analyzer to get tokens
+ *	from the input stream.
+ */
+
+#define __INTERNAL_CAPS_VISIBLE
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: parse_entry.c,v 1.69 2008/08/16 21:52:03 tom Exp $")
+
+#ifdef LINT
+static short const parametrized[] =
+{0};
+#else
+#include <parametrized.h>
+#endif
+
+static void postprocess_termcap(TERMTYPE *, bool);
+static void postprocess_terminfo(TERMTYPE *);
+static struct name_table_entry const *lookup_fullname(const char *name);
+
+#if NCURSES_XNAMES
+
+static struct name_table_entry const *
+_nc_extend_names(ENTRY * entryp, char *name, int token_type)
+{
+    static struct name_table_entry temp;
+    TERMTYPE *tp = &(entryp->tterm);
+    unsigned offset = 0;
+    unsigned actual;
+    unsigned tindex;
+    unsigned first, last, n;
+    bool found;
+
+    switch (token_type) {
+    case BOOLEAN:
+	first = 0;
+	last = tp->ext_Booleans;
+	offset = tp->ext_Booleans;
+	tindex = tp->num_Booleans;
+	break;
+    case NUMBER:
+	first = tp->ext_Booleans;
+	last = tp->ext_Numbers + first;
+	offset = tp->ext_Booleans + tp->ext_Numbers;
+	tindex = tp->num_Numbers;
+	break;
+    case STRING:
+	first = tp->ext_Booleans + tp->ext_Numbers;
+	last = tp->ext_Strings + first;
+	offset = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings;
+	tindex = tp->num_Strings;
+	break;
+    case CANCEL:
+	actual = NUM_EXT_NAMES(tp);
+	for (n = 0; n < actual; n++) {
+	    if (!strcmp(name, tp->ext_Names[n])) {
+		if (n > (unsigned) (tp->ext_Booleans + tp->ext_Numbers)) {
+		    token_type = STRING;
+		} else if (n > tp->ext_Booleans) {
+		    token_type = NUMBER;
+		} else {
+		    token_type = BOOLEAN;
+		}
+		return _nc_extend_names(entryp, name, token_type);
+	    }
+	}
+	/* Well, we are given a cancel for a name that we don't recognize */
+	return _nc_extend_names(entryp, name, STRING);
+    default:
+	return 0;
+    }
+
+    /* Adjust the 'offset' (insertion-point) to keep the lists of extended
+     * names sorted.
+     */
+    for (n = first, found = FALSE; n < last; n++) {
+	int cmp = strcmp(tp->ext_Names[n], name);
+	if (cmp == 0)
+	    found = TRUE;
+	if (cmp >= 0) {
+	    offset = n;
+	    tindex = n - first;
+	    switch (token_type) {
+	    case BOOLEAN:
+		tindex += BOOLCOUNT;
+		break;
+	    case NUMBER:
+		tindex += NUMCOUNT;
+		break;
+	    case STRING:
+		tindex += STRCOUNT;
+		break;
+	    }
+	    break;
+	}
+    }
+    if (!found) {
+	switch (token_type) {
+	case BOOLEAN:
+	    tp->ext_Booleans += 1;
+	    tp->num_Booleans += 1;
+	    tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
+	    for (last = tp->num_Booleans - 1; last > tindex; last--)
+		tp->Booleans[last] = tp->Booleans[last - 1];
+	    break;
+	case NUMBER:
+	    tp->ext_Numbers += 1;
+	    tp->num_Numbers += 1;
+	    tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers);
+	    for (last = tp->num_Numbers - 1; last > tindex; last--)
+		tp->Numbers[last] = tp->Numbers[last - 1];
+	    break;
+	case STRING:
+	    tp->ext_Strings += 1;
+	    tp->num_Strings += 1;
+	    tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings);
+	    for (last = tp->num_Strings - 1; last > tindex; last--)
+		tp->Strings[last] = tp->Strings[last - 1];
+	    break;
+	}
+	actual = NUM_EXT_NAMES(tp);
+	tp->ext_Names = typeRealloc(char *, actual, tp->ext_Names);
+	while (--actual > offset)
+	    tp->ext_Names[actual] = tp->ext_Names[actual - 1];
+	tp->ext_Names[offset] = _nc_save_str(name);
+    }
+
+    temp.nte_name = tp->ext_Names[offset];
+    temp.nte_type = token_type;
+    temp.nte_index = tindex;
+    temp.nte_link = -1;
+
+    return &temp;
+}
+#endif /* NCURSES_XNAMES */
+
+/*
+ *	int
+ *	_nc_parse_entry(entry, literal, silent)
+ *
+ *	Compile one entry.  Doesn't try to resolve use or tc capabilities.
+ *
+ *	found-forward-use = FALSE
+ *	re-initialise internal arrays
+ *	get_token();
+ *	if the token was not a name in column 1, complain and die
+ *	save names in entry's string table
+ *	while (get_token() is not EOF and not NAMES)
+ *	        check for existence and type-correctness
+ *	        enter cap into structure
+ *	        if STRING
+ *	            save string in entry's string table
+ *	push back token
+ */
+
+#define BAD_TC_USAGE if (!bad_tc_usage) \
+ 	{ bad_tc_usage = TRUE; \
+	 _nc_warning("Legacy termcap allows only a trailing tc= clause"); }
+
+NCURSES_EXPORT(int)
+_nc_parse_entry(struct entry *entryp, int literal, bool silent)
+{
+    int token_type;
+    struct name_table_entry const *entry_ptr;
+    char *ptr, *base;
+    bool bad_tc_usage = FALSE;
+
+    token_type = _nc_get_token(silent);
+
+    if (token_type == EOF)
+	return (EOF);
+    if (token_type != NAMES)
+	_nc_err_abort("Entry does not start with terminal names in column one");
+
+    _nc_init_entry(&entryp->tterm);
+
+    entryp->cstart = _nc_comment_start;
+    entryp->cend = _nc_comment_end;
+    entryp->startline = _nc_start_line;
+    DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend));
+
+    /*
+     * Strip off the 2-character termcap name, if present.  Originally termcap
+     * used that as an indexing aid.  We can retain 2-character terminfo names,
+     * but note that they would be lost if we translate to/from termcap.  This
+     * feature is supposedly obsolete since "newer" BSD implementations do not
+     * use it; however our reference for this feature is SunOS 4.x, which
+     * implemented it.  Note that the resulting terminal type was never the
+     * 2-character name, but was instead the first alias after that.
+     */
+    ptr = _nc_curr_token.tk_name;
+    if (_nc_syntax == SYN_TERMCAP
+#if NCURSES_XNAMES
+	&& !_nc_user_definable
+#endif
+	) {
+	if (ptr[2] == '|') {
+	    ptr += 3;
+	    _nc_curr_token.tk_name[2] = '\0';
+	}
+    }
+
+    entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr);
+
+    if (entryp->tterm.str_table == 0)
+	return (ERR);
+
+    DEBUG(1, ("Starting '%s'", ptr));
+
+    /*
+     * We do this because the one-token lookahead in the parse loop
+     * results in the terminal type getting prematurely set to correspond
+     * to that of the next entry.
+     */
+    _nc_set_type(_nc_first_name(entryp->tterm.term_names));
+
+    /* check for overly-long names and aliases */
+    for (base = entryp->tterm.term_names; (ptr = strchr(base, '|')) != 0;
+	 base = ptr + 1) {
+	if (ptr - base > MAX_ALIAS) {
+	    _nc_warning("%s `%.*s' may be too long",
+			(base == entryp->tterm.term_names)
+			? "primary name"
+			: "alias",
+			(int) (ptr - base), base);
+	}
+    }
+
+    entryp->nuses = 0;
+
+    for (token_type = _nc_get_token(silent);
+	 token_type != EOF && token_type != NAMES;
+	 token_type = _nc_get_token(silent)) {
+	bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0);
+	bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0);
+	if (is_use || is_tc) {
+	    entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring);
+	    entryp->uses[entryp->nuses].line = _nc_curr_line;
+	    entryp->nuses++;
+	    if (entryp->nuses > 1 && is_tc) {
+		BAD_TC_USAGE
+	    }
+	} else {
+	    /* normal token lookup */
+	    entry_ptr = _nc_find_entry(_nc_curr_token.tk_name,
+				       _nc_get_hash_table(_nc_syntax));
+
+	    /*
+	     * Our kluge to handle aliasing.  The reason it's done
+	     * this ugly way, with a linear search, is so the hashing
+	     * machinery doesn't have to be made really complicated
+	     * (also we get better warnings this way).  No point in
+	     * making this case fast, aliased caps aren't common now
+	     * and will get rarer.
+	     */
+	    if (entry_ptr == NOTFOUND) {
+		const struct alias *ap;
+
+		if (_nc_syntax == SYN_TERMCAP) {
+		    if (entryp->nuses != 0) {
+			BAD_TC_USAGE
+		    }
+		    for (ap = _nc_get_alias_table(TRUE); ap->from; ap++)
+			if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
+			    if (ap->to == (char *) 0) {
+				_nc_warning("%s (%s termcap extension) ignored",
+					    ap->from, ap->source);
+				goto nexttok;
+			    }
+
+			    entry_ptr = _nc_find_entry(ap->to,
+						       _nc_get_hash_table(TRUE));
+			    if (entry_ptr && !silent)
+				_nc_warning("%s (%s termcap extension) aliased to %s",
+					    ap->from, ap->source, ap->to);
+			    break;
+			}
+		} else {	/* if (_nc_syntax == SYN_TERMINFO) */
+		    for (ap = _nc_get_alias_table(FALSE); ap->from; ap++)
+			if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
+			    if (ap->to == (char *) 0) {
+				_nc_warning("%s (%s terminfo extension) ignored",
+					    ap->from, ap->source);
+				goto nexttok;
+			    }
+
+			    entry_ptr = _nc_find_entry(ap->to,
+						       _nc_get_hash_table(FALSE));
+			    if (entry_ptr && !silent)
+				_nc_warning("%s (%s terminfo extension) aliased to %s",
+					    ap->from, ap->source, ap->to);
+			    break;
+			}
+
+		    if (entry_ptr == NOTFOUND) {
+			entry_ptr = lookup_fullname(_nc_curr_token.tk_name);
+		    }
+		}
+	    }
+#if NCURSES_XNAMES
+	    /*
+	     * If we have extended-names active, we will automatically
+	     * define a name based on its context.
+	     */
+	    if (entry_ptr == NOTFOUND
+		&& _nc_user_definable
+		&& (entry_ptr = _nc_extend_names(entryp,
+						 _nc_curr_token.tk_name,
+						 token_type)) != 0) {
+		if (_nc_tracing >= DEBUG_LEVEL(1))
+		    _nc_warning("extended capability '%s'", _nc_curr_token.tk_name);
+	    }
+#endif /* NCURSES_XNAMES */
+
+	    /* can't find this cap name, not even as an alias */
+	    if (entry_ptr == NOTFOUND) {
+		if (!silent)
+		    _nc_warning("unknown capability '%s'",
+				_nc_curr_token.tk_name);
+		continue;
+	    }
+
+	    /* deal with bad type/value combinations. */
+	    if (token_type != CANCEL && entry_ptr->nte_type != token_type) {
+		/*
+		 * Nasty special cases here handle situations in which type
+		 * information can resolve name clashes.  Normal lookup
+		 * finds the last instance in the capability table of a
+		 * given name, regardless of type.  find_type_entry looks
+		 * for a first matching instance with given type.  So as
+		 * long as all ambiguous names occur in pairs of distinct
+		 * type, this will do the job.
+		 */
+
+		if (token_type == NUMBER
+		    && !strcmp("ma", _nc_curr_token.tk_name)) {
+		    /* tell max_attributes from arrow_key_map */
+		    entry_ptr = _nc_find_type_entry("ma", NUMBER,
+						    _nc_get_table(_nc_syntax
+								  != 0));
+		    assert(entry_ptr != 0);
+
+		} else if (token_type == STRING
+			   && !strcmp("MT", _nc_curr_token.tk_name)) {
+		    /* map terminfo's string MT to MT */
+		    entry_ptr = _nc_find_type_entry("MT", STRING,
+						    _nc_get_table(_nc_syntax
+								  != 0));
+		    assert(entry_ptr != 0);
+
+		} else if (token_type == BOOLEAN
+			   && entry_ptr->nte_type == STRING) {
+		    /* treat strings without following "=" as empty strings */
+		    token_type = STRING;
+		} else {
+		    /* we couldn't recover; skip this token */
+		    if (!silent) {
+			const char *type_name;
+			switch (entry_ptr->nte_type) {
+			case BOOLEAN:
+			    type_name = "boolean";
+			    break;
+			case STRING:
+			    type_name = "string";
+			    break;
+			case NUMBER:
+			    type_name = "numeric";
+			    break;
+			default:
+			    type_name = "unknown";
+			    break;
+			}
+			_nc_warning("wrong type used for %s capability '%s'",
+				    type_name, _nc_curr_token.tk_name);
+		    }
+		    continue;
+		}
+	    }
+
+	    /* now we know that the type/value combination is OK */
+	    switch (token_type) {
+	    case CANCEL:
+		switch (entry_ptr->nte_type) {
+		case BOOLEAN:
+		    entryp->tterm.Booleans[entry_ptr->nte_index] = CANCELLED_BOOLEAN;
+		    break;
+
+		case NUMBER:
+		    entryp->tterm.Numbers[entry_ptr->nte_index] = CANCELLED_NUMERIC;
+		    break;
+
+		case STRING:
+		    entryp->tterm.Strings[entry_ptr->nte_index] = CANCELLED_STRING;
+		    break;
+		}
+		break;
+
+	    case BOOLEAN:
+		entryp->tterm.Booleans[entry_ptr->nte_index] = TRUE;
+		break;
+
+	    case NUMBER:
+		entryp->tterm.Numbers[entry_ptr->nte_index] =
+		    _nc_curr_token.tk_valnumber;
+		break;
+
+	    case STRING:
+		ptr = _nc_curr_token.tk_valstring;
+		if (_nc_syntax == SYN_TERMCAP)
+		    ptr = _nc_captoinfo(_nc_curr_token.tk_name,
+					ptr,
+					parametrized[entry_ptr->nte_index]);
+		entryp->tterm.Strings[entry_ptr->nte_index] = _nc_save_str(ptr);
+		break;
+
+	    default:
+		if (!silent)
+		    _nc_warning("unknown token type");
+		_nc_panic_mode((char) ((_nc_syntax == SYN_TERMCAP) ? ':' : ','));
+		continue;
+	    }
+	}			/* end else cur_token.name != "use" */
+      nexttok:
+	continue;		/* cannot have a label w/o statement */
+    }				/* endwhile (not EOF and not NAMES) */
+
+    _nc_push_token(token_type);
+    _nc_set_type(_nc_first_name(entryp->tterm.term_names));
+
+    /*
+     * Try to deduce as much as possible from extension capabilities
+     * (this includes obsolete BSD capabilities).  Sigh...it would be more
+     * space-efficient to call this after use resolution, but it has
+     * to be done before entry allocation is wrapped up.
+     */
+    if (!literal) {
+	if (_nc_syntax == SYN_TERMCAP) {
+	    bool has_base_entry = FALSE;
+	    unsigned i;
+
+	    /*
+	     * Don't insert defaults if this is a `+' entry meant only
+	     * for inclusion in other entries (not sure termcap ever
+	     * had these, actually).
+	     */
+	    if (strchr(entryp->tterm.term_names, '+'))
+		has_base_entry = TRUE;
+	    else
+		/*
+		 * Otherwise, look for a base entry that will already
+		 * have picked up defaults via translation.
+		 */
+		for (i = 0; i < entryp->nuses; i++)
+		    if (!strchr((char *) entryp->uses[i].name, '+'))
+			has_base_entry = TRUE;
+
+	    postprocess_termcap(&entryp->tterm, has_base_entry);
+	} else
+	    postprocess_terminfo(&entryp->tterm);
+    }
+    _nc_wrap_entry(entryp, FALSE);
+
+    return (OK);
+}
+
+NCURSES_EXPORT(int)
+_nc_capcmp(const char *s, const char *t)
+/* compare two string capabilities, stripping out padding */
+{
+    if (!s && !t)
+	return (0);
+    else if (!s || !t)
+	return (1);
+
+    for (;;) {
+	if (s[0] == '$' && s[1] == '<') {
+	    for (s += 2;; s++)
+		if (!(isdigit(UChar(*s))
+		      || *s == '.'
+		      || *s == '*'
+		      || *s == '/'
+		      || *s == '>'))
+		    break;
+	}
+
+	if (t[0] == '$' && t[1] == '<') {
+	    for (t += 2;; t++)
+		if (!(isdigit(UChar(*t))
+		      || *t == '.'
+		      || *t == '*'
+		      || *t == '/'
+		      || *t == '>'))
+		    break;
+	}
+
+	/* we've now pushed s and t past any padding they were pointing at */
+
+	if (*s == '\0' && *t == '\0')
+	    return (0);
+
+	if (*s != *t)
+	    return (*t - *s);
+
+	/* else *s == *t but one is not NUL, so continue */
+	s++, t++;
+    }
+}
+
+static void
+append_acs0(string_desc * dst, int code, int src)
+{
+    if (src != 0) {
+	char temp[3];
+	temp[0] = (char) code;
+	temp[1] = (char) src;
+	temp[2] = 0;
+	_nc_safe_strcat(dst, temp);
+    }
+}
+
+static void
+append_acs(string_desc * dst, int code, char *src)
+{
+    if (src != 0 && strlen(src) == 1) {
+	append_acs0(dst, code, *src);
+    }
+}
+
+/*
+ * The ko capability, if present, consists of a comma-separated capability
+ * list.  For each capability, we may assume there is a keycap that sends the
+ * string which is the value of that capability.
+ */
+typedef struct {
+    const char *from;
+    const char *to;
+} assoc;
+static assoc const ko_xlate[] =
+{
+    {"al", "kil1"},		/* insert line key  -> KEY_IL    */
+    {"bt", "kcbt"},		/* back tab         -> KEY_BTAB  */
+    {"cd", "ked"},		/* clear-to-eos key -> KEY_EOL   */
+    {"ce", "kel"},		/* clear-to-eol key -> KEY_EOS   */
+    {"cl", "kclr"},		/* clear key        -> KEY_CLEAR */
+    {"ct", "tbc"},		/* clear all tabs   -> KEY_CATAB */
+    {"dc", "kdch1"},		/* delete char      -> KEY_DC    */
+    {"dl", "kdl1"},		/* delete line      -> KEY_DL    */
+    {"do", "kcud1"},		/* down key         -> KEY_DOWN  */
+    {"ei", "krmir"},		/* exit insert key  -> KEY_EIC   */
+    {"ho", "khome"},		/* home key         -> KEY_HOME  */
+    {"ic", "kich1"},		/* insert char key  -> KEY_IC    */
+    {"im", "kIC"},		/* insert-mode key  -> KEY_SIC   */
+    {"le", "kcub1"},		/* le key           -> KEY_LEFT  */
+    {"nd", "kcuf1"},		/* nd key           -> KEY_RIGHT */
+    {"nl", "kent"},		/* new line key     -> KEY_ENTER */
+    {"st", "khts"},		/* set-tab key      -> KEY_STAB  */
+    {"ta", CANCELLED_STRING},
+    {"up", "kcuu1"},		/* up-arrow key     -> KEY_UP    */
+    {(char *) 0, (char *) 0},
+};
+
+/*
+ * This routine fills in string caps that either had defaults under
+ * termcap or can be manufactured from obsolete termcap capabilities.
+ * It was lifted from Ross Ridge's mytinfo package.
+ */
+
+static const char C_CR[] = "\r";
+static const char C_LF[] = "\n";
+static const char C_BS[] = "\b";
+static const char C_HT[] = "\t";
+
+/*
+ * Note that WANTED and PRESENT are not simple inverses!  If a capability
+ * has been explicitly cancelled, it's not considered WANTED.
+ */
+#define WANTED(s)	((s) == ABSENT_STRING)
+#define PRESENT(s)	(((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING))
+
+/*
+ * This bit of legerdemain turns all the terminfo variable names into
+ * references to locations in the arrays Booleans, Numbers, and Strings ---
+ * precisely what's needed.
+ */
+
+#undef CUR
+#define CUR tp->
+
+static void
+postprocess_termcap(TERMTYPE *tp, bool has_base)
+{
+    char buf[MAX_LINE * 2 + 2];
+    string_desc result;
+
+    /*
+     * TERMCAP DEFAULTS AND OBSOLETE-CAPABILITY TRANSLATIONS
+     *
+     * This first part of the code is the functional inverse of the
+     * fragment in capdefaults.c.
+     * ----------------------------------------------------------------------
+     */
+
+    /* if there was a tc entry, assume we picked up defaults via that */
+    if (!has_base) {
+	if (WANTED(init_3string) && termcap_init2)
+	    init_3string = _nc_save_str(termcap_init2);
+
+	if (WANTED(reset_2string) && termcap_reset)
+	    reset_2string = _nc_save_str(termcap_reset);
+
+	if (WANTED(carriage_return)) {
+	    if (carriage_return_delay > 0) {
+		sprintf(buf, "%s$<%d>", C_CR, carriage_return_delay);
+		carriage_return = _nc_save_str(buf);
+	    } else
+		carriage_return = _nc_save_str(C_CR);
+	}
+	if (WANTED(cursor_left)) {
+	    if (backspace_delay > 0) {
+		sprintf(buf, "%s$<%d>", C_BS, backspace_delay);
+		cursor_left = _nc_save_str(buf);
+	    } else if (backspaces_with_bs == 1)
+		cursor_left = _nc_save_str(C_BS);
+	    else if (PRESENT(backspace_if_not_bs))
+		cursor_left = backspace_if_not_bs;
+	}
+	/* vi doesn't use "do", but it does seems to use nl (or '\n') instead */
+	if (WANTED(cursor_down)) {
+	    if (PRESENT(linefeed_if_not_lf))
+		cursor_down = linefeed_if_not_lf;
+	    else if (linefeed_is_newline != 1) {
+		if (new_line_delay > 0) {
+		    sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
+		    cursor_down = _nc_save_str(buf);
+		} else
+		    cursor_down = _nc_save_str(C_LF);
+	    }
+	}
+	if (WANTED(scroll_forward) && crt_no_scrolling != 1) {
+	    if (PRESENT(linefeed_if_not_lf))
+		cursor_down = linefeed_if_not_lf;
+	    else if (linefeed_is_newline != 1) {
+		if (new_line_delay > 0) {
+		    sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
+		    scroll_forward = _nc_save_str(buf);
+		} else
+		    scroll_forward = _nc_save_str(C_LF);
+	    }
+	}
+	if (WANTED(newline)) {
+	    if (linefeed_is_newline == 1) {
+		if (new_line_delay > 0) {
+		    sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
+		    newline = _nc_save_str(buf);
+		} else
+		    newline = _nc_save_str(C_LF);
+	    } else if (PRESENT(carriage_return) && PRESENT(scroll_forward)) {
+		_nc_str_init(&result, buf, sizeof(buf));
+		if (_nc_safe_strcat(&result, carriage_return)
+		    && _nc_safe_strcat(&result, scroll_forward))
+		    newline = _nc_save_str(buf);
+	    } else if (PRESENT(carriage_return) && PRESENT(cursor_down)) {
+		_nc_str_init(&result, buf, sizeof(buf));
+		if (_nc_safe_strcat(&result, carriage_return)
+		    && _nc_safe_strcat(&result, cursor_down))
+		    newline = _nc_save_str(buf);
+	    }
+	}
+    }
+
+    /*
+     * Inverse of capdefaults.c code ends here.
+     * ----------------------------------------------------------------------
+     *
+     * TERMCAP-TO TERMINFO MAPPINGS FOR SOURCE TRANSLATION
+     *
+     * These translations will *not* be inverted by tgetent().
+     */
+
+    if (!has_base) {
+	/*
+	 * We wait until now to decide if we've got a working cr because even
+	 * one that doesn't work can be used for newline. Unfortunately the
+	 * space allocated for it is wasted.
+	 */
+	if (return_does_clr_eol == 1 || no_correctly_working_cr == 1)
+	    carriage_return = ABSENT_STRING;
+
+	/*
+	 * Supposedly most termcap entries have ta now and '\t' is no longer a
+	 * default, but it doesn't seem to be true...
+	 */
+	if (WANTED(tab)) {
+	    if (horizontal_tab_delay > 0) {
+		sprintf(buf, "%s$<%d>", C_HT, horizontal_tab_delay);
+		tab = _nc_save_str(buf);
+	    } else
+		tab = _nc_save_str(C_HT);
+	}
+	if (init_tabs == ABSENT_NUMERIC && has_hardware_tabs == TRUE)
+	    init_tabs = 8;
+
+	/*
+	 * Assume we can beep with ^G unless we're given bl@.
+	 */
+	if (WANTED(bell))
+	    bell = _nc_save_str("\007");
+    }
+
+    /*
+     * Translate the old termcap :pt: capability to it#8 + ht=\t
+     */
+    if (has_hardware_tabs == TRUE) {
+	if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC)
+	    _nc_warning("hardware tabs with a width other than 8: %d", init_tabs);
+	else {
+	    if (tab && _nc_capcmp(tab, C_HT))
+		_nc_warning("hardware tabs with a non-^I tab string %s",
+			    _nc_visbuf(tab));
+	    else {
+		if (WANTED(tab))
+		    tab = _nc_save_str(C_HT);
+		init_tabs = 8;
+	    }
+	}
+    }
+    /*
+     * Now translate the ko capability, if there is one.  This
+     * isn't from mytinfo...
+     */
+    if (PRESENT(other_non_function_keys)) {
+	char *base = other_non_function_keys;
+	char *bp, *cp, *dp;
+	struct name_table_entry const *from_ptr;
+	struct name_table_entry const *to_ptr;
+	assoc const *ap;
+	char buf2[MAX_TERMINFO_LENGTH];
+	bool foundim;
+
+	/* we're going to use this for a special case later */
+	dp = strchr(other_non_function_keys, 'i');
+	foundim = (dp != 0) && (dp[1] == 'm');
+
+	/* look at each comma-separated capability in the ko string... */
+	for (base = other_non_function_keys;
+	     (cp = strchr(base, ',')) != 0;
+	     base = cp + 1) {
+	    size_t len = cp - base;
+
+	    for (ap = ko_xlate; ap->from; ap++) {
+		if (len == strlen(ap->from)
+		    && strncmp(ap->from, base, len) == 0)
+		    break;
+	    }
+	    if (!(ap->from && ap->to)) {
+		_nc_warning("unknown capability `%.*s' in ko string",
+			    (int) len, base);
+		continue;
+	    } else if (ap->to == CANCELLED_STRING)	/* ignore it */
+		continue;
+
+	    /* now we know we found a match in ko_table, so... */
+
+	    from_ptr = _nc_find_entry(ap->from, _nc_get_hash_table(TRUE));
+	    to_ptr = _nc_find_entry(ap->to, _nc_get_hash_table(FALSE));
+
+	    if (!from_ptr || !to_ptr)	/* should never happen! */
+		_nc_err_abort("ko translation table is invalid, I give up");
+
+	    if (WANTED(tp->Strings[from_ptr->nte_index])) {
+		_nc_warning("no value for ko capability %s", ap->from);
+		continue;
+	    }
+
+	    if (tp->Strings[to_ptr->nte_index]) {
+		/* There's no point in warning about it if it's the same
+		 * string; that's just an inefficiency.
+		 */
+		if (strcmp(
+			      tp->Strings[from_ptr->nte_index],
+			      tp->Strings[to_ptr->nte_index]) != 0)
+		    _nc_warning("%s (%s) already has an explicit value %s, ignoring ko",
+				ap->to, ap->from,
+				_nc_visbuf(tp->Strings[to_ptr->nte_index]));
+		continue;
+	    }
+
+	    /*
+	     * The magic moment -- copy the mapped key string over,
+	     * stripping out padding.
+	     */
+	    for (dp = buf2, bp = tp->Strings[from_ptr->nte_index]; *bp; bp++) {
+		if (bp[0] == '$' && bp[1] == '<') {
+		    while (*bp && *bp != '>') {
+			++bp;
+		    }
+		} else
+		    *dp++ = *bp;
+	    }
+	    *dp++ = '\0';
+
+	    tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
+	}
+
+	/*
+	 * Note: ko=im and ko=ic both want to grab the `Insert'
+	 * keycap.  There's a kich1 but no ksmir, so the ic capability
+	 * got mapped to kich1 and im to kIC to avoid a collision.
+	 * If the description has im but not ic, hack kIC back to kich1.
+	 */
+	if (foundim && WANTED(key_ic) && key_sic) {
+	    key_ic = key_sic;
+	    key_sic = ABSENT_STRING;
+	}
+    }
+
+    if (!has_base) {
+	if (!hard_copy) {
+	    if (WANTED(key_backspace))
+		key_backspace = _nc_save_str(C_BS);
+	    if (WANTED(key_left))
+		key_left = _nc_save_str(C_BS);
+	    if (WANTED(key_down))
+		key_down = _nc_save_str(C_LF);
+	}
+    }
+
+    /*
+     * Translate XENIX forms characters.
+     */
+    if (PRESENT(acs_ulcorner) ||
+	PRESENT(acs_llcorner) ||
+	PRESENT(acs_urcorner) ||
+	PRESENT(acs_lrcorner) ||
+	PRESENT(acs_ltee) ||
+	PRESENT(acs_rtee) ||
+	PRESENT(acs_btee) ||
+	PRESENT(acs_ttee) ||
+	PRESENT(acs_hline) ||
+	PRESENT(acs_vline) ||
+	PRESENT(acs_plus)) {
+	char buf2[MAX_TERMCAP_LENGTH];
+
+	_nc_str_init(&result, buf2, sizeof(buf2));
+	_nc_safe_strcat(&result, acs_chars);
+
+	append_acs(&result, 'j', acs_lrcorner);
+	append_acs(&result, 'k', acs_urcorner);
+	append_acs(&result, 'l', acs_ulcorner);
+	append_acs(&result, 'm', acs_llcorner);
+	append_acs(&result, 'n', acs_plus);
+	append_acs(&result, 'q', acs_hline);
+	append_acs(&result, 't', acs_ltee);
+	append_acs(&result, 'u', acs_rtee);
+	append_acs(&result, 'v', acs_btee);
+	append_acs(&result, 'w', acs_ttee);
+	append_acs(&result, 'x', acs_vline);
+
+	if (buf2[0]) {
+	    acs_chars = _nc_save_str(buf2);
+	    _nc_warning("acsc string synthesized from XENIX capabilities");
+	}
+    } else if (acs_chars == 0
+	       && enter_alt_charset_mode != 0
+	       && exit_alt_charset_mode != 0) {
+	acs_chars = _nc_save_str(VT_ACSC);
+    }
+}
+
+static void
+postprocess_terminfo(TERMTYPE *tp)
+{
+    /*
+     * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION
+     * ----------------------------------------------------------------------
+     */
+
+    /*
+     * Translate AIX forms characters.
+     */
+    if (PRESENT(box_chars_1)) {
+	char buf2[MAX_TERMCAP_LENGTH];
+	string_desc result;
+
+	_nc_str_init(&result, buf2, sizeof(buf2));
+	_nc_safe_strcat(&result, acs_chars);
+
+	append_acs0(&result, 'l', box_chars_1[0]);	/* ACS_ULCORNER */
+	append_acs0(&result, 'q', box_chars_1[1]);	/* ACS_HLINE */
+	append_acs0(&result, 'k', box_chars_1[2]);	/* ACS_URCORNER */
+	append_acs0(&result, 'x', box_chars_1[3]);	/* ACS_VLINE */
+	append_acs0(&result, 'j', box_chars_1[4]);	/* ACS_LRCORNER */
+	append_acs0(&result, 'm', box_chars_1[5]);	/* ACS_LLCORNER */
+	append_acs0(&result, 'w', box_chars_1[6]);	/* ACS_TTEE */
+	append_acs0(&result, 'u', box_chars_1[7]);	/* ACS_RTEE */
+	append_acs0(&result, 'v', box_chars_1[8]);	/* ACS_BTEE */
+	append_acs0(&result, 't', box_chars_1[9]);	/* ACS_LTEE */
+	append_acs0(&result, 'n', box_chars_1[10]);	/* ACS_PLUS */
+
+	if (buf2[0]) {
+	    acs_chars = _nc_save_str(buf2);
+	    _nc_warning("acsc string synthesized from AIX capabilities");
+	    box_chars_1 = ABSENT_STRING;
+	}
+    }
+    /*
+     * ----------------------------------------------------------------------
+     */
+}
+
+/*
+ * Do a linear search through the terminfo tables to find a given full-name.
+ * We don't expect to do this often, so there's no hashing function.
+ *
+ * In effect, this scans through the 3 lists of full-names, and looks them
+ * up in _nc_info_table, which is organized so that the nte_index fields are
+ * sorted, but the nte_type fields are not necessarily grouped together.
+ */
+static struct name_table_entry const *
+lookup_fullname(const char *find)
+{
+    int state = -1;
+
+    for (;;) {
+	int count = 0;
+	NCURSES_CONST char *const *names;
+
+	switch (++state) {
+	case BOOLEAN:
+	    names = boolfnames;
+	    break;
+	case STRING:
+	    names = strfnames;
+	    break;
+	case NUMBER:
+	    names = numfnames;
+	    break;
+	default:
+	    return NOTFOUND;
+	}
+
+	for (count = 0; names[count] != 0; count++) {
+	    if (!strcmp(names[count], find)) {
+		struct name_table_entry const *entry_ptr = _nc_get_table(FALSE);
+		while (entry_ptr->nte_type != state
+		       || entry_ptr->nte_index != count)
+		    entry_ptr++;
+		return entry_ptr;
+	    }
+	}
+    }
+}
+
+/* parse_entry.c ends here */
diff --git a/ncurses/tinfo/read_entry.c b/ncurses/tinfo/read_entry.c
new file mode 100644
index 0000000..b4ea61c
--- /dev/null
+++ b/ncurses/tinfo/read_entry.c
@@ -0,0 +1,546 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	read_entry.c -- Routine for reading in a compiled terminfo file
+ */
+
+#include <curses.priv.h>
+#include <hashed_db.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: read_entry.c,v 1.102 2008/08/03 19:33:04 tom Exp $")
+
+#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
+
+#if USE_DATABASE
+static void
+convert_shorts(char *buf, short *Numbers, int count)
+{
+    int i;
+    for (i = 0; i < count; i++) {
+	if (IS_NEG1(buf + 2 * i))
+	    Numbers[i] = ABSENT_NUMERIC;
+	else if (IS_NEG2(buf + 2 * i))
+	    Numbers[i] = CANCELLED_NUMERIC;
+	else
+	    Numbers[i] = LOW_MSB(buf + 2 * i);
+	TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i]));
+    }
+}
+
+static void
+convert_strings(char *buf, char **Strings, int count, int size, char *table)
+{
+    int i;
+    char *p;
+
+    for (i = 0; i < count; i++) {
+	if (IS_NEG1(buf + 2 * i)) {
+	    Strings[i] = ABSENT_STRING;
+	} else if (IS_NEG2(buf + 2 * i)) {
+	    Strings[i] = CANCELLED_STRING;
+	} else if ((int) LOW_MSB(buf + 2 * i) > size) {
+	    Strings[i] = ABSENT_STRING;
+	} else {
+	    Strings[i] = (LOW_MSB(buf + 2 * i) + table);
+	    TR(TRACE_DATABASE, ("Strings[%d] = %s", i, _nc_visbuf(Strings[i])));
+	}
+
+	/* make sure all strings are NUL terminated */
+	if (VALID_STRING(Strings[i])) {
+	    for (p = Strings[i]; p <= table + size; p++)
+		if (*p == '\0')
+		    break;
+	    /* if there is no NUL, ignore the string */
+	    if (p > table + size)
+		Strings[i] = ABSENT_STRING;
+	}
+    }
+}
+
+static int
+fake_read(char *src, int *offset, int limit, char *dst, unsigned want)
+{
+    int have = (limit - *offset);
+
+    if (have > 0) {
+	if ((int) want > have)
+	    want = have;
+	memcpy(dst, src + *offset, want);
+	*offset += want;
+    } else {
+	want = 0;
+    }
+    return (int) want;
+}
+
+#define Read(buf, count) fake_read(buffer, &offset, limit, buf, count)
+
+#define read_shorts(buf, count) \
+	(Read(buf, (unsigned) (count)*2) == (int) (count)*2)
+
+#define even_boundary(value) \
+    if ((value) % 2 != 0) Read(buf, 1)
+
+NCURSES_EXPORT(int)
+_nc_read_termtype(TERMTYPE *ptr, char *buffer, int limit)
+/* return 1 if read, 0 if not found or garbled */
+{
+    int offset = 0;
+    int name_size, bool_count, num_count, str_count, str_size;
+    int i;
+    char buf[MAX_ENTRY_SIZE + 1];
+    char *string_table;
+    unsigned want, have;
+
+    TR(TRACE_DATABASE, ("READ termtype header @%d", offset));
+
+    memset(ptr, 0, sizeof(*ptr));
+
+    /* grab the header */
+    if (!read_shorts(buf, 6)
+	|| !IS_TIC_MAGIC(buf)) {
+	return (TGETENT_NO);
+    }
+
+    name_size = LOW_MSB(buf + 2);
+    bool_count = LOW_MSB(buf + 4);
+    num_count = LOW_MSB(buf + 6);
+    str_count = LOW_MSB(buf + 8);
+    str_size = LOW_MSB(buf + 10);
+
+    TR(TRACE_DATABASE,
+       ("TERMTYPE name_size=%d, bool=%d/%d, num=%d/%d str=%d/%d(%d)",
+	name_size, bool_count, BOOLCOUNT, num_count, NUMCOUNT,
+	str_count, STRCOUNT, str_size));
+    if (name_size < 0
+	|| bool_count < 0
+	|| num_count < 0
+	|| str_count < 0
+	|| str_size < 0) {
+	return (TGETENT_NO);
+    }
+
+    want = str_size + name_size + 1;
+    if (str_size) {
+	/* try to allocate space for the string table */
+	if (str_count * 2 >= (int) sizeof(buf)
+	    || (string_table = typeMalloc(char, want)) == 0) {
+	    return (TGETENT_NO);
+	}
+    } else {
+	str_count = 0;
+	if ((string_table = typeMalloc(char, want)) == 0) {
+	    return (TGETENT_NO);
+	}
+    }
+
+    /* grab the name (a null-terminated string) */
+    want = min(MAX_NAME_SIZE, (unsigned) name_size);
+    ptr->str_table = string_table;
+    ptr->term_names = string_table;
+    if ((have = Read(ptr->term_names, want)) != want) {
+	memset(ptr->term_names + have, 0, want - have);
+    }
+    ptr->term_names[want] = '\0';
+    string_table += (want + 1);
+
+    if (have > MAX_NAME_SIZE)
+	offset = (have - MAX_NAME_SIZE);
+
+    /* grab the booleans */
+    if ((ptr->Booleans = TYPE_CALLOC(NCURSES_SBOOL,
+				     max(BOOLCOUNT, bool_count))) == 0
+	|| Read(ptr->Booleans, (unsigned) bool_count) < bool_count) {
+	return (TGETENT_NO);
+    }
+
+    /*
+     * If booleans end on an odd byte, skip it.  The machine they
+     * originally wrote terminfo on must have been a 16-bit
+     * word-oriented machine that would trap out if you tried a
+     * word access off a 2-byte boundary.
+     */
+    even_boundary(name_size + bool_count);
+
+    /* grab the numbers */
+    if ((ptr->Numbers = TYPE_CALLOC(short, max(NUMCOUNT, num_count))) == 0
+	|| !read_shorts(buf, num_count)) {
+	return (TGETENT_NO);
+    }
+    convert_shorts(buf, ptr->Numbers, num_count);
+
+    if ((ptr->Strings = TYPE_CALLOC(char *, max(STRCOUNT, str_count))) == 0)
+	  return (TGETENT_NO);
+
+    if (str_count) {
+	/* grab the string offsets */
+	if (!read_shorts(buf, str_count)) {
+	    return (TGETENT_NO);
+	}
+	/* finally, grab the string table itself */
+	if (Read(string_table, (unsigned) str_size) != str_size)
+	    return (TGETENT_NO);
+	convert_strings(buf, ptr->Strings, str_count, str_size, string_table);
+    }
+#if NCURSES_XNAMES
+
+    ptr->num_Booleans = BOOLCOUNT;
+    ptr->num_Numbers = NUMCOUNT;
+    ptr->num_Strings = STRCOUNT;
+
+    /*
+     * Read extended entries, if any, after the normal end of terminfo data.
+     */
+    even_boundary(str_size);
+    TR(TRACE_DATABASE, ("READ extended_header @%d", offset));
+    if (_nc_user_definable && read_shorts(buf, 5)) {
+	int ext_bool_count = LOW_MSB(buf + 0);
+	int ext_num_count = LOW_MSB(buf + 2);
+	int ext_str_count = LOW_MSB(buf + 4);
+	int ext_str_size = LOW_MSB(buf + 6);
+	int ext_str_limit = LOW_MSB(buf + 8);
+	unsigned need = (ext_bool_count + ext_num_count + ext_str_count);
+	int base = 0;
+
+	if (need >= sizeof(buf)
+	    || ext_str_size >= (int) sizeof(buf)
+	    || ext_str_limit >= (int) sizeof(buf)
+	    || ext_bool_count < 0
+	    || ext_num_count < 0
+	    || ext_str_count < 0
+	    || ext_str_size < 0
+	    || ext_str_limit < 0)
+	    return (TGETENT_NO);
+
+	ptr->num_Booleans = BOOLCOUNT + ext_bool_count;
+	ptr->num_Numbers = NUMCOUNT + ext_num_count;
+	ptr->num_Strings = STRCOUNT + ext_str_count;
+
+	ptr->Booleans = typeRealloc(NCURSES_SBOOL, ptr->num_Booleans, ptr->Booleans);
+	ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers);
+	ptr->Strings = typeRealloc(char *, ptr->num_Strings, ptr->Strings);
+
+	TR(TRACE_DATABASE, ("extended header is %d/%d/%d(%d:%d)",
+			    ext_bool_count, ext_num_count, ext_str_count,
+			    ext_str_size, ext_str_limit));
+
+	TR(TRACE_DATABASE, ("READ %d extended-booleans @%d",
+			    ext_bool_count, offset));
+	if ((ptr->ext_Booleans = ext_bool_count) != 0) {
+	    if (Read(ptr->Booleans + BOOLCOUNT, (unsigned)
+		     ext_bool_count) != ext_bool_count)
+		return (TGETENT_NO);
+	}
+	even_boundary(ext_bool_count);
+
+	TR(TRACE_DATABASE, ("READ %d extended-numbers @%d",
+			    ext_num_count, offset));
+	if ((ptr->ext_Numbers = ext_num_count) != 0) {
+	    if (!read_shorts(buf, ext_num_count))
+		return (TGETENT_NO);
+	    TR(TRACE_DATABASE, ("Before converting extended-numbers"));
+	    convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count);
+	}
+
+	TR(TRACE_DATABASE, ("READ extended-offsets @%d", offset));
+	if ((ext_str_count || need)
+	    && !read_shorts(buf, ext_str_count + need))
+	    return (TGETENT_NO);
+
+	TR(TRACE_DATABASE, ("READ %d bytes of extended-strings @%d",
+			    ext_str_limit, offset));
+
+	if (ext_str_limit) {
+	    if ((ptr->ext_str_table = typeMalloc(char, ext_str_limit)) == 0)
+		  return (TGETENT_NO);
+	    if (Read(ptr->ext_str_table, (unsigned) ext_str_limit) != ext_str_limit)
+		return (TGETENT_NO);
+	    TR(TRACE_DATABASE, ("first extended-string is %s", _nc_visbuf(ptr->ext_str_table)));
+	}
+
+	if ((ptr->ext_Strings = ext_str_count) != 0) {
+	    TR(TRACE_DATABASE,
+	       ("Before computing extended-string capabilities str_count=%d, ext_str_count=%d",
+		str_count, ext_str_count));
+	    convert_strings(buf, ptr->Strings + str_count, ext_str_count,
+			    ext_str_limit, ptr->ext_str_table);
+	    for (i = ext_str_count - 1; i >= 0; i--) {
+		TR(TRACE_DATABASE, ("MOVE from [%d:%d] %s",
+				    i, i + str_count,
+				    _nc_visbuf(ptr->Strings[i + str_count])));
+		ptr->Strings[i + STRCOUNT] = ptr->Strings[i + str_count];
+		if (VALID_STRING(ptr->Strings[i + STRCOUNT]))
+		    base += (strlen(ptr->Strings[i + STRCOUNT]) + 1);
+		TR(TRACE_DATABASE, ("... to    [%d] %s",
+				    i + STRCOUNT,
+				    _nc_visbuf(ptr->Strings[i + STRCOUNT])));
+	    }
+	}
+
+	if (need) {
+	    if (ext_str_count >= (MAX_ENTRY_SIZE * 2))
+		  return (TGETENT_NO);
+	    if ((ptr->ext_Names = TYPE_CALLOC(char *, need)) == 0)
+		  return (TGETENT_NO);
+	    TR(TRACE_DATABASE,
+	       ("ext_NAMES starting @%d in extended_strings, first = %s",
+		base, _nc_visbuf(ptr->ext_str_table + base)));
+	    convert_strings(buf + (2 * ext_str_count),
+			    ptr->ext_Names,
+			    (int) need,
+			    ext_str_limit, ptr->ext_str_table + base);
+	}
+
+	T(("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)",
+	   ptr->num_Booleans, ptr->ext_Booleans,
+	   ptr->num_Numbers, ptr->ext_Numbers,
+	   ptr->num_Strings, ptr->ext_Strings));
+
+	TR(TRACE_DATABASE, ("extend: num_Booleans:%d", ptr->num_Booleans));
+    } else
+#endif /* NCURSES_XNAMES */
+    {
+	T(("...done reading terminfo bool %d num %d str %d",
+	   bool_count, num_count, str_count));
+#if NCURSES_XNAMES
+	TR(TRACE_DATABASE, ("normal: num_Booleans:%d", ptr->num_Booleans));
+#endif
+    }
+
+    for (i = bool_count; i < BOOLCOUNT; i++)
+	ptr->Booleans[i] = FALSE;
+    for (i = num_count; i < NUMCOUNT; i++)
+	ptr->Numbers[i] = ABSENT_NUMERIC;
+    for (i = str_count; i < STRCOUNT; i++)
+	ptr->Strings[i] = ABSENT_STRING;
+
+    return (TGETENT_YES);
+}
+
+/*
+ *	int
+ *	_nc_read_file_entry(filename, ptr)
+ *
+ *	Read the compiled terminfo entry in the given file into the
+ *	structure pointed to by ptr, allocating space for the string
+ *	table.
+ */
+NCURSES_EXPORT(int)
+_nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
+/* return 1 if read, 0 if not found or garbled */
+{
+    int code, fd = -1;
+    int limit;
+    char buffer[MAX_ENTRY_SIZE + 1];
+
+    if (_nc_access(filename, R_OK) < 0
+	|| (fd = open(filename, O_RDONLY | O_BINARY)) < 0) {
+	T(("cannot open terminfo %s (errno=%d)", filename, errno));
+	code = TGETENT_NO;
+    } else {
+	if ((limit = read(fd, buffer, sizeof(buffer))) > 0) {
+
+	    T(("read terminfo %s", filename));
+	    if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) {
+		_nc_free_termtype(ptr);
+	    }
+	} else {
+	    code = TGETENT_NO;
+	}
+	close(fd);
+    }
+
+    return (code);
+}
+
+/*
+ * Build a terminfo pathname and try to read the data.  Returns TGETENT_YES on
+ * success, TGETENT_NO on failure.
+ */
+static int
+_nc_read_tic_entry(char *filename,
+		   unsigned limit,
+		   const char *const path,
+		   const char *name,
+		   TERMTYPE *const tp)
+{
+    int result = TGETENT_NO;
+
+    /*
+     * If we are looking in a directory, assume the entry is a file under that,
+     * according to the normal rules.
+     *
+     * FIXME - add caseless-filename fixup.
+     */
+    if (_nc_is_dir_path(path)) {
+	unsigned need = 4 + strlen(path) + strlen(name);
+
+	if (need <= limit) {
+	    (void) sprintf(filename, "%s/" LEAF_FMT "/%s", path, *name, name);
+	    result = _nc_read_file_entry(filename, tp);
+	}
+    }
+#if USE_HASHED_DB
+    else {
+	static const char suffix[] = DBM_SUFFIX;
+	DB *capdbp;
+	unsigned lens = sizeof(suffix) - 1;
+	unsigned size = strlen(path);
+	unsigned need = lens + size;
+
+	if (need <= limit) {
+	    if (size >= lens
+		&& !strcmp(path + size - lens, suffix))
+		(void) strcpy(filename, path);
+	    else
+		(void) sprintf(filename, "%s%s", path, suffix);
+
+	    /*
+	     * It would be nice to optimize the dbopen/close activity, as
+	     * done in the cgetent implementation for tc= clauses.  However,
+	     * since we support multiple database locations, we cannot do
+	     * that.
+	     */
+	    if ((capdbp = _nc_db_open(filename, FALSE)) != 0) {
+		DBT key, data;
+		int reccnt = 0;
+		char *save = strdup(name);
+
+		memset(&key, 0, sizeof(key));
+		key.data = save;
+		key.size = strlen(save);
+
+		/*
+		 * This lookup could return termcap data, which we do not want. 
+		 * We are looking for compiled (binary) terminfo data.
+		 *
+		 * cgetent uses a two-level lookup.  On the first it uses the
+		 * given name to return a record containing only the aliases
+		 * for an entry.  On the second (using that list of aliases as
+		 * a key), it returns the content of the terminal description. 
+		 * We expect second lookup to return data beginning with the
+		 * same set of aliases.
+		 *
+		 * For compiled terminfo, the list of aliases in the second
+		 * case will be null-terminated.  A termcap entry will not be,
+		 * and will run on into the description.  So we can easily
+		 * distinguish between the two (source/binary) by checking the
+		 * lengths.
+		 */
+		while (_nc_db_get(capdbp, &key, &data) == 0) {
+		    int used = data.size - 1;
+		    char *have = (char *) data.data;
+
+		    if (*have++ == 0) {
+			if (data.size > key.size
+			    && IS_TIC_MAGIC(have)) {
+			    result = _nc_read_termtype(tp, have, used);
+			    if (result == TGETENT_NO) {
+				_nc_free_termtype(tp);
+			    }
+			}
+			break;
+		    }
+
+		    /*
+		     * Just in case we have a corrupt database, do not waste
+		     * time with it.
+		     */
+		    if (++reccnt >= 3)
+			break;
+
+		    /*
+		     * Prepare for the second level.
+		     */
+		    key.data = have;
+		    key.size = used;
+		}
+
+		_nc_db_close(capdbp);
+		free(save);
+	    }
+	}
+    }
+#endif
+    return result;
+}
+#endif /* USE_DATABASE */
+
+/*
+ *	_nc_read_entry(char *name, char *filename, TERMTYPE *tp)
+ *
+ *	Find and read the compiled entry for a given terminal type,
+ *	if it exists.  We take pains here to make sure no combination
+ *	of environment variables and terminal type name can be used to
+ *	overrun the file buffer.
+ */
+
+NCURSES_EXPORT(int)
+_nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp)
+{
+    int code = TGETENT_NO;
+
+    if (strlen(name) == 0
+	|| strcmp(name, ".") == 0
+	|| strcmp(name, "..") == 0
+	|| _nc_pathlast(name) != 0
+	|| strchr(name, NCURSES_PATHSEP) != 0) {
+	T(("illegal or missing entry name '%s'", name));
+    } else {
+#if USE_DATABASE
+	DBDIRS state = dbdTIC;
+	int offset = 0;
+	const char *path;
+
+	while ((path = _nc_next_db(&state, &offset)) != 0) {
+	    code = _nc_read_tic_entry(filename, PATH_MAX, path, name, tp);
+	    if (code == TGETENT_YES) {
+		_nc_last_db();
+		break;
+	    }
+	}
+#endif
+#if USE_TERMCAP
+	if (code != TGETENT_YES) {
+	    code = _nc_read_termcap_entry(name, tp);
+	    sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source());
+	}
+#endif
+    }
+    return code;
+}
diff --git a/ncurses/tinfo/read_termcap.c b/ncurses/tinfo/read_termcap.c
new file mode 100644
index 0000000..d94d1a4
--- /dev/null
+++ b/ncurses/tinfo/read_termcap.c
@@ -0,0 +1,1174 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ * Termcap compatibility support
+ *
+ * If your OS integrator didn't install a terminfo database, you can call
+ * _nc_read_termcap_entry() to support reading and translating capabilities
+ * from the system termcap file.  This is a kludge; it will bulk up and slow
+ * down every program that uses ncurses, and translated termcap entries cannot
+ * use full terminfo capabilities.  Don't use it unless you absolutely have to;
+ * instead, get your system people to run tic(1) from root on the terminfo
+ * master included with ncurses to translate it into a terminfo database.
+ *
+ * If USE_GETCAP is enabled, we use what is effectively a copy of the 4.4BSD
+ * getcap code to fetch entries.  There are disadvantages to this; mainly that
+ * getcap(3) does its own resolution, meaning that entries read in in this way
+ * can't reference the terminfo tree.  The only thing it buys is faster startup
+ * time, getcap(3) is much faster than our tic parser.
+ */
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: read_termcap.c,v 1.71 2006/07/29 12:06:51 tom Exp $")
+
+#if !PURE_TERMINFO
+
+#define TC_SUCCESS     0
+#define TC_NOT_FOUND  -1
+#define TC_SYS_ERR    -2
+#define TC_REF_LOOP   -3
+#define TC_UNRESOLVED -4	/* this is not returned by BSD cgetent */
+
+static NCURSES_CONST char *
+get_termpath(void)
+{
+    NCURSES_CONST char *result;
+
+    if (!use_terminfo_vars() || (result = getenv("TERMPATH")) == 0)
+	result = TERMPATH;
+    T(("TERMPATH is %s", result));
+    return result;
+}
+
+#if USE_GETCAP
+
+#if HAVE_BSD_CGETENT
+#define _nc_cgetcap   cgetcap
+#define _nc_cgetent(buf, oline, db_array, name) cgetent(buf, db_array, name)
+#define _nc_cgetmatch cgetmatch
+#define _nc_cgetset   cgetset
+#else
+static int _nc_cgetmatch(char *, const char *);
+static int _nc_getent(char **, unsigned *, int *, int, char **, int, const char
+		      *, int, char *);
+static int _nc_nfcmp(const char *, char *);
+
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Casey Leedom of Lawrence Livermore National Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgment:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* static char sccsid[] = "@(#)getcap.c	8.3 (Berkeley) 3/25/94"; */
+
+#define	BFRAG		1024
+#define	BSIZE		1024
+#define	MAX_RECURSION	32	/* maximum getent recursion */
+
+static size_t topreclen;	/* toprec length */
+static char *toprec;		/* Additional record specified by cgetset() */
+static int gottoprec;		/* Flag indicating retrieval of toprecord */
+
+/*
+ * Cgetset() allows the addition of a user specified buffer to be added to the
+ * database array, in effect "pushing" the buffer on top of the virtual
+ * database.  0 is returned on success, -1 on failure.
+ */
+static int
+_nc_cgetset(const char *ent)
+{
+    if (ent == 0) {
+	FreeIfNeeded(toprec);
+	toprec = 0;
+	topreclen = 0;
+	return (0);
+    }
+    topreclen = strlen(ent);
+    if ((toprec = typeMalloc(char, topreclen + 1)) == 0) {
+	errno = ENOMEM;
+	return (-1);
+    }
+    gottoprec = 0;
+    (void) strcpy(toprec, ent);
+    return (0);
+}
+
+/*
+ * Cgetcap searches the capability record buf for the capability cap with type
+ * `type'.  A pointer to the value of cap is returned on success, 0 if the
+ * requested capability couldn't be found.
+ *
+ * Specifying a type of ':' means that nothing should follow cap (:cap:).  In
+ * this case a pointer to the terminating ':' or NUL will be returned if cap is
+ * found.
+ *
+ * If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator)
+ * return 0.
+ */
+static char *
+_nc_cgetcap(char *buf, const char *cap, int type)
+{
+    register const char *cp;
+    register char *bp;
+
+    bp = buf;
+    for (;;) {
+	/*
+	 * Skip past the current capability field - it's either the
+	 * name field if this is the first time through the loop, or
+	 * the remainder of a field whose name failed to match cap.
+	 */
+	for (;;) {
+	    if (*bp == '\0')
+		return (0);
+	    else if (*bp++ == ':')
+		break;
+	}
+
+	/*
+	 * Try to match (cap, type) in buf.
+	 */
+	for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++)
+	    continue;
+	if (*cp != '\0')
+	    continue;
+	if (*bp == '@')
+	    return (0);
+	if (type == ':') {
+	    if (*bp != '\0' && *bp != ':')
+		continue;
+	    return (bp);
+	}
+	if (*bp != type)
+	    continue;
+	bp++;
+	return (*bp == '@' ? 0 : bp);
+    }
+    /* NOTREACHED */
+}
+
+/*
+ * Cgetent extracts the capability record name from the NULL terminated file
+ * array db_array and returns a pointer to a malloc'd copy of it in buf.  Buf
+ * must be retained through all subsequent calls to cgetcap, cgetnum, cgetflag,
+ * and cgetstr, but may then be freed.
+ *
+ * Returns:
+ *
+ * positive #    on success (i.e., the index in db_array)
+ * TC_NOT_FOUND  if the requested record couldn't be found
+ * TC_SYS_ERR    if a system error was encountered (e.g.,couldn't open a file)
+ * TC_REF_LOOP   if a potential reference loop is detected
+ * TC_UNRESOLVED if we had too many recurrences to resolve
+ */
+static int
+_nc_cgetent(char **buf, int *oline, char **db_array, const char *name)
+{
+    unsigned dummy;
+
+    return (_nc_getent(buf, &dummy, oline, 0, db_array, -1, name, 0, 0));
+}
+
+/*
+ * Getent implements the functions of cgetent.  If fd is non-negative,
+ * *db_array has already been opened and fd is the open file descriptor.  We
+ * do this to save time and avoid using up file descriptors for tc=
+ * recursions.
+ *
+ * Getent returns the same success/failure codes as cgetent.  On success, a
+ * pointer to a malloc'd capability record with all tc= capabilities fully
+ * expanded and its length (not including trailing ASCII NUL) are left in
+ * *cap and *len.
+ *
+ * Basic algorithm:
+ *	+ Allocate memory incrementally as needed in chunks of size BFRAG
+ *	  for capability buffer.
+ *	+ Recurse for each tc=name and interpolate result.  Stop when all
+ *	  names interpolated, a name can't be found, or depth exceeds
+ *	  MAX_RECURSION.
+ */
+#define DOALLOC(size) typeRealloc(char, size, record)
+static int
+_nc_getent(
+	      char **cap,	/* termcap-content */
+	      unsigned *len,	/* length, needed for recursion */
+	      int *beginning,	/* line-number at match */
+	      int in_array,	/* index in 'db_array[] */
+	      char **db_array,	/* list of files to search */
+	      int fd,
+	      const char *name,
+	      int depth,
+	      char *nfield)
+{
+    register char *r_end, *rp;
+    int myfd = FALSE;
+    char *record = 0;
+    int tc_not_resolved;
+    int current;
+    int lineno;
+
+    /*
+     * Return with ``loop detected'' error if we've recurred more than
+     * MAX_RECURSION times.
+     */
+    if (depth > MAX_RECURSION)
+	return (TC_REF_LOOP);
+
+    /*
+     * Check if we have a top record from cgetset().
+     */
+    if (depth == 0 && toprec != 0 && _nc_cgetmatch(toprec, name) == 0) {
+	if ((record = DOALLOC(topreclen + BFRAG)) == 0) {
+	    errno = ENOMEM;
+	    return (TC_SYS_ERR);
+	}
+	(void) strcpy(record, toprec);
+	rp = record + topreclen + 1;
+	r_end = rp + BFRAG;
+	current = in_array;
+    } else {
+	int foundit;
+
+	/*
+	 * Allocate first chunk of memory.
+	 */
+	if ((record = DOALLOC(BFRAG)) == 0) {
+	    errno = ENOMEM;
+	    return (TC_SYS_ERR);
+	}
+	rp = r_end = record + BFRAG;
+	foundit = FALSE;
+
+	/*
+	 * Loop through database array until finding the record.
+	 */
+	for (current = in_array; db_array[current] != 0; current++) {
+	    int eof = FALSE;
+
+	    /*
+	     * Open database if not already open.
+	     */
+	    if (fd >= 0) {
+		(void) lseek(fd, (off_t) 0, SEEK_SET);
+	    } else if ((_nc_access(db_array[current], R_OK) < 0)
+		       || (fd = open(db_array[current], O_RDONLY, 0)) < 0) {
+		/* No error on unfound file. */
+		if (errno == ENOENT)
+		    continue;
+		free(record);
+		return (TC_SYS_ERR);
+	    } else {
+		myfd = TRUE;
+	    }
+	    lineno = 0;
+
+	    /*
+	     * Find the requested capability record ...
+	     */
+	    {
+		char buf[2048];
+		register char *b_end = buf;
+		register char *bp = buf;
+		register int c;
+
+		/*
+		 * Loop invariants:
+		 *      There is always room for one more character in record.
+		 *      R_end always points just past end of record.
+		 *      Rp always points just past last character in record.
+		 *      B_end always points just past last character in buf.
+		 *      Bp always points at next character in buf.
+		 */
+
+		for (;;) {
+		    int first = lineno + 1;
+
+		    /*
+		     * Read in a line implementing (\, newline)
+		     * line continuation.
+		     */
+		    rp = record;
+		    for (;;) {
+			if (bp >= b_end) {
+			    int n;
+
+			    n = read(fd, buf, sizeof(buf));
+			    if (n <= 0) {
+				if (myfd)
+				    (void) close(fd);
+				if (n < 0) {
+				    free(record);
+				    return (TC_SYS_ERR);
+				}
+				fd = -1;
+				eof = TRUE;
+				break;
+			    }
+			    b_end = buf + n;
+			    bp = buf;
+			}
+
+			c = *bp++;
+			if (c == '\n') {
+			    lineno++;
+			    if (rp == record || *(rp - 1) != '\\')
+				break;
+			}
+			*rp++ = c;
+
+			/*
+			 * Enforce loop invariant: if no room
+			 * left in record buffer, try to get
+			 * some more.
+			 */
+			if (rp >= r_end) {
+			    unsigned pos;
+			    size_t newsize;
+
+			    pos = rp - record;
+			    newsize = r_end - record + BFRAG;
+			    record = DOALLOC(newsize);
+			    if (record == 0) {
+				if (myfd)
+				    (void) close(fd);
+				errno = ENOMEM;
+				return (TC_SYS_ERR);
+			    }
+			    r_end = record + newsize;
+			    rp = record + pos;
+			}
+		    }
+		    /* loop invariant lets us do this */
+		    *rp++ = '\0';
+
+		    /*
+		     * If encountered eof check next file.
+		     */
+		    if (eof)
+			break;
+
+		    /*
+		     * Toss blank lines and comments.
+		     */
+		    if (*record == '\0' || *record == '#')
+			continue;
+
+		    /*
+		     * See if this is the record we want ...
+		     */
+		    if (_nc_cgetmatch(record, name) == 0
+			&& (nfield == 0
+			    || !_nc_nfcmp(nfield, record))) {
+			foundit = TRUE;
+			*beginning = first;
+			break;	/* found it! */
+		    }
+		}
+	    }
+	    if (foundit)
+		break;
+	}
+
+	if (!foundit)
+	    return (TC_NOT_FOUND);
+    }
+
+    /*
+     * Got the capability record, but now we have to expand all tc=name
+     * references in it ...
+     */
+    {
+	register char *newicap, *s;
+	register int newilen;
+	unsigned ilen;
+	int diff, iret, tclen, oline;
+	char *icap, *scan, *tc, *tcstart, *tcend;
+
+	/*
+	 * Loop invariants:
+	 *      There is room for one more character in record.
+	 *      R_end points just past end of record.
+	 *      Rp points just past last character in record.
+	 *      Scan points at remainder of record that needs to be
+	 *      scanned for tc=name constructs.
+	 */
+	scan = record;
+	tc_not_resolved = FALSE;
+	for (;;) {
+	    if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0)
+		break;
+
+	    /*
+	     * Find end of tc=name and stomp on the trailing `:'
+	     * (if present) so we can use it to call ourselves.
+	     */
+	    s = tc;
+	    while (*s != '\0') {
+		if (*s++ == ':') {
+		    *(s - 1) = '\0';
+		    break;
+		}
+	    }
+	    tcstart = tc - 3;
+	    tclen = s - tcstart;
+	    tcend = s;
+
+	    iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd,
+			      tc, depth + 1, 0);
+	    newicap = icap;	/* Put into a register. */
+	    newilen = ilen;
+	    if (iret != TC_SUCCESS) {
+		/* an error */
+		if (iret < TC_NOT_FOUND) {
+		    if (myfd)
+			(void) close(fd);
+		    free(record);
+		    return (iret);
+		}
+		if (iret == TC_UNRESOLVED)
+		    tc_not_resolved = TRUE;
+		/* couldn't resolve tc */
+		if (iret == TC_NOT_FOUND) {
+		    *(s - 1) = ':';
+		    scan = s - 1;
+		    tc_not_resolved = TRUE;
+		    continue;
+		}
+	    }
+
+	    /* not interested in name field of tc'ed record */
+	    s = newicap;
+	    while (*s != '\0' && *s++ != ':') ;
+	    newilen -= s - newicap;
+	    newicap = s;
+
+	    /* make sure interpolated record is `:'-terminated */
+	    s += newilen;
+	    if (*(s - 1) != ':') {
+		*s = ':';	/* overwrite NUL with : */
+		newilen++;
+	    }
+
+	    /*
+	     * Make sure there's enough room to insert the
+	     * new record.
+	     */
+	    diff = newilen - tclen;
+	    if (diff >= r_end - rp) {
+		unsigned pos, tcpos, tcposend;
+		size_t newsize;
+
+		pos = rp - record;
+		newsize = r_end - record + diff + BFRAG;
+		tcpos = tcstart - record;
+		tcposend = tcend - record;
+		record = DOALLOC(newsize);
+		if (record == 0) {
+		    if (myfd)
+			(void) close(fd);
+		    free(icap);
+		    errno = ENOMEM;
+		    return (TC_SYS_ERR);
+		}
+		r_end = record + newsize;
+		rp = record + pos;
+		tcstart = record + tcpos;
+		tcend = record + tcposend;
+	    }
+
+	    /*
+	     * Insert tc'ed record into our record.
+	     */
+	    s = tcstart + newilen;
+	    memmove(s, tcend, (size_t) (rp - tcend));
+	    memmove(tcstart, newicap, (size_t) newilen);
+	    rp += diff;
+	    free(icap);
+
+	    /*
+	     * Start scan on `:' so next cgetcap works properly
+	     * (cgetcap always skips first field).
+	     */
+	    scan = s - 1;
+	}
+    }
+
+    /*
+     * Close file (if we opened it), give back any extra memory, and
+     * return capability, length and success.
+     */
+    if (myfd)
+	(void) close(fd);
+    *len = rp - record - 1;	/* don't count NUL */
+    if (r_end > rp) {
+	if ((record = DOALLOC((size_t) (rp - record))) == 0) {
+	    errno = ENOMEM;
+	    return (TC_SYS_ERR);
+	}
+    }
+
+    *cap = record;
+    if (tc_not_resolved)
+	return (TC_UNRESOLVED);
+    return (current);
+}
+
+/*
+ * Cgetmatch will return 0 if name is one of the names of the capability
+ * record buf, -1 if not.
+ */
+static int
+_nc_cgetmatch(char *buf, const char *name)
+{
+    register const char *np;
+    register char *bp;
+
+    /*
+     * Start search at beginning of record.
+     */
+    bp = buf;
+    for (;;) {
+	/*
+	 * Try to match a record name.
+	 */
+	np = name;
+	for (;;) {
+	    if (*np == '\0') {
+		if (*bp == '|' || *bp == ':' || *bp == '\0')
+		    return (0);
+		else
+		    break;
+	    } else if (*bp++ != *np++) {
+		break;
+	    }
+	}
+
+	/*
+	 * Match failed, skip to next name in record.
+	 */
+	bp--;			/* a '|' or ':' may have stopped the match */
+	for (;;) {
+	    if (*bp == '\0' || *bp == ':')
+		return (-1);	/* match failed totally */
+	    else if (*bp++ == '|')
+		break;		/* found next name */
+	}
+    }
+}
+
+/*
+ * Compare name field of record.
+ */
+static int
+_nc_nfcmp(const char *nf, char *rec)
+{
+    char *cp, tmp;
+    int ret;
+
+    for (cp = rec; *cp != ':'; cp++) ;
+
+    tmp = *(cp + 1);
+    *(cp + 1) = '\0';
+    ret = strcmp(nf, rec);
+    *(cp + 1) = tmp;
+
+    return (ret);
+}
+#endif /* HAVE_BSD_CGETENT */
+
+/*
+ * Since ncurses provides its own 'tgetent()', we cannot use the native one.
+ * So we reproduce the logic to get down to cgetent() -- or our cut-down
+ * version of that -- to circumvent the problem of configuring against the
+ * termcap library.
+ */
+#define USE_BSD_TGETENT 1
+
+#if USE_BSD_TGETENT
+/*
+ * Copyright (c) 1980, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgment:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* static char sccsid[] = "@(#)termcap.c	8.1 (Berkeley) 6/4/93" */
+
+#define	PBUFSIZ		512	/* max length of filename path */
+#define	PVECSIZ		32	/* max number of names in path */
+#define TBUFSIZ (2048*2)
+
+static char *tbuf;
+
+/*
+ * On entry, srcp points to a non ':' character which is the beginning of the
+ * token, if any.  We'll try to return a string that doesn't end with a ':'.
+ */
+static char *
+get_tc_token(char **srcp, int *endp)
+{
+    int ch;
+    bool found = FALSE;
+    char *s, *base;
+    char *tok = 0;
+
+    *endp = TRUE;
+    for (s = base = *srcp; *s != '\0';) {
+	ch = *s++;
+	if (ch == '\\') {
+	    if (*s == '\0') {
+		break;
+	    } else if (*s++ == '\n') {
+		while (isspace(UChar(*s)))
+		    s++;
+	    } else {
+		found = TRUE;
+	    }
+	} else if (ch == ':') {
+	    if (found) {
+		tok = base;
+		s[-1] = '\0';
+		*srcp = s;
+		*endp = FALSE;
+		break;
+	    }
+	    base = s;
+	} else if (isgraph(UChar(ch))) {
+	    found = TRUE;
+	}
+    }
+
+    /* malformed entry may end without a ':' */
+    if (tok == 0 && found) {
+	tok = base;
+    }
+
+    return tok;
+}
+
+static char *
+copy_tc_token(char *dst, const char *src, size_t len)
+{
+    int ch;
+
+    while ((ch = *src++) != '\0') {
+	if (ch == '\\' && *src == '\n') {
+	    while (isspace(UChar(*src)))
+		src++;
+	    continue;
+	}
+	if (--len == 0) {
+	    dst = 0;
+	    break;
+	}
+	*dst++ = ch;
+    }
+    return dst;
+}
+
+/*
+ * Get an entry for terminal name in buffer bp from the termcap file.
+ */
+static int
+_nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
+{
+    static char *the_source;
+
+    register char *p;
+    register char *cp;
+    char *dummy = NULL;
+    char **fname;
+    char *home;
+    int i;
+    char pathbuf[PBUFSIZ];	/* holds raw path of filenames */
+    char *pathvec[PVECSIZ];	/* to point to names in pathbuf */
+    char **pvec;		/* holds usable tail of path vector */
+    NCURSES_CONST char *termpath;
+    string_desc desc;
+
+    fname = pathvec;
+    pvec = pathvec;
+    tbuf = bp;
+    p = pathbuf;
+    cp = use_terminfo_vars()? getenv("TERMCAP") : NULL;
+
+    /*
+     * TERMCAP can have one of two things in it.  It can be the name of a file
+     * to use instead of /etc/termcap.  In this case it better start with a
+     * "/".  Or it can be an entry to use so we don't have to read the file. 
+     * In this case it has to already have the newlines crunched out.  If
+     * TERMCAP does not hold a file name then a path of names is searched
+     * instead.  The path is found in the TERMPATH variable, or becomes
+     * "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
+     */
+    _nc_str_init(&desc, pathbuf, sizeof(pathbuf));
+    if (cp == NULL) {
+	_nc_safe_strcpy(&desc, get_termpath());
+    } else if (!_nc_is_abs_path(cp)) {	/* TERMCAP holds an entry */
+	if ((termpath = get_termpath()) != 0) {
+	    _nc_safe_strcat(&desc, termpath);
+	} else {
+	    char temp[PBUFSIZ];
+	    temp[0] = 0;
+	    if ((home = getenv("HOME")) != 0 && *home != '\0'
+		&& strchr(home, ' ') == 0
+		&& strlen(home) < sizeof(temp) - 10) {	/* setup path */
+		sprintf(temp, "%s/", home);	/* $HOME first */
+	    }
+	    /* if no $HOME look in current directory */
+	    strcat(temp, ".termcap");
+	    _nc_safe_strcat(&desc, temp);
+	    _nc_safe_strcat(&desc, " ");
+	    _nc_safe_strcat(&desc, get_termpath());
+	}
+    } else {			/* user-defined name in TERMCAP */
+	_nc_safe_strcat(&desc, cp);	/* still can be tokenized */
+    }
+
+    *fname++ = pathbuf;		/* tokenize path into vector of names */
+    while (*++p) {
+	if (*p == ' ' || *p == NCURSES_PATHSEP) {
+	    *p = '\0';
+	    while (*++p)
+		if (*p != ' ' && *p != NCURSES_PATHSEP)
+		    break;
+	    if (*p == '\0')
+		break;
+	    *fname++ = p;
+	    if (fname >= pathvec + PVECSIZ) {
+		fname--;
+		break;
+	    }
+	}
+    }
+    *fname = 0;			/* mark end of vector */
+    if (_nc_is_abs_path(cp)) {
+	if (_nc_cgetset(cp) < 0) {
+	    return (TC_SYS_ERR);
+	}
+    }
+
+    i = _nc_cgetent(&dummy, lineno, pathvec, name);
+
+    /* ncurses' termcap-parsing routines cannot handle multiple adjacent
+     * empty fields, and mistakenly use the last valid cap entry instead of
+     * the first (breaks tc= includes)
+     */
+    if (i >= 0) {
+	char *pd, *ps, *tok;
+	int endflag = FALSE;
+	char *list[1023];
+	size_t n, count = 0;
+
+	pd = bp;
+	ps = dummy;
+	while (!endflag && (tok = get_tc_token(&ps, &endflag)) != 0) {
+	    bool ignore = FALSE;
+
+	    for (n = 1; n < count; n++) {
+		char *s = list[n];
+		if (s[0] == tok[0]
+		    && s[1] == tok[1]) {
+		    ignore = TRUE;
+		    break;
+		}
+	    }
+	    if (ignore != TRUE) {
+		list[count++] = tok;
+		pd = copy_tc_token(pd, tok, TBUFSIZ - (2 + pd - bp));
+		if (pd == 0) {
+		    i = -1;
+		    break;
+		}
+		*pd++ = ':';
+		*pd = '\0';
+	    }
+	}
+    }
+
+    FreeIfNeeded(dummy);
+    FreeIfNeeded(the_source);
+    the_source = 0;
+
+    /* This is not related to the BSD cgetent(), but to fake up a suitable
+     * filename for ncurses' error reporting.  (If we are not using BSD
+     * cgetent, then it is the actual filename).
+     */
+    if (i >= 0) {
+#if HAVE_BSD_CGETENT
+	char temp[PATH_MAX];
+
+	_nc_str_init(&desc, temp, sizeof(temp));
+	_nc_safe_strcpy(&desc, pathvec[i]);
+	_nc_safe_strcat(&desc, ".db");
+	if (_nc_access(temp, R_OK) == 0) {
+	    _nc_safe_strcpy(&desc, pathvec[i]);
+	}
+	if ((the_source = strdup(temp)) != 0)
+	    *sourcename = the_source;
+#else
+	if ((the_source = strdup(pathvec[i])) != 0)
+	    *sourcename = the_source;
+#endif
+    }
+
+    return (i);
+}
+#endif /* USE_BSD_TGETENT */
+#endif /* USE_GETCAP */
+
+#define MAXPATHS	32
+
+/*
+ * Add a filename to the list in 'termpaths[]', checking that we really have
+ * a right to open the file.
+ */
+#if !USE_GETCAP
+static int
+add_tc(char *termpaths[], char *path, int count)
+{
+    char *save = strchr(path, NCURSES_PATHSEP);
+    if (save != 0)
+	*save = '\0';
+    if (count < MAXPATHS
+	&& _nc_access(path, R_OK) == 0) {
+	termpaths[count++] = path;
+	T(("Adding termpath %s", path));
+    }
+    termpaths[count] = 0;
+    if (save != 0)
+	*save = NCURSES_PATHSEP;
+    return count;
+}
+#define ADD_TC(path, count) filecount = add_tc(termpaths, path, count)
+#endif /* !USE_GETCAP */
+
+NCURSES_EXPORT(int)
+_nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp)
+{
+    int found = TGETENT_NO;
+    ENTRY *ep;
+#if USE_GETCAP_CACHE
+    char cwd_buf[PATH_MAX];
+#endif
+#if USE_GETCAP
+    char *p, tc[TBUFSIZ];
+    int status;
+    static char *source;
+    static int lineno;
+
+    T(("read termcap entry for %s", tn));
+
+    if (strlen(tn) == 0
+	|| strcmp(tn, ".") == 0
+	|| strcmp(tn, "..") == 0
+	|| _nc_pathlast(tn) != 0) {
+	T(("illegal or missing entry name '%s'", tn));
+	return TGETENT_NO;
+    }
+
+    if (use_terminfo_vars() && (p = getenv("TERMCAP")) != 0
+	&& !_nc_is_abs_path(p) && _nc_name_match(p, tn, "|:")) {
+	/* TERMCAP holds a termcap entry */
+	strncpy(tc, p, sizeof(tc) - 1);
+	tc[sizeof(tc) - 1] = '\0';
+	_nc_set_source("TERMCAP");
+    } else {
+	/* we're using getcap(3) */
+	if ((status = _nc_tgetent(tc, &source, &lineno, tn)) < 0)
+	    return (status == TC_NOT_FOUND ? TGETENT_NO : TGETENT_ERR);
+
+	_nc_curr_line = lineno;
+	_nc_set_source(source);
+    }
+    _nc_read_entry_source((FILE *) 0, tc, FALSE, FALSE, NULLHOOK);
+#else
+    /*
+     * Here is what the 4.4BSD termcap(3) page prescribes:
+     *
+     * It will look in the environment for a TERMCAP variable.  If found, and
+     * the value does not begin with a slash, and the terminal type name is the
+     * same as the environment string TERM, the TERMCAP string is used instead
+     * of reading a termcap file.  If it does begin with a slash, the string is
+     * used as a path name of the termcap file to search.  If TERMCAP does not
+     * begin with a slash and name is different from TERM, tgetent() searches
+     * the files $HOME/.termcap and /usr/share/misc/termcap, in that order,
+     * unless the environment variable TERMPATH exists, in which case it
+     * specifies a list of file pathnames (separated by spaces or colons) to be
+     * searched instead.
+     *
+     * It goes on to state:
+     *
+     * Whenever multiple files are searched and a tc field occurs in the
+     * requested entry, the entry it names must be found in the same file or
+     * one of the succeeding files.
+     *
+     * However, this restriction is relaxed in ncurses; tc references to
+     * previous files are permitted.
+     *
+     * This routine returns 1 if an entry is found, 0 if not found, and -1 if
+     * the database is not accessible.
+     */
+    FILE *fp;
+    char *tc, *termpaths[MAXPATHS];
+    int filecount = 0;
+    int j, k;
+    bool use_buffer = FALSE;
+    bool normal = TRUE;
+    char tc_buf[1024];
+    char pathbuf[PATH_MAX];
+    char *copied = 0;
+    char *cp;
+    struct stat test_stat[MAXPATHS];
+
+    termpaths[filecount] = 0;
+    if (use_terminfo_vars() && (tc = getenv("TERMCAP")) != 0) {
+	if (_nc_is_abs_path(tc)) {	/* interpret as a filename */
+	    ADD_TC(tc, 0);
+	    normal = FALSE;
+	} else if (_nc_name_match(tc, tn, "|:")) {	/* treat as a capability file */
+	    use_buffer = TRUE;
+	    (void) sprintf(tc_buf, "%.*s\n", (int) sizeof(tc_buf) - 2, tc);
+	    normal = FALSE;
+	}
+    }
+
+    if (normal) {		/* normal case */
+	char envhome[PATH_MAX], *h;
+
+	copied = strdup(get_termpath());
+	for (cp = copied; *cp; cp++) {
+	    if (*cp == NCURSES_PATHSEP)
+		*cp = '\0';
+	    else if (cp == copied || cp[-1] == '\0') {
+		ADD_TC(cp, filecount);
+	    }
+	}
+
+#define PRIVATE_CAP "%s/.termcap"
+
+	if (use_terminfo_vars() && (h = getenv("HOME")) != NULL && *h != '\0'
+	    && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) {
+	    /* user's .termcap, if any, should override it */
+	    (void) strcpy(envhome, h);
+	    (void) sprintf(pathbuf, PRIVATE_CAP, envhome);
+	    ADD_TC(pathbuf, filecount);
+	}
+    }
+
+    /*
+     * Probably /etc/termcap is a symlink to /usr/share/misc/termcap.
+     * Avoid reading the same file twice.
+     */
+#if HAVE_LINK
+    for (j = 0; j < filecount; j++) {
+	bool omit = FALSE;
+	if (stat(termpaths[j], &test_stat[j]) != 0
+	    || (test_stat[j].st_mode & S_IFMT) != S_IFREG) {
+	    omit = TRUE;
+	} else {
+	    for (k = 0; k < j; k++) {
+		if (test_stat[k].st_dev == test_stat[j].st_dev
+		    && test_stat[k].st_ino == test_stat[j].st_ino) {
+		    omit = TRUE;
+		    break;
+		}
+	    }
+	}
+	if (omit) {
+	    T(("Path %s is a duplicate", termpaths[j]));
+	    for (k = j + 1; k < filecount; k++) {
+		termpaths[k - 1] = termpaths[k];
+		test_stat[k - 1] = test_stat[k];
+	    }
+	    --filecount;
+	    --j;
+	}
+    }
+#endif
+
+    /* parse the sources */
+    if (use_buffer) {
+	_nc_set_source("TERMCAP");
+
+	/*
+	 * We don't suppress warning messages here.  The presumption is
+	 * that since it's just a single entry, they won't be a pain.
+	 */
+	_nc_read_entry_source((FILE *) 0, tc_buf, FALSE, FALSE, NULLHOOK);
+    } else {
+	int i;
+
+	for (i = 0; i < filecount; i++) {
+
+	    T(("Looking for %s in %s", tn, termpaths[i]));
+	    if (_nc_access(termpaths[i], R_OK) == 0
+		&& (fp = fopen(termpaths[i], "r")) != (FILE *) 0) {
+		_nc_set_source(termpaths[i]);
+
+		/*
+		 * Suppress warning messages.  Otherwise you get 400 lines of
+		 * crap from archaic termcap files as ncurses complains about
+		 * all the obsolete capabilities.
+		 */
+		_nc_read_entry_source(fp, (char *) 0, FALSE, TRUE, NULLHOOK);
+
+		(void) fclose(fp);
+	    }
+	}
+    }
+    if (copied != 0)
+	free(copied);
+#endif /* USE_GETCAP */
+
+    if (_nc_head == 0)
+	return (TGETENT_ERR);
+
+    /* resolve all use references */
+    _nc_resolve_uses2(TRUE, FALSE);
+
+    /* find a terminal matching tn, if we can */
+#if USE_GETCAP_CACHE
+    if (getcwd(cwd_buf, sizeof(cwd_buf)) != 0) {
+	_nc_set_writedir((char *) 0);	/* note: this does a chdir */
+#endif
+	for_entry_list(ep) {
+	    if (_nc_name_match(ep->tterm.term_names, tn, "|:")) {
+		/*
+		 * Make a local copy of the terminal capabilities, delinked
+		 * from the list.
+		 */
+		*tp = ep->tterm;
+		_nc_delink_entry(_nc_head, &(ep->tterm));
+		free(ep);
+
+		/*
+		 * OK, now try to write the type to user's terminfo directory. 
+		 * Next time he loads this, it will come through terminfo.
+		 *
+		 * Advantage:  Second and subsequent fetches of this entry will
+		 * be very fast.
+		 *
+		 * Disadvantage:  After the first time a termcap type is loaded
+		 * by its user, editing it in the /etc/termcap file, or in
+		 * TERMCAP, or in a local ~/.termcap, will be ineffective
+		 * unless the terminfo entry is explicitly removed.
+		 */
+#if USE_GETCAP_CACHE
+		(void) _nc_write_entry(tp);
+#endif
+		found = TGETENT_YES;
+		break;
+	    }
+	}
+#if USE_GETCAP_CACHE
+	chdir(cwd_buf);
+    }
+#endif
+
+    return (found);
+}
+#else
+extern
+NCURSES_EXPORT(void)
+_nc_read_termcap(void);
+NCURSES_EXPORT(void)
+_nc_read_termcap(void)
+{
+}
+#endif /* PURE_TERMINFO */
diff --git a/ncurses/tinfo/setbuf.c b/ncurses/tinfo/setbuf.c
new file mode 100644
index 0000000..ba910e8
--- /dev/null
+++ b/ncurses/tinfo/setbuf.c
@@ -0,0 +1,150 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+**	setbuf.c
+**
+**	Support for set_term(), reset_shell_mode(), reset_prog_mode().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: setbuf.c,v 1.13 2007/05/12 19:04:02 tom Exp $")
+
+/*
+ * If the output file descriptor is connected to a tty (the typical case) it
+ * will probably be line-buffered.  Keith Bostic pointed out that we don't want
+ * this; it hoses people running over networks by forcing out a bunch of small
+ * packets instead of one big one, so screen updates on ptys look jerky.
+ * Restore block buffering to prevent this minor lossage.
+ *
+ * The buffer size is a compromise.  Ideally we'd like a buffer that can hold
+ * the maximum possible update size (the whole screen plus cup commands to
+ * change lines as it's painted).  On a 66-line xterm this can become
+ * excessive.  So we min it with the amount of data we think we can get through
+ * two Ethernet packets (maximum packet size - 100 for TCP/IP overhead).
+ *
+ * Why two ethernet packets?  It used to be one, on the theory that said
+ * packets define the maximum size of atomic update.  But that's less than the
+ * 2000 chars on a 25 x 80 screen, and we don't want local updates to flicker
+ * either.  Two packet lengths will handle up to a 35 x 80 screen.
+ *
+ * The magic '6' is the estimated length of the end-of-line cup sequence to go
+ * to the next line.  It's generous.  We used to mess with the buffering in
+ * init_mvcur() after cost computation, but that lost the sequences emitted by
+ * init_acs() in setupscreen().
+ *
+ * "The setvbuf function may be used only after the stream pointed to by stream
+ * has been associated with an open file and before any other operation is
+ * performed on the stream." (ISO 7.9.5.6.)
+ *
+ * Grrrr...
+ *
+ * On a lighter note, many implementations do in fact allow an application to
+ * reset the buffering after it has been written to.  We try to do this because
+ * otherwise we leave stdout in buffered mode after endwin() is called.  (This
+ * also happens with SVr4 curses).
+ *
+ * There are pros/cons:
+ *
+ * con:
+ *	There is no guarantee that we can reestablish buffering once we've
+ *	dropped it.
+ *
+ *	We _may_ lose data if the implementation does not coordinate this with
+ *	fflush.
+ *
+ * pro:
+ *	An implementation is more likely to refuse to change the buffering than
+ *	to do it in one of the ways mentioned above.
+ *
+ *	The alternative is to have the application try to change buffering
+ *	itself, which is certainly no improvement.
+ *
+ * Just in case it does not work well on a particular system, the calls to
+ * change buffering are all via the macro NC_BUFFERED.  Some implementations
+ * do indeed get confused by changing setbuf on/off, and will overrun the
+ * buffer.  So we disable this by default (there may yet be a workaround).
+ */
+NCURSES_EXPORT(void)
+_nc_set_buffer(FILE *ofp, bool buffered)
+{
+    /* optional optimization hack -- do before any output to ofp */
+#if HAVE_SETVBUF || HAVE_SETBUFFER
+    if (SP->_buffered != buffered) {
+	unsigned buf_len;
+	char *buf_ptr;
+
+	if (getenv("NCURSES_NO_SETBUF") != 0)
+	    return;
+
+	fflush(ofp);
+#ifdef __DJGPP__
+	setmode(ofp, O_BINARY);
+#endif
+	if (buffered != 0) {
+	    buf_len = min(LINES * (COLS + 6), 2800);
+	    if ((buf_ptr = SP->_setbuf) == 0) {
+		if ((buf_ptr = typeMalloc(char, buf_len)) == NULL)
+		      return;
+		SP->_setbuf = buf_ptr;
+		/* Don't try to free this! */
+	    }
+#if !USE_SETBUF_0
+	    else
+		return;
+#endif
+	} else {
+#if !USE_SETBUF_0
+	    return;
+#else
+	    buf_len = 0;
+	    buf_ptr = 0;
+#endif
+	}
+
+#if HAVE_SETVBUF
+#ifdef SETVBUF_REVERSED		/* pre-svr3? */
+	(void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF);
+#else
+	(void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len);
+#endif
+#elif HAVE_SETBUFFER
+	(void) setbuffer(ofp, buf_ptr, (int) buf_len);
+#endif
+
+	SP->_buffered = buffered;
+    }
+#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */
+}
diff --git a/ncurses/tinfo/strings.c b/ncurses/tinfo/strings.c
new file mode 100644
index 0000000..78cd2ef
--- /dev/null
+++ b/ncurses/tinfo/strings.c
@@ -0,0 +1,142 @@
+/****************************************************************************
+ * Copyright (c) 2000-2003,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+**	lib_mvcur.c
+**/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: strings.c,v 1.6 2007/08/11 17:12:17 tom Exp $")
+
+/****************************************************************************
+ * Useful string functions (especially for mvcur)
+ ****************************************************************************/
+
+#if !HAVE_STRSTR
+NCURSES_EXPORT(char *)
+_nc_strstr(const char *haystack, const char *needle)
+{
+    size_t len1 = strlen(haystack);
+    size_t len2 = strlen(needle);
+    char *result = 0;
+
+    while ((len1 != 0) && (len1-- >= len2)) {
+	if (!strncmp(haystack, needle, len2)) {
+	    result = (char *) haystack;
+	    break;
+	}
+	haystack++;
+    }
+    return result;
+}
+#endif
+
+/*
+ * Initialize the descriptor so we can append to it.  Note that 'src' may
+ * be a null pointer (see _nc_str_null), so the corresponding strcat and
+ * strcpy calls have to allow for this.
+ */
+NCURSES_EXPORT(string_desc *)
+_nc_str_init(string_desc * dst, char *src, size_t len)
+{
+    if (dst != 0) {
+	dst->s_head = src;
+	dst->s_tail = src;
+	dst->s_size = len - 1;
+	dst->s_init = dst->s_size;
+	if (src != 0)
+	    *src = 0;
+    }
+    return dst;
+}
+
+/*
+ * Initialize the descriptor for only tracking the amount of memory used.
+ */
+NCURSES_EXPORT(string_desc *)
+_nc_str_null(string_desc * dst, size_t len)
+{
+    return _nc_str_init(dst, 0, len);
+}
+
+/*
+ * Copy a descriptor
+ */
+NCURSES_EXPORT(string_desc *)
+_nc_str_copy(string_desc * dst, string_desc * src)
+{
+    *dst = *src;
+    return dst;
+}
+
+/*
+ * Replaces strcat into a fixed buffer, returning false on failure.
+ */
+NCURSES_EXPORT(bool)
+_nc_safe_strcat(string_desc * dst, const char *src)
+{
+    if (src != 0) {
+	size_t len = strlen(src);
+
+	if (len < dst->s_size) {
+	    if (dst->s_tail != 0) {
+		strcpy(dst->s_tail, src);
+		dst->s_tail += len;
+	    }
+	    dst->s_size -= len;
+	    return TRUE;
+	}
+    }
+    return FALSE;
+}
+
+/*
+ * Replaces strcpy into a fixed buffer, returning false on failure.
+ */
+NCURSES_EXPORT(bool)
+_nc_safe_strcpy(string_desc * dst, const char *src)
+{
+    if (src != 0) {
+	size_t len = strlen(src);
+
+	if (len < dst->s_size) {
+	    if (dst->s_head != 0) {
+		strcpy(dst->s_head, src);
+		dst->s_tail = dst->s_head + len;
+	    }
+	    dst->s_size = dst->s_init - len;
+	    return TRUE;
+	}
+    }
+    return FALSE;
+}
diff --git a/ncurses/tinfo/trim_sgr0.c b/ncurses/tinfo/trim_sgr0.c
new file mode 100644
index 0000000..80c8f77
--- /dev/null
+++ b/ncurses/tinfo/trim_sgr0.c
@@ -0,0 +1,326 @@
+/****************************************************************************
+ * Copyright (c) 2005-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas Dickey                                                   *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: trim_sgr0.c,v 1.8 2007/04/07 17:14:11 tom Exp $")
+
+#undef CUR
+#define CUR tp->
+
+#define CSI       233
+#define ESC       033		/* ^[ */
+#define L_BRACK   '['
+
+static char *
+set_attribute_9(TERMTYPE *tp, int flag)
+{
+    const char *result;
+
+    if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0)
+	result = "";
+    return strdup(result);
+}
+
+static int
+is_csi(const char *s)
+{
+    if (UChar(s[0]) == CSI)
+	return 1;
+    else if (s[0] == ESC && s[1] == L_BRACK)
+	return 2;
+    return 0;
+}
+
+static char *
+skip_zero(char *s)
+{
+    if (s[0] == '0') {
+	if (s[1] == ';')
+	    s += 2;
+	else if (isalpha(UChar(s[1])))
+	    s += 1;
+    }
+    return s;
+}
+
+static const char *
+skip_delay(const char *s)
+{
+    if (s[0] == '$' && s[1] == '<') {
+	s += 2;
+	while (isdigit(UChar(*s)) || *s == '/')
+	    ++s;
+	if (*s == '>')
+	    ++s;
+    }
+    return s;
+}
+
+/*
+ * Improve similar_sgr a little by moving the attr-string from the beginning
+ * to the end of the s-string.
+ */
+static bool
+rewrite_sgr(char *s, char *attr)
+{
+    if (PRESENT(s)) {
+	if (PRESENT(attr)) {
+	    unsigned len_s = strlen(s);
+	    unsigned len_a = strlen(attr);
+
+	    if (len_s > len_a && !strncmp(attr, s, len_a)) {
+		unsigned n;
+		TR(TRACE_DATABASE, ("rewrite:\n\t%s", s));
+		for (n = 0; n < len_s - len_a; ++n) {
+		    s[n] = s[n + len_a];
+		}
+		strcpy(s + n, attr);
+		TR(TRACE_DATABASE, ("to:\n\t%s", s));
+	    }
+	}
+	return TRUE;
+    }
+    return FALSE;		/* oops */
+}
+
+static bool
+similar_sgr(char *a, char *b)
+{
+    bool result = FALSE;
+    int csi_a = is_csi(a);
+    int csi_b = is_csi(b);
+    unsigned len_a;
+    unsigned len_b;
+
+    TR(TRACE_DATABASE, ("similar_sgr:\n\t%s\n\t%s",
+			_nc_visbuf2(1, a),
+			_nc_visbuf2(2, b)));
+    if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) {
+	a += csi_a;
+	b += csi_b;
+	if (*a != *b) {
+	    a = skip_zero(a);
+	    b = skip_zero(b);
+	}
+    }
+    len_a = strlen(a);
+    len_b = strlen(b);
+    if (len_a && len_b) {
+	if (len_a > len_b)
+	    result = (strncmp(a, b, len_b) == 0);
+	else
+	    result = (strncmp(a, b, len_a) == 0);
+    }
+    TR(TRACE_DATABASE, ("...similar_sgr: %d\n\t%s\n\t%s", result,
+			_nc_visbuf2(1, a),
+			_nc_visbuf2(2, b)));
+    return result;
+}
+
+static unsigned
+chop_out(char *string, unsigned i, unsigned j)
+{
+    TR(TRACE_DATABASE, ("chop_out %d..%d from %s", i, j, _nc_visbuf(string)));
+    while (string[j] != '\0') {
+	string[i++] = string[j++];
+    }
+    string[i] = '\0';
+    return i;
+}
+
+/*
+ * Compare, ignoring delays.  Some of the delay values are inconsistent, and
+ * we do not want to be stopped by that.
+ *
+ * Returns the number of chars from 'full' that we matched.  If any mismatch
+ * occurs, return zero.
+ */
+static int
+compare_part(const char *part, const char *full)
+{
+    const char *next_part;
+    const char *next_full;
+    int used_full = 0;
+    int used_delay = 0;
+
+    while (*part != 0) {
+	if (*part != *full) {
+	    used_full = 0;
+	    break;
+	}
+
+	/*
+	 * Adjust the return-value to allow the rare case of
+	 *      string<delay>string
+	 * to remove the whole piece.  The most common case is a delay at the
+	 * end of the string.  The adjusted string will retain the delay, which
+	 * is conservative.
+	 */
+	if (used_delay != 0) {
+	    used_full += used_delay;
+	    used_delay = 0;
+	}
+	if (*part == '$' && *full == '$') {
+	    next_part = skip_delay(part);
+	    next_full = skip_delay(full);
+	    if (next_part != part && next_full != full) {
+		used_delay += (next_full - full);
+		full = next_full;
+		part = next_part;
+		continue;
+	    }
+	}
+	++used_full;
+	++part;
+	++full;
+    }
+    return used_full;
+}
+
+/*
+ * While 'sgr0' is the "same" as termcap 'me', there is a compatibility issue. 
+ * The sgr/sgr0 capabilities include setting/clearing alternate character set
+ * mode.  A termcap application cannot use sgr, so sgr0 strings that reset
+ * alternate character set mode will be misinterpreted.  Here, we remove those
+ * from the more common ISO/ANSI/VT100 entries, which have sgr0 agreeing with
+ * sgr.
+ *
+ * This function returns the modified sgr0 if it can be modified, a null if
+ * an error occurs, or the original sgr0 if no change is needed.
+ */
+NCURSES_EXPORT(char *)
+_nc_trim_sgr0(TERMTYPE *tp)
+{
+    char *result = exit_attribute_mode;
+
+    T((T_CALLED("_nc_trim_sgr0()")));
+
+    if (PRESENT(exit_attribute_mode)
+	&& PRESENT(set_attributes)) {
+	bool found = FALSE;
+	char *on = set_attribute_9(tp, 1);
+	char *off = set_attribute_9(tp, 0);
+	char *end = strdup(exit_attribute_mode);
+	char *tmp;
+	size_t i, j, k;
+
+	TR(TRACE_DATABASE, ("checking if we can trim sgr0 based on sgr"));
+	TR(TRACE_DATABASE, ("sgr0       %s", _nc_visbuf(end)));
+	TR(TRACE_DATABASE, ("sgr(9:off) %s", _nc_visbuf(off)));
+	TR(TRACE_DATABASE, ("sgr(9:on)  %s", _nc_visbuf(on)));
+
+	if (!rewrite_sgr(on, enter_alt_charset_mode)
+	    || !rewrite_sgr(off, exit_alt_charset_mode)
+	    || !rewrite_sgr(end, exit_alt_charset_mode)) {
+	    FreeIfNeeded(off);
+	} else if (similar_sgr(off, end)
+		   && !similar_sgr(off, on)) {
+	    TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off)));
+	    result = off;
+	    /*
+	     * If rmacs is a substring of sgr(0), remove that chunk.
+	     */
+	    if (exit_alt_charset_mode != 0) {
+		TR(TRACE_DATABASE, ("scan for rmacs %s", _nc_visbuf(exit_alt_charset_mode)));
+		j = strlen(off);
+		k = strlen(exit_alt_charset_mode);
+		if (j > k) {
+		    for (i = 0; i <= (j - k); ++i) {
+			int k2 = compare_part(exit_alt_charset_mode, off + i);
+			if (k2 != 0) {
+			    found = TRUE;
+			    chop_out(off, i, i + k2);
+			    break;
+			}
+		    }
+		}
+	    }
+	    /*
+	     * SGR 10 would reset to normal font.
+	     */
+	    if (!found) {
+		if ((i = is_csi(off)) != 0
+		    && off[strlen(off) - 1] == 'm') {
+		    TR(TRACE_DATABASE, ("looking for SGR 10 in %s",
+					_nc_visbuf(off)));
+		    tmp = skip_zero(off + i);
+		    if (tmp[0] == '1'
+			&& skip_zero(tmp + 1) != tmp + 1) {
+			i = tmp - off;
+			if (off[i - 1] == ';')
+			    i--;
+			j = skip_zero(tmp + 1) - off;
+			i = chop_out(off, i, j);
+			found = TRUE;
+		    }
+		}
+	    }
+	    if (!found
+		&& (tmp = strstr(end, off)) != 0
+		&& strcmp(end, off) != 0) {
+		i = tmp - end;
+		j = strlen(off);
+		tmp = strdup(end);
+		chop_out(tmp, i, j);
+		free(off);
+		result = tmp;
+	    }
+	    TR(TRACE_DATABASE, ("...adjusted sgr0 : %s", _nc_visbuf(result)));
+	    if (!strcmp(result, exit_attribute_mode)) {
+		TR(TRACE_DATABASE, ("...same result, discard"));
+		free(result);
+		result = exit_attribute_mode;
+	    }
+	} else {
+	    /*
+	     * Either the sgr does not reference alternate character set,
+	     * or it is incorrect.  That's too hard to decide right now.
+	     */
+	    free(off);
+	}
+	FreeIfNeeded(end);
+	FreeIfNeeded(on);
+    } else {
+	/*
+	 * Possibly some applications are confused if sgr0 contains rmacs,
+	 * but that would be a different bug report -TD
+	 */
+    }
+
+    returnPtr(result);
+}
diff --git a/ncurses/tinfo/use_screen.c b/ncurses/tinfo/use_screen.c
new file mode 100644
index 0000000..6c3b12f
--- /dev/null
+++ b/ncurses/tinfo/use_screen.c
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * Copyright (c) 2007,2008 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *     Author: Thomas E. Dickey                        2007                 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: use_screen.c,v 1.6 2008/06/07 19:16:56 tom Exp $")
+
+NCURSES_EXPORT(int)
+use_screen(SCREEN *screen, NCURSES_SCREEN_CB func, void *data)
+{
+    SCREEN *save_SP;
+    int code = OK;
+
+    T((T_CALLED("use_screen(%p,%p,%p)"), screen, func, data));
+
+    /*
+     * FIXME - add a flag so a given thread can check if _it_ has already
+     * recurred through this point, return an error if so.
+     */
+    _nc_lock_global(curses);
+    save_SP = SP;
+    set_term(screen);
+
+    code = func(screen, data);
+
+    set_term(save_SP);
+    _nc_unlock_global(curses);
+    returnCode(code);
+}
diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c
new file mode 100644
index 0000000..b53bb21
--- /dev/null
+++ b/ncurses/tinfo/write_entry.c
@@ -0,0 +1,785 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	write_entry.c -- write a terminfo structure onto the file system
+ */
+
+#include <curses.priv.h>
+#include <hashed_db.h>
+
+#include <sys/stat.h>
+
+#include <tic.h>
+#include <term_entry.h>
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
+#endif
+
+#if 1
+#define TRACE_OUT(p) DEBUG(2, p)
+#else
+#define TRACE_OUT(p)		/*nothing */
+#endif
+
+MODULE_ID("$Id: write_entry.c,v 1.72 2008/08/03 19:24:00 tom Exp $")
+
+static int total_written;
+
+static int make_db_root(const char *);
+static int write_object(TERMTYPE *, char *, unsigned *, unsigned);
+
+#if !USE_HASHED_DB
+static void
+write_file(char *filename, TERMTYPE *tp)
+{
+    char buffer[MAX_ENTRY_SIZE];
+    unsigned limit = sizeof(buffer);
+    unsigned offset = 0;
+
+    FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0;
+    if (fp == 0) {
+	perror(filename);
+	_nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename);
+    }
+    DEBUG(1, ("Created %s", filename));
+
+    if (write_object(tp, buffer, &offset, limit) == ERR
+	|| fwrite(buffer, sizeof(char), offset, fp) != offset) {
+	_nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename);
+    }
+
+    fclose(fp);
+}
+
+/*
+ * Check for access rights to destination directories
+ * Create any directories which don't exist.
+ *
+ * Note:  there's no reason to return the result of make_db_root(), since
+ * this function is called only in instances where that has to succeed.
+ */
+static void
+check_writeable(int code)
+{
+    static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+    static bool verified[sizeof(dirnames)];
+
+    char dir[sizeof(LEAF_FMT)];
+    char *s = 0;
+
+    if (code == 0 || (s = strchr(dirnames, code)) == 0)
+	_nc_err_abort("Illegal terminfo subdirectory \"" LEAF_FMT "\"", code);
+
+    if (verified[s - dirnames])
+	return;
+
+    sprintf(dir, LEAF_FMT, code);
+    if (make_db_root(dir) < 0) {
+	_nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
+    }
+
+    verified[s - dirnames] = TRUE;
+}
+#endif /* !USE_HASHED_DB */
+
+static int
+make_db_path(char *dst, const char *src, unsigned limit)
+{
+    int rc = -1;
+    const char *top = _nc_tic_dir(0);
+
+    if (src == top || _nc_is_abs_path(src)) {
+	if (strlen(src) + 1 <= limit) {
+	    (void) strcpy(dst, src);
+	    rc = 0;
+	}
+    } else {
+	if (strlen(top) + strlen(src) + 2 <= limit) {
+	    (void) sprintf(dst, "%s/%s", top, src);
+	    rc = 0;
+	}
+    }
+#if USE_HASHED_DB
+    if (rc == 0) {
+	if (_nc_is_dir_path(dst)) {
+	    rc = -1;
+	} else {
+	    unsigned have = strlen(dst);
+	    if (have > 3 && strcmp(dst + have - 3, DBM_SUFFIX)) {
+		if (have + 3 <= limit)
+		    strcat(dst, DBM_SUFFIX);
+		else
+		    rc = -1;
+	    }
+	}
+    }
+#endif
+    return rc;
+}
+
+/*
+ * Make a database-root if it doesn't exist.
+ */
+static int
+make_db_root(const char *path)
+{
+    int rc;
+    char fullpath[PATH_MAX];
+
+    if ((rc = make_db_path(fullpath, path, sizeof(fullpath))) == 0) {
+#if USE_HASHED_DB
+	DB *capdbp;
+
+	if ((capdbp = _nc_db_open(fullpath, TRUE)) == NULL)
+	    rc = -1;
+	else if (_nc_db_close(capdbp) < 0)
+	    rc = -1;
+#else
+	struct stat statbuf;
+
+	if ((rc = stat(path, &statbuf)) < 0) {
+	    rc = mkdir(path, 0777);
+	} else if (_nc_access(path, R_OK | W_OK | X_OK) < 0) {
+	    rc = -1;		/* permission denied */
+	} else if (!(S_ISDIR(statbuf.st_mode))) {
+	    rc = -1;		/* not a directory */
+	}
+#endif
+    }
+    return rc;
+}
+
+/*
+ * Set the write directory for compiled entries.
+ */
+NCURSES_EXPORT(void)
+_nc_set_writedir(char *dir)
+{
+    const char *destination;
+    char actual[PATH_MAX];
+
+    if (dir == 0
+	&& use_terminfo_vars())
+	dir = getenv("TERMINFO");
+
+    if (dir != 0)
+	(void) _nc_tic_dir(dir);
+
+    destination = _nc_tic_dir(0);
+    if (make_db_root(destination) < 0) {
+	char *home = _nc_home_terminfo();
+
+	if (home != 0) {
+	    destination = home;
+	    if (make_db_root(destination) < 0)
+		_nc_err_abort("%s: permission denied (errno %d)",
+			      destination, errno);
+	}
+    }
+
+    /*
+     * Note: because of this code, this logic should be exercised
+     * *once only* per run.
+     */
+#if USE_HASHED_DB
+    make_db_path(actual, destination, sizeof(actual));
+#else
+    if (chdir(_nc_tic_dir(destination)) < 0
+	|| getcwd(actual, sizeof(actual)) == 0)
+	_nc_err_abort("%s: not a directory", destination);
+#endif
+    _nc_keep_tic_dir(strdup(actual));
+}
+
+/*
+ *	Save the compiled version of a description in the filesystem.
+ *
+ *	make a copy of the name-list
+ *	break it up into first-name and all-but-last-name
+ *	creat(first-name)
+ *	write object information to first-name
+ *	close(first-name)
+ *      for each name in all-but-last-name
+ *	    link to first-name
+ *
+ *	Using 'time()' to obtain a reference for file timestamps is unreliable,
+ *	e.g., with NFS, because the filesystem may have a different time
+ *	reference.  We check for pre-existence of links by latching the first
+ *	timestamp from a file that we create.
+ *
+ *	The _nc_warning() calls will report a correct line number only if
+ *	_nc_curr_line is properly set before the write_entry() call.
+ */
+
+NCURSES_EXPORT(void)
+_nc_write_entry(TERMTYPE *const tp)
+{
+#if USE_HASHED_DB
+
+    char buffer[MAX_ENTRY_SIZE + 1];
+    unsigned limit = sizeof(buffer);
+    unsigned offset = 0;
+
+#else /* !USE_HASHED_DB */
+
+    struct stat statbuf;
+    char filename[PATH_MAX];
+    char linkname[PATH_MAX];
+#if USE_SYMLINKS
+    char symlinkname[PATH_MAX];
+#if !HAVE_LINK
+#undef HAVE_LINK
+#define HAVE_LINK 1
+#endif
+#endif /* USE_SYMLINKS */
+
+    static int call_count;
+    static time_t start_time;	/* time at start of writes */
+
+#endif /* USE_HASHED_DB */
+
+    char name_list[MAX_TERMINFO_LENGTH];
+    char *first_name, *other_names;
+    char *ptr;
+
+    assert(strlen(tp->term_names) != 0);
+    assert(strlen(tp->term_names) < sizeof(name_list));
+
+    (void) strcpy(name_list, tp->term_names);
+    DEBUG(7, ("Name list = '%s'", name_list));
+
+    first_name = name_list;
+
+    ptr = &name_list[strlen(name_list) - 1];
+    other_names = ptr + 1;
+
+    while (ptr > name_list && *ptr != '|')
+	ptr--;
+
+    if (ptr != name_list) {
+	*ptr = '\0';
+
+	for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++)
+	    continue;
+
+	if (*ptr == '\0')
+	    other_names = ptr;
+	else {
+	    *ptr = '\0';
+	    other_names = ptr + 1;
+	}
+    }
+
+    DEBUG(7, ("First name = '%s'", first_name));
+    DEBUG(7, ("Other names = '%s'", other_names));
+
+    _nc_set_type(first_name);
+
+#if USE_HASHED_DB
+    if (write_object(tp, buffer + 1, &offset, limit - 1) != ERR) {
+	DB *capdb = _nc_db_open(_nc_tic_dir(0), TRUE);
+	DBT key, data;
+
+	if (capdb != 0) {
+	    buffer[0] = 0;
+
+	    memset(&key, 0, sizeof(key));
+	    key.data = tp->term_names;
+	    key.size = strlen(tp->term_names);
+
+	    memset(&data, 0, sizeof(data));
+	    data.data = buffer;
+	    data.size = offset + 1;
+
+	    _nc_db_put(capdb, &key, &data);
+
+	    buffer[0] = 2;
+
+	    key.data = name_list;
+	    key.size = strlen(name_list);
+
+	    strcpy(buffer + 1, tp->term_names);
+	    data.size = strlen(tp->term_names) + 1;
+
+	    _nc_db_put(capdb, &key, &data);
+
+	    while (*other_names != '\0') {
+		ptr = other_names++;
+		while (*other_names != '|' && *other_names != '\0')
+		    other_names++;
+
+		if (*other_names != '\0')
+		    *(other_names++) = '\0';
+
+		key.data = ptr;
+		key.size = strlen(ptr);
+
+		_nc_db_put(capdb, &key, &data);
+	    }
+	    _nc_db_close(capdb);
+	}
+    }
+#else /* !USE_HASHED_DB */
+    if (call_count++ == 0) {
+	start_time = 0;
+    }
+
+    if (strlen(first_name) >= sizeof(filename) - 3)
+	_nc_warning("terminal name too long.");
+
+    sprintf(filename, LEAF_FMT "/%s", first_name[0], first_name);
+
+    /*
+     * Has this primary name been written since the first call to
+     * write_entry()?  If so, the newer write will step on the older,
+     * so warn the user.
+     */
+    if (start_time > 0 &&
+	stat(filename, &statbuf) >= 0
+	&& statbuf.st_mtime >= start_time) {
+	_nc_warning("name multiply defined.");
+    }
+
+    check_writeable(first_name[0]);
+    write_file(filename, tp);
+
+    if (start_time == 0) {
+	if (stat(filename, &statbuf) < 0
+	    || (start_time = statbuf.st_mtime) == 0) {
+	    _nc_syserr_abort("error obtaining time from %s/%s",
+			     _nc_tic_dir(0), filename);
+	}
+    }
+    while (*other_names != '\0') {
+	ptr = other_names++;
+	assert(ptr < buffer + sizeof(buffer) - 1);
+	while (*other_names != '|' && *other_names != '\0')
+	    other_names++;
+
+	if (*other_names != '\0')
+	    *(other_names++) = '\0';
+
+	if (strlen(ptr) > sizeof(linkname) - 3) {
+	    _nc_warning("terminal alias %s too long.", ptr);
+	    continue;
+	}
+	if (strchr(ptr, '/') != 0) {
+	    _nc_warning("cannot link alias %s.", ptr);
+	    continue;
+	}
+
+	check_writeable(ptr[0]);
+	sprintf(linkname, LEAF_FMT "/%s", ptr[0], ptr);
+
+	if (strcmp(filename, linkname) == 0) {
+	    _nc_warning("self-synonym ignored");
+	} else if (stat(linkname, &statbuf) >= 0 &&
+		   statbuf.st_mtime < start_time) {
+	    _nc_warning("alias %s multiply defined.", ptr);
+	} else if (_nc_access(linkname, W_OK) == 0)
+#if HAVE_LINK
+	{
+	    int code;
+#if USE_SYMLINKS
+	    strcpy(symlinkname, "../");
+	    strncat(symlinkname, filename, sizeof(symlinkname) - 4);
+	    symlinkname[sizeof(symlinkname) - 1] = '\0';
+#endif /* USE_SYMLINKS */
+#if HAVE_REMOVE
+	    code = remove(linkname);
+#else
+	    code = unlink(linkname);
+#endif
+	    if (code != 0 && errno == ENOENT)
+		code = 0;
+#if USE_SYMLINKS
+	    if (symlink(symlinkname, linkname) < 0)
+#else
+	    if (link(filename, linkname) < 0)
+#endif /* USE_SYMLINKS */
+	    {
+		/*
+		 * If there wasn't anything there, and we cannot
+		 * link to the target because it is the same as the
+		 * target, then the source must be on a filesystem
+		 * that uses caseless filenames, such as Win32, etc.
+		 */
+		if (code == 0 && errno == EEXIST)
+		    _nc_warning("can't link %s to %s", filename, linkname);
+		else if (code == 0 && (errno == EPERM || errno == ENOENT))
+		    write_file(linkname, tp);
+		else {
+#if MIXEDCASE_FILENAMES
+		    _nc_syserr_abort("can't link %s to %s", filename, linkname);
+#else
+		    _nc_warning("can't link %s to %s (errno=%d)", filename,
+				linkname, errno);
+#endif
+		}
+	    } else {
+		DEBUG(1, ("Linked %s", linkname));
+	    }
+	}
+#else /* just make copies */
+	    write_file(linkname, tp);
+#endif /* HAVE_LINK */
+    }
+#endif /* USE_HASHED_DB */
+}
+
+static unsigned
+fake_write(char *dst,
+	   unsigned *offset,
+	   unsigned limit,
+	   char *src,
+	   unsigned want,
+	   unsigned size)
+{
+    int have = (limit - *offset);
+
+    want *= size;
+    if (have > 0) {
+	if ((int) want > have)
+	    want = have;
+	memcpy(dst + *offset, src, want);
+	*offset += want;
+    } else {
+	want = 0;
+    }
+    return (int) (want / size);
+}
+
+#define Write(buf, size, count) fake_write(buffer, offset, limit, (char *) buf, count, size)
+
+#undef LITTLE_ENDIAN		/* BSD/OS defines this as a feature macro */
+#define HI(x)			((x) / 256)
+#define LO(x)			((x) % 256)
+#define LITTLE_ENDIAN(p, x)	(p)[0] = LO(x), (p)[1] = HI(x)
+
+#define WRITE_STRING(str) (Write(str, sizeof(char), strlen(str) + 1) == strlen(str) + 1)
+
+static int
+compute_offsets(char **Strings, unsigned strmax, short *offsets)
+{
+    size_t nextfree = 0;
+    unsigned i;
+
+    for (i = 0; i < strmax; i++) {
+	if (Strings[i] == ABSENT_STRING) {
+	    offsets[i] = -1;
+	} else if (Strings[i] == CANCELLED_STRING) {
+	    offsets[i] = -2;
+	} else {
+	    offsets[i] = nextfree;
+	    nextfree += strlen(Strings[i]) + 1;
+	    TRACE_OUT(("put Strings[%d]=%s(%d)", (int) i,
+		       _nc_visbuf(Strings[i]), (int) nextfree));
+	}
+    }
+    return nextfree;
+}
+
+static void
+convert_shorts(unsigned char *buf, short *Numbers, unsigned count)
+{
+    unsigned i;
+    for (i = 0; i < count; i++) {
+	if (Numbers[i] == ABSENT_NUMERIC) {	/* HI/LO won't work */
+	    buf[2 * i] = buf[2 * i + 1] = 0377;
+	} else if (Numbers[i] == CANCELLED_NUMERIC) {	/* HI/LO won't work */
+	    buf[2 * i] = 0376;
+	    buf[2 * i + 1] = 0377;
+	} else {
+	    LITTLE_ENDIAN(buf + 2 * i, Numbers[i]);
+	    TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i]));
+	}
+    }
+}
+
+#define even_boundary(value) \
+	    ((value) % 2 != 0 && Write(&zero, sizeof(char), 1) != 1)
+
+#if NCURSES_XNAMES
+static unsigned
+extended_Booleans(TERMTYPE *tp)
+{
+    unsigned short result = 0;
+    unsigned short i;
+
+    for (i = 0; i < tp->ext_Booleans; ++i) {
+	if (tp->Booleans[BOOLCOUNT + i] == TRUE)
+	    result = (i + 1);
+    }
+    return result;
+}
+
+static unsigned
+extended_Numbers(TERMTYPE *tp)
+{
+    unsigned short result = 0;
+    unsigned short i;
+
+    for (i = 0; i < tp->ext_Numbers; ++i) {
+	if (tp->Numbers[NUMCOUNT + i] != ABSENT_NUMERIC)
+	    result = (i + 1);
+    }
+    return result;
+}
+
+static unsigned
+extended_Strings(TERMTYPE *tp)
+{
+    unsigned short result = 0;
+    unsigned short i;
+
+    for (i = 0; i < tp->ext_Strings; ++i) {
+	if (tp->Strings[STRCOUNT + i] != ABSENT_STRING)
+	    result = (i + 1);
+    }
+    return result;
+}
+
+/*
+ * _nc_align_termtype() will extend entries that are referenced in a use=
+ * clause - discard the unneeded data.
+ */
+static bool
+extended_object(TERMTYPE *tp)
+{
+    bool result = FALSE;
+
+    if (_nc_user_definable) {
+	result = ((extended_Booleans(tp)
+		   + extended_Numbers(tp)
+		   + extended_Strings(tp)) != 0);
+    }
+    return result;
+}
+#endif
+
+static int
+write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit)
+{
+    char *namelist;
+    size_t namelen, boolmax, nummax, strmax;
+    char zero = '\0';
+    size_t i;
+    short nextfree;
+    short offsets[MAX_ENTRY_SIZE / 2];
+    unsigned char buf[MAX_ENTRY_SIZE];
+    unsigned last_bool = BOOLWRITE;
+    unsigned last_num = NUMWRITE;
+    unsigned last_str = STRWRITE;
+
+#if NCURSES_XNAMES
+    /*
+     * Normally we limit the list of values to exclude the "obsolete"
+     * capabilities.  However, if we are accepting extended names, add
+     * these as well, since they are used for supporting translation
+     * to/from termcap.
+     */
+    if (_nc_user_definable) {
+	last_bool = BOOLCOUNT;
+	last_num = NUMCOUNT;
+	last_str = STRCOUNT;
+    }
+#endif
+
+    namelist = tp->term_names;
+    namelen = strlen(namelist) + 1;
+
+    boolmax = 0;
+    for (i = 0; i < last_bool; i++) {
+	if (tp->Booleans[i] == TRUE)
+	    boolmax = i + 1;
+    }
+
+    nummax = 0;
+    for (i = 0; i < last_num; i++) {
+	if (tp->Numbers[i] != ABSENT_NUMERIC)
+	    nummax = i + 1;
+    }
+
+    strmax = 0;
+    for (i = 0; i < last_str; i++) {
+	if (tp->Strings[i] != ABSENT_STRING)
+	    strmax = i + 1;
+    }
+
+    nextfree = compute_offsets(tp->Strings, strmax, offsets);
+
+    /* fill in the header */
+    LITTLE_ENDIAN(buf, MAGIC);
+    LITTLE_ENDIAN(buf + 2, min(namelen, MAX_NAME_SIZE + 1));
+    LITTLE_ENDIAN(buf + 4, boolmax);
+    LITTLE_ENDIAN(buf + 6, nummax);
+    LITTLE_ENDIAN(buf + 8, strmax);
+    LITTLE_ENDIAN(buf + 10, nextfree);
+
+    /* write out the header */
+    TRACE_OUT(("Header of %s @%d", namelist, *offset));
+    if (Write(buf, 12, 1) != 1
+	|| Write(namelist, sizeof(char), namelen) != namelen)
+	  return (ERR);
+
+    for (i = 0; i < boolmax; i++)
+	if (tp->Booleans[i] == TRUE)
+	    buf[i] = TRUE;
+	else
+	    buf[i] = FALSE;
+    if (Write(buf, sizeof(char), boolmax) != boolmax)
+	  return (ERR);
+
+    if (even_boundary(namelen + boolmax))
+	return (ERR);
+
+    TRACE_OUT(("Numerics begin at %04x", *offset));
+
+    /* the numerics */
+    convert_shorts(buf, tp->Numbers, nummax);
+    if (Write(buf, 2, nummax) != nummax)
+	return (ERR);
+
+    TRACE_OUT(("String offsets begin at %04x", *offset));
+
+    /* the string offsets */
+    convert_shorts(buf, offsets, strmax);
+    if (Write(buf, 2, strmax) != strmax)
+	return (ERR);
+
+    TRACE_OUT(("String table begins at %04x", *offset));
+
+    /* the strings */
+    for (i = 0; i < strmax; i++)
+	if (VALID_STRING(tp->Strings[i]))
+	    if (!WRITE_STRING(tp->Strings[i]))
+		return (ERR);
+
+#if NCURSES_XNAMES
+    if (extended_object(tp)) {
+	unsigned extcnt = NUM_EXT_NAMES(tp);
+
+	if (even_boundary(nextfree))
+	    return (ERR);
+
+	nextfree = compute_offsets(tp->Strings + STRCOUNT,
+				   tp->ext_Strings,
+				   offsets);
+	TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree));
+
+	if (tp->ext_Strings >= SIZEOF(offsets))
+	    return (ERR);
+
+	nextfree += compute_offsets(tp->ext_Names,
+				    extcnt,
+				    offsets + tp->ext_Strings);
+	TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
+	strmax = tp->ext_Strings + extcnt;
+
+	/*
+	 * Write the extended header
+	 */
+	LITTLE_ENDIAN(buf + 0, tp->ext_Booleans);
+	LITTLE_ENDIAN(buf + 2, tp->ext_Numbers);
+	LITTLE_ENDIAN(buf + 4, tp->ext_Strings);
+	LITTLE_ENDIAN(buf + 6, strmax);
+	LITTLE_ENDIAN(buf + 8, nextfree);
+	TRACE_OUT(("WRITE extended-header @%d", *offset));
+	if (Write(buf, 10, 1) != 1)
+	    return (ERR);
+
+	TRACE_OUT(("WRITE %d booleans @%d", tp->ext_Booleans, *offset));
+	if (tp->ext_Booleans
+	    && Write(tp->Booleans + BOOLCOUNT, sizeof(char),
+		     tp->ext_Booleans) != tp->ext_Booleans)
+	      return (ERR);
+
+	if (even_boundary(tp->ext_Booleans))
+	    return (ERR);
+
+	TRACE_OUT(("WRITE %d numbers @%d", tp->ext_Numbers, *offset));
+	if (tp->ext_Numbers) {
+	    convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers);
+	    if (Write(buf, 2, tp->ext_Numbers) != tp->ext_Numbers)
+		return (ERR);
+	}
+
+	/*
+	 * Convert the offsets for the ext_Strings and ext_Names tables,
+	 * in that order.
+	 */
+	convert_shorts(buf, offsets, strmax);
+	TRACE_OUT(("WRITE offsets @%d", *offset));
+	if (Write(buf, 2, strmax) != strmax)
+	    return (ERR);
+
+	/*
+	 * Write the string table after the offset tables so we do not
+	 * have to do anything about alignment.
+	 */
+	for (i = 0; i < tp->ext_Strings; i++) {
+	    if (VALID_STRING(tp->Strings[i + STRCOUNT])) {
+		TRACE_OUT(("WRITE ext_Strings[%d]=%s", (int) i,
+			   _nc_visbuf(tp->Strings[i + STRCOUNT])));
+		if (!WRITE_STRING(tp->Strings[i + STRCOUNT]))
+		    return (ERR);
+	    }
+	}
+
+	/*
+	 * Write the extended names
+	 */
+	for (i = 0; i < extcnt; i++) {
+	    TRACE_OUT(("WRITE ext_Names[%d]=%s", (int) i, tp->ext_Names[i]));
+	    if (!WRITE_STRING(tp->ext_Names[i]))
+		return (ERR);
+	}
+
+    }
+#endif /* NCURSES_XNAMES */
+
+    total_written++;
+    return (OK);
+}
+
+/*
+ * Returns the total number of entries written by this process
+ */
+NCURSES_EXPORT(int)
+_nc_tic_written(void)
+{
+    return total_written;
+}
diff --git a/ncurses/trace/README b/ncurses/trace/README
new file mode 100644
index 0000000..e658fec
--- /dev/null
+++ b/ncurses/trace/README
@@ -0,0 +1,33 @@
+-------------------------------------------------------------------------------
+-- Copyright (c) 1998,2006 Free Software Foundation, Inc.                    --
+--                                                                           --
+-- Permission is hereby granted, free of charge, to any person obtaining a   --
+-- copy of this software and associated documentation files (the             --
+-- "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: README,v 1.2 2006/04/22 22:19:37 tom Exp $
+-------------------------------------------------------------------------------
+
+The files in this directory (trace) support both the terminfo and ncurses
+libraries.  Most of the functions are linked in only when the libraries
+are compiled with TRACE defined.
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
new file mode 100644
index 0000000..743b1f6
--- /dev/null
+++ b/ncurses/trace/lib_trace.c
@@ -0,0 +1,334 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	lib_trace.c - Tracing/Debugging routines
+ *
+ * The _tracef() function is originally from pcurses (by Pavel Curtis) in 1982. 
+ * pcurses allowed one to enable/disable tracing using traceon() and traceoff()
+ * functions.  ncurses provides a trace() function which allows one to
+ * selectively enable or disable several tracing features.
+ */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_trace.c,v 1.71 2008/08/23 18:04:29 tom Exp $")
+
+NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
+
+#ifdef TRACE
+
+#if USE_REENTRANT
+NCURSES_EXPORT(const char *)
+NCURSES_PUBLIC_VAR(_nc_tputs_trace) (void)
+{
+    return SP ? SP->_tputs_trace : _nc_prescreen._tputs_trace;
+}
+NCURSES_EXPORT(long)
+NCURSES_PUBLIC_VAR(_nc_outchars) (void)
+{
+    return SP ? SP->_outchars : _nc_prescreen._outchars;
+}
+NCURSES_EXPORT(void)
+_nc_set_tputs_trace(const char *s)
+{
+    if (SP)
+	SP->_tputs_trace = s;
+    else
+	_nc_prescreen._tputs_trace = s;
+}
+NCURSES_EXPORT(void)
+_nc_count_outchars(long increment)
+{
+    if (SP)
+	SP->_outchars += increment;
+    else
+	_nc_prescreen._outchars += increment;
+}
+#else
+NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace = "";
+NCURSES_EXPORT_VAR(long) _nc_outchars = 0;
+#endif
+
+#define TraceFP		_nc_globals.trace_fp
+#define TracePath	_nc_globals.trace_fname
+#define TraceLevel	_nc_globals.trace_level
+
+NCURSES_EXPORT(void)
+trace(const unsigned int tracelevel)
+{
+    if ((TraceFP == 0) && tracelevel) {
+	const char *mode = _nc_globals.init_trace ? "ab" : "wb";
+
+	if (TracePath[0] == '\0') {
+	    int size = sizeof(TracePath) - 12;
+	    if (getcwd(TracePath, size) == 0) {
+		perror("curses: Can't get working directory");
+		exit(EXIT_FAILURE);
+	    }
+	    TracePath[size] = '\0';
+	    assert(strlen(TracePath) <= size);
+	    strcat(TracePath, "/trace");
+	    if (_nc_is_dir_path(TracePath)) {
+		strcat(TracePath, ".log");
+	    }
+	}
+
+	_nc_globals.init_trace = TRUE;
+	_nc_tracing = tracelevel;
+	if (_nc_access(TracePath, W_OK) < 0
+	    || (TraceFP = fopen(TracePath, mode)) == 0) {
+	    perror("curses: Can't open 'trace' file");
+	    exit(EXIT_FAILURE);
+	}
+	/* Try to set line-buffered mode, or (failing that) unbuffered,
+	 * so that the trace-output gets flushed automatically at the
+	 * end of each line.  This is useful in case the program dies. 
+	 */
+#if HAVE_SETVBUF		/* ANSI */
+	(void) setvbuf(TraceFP, (char *) 0, _IOLBF, 0);
+#elif HAVE_SETBUF		/* POSIX */
+	(void) setbuffer(TraceFP, (char *) 0);
+#endif
+	_tracef("TRACING NCURSES version %s.%d (tracelevel=%#x)",
+		NCURSES_VERSION,
+		NCURSES_VERSION_PATCH,
+		tracelevel);
+    } else if (tracelevel == 0) {
+	if (TraceFP != 0) {
+	    fclose(TraceFP);
+	    TraceFP = 0;
+	}
+	_nc_tracing = tracelevel;
+    } else if (_nc_tracing != tracelevel) {
+	_nc_tracing = tracelevel;
+	_tracef("tracelevel=%#x", tracelevel);
+    }
+}
+
+static void
+_nc_va_tracef(const char *fmt, va_list ap)
+{
+    static const char Called[] = T_CALLED("");
+    static const char Return[] = T_RETURN("");
+
+    bool before = FALSE;
+    bool after = FALSE;
+    unsigned doit = _nc_tracing;
+    int save_err = errno;
+
+    if (strlen(fmt) >= sizeof(Called) - 1) {
+	if (!strncmp(fmt, Called, sizeof(Called) - 1)) {
+	    before = TRUE;
+	    TraceLevel++;
+	} else if (!strncmp(fmt, Return, sizeof(Return) - 1)) {
+	    after = TRUE;
+	}
+	if (before || after) {
+	    if ((TraceLevel <= 1)
+		|| (doit & TRACE_ICALLS) != 0)
+		doit &= (TRACE_CALLS | TRACE_CCALLS);
+	    else
+		doit = 0;
+	}
+    }
+
+    if (doit != 0) {
+	if (TraceFP == 0)
+	    TraceFP = stderr;
+#ifdef USE_PTHREADS
+	/*
+	 * TRACE_ICALLS is "really" needed to show normal use with threaded
+	 * applications, since anything can be running during a napms(),
+	 * making it appear in the hierarchical trace as it other functions
+	 * are being called.
+	 *
+	 * Rather than add the complication of a per-thread stack, just
+	 * show the thread-id in each line of the trace.
+	 */
+# if USE_WEAK_SYMBOLS
+	if ((pthread_self))
+# endif
+	    fprintf(TraceFP, "%#lx:", (long) (void *) pthread_self());
+#endif
+	if (before || after) {
+	    int n;
+	    for (n = 1; n < TraceLevel; n++)
+		fputs("+ ", TraceFP);
+	}
+	vfprintf(TraceFP, fmt, ap);
+	fputc('\n', TraceFP);
+	fflush(TraceFP);
+    }
+
+    if (after && TraceLevel)
+	TraceLevel--;
+
+    errno = save_err;
+}
+
+NCURSES_EXPORT(void)
+_tracef(const char *fmt,...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    _nc_va_tracef(fmt, ap);
+    va_end(ap);
+}
+
+/* Trace 'bool' return-values */
+NCURSES_EXPORT(NCURSES_BOOL)
+_nc_retrace_bool(NCURSES_BOOL code)
+{
+    T((T_RETURN("%s"), code ? "TRUE" : "FALSE"));
+    return code;
+}
+
+/* Trace 'int' return-values */
+NCURSES_EXPORT(int)
+_nc_retrace_int(int code)
+{
+    T((T_RETURN("%d"), code));
+    return code;
+}
+
+/* Trace 'unsigned' return-values */
+NCURSES_EXPORT(unsigned)
+_nc_retrace_unsigned(unsigned code)
+{
+    T((T_RETURN("%#x"), code));
+    return code;
+}
+
+/* Trace 'char*' return-values */
+NCURSES_EXPORT(char *)
+_nc_retrace_ptr(char *code)
+{
+    T((T_RETURN("%s"), _nc_visbuf(code)));
+    return code;
+}
+
+/* Trace 'const char*' return-values */
+NCURSES_EXPORT(const char *)
+_nc_retrace_cptr(const char *code)
+{
+    T((T_RETURN("%s"), _nc_visbuf(code)));
+    return code;
+}
+
+/* Trace 'NCURSES_CONST void*' return-values */
+NCURSES_EXPORT(NCURSES_CONST void *)
+_nc_retrace_cvoid_ptr(NCURSES_CONST void *code)
+{
+    T((T_RETURN("%p"), code));
+    return code;
+}
+
+/* Trace 'void*' return-values */
+NCURSES_EXPORT(void *)
+_nc_retrace_void_ptr(void *code)
+{
+    T((T_RETURN("%p"), code));
+    return code;
+}
+
+/* Trace 'SCREEN *' return-values */
+NCURSES_EXPORT(SCREEN *)
+_nc_retrace_sp(SCREEN *code)
+{
+    T((T_RETURN("%p"), code));
+    return code;
+}
+
+/* Trace 'WINDOW *' return-values */
+NCURSES_EXPORT(WINDOW *)
+_nc_retrace_win(WINDOW *code)
+{
+    T((T_RETURN("%p"), code));
+    return code;
+}
+
+#if USE_REENTRANT
+/*
+ * Check if the given trace-mask is enabled.
+ *
+ * This function may be called from within one of the functions that fills
+ * in parameters for _tracef(), but in that case we do not want to lock the
+ * mutex, since it is already locked.
+ */
+NCURSES_EXPORT(int)
+_nc_use_tracef(unsigned mask)
+{
+    bool result = FALSE;
+
+    _nc_lock_global(tst_tracef);
+    if (!_nc_globals.nested_tracef++) {
+	if ((result = (_nc_tracing & (mask))) != 0
+	    && _nc_try_global(tracef) == 0) {
+	    /* we will call _nc_locked_tracef(), no nesting so far */
+	} else {
+	    /* we will not call _nc_locked_tracef() */
+	    _nc_globals.nested_tracef = 0;
+	}
+    } else {
+	/* we may call _nc_locked_tracef(), but with nested_tracef > 0 */
+	result = (_nc_tracing & (mask));
+    }
+    _nc_unlock_global(tst_tracef);
+    return result;
+}
+
+/*
+ * We call this if _nc_use_tracef() returns true, which means we must unlock
+ * the tracef mutex.
+ */
+NCURSES_EXPORT(void)
+_nc_locked_tracef(const char *fmt,...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    _nc_va_tracef(fmt, ap);
+    va_end(ap);
+
+    if (--(_nc_globals.nested_tracef) == 0)
+	_nc_unlock_global(tracef);
+}
+#endif /* USE_REENTRANT */
+
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c
new file mode 100644
index 0000000..45a03ce
--- /dev/null
+++ b/ncurses/trace/lib_traceatr.c
@@ -0,0 +1,358 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas Dickey                           1996-on                 *
+ *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	lib_traceatr.c - Tracing/Debugging routines (attributes)
+ */
+
+#include <curses.priv.h>
+#include <term.h>		/* acs_chars */
+
+MODULE_ID("$Id: lib_traceatr.c,v 1.63 2008/08/03 16:24:53 tom Exp $")
+
+#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
+
+#ifdef TRACE
+
+static const char l_brace[] = StringOf(L_BRACE);
+static const char r_brace[] = StringOf(R_BRACE);
+
+#ifndef USE_TERMLIB
+
+#define my_buffer _nc_globals.traceatr_color_buf
+#define my_select _nc_globals.traceatr_color_sel
+#define my_cached _nc_globals.traceatr_color_last
+
+static char *
+color_of(int c)
+{
+    if (c != my_cached) {
+	my_cached = c;
+	my_select = !my_select;
+	if (c == COLOR_DEFAULT)
+	    strcpy(my_buffer[my_select], "default");
+	else
+	    sprintf(my_buffer[my_select], "color%d", c);
+    }
+    return my_buffer[my_select];
+}
+
+#undef my_buffer
+#undef my_select
+#endif /* !USE_TERMLIB */
+
+NCURSES_EXPORT(char *)
+_traceattr2(int bufnum, chtype newmode)
+{
+    static const struct {
+	unsigned int val;
+	const char *name;
+    } names[] =
+    {
+	/* *INDENT-OFF* */
+	{ A_STANDOUT,		"A_STANDOUT" },
+	{ A_UNDERLINE,		"A_UNDERLINE" },
+	{ A_REVERSE,		"A_REVERSE" },
+	{ A_BLINK,		"A_BLINK" },
+	{ A_DIM,		"A_DIM" },
+	{ A_BOLD,		"A_BOLD" },
+	{ A_ALTCHARSET,		"A_ALTCHARSET" },
+	{ A_INVIS,		"A_INVIS" },
+	{ A_PROTECT,		"A_PROTECT" },
+	{ A_CHARTEXT,		"A_CHARTEXT" },
+	{ A_NORMAL,		"A_NORMAL" },
+	{ A_COLOR,		"A_COLOR" },
+	/* *INDENT-ON* */
+
+    }
+#ifndef USE_TERMLIB
+    ,
+	colors[] =
+    {
+	/* *INDENT-OFF* */
+	{ COLOR_BLACK,		"COLOR_BLACK" },
+	{ COLOR_RED,		"COLOR_RED" },
+	{ COLOR_GREEN,		"COLOR_GREEN" },
+	{ COLOR_YELLOW,		"COLOR_YELLOW" },
+	{ COLOR_BLUE,		"COLOR_BLUE" },
+	{ COLOR_MAGENTA,	"COLOR_MAGENTA" },
+	{ COLOR_CYAN,		"COLOR_CYAN" },
+	{ COLOR_WHITE,		"COLOR_WHITE" },
+	/* *INDENT-ON* */
+
+    }
+#endif /* !USE_TERMLIB */
+    ;
+    size_t n;
+    char temp[80];
+    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+
+    if (result != 0) {
+	unsigned save_nc_tracing = _nc_tracing;
+
+	_nc_tracing = 0;
+
+	strcpy(result, l_brace);
+
+	for (n = 0; n < SIZEOF(names); n++) {
+	    if ((newmode & names[n].val) != 0) {
+		if (result[1] != '\0')
+		    result = _nc_trace_bufcat(bufnum, "|");
+		result = _nc_trace_bufcat(bufnum, names[n].name);
+
+		if (names[n].val == A_COLOR) {
+		    short pairnum = PAIR_NUMBER(newmode);
+#ifdef USE_TERMLIB
+		    /* pair_content lives in libncurses */
+		    (void) sprintf(temp, "{%d}", pairnum);
+#else
+		    short fg, bg;
+
+		    if (pair_content(pairnum, &fg, &bg) == OK) {
+			(void) sprintf(temp,
+				       "{%d = {%s, %s}}",
+				       pairnum,
+				       COLOR_OF(fg),
+				       COLOR_OF(bg));
+		    } else {
+			(void) sprintf(temp, "{%d}", pairnum);
+		    }
+#endif
+		    result = _nc_trace_bufcat(bufnum, temp);
+		}
+	    }
+	}
+	if (ChAttrOf(newmode) == A_NORMAL) {
+	    if (result != 0 && result[1] != '\0')
+		(void) _nc_trace_bufcat(bufnum, "|");
+	    (void) _nc_trace_bufcat(bufnum, "A_NORMAL");
+	}
+
+	_nc_tracing = save_nc_tracing;
+	result = _nc_trace_bufcat(bufnum, r_brace);
+    }
+    return result;
+}
+
+NCURSES_EXPORT(char *)
+_traceattr(attr_t newmode)
+{
+    return _traceattr2(0, newmode);
+}
+
+/* Trace 'int' return-values */
+NCURSES_EXPORT(attr_t)
+_nc_retrace_attr_t(attr_t code)
+{
+    T((T_RETURN("%s"), _traceattr(code)));
+    return code;
+}
+
+const char *
+_nc_altcharset_name(attr_t attr, chtype ch)
+{
+    typedef struct {
+	unsigned int val;
+	const char *name;
+    } ALT_NAMES;
+    static const ALT_NAMES names[] =
+    {
+	{'l', "ACS_ULCORNER"},	/* upper left corner */
+	{'m', "ACS_LLCORNER"},	/* lower left corner */
+	{'k', "ACS_URCORNER"},	/* upper right corner */
+	{'j', "ACS_LRCORNER"},	/* lower right corner */
+	{'t', "ACS_LTEE"},	/* tee pointing right */
+	{'u', "ACS_RTEE"},	/* tee pointing left */
+	{'v', "ACS_BTEE"},	/* tee pointing up */
+	{'w', "ACS_TTEE"},	/* tee pointing down */
+	{'q', "ACS_HLINE"},	/* horizontal line */
+	{'x', "ACS_VLINE"},	/* vertical line */
+	{'n', "ACS_PLUS"},	/* large plus or crossover */
+	{'o', "ACS_S1"},	/* scan line 1 */
+	{'s', "ACS_S9"},	/* scan line 9 */
+	{'`', "ACS_DIAMOND"},	/* diamond */
+	{'a', "ACS_CKBOARD"},	/* checker board (stipple) */
+	{'f', "ACS_DEGREE"},	/* degree symbol */
+	{'g', "ACS_PLMINUS"},	/* plus/minus */
+	{'~', "ACS_BULLET"},	/* bullet */
+	{',', "ACS_LARROW"},	/* arrow pointing left */
+	{'+', "ACS_RARROW"},	/* arrow pointing right */
+	{'.', "ACS_DARROW"},	/* arrow pointing down */
+	{'-', "ACS_UARROW"},	/* arrow pointing up */
+	{'h', "ACS_BOARD"},	/* board of squares */
+	{'i', "ACS_LANTERN"},	/* lantern symbol */
+	{'0', "ACS_BLOCK"},	/* solid square block */
+	{'p', "ACS_S3"},	/* scan line 3 */
+	{'r', "ACS_S7"},	/* scan line 7 */
+	{'y', "ACS_LEQUAL"},	/* less/equal */
+	{'z', "ACS_GEQUAL"},	/* greater/equal */
+	{'{', "ACS_PI"},	/* Pi */
+	{'|', "ACS_NEQUAL"},	/* not equal */
+	{'}', "ACS_STERLING"},	/* UK pound sign */
+	{'\0', (char *) 0}
+    };
+
+    const char *result = 0;
+
+    if ((attr & A_ALTCHARSET) && (acs_chars != 0)) {
+	char *cp;
+	char *found = 0;
+	const ALT_NAMES *sp;
+
+	for (cp = acs_chars; cp[0] && cp[1]; cp += 2) {
+	    if (ChCharOf(cp[1]) == ChCharOf(ch)) {
+		found = cp;
+		/* don't exit from loop - there may be redefinitions */
+	    }
+	}
+
+	if (found != 0) {
+	    ch = ChCharOf(*found);
+	    for (sp = names; sp->val; sp++)
+		if (sp->val == ch) {
+		    result = sp->name;
+		    break;
+		}
+	}
+    }
+    return result;
+}
+
+NCURSES_EXPORT(char *)
+_tracechtype2(int bufnum, chtype ch)
+{
+    const char *found;
+    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+
+    if (result != 0) {
+	strcpy(result, l_brace);
+	if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) {
+	    (void) _nc_trace_bufcat(bufnum, found);
+	} else
+	    (void) _nc_trace_bufcat(bufnum, _nc_tracechar(SP, (int) ChCharOf(ch)));
+
+	if (ChAttrOf(ch) != A_NORMAL) {
+	    (void) _nc_trace_bufcat(bufnum, " | ");
+	    (void) _nc_trace_bufcat(bufnum,
+				    _traceattr2(bufnum + 20, ChAttrOf(ch)));
+	}
+
+	result = _nc_trace_bufcat(bufnum, r_brace);
+    }
+    return result;
+}
+
+NCURSES_EXPORT(char *)
+_tracechtype(chtype ch)
+{
+    return _tracechtype2(0, ch);
+}
+
+/* Trace 'chtype' return-values */
+NCURSES_EXPORT(chtype)
+_nc_retrace_chtype(chtype code)
+{
+    T((T_RETURN("%s"), _tracechtype(code)));
+    return code;
+}
+
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(char *)
+_tracecchar_t2(int bufnum, const cchar_t *ch)
+{
+    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+    attr_t attr;
+    const char *found;
+
+    if (result != 0) {
+	strcpy(result, l_brace);
+	if (ch != 0) {
+	    attr = AttrOfD(ch);
+	    if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) {
+		(void) _nc_trace_bufcat(bufnum, found);
+		attr &= ~A_ALTCHARSET;
+	    } else if (isWidecExt(CHDEREF(ch))) {
+		(void) _nc_trace_bufcat(bufnum, "{NAC}");
+		attr &= ~A_CHARTEXT;
+	    } else {
+		PUTC_DATA;
+		int n;
+
+		PUTC_INIT;
+		(void) _nc_trace_bufcat(bufnum, "{ ");
+		for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+		    PUTC_ch = ch->chars[PUTC_i];
+		    if (PUTC_ch == L'\0')
+			break;
+		    PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st);
+		    if (PUTC_n <= 0) {
+			if (PUTC_ch != L'\0') {
+			    /* it could not be a multibyte sequence */
+			    (void) _nc_trace_bufcat(bufnum,
+						    _nc_tracechar(SP,
+								  UChar(ch->chars[PUTC_i])));
+			}
+			break;
+		    }
+		    for (n = 0; n < PUTC_n; n++) {
+			if (n)
+			    (void) _nc_trace_bufcat(bufnum, ", ");
+			(void) _nc_trace_bufcat(bufnum,
+						_nc_tracechar(SP,
+							      UChar(PUTC_buf[n])));
+		    }
+		}
+		(void) _nc_trace_bufcat(bufnum, " }");
+	    }
+	    if (attr != A_NORMAL) {
+		(void) _nc_trace_bufcat(bufnum, " | ");
+		(void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
+	    }
+	}
+
+	result = _nc_trace_bufcat(bufnum, r_brace);
+    }
+    return result;
+}
+
+NCURSES_EXPORT(char *)
+_tracecchar_t(const cchar_t *ch)
+{
+    return _tracecchar_t2(0, ch);
+}
+#endif
+
+#else
+EMPTY_MODULE(_nc_lib_traceatr)
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c
new file mode 100644
index 0000000..cc441b3
--- /dev/null
+++ b/ncurses/trace/lib_tracebits.c
@@ -0,0 +1,266 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>		/* cur_term */
+
+MODULE_ID("$Id: lib_tracebits.c,v 1.17 2008/08/03 16:09:26 tom Exp $")
+
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+#if HAVE_SYS_TERMIO_H
+#include <sys/termio.h>		/* needed for ISC */
+#endif
+
+#ifdef __EMX__
+#include <io.h>
+#endif
+
+/* may be undefined if we're using termio.h */
+#ifndef TOSTOP
+#define TOSTOP 0
+#endif
+
+#ifndef IEXTEN
+#define IEXTEN 0
+#endif
+
+#ifndef ONLCR
+#define ONLCR 0
+#endif
+
+#ifndef OCRNL
+#define OCRNL 0
+#endif
+
+#ifndef ONOCR
+#define ONOCR 0
+#endif
+
+#ifndef ONLRET
+#define ONLRET 0
+#endif
+
+#ifdef TRACE
+
+typedef struct {
+    unsigned int val;
+    const char *name;
+} BITNAMES;
+
+static void
+lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
+{
+    const BITNAMES *sp;
+
+    (void) strcat(buf, label);
+    (void) strcat(buf, ": {");
+    for (sp = table; sp->name; sp++)
+	if (sp->val != 0
+	    && (val & sp->val) == sp->val) {
+	    (void) strcat(buf, sp->name);
+	    (void) strcat(buf, ", ");
+	}
+    if (buf[strlen(buf) - 2] == ',')
+	buf[strlen(buf) - 2] = '\0';
+    (void) strcat(buf, "} ");
+}
+
+NCURSES_EXPORT(char *)
+_nc_trace_ttymode(TTY * tty)
+/* describe the state of the terminal control bits exactly */
+{
+    char *buf;
+
+#ifdef TERMIOS
+    static const BITNAMES iflags[] =
+    {
+	{BRKINT, "BRKINT"},
+	{IGNBRK, "IGNBRK"},
+	{IGNPAR, "IGNPAR"},
+	{PARMRK, "PARMRK"},
+	{INPCK, "INPCK"},
+	{ISTRIP, "ISTRIP"},
+	{INLCR, "INLCR"},
+	{IGNCR, "IGNC"},
+	{ICRNL, "ICRNL"},
+	{IXON, "IXON"},
+	{IXOFF, "IXOFF"},
+	{0, NULL}
+#define ALLIN	(BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
+    }, oflags[] =
+    {
+	{OPOST, "OPOST"},
+	{OFLAGS_TABS, "XTABS"},
+	{ONLCR, "ONLCR"},
+	{OCRNL, "OCRNL"},
+	{ONOCR, "ONOCR"},
+	{ONLRET, "ONLRET"},
+	{0, NULL}
+#define ALLOUT	(OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
+    }, cflags[] =
+    {
+	{CLOCAL, "CLOCAL"},
+	{CREAD, "CREAD"},
+	{CSTOPB, "CSTOPB"},
+#if !defined(CS5) || !defined(CS8)
+	{CSIZE, "CSIZE"},
+#endif
+	{HUPCL, "HUPCL"},
+	{PARENB, "PARENB"},
+	{PARODD | PARENB, "PARODD"},	/* concession to readability */
+	{0, NULL}
+#define ALLCTRL	(CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
+    }, lflags[] =
+    {
+	{ECHO, "ECHO"},
+	{ECHOE | ECHO, "ECHOE"},	/* concession to readability */
+	{ECHOK | ECHO, "ECHOK"},	/* concession to readability */
+	{ECHONL, "ECHONL"},
+	{ICANON, "ICANON"},
+	{ISIG, "ISIG"},
+	{NOFLSH, "NOFLSH"},
+	{TOSTOP, "TOSTOP"},
+	{IEXTEN, "IEXTEN"},
+	{0, NULL}
+#define ALLLOCAL	(ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
+    };
+
+    buf = _nc_trace_buf(0,
+			8 + sizeof(iflags) +
+			8 + sizeof(oflags) +
+			8 + sizeof(cflags) +
+			8 + sizeof(lflags) +
+			8);
+    if (buf != 0) {
+
+	if (tty->c_iflag & ALLIN)
+	    lookup_bits(buf, iflags, "iflags", tty->c_iflag);
+
+	if (tty->c_oflag & ALLOUT)
+	    lookup_bits(buf, oflags, "oflags", tty->c_oflag);
+
+	if (tty->c_cflag & ALLCTRL)
+	    lookup_bits(buf, cflags, "cflags", tty->c_cflag);
+
+#if defined(CS5) && defined(CS8)
+	{
+	    static struct {
+		int value;
+		const char *name;
+	    } csizes[] = {
+#define CS_DATA(name) { name, #name " " }
+		CS_DATA(CS5),
+#ifdef CS6
+		    CS_DATA(CS6),
+#endif
+#ifdef CS7
+		    CS_DATA(CS7),
+#endif
+		    CS_DATA(CS8),
+	    };
+	    const char *result = "CSIZE? ";
+	    int value = (tty->c_cflag & CSIZE);
+	    unsigned n;
+
+	    if (value != 0) {
+		for (n = 0; n < SIZEOF(csizes); n++) {
+		    if (csizes[n].value == value) {
+			result = csizes[n].name;
+			break;
+		    }
+		}
+	    }
+	    strcat(buf, result);
+	}
+#endif
+
+	if (tty->c_lflag & ALLLOCAL)
+	    lookup_bits(buf, lflags, "lflags", tty->c_lflag);
+    }
+#else
+    /* reference: ttcompat(4M) on SunOS 4.1 */
+#ifndef EVENP
+#define EVENP 0
+#endif
+#ifndef LCASE
+#define LCASE 0
+#endif
+#ifndef LLITOUT
+#define LLITOUT 0
+#endif
+#ifndef ODDP
+#define ODDP 0
+#endif
+#ifndef TANDEM
+#define TANDEM 0
+#endif
+
+    static const BITNAMES cflags[] =
+    {
+	{CBREAK, "CBREAK"},
+	{CRMOD, "CRMOD"},
+	{ECHO, "ECHO"},
+	{EVENP, "EVENP"},
+	{LCASE, "LCASE"},
+	{LLITOUT, "LLITOUT"},
+	{ODDP, "ODDP"},
+	{RAW, "RAW"},
+	{TANDEM, "TANDEM"},
+	{XTABS, "XTABS"},
+	{0, NULL}
+#define ALLCTRL	(CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
+    };
+
+    buf = _nc_trace_buf(0,
+			8 + sizeof(cflags));
+    if (buf != 0) {
+	if (tty->sg_flags & ALLCTRL) {
+	    lookup_bits(buf, cflags, "cflags", tty->sg_flags);
+	}
+    }
+#endif
+    return (buf);
+}
+
+NCURSES_EXPORT(char *)
+_nc_tracebits(void)
+{
+    return _nc_trace_ttymode(&(cur_term->Nttyb));
+}
+#else
+EMPTY_MODULE(_nc_tracebits)
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c
new file mode 100644
index 0000000..79cf03b
--- /dev/null
+++ b/ncurses/trace/lib_tracechr.c
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	lib_tracechr.c - Tracing/Debugging routines
+ */
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_tracechr.c,v 1.19 2008/08/03 15:39:29 tom Exp $")
+
+#ifdef TRACE
+
+NCURSES_EXPORT(char *)
+_nc_tracechar(SCREEN *sp, int ch)
+{
+    NCURSES_CONST char *name;
+    char *MyBuffer = ((sp != 0)
+		      ? sp->tracechr_buf
+		      : _nc_globals.tracechr_buf);
+
+    if (ch > KEY_MIN || ch < 0) {
+	name = _nc_keyname(sp, ch);
+	if (name == 0 || *name == '\0')
+	    name = "NULL";
+	(void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+    } else if (!is8bits(ch) || !isprint(UChar(ch))) {
+	/*
+	 * workaround for glibc bug:
+	 * sprintf changes the result from unctrl() to an empty string if it
+	 * does not correspond to a valid multibyte sequence.
+	 */
+	(void) sprintf(MyBuffer, "%#03o", ch);
+    } else {
+	name = _nc_unctrl(sp, (chtype) ch);
+	if (name == 0 || *name == 0)
+	    name = "null";	/* shouldn't happen */
+	(void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+    }
+    return (MyBuffer);
+}
+
+NCURSES_EXPORT(char *)
+_tracechar(int ch)
+{
+    return _nc_tracechar(SP, ch);
+}
+#else
+EMPTY_MODULE(_nc_lib_tracechr)
+#endif
diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
new file mode 100644
index 0000000..58732a0
--- /dev/null
+++ b/ncurses/trace/lib_tracedmp.c
@@ -0,0 +1,184 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 1996-on                                        *
+ *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	lib_tracedmp.c - Tracing/Debugging routines
+ */
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_tracedmp.c,v 1.31 2008/08/16 19:30:56 tom Exp $")
+
+#ifdef TRACE
+
+#define my_buffer _nc_globals.tracedmp_buf
+#define my_length _nc_globals.tracedmp_used
+
+NCURSES_EXPORT(void)
+_tracedump(const char *name, WINDOW *win)
+{
+    int i, j, n, width;
+
+    /* compute narrowest possible display width */
+    for (width = i = 0; i <= win->_maxy; ++i) {
+	n = 0;
+	for (j = 0; j <= win->_maxx; ++j) {
+	    if (CharOf(win->_line[i].text[j]) != L(' ')
+		|| AttrOf(win->_line[i].text[j]) != A_NORMAL
+		|| GetPair(win->_line[i].text[j]) != 0) {
+		n = j;
+	    }
+	}
+
+	if (n > width)
+	    width = n;
+    }
+    if (width < win->_maxx)
+	++width;
+    if (++width + 1 > (int) my_length) {
+	my_length = 2 * (width + 1);
+	my_buffer = typeRealloc(char, my_length, my_buffer);
+    }
+
+    for (n = 0; n <= win->_maxy; ++n) {
+	char *ep = my_buffer;
+	bool haveattrs, havecolors;
+
+	/*
+	 * Dump A_CHARTEXT part.  It is more important to make the grid line up
+	 * in the trace file than to represent control- and wide-characters, so
+	 * we map those to '.' and '?' respectively.
+	 */
+	for (j = 0; j < width; ++j) {
+	    chtype test = CharOf(win->_line[n].text[j]);
+	    ep[j] = (char) ((UChar(test) == test
+#if USE_WIDEC_SUPPORT
+			     && (win->_line[n].text[j].chars[1] == 0)
+#endif
+			    )
+			    ? (iscntrl(UChar(test))
+			       ? '.'
+			       : UChar(test))
+			    : '?');
+	}
+	ep[j] = '\0';
+	_tracef("%s[%2d] %3ld%3ld ='%s'",
+		name, n,
+		(long) win->_line[n].firstchar,
+		(long) win->_line[n].lastchar,
+		ep);
+
+	/* if there are multi-column characters on the line, print them now */
+	if_WIDEC({
+	    bool multicolumn = FALSE;
+	    for (j = 0; j < width; ++j)
+		if (WidecExt(win->_line[n].text[j]) != 0) {
+		    multicolumn = TRUE;
+		    break;
+		}
+	    if (multicolumn) {
+		ep = my_buffer;
+		for (j = 0; j < width; ++j) {
+		    int test = WidecExt(win->_line[n].text[j]);
+		    if (test) {
+			ep[j] = (char) (test + '0');
+		    } else {
+			ep[j] = ' ';
+		    }
+		}
+		ep[j] = '\0';
+		_tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
+			"widec", n, 8, " ", my_buffer);
+	    }
+	});
+
+	/* dump A_COLOR part, will screw up if there are more than 96 */
+	havecolors = FALSE;
+	for (j = 0; j < width; ++j)
+	    if (GetPair(win->_line[n].text[j]) != 0) {
+		havecolors = TRUE;
+		break;
+	    }
+	if (havecolors) {
+	    ep = my_buffer;
+	    for (j = 0; j < width; ++j) {
+		int pair = GetPair(win->_line[n].text[j]);
+		if (pair >= 52)
+		    ep[j] = '?';
+		else if (pair >= 36)
+		    ep[j] = (char) (pair + 'A');
+		else if (pair >= 10)
+		    ep[j] = (char) (pair + 'a');
+		else if (pair >= 1)
+		    ep[j] = (char) (pair + '0');
+		else
+		    ep[j] = ' ';
+	    }
+	    ep[j] = '\0';
+	    _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
+		    "colors", n, 8, " ", my_buffer);
+	}
+
+	for (i = 0; i < 4; ++i) {
+	    const char *hex = " 123456789ABCDEF";
+	    attr_t mask = (0xf << ((i + 4) * 4));
+
+	    haveattrs = FALSE;
+	    for (j = 0; j < width; ++j)
+		if (AttrOf(win->_line[n].text[j]) & mask) {
+		    haveattrs = TRUE;
+		    break;
+		}
+	    if (haveattrs) {
+		ep = my_buffer;
+		for (j = 0; j < width; ++j)
+		    ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >>
+				((i + 4) * 4)];
+		ep[j] = '\0';
+		_tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) -
+			1, "attrs", i, n, 8, " ", my_buffer);
+	    }
+	}
+    }
+#if NO_LEAKS
+    free(my_buffer);
+    my_buffer = 0;
+    my_length = 0;
+#endif
+}
+
+#else
+EMPTY_MODULE(_nc_lib_tracedmp)
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_tracemse.c b/ncurses/trace/lib_tracemse.c
new file mode 100644
index 0000000..74cc177
--- /dev/null
+++ b/ncurses/trace/lib_tracemse.c
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+ *	lib_tracemse.c - Tracing/Debugging routines (mouse events)
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_tracemse.c,v 1.15 2008/08/03 15:39:29 tom Exp $")
+
+#ifdef TRACE
+
+#define my_buffer sp->tracemse_buf
+
+NCURSES_EXPORT(char *)
+_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
+{
+    (void) sprintf(my_buffer, TRACEMSE_FMT,
+		   ep->id,
+		   ep->x,
+		   ep->y,
+		   ep->z,
+		   (unsigned long) ep->bstate);
+
+#define SHOW(m, s) if ((ep->bstate & m) == m) strcat(strcat(my_buffer, s), ", ")
+
+    SHOW(BUTTON1_RELEASED, "release-1");
+    SHOW(BUTTON1_PRESSED, "press-1");
+    SHOW(BUTTON1_CLICKED, "click-1");
+    SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
+    SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
+#if NCURSES_MOUSE_VERSION == 1
+    SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
+#endif
+
+    SHOW(BUTTON2_RELEASED, "release-2");
+    SHOW(BUTTON2_PRESSED, "press-2");
+    SHOW(BUTTON2_CLICKED, "click-2");
+    SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
+    SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
+#if NCURSES_MOUSE_VERSION == 1
+    SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
+#endif
+
+    SHOW(BUTTON3_RELEASED, "release-3");
+    SHOW(BUTTON3_PRESSED, "press-3");
+    SHOW(BUTTON3_CLICKED, "click-3");
+    SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
+    SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
+#if NCURSES_MOUSE_VERSION == 1
+    SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
+#endif
+
+    SHOW(BUTTON4_RELEASED, "release-4");
+    SHOW(BUTTON4_PRESSED, "press-4");
+    SHOW(BUTTON4_CLICKED, "click-4");
+    SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
+    SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
+#if NCURSES_MOUSE_VERSION == 1
+    SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
+#endif
+
+#if NCURSES_MOUSE_VERSION == 2
+    SHOW(BUTTON5_RELEASED, "release-5");
+    SHOW(BUTTON5_PRESSED, "press-5");
+    SHOW(BUTTON5_CLICKED, "click-5");
+    SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
+    SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
+#endif
+
+    SHOW(BUTTON_CTRL, "ctrl");
+    SHOW(BUTTON_SHIFT, "shift");
+    SHOW(BUTTON_ALT, "alt");
+    SHOW(ALL_MOUSE_EVENTS, "all-events");
+    SHOW(REPORT_MOUSE_POSITION, "position");
+
+#undef SHOW
+
+    if (my_buffer[strlen(my_buffer) - 1] == ' ')
+	my_buffer[strlen(my_buffer) - 2] = '\0';
+    (void) strcat(my_buffer, "}");
+    return (my_buffer);
+}
+
+NCURSES_EXPORT(char *)
+_tracemouse(MEVENT const *ep)
+{
+    return _nc_tracemouse(SP, ep);
+}
+
+#else /* !TRACE */
+EMPTY_MODULE(_nc_lib_tracemouse)
+#endif
diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c
new file mode 100644
index 0000000..6345acc
--- /dev/null
+++ b/ncurses/trace/trace_buf.c
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                 1997-on                        *
+ ****************************************************************************/
+/*
+ *	trace_buf.c - Tracing/Debugging buffers (attributes)
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: trace_buf.c,v 1.14 2008/08/03 15:13:56 tom Exp $")
+
+#define MyList _nc_globals.tracebuf_ptr
+#define MySize _nc_globals.tracebuf_used
+
+static char *
+_nc_trace_alloc(int bufnum, size_t want)
+{
+    char *result = 0;
+
+    if (bufnum >= 0) {
+	if ((size_t) (bufnum + 1) > MySize) {
+	    size_t need = (bufnum + 1) * 2;
+	    if ((MyList = typeRealloc(TRACEBUF, need, MyList)) != 0) {
+		while (need > MySize)
+		    MyList[MySize++].text = 0;
+	    }
+	}
+
+	if (MyList != 0) {
+	    if (MyList[bufnum].text == 0
+		|| want > MyList[bufnum].size) {
+		MyList[bufnum].text = typeRealloc(char, want, MyList[bufnum].text);
+		if (MyList[bufnum].text != 0)
+		    MyList[bufnum].size = want;
+	    }
+	    result = MyList[bufnum].text;
+	}
+    }
+#if NO_LEAKS
+    else {
+	if (MySize) {
+	    if (MyList) {
+		while (MySize--) {
+		    if (MyList[MySize].text != 0) {
+			free(MyList[MySize].text);
+		    }
+		}
+		free(MyList);
+		MyList = 0;
+	    }
+	    MySize = 0;
+	}
+    }
+#endif
+    return result;
+}
+
+/*
+ * (re)Allocate a buffer big enough for the caller's wants.
+ */
+NCURSES_EXPORT(char *)
+_nc_trace_buf(int bufnum, size_t want)
+{
+    char *result = _nc_trace_alloc(bufnum, want);
+    if (result != 0)
+	*result = '\0';
+    return result;
+}
+
+/*
+ * Append a new string to an existing buffer.
+ */
+NCURSES_EXPORT(char *)
+_nc_trace_bufcat(int bufnum, const char *value)
+{
+    char *buffer = _nc_trace_alloc(bufnum, 0);
+    if (buffer != 0) {
+	size_t have = strlen(buffer);
+
+	buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value));
+	if (buffer != 0)
+	    (void) strcpy(buffer + have, value);
+
+    }
+    return buffer;
+}
diff --git a/ncurses/trace/trace_tries.c b/ncurses/trace/trace_tries.c
new file mode 100644
index 0000000..f813aba
--- /dev/null
+++ b/ncurses/trace/trace_tries.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1999                        *
+ ****************************************************************************/
+/*
+ *	trace_tries.c - Tracing/Debugging buffers (keycode tries-trees)
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: trace_tries.c,v 1.13 2008/08/03 15:43:30 tom Exp $")
+
+#ifdef TRACE
+#define my_buffer _nc_globals.tracetry_buf
+#define my_length _nc_globals.tracetry_used
+
+static void
+recur_tries(TRIES * tree, unsigned level)
+{
+    if (level > my_length) {
+	my_length = (level + 1) * 4;
+	my_buffer = (unsigned char *) realloc(my_buffer, my_length);
+    }
+
+    while (tree != 0) {
+	if ((my_buffer[level] = tree->ch) == 0)
+	    my_buffer[level] = 128;
+	my_buffer[level + 1] = 0;
+	if (tree->value != 0) {
+	    _tracef("%5d: %s (%s)", tree->value,
+		    _nc_visbuf((char *) my_buffer), keyname(tree->value));
+	}
+	if (tree->child)
+	    recur_tries(tree->child, level + 1);
+	tree = tree->sibling;
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_trace_tries(TRIES * tree)
+{
+    my_buffer = typeMalloc(unsigned char, my_length = 80);
+    _tracef("BEGIN tries %p", tree);
+    recur_tries(tree, 0);
+    _tracef(". . . tries %p", tree);
+    free(my_buffer);
+}
+
+#else
+EMPTY_MODULE(_nc_trace_tries)
+#endif
diff --git a/ncurses/trace/trace_xnames.c b/ncurses/trace/trace_xnames.c
new file mode 100644
index 0000000..9b0b592
--- /dev/null
+++ b/ncurses/trace/trace_xnames.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * Copyright (c) 1999,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey <dickey@clark.net> 1999                        *
+ ****************************************************************************/
+/*
+ *	trace_xnames.c - Tracing/Debugging buffers (TERMTYPE extended names)
+ */
+
+#include <curses.priv.h>
+#include <term_entry.h>
+
+MODULE_ID("$Id: trace_xnames.c,v 1.5 2000/12/10 03:02:45 tom Exp $")
+
+NCURSES_EXPORT(void)
+_nc_trace_xnames(TERMTYPE * tp GCC_UNUSED)
+{
+#ifdef TRACE
+#if NCURSES_XNAMES
+    int limit = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings;
+    int n, m;
+    if (limit) {
+	int begin_num = tp->ext_Booleans;
+	int begin_str = tp->ext_Booleans + tp->ext_Numbers;
+
+	_tracef("extended names (%s) %d = %d+%d+%d of %d+%d+%d",
+		tp->term_names,
+		limit,
+		tp->ext_Booleans, tp->ext_Numbers, tp->ext_Strings,
+		tp->num_Booleans, tp->num_Numbers, tp->num_Strings);
+	for (n = 0; n < limit; n++) {
+	    if ((m = n - begin_str) >= 0) {
+		_tracef("[%d] %s = %s", n,
+			tp->ext_Names[n],
+			_nc_visbuf(tp->Strings[tp->num_Strings + m - tp->ext_Strings]));
+	    } else if ((m = n - begin_num) >= 0) {
+		_tracef("[%d] %s = %d (num)", n,
+			tp->ext_Names[n],
+			tp->Numbers[tp->num_Numbers + m - tp->ext_Numbers]);
+	    } else {
+		_tracef("[%d] %s = %d (bool)", n,
+			tp->ext_Names[n],
+			tp->Booleans[tp->num_Booleans + n - tp->ext_Booleans]);
+	    }
+	}
+    }
+#endif
+#endif
+}
diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c
new file mode 100644
index 0000000..f4ee467
--- /dev/null
+++ b/ncurses/trace/varargs.c
@@ -0,0 +1,184 @@
+/****************************************************************************
+ * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 2001                                           *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+MODULE_ID("$Id: varargs.c,v 1.7 2008/08/03 15:42:49 tom Exp $")
+
+#ifdef TRACE
+
+#define MAX_PARMS 10
+
+typedef enum {
+    atUnknown = 0, atInteger, atFloat, atPoint, atString
+} ARGTYPE;
+
+#define VA_INT(type) ival = va_arg(ap, type)
+#define VA_FLT(type) fval = va_arg(ap, type)
+#define VA_PTR(type) pval = (char *)va_arg(ap, type)
+#define VA_STR(type) sval = va_arg(ap, type)
+
+#define MyBuffer _nc_globals.tracearg_buf
+#define MyLength _nc_globals.tracearg_used
+
+/*
+ * Returns a string that represents the parameter list of a printf-style call.
+ */
+NCURSES_EXPORT(char *)
+_nc_varargs(const char *fmt, va_list ap)
+{
+    static char dummy[] = "";
+
+    char buffer[BUFSIZ];
+    const char *param;
+    int n;
+
+    if (fmt == 0 || *fmt == '\0')
+	return dummy;
+    if (MyLength == 0)
+	MyBuffer = typeMalloc(char, MyLength = BUFSIZ);
+    if (MyBuffer == 0)
+	return dummy;
+    *MyBuffer = '\0';
+
+    while (*fmt != '\0') {
+	if (*fmt == '%') {
+	    char *pval = 0;	/* avoid const-cast */
+	    const char *sval = "";
+	    double fval = 0.0;
+	    int done = FALSE;
+	    int ival = 0;
+	    int type = 0;
+	    ARGTYPE parm[MAX_PARMS];
+	    int parms = 0;
+	    ARGTYPE used = atUnknown;
+
+	    while (*++fmt != '\0' && !done) {
+
+		if (*fmt == '*') {
+		    VA_INT(int);
+		    if (parms < MAX_PARMS)
+			parm[parms++] = atInteger;
+		} else if (isalpha(UChar(*fmt))) {
+		    done = TRUE;
+		    switch (*fmt) {
+		    case 'Z':	/* FALLTHRU */
+		    case 'h':	/* FALLTHRU */
+		    case 'l':	/* FALLTHRU */
+			done = FALSE;
+			type = *fmt;
+			break;
+		    case 'i':	/* FALLTHRU */
+		    case 'd':	/* FALLTHRU */
+		    case 'u':	/* FALLTHRU */
+		    case 'x':	/* FALLTHRU */
+		    case 'X':	/* FALLTHRU */
+			if (type == 'l')
+			    VA_INT(long);
+			else if (type == 'Z')
+			    VA_INT(size_t);
+			else
+			    VA_INT(int);
+			used = atInteger;
+			break;
+		    case 'f':	/* FALLTHRU */
+		    case 'e':	/* FALLTHRU */
+		    case 'E':	/* FALLTHRU */
+		    case 'g':	/* FALLTHRU */
+		    case 'G':	/* FALLTHRU */
+			VA_FLT(double);
+			used = atFloat;
+			break;
+		    case 'c':
+			VA_INT(int);
+			used = atInteger;
+			break;
+		    case 's':
+			VA_STR(const char *);
+			used = atString;
+			break;
+		    case 'p':
+			VA_PTR(void *);
+			used = atPoint;
+			break;
+		    case 'n':
+			VA_PTR(int *);
+			used = atPoint;
+			break;
+		    default:
+			break;
+		    }
+		} else if (*fmt == '%') {
+		    done = TRUE;
+		}
+		if (used != atUnknown && parms < MAX_PARMS) {
+		    parm[parms++] = used;
+		    for (n = 0; n < parms; ++n) {
+			used = parm[n];
+			param = buffer;
+			switch (used) {
+			case atInteger:
+			    sprintf(buffer, "%d", ival);
+			    break;
+			case atFloat:
+			    sprintf(buffer, "%f", fval);
+			    break;
+			case atPoint:
+			    sprintf(buffer, "%p", pval);
+			    break;
+			case atString:
+			    param = _nc_visbuf2(1, sval);
+			    break;
+			case atUnknown:
+			default:
+			    strcpy(buffer, "?");
+			    break;
+			}
+			MyLength += strlen(param) + 2;
+			MyBuffer = typeRealloc(char, MyLength, MyBuffer);
+			sprintf(MyBuffer + strlen(MyBuffer), ", %s", param);
+		    }
+		}
+		used = atUnknown;
+	    }
+	} else {
+	    fmt++;
+	}
+    }
+
+    return (MyBuffer);
+}
+#else
+EMPTY_MODULE(_nc_varargs)
+#endif
diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c
new file mode 100644
index 0000000..bf9fb14
--- /dev/null
+++ b/ncurses/trace/visbuf.c
@@ -0,0 +1,331 @@
+/****************************************************************************
+ * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                        1996-on                 *
+ *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/*
+ *	visbuf.c - Tracing/Debugging support routines
+ */
+
+#define NEED_NCURSES_CH_T
+#include <curses.priv.h>
+
+#include <tic.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: visbuf.c,v 1.32 2008/08/04 23:07:39 tom Exp $")
+
+#define NormalLen(len) (size_t) (((size_t)(len) + 1) * 4)
+#define WideLen(len)   (size_t) (((size_t)(len) + 1) * 4 * MB_CUR_MAX)
+
+#ifdef TRACE
+static const char d_quote[] = StringOf(D_QUOTE);
+static const char l_brace[] = StringOf(L_BRACE);
+static const char r_brace[] = StringOf(R_BRACE);
+#endif
+
+static char *
+_nc_vischar(char *tp, unsigned c)
+{
+    if (c == '"' || c == '\\') {
+	*tp++ = '\\';
+	*tp++ = (char) c;
+    } else if (is7bits(c) && (isgraph(c) || c == ' ')) {
+	*tp++ = (char) c;
+    } else if (c == '\n') {
+	*tp++ = '\\';
+	*tp++ = 'n';
+    } else if (c == '\r') {
+	*tp++ = '\\';
+	*tp++ = 'r';
+    } else if (c == '\b') {
+	*tp++ = '\\';
+	*tp++ = 'b';
+    } else if (c == '\033') {
+	*tp++ = '\\';
+	*tp++ = 'e';
+    } else if (UChar(c) == 0x7f) {
+	*tp++ = '\\';
+	*tp++ = '^';
+	*tp++ = '?';
+    } else if (is7bits(c) && iscntrl(UChar(c))) {
+	*tp++ = '\\';
+	*tp++ = '^';
+	*tp++ = (char) ('@' + c);
+    } else {
+	sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c));
+	tp += strlen(tp);
+    }
+    *tp = 0;
+    return tp;
+}
+
+static const char *
+_nc_visbuf2n(int bufnum, const char *buf, int len)
+{
+    const char *vbuf;
+    char *tp;
+    int c;
+
+    if (buf == 0)
+	return ("(null)");
+    if (buf == CANCELLED_STRING)
+	return ("(cancelled)");
+
+    if (len < 0)
+	len = (int) strlen(buf);
+
+#ifdef TRACE
+    vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len));
+#else
+    {
+	static char *mybuf[4];
+	mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]);
+	vbuf = tp = mybuf[bufnum];
+    }
+#endif
+    if (tp != 0) {
+	*tp++ = D_QUOTE;
+	while ((--len >= 0) && (c = *buf++) != '\0') {
+	    tp = _nc_vischar(tp, UChar(c));
+	}
+	*tp++ = D_QUOTE;
+	*tp++ = '\0';
+    } else {
+	vbuf = ("(_nc_visbuf2n failed)");
+    }
+    return (vbuf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_visbuf2(int bufnum, const char *buf)
+{
+    return _nc_visbuf2n(bufnum, buf, -1);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_visbuf(const char *buf)
+{
+    return _nc_visbuf2(0, buf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_visbufn(const char *buf, int len)
+{
+    return _nc_visbuf2n(0, buf, len);
+}
+
+#ifdef TRACE
+#if USE_WIDEC_SUPPORT
+
+#if defined(USE_TERMLIB)
+#define _nc_wchstrlen _my_wchstrlen
+static int
+_nc_wchstrlen(const cchar_t *s)
+{
+    int result = 0;
+    while (CharOf(s[result]) != L'\0') {
+	result++;
+    }
+    return result;
+}
+#endif
+
+static const char *
+_nc_viswbuf2n(int bufnum, const wchar_t *buf, int len)
+{
+    const char *vbuf;
+    char *tp;
+    wchar_t c;
+
+    if (buf == 0)
+	return ("(null)");
+
+    if (len < 0)
+	len = (int) wcslen(buf);
+
+#ifdef TRACE
+    vbuf = tp = _nc_trace_buf(bufnum, WideLen(len));
+#else
+    {
+	static char *mybuf[2];
+	mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]);
+	vbuf = tp = mybuf[bufnum];
+    }
+#endif
+    if (tp != 0) {
+	*tp++ = D_QUOTE;
+	while ((--len >= 0) && (c = *buf++) != '\0') {
+	    char temp[CCHARW_MAX + 80];
+	    int j = wctomb(temp, c), k;
+	    if (j <= 0) {
+		sprintf(temp, "\\u%08X", (unsigned) c);
+		j = (int) strlen(temp);
+	    }
+	    for (k = 0; k < j; ++k) {
+		tp = _nc_vischar(tp, UChar(temp[k]));
+	    }
+	}
+	*tp++ = D_QUOTE;
+	*tp++ = '\0';
+    } else {
+	vbuf = ("(_nc_viswbuf2n failed)");
+    }
+    return (vbuf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viswbuf2(int bufnum, const wchar_t *buf)
+{
+    return _nc_viswbuf2n(bufnum, buf, -1);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viswbuf(const wchar_t *buf)
+{
+    return _nc_viswbuf2(0, buf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viswbufn(const wchar_t *buf, int len)
+{
+    return _nc_viswbuf2n(0, buf, len);
+}
+
+/* this special case is used for wget_wstr() */
+NCURSES_EXPORT(const char *)
+_nc_viswibuf(const wint_t *buf)
+{
+    static wchar_t *mybuf;
+    static unsigned mylen;
+    unsigned n;
+
+    for (n = 0; buf[n] != 0; ++n) ;
+    if (mylen < ++n) {
+	mylen = n + 80;
+	if (mybuf != 0)
+	    mybuf = typeRealloc(wchar_t, mylen, mybuf);
+	else
+	    mybuf = typeMalloc(wchar_t, mylen);
+    }
+    for (n = 0; buf[n] != 0; ++n)
+	mybuf[n] = (wchar_t) buf[n];
+
+    return _nc_viswbuf2(0, mybuf);
+}
+#endif /* USE_WIDEC_SUPPORT */
+
+/* use these functions for displaying parts of a line within a window */
+NCURSES_EXPORT(const char *)
+_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
+{
+    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+    int first;
+    const char *found;
+
+    if (result != 0) {
+#if USE_WIDEC_SUPPORT
+	if (len < 0)
+	    len = _nc_wchstrlen(buf);
+#endif /* USE_WIDEC_SUPPORT */
+
+	/*
+	 * Display one or more strings followed by attributes.
+	 */
+	first = 0;
+	while (first < len) {
+	    attr_t attr = AttrOf(buf[first]);
+	    int last = len - 1;
+	    int j;
+
+	    for (j = first + 1; j < len; ++j) {
+		if (!SameAttrOf(buf[j], buf[first])) {
+		    last = j - 1;
+		    break;
+		}
+	    }
+
+	    result = _nc_trace_bufcat(bufnum, l_brace);
+	    result = _nc_trace_bufcat(bufnum, d_quote);
+	    for (j = first; j <= last; ++j) {
+		found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j]));
+		if (found != 0) {
+		    result = _nc_trace_bufcat(bufnum, found);
+		    attr &= ~A_ALTCHARSET;
+		} else
+#if USE_WIDEC_SUPPORT
+		if (!isWidecExt(buf[j])) {
+		    PUTC_DATA;
+
+		    PUTC_INIT;
+		    for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+			int k;
+
+			PUTC_ch = buf[j].chars[PUTC_i];
+			if (PUTC_ch == L'\0')
+			    break;
+			PUTC_n = (int) wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st);
+			if (PUTC_n <= 0)
+			    break;
+			for (k = 0; k < PUTC_n; k++) {
+			    char temp[80];
+			    _nc_vischar(temp, UChar(PUTC_buf[k]));
+			    result = _nc_trace_bufcat(bufnum, temp);
+			}
+		    }
+		}
+#else
+		{
+		    char temp[80];
+		    _nc_vischar(temp, UChar(buf[j]));
+		    result = _nc_trace_bufcat(bufnum, temp);
+		}
+#endif /* USE_WIDEC_SUPPORT */
+	    }
+	    result = _nc_trace_bufcat(bufnum, d_quote);
+	    if (attr != A_NORMAL) {
+		result = _nc_trace_bufcat(bufnum, " | ");
+		result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
+	    }
+	    result = _nc_trace_bufcat(bufnum, r_brace);
+	    first = last + 1;
+	}
+    }
+    return result;
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viscbuf(const NCURSES_CH_T * buf, int len)
+{
+    return _nc_viscbuf2(0, buf, len);
+}
+#endif /* TRACE */
diff --git a/ncurses/tty/MKexpanded.sh b/ncurses/tty/MKexpanded.sh
new file mode 100755
index 0000000..bf9acf2
--- /dev/null
+++ b/ncurses/tty/MKexpanded.sh
@@ -0,0 +1,99 @@
+#! /bin/sh
+##############################################################################
+# Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.                #
+#                                                                            #
+# Permission is hereby granted, free of charge, to any person obtaining a    #
+# copy of this software and associated documentation files (the "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.                                                             #
+##############################################################################
+#
+# Author: Thomas E. Dickey <dickey@clark.net> 1997
+#
+# $Id: MKexpanded.sh,v 1.11 2005/01/02 01:06:40 tom Exp $
+#
+# Script to generate 'expanded.c', a dummy source that contains functions
+# corresponding to complex macros used in this library.  By making functions,
+# we simplify analysis and debugging.
+
+if test $# != 0; then
+preprocessor="$1"
+else
+preprocessor="cc -E"
+fi
+shift
+if test $# != 0 ; then
+	preprocessor="$preprocessor $*"
+else
+	preprocessor="$preprocessor -DHAVE_CONFIG_H -I. -I../include"
+fi
+
+TMP=gen$$.c
+trap "rm -f $TMP" 0 1 2 5 15
+
+cat <<EOF
+/* generated by MKexpanded.sh */
+#include <curses.priv.h>
+#include <term.h>
+#if NCURSES_EXPANDED
+EOF
+
+cat >$TMP <<EOF
+#include <ncurses_cfg.h>
+#undef NCURSES_EXPANDED /* this probably is set in ncurses_cfg.h */
+#include <curses.priv.h>
+/* these are names we'd like to see */
+#undef ALL_BUT_COLOR
+#undef PAIR_NUMBER
+#undef TRUE
+#undef FALSE
+/* this is a marker */
+IGNORE
+NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *S, attr_t at)
+{
+	toggle_attr_on(*S,at);
+}
+NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *S, attr_t at) 
+{
+	toggle_attr_off(*S,at);
+}
+NCURSES_EXPORT(int) _nc_DelCharCost (int count)
+{
+	return DelCharCost(count);
+}
+NCURSES_EXPORT(int) _nc_InsCharCost (int count)
+{
+	return InsCharCost(count);
+}
+NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T c)
+{
+	UpdateAttrs(c);
+}
+EOF
+
+$preprocessor $TMP 2>/dev/null | sed -e '1,/^IGNORE$/d'
+
+cat <<EOF
+#else /* ! NCURSES_EXPANDED */
+NCURSES_EXPORT(void) _nc_expanded (void) { }
+#endif /* NCURSES_EXPANDED */
+EOF
diff --git a/ncurses/tty/hardscroll.c b/ncurses/tty/hardscroll.c
new file mode 100644
index 0000000..2c40997
--- /dev/null
+++ b/ncurses/tty/hardscroll.c
@@ -0,0 +1,328 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Alexander V Lukyanov                    1997-1998               *
+ ****************************************************************************/
+
+/******************************************************************************
+
+NAME
+   hardscroll.c -- hardware-scrolling optimization for ncurses
+
+SYNOPSIS
+   void _nc_scroll_optimize(void)
+
+DESCRIPTION
+			OVERVIEW
+
+This algorithm for computes optimum hardware scrolling to transform an
+old screen (curscr) into a new screen (newscr) via vertical line moves.
+
+Because the screen has a `grain' (there are insert/delete/scroll line
+operations but no insert/delete/scroll column operations), it is efficient
+break the update algorithm into two pieces: a first stage that does only line
+moves, optimizing the end product of user-invoked insertions, deletions, and
+scrolls; and a second phase (corresponding to the present doupdate code in
+ncurses) that does only line transformations.
+
+The common case we want hardware scrolling for is to handle line insertions
+and deletions in screen-oriented text-editors.  This two-stage approach will
+accomplish that at a low computation and code-size cost.
+
+			LINE-MOVE COMPUTATION
+
+Now, to a discussion of the line-move computation.
+
+For expository purposes, consider the screen lines to be represented by
+integers 0..23 (with the understanding that the value of 23 may vary).
+Let a new line introduced by insertion, scrolling, or at the bottom of
+the screen following a line delete be given the index -1.
+
+Assume that the real screen starts with lines 0..23.  Now, we have
+the following possible line-oriented operations on the screen:
+
+Insertion: inserts a line at a given screen row, forcing all lines below
+to scroll forward.  The last screen line is lost.  For example, an insertion
+at line 5 would produce: 0..4 -1 5..23.
+
+Deletion: deletes a line at a given screen row, forcing all lines below
+to scroll forward.  The last screen line is made new.  For example, a deletion
+at line 7 would produce: 0..6 8..23 -1.
+
+Scroll up: move a range of lines up 1.  The bottom line of the range
+becomes new.  For example, scrolling up the region from 9 to 14 will
+produce 0..8 10..14 -1 15..23.
+
+Scroll down: move a range of lines down 1.  The top line of the range
+becomes new.  For example, scrolling down the region from 12 to 16 will produce
+0..11 -1 12..15 17..23.
+
+Now, an obvious property of all these operations is that they preserve the
+order of old lines, though not their position in the sequence.
+
+The key trick of this algorithm is that the original line indices described
+above are actually maintained as _line[].oldindex fields in the window
+structure, and stick to each line through scroll and insert/delete operations.
+
+Thus, it is possible at update time to look at the oldnum fields and compute
+an optimal set of il/dl/scroll operations that will take the real screen
+lines to the virtual screen lines.  Once these vertical moves have been done,
+we can hand off to the second stage of the update algorithm, which does line
+transformations.
+
+Note that the move computation does not need to have the full generality
+of a diff algorithm (which it superficially resembles) because lines cannot
+be moved out of order.
+
+			THE ALGORITHM
+
+The scrolling is done in two passes. The first pass is from top to bottom
+scroling hunks UP. The second one is from bottom to top scrolling hunks DOWN.
+Obviously enough, no lines to be scrolled will be destroyed. (lav)
+
+HOW TO TEST THIS:
+
+Use the following production:
+
+hardscroll: hardscroll.c
+	$(CC) -g -DSCROLLDEBUG hardscroll.c -o hardscroll
+
+Then just type scramble vectors and watch.  The following test loads are
+a representative sample of cases:
+
+-----------------------------  CUT HERE ------------------------------------
+# No lines moved
+ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
+#
+# A scroll up
+ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 -1
+#
+# A scroll down
+-1  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
+#
+# An insertion (after line 12)
+ 0  1  2  3  4  5  6  7  8  9 10 11 12 -1 13 14 15 16 17 18 19 20 21 22
+#
+# A simple deletion (line 10)
+ 0  1  2  3  4  5  6  7  8  9  11 12 13 14 15 16 17 18 19 20 21 22 23 -1
+#
+# A more complex case
+-1 -1 -1 -1 -1  3  4  5  6  7  -1 -1  8  9 10 11 12 13 14 15 16 17 -1 -1
+-----------------------------  CUT HERE ------------------------------------
+
+AUTHOR
+    Eric S. Raymond <esr@snark.thyrsus.com>, November 1994
+    New algorithm by Alexander V. Lukyanov <lav@yars.free.net>, Aug 1997
+
+*****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: hardscroll.c,v 1.42 2008/08/03 23:49:30 tom Exp $")
+
+#if defined(SCROLLDEBUG) || defined(HASHDEBUG)
+
+# undef screen_lines
+# define screen_lines MAXLINES
+NCURSES_EXPORT_VAR(int)
+oldnums[MAXLINES];
+# define OLDNUM(n)	oldnums[n]
+# define _tracef	printf
+# undef TR
+# define TR(n, a)	if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); }
+
+extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
+
+#else /* no debug */
+
+/* OLDNUM(n) indicates which line will be shifted to the position n.
+   if OLDNUM(n) == _NEWINDEX, then the line n in new, not shifted from
+   somewhere. */
+NCURSES_EXPORT_VAR(int *)
+_nc_oldnums = 0;		/* obsolete: keep for ABI compat */
+
+# if USE_HASHMAP
+#  define oldnums       SP->_oldnum_list
+#  define OLDNUM(n)	oldnums[n]
+# else				/* !USE_HASHMAP */
+#  define OLDNUM(n)	newscr->_line[n].oldindex
+# endif				/* !USE_HASHMAP */
+
+#define OLDNUM_SIZE     SP->_oldnum_size
+
+#endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */
+
+NCURSES_EXPORT(void)
+_nc_scroll_optimize(void)
+/* scroll optimization to transform curscr to newscr */
+{
+    int i;
+    int start, end, shift;
+
+    TR(TRACE_ICALLS, (T_CALLED("_nc_scroll_optimize")));
+
+#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
+#if USE_HASHMAP
+    /* get enough storage */
+    if (OLDNUM_SIZE < screen_lines) {
+	int *new_oldnums = typeRealloc(int, screen_lines, oldnums);
+	if (!new_oldnums)
+	    return;
+	oldnums = new_oldnums;
+	OLDNUM_SIZE = screen_lines;
+    }
+    /* calculate the indices */
+    _nc_hash_map();
+#endif
+#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
+
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_UPDATE | TRACE_MOVE)) {
+	_nc_linedump();
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    /* pass 1 - from top to bottom scrolling up */
+    for (i = 0; i < screen_lines;) {
+	while (i < screen_lines && (OLDNUM(i) == _NEWINDEX || OLDNUM(i) <= i))
+	    i++;
+	if (i >= screen_lines)
+	    break;
+
+	shift = OLDNUM(i) - i;	/* shift > 0 */
+	start = i;
+
+	i++;
+	while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i
+	       == shift)
+	    i++;
+	end = i - 1 + shift;
+
+	TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift));
+#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
+	if (_nc_scrolln(shift, start, end, screen_lines - 1) == ERR) {
+	    TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll"));
+	    continue;
+	}
+#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
+    }
+
+    /* pass 2 - from bottom to top scrolling down */
+    for (i = screen_lines - 1; i >= 0;) {
+	while (i >= 0 && (OLDNUM(i) == _NEWINDEX || OLDNUM(i) >= i))
+	    i--;
+	if (i < 0)
+	    break;
+
+	shift = OLDNUM(i) - i;	/* shift < 0 */
+	end = i;
+
+	i--;
+	while (i >= 0 && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift)
+	    i--;
+	start = i + 1 - (-shift);
+
+	TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift));
+#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
+	if (_nc_scrolln(shift, start, end, screen_lines - 1) == ERR) {
+	    TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll"));
+	    continue;
+	}
+#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
+    }
+    TR(TRACE_ICALLS, (T_RETURN("")));
+}
+
+#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
+NCURSES_EXPORT(void)
+_nc_linedump(void)
+/* dump the state of the real and virtual oldnum fields */
+{
+    int n;
+    char *buf = 0;
+    size_t want = (screen_lines + 1) * 4;
+
+    if ((buf = typeMalloc(char, want)) != 0) {
+
+	(void) strcpy(buf, "virt");
+	for (n = 0; n < screen_lines; n++)
+	    (void) sprintf(buf + strlen(buf), " %02d", OLDNUM(n));
+	TR(TRACE_UPDATE | TRACE_MOVE, (buf));
+	free(buf);
+    }
+}
+#endif /* defined(TRACE) || defined(SCROLLDEBUG) */
+
+#ifdef SCROLLDEBUG
+
+int
+main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+{
+    char line[BUFSIZ], *st;
+
+#ifdef TRACE
+    _nc_tracing = TRACE_MOVE;
+#endif
+    for (;;) {
+	int n;
+
+	for (n = 0; n < screen_lines; n++)
+	    oldnums[n] = _NEWINDEX;
+
+	/* grab the test vector */
+	if (fgets(line, sizeof(line), stdin) == (char *) NULL)
+	    exit(EXIT_SUCCESS);
+
+	/* parse it */
+	n = 0;
+	if (line[0] == '#') {
+	    (void) fputs(line, stderr);
+	    continue;
+	}
+	st = strtok(line, " ");
+	do {
+	    oldnums[n++] = atoi(st);
+	} while
+	    ((st = strtok((char *) NULL, " ")) != 0);
+
+	/* display it */
+	(void) fputs("Initial input:\n", stderr);
+	_nc_linedump();
+
+	_nc_scroll_optimize();
+    }
+}
+
+#endif /* SCROLLDEBUG */
+
+/* hardscroll.c ends here */
diff --git a/ncurses/tty/hashmap.c b/ncurses/tty/hashmap.c
new file mode 100644
index 0000000..9b60df6
--- /dev/null
+++ b/ncurses/tty/hashmap.c
@@ -0,0 +1,549 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
+
+/******************************************************************************
+
+NAME
+   hashmap.c -- fill in scramble vector based on text hashes
+
+SYNOPSIS
+   void _nc_hash_map(void)
+
+DESCRIPTION:
+   This code attempts to recognize pairs of old and new lines in the physical
+and virtual screens.  When a line pair is recognized, the old line index is
+placed in the oldindex member of the virtual screen line, to be used by the
+vertical-motion optimizer portion of the update logic (see hardscroll.c).
+
+   Line pairs are recognized by applying a modified Heckel's algorithm,
+sped up by hashing.  If a line hash is unique in both screens, those
+lines must be a pair. Then if the lines just before or after the pair
+are the same or similar, they are a pair too.
+
+   We don't worry about false pairs produced by hash collisions, on the
+assumption that such cases are rare and will only make the latter stages
+of update less efficient, not introduce errors.
+
+HOW TO TEST THIS:
+
+Use the following production:
+
+hashmap: hashmap.c
+	$(CC) -g -DHASHDEBUG hashmap.c hardscroll.c ../objects/lib_trace.o -o hashmap
+
+AUTHOR
+    Eric S. Raymond <esr@snark.thyrsus.com>, May 1996
+    Bug fixes and improvements by Alexander V. Lukyanov <lav@yars.free.net>, 1997
+
+*****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>		/* for back_color_erase */
+
+MODULE_ID("$Id: hashmap.c,v 1.56 2007/10/13 18:47:25 Miroslav.Lichvar Exp $")
+
+#ifdef HASHDEBUG
+
+# define _tracef	printf
+# undef TR
+# define TR(n, a)	if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); }
+# undef screen_lines
+# define screen_lines MAXLINES
+# define TEXTWIDTH	1
+int oldnums[MAXLINES], reallines[MAXLINES];
+static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH];
+static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH];
+# define OLDNUM(n)	oldnums[n]
+# define OLDTEXT(n)	oldtext[n]
+# define NEWTEXT(m)	newtext[m]
+# define PENDING(n)     1
+
+#else /* !HASHDEBUG */
+
+# define OLDNUM(n)	SP->_oldnum_list[n]
+# define OLDTEXT(n)	curscr->_line[n].text
+# define NEWTEXT(m)	newscr->_line[m].text
+# define TEXTWIDTH	(curscr->_maxx+1)
+# define PENDING(n)     (newscr->_line[n].firstchar != _NOCHANGE)
+
+#endif /* !HASHDEBUG */
+
+#define oldhash		(SP->oldhash)
+#define newhash		(SP->newhash)
+#define hashtab		(SP->hashtab)
+#define lines_alloc	(SP->hashtab_len)
+
+#if USE_WIDEC_SUPPORT
+#define HASH_VAL(ch) (ch.chars[0])
+#else
+#define HASH_VAL(ch) (ch)
+#endif
+
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+
+static NCURSES_INLINE unsigned long
+hash(NCURSES_CH_T * text)
+{
+    int i;
+    NCURSES_CH_T ch;
+    unsigned long result = 0;
+    for (i = TEXTWIDTH; i > 0; i--) {
+	ch = *text++;
+	result += (result << 5) + HASH_VAL(ch);
+    }
+    return result;
+}
+
+/* approximate update cost */
+static int
+update_cost(NCURSES_CH_T * from, NCURSES_CH_T * to)
+{
+    int cost = 0;
+    int i;
+
+    for (i = TEXTWIDTH; i > 0; i--, from++, to++)
+	if (!(CharEq(*from, *to)))
+	    cost++;
+
+    return cost;
+}
+
+static int
+update_cost_from_blank(NCURSES_CH_T * to)
+{
+    int cost = 0;
+    int i;
+    NCURSES_CH_T blank = blankchar;
+
+    if (back_color_erase)
+	SetPair(blank, GetPair(stdscr->_nc_bkgd));
+
+    for (i = TEXTWIDTH; i > 0; i--, to++)
+	if (!(CharEq(blank, *to)))
+	    cost++;
+
+    return cost;
+}
+
+/*
+ * Returns true when moving line 'from' to line 'to' seems to be cost
+ * effective. 'blank' indicates whether the line 'to' would become blank.
+ */
+static NCURSES_INLINE bool
+cost_effective(const int from, const int to, const bool blank)
+{
+    int new_from;
+
+    if (from == to)
+	return FALSE;
+
+    new_from = OLDNUM(from);
+    if (new_from == _NEWINDEX)
+	new_from = from;
+
+    /*
+     * On the left side of >= is the cost before moving;
+     * on the right side -- cost after moving.
+     */
+    return (((blank ? update_cost_from_blank(NEWTEXT(to))
+	      : update_cost(OLDTEXT(to), NEWTEXT(to)))
+	     + update_cost(OLDTEXT(new_from), NEWTEXT(from)))
+	    >= ((new_from == from ? update_cost_from_blank(NEWTEXT(from))
+		 : update_cost(OLDTEXT(new_from), NEWTEXT(from)))
+		+ update_cost(OLDTEXT(from), NEWTEXT(to)))) ? TRUE : FALSE;
+}
+
+static void
+grow_hunks(void)
+{
+    int start, end, shift;
+    int back_limit, forward_limit;	/* limits for cells to fill */
+    int back_ref_limit, forward_ref_limit;	/* limits for refrences */
+    int i;
+    int next_hunk;
+
+    /*
+     * This is tricky part.  We have unique pairs to use as anchors.
+     * Use these to deduce the presence of spans of identical lines.
+     */
+    back_limit = 0;
+    back_ref_limit = 0;
+
+    i = 0;
+    while (i < screen_lines && OLDNUM(i) == _NEWINDEX)
+	i++;
+    for (; i < screen_lines; i = next_hunk) {
+	start = i;
+	shift = OLDNUM(i) - i;
+
+	/* get forward limit */
+	i = start + 1;
+	while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i
+	       == shift)
+	    i++;
+	end = i;
+	while (i < screen_lines && OLDNUM(i) == _NEWINDEX)
+	    i++;
+	next_hunk = i;
+	forward_limit = i;
+	if (i >= screen_lines || OLDNUM(i) >= i)
+	    forward_ref_limit = i;
+	else
+	    forward_ref_limit = OLDNUM(i);
+
+	i = start - 1;
+	/* grow back */
+	if (shift < 0)
+	    back_limit = back_ref_limit + (-shift);
+	while (i >= back_limit) {
+	    if (newhash[i] == oldhash[i + shift]
+		|| cost_effective(i + shift, i, shift < 0)) {
+		OLDNUM(i) = i + shift;
+		TR(TRACE_UPDATE | TRACE_MOVE,
+		   ("connected new line %d to old line %d (backward continuation)",
+		    i, i + shift));
+	    } else {
+		TR(TRACE_UPDATE | TRACE_MOVE,
+		   ("not connecting new line %d to old line %d (backward continuation)",
+		    i, i + shift));
+		break;
+	    }
+	    i--;
+	}
+
+	i = end;
+	/* grow forward */
+	if (shift > 0)
+	    forward_limit = forward_ref_limit - shift;
+	while (i < forward_limit) {
+	    if (newhash[i] == oldhash[i + shift]
+		|| cost_effective(i + shift, i, shift > 0)) {
+		OLDNUM(i) = i + shift;
+		TR(TRACE_UPDATE | TRACE_MOVE,
+		   ("connected new line %d to old line %d (forward continuation)",
+		    i, i + shift));
+	    } else {
+		TR(TRACE_UPDATE | TRACE_MOVE,
+		   ("not connecting new line %d to old line %d (forward continuation)",
+		    i, i + shift));
+		break;
+	    }
+	    i++;
+	}
+
+	back_ref_limit = back_limit = i;
+	if (shift > 0)
+	    back_ref_limit += shift;
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_hash_map(void)
+{
+    HASHMAP *sp;
+    register int i;
+    int start, shift, size;
+
+    if (screen_lines > lines_alloc) {
+	if (hashtab)
+	    free(hashtab);
+	hashtab = typeMalloc(HASHMAP, (screen_lines + 1) * 2);
+	if (!hashtab) {
+	    if (oldhash) {
+		FreeAndNull(oldhash);
+	    }
+	    lines_alloc = 0;
+	    return;
+	}
+	lines_alloc = screen_lines;
+    }
+
+    if (oldhash && newhash) {
+	/* re-hash only changed lines */
+	for (i = 0; i < screen_lines; i++) {
+	    if (PENDING(i))
+		newhash[i] = hash(NEWTEXT(i));
+	}
+    } else {
+	/* re-hash all */
+	if (oldhash == 0)
+	    oldhash = typeCalloc(unsigned long, (unsigned) screen_lines);
+	if (newhash == 0)
+	    newhash = typeCalloc(unsigned long, (unsigned) screen_lines);
+	if (!oldhash || !newhash)
+	    return;		/* malloc failure */
+	for (i = 0; i < screen_lines; i++) {
+	    newhash[i] = hash(NEWTEXT(i));
+	    oldhash[i] = hash(OLDTEXT(i));
+	}
+    }
+
+#ifdef HASH_VERIFY
+    for (i = 0; i < screen_lines; i++) {
+	if (newhash[i] != hash(NEWTEXT(i)))
+	    fprintf(stderr, "error in newhash[%d]\n", i);
+	if (oldhash[i] != hash(OLDTEXT(i)))
+	    fprintf(stderr, "error in oldhash[%d]\n", i);
+    }
+#endif
+
+    /*
+     * Set up and count line-hash values.
+     */
+    memset(hashtab, '\0', sizeof(*hashtab) * (screen_lines + 1) * 2);
+    for (i = 0; i < screen_lines; i++) {
+	unsigned long hashval = oldhash[i];
+
+	for (sp = hashtab; sp->hashval; sp++)
+	    if (sp->hashval == hashval)
+		break;
+	sp->hashval = hashval;	/* in case this is a new entry */
+	sp->oldcount++;
+	sp->oldindex = i;
+    }
+    for (i = 0; i < screen_lines; i++) {
+	unsigned long hashval = newhash[i];
+
+	for (sp = hashtab; sp->hashval; sp++)
+	    if (sp->hashval == hashval)
+		break;
+	sp->hashval = hashval;	/* in case this is a new entry */
+	sp->newcount++;
+	sp->newindex = i;
+
+	OLDNUM(i) = _NEWINDEX;	/* initialize old indices array */
+    }
+
+    /*
+     * Mark line pairs corresponding to unique hash pairs.
+     *
+     * We don't mark lines with offset 0, because it can make fail
+     * extending hunks by cost_effective. Otherwise, it does not
+     * have any side effects.
+     */
+    for (sp = hashtab; sp->hashval; sp++)
+	if (sp->oldcount == 1 && sp->newcount == 1
+	    && sp->oldindex != sp->newindex) {
+	    TR(TRACE_UPDATE | TRACE_MOVE,
+	       ("new line %d is hash-identical to old line %d (unique)",
+		sp->newindex, sp->oldindex));
+	    OLDNUM(sp->newindex) = sp->oldindex;
+	}
+
+    grow_hunks();
+
+    /*
+     * Eliminate bad or impossible shifts -- this includes removing
+     * those hunks which could not grow because of conflicts, as well
+     * those which are to be moved too far, they are likely to destroy
+     * more than carry.
+     */
+    for (i = 0; i < screen_lines;) {
+	while (i < screen_lines && OLDNUM(i) == _NEWINDEX)
+	    i++;
+	if (i >= screen_lines)
+	    break;
+	start = i;
+	shift = OLDNUM(i) - i;
+	i++;
+	while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i
+	       == shift)
+	    i++;
+	size = i - start;
+	if (size < 3 || size + min(size / 8, 2) < abs(shift)) {
+	    while (start < i) {
+		OLDNUM(start) = _NEWINDEX;
+		start++;
+	    }
+	}
+    }
+
+    /* After clearing invalid hunks, try grow the rest. */
+    grow_hunks();
+}
+
+NCURSES_EXPORT(void)
+_nc_make_oldhash(int i)
+{
+    if (oldhash)
+	oldhash[i] = hash(OLDTEXT(i));
+}
+
+NCURSES_EXPORT(void)
+_nc_scroll_oldhash(int n, int top, int bot)
+{
+    size_t size;
+    int i;
+
+    if (!oldhash)
+	return;
+
+    size = sizeof(*oldhash) * (bot - top + 1 - abs(n));
+    if (n > 0) {
+	memmove(oldhash + top, oldhash + top + n, size);
+	for (i = bot; i > bot - n; i--)
+	    oldhash[i] = hash(OLDTEXT(i));
+    } else {
+	memmove(oldhash + top - n, oldhash + top, size);
+	for (i = top; i < top - n; i++)
+	    oldhash[i] = hash(OLDTEXT(i));
+    }
+}
+
+#ifdef HASHDEBUG
+static void
+usage(void)
+{
+    static const char *table[] =
+    {
+	"hashmap test-driver",
+	"",
+	"#  comment",
+	"l  get initial line number vector",
+	"n  use following letters as text of new lines",
+	"o  use following letters as text of old lines",
+	"d  dump state of test arrays",
+	"h  apply hash mapper and see scroll optimization",
+	"?  this message"
+    };
+    size_t n;
+    for (n = 0; n < sizeof(table) / sizeof(table[0]); n++)
+	fprintf(stderr, "%s\n", table[n]);
+}
+
+int
+main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+{
+    char line[BUFSIZ], *st;
+    int n;
+
+    if (setupterm(NULL, fileno(stdout), (int *) 0) == ERR)
+	return EXIT_FAILURE;
+    (void) _nc_alloc_screen();
+
+    for (n = 0; n < screen_lines; n++) {
+	reallines[n] = n;
+	oldnums[n] = _NEWINDEX;
+	CharOf(oldtext[n][0]) = CharOf(newtext[n][0]) = '.';
+    }
+
+    if (isatty(fileno(stdin)))
+	usage();
+
+#ifdef TRACE
+    _nc_tracing = TRACE_MOVE;
+#endif
+    for (;;) {
+	/* grab a test command */
+	if (fgets(line, sizeof(line), stdin) == (char *) NULL)
+	    break;
+
+	switch (line[0]) {
+	case '#':		/* comment */
+	    (void) fputs(line, stderr);
+	    break;
+
+	case 'l':		/* get initial line number vector */
+	    for (n = 0; n < screen_lines; n++) {
+		reallines[n] = n;
+		oldnums[n] = _NEWINDEX;
+	    }
+	    n = 0;
+	    st = strtok(line, " ");
+	    do {
+		oldnums[n++] = atoi(st);
+	    } while
+		((st = strtok((char *) NULL, " ")) != 0);
+	    break;
+
+	case 'n':		/* use following letters as text of new lines */
+	    for (n = 0; n < screen_lines; n++)
+		CharOf(newtext[n][0]) = '.';
+	    for (n = 0; n < screen_lines; n++)
+		if (line[n + 1] == '\n')
+		    break;
+		else
+		    CharOf(newtext[n][0]) = line[n + 1];
+	    break;
+
+	case 'o':		/* use following letters as text of old lines */
+	    for (n = 0; n < screen_lines; n++)
+		CharOf(oldtext[n][0]) = '.';
+	    for (n = 0; n < screen_lines; n++)
+		if (line[n + 1] == '\n')
+		    break;
+		else
+		    CharOf(oldtext[n][0]) = line[n + 1];
+	    break;
+
+	case 'd':		/* dump state of test arrays */
+#ifdef TRACE
+	    _nc_linedump();
+#endif
+	    (void) fputs("Old lines: [", stdout);
+	    for (n = 0; n < screen_lines; n++)
+		putchar(CharOf(oldtext[n][0]));
+	    putchar(']');
+	    putchar('\n');
+	    (void) fputs("New lines: [", stdout);
+	    for (n = 0; n < screen_lines; n++)
+		putchar(CharOf(newtext[n][0]));
+	    putchar(']');
+	    putchar('\n');
+	    break;
+
+	case 'h':		/* apply hash mapper and see scroll optimization */
+	    _nc_hash_map();
+	    (void) fputs("Result:\n", stderr);
+#ifdef TRACE
+	    _nc_linedump();
+#endif
+	    _nc_scroll_optimize();
+	    (void) fputs("Done.\n", stderr);
+	    break;
+	default:
+	case '?':
+	    usage();
+	    break;
+	}
+    }
+#if NO_LEAKS
+    _nc_free_and_exit(EXIT_SUCCESS);
+#else
+    return EXIT_SUCCESS;
+#endif
+}
+
+#endif /* HASHDEBUG */
+
+/* hashmap.c ends here */
diff --git a/ncurses/tty/lib_mvcur.c b/ncurses/tty/lib_mvcur.c
new file mode 100644
index 0000000..8e66fa3
--- /dev/null
+++ b/ncurses/tty/lib_mvcur.c
@@ -0,0 +1,1249 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_mvcur.c
+**
+**	The routines for moving the physical cursor and scrolling:
+**
+**		void _nc_mvcur_init(void)
+**
+**		void _nc_mvcur_resume(void)
+**
+**		int mvcur(int old_y, int old_x, int new_y, int new_x)
+**
+**		void _nc_mvcur_wrap(void)
+**
+** Comparisons with older movement optimizers:
+**    SVr3 curses mvcur() can't use cursor_to_ll or auto_left_margin.
+**    4.4BSD curses can't use cuu/cud/cuf/cub/hpa/vpa/tab/cbt for local
+** motions.  It doesn't use tactics based on auto_left_margin.  Weirdly
+** enough, it doesn't use its own hardware-scrolling routine to scroll up
+** destination lines for out-of-bounds addresses!
+**    old ncurses optimizer: less accurate cost computations (in fact,
+** it was broken and had to be commented out!).
+**
+** Compile with -DMAIN to build an interactive tester/timer for the movement
+** optimizer.  You can use it to investigate the optimizer's behavior.
+** You can also use it for tuning the formulas used to determine whether
+** or not full optimization is attempted.
+**
+** This code has a nasty tendency to find bugs in terminfo entries, because it
+** exercises the non-cup movement capabilities heavily.  If you think you've
+** found a bug, try deleting subsets of the following capabilities (arranged
+** in decreasing order of suspiciousness): it, tab, cbt, hpa, vpa, cuu, cud,
+** cuf, cub, cuu1, cud1, cuf1, cub1.  It may be that one or more are wrong.
+**
+** Note: you should expect this code to look like a resource hog in a profile.
+** That's because it does a lot of I/O, through the tputs() calls.  The I/O
+** cost swamps the computation overhead (and as machines get faster, this
+** will become even more true).  Comments in the test exerciser at the end
+** go into detail about tuning and how you can gauge the optimizer's
+** effectiveness.
+**/
+
+/****************************************************************************
+ *
+ * Constants and macros for optimizer tuning.
+ *
+ ****************************************************************************/
+
+/*
+ * The average overhead of a full optimization computation in character
+ * transmission times.  If it's too high, the algorithm will be a bit
+ * over-biased toward using cup rather than local motions; if it's too
+ * low, the algorithm may spend more time than is strictly optimal
+ * looking for non-cup motions.  Profile the optimizer using the `t'
+ * command of the exerciser (see below), and round to the nearest integer.
+ *
+ * Yes, I (esr) thought about computing expected overhead dynamically, say
+ * by derivation from a running average of optimizer times.  But the
+ * whole point of this optimization is to *decrease* the frequency of
+ * system calls. :-)
+ */
+#define COMPUTE_OVERHEAD	1	/* I use a 90MHz Pentium @ 9.6Kbps */
+
+/*
+ * LONG_DIST is the distance we consider to be just as costly to move over as a
+ * cup sequence is to emit.  In other words, it's the length of a cup sequence
+ * adjusted for average computation overhead.  The magic number is the length
+ * of "\033[yy;xxH", the typical cup sequence these days.
+ */
+#define LONG_DIST		(8 - COMPUTE_OVERHEAD)
+
+/*
+ * Tell whether a motion is optimizable by local motions.  Needs to be cheap to
+ * compute. In general, all the fast moves go to either the right or left edge
+ * of the screen.  So any motion to a location that is (a) further away than
+ * LONG_DIST and (b) further inward from the right or left edge than LONG_DIST,
+ * we'll consider nonlocal.
+ */
+#define NOT_LOCAL(fy, fx, ty, tx)	((tx > LONG_DIST) \
+ 		 && (tx < screen_columns - 1 - LONG_DIST) \
+		 && (abs(ty-fy) + abs(tx-fx) > LONG_DIST))
+
+/****************************************************************************
+ *
+ * External interfaces
+ *
+ ****************************************************************************/
+
+/*
+ * For this code to work OK, the following components must live in the
+ * screen structure:
+ *
+ *	int		_char_padding;	// cost of character put
+ *	int		_cr_cost;	// cost of (carriage_return)
+ *	int		_cup_cost;	// cost of (cursor_address)
+ *	int		_home_cost;	// cost of (cursor_home)
+ *	int		_ll_cost;	// cost of (cursor_to_ll)
+ *#if USE_HARD_TABS
+ *	int		_ht_cost;	// cost of (tab)
+ *	int		_cbt_cost;	// cost of (back_tab)
+ *#endif USE_HARD_TABS
+ *	int		_cub1_cost;	// cost of (cursor_left)
+ *	int		_cuf1_cost;	// cost of (cursor_right)
+ *	int		_cud1_cost;	// cost of (cursor_down)
+ *	int		_cuu1_cost;	// cost of (cursor_up)
+ *	int		_cub_cost;	// cost of (parm_cursor_left)
+ *	int		_cuf_cost;	// cost of (parm_cursor_right)
+ *	int		_cud_cost;	// cost of (parm_cursor_down)
+ *	int		_cuu_cost;	// cost of (parm_cursor_up)
+ *	int		_hpa_cost;	// cost of (column_address)
+ *	int		_vpa_cost;	// cost of (row_address)
+ *	int		_ech_cost;	// cost of (erase_chars)
+ *	int		_rep_cost;	// cost of (repeat_char)
+ *
+ * The USE_HARD_TABS switch controls whether it is reliable to use tab/backtabs
+ * for local motions.  On many systems, it's not, due to uncertainties about
+ * tab delays and whether or not tabs will be expanded in raw mode.  If you
+ * have parm_right_cursor, tab motions don't win you a lot anyhow.
+ */
+
+#include <curses.priv.h>
+#include <term.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_mvcur.c,v 1.113 2008/08/16 19:30:58 tom Exp $")
+
+#define WANT_CHAR(y, x)	SP->_newscr->_line[y].text[x]	/* desired state */
+#define BAUDRATE	cur_term->_baudrate	/* bits per second */
+
+#if defined(MAIN) || defined(NCURSES_TEST)
+#include <sys/time.h>
+
+static bool profiling = FALSE;
+static float diff;
+#endif /* MAIN */
+
+#define OPT_SIZE 512
+
+static int normalized_cost(const char *const cap, int affcnt);
+
+/****************************************************************************
+ *
+ * Initialization/wrapup (including cost pre-computation)
+ *
+ ****************************************************************************/
+
+#ifdef TRACE
+static int
+trace_cost_of(const char *capname, const char *cap, int affcnt)
+{
+    int result = _nc_msec_cost(cap, affcnt);
+    TR(TRACE_CHARPUT | TRACE_MOVE,
+       ("CostOf %s %d %s", capname, result, _nc_visbuf(cap)));
+    return result;
+}
+#define CostOf(cap,affcnt) trace_cost_of(#cap,cap,affcnt);
+
+static int
+trace_normalized_cost(const char *capname, const char *cap, int affcnt)
+{
+    int result = normalized_cost(cap, affcnt);
+    TR(TRACE_CHARPUT | TRACE_MOVE,
+       ("NormalizedCost %s %d %s", capname, result, _nc_visbuf(cap)));
+    return result;
+}
+#define NormalizedCost(cap,affcnt) trace_normalized_cost(#cap,cap,affcnt);
+
+#else
+
+#define CostOf(cap,affcnt) _nc_msec_cost(cap,affcnt);
+#define NormalizedCost(cap,affcnt) normalized_cost(cap,affcnt);
+
+#endif
+
+NCURSES_EXPORT(int)
+_nc_msec_cost(const char *const cap, int affcnt)
+/* compute the cost of a given operation */
+{
+    if (cap == 0)
+	return (INFINITY);
+    else {
+	const char *cp;
+	float cum_cost = 0.0;
+
+	for (cp = cap; *cp; cp++) {
+	    /* extract padding, either mandatory or required */
+	    if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>')) {
+		float number = 0.0;
+
+		for (cp += 2; *cp != '>'; cp++) {
+		    if (isdigit(UChar(*cp)))
+			number = number * 10 + (*cp - '0');
+		    else if (*cp == '*')
+			number *= affcnt;
+		    else if (*cp == '.' && (*++cp != '>') && isdigit(UChar(*cp)))
+			number += (*cp - '0') / 10.0;
+		}
+
+#if NCURSES_NO_PADDING
+		if (!GetNoPadding(SP))
+#endif
+		    cum_cost += number * 10;
+	    } else
+		cum_cost += SP->_char_padding;
+	}
+
+	return ((int) cum_cost);
+    }
+}
+
+static int
+normalized_cost(const char *const cap, int affcnt)
+/* compute the effective character-count for an operation (round up) */
+{
+    int cost = _nc_msec_cost(cap, affcnt);
+    if (cost != INFINITY)
+	cost = (cost + SP->_char_padding - 1) / SP->_char_padding;
+    return cost;
+}
+
+static void
+reset_scroll_region(void)
+/* Set the scroll-region to a known state (the default) */
+{
+    if (change_scroll_region) {
+	TPUTS_TRACE("change_scroll_region");
+	putp(TPARM_2(change_scroll_region, 0, screen_lines - 1));
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_mvcur_resume(void)
+/* what to do at initialization time and after each shellout */
+{
+    /* initialize screen for cursor access */
+    if (enter_ca_mode) {
+	TPUTS_TRACE("enter_ca_mode");
+	putp(enter_ca_mode);
+    }
+
+    /*
+     * Doing this here rather than in _nc_mvcur_wrap() ensures that
+     * ncurses programs will see a reset scroll region even if a
+     * program that messed with it died ungracefully.
+     *
+     * This also undoes the effects of terminal init strings that assume
+     * they know the screen size.  This is useful when you're running
+     * a vt100 emulation through xterm.
+     */
+    reset_scroll_region();
+    SP->_cursrow = SP->_curscol = -1;
+
+    /* restore cursor shape */
+    if (SP->_cursor != -1) {
+	int cursor = SP->_cursor;
+	SP->_cursor = -1;
+	curs_set(cursor);
+    }
+}
+
+NCURSES_EXPORT(void)
+_nc_mvcur_init(void)
+/* initialize the cost structure */
+{
+    if (isatty(fileno(SP->_ofp)))
+	SP->_char_padding = ((BAUDBYTE * 1000 * 10)
+			     / (BAUDRATE > 0 ? BAUDRATE : 9600));
+    else
+	SP->_char_padding = 1;	/* must be nonzero */
+    if (SP->_char_padding <= 0)
+	SP->_char_padding = 1;	/* must be nonzero */
+    TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding));
+
+    /* non-parameterized local-motion strings */
+    SP->_cr_cost = CostOf(carriage_return, 0);
+    SP->_home_cost = CostOf(cursor_home, 0);
+    SP->_ll_cost = CostOf(cursor_to_ll, 0);
+#if USE_HARD_TABS
+    if (getenv("NCURSES_NO_HARD_TABS") == 0) {
+	SP->_ht_cost = CostOf(tab, 0);
+	SP->_cbt_cost = CostOf(back_tab, 0);
+    } else {
+	SP->_ht_cost = INFINITY;
+	SP->_cbt_cost = INFINITY;
+    }
+#endif /* USE_HARD_TABS */
+    SP->_cub1_cost = CostOf(cursor_left, 0);
+    SP->_cuf1_cost = CostOf(cursor_right, 0);
+    SP->_cud1_cost = CostOf(cursor_down, 0);
+    SP->_cuu1_cost = CostOf(cursor_up, 0);
+
+    SP->_smir_cost = CostOf(enter_insert_mode, 0);
+    SP->_rmir_cost = CostOf(exit_insert_mode, 0);
+    SP->_ip_cost = 0;
+    if (insert_padding) {
+	SP->_ip_cost = CostOf(insert_padding, 0);
+    }
+
+    /*
+     * Assumption: if the terminal has memory_relative addressing, the
+     * initialization strings or smcup will set single-page mode so we
+     * can treat it like absolute screen addressing.  This seems to be true
+     * for all cursor_mem_address terminal types in the terminfo database.
+     */
+    SP->_address_cursor = cursor_address ? cursor_address : cursor_mem_address;
+
+    /*
+     * Parametrized local-motion strings.  This static cost computation
+     * depends on the following assumptions:
+     *
+     * (1) They never have * padding.  In the entire master terminfo database
+     *     as of March 1995, only the obsolete Zenith Z-100 pc violates this.
+     *     (Proportional padding is found mainly in insert, delete and scroll
+     *     capabilities).
+     *
+     * (2) The average case of cup has two two-digit parameters.  Strictly,
+     *     the average case for a 24 * 80 screen has ((10*10*(1 + 1)) +
+     *     (14*10*(1 + 2)) + (10*70*(2 + 1)) + (14*70*4)) / (24*80) = 3.458
+     *     digits of parameters.  On a 25x80 screen the average is 3.6197.
+     *     On larger screens the value gets much closer to 4.
+     *
+     * (3) The average case of cub/cuf/hpa/ech/rep has 2 digits of parameters
+     *     (strictly, (((10 * 1) + (70 * 2)) / 80) = 1.8750).
+     *
+     * (4) The average case of cud/cuu/vpa has 2 digits of parameters
+     *     (strictly, (((10 * 1) + (14 * 2)) / 24) = 1.5833).
+     *
+     * All these averages depend on the assumption that all parameter values
+     * are equally probable.
+     */
+    SP->_cup_cost = CostOf(TPARM_2(SP->_address_cursor, 23, 23), 1);
+    SP->_cub_cost = CostOf(TPARM_1(parm_left_cursor, 23), 1);
+    SP->_cuf_cost = CostOf(TPARM_1(parm_right_cursor, 23), 1);
+    SP->_cud_cost = CostOf(TPARM_1(parm_down_cursor, 23), 1);
+    SP->_cuu_cost = CostOf(TPARM_1(parm_up_cursor, 23), 1);
+    SP->_hpa_cost = CostOf(TPARM_1(column_address, 23), 1);
+    SP->_vpa_cost = CostOf(TPARM_1(row_address, 23), 1);
+
+    /* non-parameterized screen-update strings */
+    SP->_ed_cost = NormalizedCost(clr_eos, 1);
+    SP->_el_cost = NormalizedCost(clr_eol, 1);
+    SP->_el1_cost = NormalizedCost(clr_bol, 1);
+    SP->_dch1_cost = NormalizedCost(delete_character, 1);
+    SP->_ich1_cost = NormalizedCost(insert_character, 1);
+
+    /*
+     * If this is a bce-terminal, we want to bias the choice so we use clr_eol
+     * rather than spaces at the end of a line.
+     */
+    if (back_color_erase)
+	SP->_el_cost = 0;
+
+    /* parameterized screen-update strings */
+    SP->_dch_cost = NormalizedCost(TPARM_1(parm_dch, 23), 1);
+    SP->_ich_cost = NormalizedCost(TPARM_1(parm_ich, 23), 1);
+    SP->_ech_cost = NormalizedCost(TPARM_1(erase_chars, 23), 1);
+    SP->_rep_cost = NormalizedCost(TPARM_2(repeat_char, ' ', 23), 1);
+
+    SP->_cup_ch_cost = NormalizedCost(TPARM_2(SP->_address_cursor, 23, 23), 1);
+    SP->_hpa_ch_cost = NormalizedCost(TPARM_1(column_address, 23), 1);
+    SP->_cuf_ch_cost = NormalizedCost(TPARM_1(parm_right_cursor, 23), 1);
+    SP->_inline_cost = min(SP->_cup_ch_cost,
+			   min(SP->_hpa_ch_cost,
+			       SP->_cuf_ch_cost));
+
+    /*
+     * If save_cursor is used within enter_ca_mode, we should not use it for
+     * scrolling optimization, since the corresponding restore_cursor is not
+     * nested on the various terminals (vt100, xterm, etc.) which use this
+     * feature.
+     */
+    if (save_cursor != 0
+	&& enter_ca_mode != 0
+	&& strstr(enter_ca_mode, save_cursor) != 0) {
+	T(("...suppressed sc/rc capability due to conflict with smcup/rmcup"));
+	save_cursor = 0;
+	restore_cursor = 0;
+    }
+
+    /*
+     * A different, possibly better way to arrange this would be to set
+     * SP->_endwin = TRUE at window initialization time and let this be
+     * called by doupdate's return-from-shellout code.
+     */
+    _nc_mvcur_resume();
+}
+
+NCURSES_EXPORT(void)
+_nc_mvcur_wrap(void)
+/* wrap up cursor-addressing mode */
+{
+    /* leave cursor at screen bottom */
+    mvcur(-1, -1, screen_lines - 1, 0);
+
+    /* set cursor to normal mode */
+    if (SP->_cursor != -1) {
+	int cursor = SP->_cursor;
+	curs_set(1);
+	SP->_cursor = cursor;
+    }
+
+    if (exit_ca_mode) {
+	TPUTS_TRACE("exit_ca_mode");
+	putp(exit_ca_mode);
+    }
+    /*
+     * Reset terminal's tab counter.  There's a long-time bug that
+     * if you exit a "curses" program such as vi or more, tab
+     * forward, and then backspace, the cursor doesn't go to the
+     * right place.  The problem is that the kernel counts the
+     * escape sequences that reset things as column positions.
+     * Utter a \r to reset this invisibly.
+     */
+    _nc_outch('\r');
+}
+
+/****************************************************************************
+ *
+ * Optimized cursor movement
+ *
+ ****************************************************************************/
+
+/*
+ * Perform repeated-append, returning cost
+ */
+static NCURSES_INLINE int
+repeated_append(string_desc * target, int total, int num, int repeat, const char *src)
+{
+    size_t need = repeat * strlen(src);
+
+    if (need < target->s_size) {
+	while (repeat-- > 0) {
+	    if (_nc_safe_strcat(target, src)) {
+		total += num;
+	    } else {
+		total = INFINITY;
+		break;
+	    }
+	}
+    } else {
+	total = INFINITY;
+    }
+    return total;
+}
+
+#ifndef NO_OPTIMIZE
+#define NEXTTAB(fr)	(fr + init_tabs - (fr % init_tabs))
+
+/*
+ * Assume back_tab (CBT) does not wrap backwards at the left margin, return
+ * a negative value at that point to simplify the loop.
+ */
+#define LASTTAB(fr)	((fr > 0) ? ((fr - 1) / init_tabs) * init_tabs : -1)
+
+static int
+relative_move(string_desc * target, int from_y, int from_x, int to_y, int
+	      to_x, bool ovw)
+/* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */
+{
+    string_desc save;
+    int n, vcost = 0, hcost = 0;
+
+    (void) _nc_str_copy(&save, target);
+
+    if (to_y != from_y) {
+	vcost = INFINITY;
+
+	if (row_address != 0
+	    && _nc_safe_strcat(target, TPARM_1(row_address, to_y))) {
+	    vcost = SP->_vpa_cost;
+	}
+
+	if (to_y > from_y) {
+	    n = (to_y - from_y);
+
+	    if (parm_down_cursor
+		&& SP->_cud_cost < vcost
+		&& _nc_safe_strcat(_nc_str_copy(target, &save),
+				   TPARM_1(parm_down_cursor, n))) {
+		vcost = SP->_cud_cost;
+	    }
+
+	    if (cursor_down
+		&& (*cursor_down != '\n' || SP->_nl)
+		&& (n * SP->_cud1_cost < vcost)) {
+		vcost = repeated_append(_nc_str_copy(target, &save), 0,
+					SP->_cud1_cost, n, cursor_down);
+	    }
+	} else {		/* (to_y < from_y) */
+	    n = (from_y - to_y);
+
+	    if (parm_up_cursor
+		&& SP->_cuu_cost < vcost
+		&& _nc_safe_strcat(_nc_str_copy(target, &save),
+				   TPARM_1(parm_up_cursor, n))) {
+		vcost = SP->_cuu_cost;
+	    }
+
+	    if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
+		vcost = repeated_append(_nc_str_copy(target, &save), 0,
+					SP->_cuu1_cost, n, cursor_up);
+	    }
+	}
+
+	if (vcost == INFINITY)
+	    return (INFINITY);
+    }
+
+    save = *target;
+
+    if (to_x != from_x) {
+	char str[OPT_SIZE];
+	string_desc check;
+
+	hcost = INFINITY;
+
+	if (column_address
+	    && _nc_safe_strcat(_nc_str_copy(target, &save),
+			       TPARM_1(column_address, to_x))) {
+	    hcost = SP->_hpa_cost;
+	}
+
+	if (to_x > from_x) {
+	    n = to_x - from_x;
+
+	    if (parm_right_cursor
+		&& SP->_cuf_cost < hcost
+		&& _nc_safe_strcat(_nc_str_copy(target, &save),
+				   TPARM_1(parm_right_cursor, n))) {
+		hcost = SP->_cuf_cost;
+	    }
+
+	    if (cursor_right) {
+		int lhcost = 0;
+
+		(void) _nc_str_init(&check, str, sizeof(str));
+
+#if USE_HARD_TABS
+		/* use hard tabs, if we have them, to do as much as possible */
+		if (init_tabs > 0 && tab) {
+		    int nxt, fr;
+
+		    for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) {
+			lhcost = repeated_append(&check, lhcost,
+						 SP->_ht_cost, 1, tab);
+			if (lhcost == INFINITY)
+			    break;
+		    }
+
+		    n = to_x - fr;
+		    from_x = fr;
+		}
+#endif /* USE_HARD_TABS */
+
+		if (n <= 0 || n >= (int) check.s_size)
+		    ovw = FALSE;
+#if BSD_TPUTS
+		/*
+		 * If we're allowing BSD-style padding in tputs, don't generate
+		 * a string with a leading digit.  Otherwise, that will be
+		 * interpreted as a padding value rather than sent to the
+		 * screen.
+		 */
+		if (ovw
+		    && n > 0
+		    && n < (int) check.s_size
+		    && vcost == 0
+		    && str[0] == '\0') {
+		    int wanted = CharOf(WANT_CHAR(to_y, from_x));
+		    if (is8bits(wanted) && isdigit(wanted))
+			ovw = FALSE;
+		}
+#endif
+		/*
+		 * If we have no attribute changes, overwrite is cheaper.
+		 * Note: must suppress this by passing in ovw = FALSE whenever
+		 * WANT_CHAR would return invalid data.  In particular, this
+		 * is true between the time a hardware scroll has been done
+		 * and the time the structure WANT_CHAR would access has been
+		 * updated.
+		 */
+		if (ovw) {
+		    int i;
+
+		    for (i = 0; i < n; i++) {
+			NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i);
+			if (!SameAttrOf(ch, SCREEN_ATTRS(SP))
+#if USE_WIDEC_SUPPORT
+			    || !Charable(ch)
+#endif
+			    ) {
+			    ovw = FALSE;
+			    break;
+			}
+		    }
+		}
+		if (ovw) {
+		    int i;
+
+		    for (i = 0; i < n; i++)
+			*check.s_tail++ = (char) CharOf(WANT_CHAR(to_y,
+								  from_x + i));
+		    *check.s_tail = '\0';
+		    check.s_size -= n;
+		    lhcost += n * SP->_char_padding;
+		} else {
+		    lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost,
+					     n, cursor_right);
+		}
+
+		if (lhcost < hcost
+		    && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
+		    hcost = lhcost;
+		}
+	    }
+	} else {		/* (to_x < from_x) */
+	    n = from_x - to_x;
+
+	    if (parm_left_cursor
+		&& SP->_cub_cost < hcost
+		&& _nc_safe_strcat(_nc_str_copy(target, &save),
+				   TPARM_1(parm_left_cursor, n))) {
+		hcost = SP->_cub_cost;
+	    }
+
+	    if (cursor_left) {
+		int lhcost = 0;
+
+		(void) _nc_str_init(&check, str, sizeof(str));
+
+#if USE_HARD_TABS
+		if (init_tabs > 0 && back_tab) {
+		    int nxt, fr;
+
+		    for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) {
+			lhcost = repeated_append(&check, lhcost,
+						 SP->_cbt_cost, 1, back_tab);
+			if (lhcost == INFINITY)
+			    break;
+		    }
+
+		    n = fr - to_x;
+		}
+#endif /* USE_HARD_TABS */
+
+		lhcost = repeated_append(&check, lhcost, SP->_cub1_cost, n, cursor_left);
+
+		if (lhcost < hcost
+		    && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
+		    hcost = lhcost;
+		}
+	    }
+	}
+
+	if (hcost == INFINITY)
+	    return (INFINITY);
+    }
+
+    return (vcost + hcost);
+}
+#endif /* !NO_OPTIMIZE */
+
+/*
+ * With the machinery set up above, it's conceivable that
+ * onscreen_mvcur could be modified into a recursive function that does
+ * an alpha-beta search of motion space, as though it were a chess
+ * move tree, with the weight function being boolean and the search
+ * depth equated to length of string.  However, this would jack up the
+ * computation cost a lot, especially on terminals without a cup
+ * capability constraining the search tree depth.  So we settle for
+ * the simpler method below.
+ */
+
+static NCURSES_INLINE int
+onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
+/* onscreen move from (yold, xold) to (ynew, xnew) */
+{
+    string_desc result;
+    char buffer[OPT_SIZE];
+    int tactic = 0, newcost, usecost = INFINITY;
+    int t5_cr_cost;
+
+#if defined(MAIN) || defined(NCURSES_TEST)
+    struct timeval before, after;
+
+    gettimeofday(&before, NULL);
+#endif /* MAIN */
+
+#define NullResult _nc_str_null(&result, sizeof(buffer))
+#define InitResult _nc_str_init(&result, buffer, sizeof(buffer))
+
+    /* tactic #0: use direct cursor addressing */
+    if (_nc_safe_strcpy(InitResult, TPARM_2(SP->_address_cursor, ynew, xnew))) {
+	tactic = 0;
+	usecost = SP->_cup_cost;
+
+#if defined(TRACE) || defined(NCURSES_TEST)
+	if (!(_nc_optimize_enable & OPTIMIZE_MVCUR))
+	    goto nonlocal;
+#endif /* TRACE */
+
+	/*
+	 * We may be able to tell in advance that the full optimization
+	 * will probably not be worth its overhead.  Also, don't try to
+	 * use local movement if the current attribute is anything but
+	 * A_NORMAL...there are just too many ways this can screw up
+	 * (like, say, local-movement \n getting mapped to some obscure
+	 * character because A_ALTCHARSET is on).
+	 */
+	if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew)) {
+#if defined(MAIN) || defined(NCURSES_TEST)
+	    if (!profiling) {
+		(void) fputs("nonlocal\n", stderr);
+		goto nonlocal;	/* always run the optimizer if profiling */
+	    }
+#else
+	    goto nonlocal;
+#endif /* MAIN */
+	}
+    }
+#ifndef NO_OPTIMIZE
+    /* tactic #1: use local movement */
+    if (yold != -1 && xold != -1
+	&& ((newcost = relative_move(NullResult, yold, xold, ynew, xnew,
+				     ovw)) != INFINITY)
+	&& newcost < usecost) {
+	tactic = 1;
+	usecost = newcost;
+    }
+
+    /* tactic #2: use carriage-return + local movement */
+    if (yold != -1 && carriage_return
+	&& ((newcost = relative_move(NullResult, yold, 0, ynew, xnew, ovw))
+	    != INFINITY)
+	&& SP->_cr_cost + newcost < usecost) {
+	tactic = 2;
+	usecost = SP->_cr_cost + newcost;
+    }
+
+    /* tactic #3: use home-cursor + local movement */
+    if (cursor_home
+	&& ((newcost = relative_move(NullResult, 0, 0, ynew, xnew, ovw)) != INFINITY)
+	&& SP->_home_cost + newcost < usecost) {
+	tactic = 3;
+	usecost = SP->_home_cost + newcost;
+    }
+
+    /* tactic #4: use home-down + local movement */
+    if (cursor_to_ll
+	&& ((newcost = relative_move(NullResult, screen_lines - 1, 0, ynew,
+				     xnew, ovw)) != INFINITY)
+	&& SP->_ll_cost + newcost < usecost) {
+	tactic = 4;
+	usecost = SP->_ll_cost + newcost;
+    }
+
+    /*
+     * tactic #5: use left margin for wrap to right-hand side,
+     * unless strange wrap behavior indicated by xenl might hose us.
+     */
+    t5_cr_cost = (xold > 0 ? SP->_cr_cost : 0);
+    if (auto_left_margin && !eat_newline_glitch
+	&& yold > 0 && cursor_left
+	&& ((newcost = relative_move(NullResult, yold - 1, screen_columns -
+				     1, ynew, xnew, ovw)) != INFINITY)
+	&& t5_cr_cost + SP->_cub1_cost + newcost < usecost) {
+	tactic = 5;
+	usecost = t5_cr_cost + SP->_cub1_cost + newcost;
+    }
+
+    /*
+     * These cases are ordered by estimated relative frequency.
+     */
+    if (tactic)
+	InitResult;
+    switch (tactic) {
+    case 1:
+	(void) relative_move(&result, yold, xold, ynew, xnew, ovw);
+	break;
+    case 2:
+	(void) _nc_safe_strcpy(&result, carriage_return);
+	(void) relative_move(&result, yold, 0, ynew, xnew, ovw);
+	break;
+    case 3:
+	(void) _nc_safe_strcpy(&result, cursor_home);
+	(void) relative_move(&result, 0, 0, ynew, xnew, ovw);
+	break;
+    case 4:
+	(void) _nc_safe_strcpy(&result, cursor_to_ll);
+	(void) relative_move(&result, screen_lines - 1, 0, ynew, xnew, ovw);
+	break;
+    case 5:
+	if (xold > 0)
+	    (void) _nc_safe_strcat(&result, carriage_return);
+	(void) _nc_safe_strcat(&result, cursor_left);
+	(void) relative_move(&result, yold - 1, screen_columns - 1, ynew,
+			     xnew, ovw);
+	break;
+    }
+#endif /* !NO_OPTIMIZE */
+
+  nonlocal:
+#if defined(MAIN) || defined(NCURSES_TEST)
+    gettimeofday(&after, NULL);
+    diff = after.tv_usec - before.tv_usec
+	+ (after.tv_sec - before.tv_sec) * 1000000;
+    if (!profiling)
+	(void) fprintf(stderr,
+		       "onscreen: %d microsec, %f 28.8Kbps char-equivalents\n",
+		       (int) diff, diff / 288);
+#endif /* MAIN */
+
+    if (usecost != INFINITY) {
+	TPUTS_TRACE("mvcur");
+	tputs(buffer, 1, _nc_outch);
+	SP->_cursrow = ynew;
+	SP->_curscol = xnew;
+	return (OK);
+    } else
+	return (ERR);
+}
+
+NCURSES_EXPORT(int)
+mvcur(int yold, int xold, int ynew, int xnew)
+/* optimized cursor move from (yold, xold) to (ynew, xnew) */
+{
+    NCURSES_CH_T oldattr;
+    int code;
+
+    TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
+				  yold, xold, ynew, xnew));
+
+    if (SP == 0) {
+	code = ERR;
+    } else if (yold == ynew && xold == xnew) {
+	code = OK;
+    } else {
+
+	/*
+	 * Most work here is rounding for terminal boundaries getting the
+	 * column position implied by wraparound or the lack thereof and
+	 * rolling up the screen to get ynew on the screen.
+	 */
+	if (xnew >= screen_columns) {
+	    ynew += xnew / screen_columns;
+	    xnew %= screen_columns;
+	}
+
+	/*
+	 * Force restore even if msgr is on when we're in an alternate
+	 * character set -- these have a strong tendency to screw up the CR &
+	 * LF used for local character motions!
+	 */
+	oldattr = SCREEN_ATTRS(SP);
+	if ((AttrOf(oldattr) & A_ALTCHARSET)
+	    || (AttrOf(oldattr) && !move_standout_mode)) {
+	    TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
+			       (unsigned long) AttrOf(oldattr),
+			       _traceattr(AttrOf(oldattr))));
+	    (void) VIDATTR(A_NORMAL, 0);
+	}
+
+	if (xold >= screen_columns) {
+	    int l;
+
+	    if (SP->_nl) {
+		l = (xold + 1) / screen_columns;
+		yold += l;
+		if (yold >= screen_lines)
+		    l -= (yold - screen_lines - 1);
+
+		if (l > 0) {
+		    if (carriage_return) {
+			TPUTS_TRACE("carriage_return");
+			putp(carriage_return);
+		    } else
+			_nc_outch('\r');
+		    xold = 0;
+
+		    while (l > 0) {
+			if (newline) {
+			    TPUTS_TRACE("newline");
+			    putp(newline);
+			} else
+			    _nc_outch('\n');
+			l--;
+		    }
+		}
+	    } else {
+		/*
+		 * If caller set nonl(), we cannot really use newlines to
+		 * position to the next row.
+		 */
+		xold = -1;
+		yold = -1;
+	    }
+	}
+
+	if (yold > screen_lines - 1)
+	    yold = screen_lines - 1;
+	if (ynew > screen_lines - 1)
+	    ynew = screen_lines - 1;
+
+	/* destination location is on screen now */
+	code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE);
+
+	/*
+	 * Restore attributes if we disabled them before moving.
+	 */
+	if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) {
+	    TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move",
+			       (unsigned long) AttrOf(oldattr),
+			       _traceattr(AttrOf(oldattr))));
+	    (void) VIDATTR(AttrOf(oldattr), GetPair(oldattr));
+	}
+    }
+    returnCode(code);
+}
+
+#if defined(TRACE) || defined(NCURSES_TEST)
+NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL;
+#endif
+
+#if defined(MAIN) || defined(NCURSES_TEST)
+/****************************************************************************
+ *
+ * Movement optimizer test code
+ *
+ ****************************************************************************/
+
+#include <tic.h>
+#include <dump_entry.h>
+#include <time.h>
+
+NCURSES_EXPORT_VAR(const char *) _nc_progname = "mvcur";
+
+static unsigned long xmits;
+
+/* these override lib_tputs.c */
+NCURSES_EXPORT(int)
+tputs(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED)
+/* stub tputs() that dumps sequences in a visible form */
+{
+    if (profiling)
+	xmits += strlen(string);
+    else
+	(void) fputs(_nc_visbuf(string), stdout);
+    return (OK);
+}
+
+NCURSES_EXPORT(int)
+putp(const char *string)
+{
+    return (tputs(string, 1, _nc_outch));
+}
+
+NCURSES_EXPORT(int)
+_nc_outch(int ch)
+{
+    putc(ch, stdout);
+    return OK;
+}
+
+NCURSES_EXPORT(int)
+delay_output(int ms GCC_UNUSED)
+{
+    return OK;
+}
+
+static char tname[PATH_MAX];
+
+static void
+load_term(void)
+{
+    (void) setupterm(tname, STDOUT_FILENO, NULL);
+}
+
+static int
+roll(int n)
+{
+    int i, j;
+
+    i = (RAND_MAX / n) * n;
+    while ((j = rand()) >= i)
+	continue;
+    return (j % n);
+}
+
+int
+main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+{
+    strcpy(tname, getenv("TERM"));
+    load_term();
+    _nc_setupscreen(lines, columns, stdout, FALSE, 0);
+    baudrate();
+
+    _nc_mvcur_init();
+    NC_BUFFERED(FALSE);
+
+    (void) puts("The mvcur tester.  Type ? for help");
+
+    fputs("smcup:", stdout);
+    putchar('\n');
+
+    for (;;) {
+	int fy, fx, ty, tx, n, i;
+	char buf[BUFSIZ], capname[BUFSIZ];
+
+	(void) fputs("> ", stdout);
+	(void) fgets(buf, sizeof(buf), stdin);
+
+	if (buf[0] == '?') {
+	    (void) puts("?                -- display this help message");
+	    (void)
+		puts("fy fx ty tx      -- (4 numbers) display (fy,fx)->(ty,tx) move");
+	    (void) puts("s[croll] n t b m -- display scrolling sequence");
+	    (void)
+		printf("r[eload]         -- reload terminal info for %s\n",
+		       termname());
+	    (void)
+		puts("l[oad] <term>    -- load terminal info for type <term>");
+	    (void) puts("d[elete] <cap>   -- delete named capability");
+	    (void) puts("i[nspect]        -- display terminal capabilities");
+	    (void)
+		puts("c[ost]           -- dump cursor-optimization cost table");
+	    (void) puts("o[optimize]      -- toggle movement optimization");
+	    (void)
+		puts("t[orture] <num>  -- torture-test with <num> random moves");
+	    (void) puts("q[uit]           -- quit the program");
+	} else if (sscanf(buf, "%d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
+	    struct timeval before, after;
+
+	    putchar('"');
+
+	    gettimeofday(&before, NULL);
+	    mvcur(fy, fx, ty, tx);
+	    gettimeofday(&after, NULL);
+
+	    printf("\" (%ld msec)\n",
+		   (long) (after.tv_usec - before.tv_usec
+			   + (after.tv_sec - before.tv_sec)
+			   * 1000000));
+	} else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
+	    struct timeval before, after;
+
+	    putchar('"');
+
+	    gettimeofday(&before, NULL);
+	    _nc_scrolln(fy, fx, ty, tx);
+	    gettimeofday(&after, NULL);
+
+	    printf("\" (%ld msec)\n",
+		   (long) (after.tv_usec - before.tv_usec + (after.tv_sec -
+							     before.tv_sec)
+			   * 1000000));
+	} else if (buf[0] == 'r') {
+	    (void) strcpy(tname, termname());
+	    load_term();
+	} else if (sscanf(buf, "l %s", tname) == 1) {
+	    load_term();
+	} else if (sscanf(buf, "d %s", capname) == 1) {
+	    struct name_table_entry const *np = _nc_find_entry(capname,
+							       _nc_get_hash_table(FALSE));
+
+	    if (np == NULL)
+		(void) printf("No such capability as \"%s\"\n", capname);
+	    else {
+		switch (np->nte_type) {
+		case BOOLEAN:
+		    cur_term->type.Booleans[np->nte_index] = FALSE;
+		    (void)
+			printf("Boolean capability `%s' (%d) turned off.\n",
+			       np->nte_name, np->nte_index);
+		    break;
+
+		case NUMBER:
+		    cur_term->type.Numbers[np->nte_index] = ABSENT_NUMERIC;
+		    (void) printf("Number capability `%s' (%d) set to -1.\n",
+				  np->nte_name, np->nte_index);
+		    break;
+
+		case STRING:
+		    cur_term->type.Strings[np->nte_index] = ABSENT_STRING;
+		    (void) printf("String capability `%s' (%d) deleted.\n",
+				  np->nte_name, np->nte_index);
+		    break;
+		}
+	    }
+	} else if (buf[0] == 'i') {
+	    dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
+	    dump_entry(&cur_term->type, FALSE, TRUE, 0, 0);
+	    putchar('\n');
+	} else if (buf[0] == 'o') {
+	    if (_nc_optimize_enable & OPTIMIZE_MVCUR) {
+		_nc_optimize_enable &= ~OPTIMIZE_MVCUR;
+		(void) puts("Optimization is now off.");
+	    } else {
+		_nc_optimize_enable |= OPTIMIZE_MVCUR;
+		(void) puts("Optimization is now on.");
+	    }
+	}
+	/*
+	 * You can use the `t' test to profile and tune the movement
+	 * optimizer.  Use iteration values in three digits or more.
+	 * At above 5000 iterations the profile timing averages are stable
+	 * to within a millisecond or three.
+	 *
+	 * The `overhead' field of the report will help you pick a
+	 * COMPUTE_OVERHEAD figure appropriate for your processor and
+	 * expected line speed.  The `total estimated time' is
+	 * computation time plus a character-transmission time
+	 * estimate computed from the number of transmits and the baud
+	 * rate.
+	 *
+	 * Use this together with the `o' command to get a read on the
+	 * optimizer's effectiveness.  Compare the total estimated times
+	 * for `t' runs of the same length in both optimized and un-optimized
+	 * modes.  As long as the optimized times are less, the optimizer
+	 * is winning.
+	 */
+	else if (sscanf(buf, "t %d", &n) == 1) {
+	    float cumtime = 0.0, perchar;
+	    int speeds[] =
+	    {2400, 9600, 14400, 19200, 28800, 38400, 0};
+
+	    srand((unsigned) (getpid() + time((time_t *) 0)));
+	    profiling = TRUE;
+	    xmits = 0;
+	    for (i = 0; i < n; i++) {
+		/*
+		 * This does a move test between two random locations,
+		 * Random moves probably short-change the optimizer,
+		 * which will work better on the short moves probably
+		 * typical of doupdate()'s usage pattern.  Still,
+		 * until we have better data...
+		 */
+#ifdef FIND_COREDUMP
+		int from_y = roll(lines);
+		int to_y = roll(lines);
+		int from_x = roll(columns);
+		int to_x = roll(columns);
+
+		printf("(%d,%d) -> (%d,%d)\n", from_y, from_x, to_y, to_x);
+		mvcur(from_y, from_x, to_y, to_x);
+#else
+		mvcur(roll(lines), roll(columns), roll(lines), roll(columns));
+#endif /* FIND_COREDUMP */
+		if (diff)
+		    cumtime += diff;
+	    }
+	    profiling = FALSE;
+
+	    /*
+	     * Average milliseconds per character optimization time.
+	     * This is the key figure to watch when tuning the optimizer.
+	     */
+	    perchar = cumtime / n;
+
+	    (void) printf("%d moves (%ld chars) in %d msec, %f msec each:\n",
+			  n, xmits, (int) cumtime, perchar);
+
+	    for (i = 0; speeds[i]; i++) {
+		/*
+		 * Total estimated time for the moves, computation and
+		 * transmission both. Transmission time is an estimate
+		 * assuming 9 bits/char, 8 bits + 1 stop bit.
+		 */
+		float totalest = cumtime + xmits * 9 * 1e6 / speeds[i];
+
+		/*
+		 * Per-character optimization overhead in character transmits
+		 * at the current speed.  Round this to the nearest integer
+		 * to figure COMPUTE_OVERHEAD for the speed.
+		 */
+		float overhead = speeds[i] * perchar / 1e6;
+
+		(void)
+		    printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n",
+			   speeds[i], overhead, totalest);
+	    }
+	} else if (buf[0] == 'c') {
+	    (void) printf("char padding: %d\n", SP->_char_padding);
+	    (void) printf("cr cost: %d\n", SP->_cr_cost);
+	    (void) printf("cup cost: %d\n", SP->_cup_cost);
+	    (void) printf("home cost: %d\n", SP->_home_cost);
+	    (void) printf("ll cost: %d\n", SP->_ll_cost);
+#if USE_HARD_TABS
+	    (void) printf("ht cost: %d\n", SP->_ht_cost);
+	    (void) printf("cbt cost: %d\n", SP->_cbt_cost);
+#endif /* USE_HARD_TABS */
+	    (void) printf("cub1 cost: %d\n", SP->_cub1_cost);
+	    (void) printf("cuf1 cost: %d\n", SP->_cuf1_cost);
+	    (void) printf("cud1 cost: %d\n", SP->_cud1_cost);
+	    (void) printf("cuu1 cost: %d\n", SP->_cuu1_cost);
+	    (void) printf("cub cost: %d\n", SP->_cub_cost);
+	    (void) printf("cuf cost: %d\n", SP->_cuf_cost);
+	    (void) printf("cud cost: %d\n", SP->_cud_cost);
+	    (void) printf("cuu cost: %d\n", SP->_cuu_cost);
+	    (void) printf("hpa cost: %d\n", SP->_hpa_cost);
+	    (void) printf("vpa cost: %d\n", SP->_vpa_cost);
+	} else if (buf[0] == 'x' || buf[0] == 'q')
+	    break;
+	else
+	    (void) puts("Invalid command.");
+    }
+
+    (void) fputs("rmcup:", stdout);
+    _nc_mvcur_wrap();
+    putchar('\n');
+
+    return (0);
+}
+
+#endif /* MAIN */
+
+/* lib_mvcur.c ends here */
diff --git a/ncurses/tty/lib_tstp.c b/ncurses/tty/lib_tstp.c
new file mode 100644
index 0000000..06c8411
--- /dev/null
+++ b/ncurses/tty/lib_tstp.c
@@ -0,0 +1,389 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1995-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_tstp.c
+**
+**	The routine _nc_signal_handler().
+**
+*/
+#include <curses.priv.h>
+
+#include <SigAction.h>
+
+#if SVR4_ACTION && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+MODULE_ID("$Id: lib_tstp.c,v 1.37 2008/05/03 16:24:56 tom Exp $")
+
+#if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC)
+#define USE_SIGTSTP 1
+#else
+#define USE_SIGTSTP 0
+#endif
+
+#ifdef TRACE
+static const char *
+signal_name(int sig)
+{
+    switch (sig) {
+    case SIGALRM:
+	return "SIGALRM";
+#ifdef SIGCONT
+    case SIGCONT:
+	return "SIGCONT";
+#endif
+    case SIGINT:
+	return "SIGINT";
+    case SIGQUIT:
+	return "SIGQUIT";
+    case SIGTERM:
+	return "SIGTERM";
+#ifdef SIGTSTP
+    case SIGTSTP:
+	return "SIGTSTP";
+#endif
+#ifdef SIGTTOU
+    case SIGTTOU:
+	return "SIGTTOU";
+#endif
+#ifdef SIGWINCH
+    case SIGWINCH:
+	return "SIGWINCH";
+#endif
+    default:
+	return "unknown signal";
+    }
+}
+#endif
+
+/*
+ * Note: This code is fragile!  Its problem is that different OSs
+ * handle restart of system calls interrupted by signals differently.
+ * The ncurses code needs signal-call restart to happen -- otherwise,
+ * interrupted wgetch() calls will return FAIL, probably making the
+ * application think the input stream has ended and it should
+ * terminate.  In particular, you know you have this problem if, when
+ * you suspend an ncurses-using lynx with ^Z and resume, it dies
+ * immediately.
+ *
+ * Default behavior of POSIX sigaction(2) is not to restart
+ * interrupted system calls, but Linux's sigaction does it anyway (at
+ * least, on and after the 1.1.47 I (esr) use).  Thus this code works
+ * OK under Linux.  The 4.4BSD sigaction(2) supports a (non-portable)
+ * SA_RESTART flag that forces the right behavior.  Thus, this code
+ * should work OK under BSD/OS, NetBSD, and FreeBSD (let us know if it
+ * does not).
+ *
+ * Stock System Vs (and anything else using a strict-POSIX
+ * sigaction(2) without SA_RESTART) may have a problem.  Possible
+ * solutions:
+ *
+ *    sigvec      restarts by default (SV_INTERRUPT flag to not restart)
+ *    signal      restarts by default in SVr4 (assuming you link with -lucb)
+ *                and BSD, but not SVr3.
+ *    sigset      restarts, but is only available under SVr4/Solaris.
+ *
+ * The signal(3) call is mandated by the ANSI standard, and its
+ * interaction with sigaction(2) is described in the POSIX standard
+ * (3.3.4.2, page 72,line 934).  According to section 8.1, page 191,
+ * however, signal(3) itself is not required by POSIX.1.  And POSIX is
+ * silent on whether it is required to restart signals.
+ *
+ * So.  The present situation is, we use sigaction(2) with no
+ * guarantee of restart anywhere but on Linux and BSD.  We could
+ * switch to signal(3) and collar Linux, BSD, and SVr4.  Any way
+ * we slice it, System V UNIXes older than SVr4 will probably lose
+ * (this may include XENIX).
+ *
+ * This implementation will probably be changed to use signal(3) in
+ * the future.  If nothing else, it's simpler...
+ */
+
+#if USE_SIGTSTP
+static void
+tstp(int dummy GCC_UNUSED)
+{
+    sigset_t mask, omask;
+    sigaction_t act, oact;
+
+#ifdef SIGTTOU
+    int sigttou_blocked;
+#endif
+
+    T(("tstp() called"));
+
+    /*
+     * The user may have changed the prog_mode tty bits, so save them.
+     *
+     * But first try to detect whether we still are in the foreground
+     * process group - if not, an interactive shell may already have
+     * taken ownership of the tty and modified the settings when our
+     * parent was stopped before us, and we would likely pick up the
+     * settings already modified by the shell.
+     */
+    if (SP != 0 && !SP->_endwin)	/* don't do this if we're not in curses */
+#if HAVE_TCGETPGRP
+	if (tcgetpgrp(STDIN_FILENO) == getpgrp())
+#endif
+	    def_prog_mode();
+
+    /*
+     * Block window change and timer signals.  The latter
+     * is because applications use timers to decide when
+     * to repaint the screen.
+     */
+    (void) sigemptyset(&mask);
+    (void) sigaddset(&mask, SIGALRM);
+#if USE_SIGWINCH
+    (void) sigaddset(&mask, SIGWINCH);
+#endif
+    (void) sigprocmask(SIG_BLOCK, &mask, &omask);
+
+#ifdef SIGTTOU
+    sigttou_blocked = sigismember(&omask, SIGTTOU);
+    if (!sigttou_blocked) {
+	(void) sigemptyset(&mask);
+	(void) sigaddset(&mask, SIGTTOU);
+	(void) sigprocmask(SIG_BLOCK, &mask, NULL);
+    }
+#endif
+
+    /*
+     * End window mode, which also resets the terminal state to the
+     * original (pre-curses) modes.
+     */
+    endwin();
+
+    /* Unblock SIGTSTP. */
+    (void) sigemptyset(&mask);
+    (void) sigaddset(&mask, SIGTSTP);
+#ifdef SIGTTOU
+    if (!sigttou_blocked) {
+	/* Unblock this too if it wasn't blocked on entry */
+	(void) sigaddset(&mask, SIGTTOU);
+    }
+#endif
+    (void) sigprocmask(SIG_UNBLOCK, &mask, NULL);
+
+    /* Now we want to resend SIGSTP to this process and suspend it */
+    act.sa_handler = SIG_DFL;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = 0;
+#ifdef SA_RESTART
+    act.sa_flags |= SA_RESTART;
+#endif /* SA_RESTART */
+    sigaction(SIGTSTP, &act, &oact);
+    kill(getpid(), SIGTSTP);
+
+    /* Process gets suspended...time passes...process resumes */
+
+    T(("SIGCONT received"));
+    sigaction(SIGTSTP, &oact, NULL);
+    flushinp();
+
+    /*
+     * If the user modified the tty state while suspended, he wants
+     * those changes to stick.  So save the new "default" terminal state.
+     */
+    def_shell_mode();
+
+    /*
+     * This relies on the fact that doupdate() will restore the
+     * program-mode tty state, and issue enter_ca_mode if need be.
+     */
+    doupdate();
+
+    /* Reset the signals. */
+    (void) sigprocmask(SIG_SETMASK, &omask, NULL);
+}
+#endif /* USE_SIGTSTP */
+
+static void
+cleanup(int sig)
+{
+    /*
+     * Actually, doing any sort of I/O from within an signal handler is
+     * "unsafe".  But we'll _try_ to clean up the screen and terminal
+     * settings on the way out.
+     */
+    if (!_nc_globals.cleanup_nested++
+	&& (sig == SIGINT
+	    || sig == SIGQUIT)) {
+#if HAVE_SIGACTION || HAVE_SIGVEC
+	sigaction_t act;
+	sigemptyset(&act.sa_mask);
+	act.sa_flags = 0;
+	act.sa_handler = SIG_IGN;
+	if (sigaction(sig, &act, NULL) == 0)
+#else
+	if (signal(sig, SIG_IGN) != SIG_ERR)
+#endif
+	{
+	    SCREEN *scan;
+	    for (each_screen(scan)) {
+		if (scan->_ofp != 0
+		    && isatty(fileno(scan->_ofp))) {
+		    scan->_cleanup = TRUE;
+		    scan->_outch = _nc_outch;
+		}
+		set_term(scan);
+		endwin();
+		if (SP)
+		    SP->_endwin = FALSE;	/* in case we have an atexit! */
+	    }
+	}
+    }
+    exit(EXIT_FAILURE);
+}
+
+#if USE_SIGWINCH
+static void
+sigwinch(int sig GCC_UNUSED)
+{
+    _nc_globals.have_sigwinch = 1;
+}
+#endif /* USE_SIGWINCH */
+
+/*
+ * If the given signal is still in its default state, set it to the given
+ * handler.
+ */
+static int
+CatchIfDefault(int sig, RETSIGTYPE (*handler) (int))
+{
+    int result;
+#if HAVE_SIGACTION || HAVE_SIGVEC
+    sigaction_t old_act;
+    sigaction_t new_act;
+
+    memset(&new_act, 0, sizeof(new_act));
+    sigemptyset(&new_act.sa_mask);
+#ifdef SA_RESTART
+#ifdef SIGWINCH
+    if (sig != SIGWINCH)
+#endif
+	new_act.sa_flags |= SA_RESTART;
+#endif /* SA_RESTART */
+    new_act.sa_handler = handler;
+
+    if (sigaction(sig, NULL, &old_act) == 0
+	&& (old_act.sa_handler == SIG_DFL
+	    || old_act.sa_handler == handler
+#if USE_SIGWINCH
+	    || (sig == SIGWINCH && old_act.sa_handler == SIG_IGN)
+#endif
+	)) {
+	(void) sigaction(sig, &new_act, NULL);
+	result = TRUE;
+    } else {
+	result = FALSE;
+    }
+#else /* !HAVE_SIGACTION */
+    RETSIGTYPE (*ohandler) (int);
+
+    ohandler = signal(sig, SIG_IGN);
+    if (ohandler == SIG_DFL
+	|| ohandler == handler
+#if USE_SIGWINCH
+	|| (sig == SIGWINCH && ohandler == SIG_IGN)
+#endif
+	) {
+	signal(sig, handler);
+	result = TRUE;
+    } else {
+	signal(sig, ohandler);
+	result = FALSE;
+    }
+#endif
+    T(("CatchIfDefault - will %scatch %s",
+       result ? "" : "not ", signal_name(sig)));
+    return result;
+}
+
+/*
+ * This is invoked once at the beginning (e.g., from 'initscr()'), to
+ * initialize the signal catchers, and thereafter when spawning a shell (and
+ * returning) to disable/enable the SIGTSTP (i.e., ^Z) catcher.
+ *
+ * If the application has already set one of the signals, we'll not modify it
+ * (during initialization).
+ *
+ * The XSI document implies that we shouldn't keep the SIGTSTP handler if
+ * the caller later changes its mind, but that doesn't seem correct.
+ */
+NCURSES_EXPORT(void)
+_nc_signal_handler(bool enable)
+{
+    T((T_CALLED("_nc_signal_handler(%d)"), enable));
+#if USE_SIGTSTP			/* Xenix 2.x doesn't have SIGTSTP, for example */
+    {
+	static bool ignore_tstp = FALSE;
+
+	if (!ignore_tstp) {
+	    static sigaction_t new_sigaction, old_sigaction;
+
+	    if (!enable) {
+		new_sigaction.sa_handler = SIG_IGN;
+		sigaction(SIGTSTP, &new_sigaction, &old_sigaction);
+	    } else if (new_sigaction.sa_handler != SIG_DFL) {
+		sigaction(SIGTSTP, &old_sigaction, NULL);
+	    } else if (sigaction(SIGTSTP, NULL, &old_sigaction) == 0
+		       && (old_sigaction.sa_handler == SIG_DFL)) {
+		sigemptyset(&new_sigaction.sa_mask);
+#ifdef SA_RESTART
+		new_sigaction.sa_flags |= SA_RESTART;
+#endif /* SA_RESTART */
+		new_sigaction.sa_handler = tstp;
+		(void) sigaction(SIGTSTP, &new_sigaction, NULL);
+	    } else {
+		ignore_tstp = TRUE;
+	    }
+	}
+    }
+#endif /* !USE_SIGTSTP */
+
+    if (!_nc_globals.init_signals) {
+	if (enable) {
+	    CatchIfDefault(SIGINT, cleanup);
+	    CatchIfDefault(SIGTERM, cleanup);
+#if USE_SIGWINCH
+	    CatchIfDefault(SIGWINCH, sigwinch);
+#endif
+	    _nc_globals.init_signals = TRUE;
+	}
+    }
+    returnVoid;
+}
diff --git a/ncurses/tty/lib_twait.c b/ncurses/tty/lib_twait.c
new file mode 100644
index 0000000..16d12ed
--- /dev/null
+++ b/ncurses/tty/lib_twait.c
@@ -0,0 +1,450 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*
+**	lib_twait.c
+**
+**	The routine _nc_timed_wait().
+**
+**	(This file was originally written by Eric Raymond; however except for
+**	comments, none of the original code remains - T.Dickey).
+*/
+
+#include <curses.priv.h>
+
+#if defined __HAIKU__ && defined __BEOS__
+#undef __BEOS__
+#endif
+
+#ifdef __BEOS__
+#undef false
+#undef true
+#include <OS.h>
+#endif
+
+#if USE_FUNC_POLL
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# endif
+#elif HAVE_SELECT
+# if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
+#  include <sys/time.h>
+# endif
+# if HAVE_SYS_SELECT_H
+#  include <sys/select.h>
+# endif
+#endif
+
+#undef CUR
+
+MODULE_ID("$Id: lib_twait.c,v 1.59 2008/08/30 20:08:19 tom Exp $")
+
+static long
+_nc_gettime(TimeType * t0, bool first)
+{
+    long res;
+
+#if PRECISE_GETTIME
+    TimeType t1;
+    gettimeofday(&t1, (struct timezone *) 0);
+    if (first) {
+	*t0 = t1;
+	res = 0;
+    } else {
+	/* .tv_sec and .tv_usec are unsigned, be careful when subtracting */
+	if (t0->tv_usec > t1.tv_usec) {
+	    t1.tv_usec += 1000000;	/* Convert 1s in 1e6 microsecs */
+	    t1.tv_sec--;
+	}
+	res = (t1.tv_sec - t0->tv_sec) * 1000
+	    + (t1.tv_usec - t0->tv_usec) / 1000;
+    }
+#else
+    time_t t1 = time((time_t *) 0);
+    if (first) {
+	*t0 = t1;
+    }
+    res = (t1 - *t0) * 1000;
+#endif
+    TR(TRACE_IEVENT, ("%s time: %ld msec", first ? "get" : "elapsed", res));
+    return res;
+}
+
+#ifdef NCURSES_WGETCH_EVENTS
+NCURSES_EXPORT(int)
+_nc_eventlist_timeout(_nc_eventlist * evl)
+{
+    int event_delay = -1;
+    int n;
+
+    if (evl != 0) {
+
+	for (n = 0; n < evl->count; ++n) {
+	    _nc_event *ev = evl->events[n];
+
+	    if (ev->type == _NC_EVENT_TIMEOUT_MSEC) {
+		event_delay = ev->data.timeout_msec;
+		if (event_delay < 0)
+		    event_delay = INT_MAX;	/* FIXME Is this defined? */
+	    }
+	}
+    }
+    return event_delay;
+}
+#endif /* NCURSES_WGETCH_EVENTS */
+
+/*
+ * Wait a specified number of milliseconds, returning nonzero if the timer
+ * didn't expire before there is activity on the specified file descriptors.
+ * The file-descriptors are specified by the mode:
+ *	0 - none (absolute time)
+ *	1 - ncurses' normal input-descriptor
+ *	2 - mouse descriptor, if any
+ *	3 - either input or mouse.
+ *
+ * Experimental:  if NCURSES_WGETCH_EVENTS is defined, (mode & 4) determines
+ * whether to pay attention to evl argument.  If set, the smallest of
+ * millisecond and of timeout of evl is taken.
+ *
+ * We return a mask that corresponds to the mode (e.g., 2 for mouse activity).
+ *
+ * If the milliseconds given are -1, the wait blocks until activity on the
+ * descriptors.
+ */
+NCURSES_EXPORT(int)
+_nc_timed_wait(SCREEN *sp,
+	       int mode,
+	       int milliseconds,
+	       int *timeleft
+	       EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    int fd;
+    int count;
+    int result = 0;
+    TimeType t0;
+
+#ifdef NCURSES_WGETCH_EVENTS
+    int timeout_is_event = 0;
+    int n;
+#endif
+
+#if USE_FUNC_POLL
+#define MIN_FDS 2
+    struct pollfd fd_list[MIN_FDS];
+    struct pollfd *fds = fd_list;
+#elif defined(__BEOS__)
+#elif HAVE_SELECT
+    fd_set set;
+#endif
+
+    long starttime, returntime;
+
+    TR(TRACE_IEVENT, ("start twait: %d milliseconds, mode: %d",
+		      milliseconds, mode));
+
+#ifdef NCURSES_WGETCH_EVENTS
+    if (mode & 4) {
+	int event_delay = _nc_eventlist_timeout(evl);
+
+	if (event_delay >= 0
+	    && (milliseconds >= event_delay || milliseconds < 0)) {
+	    milliseconds = event_delay;
+	    timeout_is_event = 1;
+	}
+    }
+#endif
+
+#if PRECISE_GETTIME && HAVE_NANOSLEEP
+  retry:
+#endif
+    starttime = _nc_gettime(&t0, TRUE);
+
+    count = 0;
+
+#ifdef NCURSES_WGETCH_EVENTS
+    if ((mode & 4) && evl)
+	evl->result_flags = 0;
+#endif
+
+#if USE_FUNC_POLL
+    memset(fd_list, 0, sizeof(fd_list));
+
+#ifdef NCURSES_WGETCH_EVENTS
+    if ((mode & 4) && evl)
+	fds = typeMalloc(struct pollfd, MIN_FDS + evl->count);
+#endif
+
+    if (mode & 1) {
+	fds[count].fd = sp->_ifd;
+	fds[count].events = POLLIN;
+	count++;
+    }
+    if ((mode & 2)
+	&& (fd = sp->_mouse_fd) >= 0) {
+	fds[count].fd = fd;
+	fds[count].events = POLLIN;
+	count++;
+    }
+#ifdef NCURSES_WGETCH_EVENTS
+    if ((mode & 4) && evl) {
+	for (n = 0; n < evl->count; ++n) {
+	    _nc_event *ev = evl->events[n];
+
+	    if (ev->type == _NC_EVENT_FILE
+		&& (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+		fds[count].fd = ev->data.fev.fd;
+		fds[count].events = POLLIN;
+		count++;
+	    }
+	}
+    }
+#endif
+
+    result = poll(fds, (unsigned) count, milliseconds);
+
+#ifdef NCURSES_WGETCH_EVENTS
+    if ((mode & 4) && evl) {
+	int c;
+
+	if (!result)
+	    count = 0;
+
+	for (n = 0; n < evl->count; ++n) {
+	    _nc_event *ev = evl->events[n];
+
+	    if (ev->type == _NC_EVENT_FILE
+		&& (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+		ev->data.fev.result = 0;
+		for (c = 0; c < count; c++)
+		    if (fds[c].fd == ev->data.fev.fd
+			&& fds[c].revents & POLLIN) {
+			ev->data.fev.result |= _NC_EVENT_FILE_READABLE;
+			evl->result_flags |= _NC_EVENT_FILE_READABLE;
+		    }
+	    } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC
+		       && !result && timeout_is_event) {
+		evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC;
+	    }
+	}
+    }
+
+    if (fds != fd_list)
+	free((char *) fds);
+
+#endif
+
+#elif defined(__BEOS__)
+    /*
+     * BeOS's select() is declared in socket.h, so the configure script does
+     * not see it.  That's just as well, since that function works only for
+     * sockets.  This (using snooze and ioctl) was distilled from Be's patch
+     * for ncurses which uses a separate thread to simulate select().
+     *
+     * FIXME: the return values from the ioctl aren't very clear if we get
+     * interrupted.
+     *
+     * FIXME: this assumes mode&1 if milliseconds < 0 (see lib_getch.c).
+     */
+    result = 0;
+    if (mode & 1) {
+	int step = (milliseconds < 0) ? 0 : 5000;
+	bigtime_t d;
+	bigtime_t useconds = milliseconds * 1000;
+	int n, howmany;
+
+	if (useconds <= 0)	/* we're here to go _through_ the loop */
+	    useconds = 1;
+
+	for (d = 0; d < useconds; d += step) {
+	    n = 0;
+	    howmany = ioctl(0, 'ichr', &n);
+	    if (howmany >= 0 && n > 0) {
+		result = 1;
+		break;
+	    }
+	    if (useconds > 1 && step > 0) {
+		snooze(step);
+		milliseconds -= (step / 1000);
+		if (milliseconds <= 0) {
+		    milliseconds = 0;
+		    break;
+		}
+	    }
+	}
+    } else if (milliseconds > 0) {
+	snooze(milliseconds * 1000);
+	milliseconds = 0;
+    }
+#elif HAVE_SELECT
+    /*
+     * select() modifies the fd_set arguments; do this in the
+     * loop.
+     */
+    FD_ZERO(&set);
+
+    if (mode & 1) {
+	FD_SET(sp->_ifd, &set);
+	count = sp->_ifd + 1;
+    }
+    if ((mode & 2)
+	&& (fd = sp->_mouse_fd) >= 0) {
+	FD_SET(fd, &set);
+	count = max(fd, count) + 1;
+    }
+#ifdef NCURSES_WGETCH_EVENTS
+    if ((mode & 4) && evl) {
+	for (n = 0; n < evl->count; ++n) {
+	    _nc_event *ev = evl->events[n];
+
+	    if (ev->type == _NC_EVENT_FILE
+		&& (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+		FD_SET(ev->data.fev.fd, &set);
+		count = max(ev->data.fev.fd + 1, count);
+	    }
+	}
+    }
+#endif
+
+    if (milliseconds >= 0) {
+	struct timeval ntimeout;
+	ntimeout.tv_sec = milliseconds / 1000;
+	ntimeout.tv_usec = (milliseconds % 1000) * 1000;
+	result = select(count, &set, NULL, NULL, &ntimeout);
+    } else {
+	result = select(count, &set, NULL, NULL, NULL);
+    }
+
+#ifdef NCURSES_WGETCH_EVENTS
+    if ((mode & 4) && evl) {
+	evl->result_flags = 0;
+	for (n = 0; n < evl->count; ++n) {
+	    _nc_event *ev = evl->events[n];
+
+	    if (ev->type == _NC_EVENT_FILE
+		&& (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) {
+		ev->data.fev.result = 0;
+		if (FD_ISSET(ev->data.fev.fd, &set)) {
+		    ev->data.fev.result |= _NC_EVENT_FILE_READABLE;
+		    evl->result_flags |= _NC_EVENT_FILE_READABLE;
+		}
+	    } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC
+		       && !result && timeout_is_event)
+		evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC;
+	}
+    }
+#endif
+
+#endif /* USE_FUNC_POLL, etc */
+
+    returntime = _nc_gettime(&t0, FALSE);
+
+    if (milliseconds >= 0)
+	milliseconds -= (returntime - starttime);
+
+#ifdef NCURSES_WGETCH_EVENTS
+    if (evl) {
+	evl->result_flags = 0;
+	for (n = 0; n < evl->count; ++n) {
+	    _nc_event *ev = evl->events[n];
+
+	    if (ev->type == _NC_EVENT_TIMEOUT_MSEC) {
+		long diff = (returntime - starttime);
+		if (ev->data.timeout_msec <= diff)
+		    ev->data.timeout_msec = 0;
+		else
+		    ev->data.timeout_msec -= diff;
+	    }
+
+	}
+    }
+#endif
+
+#if PRECISE_GETTIME && HAVE_NANOSLEEP
+    /*
+     * If the timeout hasn't expired, and we've gotten no data,
+     * this is probably a system where 'select()' needs to be left
+     * alone so that it can complete.  Make this process sleep,
+     * then come back for more.
+     */
+    if (result == 0 && milliseconds > 100) {
+	napms(100);		/* FIXME: this won't be right if I recur! */
+	milliseconds -= 100;
+	goto retry;
+    }
+#endif
+
+    /* return approximate time left in milliseconds */
+    if (timeleft)
+	*timeleft = milliseconds;
+
+    TR(TRACE_IEVENT, ("end twait: returned %d (%d), remaining time %d msec",
+		      result, errno, milliseconds));
+
+    /*
+     * Both 'poll()' and 'select()' return the number of file descriptors
+     * that are active.  Translate this back to the mask that denotes which
+     * file-descriptors, so that we don't need all of this system-specific
+     * code everywhere.
+     */
+    if (result != 0) {
+	if (result > 0) {
+	    result = 0;
+#if USE_FUNC_POLL
+	    for (count = 0; count < MIN_FDS; count++) {
+		if ((mode & (1 << count))
+		    && (fds[count].revents & POLLIN)) {
+		    result |= (1 << count);
+		}
+	    }
+#elif defined(__BEOS__)
+	    result = 1;		/* redundant, but simple */
+#elif HAVE_SELECT
+	    if ((mode & 2)
+		&& (fd = sp->_mouse_fd) >= 0
+		&& FD_ISSET(fd, &set))
+		result |= 2;
+	    if ((mode & 1)
+		&& FD_ISSET(sp->_ifd, &set))
+		result |= 1;
+#endif
+	} else
+	    result = 0;
+    }
+#ifdef NCURSES_WGETCH_EVENTS
+    if ((mode & 4) && evl && evl->result_flags)
+	result |= 4;
+#endif
+
+    return (result);
+}
diff --git a/ncurses/tty/lib_vidattr.c b/ncurses/tty/lib_vidattr.c
new file mode 100644
index 0000000..ac2a74f
--- /dev/null
+++ b/ncurses/tty/lib_vidattr.c
@@ -0,0 +1,338 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996 on                 *
+ ****************************************************************************/
+
+/*
+ *	vidputs(newmode, outc)
+ *
+ *	newmode is taken to be the logical 'or' of the symbols in curses.h
+ *	representing graphic renditions.  The terminal is set to be in all of
+ *	the given modes, if possible.
+ *
+ *	if the new attribute is normal
+ *		if exit-alt-char-set exists
+ *			emit it
+ *		emit exit-attribute-mode
+ *	else if set-attributes exists
+ *		use it to set exactly what you want
+ *	else
+ *		if exit-attribute-mode exists
+ *			turn off everything
+ *		else
+ *			turn off those which can be turned off and aren't in
+ *			newmode.
+ *		turn on each mode which should be on and isn't, one by one
+ *
+ *	NOTE that this algorithm won't achieve the desired mix of attributes
+ *	in some cases, but those are probably just those cases in which it is
+ *	actually impossible, anyway, so...
+ *
+ * 	NOTE that we cannot assume that there's no interaction between color
+ *	and other attribute resets.  So each time we reset color (or other
+ *	attributes) we'll have to be prepared to restore the other.
+ */
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_vidattr.c,v 1.49 2007/06/30 21:58:04 tom Exp $")
+
+#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
+
+#define TurnOn(mask,mode) \
+	if ((turn_on & mask) && mode) { doPut(mode); }
+
+#define TurnOff(mask,mode) \
+	if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; }
+
+	/* if there is no current screen, assume we *can* do color */
+#define SetColorsIf(why,old_attr) \
+	if (can_color && (why)) { \
+		int old_pair = PAIR_NUMBER(old_attr); \
+		TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, pair)); \
+		if ((pair != old_pair) \
+		 || (fix_pair0 && (pair == 0)) \
+		 || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \
+			_nc_do_color(old_pair, pair, reverse, outc); \
+		} \
+	}
+
+#define PreviousAttr _nc_prescreen.previous_attr
+
+NCURSES_EXPORT(int)
+vidputs(chtype newmode, int (*outc) (int))
+{
+    attr_t turn_on, turn_off;
+    int pair;
+    bool reverse = FALSE;
+    bool can_color = (SP == 0 || SP->_coloron);
+#if NCURSES_EXT_FUNCS
+    bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color);
+#else
+#define fix_pair0 FALSE
+#endif
+
+    newmode &= A_ATTRIBUTES;
+    T((T_CALLED("vidputs(%s)"), _traceattr(newmode)));
+
+    /* this allows us to go on whether or not newterm() has been called */
+    if (SP)
+	PreviousAttr = AttrOf(SCREEN_ATTRS(SP));
+
+    TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(PreviousAttr)));
+
+    if ((SP != 0)
+	&& (magic_cookie_glitch > 0)) {
+#if USE_XMC_SUPPORT
+	static const chtype table[] =
+	{
+	    A_STANDOUT,
+	    A_UNDERLINE,
+	    A_REVERSE,
+	    A_BLINK,
+	    A_DIM,
+	    A_BOLD,
+	    A_INVIS,
+	    A_PROTECT,
+	};
+	unsigned n;
+	int used = 0;
+	int limit = (max_attributes <= 0) ? 1 : max_attributes;
+	chtype retain = 0;
+
+	/*
+	 * Limit the number of attribute bits set in the newmode according to
+	 * the terminfo max_attributes value.
+	 */
+	for (n = 0; n < SIZEOF(table); ++n) {
+	    if ((table[n] & SP->_ok_attributes) == 0) {
+		newmode &= ~table[n];
+	    } else if ((table[n] & newmode) != 0) {
+		if (used++ >= limit) {
+		    newmode &= ~table[n];
+		    if (newmode == retain)
+			break;
+		} else {
+		    retain = newmode;
+		}
+	    }
+	}
+#else
+	newmode &= ~(SP->_xmc_suppress);
+#endif
+	TR(TRACE_ATTRS, ("suppressed attribute is %s", _traceattr(newmode)));
+    }
+
+    /*
+     * If we have a terminal that cannot combine color with video
+     * attributes, use the colors in preference.
+     */
+    if (((newmode & A_COLOR) != 0
+	 || fix_pair0)
+	&& (no_color_video > 0)) {
+	/*
+	 * If we had chosen the A_xxx definitions to correspond to the
+	 * no_color_video mask, we could simply shift it up and mask off the
+	 * attributes.  But we did not (actually copied Solaris' definitions).
+	 * However, this is still simpler/faster than a lookup table.
+	 *
+	 * The 63 corresponds to A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK,
+	 * A_DIM, A_BOLD which are 1:1 with no_color_video.  The bits that
+	 * correspond to A_INVIS, A_PROTECT (192) must be shifted up 1 and
+	 * A_ALTCHARSET (256) down 2 to line up.  We use the NCURSES_BITS
+	 * macro so this will work properly for the wide-character layout.
+	 */
+	unsigned value = no_color_video;
+	attr_t mask = NCURSES_BITS((value & 63)
+				   | ((value & 192) << 1)
+				   | ((value & 256) >> 2), 8);
+
+	if ((mask & A_REVERSE) != 0
+	    && (newmode & A_REVERSE) != 0) {
+	    reverse = TRUE;
+	    mask &= ~A_REVERSE;
+	}
+	newmode &= ~mask;
+    }
+
+    if (newmode == PreviousAttr)
+	returnCode(OK);
+
+    pair = PAIR_NUMBER(newmode);
+
+    if (reverse) {
+	newmode &= ~A_REVERSE;
+    }
+
+    turn_off = (~newmode & PreviousAttr) & ALL_BUT_COLOR;
+    turn_on = (newmode & ~PreviousAttr) & ALL_BUT_COLOR;
+
+    SetColorsIf(((pair == 0) && !fix_pair0), PreviousAttr);
+
+    if (newmode == A_NORMAL) {
+	if ((PreviousAttr & A_ALTCHARSET) && exit_alt_charset_mode) {
+	    doPut(exit_alt_charset_mode);
+	    PreviousAttr &= ~A_ALTCHARSET;
+	}
+	if (PreviousAttr) {
+	    if (exit_attribute_mode) {
+		doPut(exit_attribute_mode);
+	    } else {
+		if (!SP || SP->_use_rmul) {
+		    TurnOff(A_UNDERLINE, exit_underline_mode);
+		}
+		if (!SP || SP->_use_rmso) {
+		    TurnOff(A_STANDOUT, exit_standout_mode);
+		}
+	    }
+	    PreviousAttr &= ALL_BUT_COLOR;
+	}
+
+	SetColorsIf((pair != 0) || fix_pair0, PreviousAttr);
+    } else if (set_attributes) {
+	if (turn_on || turn_off) {
+	    TPUTS_TRACE("set_attributes");
+	    tputs(tparm(set_attributes,
+			(newmode & A_STANDOUT) != 0,
+			(newmode & A_UNDERLINE) != 0,
+			(newmode & A_REVERSE) != 0,
+			(newmode & A_BLINK) != 0,
+			(newmode & A_DIM) != 0,
+			(newmode & A_BOLD) != 0,
+			(newmode & A_INVIS) != 0,
+			(newmode & A_PROTECT) != 0,
+			(newmode & A_ALTCHARSET) != 0), 1, outc);
+	    PreviousAttr &= ALL_BUT_COLOR;
+	}
+	SetColorsIf((pair != 0) || fix_pair0, PreviousAttr);
+    } else {
+
+	TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off)));
+
+	TurnOff(A_ALTCHARSET, exit_alt_charset_mode);
+
+	if (!SP || SP->_use_rmul) {
+	    TurnOff(A_UNDERLINE, exit_underline_mode);
+	}
+
+	if (!SP || SP->_use_rmso) {
+	    TurnOff(A_STANDOUT, exit_standout_mode);
+	}
+
+	if (turn_off && exit_attribute_mode) {
+	    doPut(exit_attribute_mode);
+	    turn_on |= (newmode & ALL_BUT_COLOR);
+	    PreviousAttr &= ALL_BUT_COLOR;
+	}
+	SetColorsIf((pair != 0) || fix_pair0, PreviousAttr);
+
+	TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on)));
+	/* *INDENT-OFF* */
+	TurnOn(A_ALTCHARSET,	enter_alt_charset_mode);
+	TurnOn(A_BLINK,		enter_blink_mode);
+	TurnOn(A_BOLD,		enter_bold_mode);
+	TurnOn(A_DIM,		enter_dim_mode);
+	TurnOn(A_REVERSE,	enter_reverse_mode);
+	TurnOn(A_STANDOUT,	enter_standout_mode);
+	TurnOn(A_PROTECT,	enter_protected_mode);
+	TurnOn(A_INVIS,		enter_secure_mode);
+	TurnOn(A_UNDERLINE,	enter_underline_mode);
+#if USE_WIDEC_SUPPORT
+	TurnOn(A_HORIZONTAL,	enter_horizontal_hl_mode);
+	TurnOn(A_LEFT,		enter_left_hl_mode);
+	TurnOn(A_LOW,		enter_low_hl_mode);
+	TurnOn(A_RIGHT,		enter_right_hl_mode);
+	TurnOn(A_TOP,		enter_top_hl_mode);
+	TurnOn(A_VERTICAL,	enter_vertical_hl_mode);
+#endif
+	/* *INDENT-ON* */
+
+    }
+
+    if (reverse)
+	newmode |= A_REVERSE;
+
+    if (SP)
+	SetAttr(SCREEN_ATTRS(SP), newmode);
+    else
+	PreviousAttr = newmode;
+
+    returnCode(OK);
+}
+
+NCURSES_EXPORT(int)
+vidattr(chtype newmode)
+{
+    T((T_CALLED("vidattr(%s)"), _traceattr(newmode)));
+
+    returnCode(vidputs(newmode, _nc_outch));
+}
+
+NCURSES_EXPORT(chtype)
+termattrs(void)
+{
+    chtype attrs = A_NORMAL;
+
+    T((T_CALLED("termattrs()")));
+    if (enter_alt_charset_mode)
+	attrs |= A_ALTCHARSET;
+
+    if (enter_blink_mode)
+	attrs |= A_BLINK;
+
+    if (enter_bold_mode)
+	attrs |= A_BOLD;
+
+    if (enter_dim_mode)
+	attrs |= A_DIM;
+
+    if (enter_reverse_mode)
+	attrs |= A_REVERSE;
+
+    if (enter_standout_mode)
+	attrs |= A_STANDOUT;
+
+    if (enter_protected_mode)
+	attrs |= A_PROTECT;
+
+    if (enter_secure_mode)
+	attrs |= A_INVIS;
+
+    if (enter_underline_mode)
+	attrs |= A_UNDERLINE;
+
+    if (SP->_coloron)
+	attrs |= A_COLOR;
+
+    returnChar(attrs);
+}
diff --git a/ncurses/tty/tty_display.h b/ncurses/tty/tty_display.h
new file mode 100644
index 0000000..4c45a08
--- /dev/null
+++ b/ncurses/tty/tty_display.h
@@ -0,0 +1,140 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ************************************************************************** */
+
+#ifndef TTY_DISPLAY_H
+#define TTY_DISPLAY_H 1
+
+/*
+ * $Id: tty_display.h,v 1.6 2005/01/01 23:41:12 tom Exp $
+ */
+extern NCURSES_EXPORT(bool) _nc_tty_beep (void);
+extern NCURSES_EXPORT(bool) _nc_tty_check_resize (void);
+extern NCURSES_EXPORT(bool) _nc_tty_cursor (int);
+extern NCURSES_EXPORT(bool) _nc_tty_flash (void);
+extern NCURSES_EXPORT(bool) _nc_tty_init_color (int,int,int,int);
+extern NCURSES_EXPORT(bool) _nc_tty_init_pair (int,int,int);
+extern NCURSES_EXPORT(bool) _nc_tty_slk_hide (bool);
+extern NCURSES_EXPORT(bool) _nc_tty_slk_update (int,const char *);
+extern NCURSES_EXPORT(bool) _nc_tty_start_color (void);
+extern NCURSES_EXPORT(void) _nc_tty_display_resume (void);
+extern NCURSES_EXPORT(void) _nc_tty_display_suspend (void);
+extern NCURSES_EXPORT(void) _nc_tty_dispose (void);	/* frees SP->_term */
+extern NCURSES_EXPORT(void) _nc_tty_switch_to (void);
+extern NCURSES_EXPORT(void) _nc_tty_update (void);
+
+struct tty_display_data {
+	int             _fifohold;      /* set if breakout marked           */
+	unsigned long   _current_attr;  /* terminal attribute current set   */
+	int             _cursrow;       /* physical cursor row (-1=unknown) */
+	int             _curscol;       /* physical cursor column           */
+
+	/* cursor movement costs; units are 10ths of milliseconds */
+	int             _char_padding;  /* cost of character put            */
+	int             _cr_cost;       /* cost of (carriage_return)        */
+	int             _cup_cost;      /* cost of (cursor_address)         */
+	int             _home_cost;     /* cost of (cursor_home)            */
+	int             _ll_cost;       /* cost of (cursor_to_ll)           */
+#if USE_HARD_TABS
+	int             _ht_cost;       /* cost of (tab)                    */
+	int             _cbt_cost;      /* cost of (backtab)                */
+#endif /* USE_HARD_TABS */
+	int             _cub1_cost;     /* cost of (cursor_left)            */
+	int             _cuf1_cost;     /* cost of (cursor_right)           */
+	int             _cud1_cost;     /* cost of (cursor_down)            */
+	int             _cuu1_cost;     /* cost of (cursor_up)              */
+	int             _cub_cost;      /* cost of (parm_cursor_left)       */
+	int             _cuf_cost;      /* cost of (parm_cursor_right)      */
+	int             _cud_cost;      /* cost of (parm_cursor_down)       */
+	int             _cuu_cost;      /* cost of (parm_cursor_up)         */
+	int             _hpa_cost;      /* cost of (column_address)         */
+	int             _vpa_cost;      /* cost of (row_address)            */
+	/* used in lib_doupdate.c, must be chars */
+	int             _ed_cost;       /* cost of (clr_eos)                */
+	int             _el_cost;       /* cost of (clr_eol)                */
+	int             _el1_cost;      /* cost of (clr_bol)                */
+	int             _dch1_cost;     /* cost of (delete_character)       */
+	int             _ich1_cost;     /* cost of (insert_character)       */
+	int             _dch_cost;      /* cost of (parm_dch)               */
+	int             _ich_cost;      /* cost of (parm_ich)               */
+	int             _ech_cost;      /* cost of (erase_chars)            */
+	int             _rep_cost;      /* cost of (repeat_char)            */
+	int             _hpa_ch_cost;   /* cost of (column_address)         */
+	int             _cup_ch_cost;   /* cost of (cursor_address)         */
+	int             _smir_cost;	/* cost of (enter_insert_mode)      */
+	int             _rmir_cost;	/* cost of (exit_insert_mode)       */
+	int             _ip_cost;       /* cost of (insert_padding)         */
+	/* used in lib_mvcur.c */
+	char *          _address_cursor;
+	int             _carriage_return_length;
+	int             _cursor_home_length;
+	int             _cursor_to_ll_length;
+
+	chtype          _xmc_suppress;  /* attributes to suppress if xmc     */
+	chtype          _xmc_triggers;  /* attributes to process if xmc      */
+
+	bool            _sig_winch;
+};
+
+
+#define DelCharCost(count) \
+		((parm_dch != 0) \
+		? D->_dch_cost \
+		: ((delete_character != 0) \
+			? (D->_dch1_cost * count) \
+			: INFINITY))
+
+#define InsCharCost(count) \
+		((parm_ich != 0) \
+		? D->_ich_cost \
+		: ((enter_insert_mode && exit_insert_mode) \
+		  ? D->_smir_cost + D->_rmir_cost + (D->_ip_cost * count) \
+		  : ((insert_character != 0) \
+		    ? ((D->_ich1_cost + D->_ip_cost) * count) \
+		    : INFINITY)))
+
+#if USE_XMC_SUPPORT
+#define UpdateAttrs(c)	if (!SameAttrOf(D->_current_attr, AttrOf(c))) { \
+				attr_t chg = D->_current_attr; \
+				vidattr(AttrOf(c)); \
+				if (magic_cookie_glitch > 0 \
+				 && XMC_CHANGES((chg ^ D->_current_attr))) { \
+					T(("%s @%d before glitch %d,%d", \
+						__FILE__, __LINE__, \
+						D->_cursrow, \
+						D->_curscol)); \
+					_nc_do_xmc_glitch(chg); \
+				} \
+			}
+#else
+#define UpdateAttrs(c)	if (!SameAttrOf(D->_current_attr, AttrOf(c))) \
+				vidattr(AttrOf(c));
+#endif
+
+#define XMC_CHANGES(c) ((c) & D->_xmc_suppress)
+
+#endif /* TTY_DISPLAY_H */
diff --git a/ncurses/tty/tty_input.h b/ncurses/tty/tty_input.h
new file mode 100644
index 0000000..e520793
--- /dev/null
+++ b/ncurses/tty/tty_input.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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: tty_input.h,v 1.2 2000/12/10 02:26:51 tom Exp $
+ */
+
+#ifndef TTY_INPUT_H
+#define TTY_INPUT_H 1
+
+extern NCURSES_EXPORT(bool) _nc_tty_mouse_mask (mmask_t);
+extern NCURSES_EXPORT(bool) _nc_tty_pending (void);
+extern NCURSES_EXPORT(int)  _nc_tty_next_event (int);
+extern NCURSES_EXPORT(void) _nc_tty_flags_changed (void);
+extern NCURSES_EXPORT(void) _nc_tty_flush (void);
+extern NCURSES_EXPORT(void) _nc_tty_input_resume (void);
+extern NCURSES_EXPORT(void) _nc_tty_input_suspend (void);
+
+struct tty_input_data {
+	int             _ifd;           /* input file ptr for screen        */
+	int             _keypad_xmit;   /* current terminal state           */
+	int             _meta_on;       /* current terminal state           */
+
+	/*
+	 * These are the data that support the mouse interface.
+	 */
+	bool            (*_mouse_event) (SCREEN *);
+	bool            (*_mouse_inline)(SCREEN *);
+	bool            (*_mouse_parse) (int);
+	void            (*_mouse_resume)(SCREEN *);
+	void            (*_mouse_wrap)  (SCREEN *);
+	int             _mouse_fd;      /* file-descriptor, if any */
+	int             mousetype;
+};
+
+#endif /* TTY_INPUT_H */
diff --git a/ncurses/tty/tty_update.c b/ncurses/tty/tty_update.c
new file mode 100644
index 0000000..6a3a0c8
--- /dev/null
+++ b/ncurses/tty/tty_update.c
@@ -0,0 +1,1976 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ ****************************************************************************/
+
+/*-----------------------------------------------------------------
+ *
+ *	lib_doupdate.c
+ *
+ * 	The routine doupdate() and its dependents.
+ * 	All physical output is concentrated here (except _nc_outch()
+  *	in lib_tputs.c).
+ *
+ *-----------------------------------------------------------------*/
+
+#include <curses.priv.h>
+
+#if defined __HAIKU__ && defined __BEOS__
+#undef __BEOS__
+#endif
+
+#ifdef __BEOS__
+#undef false
+#undef true
+#include <OS.h>
+#endif
+
+#if defined(TRACE) && HAVE_SYS_TIMES_H && HAVE_TIMES
+#define USE_TRACE_TIMES 1
+#else
+#define USE_TRACE_TIMES 0
+#endif
+
+#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
+#include <sys/time.h>
+#endif
+
+#if USE_TRACE_TIMES
+#include <sys/times.h>
+#endif
+
+#if USE_FUNC_POLL
+#elif HAVE_SELECT
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+#endif
+
+#include <ctype.h>
+#include <term.h>
+
+MODULE_ID("$Id: tty_update.c,v 1.246 2008/08/30 20:08:19 tom Exp $")
+
+/*
+ * This define controls the line-breakout optimization.  Every once in a
+ * while during screen refresh, we want to check for input and abort the
+ * update if there's some waiting.  CHECK_INTERVAL controls the number of
+ * changed lines to be emitted between input checks.
+ *
+ * Note: Input-check-and-abort is no longer done if the screen is being
+ * updated from scratch.  This is a feature, not a bug.
+ */
+#define CHECK_INTERVAL	5
+
+#define FILL_BCE() (SP->_coloron && !SP->_default_color && !back_color_erase)
+
+static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
+static NCURSES_CH_T normal = NewChar(BLANK_TEXT);
+
+/*
+ * Enable checking to see if doupdate and friends are tracking the true
+ * cursor position correctly.  NOTE: this is a debugging hack which will
+ * work ONLY on ANSI-compatible terminals!
+ */
+/* #define POSITION_DEBUG */
+
+static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win);
+static int ClrBottom(int total);
+static void ClearScreen(NCURSES_CH_T blank);
+static void ClrUpdate(void);
+static void DelChar(int count);
+static void InsStr(NCURSES_CH_T * line, int count);
+static void TransformLine(int const lineno);
+
+#ifdef POSITION_DEBUG
+/****************************************************************************
+ *
+ * Debugging code.  Only works on ANSI-standard terminals.
+ *
+ ****************************************************************************/
+
+static void
+position_check(int expected_y, int expected_x, char *legend)
+/* check to see if the real cursor position matches the virtual */
+{
+    char buf[20];
+    char *s;
+    int y, x;
+
+    if (!_nc_tracing || (expected_y < 0 && expected_x < 0))
+	return;
+
+    _nc_flush();
+    memset(buf, '\0', sizeof(buf));
+    putp("\033[6n");		/* only works on ANSI-compatibles */
+    _nc_flush();
+    *(s = buf) = 0;
+    do {
+	int ask = sizeof(buf) - 1 - (s - buf);
+	int got = read(0, s, ask);
+	if (got == 0)
+	    break;
+	s += got;
+    } while (strchr(buf, 'R') == 0);
+    _tracef("probe returned %s", _nc_visbuf(buf));
+
+    /* try to interpret as a position report */
+    if (sscanf(buf, "\033[%d;%dR", &y, &x) != 2) {
+	_tracef("position probe failed in %s", legend);
+    } else {
+	if (expected_x < 0)
+	    expected_x = x - 1;
+	if (expected_y < 0)
+	    expected_y = y - 1;
+	if (y - 1 != expected_y || x - 1 != expected_x) {
+	    beep();
+	    tputs(tparm("\033[%d;%dH", expected_y + 1, expected_x + 1), 1, _nc_outch);
+	    _tracef("position seen (%d, %d) doesn't match expected one (%d, %d) in %s",
+		    y - 1, x - 1, expected_y, expected_x, legend);
+	} else {
+	    _tracef("position matches OK in %s", legend);
+	}
+    }
+}
+#else
+#define position_check(expected_y, expected_x, legend)	/* nothing */
+#endif /* POSITION_DEBUG */
+
+/****************************************************************************
+ *
+ * Optimized update code
+ *
+ ****************************************************************************/
+
+static NCURSES_INLINE void
+GoTo(int const row, int const col)
+{
+    TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)",
+		    row, col, SP->_cursrow, SP->_curscol));
+
+    position_check(SP->_cursrow, SP->_curscol, "GoTo");
+
+    mvcur(SP->_cursrow, SP->_curscol, row, col);
+    position_check(SP->_cursrow, SP->_curscol, "GoTo2");
+}
+
+static NCURSES_INLINE void
+PutAttrChar(CARG_CH_T ch)
+{
+    int chlen = 1;
+    NCURSES_CH_T my_ch;
+    PUTC_DATA;
+    NCURSES_CH_T tilde;
+    NCURSES_CH_T attr = CHDEREF(ch);
+
+    TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)",
+		       _tracech_t(ch),
+		       SP->_cursrow, SP->_curscol));
+#if USE_WIDEC_SUPPORT
+    /*
+     * If this is not a valid character, there is nothing more to do.
+     */
+    if (isWidecExt(CHDEREF(ch))) {
+	TR(TRACE_CHARPUT, ("...skip"));
+	return;
+    }
+    /*
+     * Determine the number of character cells which the 'ch' value will use
+     * on the screen.  It should be at least one.
+     */
+    if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) {
+	static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+
+	/*
+	 * If the character falls into any of these special cases, do
+	 * not force the result to a blank:
+	 *
+	 * a) it is printable (this works around a bug in wcwidth()).
+	 * b) use_legacy_coding() has been called to modify the treatment
+	 *    of codes 128-255.
+	 * c) the acs_map[] has been initialized to allow codes 0-31
+	 *    to be rendered.  This supports Linux console's "PC"
+	 *    characters.  Codes 128-255 are allowed though this is
+	 *    not checked.
+	 */
+	if (is8bits(CharOf(CHDEREF(ch)))
+	    && (isprint(CharOf(CHDEREF(ch)))
+		|| (SP->_legacy_coding > 0 && CharOf(CHDEREF(ch)) >= 160)
+		|| (SP->_legacy_coding > 1 && CharOf(CHDEREF(ch)) >= 128)
+		|| (AttrOf(attr) & A_ALTCHARSET
+		    && ((CharOfD(ch) < ACS_LEN
+			 && SP->_acs_map != 0
+			 && SP->_acs_map[CharOfD(ch)] != 0)
+			|| (CharOfD(ch) >= 128))))) {
+	    ;
+	} else {
+	    ch = CHREF(blank);
+	    TR(TRACE_CHARPUT, ("forced to blank"));
+	}
+	chlen = 1;
+    }
+#endif
+
+    if ((AttrOf(attr) & A_ALTCHARSET)
+	&& SP->_acs_map != 0
+	&& CharOfD(ch) < ACS_LEN) {
+	my_ch = CHDEREF(ch);	/* work around const param */
+#if USE_WIDEC_SUPPORT
+	/*
+	 * This is crude & ugly, but works most of the time.  It checks if the
+	 * acs_chars string specified that we have a mapping for this
+	 * character, and uses the wide-character mapping when we expect the
+	 * normal one to be broken (by mis-design ;-).
+	 */
+	if (SP->_screen_acs_fix
+	    && SP->_screen_acs_map[CharOf(my_ch)]) {
+	    RemAttr(attr, A_ALTCHARSET);
+	    my_ch = _nc_wacs[CharOf(my_ch)];
+	}
+#endif
+	/*
+	 * If we (still) have alternate character set, it is the normal 8bit
+	 * flavor.  The _screen_acs_map[] array tells if the character was
+	 * really in acs_chars, needed because of the way wide/normal line
+	 * drawing flavors are integrated.
+	 */
+	if (AttrOf(attr) & A_ALTCHARSET) {
+	    int j = CharOfD(ch);
+	    chtype temp = UChar(SP->_acs_map[j]);
+
+	    if (!(SP->_screen_acs_map[j])) {
+		RemAttr(attr, A_ALTCHARSET);
+		if (temp == 0)
+		    temp = ' ';
+	    }
+	    if (temp != 0)
+		SetChar(my_ch, temp, AttrOf(attr));
+	}
+	ch = CHREF(my_ch);
+    }
+    if (tilde_glitch && (CharOfD(ch) == L('~'))) {
+	SetChar(tilde, L('`'), AttrOf(attr));
+	ch = CHREF(tilde);
+    }
+
+    UpdateAttrs(attr);
+#if !USE_WIDEC_SUPPORT
+    /* FIXME - we do this special case for signal handling, should see how to
+     * make it work for wide characters.
+     */
+    if (SP->_outch != 0) {
+	SP->_outch(UChar(ch));
+    } else
+#endif
+    {
+	PUTC(CHDEREF(ch), SP->_ofp);	/* macro's fastest... */
+	COUNT_OUTCHARS(1);
+    }
+    SP->_curscol += chlen;
+    if (char_padding) {
+	TPUTS_TRACE("char_padding");
+	putp(char_padding);
+    }
+}
+
+static bool
+check_pending(void)
+/* check for pending input */
+{
+    bool have_pending = FALSE;
+
+    /*
+     * Only carry out this check when the flag is zero, otherwise we'll
+     * have the refreshing slow down drastically (or stop) if there's an
+     * unread character available.
+     */
+    if (SP->_fifohold != 0)
+	return FALSE;
+
+    if (SP->_checkfd >= 0) {
+#if USE_FUNC_POLL
+	struct pollfd fds[1];
+	fds[0].fd = SP->_checkfd;
+	fds[0].events = POLLIN;
+	if (poll(fds, 1, 0) > 0) {
+	    have_pending = TRUE;
+	}
+#elif defined(__BEOS__)
+	/*
+	 * BeOS's select() is declared in socket.h, so the configure script does
+	 * not see it.  That's just as well, since that function works only for
+	 * sockets.  This (using snooze and ioctl) was distilled from Be's patch
+	 * for ncurses which uses a separate thread to simulate select().
+	 *
+	 * FIXME: the return values from the ioctl aren't very clear if we get
+	 * interrupted.
+	 */
+	int n = 0;
+	int howmany = ioctl(0, 'ichr', &n);
+	if (howmany >= 0 && n > 0) {
+	    have_pending = TRUE;
+	}
+#elif HAVE_SELECT
+	fd_set fdset;
+	struct timeval ktimeout;
+
+	ktimeout.tv_sec =
+	    ktimeout.tv_usec = 0;
+
+	FD_ZERO(&fdset);
+	FD_SET(SP->_checkfd, &fdset);
+	if (select(SP->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) {
+	    have_pending = TRUE;
+	}
+#endif
+    }
+    if (have_pending) {
+	SP->_fifohold = 5;
+	_nc_flush();
+    }
+    return FALSE;
+}
+
+/* put char at lower right corner */
+static void
+PutCharLR(const ARG_CH_T ch)
+{
+    if (!auto_right_margin) {
+	/* we can put the char directly */
+	PutAttrChar(ch);
+    } else if (enter_am_mode && exit_am_mode) {
+	/* we can suppress automargin */
+	TPUTS_TRACE("exit_am_mode");
+	putp(exit_am_mode);
+
+	PutAttrChar(ch);
+	SP->_curscol--;
+	position_check(SP->_cursrow, SP->_curscol, "exit_am_mode");
+
+	TPUTS_TRACE("enter_am_mode");
+	putp(enter_am_mode);
+    } else if ((enter_insert_mode && exit_insert_mode)
+	       || insert_character || parm_ich) {
+	GoTo(screen_lines - 1, screen_columns - 2);
+	PutAttrChar(ch);
+	GoTo(screen_lines - 1, screen_columns - 2);
+	InsStr(newscr->_line[screen_lines - 1].text + screen_columns - 2, 1);
+    }
+}
+
+/*
+ * Wrap the cursor position, i.e., advance to the beginning of the next line.
+ */
+static void
+wrap_cursor(void)
+{
+    if (eat_newline_glitch) {
+	/*
+	 * xenl can manifest two different ways.  The vt100 way is that, when
+	 * you'd expect the cursor to wrap, it stays hung at the right margin
+	 * (on top of the character just emitted) and doesn't wrap until the
+	 * *next* graphic char is emitted.  The c100 way is to ignore LF
+	 * received just after an am wrap.
+	 *
+	 * An aggressive way to handle this would be to emit CR/LF after the
+	 * char and then assume the wrap is done, you're on the first position
+	 * of the next line, and the terminal out of its weird state.  Here
+	 * it's safe to just tell the code that the cursor is in hyperspace and
+	 * let the next mvcur() call straighten things out.
+	 */
+	SP->_curscol = -1;
+	SP->_cursrow = -1;
+    } else if (auto_right_margin) {
+	SP->_curscol = 0;
+	SP->_cursrow++;
+	/*
+	 * We've actually moved - but may have to work around problems with
+	 * video attributes not working.
+	 */
+	if (!move_standout_mode && AttrOf(SCREEN_ATTRS(SP))) {
+	    TR(TRACE_CHARPUT, ("turning off (%#lx) %s before wrapping",
+			       (unsigned long) AttrOf(SCREEN_ATTRS(SP)),
+			       _traceattr(AttrOf(SCREEN_ATTRS(SP)))));
+	    (void) VIDATTR(A_NORMAL, 0);
+	}
+    } else {
+	SP->_curscol--;
+    }
+    position_check(SP->_cursrow, SP->_curscol, "wrap_cursor");
+}
+
+static NCURSES_INLINE void
+PutChar(const ARG_CH_T ch)
+/* insert character, handling automargin stuff */
+{
+    if (SP->_cursrow == screen_lines - 1 && SP->_curscol == screen_columns - 1)
+	PutCharLR(ch);
+    else
+	PutAttrChar(ch);
+
+    if (SP->_curscol >= screen_columns)
+	wrap_cursor();
+
+    position_check(SP->_cursrow, SP->_curscol, "PutChar");
+}
+
+/*
+ * Check whether the given character can be output by clearing commands.  This
+ * includes test for being a space and not including any 'bad' attributes, such
+ * as A_REVERSE.  All attribute flags which don't affect appearance of a space
+ * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
+ */
+static NCURSES_INLINE bool
+can_clear_with(ARG_CH_T ch)
+{
+    if (!back_color_erase && SP->_coloron) {
+#if NCURSES_EXT_FUNCS
+	int pair;
+
+	if (!SP->_default_color)
+	    return FALSE;
+	if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK)
+	    return FALSE;
+	if ((pair = GetPair(CHDEREF(ch))) != 0) {
+	    short fg, bg;
+	    pair_content(pair, &fg, &bg);
+	    if (fg != C_MASK || bg != C_MASK)
+		return FALSE;
+	}
+#else
+	if (AttrOfD(ch) & A_COLOR)
+	    return FALSE;
+#endif
+    }
+    return (ISBLANK(CHDEREF(ch)) &&
+	    (AttrOfD(ch) & ~(NONBLANK_ATTR | A_COLOR)) == BLANK_ATTR);
+}
+
+/*
+ * Issue a given span of characters from an array.
+ * Must be functionally equivalent to:
+ *	for (i = 0; i < num; i++)
+ *	    PutChar(ntext[i]);
+ * but can leave the cursor positioned at the middle of the interval.
+ *
+ * Returns: 0 - cursor is at the end of interval
+ *	    1 - cursor is somewhere in the middle
+ *
+ * This code is optimized using ech and rep.
+ */
+static int
+EmitRange(const NCURSES_CH_T * ntext, int num)
+{
+    int i;
+
+    TR(TRACE_CHARPUT, ("EmitRange %d:%s", num, _nc_viscbuf(ntext, num)));
+
+    if (erase_chars || repeat_char) {
+	while (num > 0) {
+	    int runcount;
+	    NCURSES_CH_T ntext0;
+
+	    while (num > 1 && !CharEq(ntext[0], ntext[1])) {
+		PutChar(CHREF(ntext[0]));
+		ntext++;
+		num--;
+	    }
+	    ntext0 = ntext[0];
+	    if (num == 1) {
+		PutChar(CHREF(ntext0));
+		return 0;
+	    }
+	    runcount = 2;
+
+	    while (runcount < num && CharEq(ntext[runcount], ntext0))
+		runcount++;
+
+	    /*
+	     * The cost expression in the middle isn't exactly right.
+	     * _cup_ch_cost is an upper bound on the cost for moving to the
+	     * end of the erased area, but not the cost itself (which we
+	     * can't compute without emitting the move).  This may result
+	     * in erase_chars not getting used in some situations for
+	     * which it would be marginally advantageous.
+	     */
+	    if (erase_chars
+		&& runcount > SP->_ech_cost + SP->_cup_ch_cost
+		&& can_clear_with(CHREF(ntext0))) {
+		UpdateAttrs(ntext0);
+		putp(TPARM_1(erase_chars, runcount));
+
+		/*
+		 * If this is the last part of the given interval,
+		 * don't bother moving cursor, since it can be the
+		 * last update on the line.
+		 */
+		if (runcount < num) {
+		    GoTo(SP->_cursrow, SP->_curscol + runcount);
+		} else {
+		    return 1;	/* cursor stays in the middle */
+		}
+	    } else if (repeat_char && runcount > SP->_rep_cost) {
+		bool wrap_possible = (SP->_curscol + runcount >= screen_columns);
+		int rep_count = runcount;
+
+		if (wrap_possible)
+		    rep_count--;
+
+		UpdateAttrs(ntext0);
+		tputs(TPARM_2(repeat_char, CharOf(ntext0), rep_count),
+		      rep_count, _nc_outch);
+		SP->_curscol += rep_count;
+
+		if (wrap_possible)
+		    PutChar(CHREF(ntext0));
+	    } else {
+		for (i = 0; i < runcount; i++)
+		    PutChar(CHREF(ntext[i]));
+	    }
+	    ntext += runcount;
+	    num -= runcount;
+	}
+	return 0;
+    }
+
+    for (i = 0; i < num; i++)
+	PutChar(CHREF(ntext[i]));
+    return 0;
+}
+
+/*
+ * Output the line in the given range [first .. last]
+ *
+ * If there's a run of identical characters that's long enough to justify
+ * cursor movement, use that also.
+ *
+ * Returns: same as EmitRange
+ */
+static int
+PutRange(const NCURSES_CH_T * otext,
+	 const NCURSES_CH_T * ntext,
+	 int row,
+	 int first, int last)
+{
+    int i, j, same;
+
+    TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)",
+		       otext, ntext, row, first, last));
+
+    if (otext != ntext
+	&& (last - first + 1) > SP->_inline_cost) {
+	for (j = first, same = 0; j <= last; j++) {
+	    if (!same && isWidecExt(otext[j]))
+		continue;
+	    if (CharEq(otext[j], ntext[j])) {
+		same++;
+	    } else {
+		if (same > SP->_inline_cost) {
+		    EmitRange(ntext + first, j - same - first);
+		    GoTo(row, first = j);
+		}
+		same = 0;
+	    }
+	}
+	i = EmitRange(ntext + first, j - same - first);
+	/*
+	 * Always return 1 for the next GoTo() after a PutRange() if we found
+	 * identical characters at end of interval
+	 */
+	return (same == 0 ? i : 1);
+    }
+    return EmitRange(ntext + first, last - first + 1);
+}
+
+/* leave unbracketed here so 'indent' works */
+#define MARK_NOCHANGE(win,row) \
+		win->_line[row].firstchar = _NOCHANGE; \
+		win->_line[row].lastchar = _NOCHANGE; \
+		if_USE_SCROLL_HINTS(win->_line[row].oldindex = row)
+
+NCURSES_EXPORT(int)
+doupdate(void)
+{
+    int i;
+    int nonempty;
+#if USE_TRACE_TIMES
+    struct tms before, after;
+#endif /* USE_TRACE_TIMES */
+
+    T((T_CALLED("doupdate()")));
+
+    if (curscr == 0
+	|| newscr == 0)
+	returnCode(ERR);
+
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_UPDATE)) {
+	if (curscr->_clear)
+	    _tracef("curscr is clear");
+	else
+	    _tracedump("curscr", curscr);
+	_tracedump("newscr", newscr);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
+    _nc_signal_handler(FALSE);
+
+    if (SP->_fifohold)
+	SP->_fifohold--;
+
+#if USE_SIZECHANGE
+    if (SP->_endwin || _nc_handle_sigwinch(SP)) {
+	/*
+	 * This is a transparent extension:  XSI does not address it,
+	 * and applications need not know that ncurses can do it.
+	 *
+	 * Check if the terminal size has changed while curses was off
+	 * (this can happen in an xterm, for example), and resize the
+	 * ncurses data structures accordingly.
+	 */
+	_nc_update_screensize(SP);
+    }
+#endif
+
+    if (SP->_endwin) {
+
+	T(("coming back from shell mode"));
+	reset_prog_mode();
+
+	_nc_mvcur_resume();
+	_nc_screen_resume();
+	SP->_mouse_resume(SP);
+
+	SP->_endwin = FALSE;
+    }
+#if USE_TRACE_TIMES
+    /* zero the metering machinery */
+    RESET_OUTCHARS();
+    (void) times(&before);
+#endif /* USE_TRACE_TIMES */
+
+    /*
+     * This is the support for magic-cookie terminals.  The theory:  we scan
+     * the virtual screen looking for attribute turnons.  Where we find one,
+     * check to make sure it's realizable by seeing if the required number of
+     * un-attributed blanks are present before and after the attributed range;
+     * try to shift the range boundaries over blanks (not changing the screen
+     * display) so this becomes true.  If it is, shift the beginning attribute
+     * change appropriately (the end one, if we've gotten this far, is
+     * guaranteed room for its cookie).  If not, nuke the added attributes out
+     * of the span.
+     */
+#if USE_XMC_SUPPORT
+    if (magic_cookie_glitch > 0) {
+	int j, k;
+	attr_t rattr = A_NORMAL;
+
+	for (i = 0; i < screen_lines; i++) {
+	    for (j = 0; j < screen_columns; j++) {
+		bool failed = FALSE;
+		NCURSES_CH_T *thisline = newscr->_line[i].text;
+		attr_t thisattr = AttrOf(thisline[j]) & SP->_xmc_triggers;
+		attr_t turnon = thisattr & ~rattr;
+
+		/* is an attribute turned on here? */
+		if (turnon == 0) {
+		    rattr = thisattr;
+		    continue;
+		}
+
+		TR(TRACE_ATTRS, ("At (%d, %d): from %s...", i, j, _traceattr(rattr)));
+		TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon)));
+
+		/*
+		 * If the attribute change location is a blank with a "safe"
+		 * attribute, undo the attribute turnon.  This may ensure
+		 * there's enough room to set the attribute before the first
+		 * non-blank in the run.
+		 */
+#define SAFE(a)	(!((a) & SP->_xmc_triggers))
+		if (ISBLANK(thisline[j]) && SAFE(turnon)) {
+		    RemAttr(thisline[j], turnon);
+		    continue;
+		}
+
+		/* check that there's enough room at start of span */
+		for (k = 1; k <= magic_cookie_glitch; k++) {
+		    if (j - k < 0
+			|| !ISBLANK(thisline[j - k])
+			|| !SAFE(AttrOf(thisline[j - k]))) {
+			failed = TRUE;
+			TR(TRACE_ATTRS, ("No room at start in %d,%d%s%s",
+					 i, j - k,
+					 (ISBLANK(thisline[j - k])
+					  ? ""
+					  : ":nonblank"),
+					 (SAFE(AttrOf(thisline[j - k]))
+					  ? ""
+					  : ":unsafe")));
+			break;
+		    }
+		}
+		if (!failed) {
+		    bool end_onscreen = FALSE;
+		    int m, n = j;
+
+		    /* find end of span, if it's onscreen */
+		    for (m = i; m < screen_lines; m++) {
+			for (; n < screen_columns; n++) {
+			    attr_t testattr = AttrOf(newscr->_line[m].text[n]);
+			    if ((testattr & SP->_xmc_triggers) == rattr) {
+				end_onscreen = TRUE;
+				TR(TRACE_ATTRS,
+				   ("Range attributed with %s ends at (%d, %d)",
+				    _traceattr(turnon), m, n));
+				goto foundit;
+			    }
+			}
+			n = 0;
+		    }
+		    TR(TRACE_ATTRS,
+		       ("Range attributed with %s ends offscreen",
+			_traceattr(turnon)));
+		  foundit:;
+
+		    if (end_onscreen) {
+			NCURSES_CH_T *lastline = newscr->_line[m].text;
+
+			/*
+			 * If there are safely-attributed blanks at the end of
+			 * the range, shorten the range.  This will help ensure
+			 * that there is enough room at end of span.
+			 */
+			while (n >= 0
+			       && ISBLANK(lastline[n])
+			       && SAFE(AttrOf(lastline[n]))) {
+			    RemAttr(lastline[n--], turnon);
+			}
+
+			/* check that there's enough room at end of span */
+			for (k = 1; k <= magic_cookie_glitch; k++) {
+			    if (n + k >= screen_columns
+				|| !ISBLANK(lastline[n + k])
+				|| !SAFE(AttrOf(lastline[n + k]))) {
+				failed = TRUE;
+				TR(TRACE_ATTRS,
+				   ("No room at end in %d,%d%s%s",
+				    i, j - k,
+				    (ISBLANK(lastline[n + k])
+				     ? ""
+				     : ":nonblank"),
+				    (SAFE(AttrOf(lastline[n + k]))
+				     ? ""
+				     : ":unsafe")));
+				break;
+			    }
+			}
+		    }
+		}
+
+		if (failed) {
+		    int p, q = j;
+
+		    TR(TRACE_ATTRS,
+		       ("Clearing %s beginning at (%d, %d)",
+			_traceattr(turnon), i, j));
+
+		    /* turn off new attributes over span */
+		    for (p = i; p < screen_lines; p++) {
+			for (; q < screen_columns; q++) {
+			    attr_t testattr = AttrOf(newscr->_line[p].text[q]);
+			    if ((testattr & SP->_xmc_triggers) == rattr)
+				goto foundend;
+			    RemAttr(newscr->_line[p].text[q], turnon);
+			}
+			q = 0;
+		    }
+		  foundend:;
+		} else {
+		    TR(TRACE_ATTRS,
+		       ("Cookie space for %s found before (%d, %d)",
+			_traceattr(turnon), i, j));
+
+		    /*
+		     * Back up the start of range so there's room for cookies
+		     * before the first nonblank character.
+		     */
+		    for (k = 1; k <= magic_cookie_glitch; k++)
+			AddAttr(thisline[j - k], turnon);
+		}
+
+		rattr = thisattr;
+	    }
+	}
+
+#ifdef TRACE
+	/* show altered highlights after magic-cookie check */
+	if (USE_TRACEF(TRACE_UPDATE)) {
+	    _tracef("After magic-cookie check...");
+	    _tracedump("newscr", newscr);
+	    _nc_unlock_global(tracef);
+	}
+#endif /* TRACE */
+    }
+#endif /* USE_XMC_SUPPORT */
+
+    nonempty = 0;
+    if (curscr->_clear || newscr->_clear) {	/* force refresh ? */
+	ClrUpdate();
+	curscr->_clear = FALSE;	/* reset flag */
+	newscr->_clear = FALSE;	/* reset flag */
+    } else {
+	int changedlines = CHECK_INTERVAL;
+
+	if (check_pending())
+	    goto cleanup;
+
+	nonempty = min(screen_lines, newscr->_maxy + 1);
+
+	if (SP->_scrolling) {
+	    _nc_scroll_optimize();
+	}
+
+	nonempty = ClrBottom(nonempty);
+
+	TR(TRACE_UPDATE, ("Transforming lines, nonempty %d", nonempty));
+	for (i = 0; i < nonempty; i++) {
+	    /*
+	     * Here is our line-breakout optimization.
+	     */
+	    if (changedlines == CHECK_INTERVAL) {
+		if (check_pending())
+		    goto cleanup;
+		changedlines = 0;
+	    }
+
+	    /*
+	     * newscr->line[i].firstchar is normally set
+	     * by wnoutrefresh.  curscr->line[i].firstchar
+	     * is normally set by _nc_scroll_window in the
+	     * vertical-movement optimization code,
+	     */
+	    if (newscr->_line[i].firstchar != _NOCHANGE
+		|| curscr->_line[i].firstchar != _NOCHANGE) {
+		TransformLine(i);
+		changedlines++;
+	    }
+
+	    /* mark line changed successfully */
+	    if (i <= newscr->_maxy) {
+		MARK_NOCHANGE(newscr, i);
+	    }
+	    if (i <= curscr->_maxy) {
+		MARK_NOCHANGE(curscr, i);
+	    }
+	}
+    }
+
+    /* put everything back in sync */
+    for (i = nonempty; i <= newscr->_maxy; i++) {
+	MARK_NOCHANGE(newscr, i);
+    }
+    for (i = nonempty; i <= curscr->_maxy; i++) {
+	MARK_NOCHANGE(curscr, i);
+    }
+
+    if (!newscr->_leaveok) {
+	curscr->_curx = newscr->_curx;
+	curscr->_cury = newscr->_cury;
+
+	GoTo(curscr->_cury, curscr->_curx);
+    }
+
+  cleanup:
+    /*
+     * We would like to keep the physical screen in normal mode in case we get
+     * other processes writing to the screen.  This goal cannot be met for
+     * magic cookies since it interferes with attributes that may propagate
+     * past the current position.
+     */
+#if USE_XMC_SUPPORT
+    if (magic_cookie_glitch != 0)
+#endif
+	UpdateAttrs(normal);
+
+    _nc_flush();
+    WINDOW_ATTRS(curscr) = WINDOW_ATTRS(newscr);
+
+#if USE_TRACE_TIMES
+    (void) times(&after);
+    TR(TRACE_TIMES,
+       ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time",
+	_nc_outchars,
+	(long) (after.tms_stime - before.tms_stime),
+	(long) (after.tms_utime - before.tms_utime)));
+#endif /* USE_TRACE_TIMES */
+
+    _nc_signal_handler(TRUE);
+
+    returnCode(OK);
+}
+
+/*
+ *	ClrBlank(win)
+ *
+ *	Returns the attributed character that corresponds to the "cleared"
+ *	screen.  If the terminal has the back-color-erase feature, this will be
+ *	colored according to the wbkgd() call.
+ *
+ *	We treat 'curscr' specially because it isn't supposed to be set directly
+ *	in the wbkgd() call.  Assume 'stdscr' for this case.
+ */
+#define BCE_ATTRS (A_NORMAL|A_COLOR)
+#define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_nc_bkgd)
+
+static NCURSES_INLINE NCURSES_CH_T
+ClrBlank(WINDOW *win)
+{
+    NCURSES_CH_T blank = blankchar;
+    if (back_color_erase)
+	AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS));
+    return blank;
+}
+
+/*
+**	ClrUpdate()
+**
+**	Update by clearing and redrawing the entire screen.
+**
+*/
+
+static void
+ClrUpdate(void)
+{
+    int i;
+    NCURSES_CH_T blank = ClrBlank(stdscr);
+    int nonempty = min(screen_lines, newscr->_maxy + 1);
+
+    TR(TRACE_UPDATE, (T_CALLED("ClrUpdate")));
+
+    ClearScreen(blank);
+
+    TR(TRACE_UPDATE, ("updating screen from scratch"));
+
+    nonempty = ClrBottom(nonempty);
+
+    for (i = 0; i < nonempty; i++)
+	TransformLine(i);
+
+    TR(TRACE_UPDATE, (T_RETURN("")));
+}
+
+/*
+**	ClrToEOL(blank)
+**
+**	Clear to end of current line, starting at the cursor position
+*/
+
+static void
+ClrToEOL(NCURSES_CH_T blank, bool needclear)
+{
+    int j;
+
+    if (curscr != 0
+	&& SP->_cursrow >= 0) {
+	for (j = SP->_curscol; j < screen_columns; j++) {
+	    if (j >= 0) {
+		NCURSES_CH_T *cp = &(curscr->_line[SP->_cursrow].text[j]);
+
+		if (!CharEq(*cp, blank)) {
+		    *cp = blank;
+		    needclear = TRUE;
+		}
+	    }
+	}
+    } else {
+	needclear = TRUE;
+    }
+
+    if (needclear) {
+	UpdateAttrs(blank);
+	TPUTS_TRACE("clr_eol");
+	if (clr_eol && SP->_el_cost <= (screen_columns - SP->_curscol)) {
+	    putp(clr_eol);
+	} else {
+	    int count = (screen_columns - SP->_curscol);
+	    while (count-- > 0)
+		PutChar(CHREF(blank));
+	}
+    }
+}
+
+/*
+**	ClrToEOS(blank)
+**
+**	Clear to end of screen, starting at the cursor position
+*/
+
+static void
+ClrToEOS(NCURSES_CH_T blank)
+{
+    int row, col;
+
+    row = SP->_cursrow;
+    col = SP->_curscol;
+
+    UpdateAttrs(blank);
+    TPUTS_TRACE("clr_eos");
+    tputs(clr_eos, screen_lines - row, _nc_outch);
+
+    while (col < screen_columns)
+	curscr->_line[row].text[col++] = blank;
+
+    for (row++; row < screen_lines; row++) {
+	for (col = 0; col < screen_columns; col++)
+	    curscr->_line[row].text[col] = blank;
+    }
+}
+
+/*
+ *	ClrBottom(total)
+ *
+ *	Test if clearing the end of the screen would satisfy part of the
+ *	screen-update.  Do this by scanning backwards through the lines in the
+ *	screen, checking if each is blank, and one or more are changed.
+ */
+static int
+ClrBottom(int total)
+{
+    int row;
+    int col;
+    int top = total;
+    int last = min(screen_columns, newscr->_maxx + 1);
+    NCURSES_CH_T blank = newscr->_line[total - 1].text[last - 1];
+    bool ok;
+
+    if (clr_eos && can_clear_with(CHREF(blank))) {
+
+	for (row = total - 1; row >= 0; row--) {
+	    for (col = 0, ok = TRUE; ok && col < last; col++) {
+		ok = (CharEq(newscr->_line[row].text[col], blank));
+	    }
+	    if (!ok)
+		break;
+
+	    for (col = 0; ok && col < last; col++) {
+		ok = (CharEq(curscr->_line[row].text[col], blank));
+	    }
+	    if (!ok)
+		top = row;
+	}
+
+	/* don't use clr_eos for just one line if clr_eol available */
+	if (top < total) {
+	    GoTo(top, 0);
+	    ClrToEOS(blank);
+	    if (SP->oldhash && SP->newhash) {
+		for (row = top; row < screen_lines; row++)
+		    SP->oldhash[row] = SP->newhash[row];
+	    }
+	}
+    }
+    return top;
+}
+
+#if USE_XMC_SUPPORT
+#if USE_WIDEC_SUPPORT
+#define check_xmc_transition(a, b) \
+    ((((a)->attr ^ (b)->attr) & ~((a)->attr) & SP->_xmc_triggers) != 0)
+#define xmc_turn_on(a,b) check_xmc_transition(&(a), &(b))
+#else
+#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0)
+#endif
+
+#define xmc_new(r,c) newscr->_line[r].text[c]
+#define xmc_turn_off(a,b) xmc_turn_on(b,a)
+#endif /* USE_XMC_SUPPORT */
+
+/*
+**	TransformLine(lineno)
+**
+**	Transform the given line in curscr to the one in newscr, using
+**	Insert/Delete Character if _nc_idcok && has_ic().
+**
+**		firstChar = position of first different character in line
+**		oLastChar = position of last different character in old line
+**		nLastChar = position of last different character in new line
+**
+**		move to firstChar
+**		overwrite chars up to min(oLastChar, nLastChar)
+**		if oLastChar < nLastChar
+**			insert newLine[oLastChar+1..nLastChar]
+**		else
+**			delete oLastChar - nLastChar spaces
+*/
+
+static void
+TransformLine(int const lineno)
+{
+    int firstChar, oLastChar, nLastChar;
+    NCURSES_CH_T *newLine = newscr->_line[lineno].text;
+    NCURSES_CH_T *oldLine = curscr->_line[lineno].text;
+    int n;
+    bool attrchanged = FALSE;
+
+    TR(TRACE_UPDATE, (T_CALLED("TransformLine(%d)"), lineno));
+
+    /* copy new hash value to old one */
+    if (SP->oldhash && SP->newhash)
+	SP->oldhash[lineno] = SP->newhash[lineno];
+
+    /*
+     * If we have colors, there is the possibility of having two color pairs
+     * that display as the same colors.  For instance, Lynx does this.  Check
+     * for this case, and update the old line with the new line's colors when
+     * they are equivalent.
+     */
+    if (SP->_coloron) {
+	int oldPair;
+	int newPair;
+
+	for (n = 0; n < screen_columns; n++) {
+	    if (!CharEq(newLine[n], oldLine[n])) {
+		oldPair = GetPair(oldLine[n]);
+		newPair = GetPair(newLine[n]);
+		if (oldPair != newPair
+		    && unColor(oldLine[n]) == unColor(newLine[n])) {
+		    if (oldPair < COLOR_PAIRS
+			&& newPair < COLOR_PAIRS
+			&& SP->_color_pairs[oldPair] == SP->_color_pairs[newPair]) {
+			SetPair(oldLine[n], GetPair(newLine[n]));
+		    }
+		}
+	    }
+	}
+    }
+
+    if (ceol_standout_glitch && clr_eol) {
+	firstChar = 0;
+	while (firstChar < screen_columns) {
+	    if (!SameAttrOf(newLine[firstChar], oldLine[firstChar])) {
+		attrchanged = TRUE;
+		break;
+	    }
+	    firstChar++;
+	}
+    }
+
+    firstChar = 0;
+
+    if (attrchanged) {		/* we may have to disregard the whole line */
+	GoTo(lineno, firstChar);
+	ClrToEOL(ClrBlank(curscr), FALSE);
+	PutRange(oldLine, newLine, lineno, 0, (screen_columns - 1));
+#if USE_XMC_SUPPORT
+
+	/*
+	 * This is a very simple loop to paint characters which may have the
+	 * magic cookie glitch embedded.  It doesn't know much about video
+	 * attributes which are continued from one line to the next.  It
+	 * assumes that we have filtered out requests for attribute changes
+	 * that do not get mapped to blank positions.
+	 *
+	 * FIXME: we are not keeping track of where we put the cookies, so this
+	 * will work properly only once, since we may overwrite a cookie in a
+	 * following operation.
+	 */
+    } else if (magic_cookie_glitch > 0) {
+	GoTo(lineno, firstChar);
+	for (n = 0; n < screen_columns; n++) {
+	    int m = n + magic_cookie_glitch;
+
+	    /* check for turn-on:
+	     * If we are writing an attributed blank, where the
+	     * previous cell is not attributed.
+	     */
+	    if (ISBLANK(newLine[n])
+		&& ((n > 0
+		     && xmc_turn_on(newLine[n - 1], newLine[n]))
+		    || (n == 0
+			&& lineno > 0
+			&& xmc_turn_on(xmc_new(lineno - 1, screen_columns - 1),
+				       newLine[n])))) {
+		n = m;
+	    }
+
+	    PutChar(CHREF(newLine[n]));
+
+	    /* check for turn-off:
+	     * If we are writing an attributed non-blank, where the
+	     * next cell is blank, and not attributed.
+	     */
+	    if (!ISBLANK(newLine[n])
+		&& ((n + 1 < screen_columns
+		     && xmc_turn_off(newLine[n], newLine[n + 1]))
+		    || (n + 1 >= screen_columns
+			&& lineno + 1 < screen_lines
+			&& xmc_turn_off(newLine[n], xmc_new(lineno + 1, 0))))) {
+		n = m;
+	    }
+
+	}
+#endif
+    } else {
+	NCURSES_CH_T blank;
+
+	/* it may be cheap to clear leading whitespace with clr_bol */
+	blank = newLine[0];
+	if (clr_bol && can_clear_with(CHREF(blank))) {
+	    int oFirstChar, nFirstChar;
+
+	    for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++)
+		if (!CharEq(oldLine[oFirstChar], blank))
+		    break;
+	    for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++)
+		if (!CharEq(newLine[nFirstChar], blank))
+		    break;
+
+	    if (nFirstChar == oFirstChar) {
+		firstChar = nFirstChar;
+		/* find the first differing character */
+		while (firstChar < screen_columns
+		       && CharEq(newLine[firstChar], oldLine[firstChar]))
+		    firstChar++;
+	    } else if (oFirstChar > nFirstChar) {
+		firstChar = nFirstChar;
+	    } else {		/* oFirstChar < nFirstChar */
+		firstChar = oFirstChar;
+		if (SP->_el1_cost < nFirstChar - oFirstChar) {
+		    if (nFirstChar >= screen_columns
+			&& SP->_el_cost <= SP->_el1_cost) {
+			GoTo(lineno, 0);
+			UpdateAttrs(blank);
+			TPUTS_TRACE("clr_eol");
+			putp(clr_eol);
+		    } else {
+			GoTo(lineno, nFirstChar - 1);
+			UpdateAttrs(blank);
+			TPUTS_TRACE("clr_bol");
+			putp(clr_bol);
+		    }
+
+		    while (firstChar < nFirstChar)
+			oldLine[firstChar++] = blank;
+		}
+	    }
+	} else {
+	    /* find the first differing character */
+	    while (firstChar < screen_columns
+		   && CharEq(newLine[firstChar], oldLine[firstChar]))
+		firstChar++;
+	}
+	/* if there wasn't one, we're done */
+	if (firstChar >= screen_columns) {
+	    TR(TRACE_UPDATE, (T_RETURN("")));
+	    return;
+	}
+
+	blank = newLine[screen_columns - 1];
+
+	if (!can_clear_with(CHREF(blank))) {
+	    /* find the last differing character */
+	    nLastChar = screen_columns - 1;
+
+	    while (nLastChar > firstChar
+		   && CharEq(newLine[nLastChar], oldLine[nLastChar]))
+		nLastChar--;
+
+	    if (nLastChar >= firstChar) {
+		GoTo(lineno, firstChar);
+		PutRange(oldLine, newLine, lineno, firstChar, nLastChar);
+		memcpy(oldLine + firstChar,
+		       newLine + firstChar,
+		       (nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T));
+	    }
+	    TR(TRACE_UPDATE, (T_RETURN("")));
+	    return;
+	}
+
+	/* find last non-blank character on old line */
+	oLastChar = screen_columns - 1;
+	while (oLastChar > firstChar && CharEq(oldLine[oLastChar], blank))
+	    oLastChar--;
+
+	/* find last non-blank character on new line */
+	nLastChar = screen_columns - 1;
+	while (nLastChar > firstChar && CharEq(newLine[nLastChar], blank))
+	    nLastChar--;
+
+	if ((nLastChar == firstChar)
+	    && (SP->_el_cost < (oLastChar - nLastChar))) {
+	    GoTo(lineno, firstChar);
+	    if (!CharEq(newLine[firstChar], blank))
+		PutChar(CHREF(newLine[firstChar]));
+	    ClrToEOL(blank, FALSE);
+	} else if ((nLastChar != oLastChar)
+		   && (!CharEq(newLine[nLastChar], oldLine[oLastChar])
+		       || !(_nc_idcok && has_ic()))) {
+	    GoTo(lineno, firstChar);
+	    if ((oLastChar - nLastChar) > SP->_el_cost) {
+		if (PutRange(oldLine, newLine, lineno, firstChar, nLastChar))
+		    GoTo(lineno, nLastChar + 1);
+		ClrToEOL(blank, FALSE);
+	    } else {
+		n = max(nLastChar, oLastChar);
+		PutRange(oldLine, newLine, lineno, firstChar, n);
+	    }
+	} else {
+	    int nLastNonblank = nLastChar;
+	    int oLastNonblank = oLastChar;
+
+	    /* find the last characters that really differ */
+	    /* can be -1 if no characters differ */
+	    while (CharEq(newLine[nLastChar], oldLine[oLastChar])) {
+		/* don't split a wide char */
+		if (isWidecExt(newLine[nLastChar]) &&
+		    !CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1]))
+		    break;
+		nLastChar--;
+		oLastChar--;
+		if (nLastChar == -1 || oLastChar == -1)
+		    break;
+	    }
+
+	    n = min(oLastChar, nLastChar);
+	    if (n >= firstChar) {
+		GoTo(lineno, firstChar);
+		PutRange(oldLine, newLine, lineno, firstChar, n);
+	    }
+
+	    if (oLastChar < nLastChar) {
+		int m = max(nLastNonblank, oLastNonblank);
+#if USE_WIDEC_SUPPORT
+		while (isWidecExt(newLine[n + 1]) && n) {
+		    --n;
+		    --oLastChar;
+		}
+#endif
+		GoTo(lineno, n + 1);
+		if ((nLastChar < nLastNonblank)
+		    || InsCharCost(nLastChar - oLastChar) > (m - n)) {
+		    PutRange(oldLine, newLine, lineno, n + 1, m);
+		} else {
+		    InsStr(&newLine[n + 1], nLastChar - oLastChar);
+		}
+	    } else if (oLastChar > nLastChar) {
+		GoTo(lineno, n + 1);
+		if (DelCharCost(oLastChar - nLastChar)
+		    > SP->_el_cost + nLastNonblank - (n + 1)) {
+		    if (PutRange(oldLine, newLine, lineno,
+				 n + 1, nLastNonblank))
+			GoTo(lineno, nLastNonblank + 1);
+		    ClrToEOL(blank, FALSE);
+		} else {
+		    /*
+		     * The delete-char sequence will
+		     * effectively shift in blanks from the
+		     * right margin of the screen.  Ensure
+		     * that they are the right color by
+		     * setting the video attributes from
+		     * the last character on the row.
+		     */
+		    UpdateAttrs(blank);
+		    DelChar(oLastChar - nLastChar);
+		}
+	    }
+	}
+    }
+
+    /* update the code's internal representation */
+    if (screen_columns > firstChar)
+	memcpy(oldLine + firstChar,
+	       newLine + firstChar,
+	       (screen_columns - firstChar) * sizeof(NCURSES_CH_T));
+    TR(TRACE_UPDATE, (T_RETURN("")));
+    return;
+}
+
+/*
+**	ClearScreen(blank)
+**
+**	Clear the physical screen and put cursor at home
+**
+*/
+
+static void
+ClearScreen(NCURSES_CH_T blank)
+{
+    int i, j;
+    bool fast_clear = (clear_screen || clr_eos || clr_eol);
+
+    TR(TRACE_UPDATE, ("ClearScreen() called"));
+
+#if NCURSES_EXT_FUNCS
+    if (SP->_coloron
+	&& !SP->_default_color) {
+	_nc_do_color(GET_SCREEN_PAIR(SP), 0, FALSE, _nc_outch);
+	if (!back_color_erase) {
+	    fast_clear = FALSE;
+	}
+    }
+#endif
+
+    if (fast_clear) {
+	if (clear_screen) {
+	    UpdateAttrs(blank);
+	    TPUTS_TRACE("clear_screen");
+	    putp(clear_screen);
+	    SP->_cursrow = SP->_curscol = 0;
+	    position_check(SP->_cursrow, SP->_curscol, "ClearScreen");
+	} else if (clr_eos) {
+	    SP->_cursrow = SP->_curscol = -1;
+	    GoTo(0, 0);
+
+	    UpdateAttrs(blank);
+	    TPUTS_TRACE("clr_eos");
+	    tputs(clr_eos, screen_lines, _nc_outch);
+	} else if (clr_eol) {
+	    SP->_cursrow = SP->_curscol = -1;
+
+	    UpdateAttrs(blank);
+	    for (i = 0; i < screen_lines; i++) {
+		GoTo(i, 0);
+		TPUTS_TRACE("clr_eol");
+		putp(clr_eol);
+	    }
+	    GoTo(0, 0);
+	}
+    } else {
+	UpdateAttrs(blank);
+	for (i = 0; i < screen_lines; i++) {
+	    GoTo(i, 0);
+	    for (j = 0; j < screen_columns; j++)
+		PutChar(CHREF(blank));
+	}
+	GoTo(0, 0);
+    }
+
+    for (i = 0; i < screen_lines; i++) {
+	for (j = 0; j < screen_columns; j++)
+	    curscr->_line[i].text[j] = blank;
+    }
+
+    TR(TRACE_UPDATE, ("screen cleared"));
+}
+
+/*
+**	InsStr(line, count)
+**
+**	Insert the count characters pointed to by line.
+**
+*/
+
+static void
+InsStr(NCURSES_CH_T * line, int count)
+{
+    TR(TRACE_UPDATE, ("InsStr(%p,%d) called", line, count));
+
+    /* Prefer parm_ich as it has the smallest cost - no need to shift
+     * the whole line on each character. */
+    /* The order must match that of InsCharCost. */
+    if (parm_ich) {
+	TPUTS_TRACE("parm_ich");
+	tputs(TPARM_1(parm_ich, count), count, _nc_outch);
+	while (count) {
+	    PutAttrChar(CHREF(*line));
+	    line++;
+	    count--;
+	}
+    } else if (enter_insert_mode && exit_insert_mode) {
+	TPUTS_TRACE("enter_insert_mode");
+	putp(enter_insert_mode);
+	while (count) {
+	    PutAttrChar(CHREF(*line));
+	    if (insert_padding) {
+		TPUTS_TRACE("insert_padding");
+		putp(insert_padding);
+	    }
+	    line++;
+	    count--;
+	}
+	TPUTS_TRACE("exit_insert_mode");
+	putp(exit_insert_mode);
+    } else {
+	while (count) {
+	    TPUTS_TRACE("insert_character");
+	    putp(insert_character);
+	    PutAttrChar(CHREF(*line));
+	    if (insert_padding) {
+		TPUTS_TRACE("insert_padding");
+		putp(insert_padding);
+	    }
+	    line++;
+	    count--;
+	}
+    }
+    position_check(SP->_cursrow, SP->_curscol, "InsStr");
+}
+
+/*
+**	DelChar(count)
+**
+**	Delete count characters at current position
+**
+*/
+
+static void
+DelChar(int count)
+{
+    int n;
+
+    TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%ld,%ld)",
+		      count,
+		      (long) newscr->_cury,
+		      (long) newscr->_curx));
+
+    if (parm_dch) {
+	TPUTS_TRACE("parm_dch");
+	tputs(TPARM_1(parm_dch, count), count, _nc_outch);
+    } else {
+	for (n = 0; n < count; n++) {
+	    TPUTS_TRACE("delete_character");
+	    putp(delete_character);
+	}
+    }
+}
+
+/*
+ * Physical-scrolling support
+ *
+ * This code was adapted from Keith Bostic's hardware scrolling
+ * support for 4.4BSD curses.  I (esr) translated it to use terminfo
+ * capabilities, narrowed the call interface slightly, and cleaned
+ * up some convoluted tests.  I also added support for the memory_above
+ * memory_below, and non_dest_scroll_region capabilities.
+ *
+ * For this code to work, we must have either
+ * change_scroll_region and scroll forward/reverse commands, or
+ * insert and delete line capabilities.
+ * When the scrolling region has been set, the cursor has to
+ * be at the last line of the region to make the scroll up
+ * happen, or on the first line of region to scroll down.
+ *
+ * This code makes one aesthetic decision in the opposite way from
+ * BSD curses.  BSD curses preferred pairs of il/dl operations
+ * over scrolls, allegedly because il/dl looked faster.  We, on
+ * the other hand, prefer scrolls because (a) they're just as fast
+ * on many terminals and (b) using them avoids bouncing an
+ * unchanged bottom section of the screen up and down, which is
+ * visually nasty.
+ *
+ * (lav): added more cases, used dl/il when bot==maxy and in csr case.
+ *
+ * I used assumption that capabilities il/il1/dl/dl1 work inside
+ * changed scroll region not shifting screen contents outside of it.
+ * If there are any terminals behaving different way, it would be
+ * necessary to add some conditions to scroll_csr_forward/backward.
+ */
+
+/* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */
+static int
+scroll_csr_forward(int n, int top, int bot, int miny, int maxy, NCURSES_CH_T blank)
+{
+    int i;
+
+    if (n == 1 && scroll_forward && top == miny && bot == maxy) {
+	GoTo(bot, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("scroll_forward");
+	putp(scroll_forward);
+    } else if (n == 1 && delete_line && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("delete_line");
+	putp(delete_line);
+    } else if (parm_index && top == miny && bot == maxy) {
+	GoTo(bot, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("parm_index");
+	tputs(TPARM_2(parm_index, n, 0), n, _nc_outch);
+    } else if (parm_delete_line && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("parm_delete_line");
+	tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch);
+    } else if (scroll_forward && top == miny && bot == maxy) {
+	GoTo(bot, 0);
+	UpdateAttrs(blank);
+	for (i = 0; i < n; i++) {
+	    TPUTS_TRACE("scroll_forward");
+	    putp(scroll_forward);
+	}
+    } else if (delete_line && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	for (i = 0; i < n; i++) {
+	    TPUTS_TRACE("delete_line");
+	    putp(delete_line);
+	}
+    } else
+	return ERR;
+
+#if NCURSES_EXT_FUNCS
+    if (FILL_BCE()) {
+	int j;
+	for (i = 0; i < n; i++) {
+	    GoTo(bot - i, 0);
+	    for (j = 0; j < screen_columns; j++)
+		PutChar(CHREF(blank));
+	}
+    }
+#endif
+    return OK;
+}
+
+/* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */
+/* n > 0 */
+static int
+scroll_csr_backward(int n, int top, int bot, int miny, int maxy,
+		    NCURSES_CH_T blank)
+{
+    int i;
+
+    if (n == 1 && scroll_reverse && top == miny && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("scroll_reverse");
+	putp(scroll_reverse);
+    } else if (n == 1 && insert_line && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("insert_line");
+	putp(insert_line);
+    } else if (parm_rindex && top == miny && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("parm_rindex");
+	tputs(TPARM_2(parm_rindex, n, 0), n, _nc_outch);
+    } else if (parm_insert_line && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	TPUTS_TRACE("parm_insert_line");
+	tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch);
+    } else if (scroll_reverse && top == miny && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	for (i = 0; i < n; i++) {
+	    TPUTS_TRACE("scroll_reverse");
+	    putp(scroll_reverse);
+	}
+    } else if (insert_line && bot == maxy) {
+	GoTo(top, 0);
+	UpdateAttrs(blank);
+	for (i = 0; i < n; i++) {
+	    TPUTS_TRACE("insert_line");
+	    putp(insert_line);
+	}
+    } else
+	return ERR;
+
+#if NCURSES_EXT_FUNCS
+    if (FILL_BCE()) {
+	int j;
+	for (i = 0; i < n; i++) {
+	    GoTo(top + i, 0);
+	    for (j = 0; j < screen_columns; j++)
+		PutChar(CHREF(blank));
+	}
+    }
+#endif
+    return OK;
+}
+
+/* scroll by using delete_line at del and insert_line at ins */
+/* n > 0 */
+static int
+scroll_idl(int n, int del, int ins, NCURSES_CH_T blank)
+{
+    int i;
+
+    if (!((parm_delete_line || delete_line) && (parm_insert_line || insert_line)))
+	return ERR;
+
+    GoTo(del, 0);
+    UpdateAttrs(blank);
+    if (n == 1 && delete_line) {
+	TPUTS_TRACE("delete_line");
+	putp(delete_line);
+    } else if (parm_delete_line) {
+	TPUTS_TRACE("parm_delete_line");
+	tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch);
+    } else {			/* if (delete_line) */
+	for (i = 0; i < n; i++) {
+	    TPUTS_TRACE("delete_line");
+	    putp(delete_line);
+	}
+    }
+
+    GoTo(ins, 0);
+    UpdateAttrs(blank);
+    if (n == 1 && insert_line) {
+	TPUTS_TRACE("insert_line");
+	putp(insert_line);
+    } else if (parm_insert_line) {
+	TPUTS_TRACE("parm_insert_line");
+	tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch);
+    } else {			/* if (insert_line) */
+	for (i = 0; i < n; i++) {
+	    TPUTS_TRACE("insert_line");
+	    putp(insert_line);
+	}
+    }
+
+    return OK;
+}
+
+/*
+ * Note:  some terminals require the cursor to be within the scrolling margins
+ * before setting them.  Generally, the cursor must be at the appropriate end
+ * of the scrolling margins when issuing an indexing operation (it is not
+ * apparent whether it must also be at the left margin; we do this just to be
+ * safe).  To make the related cursor movement a little faster, we use the
+ * save/restore cursor capabilities if the terminal has them.
+ */
+NCURSES_EXPORT(int)
+_nc_scrolln(int n, int top, int bot, int maxy)
+/* scroll region from top to bot by n lines */
+{
+    NCURSES_CH_T blank = ClrBlank(stdscr);
+    int i;
+    bool cursor_saved = FALSE;
+    int res;
+
+    TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy));
+
+#if USE_XMC_SUPPORT
+    /*
+     * If we scroll, we might remove a cookie.
+     */
+    if (magic_cookie_glitch > 0) {
+	return (ERR);
+    }
+#endif
+
+    if (n > 0) {		/* scroll up (forward) */
+	/*
+	 * Explicitly clear if stuff pushed off top of region might
+	 * be saved by the terminal.
+	 */
+	res = scroll_csr_forward(n, top, bot, 0, maxy, blank);
+
+	if (res == ERR && change_scroll_region) {
+	    if ((((n == 1 && scroll_forward) || parm_index)
+		 && (SP->_cursrow == bot || SP->_cursrow == bot - 1))
+		&& save_cursor && restore_cursor) {
+		cursor_saved = TRUE;
+		TPUTS_TRACE("save_cursor");
+		putp(save_cursor);
+	    }
+	    TPUTS_TRACE("change_scroll_region");
+	    putp(TPARM_2(change_scroll_region, top, bot));
+	    if (cursor_saved) {
+		TPUTS_TRACE("restore_cursor");
+		putp(restore_cursor);
+	    } else {
+		SP->_cursrow = SP->_curscol = -1;
+	    }
+
+	    res = scroll_csr_forward(n, top, bot, top, bot, blank);
+
+	    TPUTS_TRACE("change_scroll_region");
+	    putp(TPARM_2(change_scroll_region, 0, maxy));
+	    SP->_cursrow = SP->_curscol = -1;
+	}
+
+	if (res == ERR && _nc_idlok)
+	    res = scroll_idl(n, top, bot - n + 1, blank);
+
+	/*
+	 * Clear the newly shifted-in text.
+	 */
+	if (res != ERR
+	    && (non_dest_scroll_region || (memory_below && bot == maxy))) {
+	    static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
+	    if (bot == maxy && clr_eos) {
+		GoTo(bot - n + 1, 0);
+		ClrToEOS(blank2);
+	    } else {
+		for (i = 0; i < n; i++) {
+		    GoTo(bot - i, 0);
+		    ClrToEOL(blank2, FALSE);
+		}
+	    }
+	}
+
+    } else {			/* (n < 0) - scroll down (backward) */
+	res = scroll_csr_backward(-n, top, bot, 0, maxy, blank);
+
+	if (res == ERR && change_scroll_region) {
+	    if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top - 1)
+		&& save_cursor && restore_cursor) {
+		cursor_saved = TRUE;
+		TPUTS_TRACE("save_cursor");
+		putp(save_cursor);
+	    }
+	    TPUTS_TRACE("change_scroll_region");
+	    putp(TPARM_2(change_scroll_region, top, bot));
+	    if (cursor_saved) {
+		TPUTS_TRACE("restore_cursor");
+		putp(restore_cursor);
+	    } else {
+		SP->_cursrow = SP->_curscol = -1;
+	    }
+
+	    res = scroll_csr_backward(-n, top, bot, top, bot, blank);
+
+	    TPUTS_TRACE("change_scroll_region");
+	    putp(TPARM_2(change_scroll_region, 0, maxy));
+	    SP->_cursrow = SP->_curscol = -1;
+	}
+
+	if (res == ERR && _nc_idlok)
+	    res = scroll_idl(-n, bot + n + 1, top, blank);
+
+	/*
+	 * Clear the newly shifted-in text.
+	 */
+	if (res != ERR
+	    && (non_dest_scroll_region || (memory_above && top == 0))) {
+	    static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT);
+	    for (i = 0; i < -n; i++) {
+		GoTo(i + top, 0);
+		ClrToEOL(blank2, FALSE);
+	    }
+	}
+    }
+
+    if (res == ERR)
+	return (ERR);
+
+    _nc_scroll_window(curscr, n, top, bot, blank);
+
+    /* shift hash values too - they can be reused */
+    _nc_scroll_oldhash(n, top, bot);
+
+    return (OK);
+}
+
+NCURSES_EXPORT(void)
+_nc_screen_resume(void)
+{
+    /* make sure terminal is in a sane known state */
+    SetAttr(SCREEN_ATTRS(SP), A_NORMAL);
+    newscr->_clear = TRUE;
+
+    /* reset color pairs and definitions */
+    if (SP->_coloron || SP->_color_defs)
+	_nc_reset_colors();
+
+    /* restore user-defined colors, if any */
+    if (SP->_color_defs < 0) {
+	int n;
+	SP->_color_defs = -(SP->_color_defs);
+	for (n = 0; n < SP->_color_defs; ++n) {
+	    if (SP->_color_table[n].init) {
+		init_color(n,
+			   SP->_color_table[n].r,
+			   SP->_color_table[n].g,
+			   SP->_color_table[n].b);
+	    }
+	}
+    }
+
+    if (exit_attribute_mode)
+	putp(exit_attribute_mode);
+    else {
+	/* turn off attributes */
+	if (exit_alt_charset_mode)
+	    putp(exit_alt_charset_mode);
+	if (exit_standout_mode)
+	    putp(exit_standout_mode);
+	if (exit_underline_mode)
+	    putp(exit_underline_mode);
+    }
+    if (exit_insert_mode)
+	putp(exit_insert_mode);
+    if (enter_am_mode && exit_am_mode)
+	putp(auto_right_margin ? enter_am_mode : exit_am_mode);
+}
+
+NCURSES_EXPORT(void)
+_nc_screen_init(void)
+{
+    _nc_screen_resume();
+}
+
+/* wrap up screen handling */
+NCURSES_EXPORT(void)
+_nc_screen_wrap(void)
+{
+    UpdateAttrs(normal);
+#if NCURSES_EXT_FUNCS
+    if (SP->_coloron
+	&& !SP->_default_color) {
+	static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+	SP->_default_color = TRUE;
+	_nc_do_color(-1, 0, FALSE, _nc_outch);
+	SP->_default_color = FALSE;
+
+	mvcur(SP->_cursrow, SP->_curscol, screen_lines - 1, 0);
+
+	ClrToEOL(blank, TRUE);
+    }
+#endif
+    if (SP->_color_defs) {
+	_nc_reset_colors();
+    }
+}
+
+#if USE_XMC_SUPPORT
+NCURSES_EXPORT(void)
+_nc_do_xmc_glitch(attr_t previous)
+{
+    attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP)));
+
+    while (chg != 0) {
+	if (chg & 1) {
+	    SP->_curscol += magic_cookie_glitch;
+	    if (SP->_curscol >= SP->_columns)
+		wrap_cursor();
+	    TR(TRACE_UPDATE, ("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol));
+	}
+	chg >>= 1;
+    }
+}
+#endif /* USE_XMC_SUPPORT */
diff --git a/ncurses/widechar/charable.c b/ncurses/widechar/charable.c
new file mode 100644
index 0000000..91ceb32
--- /dev/null
+++ b/ncurses/widechar/charable.c
@@ -0,0 +1,80 @@
+/****************************************************************************
+ * Copyright (c) 2003-2005,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/*
+**	Support functions for wide/narrow conversion.
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: charable.c,v 1.5 2008/07/05 20:51:41 tom Exp $")
+
+NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch)
+{
+    bool result;
+#if HAVE_WCTOB
+    result = (wctob((wint_t) ch) == (int) ch);
+#else
+    result = (_nc_to_char(ch) >= 0);
+#endif
+    return result;
+}
+
+NCURSES_EXPORT(int) _nc_to_char(wint_t ch)
+{
+    int result;
+#if HAVE_WCTOB
+    result = wctob(ch);
+#elif HAVE_WCTOMB
+    char temp[MB_LEN_MAX];
+    result = wctomb(temp, ch);
+    if (strlen(temp) == 1)
+	result = UChar(temp[0]);
+    else
+	result = -1;
+#endif
+    return result;
+}
+
+NCURSES_EXPORT(wint_t) _nc_to_widechar(int ch)
+{
+    wint_t result;
+#if HAVE_BTOWC
+    result = btowc(ch);
+#elif HAVE_MBTOWC
+    wchar_t convert;
+    char temp[2];
+    temp[0] = ch;
+    temp[1] = '\0';
+    if (mbtowc(&convert, temp, 1) >= 0)
+	result = convert;
+    else
+	result = WEOF;
+#endif
+    return result;
+}
diff --git a/ncurses/widechar/lib_add_wch.c b/ncurses/widechar/lib_add_wch.c
new file mode 100644
index 0000000..93b41bb
--- /dev/null
+++ b/ncurses/widechar/lib_add_wch.c
@@ -0,0 +1,113 @@
+/****************************************************************************
+ * Copyright (c) 2004,2006 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/*
+**	lib_add_wch.c
+**
+**	The routine wadd_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_add_wch.c,v 1.6 2006/12/02 21:19:17 tom Exp $")
+
+NCURSES_EXPORT(int)
+wadd_wch(WINDOW *win, const cchar_t *wch)
+{
+    PUTC_DATA;
+    int n;
+    int code = ERR;
+
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win,
+				      _tracech_t(wch)));
+
+    if (win != 0) {
+	PUTC_INIT;
+	for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+	    attr_t attrs = (wch->attr & A_ATTRIBUTES);
+
+	    if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0')
+		break;
+	    if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
+		code = ERR;
+		if (is8bits(PUTC_ch))
+		    code = waddch(win, UChar(PUTC_ch) | attrs);
+		break;
+	    }
+	    for (n = 0; n < PUTC_n; n++) {
+		if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) {
+		    break;
+		}
+	    }
+	    if (code == ERR)
+		break;
+	}
+    }
+
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+    return (code);
+}
+
+NCURSES_EXPORT(int)
+wecho_wchar(WINDOW *win, const cchar_t *wch)
+{
+    PUTC_DATA;
+    int n;
+    int code = ERR;
+
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win,
+				      _tracech_t(wch)));
+
+    if (win != 0) {
+	PUTC_INIT;
+	for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+	    attr_t attrs = (wch->attr & A_ATTRIBUTES);
+
+	    if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0')
+		break;
+	    if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
+		code = ERR;
+		if (is8bits(PUTC_ch))
+		    code = waddch(win, UChar(PUTC_ch) | attrs);
+		break;
+	    }
+	    for (n = 0; n < PUTC_n; n++) {
+		if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) {
+		    break;
+		}
+	    }
+	    if (code == ERR)
+		break;
+	}
+	wrefresh(win);
+    }
+
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+    return (code);
+}
diff --git a/ncurses/widechar/lib_box_set.c b/ncurses/widechar/lib_box_set.c
new file mode 100644
index 0000000..35fce46
--- /dev/null
+++ b/ncurses/widechar/lib_box_set.c
@@ -0,0 +1,113 @@
+/****************************************************************************
+ * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Authors: Sven Verdoolaege and Thomas Dickey 2001,2002                    *
+ ****************************************************************************/
+
+/*
+**	lib_box_set.c
+**
+**	The routine wborder_set().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_box_set.c,v 1.4 2003/12/06 18:02:13 tom Exp $")
+
+NCURSES_EXPORT(int)
+wborder_set(WINDOW *win,
+	    const ARG_CH_T ls, const ARG_CH_T rs,
+	    const ARG_CH_T ts, const ARG_CH_T bs,
+	    const ARG_CH_T tl, const ARG_CH_T tr,
+	    const ARG_CH_T bl, const ARG_CH_T br)
+{
+    NCURSES_SIZE_T i;
+    NCURSES_SIZE_T endx, endy;
+    NCURSES_CH_T wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
+
+    T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
+       win,
+       _tracech_t2(1, ls),
+       _tracech_t2(2, rs),
+       _tracech_t2(3, ts),
+       _tracech_t2(4, bs),
+       _tracech_t2(5, tl),
+       _tracech_t2(6, tr),
+       _tracech_t2(7, bl),
+       _tracech_t2(8, br)));
+
+    if (!win)
+	returnCode(ERR);
+
+#define RENDER_WITH_DEFAULT(ch,def) w ##ch = _nc_render(win, (ch == 0) ? *(const ARG_CH_T)def : *ch)
+
+    RENDER_WITH_DEFAULT(ls, WACS_VLINE);
+    RENDER_WITH_DEFAULT(rs, WACS_VLINE);
+    RENDER_WITH_DEFAULT(ts, WACS_HLINE);
+    RENDER_WITH_DEFAULT(bs, WACS_HLINE);
+    RENDER_WITH_DEFAULT(tl, WACS_ULCORNER);
+    RENDER_WITH_DEFAULT(tr, WACS_URCORNER);
+    RENDER_WITH_DEFAULT(bl, WACS_LLCORNER);
+    RENDER_WITH_DEFAULT(br, WACS_LRCORNER);
+
+    T(("using %s, %s, %s, %s, %s, %s, %s, %s",
+       _tracech_t2(1, CHREF(wls)),
+       _tracech_t2(2, CHREF(wrs)),
+       _tracech_t2(3, CHREF(wts)),
+       _tracech_t2(4, CHREF(wbs)),
+       _tracech_t2(5, CHREF(wtl)),
+       _tracech_t2(6, CHREF(wtr)),
+       _tracech_t2(7, CHREF(wbl)),
+       _tracech_t2(8, CHREF(wbr))));
+
+    endx = win->_maxx;
+    endy = win->_maxy;
+
+    for (i = 0; i <= endx; i++) {
+	win->_line[0].text[i] = wts;
+	win->_line[endy].text[i] = wbs;
+    }
+    win->_line[endy].firstchar = win->_line[0].firstchar = 0;
+    win->_line[endy].lastchar = win->_line[0].lastchar = endx;
+
+    for (i = 0; i <= endy; i++) {
+	win->_line[i].text[0] = wls;
+	win->_line[i].text[endx] = wrs;
+	win->_line[i].firstchar = 0;
+	win->_line[i].lastchar = endx;
+    }
+    win->_line[0].text[0] = wtl;
+    win->_line[0].text[endx] = wtr;
+    win->_line[endy].text[0] = wbl;
+    win->_line[endy].text[endx] = wbr;
+
+    _nc_synchook(win);
+    returnCode(OK);
+}
diff --git a/ncurses/widechar/lib_cchar.c b/ncurses/widechar/lib_cchar.c
new file mode 100644
index 0000000..b4a0c37
--- /dev/null
+++ b/ncurses/widechar/lib_cchar.c
@@ -0,0 +1,129 @@
+/****************************************************************************
+ * Copyright (c) 2001-2005,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/*
+**	lib_cchar.c
+**
+**	The routines setcchar() and getcchar().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_cchar.c,v 1.12 2007/05/12 19:03:06 tom Exp $")
+
+/* 
+ * The SuSv2 description leaves some room for interpretation.  We'll assume wch
+ * points to a string which is L'\0' terminated, contains at least one
+ * character with strictly positive width, which must be the first, and
+ * contains no characters of negative width.
+ */
+NCURSES_EXPORT(int)
+setcchar(cchar_t *wcval,
+	 const wchar_t *wch,
+	 const attr_t attrs,
+	 short color_pair,
+	 const void *opts)
+{
+    int i;
+    int len;
+    int code = OK;
+
+    TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"),
+		      wcval, _nc_viswbuf(wch),
+		      (unsigned long) attrs, color_pair, opts));
+
+    len = wcslen(wch);
+    if (opts != NULL
+	|| (len > 1 && wcwidth(wch[0]) < 0)) {
+	code = ERR;
+    } else {
+	if (len > CCHARW_MAX)
+	    len = CCHARW_MAX;
+
+	/*
+	 * If we have a following spacing-character, stop at that point.  We
+	 * are only interested in adding non-spacing characters.
+	 */
+	for (i = 1; i < len; ++i) {
+	    if (wcwidth(wch[i]) != 0) {
+		len = i;
+		break;
+	    }
+	}
+
+	memset(wcval, 0, sizeof(*wcval));
+
+	if (len != 0) {
+	    SetAttr(*wcval, attrs | COLOR_PAIR(color_pair));
+	    SetPair(CHDEREF(wcval), color_pair);
+	    memcpy(&wcval->chars, wch, len * sizeof(wchar_t));
+	    TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
+			      _tracecchar_t(wcval)));
+	}
+    }
+
+    TR(TRACE_CCALLS, (T_RETURN("%d"), code));
+    return (code);
+}
+
+NCURSES_EXPORT(int)
+getcchar(const cchar_t *wcval,
+	 wchar_t *wch,
+	 attr_t *attrs,
+	 short *color_pair,
+	 void *opts)
+{
+    wchar_t *wp;
+    int len;
+    int code = ERR;
+
+    TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
+		      wcval, wch, attrs, color_pair, opts));
+
+    if (opts == NULL) {
+	len = (wp = wmemchr(wcval->chars, L'\0', CCHARW_MAX))
+	    ? wp - wcval->chars
+	    : CCHARW_MAX;
+
+	if (wch == NULL) {
+	    code = len;
+	} else if (attrs == 0 || color_pair == 0) {
+	    code = ERR;
+	} else if (len >= 0) {
+	    *attrs = AttrOf(*wcval) & A_ATTRIBUTES;
+	    *color_pair = GetPair(*wcval);
+	    wmemcpy(wch, wcval->chars, (unsigned) len);
+	    wch[len] = L'\0';
+	    code = OK;
+	}
+    }
+
+    TR(TRACE_CCALLS, (T_RETURN("%d"), code));
+    return (code);
+}
diff --git a/ncurses/widechar/lib_erasewchar.c b/ncurses/widechar/lib_erasewchar.c
new file mode 100644
index 0000000..7d64553
--- /dev/null
+++ b/ncurses/widechar/lib_erasewchar.c
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 2002                                           *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_erasewchar.c,v 1.1 2002/05/11 20:38:06 tom Exp $")
+
+/*
+ *	erasewchar()
+ *
+ *	Return erase character as given in cur_term->Ottyb.
+ *
+ */
+
+NCURSES_EXPORT(int)
+erasewchar(wchar_t * wch)
+{
+    int value;
+    int result = ERR;
+
+    T((T_CALLED("erasewchar()")));
+    if ((value = erasechar()) != ERR) {
+	*wch = value;
+	result = OK;
+    }
+    returnCode(result);
+}
+
+/*
+ *	killwchar()
+ *
+ *	Return kill character as given in cur_term->Ottyb.
+ *
+ */
+
+NCURSES_EXPORT(int)
+killwchar(wchar_t * wch)
+{
+    int value;
+    int result = ERR;
+
+    T((T_CALLED("killwchar()")));
+    if ((value = killchar()) != ERR) {
+	*wch = value;
+	result = OK;
+    }
+    returnCode(result);
+}
diff --git a/ncurses/widechar/lib_get_wch.c b/ncurses/widechar/lib_get_wch.c
new file mode 100644
index 0000000..6cf3129
--- /dev/null
+++ b/ncurses/widechar/lib_get_wch.c
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * Copyright (c) 2002-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 2002-on                                        *
+ ****************************************************************************/
+
+/*
+**	lib_get_wch.c
+**
+**	The routine get_wch().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_get_wch.c,v 1.17 2008/08/16 19:22:55 tom Exp $")
+
+#if HAVE_MBTOWC && HAVE_MBLEN
+#define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
+#define count_mbytes(buffer,length,state) mblen(buffer,length)
+#define check_mbytes(wch,buffer,length,state) \
+	(int) mbtowc(&wch, buffer, length)
+#define state_unused
+#elif HAVE_MBRTOWC && HAVE_MBRLEN
+#define reset_mbytes(state) init_mb(state)
+#define count_mbytes(buffer,length,state) mbrlen(buffer,length,&state)
+#define check_mbytes(wch,buffer,length,state) \
+	(int) mbrtowc(&wch, buffer, length, &state)
+#else
+make an error
+#endif
+
+NCURSES_EXPORT(int)
+wget_wch(WINDOW *win, wint_t *result)
+{
+    SCREEN *sp;
+    int code;
+    char buffer[(MB_LEN_MAX * 9) + 1];	/* allow some redundant shifts */
+    int status;
+    size_t count = 0;
+    unsigned long value;
+    wchar_t wch;
+#ifndef state_unused
+    mbstate_t state;
+#endif
+
+    T((T_CALLED("wget_wch(%p)"), win));
+
+    /*
+     * We can get a stream of single-byte characters and KEY_xxx codes from
+     * _nc_wgetch(), while we want to return a wide character or KEY_xxx code.
+     */
+    _nc_lock_global(curses);
+    sp = _nc_screen_of(win);
+    if (sp != 0) {
+	for (;;) {
+	    T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer)));
+	    code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist
+							       *) 0));
+	    if (code == ERR) {
+		break;
+	    } else if (code == KEY_CODE_YES) {
+		/*
+		 * If we were processing an incomplete multibyte character,
+		 * return an error since we have a KEY_xxx code which
+		 * interrupts it.  For some cases, we could improve this by
+		 * writing a new version of lib_getch.c(!), but it is not clear
+		 * whether the improvement would be worth the effort.
+		 */
+		if (count != 0) {
+		    _nc_ungetch(sp, (int) value);
+		    code = ERR;
+		}
+		break;
+	    } else if (count + 1 >= sizeof(buffer)) {
+		_nc_ungetch(sp, (int) value);
+		code = ERR;
+		break;
+	    } else {
+		buffer[count++] = (char) UChar(value);
+		reset_mbytes(state);
+		status = count_mbytes(buffer, count, state);
+		if (status >= 0) {
+		    reset_mbytes(state);
+		    if (check_mbytes(wch, buffer, count, state) != status) {
+			code = ERR;	/* the two calls should match */
+			_nc_ungetch(sp, (int) value);
+		    }
+		    value = wch;
+		    break;
+		}
+	    }
+	}
+    } else {
+	code = ERR;
+    }
+    *result = value;
+    _nc_unlock_global(curses);
+    T(("result %#lo", value));
+    returnCode(code);
+}
diff --git a/ncurses/widechar/lib_get_wstr.c b/ncurses/widechar/lib_get_wstr.c
new file mode 100644
index 0000000..baa70a5
--- /dev/null
+++ b/ncurses/widechar/lib_get_wstr.c
@@ -0,0 +1,232 @@
+/****************************************************************************
+ * Copyright (c) 2002-2004,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+**	lib_get_wstr.c
+**
+**	The routine wgetn_wstr().
+**
+*/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_get_wstr.c,v 1.10 2008/08/16 19:25:33 tom Exp $")
+
+static int
+wadd_wint(WINDOW *win, wint_t *src)
+{
+    cchar_t tmp;
+    wchar_t wch[2];
+
+    wch[0] = (wchar_t) (*src);
+    wch[1] = 0;
+    setcchar(&tmp, wch, A_NORMAL, 0, NULL);
+    return wadd_wch(win, &tmp);
+}
+
+/*
+ * This wipes out the last character, no matter whether it was a tab, control
+ * or other character, and handles reverse wraparound.
+ */
+static wint_t *
+WipeOut(WINDOW *win, int y, int x, wint_t *first, wint_t *last, bool echoed)
+{
+    if (last > first) {
+	*--last = '\0';
+	if (echoed) {
+	    int y1 = win->_cury;
+	    int x1 = win->_curx;
+	    int n;
+
+	    wmove(win, y, x);
+	    for (n = 0; first[n] != 0; ++n) {
+		wadd_wint(win, first + n);
+	    }
+	    getyx(win, y, x);
+	    while (win->_cury < y1
+		   || (win->_cury == y1 && win->_curx < x1))
+		waddch(win, (chtype) ' ');
+
+	    wmove(win, y, x);
+	}
+    }
+    return last;
+}
+
+NCURSES_EXPORT(int)
+wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
+{
+    SCREEN *sp = _nc_screen_of(win);
+    TTY buf;
+    bool oldnl, oldecho, oldraw, oldcbreak;
+    wint_t erasec;
+    wint_t killc;
+    wint_t *oldstr = str;
+    wint_t *tmpstr = str;
+    wint_t ch;
+    int y, x, code;
+
+    T((T_CALLED("wgetn_wstr(%p,%p, %d)"), win, str, maxlen));
+
+    if (!win)
+	returnCode(ERR);
+
+    _nc_get_tty_mode(&buf);
+
+    oldnl = sp->_nl;
+    oldecho = sp->_echo;
+    oldraw = sp->_raw;
+    oldcbreak = sp->_cbreak;
+    nl();
+    noecho();
+    noraw();
+    cbreak();
+
+    erasec = (wint_t) erasechar();
+    killc = (wint_t) killchar();
+
+    getyx(win, y, x);
+
+    if (is_wintouched(win) || (win->_flags & _HASMOVED))
+	wrefresh(win);
+
+    while ((code = wget_wch(win, &ch)) != ERR) {
+	/*
+	 * Map special characters into key-codes.
+	 */
+	if (ch == '\r')
+	    ch = '\n';
+	if (ch == '\n') {
+	    code = KEY_CODE_YES;
+	    ch = KEY_ENTER;
+	}
+	if (ch < KEY_MIN) {
+	    if (ch == erasec) {
+		ch = KEY_BACKSPACE;
+		code = KEY_CODE_YES;
+	    }
+	    if (ch == killc) {
+		ch = KEY_EOL;
+		code = KEY_CODE_YES;
+	    }
+	}
+	if (code == KEY_CODE_YES) {
+	    /*
+	     * Some terminals (the Wyse-50 is the most common) generate a \n
+	     * from the down-arrow key.  With this logic, it's the user's
+	     * choice whether to set kcud=\n for wget_wch(); terminating
+	     * *getn_wstr() with \n should work either way.
+	     */
+	    if (ch == KEY_DOWN || ch == KEY_ENTER) {
+		if (oldecho == TRUE
+		    && win->_cury == win->_maxy
+		    && win->_scroll)
+		    wechochar(win, (chtype) '\n');
+		break;
+	    }
+	    if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
+		if (tmpstr > oldstr) {
+		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+		}
+	    } else if (ch == KEY_EOL) {
+		while (tmpstr > oldstr) {
+		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+		}
+	    } else {
+		beep();
+	    }
+	} else if (maxlen >= 0 && tmpstr - oldstr >= maxlen) {
+	    beep();
+	} else {
+	    *tmpstr++ = ch;
+	    *tmpstr = 0;
+	    if (oldecho == TRUE) {
+		int oldy = win->_cury;
+
+		if (wadd_wint(win, tmpstr - 1) == ERR) {
+		    /*
+		     * We can't really use the lower-right corner for input,
+		     * since it'll mess up bookkeeping for erases.
+		     */
+		    win->_flags &= ~_WRAPPED;
+		    waddch(win, (chtype) ' ');
+		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+		    continue;
+		} else if (win->_flags & _WRAPPED) {
+		    /*
+		     * If the last waddch forced a wrap & scroll, adjust our
+		     * reference point for erasures.
+		     */
+		    if (win->_scroll
+			&& oldy == win->_maxy
+			&& win->_cury == win->_maxy) {
+			if (--y <= 0) {
+			    y = 0;
+			}
+		    }
+		    win->_flags &= ~_WRAPPED;
+		}
+		wrefresh(win);
+	    }
+	}
+    }
+
+    win->_curx = 0;
+    win->_flags &= ~_WRAPPED;
+    if (win->_cury < win->_maxy)
+	win->_cury++;
+    wrefresh(win);
+
+    /* Restore with a single I/O call, to fix minor asymmetry between
+     * raw/noraw, etc.
+     */
+    sp->_nl = oldnl;
+    sp->_echo = oldecho;
+    sp->_raw = oldraw;
+    sp->_cbreak = oldcbreak;
+
+    (void) _nc_set_tty_mode(&buf);
+
+    *tmpstr = 0;
+    if (code == ERR) {
+	if (tmpstr == oldstr) {
+	    *tmpstr++ = WEOF;
+	    *tmpstr = 0;
+	}
+	returnCode(ERR);
+    }
+
+    T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr)));
+
+    returnCode(OK);
+}
diff --git a/ncurses/widechar/lib_hline_set.c b/ncurses/widechar/lib_hline_set.c
new file mode 100644
index 0000000..43175de
--- /dev/null
+++ b/ncurses/widechar/lib_hline_set.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas Dickey 2002                                              *
+ ****************************************************************************/
+
+/*
+**	lib_hline_set.c
+**
+**	The routine whline_set().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_hline_set.c,v 1.2 2002/03/23 21:35:34 tom Exp $")
+
+NCURSES_EXPORT(int)
+whline_set(WINDOW *win, const cchar_t * ch, int n)
+{
+    int code = ERR;
+    NCURSES_SIZE_T start;
+    NCURSES_SIZE_T end;
+
+    T((T_CALLED("whline_set(%p,%s,%d)"), win, _tracecchar_t(ch), n));
+
+    if (win) {
+	struct ldat *line = &(win->_line[win->_cury]);
+	NCURSES_CH_T wch;
+
+	start = win->_curx;
+	end = start + n - 1;
+	if (end > win->_maxx)
+	    end = win->_maxx;
+
+	CHANGED_RANGE(line, start, end);
+
+	if (ch == 0)
+	    wch = *WACS_HLINE;
+	else
+	    wch = *ch;
+	wch = _nc_render(win, wch);
+
+	while (end >= start) {
+	    line->text[end] = wch;
+	    end--;
+	}
+
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/widechar/lib_in_wch.c b/ncurses/widechar/lib_in_wch.c
new file mode 100644
index 0000000..5cd92e3
--- /dev/null
+++ b/ncurses/widechar/lib_in_wch.c
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * Copyright (c) 2002-2004,2006 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas Dickey                                                    *
+ ****************************************************************************/
+
+/*
+**	lib_in_wch.c
+**
+**	The routine win_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_in_wch.c,v 1.4 2006/09/03 15:41:22 tom Exp $")
+
+NCURSES_EXPORT(int)
+win_wch(WINDOW *win, cchar_t *wcval)
+{
+    int row, col;
+    int code = OK;
+
+    TR(TRACE_CCALLS, (T_CALLED("win_wch(%p,%p)"), win, wcval));
+    if (win != 0
+	&& wcval != 0) {
+	getyx(win, row, col);
+
+	*wcval = win->_line[row].text[col];
+	TR(TRACE_CCALLS, ("data %s", _tracecchar_t(wcval)));
+    } else {
+	code = ERR;
+    }
+    TR(TRACE_CCALLS, (T_RETURN("%d"), code));
+    return (code);
+}
diff --git a/ncurses/widechar/lib_in_wchnstr.c b/ncurses/widechar/lib_in_wchnstr.c
new file mode 100644
index 0000000..e9f0646
--- /dev/null
+++ b/ncurses/widechar/lib_in_wchnstr.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * Copyright (c) 2002-2004-2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas Dickey                                                    *
+ ****************************************************************************/
+
+/*
+**	lib_in_wchnstr.c
+**
+**	The routine win_wchnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_in_wchnstr.c,v 1.7 2007/02/11 01:00:00 tom Exp $")
+
+NCURSES_EXPORT(int)
+win_wchnstr(WINDOW *win, cchar_t *wchstr, int n)
+{
+    int code = OK;
+
+    T((T_CALLED("win_wchnstr(%p,%p,%d)"), win, wchstr, n));
+    if (win != 0
+	&& wchstr != 0) {
+	NCURSES_CH_T *src;
+	int row, col;
+	int j, k, limit;
+
+	getyx(win, row, col);
+	limit = getmaxx(win) - col;
+	src = &(win->_line[row].text[col]);
+
+	if (n < 0) {
+	    n = limit;
+	} else if (n > limit) {
+	    n = limit;
+	}
+	for (j = k = 0; j < n; ++j) {
+	    if (j == 0 || !WidecExt(src[j]) || isWidecBase(src[j])) {
+		wchstr[k++] = src[j];
+	    }
+	}
+	memset(&(wchstr[k]), 0, sizeof(*wchstr));
+	T(("result = %s", _nc_viscbuf(wchstr, n)));
+    } else {
+	code = ERR;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/widechar/lib_ins_wch.c b/ncurses/widechar/lib_ins_wch.c
new file mode 100644
index 0000000..c3d0420
--- /dev/null
+++ b/ncurses/widechar/lib_ins_wch.c
@@ -0,0 +1,144 @@
+/****************************************************************************
+ * Copyright (c) 2002-2003,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas Dickey 2002                                              *
+ ****************************************************************************/
+
+/*
+**	lib_ins_wch.c
+**
+**	The routine wins_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_ins_wch.c,v 1.8 2005/12/03 20:24:19 tom Exp $")
+
+/*
+ * Insert the given character, updating the current location to simplify
+ * inserting a string.
+ */
+static int
+_nc_insert_wch(WINDOW *win, const cchar_t *wch)
+{
+    int cells = wcwidth(CharOf(CHDEREF(wch)));
+    int cell;
+
+    if (cells <= 0)
+	cells = 1;
+
+    if (win->_curx <= win->_maxx) {
+	struct ldat *line = &(win->_line[win->_cury]);
+	NCURSES_CH_T *end = &(line->text[win->_curx]);
+	NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
+	NCURSES_CH_T *temp2 = temp1 - cells;
+
+	CHANGED_TO_EOL(line, win->_curx, win->_maxx);
+	while (temp1 > end)
+	    *temp1-- = *temp2--;
+
+	*temp1 = _nc_render(win, *wch);
+	for (cell = 1; cell < cells; ++cell) {
+	    SetWidecExt(temp1[cell], cell);
+	}
+
+	win->_curx++;
+    }
+    return OK;
+}
+
+NCURSES_EXPORT(int)
+wins_wch(WINDOW *win, const cchar_t *wch)
+{
+    NCURSES_SIZE_T oy;
+    NCURSES_SIZE_T ox;
+    int code = ERR;
+
+    T((T_CALLED("wins_wch(%p, %s)"), win, _tracecchar_t(wch)));
+
+    if (win != 0) {
+	oy = win->_cury;
+	ox = win->_curx;
+
+	code = _nc_insert_wch(win, wch);
+
+	win->_curx = ox;
+	win->_cury = oy;
+	_nc_synchook(win);
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
+{
+    int code = ERR;
+    NCURSES_SIZE_T oy;
+    NCURSES_SIZE_T ox;
+    const wchar_t *cp;
+
+    T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbufn(wstr, n), n));
+
+    if (win != 0
+	&& wstr != 0) {
+	if (n < 1)
+	    n = wcslen(wstr);
+	code = OK;
+	if (n > 0) {
+	    oy = win->_cury;
+	    ox = win->_curx;
+	    for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
+		int len = wcwidth(*cp);
+
+		if (len != 1 || !is8bits(*cp)) {
+		    cchar_t tmp_cchar;
+		    wchar_t tmp_wchar = *cp;
+		    memset(&tmp_cchar, 0, sizeof(tmp_cchar));
+		    (void) setcchar(&tmp_cchar,
+				    &tmp_wchar,
+				    WA_NORMAL,
+				    0,
+				    (void *) 0);
+		    code = _nc_insert_wch(win, &tmp_cchar);
+		} else {
+		    /* tabs, other ASCII stuff */
+		    code = _nc_insert_ch(win, (chtype) (*cp));
+		}
+		if (code != OK)
+		    break;
+	    }
+
+	    win->_curx = ox;
+	    win->_cury = oy;
+	    _nc_synchook(win);
+	}
+    }
+    returnCode(code);
+}
diff --git a/ncurses/widechar/lib_inwstr.c b/ncurses/widechar/lib_inwstr.c
new file mode 100644
index 0000000..2207a5f
--- /dev/null
+++ b/ncurses/widechar/lib_inwstr.c
@@ -0,0 +1,100 @@
+/****************************************************************************
+ * Copyright (c) 2002,2004 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas Dickey                                                    *
+ ****************************************************************************/
+
+/*
+**	lib_inwstr.c
+**
+**	The routines winnwstr() and winwstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_inwstr.c,v 1.4 2004/10/23 20:41:28 tom Exp $")
+
+NCURSES_EXPORT(int)
+winnwstr(WINDOW *win, wchar_t *wstr, int n)
+{
+    int row, col, inx;
+    int count = 0;
+    int last = 0;
+    cchar_t *text;
+    wchar_t wch;
+
+    T((T_CALLED("winnwstr(%p,%p,%d)"), win, wstr, n));
+    if (wstr != 0) {
+	if (win) {
+	    getyx(win, row, col);
+
+	    text = win->_line[row].text;
+	    while (count < n && count != ERR) {
+		if (!isWidecExt(text[col])) {
+		    for (inx = 0; (inx < CCHARW_MAX)
+			 && ((wch = text[col].chars[inx]) != 0);
+			 ++inx) {
+			if (count + 1 > n) {
+			    if ((count = last) == 0) {
+				count = ERR;	/* error if we store nothing */
+			    }
+			    break;
+			}
+			wstr[count++] = wch;
+		    }
+		}
+		last = count;
+		if (++col > win->_maxx) {
+		    break;
+		}
+	    }
+	}
+	if (count > 0) {
+	    wstr[count] = '\0';
+	    T(("winnwstr returns %s", _nc_viswbuf(wstr)));
+	}
+    }
+    returnCode(count);
+}
+
+/*
+ * X/Open says winwstr() returns OK if not ERR.  If that is not a blunder, it
+ * must have a null termination on the string (see above).  Unlike winnstr(),
+ * it does not define what happens for a negative count with winnwstr().
+ */
+NCURSES_EXPORT(int)
+winwstr(WINDOW *win, wchar_t *wstr)
+{
+    int result = OK;
+    T((T_CALLED("winwstr(%p,%p)"), win, wstr));
+    if (winnwstr(win, wstr, CCHARW_MAX * (win->_maxx - win->_curx + 1)) == ERR)
+	result = ERR;
+    returnCode(result);
+}
diff --git a/ncurses/widechar/lib_key_name.c b/ncurses/widechar/lib_key_name.c
new file mode 100644
index 0000000..da65f21
--- /dev/null
+++ b/ncurses/widechar/lib_key_name.c
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * Copyright (c) 2007 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/*
+**	lib_key_name.c
+**
+**	The routine key_name().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_key_name.c,v 1.3 2008/10/11 20:15:14 tom Exp $")
+
+NCURSES_EXPORT(NCURSES_CONST char *)
+key_name(wchar_t c)
+{
+    cchar_t my_cchar;
+    wchar_t *my_wchars;
+    size_t len;
+
+    /* FIXME: move to _nc_globals */
+    static char result[MB_LEN_MAX + 1];
+
+    memset(&my_cchar, 0, sizeof(my_cchar));
+    my_cchar.chars[0] = c;
+    my_cchar.chars[1] = L'\0';
+
+    my_wchars = wunctrl(&my_cchar);
+    len = wcstombs(result, my_wchars, sizeof(result) - 1);
+    if (isEILSEQ(len) || (len == 0)) {
+	return 0;
+    }
+
+    result[len] = '\0';
+    return result;
+}
diff --git a/ncurses/widechar/lib_pecho_wchar.c b/ncurses/widechar/lib_pecho_wchar.c
new file mode 100644
index 0000000..e612775
--- /dev/null
+++ b/ncurses/widechar/lib_pecho_wchar.c
@@ -0,0 +1,57 @@
+/****************************************************************************
+ * Copyright (c) 2004 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_pecho_wchar.c,v 1.1 2004/01/03 21:42:01 tom Exp $")
+
+NCURSES_EXPORT(int)
+pecho_wchar(WINDOW *pad, const cchar_t * wch)
+{
+    T((T_CALLED("pecho_wchar(%p, %s)"), pad, _tracech_t(wch)));
+
+    if (pad == 0)
+	returnCode(ERR);
+
+    if (!(pad->_flags & _ISPAD))
+	returnCode(wecho_wchar(pad, wch));
+
+    wadd_wch(pad, wch);
+    prefresh(pad, pad->_pad._pad_y,
+	     pad->_pad._pad_x,
+	     pad->_pad._pad_top,
+	     pad->_pad._pad_left,
+	     pad->_pad._pad_bottom,
+	     pad->_pad._pad_right);
+
+    returnCode(OK);
+}
diff --git a/ncurses/widechar/lib_slk_wset.c b/ncurses/widechar/lib_slk_wset.c
new file mode 100644
index 0000000..646b5d9
--- /dev/null
+++ b/ncurses/widechar/lib_slk_wset.c
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * Copyright (c) 2003-2004,2005 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+/*
+ *	lib_slk_wset.c
+ *      Set soft label text.
+ */
+#include <curses.priv.h>
+
+#if HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
+
+MODULE_ID("$Id: lib_slk_wset.c,v 1.11 2005/01/16 01:03:53 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_wset(int i, const wchar_t *astr, int format)
+{
+    int result = ERR;
+    size_t arglen;
+    const wchar_t *str;
+    char *mystr;
+    mbstate_t state;
+
+    T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format));
+
+    init_mb(state);
+    str = astr;
+    if ((arglen = wcsrtombs(NULL, &str, 0, &state)) != (size_t) -1) {
+	if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) {
+	    str = astr;
+	    if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) {
+		/* glibc documentation claims that the terminating L'\0'
+		 * is written, but it is not...
+		 */
+		mystr[arglen] = 0;
+		result = slk_set(i, mystr, format);
+	    }
+	    free(mystr);
+	}
+    }
+    returnCode(result);
+}
diff --git a/ncurses/widechar/lib_unget_wch.c b/ncurses/widechar/lib_unget_wch.c
new file mode 100644
index 0000000..bb2c4a0
--- /dev/null
+++ b/ncurses/widechar/lib_unget_wch.c
@@ -0,0 +1,103 @@
+/****************************************************************************
+ * Copyright (c) 2002-2007,2008 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey 2002                                           *
+ ****************************************************************************/
+
+/*
+**	lib_unget_wch.c
+**
+**	The routine unget_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_unget_wch.c,v 1.10 2008/06/07 14:50:37 tom Exp $")
+
+/*
+ * Wrapper for wcrtomb() which obtains the length needed for the given
+ * wide-character 'source'.
+ */
+NCURSES_EXPORT(size_t)
+_nc_wcrtomb(char *target, wchar_t source, mbstate_t * state)
+{
+    int result;
+
+    if (target == 0) {
+	wchar_t temp[2];
+	const wchar_t *tempp = temp;
+	temp[0] = source;
+	temp[1] = 0;
+	result = wcsrtombs(NULL, &tempp, 0, state);
+    } else {
+	result = wcrtomb(target, source, state);
+    }
+    if (!isEILSEQ(result) && (result == 0))
+	result = 1;
+    return result;
+}
+
+NCURSES_EXPORT(int)
+unget_wch(const wchar_t wch)
+{
+    int result = OK;
+    mbstate_t state;
+    size_t length;
+    int n;
+
+    T((T_CALLED("unget_wch(%#lx)"), (unsigned long) wch));
+
+    init_mb(state);
+    length = _nc_wcrtomb(0, wch, &state);
+
+    if (length != (size_t) (-1)
+	&& length != 0) {
+	char *string;
+
+	if ((string = (char *) malloc(length)) != 0) {
+	    init_mb(state);
+	    wcrtomb(string, wch, &state);
+
+	    for (n = (int) (length - 1); n >= 0; --n) {
+		if (_nc_ungetch(SP, string[n]) != OK) {
+		    result = ERR;
+		    break;
+		}
+	    }
+	    free(string);
+	} else {
+	    result = ERR;
+	}
+    } else {
+	result = ERR;
+    }
+
+    returnCode(result);
+}
diff --git a/ncurses/widechar/lib_vid_attr.c b/ncurses/widechar/lib_vid_attr.c
new file mode 100644
index 0000000..1dc679e
--- /dev/null
+++ b/ncurses/widechar/lib_vid_attr.c
@@ -0,0 +1,275 @@
+/****************************************************************************
+ * Copyright (c) 2002-2006,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas E. Dickey                                                *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_vid_attr.c,v 1.5 2007/06/30 22:03:02 tom Exp $")
+
+#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
+
+#define TurnOn(mask,mode) \
+	if ((turn_on & mask) && mode) { doPut(mode); }
+
+#define TurnOff(mask,mode) \
+	if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; }
+
+	/* if there is no current screen, assume we *can* do color */
+#define SetColorsIf(why, old_attr, old_pair) \
+	if (can_color && (why)) { \
+		TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, pair)); \
+		if ((pair != old_pair) \
+		 || (fix_pair0 && (pair == 0)) \
+		 || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \
+			_nc_do_color(old_pair, pair, reverse, outc); \
+		} \
+	}
+
+#define set_color(mode, pair) mode &= ALL_BUT_COLOR; mode |= COLOR_PAIR(pair)
+
+NCURSES_EXPORT(int)
+vid_puts(attr_t newmode, short pair, void *opts GCC_UNUSED, int (*outc) (int))
+{
+#if NCURSES_EXT_COLORS
+    static attr_t previous_attr = A_NORMAL;
+    static int previous_pair = 0;
+
+    attr_t turn_on, turn_off;
+    bool reverse = FALSE;
+    bool can_color = (SP == 0 || SP->_coloron);
+#if NCURSES_EXT_FUNCS
+    bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color);
+#else
+#define fix_pair0 FALSE
+#endif
+
+    newmode &= A_ATTRIBUTES;
+    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair));
+
+    /* this allows us to go on whether or not newterm() has been called */
+    if (SP) {
+	previous_attr = AttrOf(SCREEN_ATTRS(SP));
+	previous_pair = GetPair(SCREEN_ATTRS(SP));
+    }
+
+    TR(TRACE_ATTRS, ("previous attribute was %s, %d",
+		     _traceattr(previous_attr), previous_pair));
+
+#if !USE_XMC_SUPPORT
+    if ((SP != 0)
+	&& (magic_cookie_glitch > 0))
+	newmode &= ~(SP->_xmc_suppress);
+#endif
+
+    /*
+     * If we have a terminal that cannot combine color with video
+     * attributes, use the colors in preference.
+     */
+    if ((pair != 0
+	 || fix_pair0)
+	&& (no_color_video > 0)) {
+	/*
+	 * If we had chosen the A_xxx definitions to correspond to the
+	 * no_color_video mask, we could simply shift it up and mask off the
+	 * attributes.  But we did not (actually copied Solaris' definitions).
+	 * However, this is still simpler/faster than a lookup table.
+	 *
+	 * The 63 corresponds to A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK,
+	 * A_DIM, A_BOLD which are 1:1 with no_color_video.  The bits that
+	 * correspond to A_INVIS, A_PROTECT (192) must be shifted up 1 and
+	 * A_ALTCHARSET (256) down 2 to line up.  We use the NCURSES_BITS
+	 * macro so this will work properly for the wide-character layout.
+	 */
+	unsigned value = no_color_video;
+	attr_t mask = NCURSES_BITS((value & 63)
+				   | ((value & 192) << 1)
+				   | ((value & 256) >> 2), 8);
+
+	if ((mask & A_REVERSE) != 0
+	    && (newmode & A_REVERSE) != 0) {
+	    reverse = TRUE;
+	    mask &= ~A_REVERSE;
+	}
+	newmode &= ~mask;
+    }
+
+    if (newmode == previous_attr
+	&& pair == previous_pair)
+	returnCode(OK);
+
+    if (reverse) {
+	newmode &= ~A_REVERSE;
+    }
+
+    turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR;
+    turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR;
+
+    SetColorsIf(((pair == 0) && !fix_pair0), previous_attr, previous_pair);
+
+    if (newmode == A_NORMAL) {
+	if ((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) {
+	    doPut(exit_alt_charset_mode);
+	    previous_attr &= ~A_ALTCHARSET;
+	}
+	if (previous_attr) {
+	    if (exit_attribute_mode) {
+		doPut(exit_attribute_mode);
+	    } else {
+		if (!SP || SP->_use_rmul) {
+		    TurnOff(A_UNDERLINE, exit_underline_mode);
+		}
+		if (!SP || SP->_use_rmso) {
+		    TurnOff(A_STANDOUT, exit_standout_mode);
+		}
+	    }
+	    previous_attr &= ALL_BUT_COLOR;
+	    previous_pair = 0;
+	}
+
+	SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+    } else if (set_attributes) {
+	if (turn_on || turn_off) {
+	    TPUTS_TRACE("set_attributes");
+	    tputs(TPARM_9(set_attributes,
+			  (newmode & A_STANDOUT) != 0,
+			  (newmode & A_UNDERLINE) != 0,
+			  (newmode & A_REVERSE) != 0,
+			  (newmode & A_BLINK) != 0,
+			  (newmode & A_DIM) != 0,
+			  (newmode & A_BOLD) != 0,
+			  (newmode & A_INVIS) != 0,
+			  (newmode & A_PROTECT) != 0,
+			  (newmode & A_ALTCHARSET) != 0), 1, outc);
+	    previous_attr &= ALL_BUT_COLOR;
+	    previous_pair = 0;
+	}
+	SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+    } else {
+
+	TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off)));
+
+	TurnOff(A_ALTCHARSET, exit_alt_charset_mode);
+
+	if (!SP || SP->_use_rmul) {
+	    TurnOff(A_UNDERLINE, exit_underline_mode);
+	}
+
+	if (!SP || SP->_use_rmso) {
+	    TurnOff(A_STANDOUT, exit_standout_mode);
+	}
+
+	if (turn_off && exit_attribute_mode) {
+	    doPut(exit_attribute_mode);
+	    turn_on |= (newmode & ALL_BUT_COLOR);
+	    previous_attr &= ALL_BUT_COLOR;
+	    previous_pair = 0;
+	}
+	SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+
+	TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on)));
+	/* *INDENT-OFF* */
+	TurnOn(A_ALTCHARSET,	enter_alt_charset_mode);
+	TurnOn(A_BLINK,		enter_blink_mode);
+	TurnOn(A_BOLD,		enter_bold_mode);
+	TurnOn(A_DIM,		enter_dim_mode);
+	TurnOn(A_REVERSE,	enter_reverse_mode);
+	TurnOn(A_STANDOUT,	enter_standout_mode);
+	TurnOn(A_PROTECT,	enter_protected_mode);
+	TurnOn(A_INVIS,		enter_secure_mode);
+	TurnOn(A_UNDERLINE,	enter_underline_mode);
+#if USE_WIDEC_SUPPORT
+	TurnOn(A_HORIZONTAL,	enter_horizontal_hl_mode);
+	TurnOn(A_LEFT,		enter_left_hl_mode);
+	TurnOn(A_LOW,		enter_low_hl_mode);
+	TurnOn(A_RIGHT,		enter_right_hl_mode);
+	TurnOn(A_TOP,		enter_top_hl_mode);
+	TurnOn(A_VERTICAL,	enter_vertical_hl_mode);
+#endif
+	/* *INDENT-ON* */
+
+    }
+
+    if (reverse)
+	newmode |= A_REVERSE;
+
+    if (SP) {
+	SetAttr(SCREEN_ATTRS(SP), newmode);
+	SetPair(SCREEN_ATTRS(SP), pair);
+    } else {
+	previous_attr = newmode;
+	previous_pair = pair;
+    }
+
+    returnCode(OK);
+#else
+    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair));
+    set_color(newmode, pair);
+    returnCode(vidputs(newmode, outc));
+#endif
+}
+
+#undef vid_attr
+NCURSES_EXPORT(int)
+vid_attr(attr_t newmode, short pair, void *opts)
+{
+    T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), pair));
+    returnCode(vid_puts(newmode, pair, opts, _nc_outch));
+}
+
+/*
+ * This implementation uses the same mask values for A_xxx and WA_xxx, so
+ * we can use termattrs() for part of the logic.
+ */
+NCURSES_EXPORT(attr_t)
+term_attrs(void)
+{
+    attr_t attrs;
+
+    T((T_CALLED("term_attrs()")));
+    attrs = termattrs();
+
+    /* these are only supported for wide-character mode */
+    if (enter_horizontal_hl_mode)
+	attrs |= WA_HORIZONTAL;
+    if (enter_left_hl_mode)
+	attrs |= WA_LEFT;
+    if (enter_low_hl_mode)
+	attrs |= WA_LOW;
+    if (enter_right_hl_mode)
+	attrs |= WA_RIGHT;
+    if (enter_top_hl_mode)
+	attrs |= WA_TOP;
+    if (enter_vertical_hl_mode)
+	attrs |= WA_VERTICAL;
+
+    returnAttr(attrs);
+}
diff --git a/ncurses/widechar/lib_vline_set.c b/ncurses/widechar/lib_vline_set.c
new file mode 100644
index 0000000..af42df1
--- /dev/null
+++ b/ncurses/widechar/lib_vline_set.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas Dickey 2002                                              *
+ ****************************************************************************/
+
+/*
+**	lib_vline_set.c
+**
+**	The routine wvline_set().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_vline_set.c,v 1.2 2002/03/23 21:36:01 tom Exp $")
+
+NCURSES_EXPORT(int)
+wvline_set(WINDOW *win, const cchar_t * ch, int n)
+{
+    int code = ERR;
+    NCURSES_SIZE_T row, col;
+    NCURSES_SIZE_T end;
+
+    T((T_CALLED("wvline(%p,%s,%d)"), win, _tracecchar_t(ch), n));
+
+    if (win) {
+	NCURSES_CH_T wch;
+	row = win->_cury;
+	col = win->_curx;
+	end = row + n - 1;
+	if (end > win->_maxy)
+	    end = win->_maxy;
+
+	if (ch == 0)
+	    wch = *WACS_VLINE;
+	else
+	    wch = *ch;
+	wch = _nc_render(win, wch);
+
+	while (end >= row) {
+	    struct ldat *line = &(win->_line[end]);
+	    line->text[col] = wch;
+	    CHANGED_CELL(line, col);
+	    end--;
+	}
+
+	_nc_synchook(win);
+	code = OK;
+    }
+    returnCode(code);
+}
diff --git a/ncurses/widechar/lib_wacs.c b/ncurses/widechar/lib_wacs.c
new file mode 100644
index 0000000..fe893b4
--- /dev/null
+++ b/ncurses/widechar/lib_wacs.c
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * Copyright (c) 2002,2006 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/****************************************************************************
+ *  Author: Thomas Dickey 2002                                              *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>
+
+MODULE_ID("$Id: lib_wacs.c,v 1.7 2006/12/17 15:16:17 tom Exp $")
+
+NCURSES_EXPORT_VAR(cchar_t) * _nc_wacs = 0;
+
+NCURSES_EXPORT(void)
+_nc_init_wacs(void)
+{
+    /* *INDENT-OFF* */
+    static const struct {
+	int	map;
+	int	value[2];
+    } table[] = {
+	/* VT100 symbols */
+	{ 'l',	{ '+',	0x250c }},	/* upper left corner */
+	{ 'm',	{ '+',	0x2514 }},	/* lower left corner */
+	{ 'k',	{ '+',	0x2510 }},	/* upper right corner */
+	{ 'j',	{ '+',	0x2518 }},	/* lower right corner */
+	{ 't',	{ '+',	0x251c }},	/* tee pointing left */
+	{ 'u',	{ '+',	0x2524 }},	/* tee pointing right */
+	{ 'v',	{ '+',	0x2534 }},	/* tee pointing up */
+	{ 'w',	{ '+',	0x252c }},	/* tee pointing down */
+	{ 'q',	{ '-',	0x2500 }},	/* horizontal line */
+	{ 'x',	{ '|',	0x2502 }},	/* vertical line */
+	{ 'n',	{ '+',	0x253c }},	/* large plus or crossover */
+	{ 'o',	{ '~',	0x23ba }},	/* scan line 1 */
+	{ 's',	{ '_',	0x23bd }},	/* scan line 9 */
+	{ '`',	{ '+',	0x25c6 }},	/* diamond */
+	{ 'a',	{ ':',	0x2592 }},	/* checker board (stipple) */
+	{ 'f',	{ '\'',	0x00b0 }},	/* degree symbol */
+	{ 'g',	{ '#',	0x00b1 }},	/* plus/minus */
+	{ '~',	{ 'o',	0x00b7 }},	/* bullet */
+	/* Teletype 5410v1 symbols */
+	{ ',',	{ '<',	0x2190 }},	/* arrow pointing left */
+	{ '+',	{ '>',	0x2192 }},	/* arrow pointing right */
+	{ '.',	{ 'v',	0x2193 }},	/* arrow pointing down */
+	{ '-',	{ '^',	0x2191 }},	/* arrow pointing up */
+	{ 'h',	{ '#',	0x2592 }},	/* board of squares */
+	{ 'i',	{ '#',	0x2603 }},	/* lantern symbol */
+	{ '0',	{ '#',	0x25ae }},	/* solid square block */
+	/* these defaults were invented for ncurses */
+	{ 'p',	{ '-',	0x23bb }},	/* scan line 3 */
+	{ 'r',	{ '-',	0x23bc }},	/* scan line 7 */
+	{ 'y',	{ '<',	0x2264 }},	/* less-than-or-equal-to */
+	{ 'z',	{ '>',	0x2265 }},	/* greater-than-or-equal-to */
+	{ '{',	{ '*',	0x03c0 }},	/* greek pi */
+	{ '|',	{ '!',	0x2260 }},	/* not-equal */
+	{ '}',	{ 'f',	0x00a3 }},	/* pound-sterling symbol */
+    };
+    /* *INDENT-ON* */
+
+    unsigned n, m;
+    int active = _nc_unicode_locale();
+
+    /*
+     * If we're running in a UTF-8 locale, will use the Unicode equivalents
+     * rather than the terminfo information.  Actually the terminfo should
+     * be the rule, but there are people who are offended by the notion that
+     * a Unicode-capable terminal would have something resembling a mode.
+     * So the smacs/rmacs may be disabled -- sometime.
+     */
+    T(("initializing WIDE-ACS map (Unicode is%s active)",
+       active ? "" : " not"));
+
+    _nc_wacs = typeCalloc(cchar_t, ACS_LEN);
+    for (n = 0; n < SIZEOF(table); ++n) {
+	int wide = wcwidth(table[n].value[active]);
+
+	m = table[n].map;
+	if (active && (wide == 1)) {
+	    SetChar(_nc_wacs[m], table[n].value[active], A_NORMAL);
+	} else if (acs_map[m] & A_ALTCHARSET) {
+	    SetChar(_nc_wacs[m], m, A_ALTCHARSET);
+	} else {
+	    SetChar(_nc_wacs[m], table[n].value[0], A_NORMAL);
+	}
+
+	T(("#%d, SetChar(%c, %#04x) = %s",
+	   n, m,
+	   table[n].value[active],
+	   _tracecchar_t(&_nc_wacs[m])));
+    }
+}
diff --git a/ncurses/widechar/lib_wunctrl.c b/ncurses/widechar/lib_wunctrl.c
new file mode 100644
index 0000000..be2259a
--- /dev/null
+++ b/ncurses/widechar/lib_wunctrl.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 2001-2005,2007 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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.                                                           *
+ ****************************************************************************/
+
+/*
+**	lib_wunctrl.c
+**
+**	The routine wunctrl().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_wunctrl.c,v 1.12 2007/06/12 20:22:32 tom Exp $")
+
+NCURSES_EXPORT(wchar_t *)
+wunctrl(cchar_t *wc)
+{
+    static wchar_t str[CCHARW_MAX + 1], *sp;
+
+    if (Charable(*wc)) {
+	const char *p = unctrl((unsigned) _nc_to_char((wint_t) CharOf(*wc)));
+
+	for (sp = str; *p; ++p) {
+	    *sp++ = _nc_to_widechar(*p);
+	}
+	*sp = 0;
+	return str;
+    } else
+	return wc->chars;
+}