Update to ncurses-6.0

Change-Id: I98ab2ea8a5e13cca9f8b7cf6277b9b14a4da4299
diff --git a/ncurses/Makefile b/ncurses/Makefile
deleted file mode 100644
index cf9bbab..0000000
--- a/ncurses/Makefile
+++ /dev/null
@@ -1,2022 +0,0 @@
-# $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 	= 
-
-
-x		= 
-o		= .o
-
-MODEL		= normal
-DESTDIR		= 
-top_srcdir	= ..
-srcdir		= .
-prefix		= /usr/local
-exec_prefix	= ${prefix}
-bindir		= ${exec_prefix}/bin
-libdir		= ${exec_prefix}/lib
-includedir	= ${prefix}/include/ncurses
-datadir		= ${prefix}/share
-
-LIBTOOL		= 
-LIBTOOL_CLEAN	= 
-LIBTOOL_COMPILE	= 
-LIBTOOL_LINK	= ${CC}
-LIBTOOL_INSTALL	= 
-LIBTOOL_UNINSTALL = 
-
-INSTALL		= /usr/bin/install -c
-INSTALL_LIB	= /usr/bin/install -c -m 644
-INSTALL_PROG	= ${INSTALL}
-INSTALL_DATA	= ${INSTALL} -m 644
-
-AR		= arm-eabi-ar
-AR_OPTS		= rv
-AWK		= mawk
-LD		= arm-eabi-ld
-LN_S		= ln -s
-
-CC		= agcc.pl
-CPP		= agcc.pl -E
-CFLAGS		= -O2 --param max-inline-insns-single=1200
-
-INCDIR		= $(srcdir)/../include
-CPPFLAGS	= -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) -I. -I../include  -U_XOPEN_SOURCE -D_XOPEN_SOURCE=500 -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=199506L -DNDEBUG -I${includedir}
-
-CCFLAGS		= $(CPPFLAGS) $(CFLAGS)
-
-BUILD_CPPFLAGS	= -I../include 
-BUILD_CC	= gcc
-BUILD_CCFLAGS	= -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) -I$(INCDIR) $(BUILD_CPPFLAGS) 
-BUILD_LDFLAGS	= 
-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	= 
-x		= 
-
-CFLAGS_LIBTOOL	= $(CCFLAGS)
-CFLAGS_NORMAL	= $(CCFLAGS)
-CFLAGS_DEBUG	= $(CCFLAGS) -g -DTRACE
-CFLAGS_PROFILE	= $(CCFLAGS) -pg
-CFLAGS_SHARED	= $(CCFLAGS) unknown
-
-CFLAGS_DEFAULT	= $(CFLAGS_NORMAL)
-
-LINK		= $(LIBTOOL)
-LDFLAGS		=   
-
-SHLIB_DIRS	= -L../lib
-SHLIB_LIST	= $(SHLIB_DIRS) 
-TINFO_LIST	= $(SHLIB_DIRS) 
-TICS_LIST	= $(SHLIB_DIRS) 
-
-MK_SHARED_LIB	= echo unknown
-
-NCURSES_MAJOR	= 5
-NCURSES_MINOR	= 7
-REL_VERSION	= 5.7
-ABI_VERSION	= 5
-
-RANLIB		= arm-eabi-ranlib
-
-LIBRARIES	=  ../lib/libncurses.a ../lib/libncurses_g.a
-
-LINT		= 
-LINT_OPTS	= 
-LINT_LIBS	= -lncurses 
-
-FALLBACK_LIST	= 
-
-USE_BIG_STRINGS	= 1
-TERMINFO_CAPS	= $(top_srcdir)/include/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/libncurses.a
-TEST_ARGS	= -static -L../lib -lform -lmenu -lpanel -lncurses  -dynamic 
-TEST_LDFLAGS	=  $(TEST_ARGS)   
-
-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 /usr/local/share/terminfo ${top_srcdir}/misc/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/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/Caps >$@
-
-./names.c: $(tinfo)/MKnames.awk
-	$(AWK) -f $(tinfo)/MKnames.awk bigstrings=$(USE_BIG_STRINGS) $(srcdir)/../include/Caps >$@
-
-./unctrl.c: $(base)/MKunctrl.awk
-	echo | $(AWK) -f $(base)/MKunctrl.awk bigstrings=$(USE_BIG_STRINGS) >$@
-
-tags:
-	ctags *.[ch] */*.[ch]
-
-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)
-	 $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DMAIN $(tinfo)/captoinfo.c $(TEST_LDFLAGS)
-
-hardscroll$x : $(serial)/hardscroll.c $(TEST_DEPS)
-	 $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DSCROLLDEBUG $(serial)/hardscroll.c $(TEST_LDFLAGS)
-
-hashmap$x : $(serial)/hashmap.c $(serial)/hardscroll.c $(TEST_DEPS)
-	 $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DHASHDEBUG $(serial)/hashmap.c $(serial)/hardscroll.c $(TEST_LDFLAGS)
-
-lib_mvcur$x : $(serial)/lib_mvcur.c $(TEST_DEPS) \
-		../objects/dump_entry$o
-	 $(LIBTOOL_LINK) -o $@ $(CFLAGS_DEFAULT) -DNCURSES_TEST -I$(serial)/../../progs $(serial)/lib_mvcur.c ../objects/dump_entry$o $(TEST_LDFLAGS)
-
-link_test$x : ./link_test.c $(TEST_DEPS) \
-		../objects/link_test$o
-	 $(CC) -o $@ $(CFLAGS_DEFAULT) ../objects/link_test$o $(TEST_LDFLAGS)
-
-../objects/dump_entry$o:
-	cd ../progs && $(MAKE) ../objects/dump_entry$o
-
-###############################################################################
-# The remainder of this file is automatically generated during configuration
-###############################################################################
-
-# generated by mk-0th.awk
-#   libname:    ncurses
-#   subsets:    ticlib+termlib+ext_tinfo+base+ext_funcs
-
-.SUFFIXES: .c .cc .h .i .ii
-.c.i :
-	$(CPP) $(CPPFLAGS) $< >$@
-.cc.ii :
-	$(CPP) $(CPPFLAGS) $< >$@
-.h.i :
-	$(CPP) $(CPPFLAGS) $< >$@
-
-C_SRC = \
-	$(serial)/hardscroll.c \
-	$(serial)/hashmap.c \
-	$(base)/lib_addch.c \
-	$(base)/lib_addstr.c \
-	$(base)/lib_beep.c \
-	$(base)/lib_bkgd.c \
-	$(base)/lib_box.c \
-	$(base)/lib_chgat.c \
-	$(base)/lib_clear.c \
-	$(base)/lib_clearok.c \
-	$(base)/lib_clrbot.c \
-	$(base)/lib_clreol.c \
-	$(base)/lib_color.c \
-	$(base)/lib_colorset.c \
-	$(base)/lib_delch.c \
-	$(base)/lib_delwin.c \
-	$(base)/lib_echo.c \
-	$(base)/lib_endwin.c \
-	$(base)/lib_erase.c \
-	$(base)/lib_flash.c \
-	./lib_gen.c \
-	$(base)/lib_getch.c \
-	$(base)/lib_getstr.c \
-	$(base)/lib_hline.c \
-	$(base)/lib_immedok.c \
-	$(base)/lib_inchstr.c \
-	$(base)/lib_initscr.c \
-	$(base)/lib_insch.c \
-	$(base)/lib_insdel.c \
-	$(base)/lib_insnstr.c \
-	$(base)/lib_instr.c \
-	$(base)/lib_isendwin.c \
-	$(base)/lib_leaveok.c \
-	$(base)/lib_mouse.c \
-	$(base)/lib_move.c \
-	$(serial)/lib_mvcur.c \
-	$(base)/lib_mvwin.c \
-	$(base)/lib_newterm.c \
-	$(base)/lib_newwin.c \
-	$(base)/lib_nl.c \
-	$(base)/lib_overlay.c \
-	$(base)/lib_pad.c \
-	$(base)/lib_printw.c \
-	$(base)/lib_redrawln.c \
-	$(base)/lib_refresh.c \
-	$(base)/lib_restart.c \
-	$(base)/lib_scanw.c \
-	$(base)/lib_screen.c \
-	$(base)/lib_scroll.c \
-	$(base)/lib_scrollok.c \
-	$(base)/lib_scrreg.c \
-	$(base)/lib_set_term.c \
-	$(base)/lib_slk.c \
-	$(base)/lib_slkatr_set.c \
-	$(base)/lib_slkatrof.c \
-	$(base)/lib_slkatron.c \
-	$(base)/lib_slkatrset.c \
-	$(base)/lib_slkattr.c \
-	$(base)/lib_slkclear.c \
-	$(base)/lib_slkcolor.c \
-	$(base)/lib_slkinit.c \
-	$(base)/lib_slklab.c \
-	$(base)/lib_slkrefr.c \
-	$(base)/lib_slkset.c \
-	$(base)/lib_slktouch.c \
-	$(base)/lib_touch.c \
-	$(trace)/lib_tracedmp.c \
-	$(trace)/lib_tracemse.c \
-	$(serial)/lib_tstp.c \
-	$(base)/lib_ungetch.c \
-	$(serial)/lib_vidattr.c \
-	$(base)/lib_vline.c \
-	$(base)/lib_wattroff.c \
-	$(base)/lib_wattron.c \
-	$(base)/lib_winch.c \
-	$(base)/lib_window.c \
-	$(base)/nc_panel.c \
-	$(base)/safe_sprintf.c \
-	$(serial)/tty_update.c \
-	$(trace)/varargs.c \
-	$(base)/memmove.c \
-	$(base)/vsscanf.c \
-	$(base)/lib_freeall.c \
-	./expanded.c \
-	$(base)/legacy_coding.c \
-	$(base)/lib_dft_fgbg.c \
-	$(tinfo)/lib_print.c \
-	$(base)/resizeterm.c \
-	$(trace)/trace_xnames.c \
-	$(tinfo)/use_screen.c \
-	$(base)/use_window.c \
-	$(base)/wresize.c \
-	$(tinfo)/access.c \
-	$(tinfo)/add_tries.c \
-	$(tinfo)/alloc_ttype.c \
-	./codes.c \
-	$(tinfo)/comp_error.c \
-	$(tinfo)/db_iterator.c \
-	$(tinfo)/doalloc.c \
-	$(tinfo)/entries.c \
-	./fallback.c \
-	$(tinfo)/free_ttype.c \
-	$(tinfo)/getenv_num.c \
-	$(tinfo)/home_terminfo.c \
-	$(tinfo)/init_keytry.c \
-	$(tinfo)/lib_acs.c \
-	$(tinfo)/lib_baudrate.c \
-	$(tinfo)/lib_cur_term.c \
-	$(tinfo)/lib_data.c \
-	$(tinfo)/lib_has_cap.c \
-	$(tinfo)/lib_kernel.c \
-	./lib_keyname.c \
-	$(tinfo)/lib_longname.c \
-	$(tinfo)/lib_napms.c \
-	$(tinfo)/lib_options.c \
-	$(tinfo)/lib_raw.c \
-	$(tinfo)/lib_setup.c \
-	$(tinfo)/lib_termcap.c \
-	$(tinfo)/lib_termname.c \
-	$(tinfo)/lib_tgoto.c \
-	$(tinfo)/lib_ti.c \
-	$(tinfo)/lib_tparm.c \
-	$(tinfo)/lib_tputs.c \
-	$(trace)/lib_trace.c \
-	$(trace)/lib_traceatr.c \
-	$(trace)/lib_tracebits.c \
-	$(trace)/lib_tracechr.c \
-	$(tinfo)/lib_ttyflags.c \
-	$(serial)/lib_twait.c \
-	$(tinfo)/name_match.c \
-	./names.c \
-	$(tinfo)/read_entry.c \
-	$(tinfo)/read_termcap.c \
-	$(tinfo)/setbuf.c \
-	$(tinfo)/strings.c \
-	$(trace)/trace_buf.c \
-	$(trace)/trace_tries.c \
-	$(base)/tries.c \
-	$(tinfo)/trim_sgr0.c \
-	./unctrl.c \
-	$(trace)/visbuf.c \
-	$(tinfo)/alloc_entry.c \
-	$(tinfo)/captoinfo.c \
-	./comp_captab.c \
-	$(tinfo)/comp_expand.c \
-	$(tinfo)/comp_hash.c \
-	$(tinfo)/comp_parse.c \
-	$(tinfo)/comp_scan.c \
-	$(tinfo)/parse_entry.c \
-	$(tinfo)/write_entry.c \
-	$(base)/define_key.c \
-	$(tinfo)/hashed_db.c \
-	$(base)/key_defined.c \
-	$(base)/keybound.c \
-	$(base)/keyok.c \
-	$(base)/version.c
-
-# Producing llib-lncurses is time-consuming, so there's no direct-dependency for
-# it in the lintlib rule.  We'll only remove in the cleanest setup.
-clean ::
-	rm -f llib-lncurses.*
-
-realclean ::
-	rm -f llib-lncurses
-
-llib-lncurses : $(C_SRC)
-	cproto -a -l -DNCURSES_ENABLE_STDBOOL_H=0 -DLINT $(CPPFLAGS) $(C_SRC) >$@
-
-lintlib :
-	sh $(srcdir)/../misc/makellib ncurses $(CPPFLAGS)
-lint :
-	$(LINT) $(LINT_OPTS) $(CPPFLAGS) $(C_SRC) $(LINT_LIBS)
-
-# generated by mk-1st.awk (subset=ticlib+termlib+ext_tinfo+base+ext_funcs)
-#  name:          ncurses
-#  traces:        DEBUG
-#  MODEL:         NORMAL
-#  model:         objects
-#  prefix:        lib
-#  suffix:        .a
-#  subset:        ticlib+termlib+ext_tinfo+base+ext_funcs
-#  ShlibVer:      auto
-#  ShlibVerInfix: no
-#  TermlibRoot:   ncurses
-#  TermlibSuffix: .a
-#  ReLink:        
-#  DoLinks:       no
-#  rmSoLocs:      no
-#  ldconfig:      :
-#  overwrite:     no
-#  depend:        ../include/ncurses_cfg.h ./curses.priv.h
-#  host:          arm-unknown-eabi
-
-NORMAL_OBJS = \
-	../objects/hardscroll$o \
-	../objects/hashmap$o \
-	../objects/lib_addch$o \
-	../objects/lib_addstr$o \
-	../objects/lib_beep$o \
-	../objects/lib_bkgd$o \
-	../objects/lib_box$o \
-	../objects/lib_chgat$o \
-	../objects/lib_clear$o \
-	../objects/lib_clearok$o \
-	../objects/lib_clrbot$o \
-	../objects/lib_clreol$o \
-	../objects/lib_color$o \
-	../objects/lib_colorset$o \
-	../objects/lib_delch$o \
-	../objects/lib_delwin$o \
-	../objects/lib_echo$o \
-	../objects/lib_endwin$o \
-	../objects/lib_erase$o \
-	../objects/lib_flash$o \
-	../objects/lib_gen$o \
-	../objects/lib_getch$o \
-	../objects/lib_getstr$o \
-	../objects/lib_hline$o \
-	../objects/lib_immedok$o \
-	../objects/lib_inchstr$o \
-	../objects/lib_initscr$o \
-	../objects/lib_insch$o \
-	../objects/lib_insdel$o \
-	../objects/lib_insnstr$o \
-	../objects/lib_instr$o \
-	../objects/lib_isendwin$o \
-	../objects/lib_leaveok$o \
-	../objects/lib_mouse$o \
-	../objects/lib_move$o \
-	../objects/lib_mvcur$o \
-	../objects/lib_mvwin$o \
-	../objects/lib_newterm$o \
-	../objects/lib_newwin$o \
-	../objects/lib_nl$o \
-	../objects/lib_overlay$o \
-	../objects/lib_pad$o \
-	../objects/lib_printw$o \
-	../objects/lib_redrawln$o \
-	../objects/lib_refresh$o \
-	../objects/lib_restart$o \
-	../objects/lib_scanw$o \
-	../objects/lib_screen$o \
-	../objects/lib_scroll$o \
-	../objects/lib_scrollok$o \
-	../objects/lib_scrreg$o \
-	../objects/lib_set_term$o \
-	../objects/lib_slk$o \
-	../objects/lib_slkatr_set$o \
-	../objects/lib_slkatrof$o \
-	../objects/lib_slkatron$o \
-	../objects/lib_slkatrset$o \
-	../objects/lib_slkattr$o \
-	../objects/lib_slkclear$o \
-	../objects/lib_slkcolor$o \
-	../objects/lib_slkinit$o \
-	../objects/lib_slklab$o \
-	../objects/lib_slkrefr$o \
-	../objects/lib_slkset$o \
-	../objects/lib_slktouch$o \
-	../objects/lib_touch$o \
-	../objects/lib_tstp$o \
-	../objects/lib_ungetch$o \
-	../objects/lib_vidattr$o \
-	../objects/lib_vline$o \
-	../objects/lib_wattroff$o \
-	../objects/lib_wattron$o \
-	../objects/lib_winch$o \
-	../objects/lib_window$o \
-	../objects/nc_panel$o \
-	../objects/safe_sprintf$o \
-	../objects/tty_update$o \
-	../objects/varargs$o \
-	../objects/memmove$o \
-	../objects/vsscanf$o \
-	../objects/lib_freeall$o \
-	../objects/expanded$o \
-	../objects/legacy_coding$o \
-	../objects/lib_dft_fgbg$o \
-	../objects/lib_print$o \
-	../objects/resizeterm$o \
-	../objects/use_screen$o \
-	../objects/use_window$o \
-	../objects/wresize$o \
-	../objects/access$o \
-	../objects/add_tries$o \
-	../objects/alloc_ttype$o \
-	../objects/codes$o \
-	../objects/comp_error$o \
-	../objects/db_iterator$o \
-	../objects/doalloc$o \
-	../objects/entries$o \
-	../objects/fallback$o \
-	../objects/free_ttype$o \
-	../objects/getenv_num$o \
-	../objects/home_terminfo$o \
-	../objects/init_keytry$o \
-	../objects/lib_acs$o \
-	../objects/lib_baudrate$o \
-	../objects/lib_cur_term$o \
-	../objects/lib_data$o \
-	../objects/lib_has_cap$o \
-	../objects/lib_kernel$o \
-	../objects/lib_keyname$o \
-	../objects/lib_longname$o \
-	../objects/lib_napms$o \
-	../objects/lib_options$o \
-	../objects/lib_raw$o \
-	../objects/lib_setup$o \
-	../objects/lib_termcap$o \
-	../objects/lib_termname$o \
-	../objects/lib_tgoto$o \
-	../objects/lib_ti$o \
-	../objects/lib_tparm$o \
-	../objects/lib_tputs$o \
-	../objects/lib_trace$o \
-	../objects/lib_ttyflags$o \
-	../objects/lib_twait$o \
-	../objects/name_match$o \
-	../objects/names$o \
-	../objects/read_entry$o \
-	../objects/read_termcap$o \
-	../objects/setbuf$o \
-	../objects/strings$o \
-	../objects/tries$o \
-	../objects/trim_sgr0$o \
-	../objects/unctrl$o \
-	../objects/visbuf$o \
-	../objects/alloc_entry$o \
-	../objects/captoinfo$o \
-	../objects/comp_captab$o \
-	../objects/comp_expand$o \
-	../objects/comp_hash$o \
-	../objects/comp_parse$o \
-	../objects/comp_scan$o \
-	../objects/parse_entry$o \
-	../objects/write_entry$o \
-	../objects/define_key$o \
-	../objects/hashed_db$o \
-	../objects/key_defined$o \
-	../objects/keybound$o \
-	../objects/keyok$o \
-	../objects/version$o
-
-$(NORMAL_OBJS) : ../include/ncurses_cfg.h ./curses.priv.h
-
-../lib/libncurses.a : $(NORMAL_OBJS)
-	$(AR) $(AR_OPTS) $@ $?
-	$(RANLIB) $@
-
-install \
-install.libs \
-install.ncurses :: $(DESTDIR)$(libdir) ../lib/libncurses.a
-	@echo installing ../lib/libncurses.a as $(DESTDIR)$(libdir)/libncurses.a
-	$(INSTALL_DATA) ../lib/libncurses.a $(DESTDIR)$(libdir)/libncurses.a
-	$(RANLIB) $(DESTDIR)$(libdir)/libncurses.a
-
-uninstall \
-uninstall.libs \
-uninstall.ncurses ::
-	@echo uninstalling $(DESTDIR)$(libdir)/libncurses.a
-	-@rm -f $(DESTDIR)$(libdir)/libncurses.a
-
-clean ::
-	-rm -f ../lib/libncurses.a
-
-mostlyclean::
-	-rm -f $(NORMAL_OBJS)
-
-# generated by mk-2nd.awk
-#   model:      objects
-#   MODEL:      NORMAL
-#   echo:       yes
-#   subset:     ticlib+termlib+ext_tinfo+base+ext_funcs
-#   crenames:   yes
-#   cxxrenames: no
-#   traces:     DEBUG
-#   srcdir:     .
-
-../objects/hardscroll$o :	$(serial)/hardscroll.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(serial)/hardscroll.c -o ../objects/hardscroll$o
-
-../objects/hashmap$o :	$(serial)/hashmap.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(serial)/hashmap.c -o ../objects/hashmap$o
-
-../objects/lib_addch$o :	$(base)/lib_addch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_addch.c -o ../objects/lib_addch$o
-
-../objects/lib_addstr$o :	$(base)/lib_addstr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_addstr.c -o ../objects/lib_addstr$o
-
-../objects/lib_beep$o :	$(base)/lib_beep.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_beep.c -o ../objects/lib_beep$o
-
-../objects/lib_bkgd$o :	$(base)/lib_bkgd.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_bkgd.c -o ../objects/lib_bkgd$o
-
-../objects/lib_box$o :	$(base)/lib_box.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_box.c -o ../objects/lib_box$o
-
-../objects/lib_chgat$o :	$(base)/lib_chgat.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_chgat.c -o ../objects/lib_chgat$o
-
-../objects/lib_clear$o :	$(base)/lib_clear.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_clear.c -o ../objects/lib_clear$o
-
-../objects/lib_clearok$o :	$(base)/lib_clearok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_clearok.c -o ../objects/lib_clearok$o
-
-../objects/lib_clrbot$o :	$(base)/lib_clrbot.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_clrbot.c -o ../objects/lib_clrbot$o
-
-../objects/lib_clreol$o :	$(base)/lib_clreol.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_clreol.c -o ../objects/lib_clreol$o
-
-../objects/lib_color$o :	$(base)/lib_color.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_color.c -o ../objects/lib_color$o
-
-../objects/lib_colorset$o :	$(base)/lib_colorset.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_colorset.c -o ../objects/lib_colorset$o
-
-../objects/lib_delch$o :	$(base)/lib_delch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_delch.c -o ../objects/lib_delch$o
-
-../objects/lib_delwin$o :	$(base)/lib_delwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_delwin.c -o ../objects/lib_delwin$o
-
-../objects/lib_echo$o :	$(base)/lib_echo.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_echo.c -o ../objects/lib_echo$o
-
-../objects/lib_endwin$o :	$(base)/lib_endwin.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_endwin.c -o ../objects/lib_endwin$o
-
-../objects/lib_erase$o :	$(base)/lib_erase.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_erase.c -o ../objects/lib_erase$o
-
-../objects/lib_flash$o :	$(base)/lib_flash.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_flash.c -o ../objects/lib_flash$o
-
-../objects/lib_gen$o :	./lib_gen.c \
-			../include/curses.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/lib_gen.c -o ../objects/lib_gen$o
-
-../objects/lib_getch$o :	$(base)/lib_getch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_getch.c -o ../objects/lib_getch$o
-
-../objects/lib_getstr$o :	$(base)/lib_getstr.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_getstr.c -o ../objects/lib_getstr$o
-
-../objects/lib_hline$o :	$(base)/lib_hline.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_hline.c -o ../objects/lib_hline$o
-
-../objects/lib_immedok$o :	$(base)/lib_immedok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_immedok.c -o ../objects/lib_immedok$o
-
-../objects/lib_inchstr$o :	$(base)/lib_inchstr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_inchstr.c -o ../objects/lib_inchstr$o
-
-../objects/lib_initscr$o :	$(base)/lib_initscr.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_initscr.c -o ../objects/lib_initscr$o
-
-../objects/lib_insch$o :	$(base)/lib_insch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_insch.c -o ../objects/lib_insch$o
-
-../objects/lib_insdel$o :	$(base)/lib_insdel.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_insdel.c -o ../objects/lib_insdel$o
-
-../objects/lib_insnstr$o :	$(base)/lib_insnstr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_insnstr.c -o ../objects/lib_insnstr$o
-
-../objects/lib_instr$o :	$(base)/lib_instr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_instr.c -o ../objects/lib_instr$o
-
-../objects/lib_isendwin$o :	$(base)/lib_isendwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_isendwin.c -o ../objects/lib_isendwin$o
-
-../objects/lib_leaveok$o :	$(base)/lib_leaveok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_leaveok.c -o ../objects/lib_leaveok$o
-
-../objects/lib_mouse$o :	$(base)/lib_mouse.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_mouse.c -o ../objects/lib_mouse$o
-
-../objects/lib_move$o :	$(base)/lib_move.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_move.c -o ../objects/lib_move$o
-
-../objects/lib_mvcur$o :	$(serial)/lib_mvcur.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(serial)/lib_mvcur.c -o ../objects/lib_mvcur$o
-
-../objects/lib_mvwin$o :	$(base)/lib_mvwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_mvwin.c -o ../objects/lib_mvwin$o
-
-../objects/lib_newterm$o :	$(base)/lib_newterm.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_newterm.c -o ../objects/lib_newterm$o
-
-../objects/lib_newwin$o :	$(base)/lib_newwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_newwin.c -o ../objects/lib_newwin$o
-
-../objects/lib_nl$o :	$(base)/lib_nl.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_nl.c -o ../objects/lib_nl$o
-
-../objects/lib_overlay$o :	$(base)/lib_overlay.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_overlay.c -o ../objects/lib_overlay$o
-
-../objects/lib_pad$o :	$(base)/lib_pad.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_pad.c -o ../objects/lib_pad$o
-
-../objects/lib_printw$o :	$(base)/lib_printw.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_printw.c -o ../objects/lib_printw$o
-
-../objects/lib_redrawln$o :	$(base)/lib_redrawln.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_redrawln.c -o ../objects/lib_redrawln$o
-
-../objects/lib_refresh$o :	$(base)/lib_refresh.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_refresh.c -o ../objects/lib_refresh$o
-
-../objects/lib_restart$o :	$(base)/lib_restart.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_restart.c -o ../objects/lib_restart$o
-
-../objects/lib_scanw$o :	$(base)/lib_scanw.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_scanw.c -o ../objects/lib_scanw$o
-
-../objects/lib_screen$o :	$(base)/lib_screen.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_screen.c -o ../objects/lib_screen$o
-
-../objects/lib_scroll$o :	$(base)/lib_scroll.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_scroll.c -o ../objects/lib_scroll$o
-
-../objects/lib_scrollok$o :	$(base)/lib_scrollok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_scrollok.c -o ../objects/lib_scrollok$o
-
-../objects/lib_scrreg$o :	$(base)/lib_scrreg.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_scrreg.c -o ../objects/lib_scrreg$o
-
-../objects/lib_set_term$o :	$(base)/lib_set_term.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_set_term.c -o ../objects/lib_set_term$o
-
-../objects/lib_slk$o :	$(base)/lib_slk.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slk.c -o ../objects/lib_slk$o
-
-../objects/lib_slkatr_set$o :	$(base)/lib_slkatr_set.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkatr_set.c -o ../objects/lib_slkatr_set$o
-
-../objects/lib_slkatrof$o :	$(base)/lib_slkatrof.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkatrof.c -o ../objects/lib_slkatrof$o
-
-../objects/lib_slkatron$o :	$(base)/lib_slkatron.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkatron.c -o ../objects/lib_slkatron$o
-
-../objects/lib_slkatrset$o :	$(base)/lib_slkatrset.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkatrset.c -o ../objects/lib_slkatrset$o
-
-../objects/lib_slkattr$o :	$(base)/lib_slkattr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkattr.c -o ../objects/lib_slkattr$o
-
-../objects/lib_slkclear$o :	$(base)/lib_slkclear.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkclear.c -o ../objects/lib_slkclear$o
-
-../objects/lib_slkcolor$o :	$(base)/lib_slkcolor.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkcolor.c -o ../objects/lib_slkcolor$o
-
-../objects/lib_slkinit$o :	$(base)/lib_slkinit.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkinit.c -o ../objects/lib_slkinit$o
-
-../objects/lib_slklab$o :	$(base)/lib_slklab.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slklab.c -o ../objects/lib_slklab$o
-
-../objects/lib_slkrefr$o :	$(base)/lib_slkrefr.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkrefr.c -o ../objects/lib_slkrefr$o
-
-../objects/lib_slkset$o :	$(base)/lib_slkset.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slkset.c -o ../objects/lib_slkset$o
-
-../objects/lib_slktouch$o :	$(base)/lib_slktouch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_slktouch.c -o ../objects/lib_slktouch$o
-
-../objects/lib_touch$o :	$(base)/lib_touch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_touch.c -o ../objects/lib_touch$o
-
-../objects/lib_tstp$o :	$(serial)/lib_tstp.c \
-			$(srcdir)/SigAction.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(serial)/lib_tstp.c -o ../objects/lib_tstp$o
-
-../objects/lib_ungetch$o :	$(base)/lib_ungetch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_ungetch.c -o ../objects/lib_ungetch$o
-
-../objects/lib_vidattr$o :	$(serial)/lib_vidattr.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(serial)/lib_vidattr.c -o ../objects/lib_vidattr$o
-
-../objects/lib_vline$o :	$(base)/lib_vline.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_vline.c -o ../objects/lib_vline$o
-
-../objects/lib_wattroff$o :	$(base)/lib_wattroff.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_wattroff.c -o ../objects/lib_wattroff$o
-
-../objects/lib_wattron$o :	$(base)/lib_wattron.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_wattron.c -o ../objects/lib_wattron$o
-
-../objects/lib_winch$o :	$(base)/lib_winch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_winch.c -o ../objects/lib_winch$o
-
-../objects/lib_window$o :	$(base)/lib_window.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_window.c -o ../objects/lib_window$o
-
-../objects/link_test$o :	./link_test.c \
-			../include/curses.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/link_test.c -o ../objects/link_test$o
-
-../objects/nc_panel$o :	$(base)/nc_panel.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/nc_panel.c -o ../objects/nc_panel$o
-
-../objects/safe_sprintf$o :	$(base)/safe_sprintf.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/safe_sprintf.c -o ../objects/safe_sprintf$o
-
-../objects/tty_update$o :	$(serial)/tty_update.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(serial)/tty_update.c -o ../objects/tty_update$o
-
-../objects/varargs$o :	$(trace)/varargs.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(trace)/varargs.c -o ../objects/varargs$o
-
-../objects/memmove$o :	$(base)/memmove.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/memmove.c -o ../objects/memmove$o
-
-../objects/vsscanf$o :	$(base)/vsscanf.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/vsscanf.c -o ../objects/vsscanf$o
-
-../objects/lib_freeall$o :	$(base)/lib_freeall.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_freeall.c -o ../objects/lib_freeall$o
-
-../objects/expanded$o :	./expanded.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/expanded.c -o ../objects/expanded$o
-
-../objects/legacy_coding$o :	$(base)/legacy_coding.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/legacy_coding.c -o ../objects/legacy_coding$o
-
-../objects/lib_dft_fgbg$o :	$(base)/lib_dft_fgbg.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/lib_dft_fgbg.c -o ../objects/lib_dft_fgbg$o
-
-../objects/lib_print$o :	$(tinfo)/lib_print.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_print.c -o ../objects/lib_print$o
-
-../objects/resizeterm$o :	$(base)/resizeterm.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/resizeterm.c -o ../objects/resizeterm$o
-
-../objects/use_screen$o :	$(tinfo)/use_screen.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/use_screen.c -o ../objects/use_screen$o
-
-../objects/use_window$o :	$(base)/use_window.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/use_window.c -o ../objects/use_window$o
-
-../objects/wresize$o :	$(base)/wresize.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/wresize.c -o ../objects/wresize$o
-
-../objects/access$o :	$(tinfo)/access.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/access.c -o ../objects/access$o
-
-../objects/add_tries$o :	$(tinfo)/add_tries.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/add_tries.c -o ../objects/add_tries$o
-
-../objects/alloc_ttype$o :	$(tinfo)/alloc_ttype.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/alloc_ttype.c -o ../objects/alloc_ttype$o
-
-../objects/codes$o :	./codes.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/codes.c -o ../objects/codes$o
-
-../objects/comp_error$o :	$(tinfo)/comp_error.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/comp_error.c -o ../objects/comp_error$o
-
-../objects/db_iterator$o :	$(tinfo)/db_iterator.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/db_iterator.c -o ../objects/db_iterator$o
-
-../objects/doalloc$o :	$(tinfo)/doalloc.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/doalloc.c -o ../objects/doalloc$o
-
-../objects/entries$o :	$(tinfo)/entries.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/entries.c -o ../objects/entries$o
-
-../objects/fallback$o :	./fallback.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/fallback.c -o ../objects/fallback$o
-
-../objects/free_ttype$o :	$(tinfo)/free_ttype.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/free_ttype.c -o ../objects/free_ttype$o
-
-../objects/getenv_num$o :	$(tinfo)/getenv_num.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/getenv_num.c -o ../objects/getenv_num$o
-
-../objects/home_terminfo$o :	$(tinfo)/home_terminfo.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/home_terminfo.c -o ../objects/home_terminfo$o
-
-../objects/init_keytry$o :	$(tinfo)/init_keytry.c \
-			../include/term.h \
-			$(INCDIR)/tic.h \
-			init_keytry.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/init_keytry.c -o ../objects/init_keytry$o
-
-../objects/lib_acs$o :	$(tinfo)/lib_acs.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_acs.c -o ../objects/lib_acs$o
-
-../objects/lib_baudrate$o :	$(tinfo)/lib_baudrate.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_baudrate.c -o ../objects/lib_baudrate$o
-
-../objects/lib_cur_term$o :	$(tinfo)/lib_cur_term.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_cur_term.c -o ../objects/lib_cur_term$o
-
-../objects/lib_data$o :	$(tinfo)/lib_data.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_data.c -o ../objects/lib_data$o
-
-../objects/lib_has_cap$o :	$(tinfo)/lib_has_cap.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_has_cap.c -o ../objects/lib_has_cap$o
-
-../objects/lib_kernel$o :	$(tinfo)/lib_kernel.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_kernel.c -o ../objects/lib_kernel$o
-
-../objects/lib_keyname$o :	./lib_keyname.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/lib_keyname.c -o ../objects/lib_keyname$o
-
-../objects/lib_longname$o :	$(tinfo)/lib_longname.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_longname.c -o ../objects/lib_longname$o
-
-../objects/lib_napms$o :	$(tinfo)/lib_napms.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_napms.c -o ../objects/lib_napms$o
-
-../objects/lib_options$o :	$(tinfo)/lib_options.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_options.c -o ../objects/lib_options$o
-
-../objects/lib_raw$o :	$(tinfo)/lib_raw.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_raw.c -o ../objects/lib_raw$o
-
-../objects/lib_setup$o :	$(tinfo)/lib_setup.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_setup.c -o ../objects/lib_setup$o
-
-../objects/lib_termcap$o :	$(tinfo)/lib_termcap.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h \
-			$(INCDIR)/capdefaults.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_termcap.c -o ../objects/lib_termcap$o
-
-../objects/lib_termname$o :	$(tinfo)/lib_termname.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_termname.c -o ../objects/lib_termname$o
-
-../objects/lib_tgoto$o :	$(tinfo)/lib_tgoto.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_tgoto.c -o ../objects/lib_tgoto$o
-
-../objects/lib_ti$o :	$(tinfo)/lib_ti.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_ti.c -o ../objects/lib_ti$o
-
-../objects/lib_tparm$o :	$(tinfo)/lib_tparm.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_tparm.c -o ../objects/lib_tparm$o
-
-../objects/lib_tputs$o :	$(tinfo)/lib_tputs.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_tputs.c -o ../objects/lib_tputs$o
-
-../objects/lib_trace$o :	$(trace)/lib_trace.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(trace)/lib_trace.c -o ../objects/lib_trace$o
-
-../objects/lib_ttyflags$o :	$(tinfo)/lib_ttyflags.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/lib_ttyflags.c -o ../objects/lib_ttyflags$o
-
-../objects/lib_twait$o :	$(serial)/lib_twait.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(serial)/lib_twait.c -o ../objects/lib_twait$o
-
-../objects/name_match$o :	$(tinfo)/name_match.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/name_match.c -o ../objects/name_match$o
-
-../objects/names$o :	./names.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/names.c -o ../objects/names$o
-
-../objects/read_entry$o :	$(tinfo)/read_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/read_entry.c -o ../objects/read_entry$o
-
-../objects/read_termcap$o :	$(tinfo)/read_termcap.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/read_termcap.c -o ../objects/read_termcap$o
-
-../objects/setbuf$o :	$(tinfo)/setbuf.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/setbuf.c -o ../objects/setbuf$o
-
-../objects/strings$o :	$(tinfo)/strings.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/strings.c -o ../objects/strings$o
-
-../objects/tries$o :	$(base)/tries.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/tries.c -o ../objects/tries$o
-
-../objects/trim_sgr0$o :	$(tinfo)/trim_sgr0.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/trim_sgr0.c -o ../objects/trim_sgr0$o
-
-../objects/unctrl$o :	./unctrl.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/unctrl.c -o ../objects/unctrl$o
-
-../objects/visbuf$o :	$(trace)/visbuf.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(trace)/visbuf.c -o ../objects/visbuf$o
-
-../objects/alloc_entry$o :	$(tinfo)/alloc_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/alloc_entry.c -o ../objects/alloc_entry$o
-
-../objects/captoinfo$o :	$(tinfo)/captoinfo.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/captoinfo.c -o ../objects/captoinfo$o
-
-../objects/comp_captab$o :	./comp_captab.c \
-			$(INCDIR)/tic.h \
-			../include/term.h \
-			../include/hashsize.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/comp_captab.c -o ../objects/comp_captab$o
-
-../objects/comp_expand$o :	$(tinfo)/comp_expand.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/comp_expand.c -o ../objects/comp_expand$o
-
-../objects/comp_hash$o :	$(tinfo)/comp_hash.c \
-			../include/term.h \
-			$(INCDIR)/tic.h \
-			../include/hashsize.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/comp_hash.c -o ../objects/comp_hash$o
-
-../objects/comp_parse$o :	$(tinfo)/comp_parse.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/comp_parse.c -o ../objects/comp_parse$o
-
-../objects/comp_scan$o :	$(tinfo)/comp_scan.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/comp_scan.c -o ../objects/comp_scan$o
-
-../objects/parse_entry$o :	$(tinfo)/parse_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h \
-			../include/parametrized.h \
-			$(INCDIR)/capdefaults.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/parse_entry.c -o ../objects/parse_entry$o
-
-../objects/write_entry$o :	$(tinfo)/write_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/write_entry.c -o ../objects/write_entry$o
-
-../objects/define_key$o :	$(base)/define_key.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/define_key.c -o ../objects/define_key$o
-
-../objects/hashed_db$o :	$(tinfo)/hashed_db.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(tinfo)/hashed_db.c -o ../objects/hashed_db$o
-
-../objects/key_defined$o :	$(base)/key_defined.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/key_defined.c -o ../objects/key_defined$o
-
-../objects/keybound$o :	$(base)/keybound.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/keybound.c -o ../objects/keybound$o
-
-../objects/keyok$o :	$(base)/keyok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/keyok.c -o ../objects/keyok$o
-
-../objects/version$o :	$(base)/version.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_NORMAL) -c ../ncurses/$(base)/version.c -o ../objects/version$o
-
-
-# generated by mk-1st.awk (subset=ticlib+termlib+ext_tinfo+base+ext_funcs)
-#  name:          ncurses
-#  traces:        DEBUG
-#  MODEL:         DEBUG
-#  model:         obj_g
-#  prefix:        lib
-#  suffix:        _g.a
-#  subset:        ticlib+termlib+ext_tinfo+base+ext_funcs
-#  ShlibVer:      auto
-#  ShlibVerInfix: no
-#  TermlibRoot:   ncurses
-#  TermlibSuffix: .a
-#  ReLink:        
-#  DoLinks:       no
-#  rmSoLocs:      no
-#  ldconfig:      :
-#  overwrite:     no
-#  depend:        ../include/ncurses_cfg.h ./curses.priv.h
-#  host:          arm-unknown-eabi
-
-DEBUG_OBJS = \
-	../obj_g/hardscroll$o \
-	../obj_g/hashmap$o \
-	../obj_g/lib_addch$o \
-	../obj_g/lib_addstr$o \
-	../obj_g/lib_beep$o \
-	../obj_g/lib_bkgd$o \
-	../obj_g/lib_box$o \
-	../obj_g/lib_chgat$o \
-	../obj_g/lib_clear$o \
-	../obj_g/lib_clearok$o \
-	../obj_g/lib_clrbot$o \
-	../obj_g/lib_clreol$o \
-	../obj_g/lib_color$o \
-	../obj_g/lib_colorset$o \
-	../obj_g/lib_delch$o \
-	../obj_g/lib_delwin$o \
-	../obj_g/lib_echo$o \
-	../obj_g/lib_endwin$o \
-	../obj_g/lib_erase$o \
-	../obj_g/lib_flash$o \
-	../obj_g/lib_gen$o \
-	../obj_g/lib_getch$o \
-	../obj_g/lib_getstr$o \
-	../obj_g/lib_hline$o \
-	../obj_g/lib_immedok$o \
-	../obj_g/lib_inchstr$o \
-	../obj_g/lib_initscr$o \
-	../obj_g/lib_insch$o \
-	../obj_g/lib_insdel$o \
-	../obj_g/lib_insnstr$o \
-	../obj_g/lib_instr$o \
-	../obj_g/lib_isendwin$o \
-	../obj_g/lib_leaveok$o \
-	../obj_g/lib_mouse$o \
-	../obj_g/lib_move$o \
-	../obj_g/lib_mvcur$o \
-	../obj_g/lib_mvwin$o \
-	../obj_g/lib_newterm$o \
-	../obj_g/lib_newwin$o \
-	../obj_g/lib_nl$o \
-	../obj_g/lib_overlay$o \
-	../obj_g/lib_pad$o \
-	../obj_g/lib_printw$o \
-	../obj_g/lib_redrawln$o \
-	../obj_g/lib_refresh$o \
-	../obj_g/lib_restart$o \
-	../obj_g/lib_scanw$o \
-	../obj_g/lib_screen$o \
-	../obj_g/lib_scroll$o \
-	../obj_g/lib_scrollok$o \
-	../obj_g/lib_scrreg$o \
-	../obj_g/lib_set_term$o \
-	../obj_g/lib_slk$o \
-	../obj_g/lib_slkatr_set$o \
-	../obj_g/lib_slkatrof$o \
-	../obj_g/lib_slkatron$o \
-	../obj_g/lib_slkatrset$o \
-	../obj_g/lib_slkattr$o \
-	../obj_g/lib_slkclear$o \
-	../obj_g/lib_slkcolor$o \
-	../obj_g/lib_slkinit$o \
-	../obj_g/lib_slklab$o \
-	../obj_g/lib_slkrefr$o \
-	../obj_g/lib_slkset$o \
-	../obj_g/lib_slktouch$o \
-	../obj_g/lib_touch$o \
-	../obj_g/lib_tracedmp$o \
-	../obj_g/lib_tracemse$o \
-	../obj_g/lib_tstp$o \
-	../obj_g/lib_ungetch$o \
-	../obj_g/lib_vidattr$o \
-	../obj_g/lib_vline$o \
-	../obj_g/lib_wattroff$o \
-	../obj_g/lib_wattron$o \
-	../obj_g/lib_winch$o \
-	../obj_g/lib_window$o \
-	../obj_g/nc_panel$o \
-	../obj_g/safe_sprintf$o \
-	../obj_g/tty_update$o \
-	../obj_g/varargs$o \
-	../obj_g/memmove$o \
-	../obj_g/vsscanf$o \
-	../obj_g/lib_freeall$o \
-	../obj_g/expanded$o \
-	../obj_g/legacy_coding$o \
-	../obj_g/lib_dft_fgbg$o \
-	../obj_g/lib_print$o \
-	../obj_g/resizeterm$o \
-	../obj_g/trace_xnames$o \
-	../obj_g/use_screen$o \
-	../obj_g/use_window$o \
-	../obj_g/wresize$o \
-	../obj_g/access$o \
-	../obj_g/add_tries$o \
-	../obj_g/alloc_ttype$o \
-	../obj_g/codes$o \
-	../obj_g/comp_error$o \
-	../obj_g/db_iterator$o \
-	../obj_g/doalloc$o \
-	../obj_g/entries$o \
-	../obj_g/fallback$o \
-	../obj_g/free_ttype$o \
-	../obj_g/getenv_num$o \
-	../obj_g/home_terminfo$o \
-	../obj_g/init_keytry$o \
-	../obj_g/lib_acs$o \
-	../obj_g/lib_baudrate$o \
-	../obj_g/lib_cur_term$o \
-	../obj_g/lib_data$o \
-	../obj_g/lib_has_cap$o \
-	../obj_g/lib_kernel$o \
-	../obj_g/lib_keyname$o \
-	../obj_g/lib_longname$o \
-	../obj_g/lib_napms$o \
-	../obj_g/lib_options$o \
-	../obj_g/lib_raw$o \
-	../obj_g/lib_setup$o \
-	../obj_g/lib_termcap$o \
-	../obj_g/lib_termname$o \
-	../obj_g/lib_tgoto$o \
-	../obj_g/lib_ti$o \
-	../obj_g/lib_tparm$o \
-	../obj_g/lib_tputs$o \
-	../obj_g/lib_trace$o \
-	../obj_g/lib_traceatr$o \
-	../obj_g/lib_tracebits$o \
-	../obj_g/lib_tracechr$o \
-	../obj_g/lib_ttyflags$o \
-	../obj_g/lib_twait$o \
-	../obj_g/name_match$o \
-	../obj_g/names$o \
-	../obj_g/read_entry$o \
-	../obj_g/read_termcap$o \
-	../obj_g/setbuf$o \
-	../obj_g/strings$o \
-	../obj_g/trace_buf$o \
-	../obj_g/trace_tries$o \
-	../obj_g/tries$o \
-	../obj_g/trim_sgr0$o \
-	../obj_g/unctrl$o \
-	../obj_g/visbuf$o \
-	../obj_g/alloc_entry$o \
-	../obj_g/captoinfo$o \
-	../obj_g/comp_captab$o \
-	../obj_g/comp_expand$o \
-	../obj_g/comp_hash$o \
-	../obj_g/comp_parse$o \
-	../obj_g/comp_scan$o \
-	../obj_g/parse_entry$o \
-	../obj_g/write_entry$o \
-	../obj_g/define_key$o \
-	../obj_g/hashed_db$o \
-	../obj_g/key_defined$o \
-	../obj_g/keybound$o \
-	../obj_g/keyok$o \
-	../obj_g/version$o
-
-$(DEBUG_OBJS) : ../include/ncurses_cfg.h ./curses.priv.h
-
-../lib/libncurses_g.a : $(DEBUG_OBJS)
-	$(AR) $(AR_OPTS) $@ $?
-	$(RANLIB) $@
-
-install \
-install.libs \
-install.ncurses :: $(DESTDIR)$(libdir) ../lib/libncurses_g.a
-	@echo installing ../lib/libncurses_g.a as $(DESTDIR)$(libdir)/libncurses_g.a
-	$(INSTALL_DATA) ../lib/libncurses_g.a $(DESTDIR)$(libdir)/libncurses_g.a
-	$(RANLIB) $(DESTDIR)$(libdir)/libncurses_g.a
-
-uninstall \
-uninstall.libs \
-uninstall.ncurses ::
-	@echo uninstalling $(DESTDIR)$(libdir)/libncurses_g.a
-	-@rm -f $(DESTDIR)$(libdir)/libncurses_g.a
-
-clean ::
-	-rm -f ../lib/libncurses_g.a
-
-mostlyclean::
-	-rm -f $(DEBUG_OBJS)
-
-# generated by mk-2nd.awk
-#   model:      obj_g
-#   MODEL:      DEBUG
-#   echo:       yes
-#   subset:     ticlib+termlib+ext_tinfo+base+ext_funcs
-#   crenames:   yes
-#   cxxrenames: no
-#   traces:     DEBUG
-#   srcdir:     .
-
-../obj_g/hardscroll$o :	$(serial)/hardscroll.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(serial)/hardscroll.c -o ../obj_g/hardscroll$o
-
-../obj_g/hashmap$o :	$(serial)/hashmap.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(serial)/hashmap.c -o ../obj_g/hashmap$o
-
-../obj_g/lib_addch$o :	$(base)/lib_addch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_addch.c -o ../obj_g/lib_addch$o
-
-../obj_g/lib_addstr$o :	$(base)/lib_addstr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_addstr.c -o ../obj_g/lib_addstr$o
-
-../obj_g/lib_beep$o :	$(base)/lib_beep.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_beep.c -o ../obj_g/lib_beep$o
-
-../obj_g/lib_bkgd$o :	$(base)/lib_bkgd.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_bkgd.c -o ../obj_g/lib_bkgd$o
-
-../obj_g/lib_box$o :	$(base)/lib_box.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_box.c -o ../obj_g/lib_box$o
-
-../obj_g/lib_chgat$o :	$(base)/lib_chgat.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_chgat.c -o ../obj_g/lib_chgat$o
-
-../obj_g/lib_clear$o :	$(base)/lib_clear.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_clear.c -o ../obj_g/lib_clear$o
-
-../obj_g/lib_clearok$o :	$(base)/lib_clearok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_clearok.c -o ../obj_g/lib_clearok$o
-
-../obj_g/lib_clrbot$o :	$(base)/lib_clrbot.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_clrbot.c -o ../obj_g/lib_clrbot$o
-
-../obj_g/lib_clreol$o :	$(base)/lib_clreol.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_clreol.c -o ../obj_g/lib_clreol$o
-
-../obj_g/lib_color$o :	$(base)/lib_color.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_color.c -o ../obj_g/lib_color$o
-
-../obj_g/lib_colorset$o :	$(base)/lib_colorset.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_colorset.c -o ../obj_g/lib_colorset$o
-
-../obj_g/lib_delch$o :	$(base)/lib_delch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_delch.c -o ../obj_g/lib_delch$o
-
-../obj_g/lib_delwin$o :	$(base)/lib_delwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_delwin.c -o ../obj_g/lib_delwin$o
-
-../obj_g/lib_echo$o :	$(base)/lib_echo.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_echo.c -o ../obj_g/lib_echo$o
-
-../obj_g/lib_endwin$o :	$(base)/lib_endwin.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_endwin.c -o ../obj_g/lib_endwin$o
-
-../obj_g/lib_erase$o :	$(base)/lib_erase.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_erase.c -o ../obj_g/lib_erase$o
-
-../obj_g/lib_flash$o :	$(base)/lib_flash.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_flash.c -o ../obj_g/lib_flash$o
-
-../obj_g/lib_gen$o :	./lib_gen.c \
-			../include/curses.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/lib_gen.c -o ../obj_g/lib_gen$o
-
-../obj_g/lib_getch$o :	$(base)/lib_getch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_getch.c -o ../obj_g/lib_getch$o
-
-../obj_g/lib_getstr$o :	$(base)/lib_getstr.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_getstr.c -o ../obj_g/lib_getstr$o
-
-../obj_g/lib_hline$o :	$(base)/lib_hline.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_hline.c -o ../obj_g/lib_hline$o
-
-../obj_g/lib_immedok$o :	$(base)/lib_immedok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_immedok.c -o ../obj_g/lib_immedok$o
-
-../obj_g/lib_inchstr$o :	$(base)/lib_inchstr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_inchstr.c -o ../obj_g/lib_inchstr$o
-
-../obj_g/lib_initscr$o :	$(base)/lib_initscr.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_initscr.c -o ../obj_g/lib_initscr$o
-
-../obj_g/lib_insch$o :	$(base)/lib_insch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_insch.c -o ../obj_g/lib_insch$o
-
-../obj_g/lib_insdel$o :	$(base)/lib_insdel.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_insdel.c -o ../obj_g/lib_insdel$o
-
-../obj_g/lib_insnstr$o :	$(base)/lib_insnstr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_insnstr.c -o ../obj_g/lib_insnstr$o
-
-../obj_g/lib_instr$o :	$(base)/lib_instr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_instr.c -o ../obj_g/lib_instr$o
-
-../obj_g/lib_isendwin$o :	$(base)/lib_isendwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_isendwin.c -o ../obj_g/lib_isendwin$o
-
-../obj_g/lib_leaveok$o :	$(base)/lib_leaveok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_leaveok.c -o ../obj_g/lib_leaveok$o
-
-../obj_g/lib_mouse$o :	$(base)/lib_mouse.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_mouse.c -o ../obj_g/lib_mouse$o
-
-../obj_g/lib_move$o :	$(base)/lib_move.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_move.c -o ../obj_g/lib_move$o
-
-../obj_g/lib_mvcur$o :	$(serial)/lib_mvcur.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(serial)/lib_mvcur.c -o ../obj_g/lib_mvcur$o
-
-../obj_g/lib_mvwin$o :	$(base)/lib_mvwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_mvwin.c -o ../obj_g/lib_mvwin$o
-
-../obj_g/lib_newterm$o :	$(base)/lib_newterm.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_newterm.c -o ../obj_g/lib_newterm$o
-
-../obj_g/lib_newwin$o :	$(base)/lib_newwin.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_newwin.c -o ../obj_g/lib_newwin$o
-
-../obj_g/lib_nl$o :	$(base)/lib_nl.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_nl.c -o ../obj_g/lib_nl$o
-
-../obj_g/lib_overlay$o :	$(base)/lib_overlay.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_overlay.c -o ../obj_g/lib_overlay$o
-
-../obj_g/lib_pad$o :	$(base)/lib_pad.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_pad.c -o ../obj_g/lib_pad$o
-
-../obj_g/lib_printw$o :	$(base)/lib_printw.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_printw.c -o ../obj_g/lib_printw$o
-
-../obj_g/lib_redrawln$o :	$(base)/lib_redrawln.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_redrawln.c -o ../obj_g/lib_redrawln$o
-
-../obj_g/lib_refresh$o :	$(base)/lib_refresh.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_refresh.c -o ../obj_g/lib_refresh$o
-
-../obj_g/lib_restart$o :	$(base)/lib_restart.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_restart.c -o ../obj_g/lib_restart$o
-
-../obj_g/lib_scanw$o :	$(base)/lib_scanw.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_scanw.c -o ../obj_g/lib_scanw$o
-
-../obj_g/lib_screen$o :	$(base)/lib_screen.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_screen.c -o ../obj_g/lib_screen$o
-
-../obj_g/lib_scroll$o :	$(base)/lib_scroll.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_scroll.c -o ../obj_g/lib_scroll$o
-
-../obj_g/lib_scrollok$o :	$(base)/lib_scrollok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_scrollok.c -o ../obj_g/lib_scrollok$o
-
-../obj_g/lib_scrreg$o :	$(base)/lib_scrreg.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_scrreg.c -o ../obj_g/lib_scrreg$o
-
-../obj_g/lib_set_term$o :	$(base)/lib_set_term.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_set_term.c -o ../obj_g/lib_set_term$o
-
-../obj_g/lib_slk$o :	$(base)/lib_slk.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slk.c -o ../obj_g/lib_slk$o
-
-../obj_g/lib_slkatr_set$o :	$(base)/lib_slkatr_set.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkatr_set.c -o ../obj_g/lib_slkatr_set$o
-
-../obj_g/lib_slkatrof$o :	$(base)/lib_slkatrof.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkatrof.c -o ../obj_g/lib_slkatrof$o
-
-../obj_g/lib_slkatron$o :	$(base)/lib_slkatron.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkatron.c -o ../obj_g/lib_slkatron$o
-
-../obj_g/lib_slkatrset$o :	$(base)/lib_slkatrset.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkatrset.c -o ../obj_g/lib_slkatrset$o
-
-../obj_g/lib_slkattr$o :	$(base)/lib_slkattr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkattr.c -o ../obj_g/lib_slkattr$o
-
-../obj_g/lib_slkclear$o :	$(base)/lib_slkclear.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkclear.c -o ../obj_g/lib_slkclear$o
-
-../obj_g/lib_slkcolor$o :	$(base)/lib_slkcolor.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkcolor.c -o ../obj_g/lib_slkcolor$o
-
-../obj_g/lib_slkinit$o :	$(base)/lib_slkinit.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkinit.c -o ../obj_g/lib_slkinit$o
-
-../obj_g/lib_slklab$o :	$(base)/lib_slklab.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slklab.c -o ../obj_g/lib_slklab$o
-
-../obj_g/lib_slkrefr$o :	$(base)/lib_slkrefr.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkrefr.c -o ../obj_g/lib_slkrefr$o
-
-../obj_g/lib_slkset$o :	$(base)/lib_slkset.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slkset.c -o ../obj_g/lib_slkset$o
-
-../obj_g/lib_slktouch$o :	$(base)/lib_slktouch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_slktouch.c -o ../obj_g/lib_slktouch$o
-
-../obj_g/lib_touch$o :	$(base)/lib_touch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_touch.c -o ../obj_g/lib_touch$o
-
-../obj_g/lib_tracedmp$o :	$(trace)/lib_tracedmp.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/lib_tracedmp.c -o ../obj_g/lib_tracedmp$o
-
-../obj_g/lib_tracemse$o :	$(trace)/lib_tracemse.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/lib_tracemse.c -o ../obj_g/lib_tracemse$o
-
-../obj_g/lib_tstp$o :	$(serial)/lib_tstp.c \
-			$(srcdir)/SigAction.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(serial)/lib_tstp.c -o ../obj_g/lib_tstp$o
-
-../obj_g/lib_ungetch$o :	$(base)/lib_ungetch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_ungetch.c -o ../obj_g/lib_ungetch$o
-
-../obj_g/lib_vidattr$o :	$(serial)/lib_vidattr.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(serial)/lib_vidattr.c -o ../obj_g/lib_vidattr$o
-
-../obj_g/lib_vline$o :	$(base)/lib_vline.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_vline.c -o ../obj_g/lib_vline$o
-
-../obj_g/lib_wattroff$o :	$(base)/lib_wattroff.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_wattroff.c -o ../obj_g/lib_wattroff$o
-
-../obj_g/lib_wattron$o :	$(base)/lib_wattron.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_wattron.c -o ../obj_g/lib_wattron$o
-
-../obj_g/lib_winch$o :	$(base)/lib_winch.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_winch.c -o ../obj_g/lib_winch$o
-
-../obj_g/lib_window$o :	$(base)/lib_window.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_window.c -o ../obj_g/lib_window$o
-
-../obj_g/link_test$o :	./link_test.c \
-			../include/curses.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/link_test.c -o ../obj_g/link_test$o
-
-../obj_g/nc_panel$o :	$(base)/nc_panel.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/nc_panel.c -o ../obj_g/nc_panel$o
-
-../obj_g/safe_sprintf$o :	$(base)/safe_sprintf.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/safe_sprintf.c -o ../obj_g/safe_sprintf$o
-
-../obj_g/tty_update$o :	$(serial)/tty_update.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(serial)/tty_update.c -o ../obj_g/tty_update$o
-
-../obj_g/varargs$o :	$(trace)/varargs.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/varargs.c -o ../obj_g/varargs$o
-
-../obj_g/memmove$o :	$(base)/memmove.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/memmove.c -o ../obj_g/memmove$o
-
-../obj_g/vsscanf$o :	$(base)/vsscanf.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/vsscanf.c -o ../obj_g/vsscanf$o
-
-../obj_g/lib_freeall$o :	$(base)/lib_freeall.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_freeall.c -o ../obj_g/lib_freeall$o
-
-../obj_g/expanded$o :	./expanded.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/expanded.c -o ../obj_g/expanded$o
-
-../obj_g/legacy_coding$o :	$(base)/legacy_coding.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/legacy_coding.c -o ../obj_g/legacy_coding$o
-
-../obj_g/lib_dft_fgbg$o :	$(base)/lib_dft_fgbg.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/lib_dft_fgbg.c -o ../obj_g/lib_dft_fgbg$o
-
-../obj_g/lib_print$o :	$(tinfo)/lib_print.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_print.c -o ../obj_g/lib_print$o
-
-../obj_g/resizeterm$o :	$(base)/resizeterm.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/resizeterm.c -o ../obj_g/resizeterm$o
-
-../obj_g/trace_xnames$o :	$(trace)/trace_xnames.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/trace_xnames.c -o ../obj_g/trace_xnames$o
-
-../obj_g/use_screen$o :	$(tinfo)/use_screen.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/use_screen.c -o ../obj_g/use_screen$o
-
-../obj_g/use_window$o :	$(base)/use_window.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/use_window.c -o ../obj_g/use_window$o
-
-../obj_g/wresize$o :	$(base)/wresize.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/wresize.c -o ../obj_g/wresize$o
-
-../obj_g/access$o :	$(tinfo)/access.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/access.c -o ../obj_g/access$o
-
-../obj_g/add_tries$o :	$(tinfo)/add_tries.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/add_tries.c -o ../obj_g/add_tries$o
-
-../obj_g/alloc_ttype$o :	$(tinfo)/alloc_ttype.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/alloc_ttype.c -o ../obj_g/alloc_ttype$o
-
-../obj_g/codes$o :	./codes.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/codes.c -o ../obj_g/codes$o
-
-../obj_g/comp_error$o :	$(tinfo)/comp_error.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/comp_error.c -o ../obj_g/comp_error$o
-
-../obj_g/db_iterator$o :	$(tinfo)/db_iterator.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/db_iterator.c -o ../obj_g/db_iterator$o
-
-../obj_g/doalloc$o :	$(tinfo)/doalloc.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/doalloc.c -o ../obj_g/doalloc$o
-
-../obj_g/entries$o :	$(tinfo)/entries.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/entries.c -o ../obj_g/entries$o
-
-../obj_g/fallback$o :	./fallback.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/fallback.c -o ../obj_g/fallback$o
-
-../obj_g/free_ttype$o :	$(tinfo)/free_ttype.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/free_ttype.c -o ../obj_g/free_ttype$o
-
-../obj_g/getenv_num$o :	$(tinfo)/getenv_num.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/getenv_num.c -o ../obj_g/getenv_num$o
-
-../obj_g/home_terminfo$o :	$(tinfo)/home_terminfo.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/home_terminfo.c -o ../obj_g/home_terminfo$o
-
-../obj_g/init_keytry$o :	$(tinfo)/init_keytry.c \
-			../include/term.h \
-			$(INCDIR)/tic.h \
-			init_keytry.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/init_keytry.c -o ../obj_g/init_keytry$o
-
-../obj_g/lib_acs$o :	$(tinfo)/lib_acs.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_acs.c -o ../obj_g/lib_acs$o
-
-../obj_g/lib_baudrate$o :	$(tinfo)/lib_baudrate.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_baudrate.c -o ../obj_g/lib_baudrate$o
-
-../obj_g/lib_cur_term$o :	$(tinfo)/lib_cur_term.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_cur_term.c -o ../obj_g/lib_cur_term$o
-
-../obj_g/lib_data$o :	$(tinfo)/lib_data.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_data.c -o ../obj_g/lib_data$o
-
-../obj_g/lib_has_cap$o :	$(tinfo)/lib_has_cap.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_has_cap.c -o ../obj_g/lib_has_cap$o
-
-../obj_g/lib_kernel$o :	$(tinfo)/lib_kernel.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_kernel.c -o ../obj_g/lib_kernel$o
-
-../obj_g/lib_keyname$o :	./lib_keyname.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/lib_keyname.c -o ../obj_g/lib_keyname$o
-
-../obj_g/lib_longname$o :	$(tinfo)/lib_longname.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_longname.c -o ../obj_g/lib_longname$o
-
-../obj_g/lib_napms$o :	$(tinfo)/lib_napms.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_napms.c -o ../obj_g/lib_napms$o
-
-../obj_g/lib_options$o :	$(tinfo)/lib_options.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_options.c -o ../obj_g/lib_options$o
-
-../obj_g/lib_raw$o :	$(tinfo)/lib_raw.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_raw.c -o ../obj_g/lib_raw$o
-
-../obj_g/lib_setup$o :	$(tinfo)/lib_setup.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_setup.c -o ../obj_g/lib_setup$o
-
-../obj_g/lib_termcap$o :	$(tinfo)/lib_termcap.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h \
-			$(INCDIR)/capdefaults.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_termcap.c -o ../obj_g/lib_termcap$o
-
-../obj_g/lib_termname$o :	$(tinfo)/lib_termname.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_termname.c -o ../obj_g/lib_termname$o
-
-../obj_g/lib_tgoto$o :	$(tinfo)/lib_tgoto.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_tgoto.c -o ../obj_g/lib_tgoto$o
-
-../obj_g/lib_ti$o :	$(tinfo)/lib_ti.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_ti.c -o ../obj_g/lib_ti$o
-
-../obj_g/lib_tparm$o :	$(tinfo)/lib_tparm.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_tparm.c -o ../obj_g/lib_tparm$o
-
-../obj_g/lib_tputs$o :	$(tinfo)/lib_tputs.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_tputs.c -o ../obj_g/lib_tputs$o
-
-../obj_g/lib_trace$o :	$(trace)/lib_trace.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/lib_trace.c -o ../obj_g/lib_trace$o
-
-../obj_g/lib_traceatr$o :	$(trace)/lib_traceatr.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/lib_traceatr.c -o ../obj_g/lib_traceatr$o
-
-../obj_g/lib_tracebits$o :	$(trace)/lib_tracebits.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/lib_tracebits.c -o ../obj_g/lib_tracebits$o
-
-../obj_g/lib_tracechr$o :	$(trace)/lib_tracechr.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/lib_tracechr.c -o ../obj_g/lib_tracechr$o
-
-../obj_g/lib_ttyflags$o :	$(tinfo)/lib_ttyflags.c \
-			../include/term.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/lib_ttyflags.c -o ../obj_g/lib_ttyflags$o
-
-../obj_g/lib_twait$o :	$(serial)/lib_twait.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(serial)/lib_twait.c -o ../obj_g/lib_twait$o
-
-../obj_g/name_match$o :	$(tinfo)/name_match.c \
-			../include/term.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/name_match.c -o ../obj_g/name_match$o
-
-../obj_g/names$o :	./names.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/names.c -o ../obj_g/names$o
-
-../obj_g/read_entry$o :	$(tinfo)/read_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/read_entry.c -o ../obj_g/read_entry$o
-
-../obj_g/read_termcap$o :	$(tinfo)/read_termcap.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/read_termcap.c -o ../obj_g/read_termcap$o
-
-../obj_g/setbuf$o :	$(tinfo)/setbuf.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/setbuf.c -o ../obj_g/setbuf$o
-
-../obj_g/strings$o :	$(tinfo)/strings.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/strings.c -o ../obj_g/strings$o
-
-../obj_g/trace_buf$o :	$(trace)/trace_buf.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/trace_buf.c -o ../obj_g/trace_buf$o
-
-../obj_g/trace_tries$o :	$(trace)/trace_tries.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/trace_tries.c -o ../obj_g/trace_tries$o
-
-../obj_g/tries$o :	$(base)/tries.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/tries.c -o ../obj_g/tries$o
-
-../obj_g/trim_sgr0$o :	$(tinfo)/trim_sgr0.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/trim_sgr0.c -o ../obj_g/trim_sgr0$o
-
-../obj_g/unctrl$o :	./unctrl.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/unctrl.c -o ../obj_g/unctrl$o
-
-../obj_g/visbuf$o :	$(trace)/visbuf.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(trace)/visbuf.c -o ../obj_g/visbuf$o
-
-../obj_g/alloc_entry$o :	$(tinfo)/alloc_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/alloc_entry.c -o ../obj_g/alloc_entry$o
-
-../obj_g/captoinfo$o :	$(tinfo)/captoinfo.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/captoinfo.c -o ../obj_g/captoinfo$o
-
-../obj_g/comp_captab$o :	./comp_captab.c \
-			$(INCDIR)/tic.h \
-			../include/term.h \
-			../include/hashsize.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/comp_captab.c -o ../obj_g/comp_captab$o
-
-../obj_g/comp_expand$o :	$(tinfo)/comp_expand.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/comp_expand.c -o ../obj_g/comp_expand$o
-
-../obj_g/comp_hash$o :	$(tinfo)/comp_hash.c \
-			../include/term.h \
-			$(INCDIR)/tic.h \
-			../include/hashsize.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/comp_hash.c -o ../obj_g/comp_hash$o
-
-../obj_g/comp_parse$o :	$(tinfo)/comp_parse.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/comp_parse.c -o ../obj_g/comp_parse$o
-
-../obj_g/comp_scan$o :	$(tinfo)/comp_scan.c \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/comp_scan.c -o ../obj_g/comp_scan$o
-
-../obj_g/parse_entry$o :	$(tinfo)/parse_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h \
-			../include/parametrized.h \
-			$(INCDIR)/capdefaults.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/parse_entry.c -o ../obj_g/parse_entry$o
-
-../obj_g/write_entry$o :	$(tinfo)/write_entry.c \
-			../include/term.h \
-			$(INCDIR)/term_entry.h \
-			$(INCDIR)/tic.h
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/write_entry.c -o ../obj_g/write_entry$o
-
-../obj_g/define_key$o :	$(base)/define_key.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/define_key.c -o ../obj_g/define_key$o
-
-../obj_g/hashed_db$o :	$(tinfo)/hashed_db.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(tinfo)/hashed_db.c -o ../obj_g/hashed_db$o
-
-../obj_g/key_defined$o :	$(base)/key_defined.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/key_defined.c -o ../obj_g/key_defined$o
-
-../obj_g/keybound$o :	$(base)/keybound.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/keybound.c -o ../obj_g/keybound$o
-
-../obj_g/keyok$o :	$(base)/keyok.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/keyok.c -o ../obj_g/keyok$o
-
-../obj_g/version$o :	$(base)/version.c
-	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS_DEBUG) -c ../ncurses/$(base)/version.c -o ../obj_g/version$o
-
-depend : ${AUTO_SRC}
-	makedepend -- ${CPPFLAGS} -- ${C_SRC}
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
diff --git a/ncurses/Makefile.in b/ncurses/Makefile.in
index 558f79f..e42c5e3 100644
--- a/ncurses/Makefile.in
+++ b/ncurses/Makefile.in
@@ -1,6 +1,6 @@
-# $Id: Makefile.in,v 1.113 2008/10/18 14:11:54 tom Exp $
+# $Id: Makefile.in,v 1.147 2015/08/05 23:15:41 tom Exp $
 ##############################################################################
-# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2014,2015 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"), #
@@ -45,7 +45,8 @@
 # turn off _all_ suffix rules; we'll generate our own
 .SUFFIXES:
 
-SHELL		= /bin/sh
+SHELL		= @SHELL@
+VPATH		= @srcdir@
 THIS		= Makefile
 
 CF_MFLAGS 	= @cf_cv_makeflags@
@@ -63,14 +64,22 @@
 bindir		= @bindir@
 libdir		= @libdir@
 includedir	= @includedir@
+datarootdir	= @datarootdir@
 datadir		= @datadir@
+includesubdir	= @includesubdir@
+
+INCLUDEDIR	= $(DESTDIR)$(includedir)$(includesubdir)
+
+PACKAGE		= @PACKAGE@
 
 LIBTOOL		= @LIBTOOL@
+LIBTOOL_OPTS	= @LIBTOOL_OPTS@ @EXPORT_SYMS@
 LIBTOOL_CLEAN	= @LIB_CLEAN@
 LIBTOOL_COMPILE	= @LIB_COMPILE@
 LIBTOOL_LINK	= @LIB_LINK@
 LIBTOOL_INSTALL	= @LIB_INSTALL@
 LIBTOOL_UNINSTALL = @LIB_UNINSTALL@
+LT_UNDEF	= @LT_UNDEF@
 
 INSTALL		= @INSTALL@
 INSTALL_LIB	= @INSTALL@ @INSTALL_LIB@
@@ -78,23 +87,27 @@
 INSTALL_DATA	= @INSTALL_DATA@
 
 AR		= @AR@
-AR_OPTS		= @AR_OPTS@
+ARFLAGS		= @ARFLAGS@
 AWK		= @AWK@
 LD		= @LD@
 LN_S		= @LN_S@
+NM		= @NM@
+
+CTAGS		= @CTAGS@
+ETAGS		= @ETAGS@
 
 CC		= @CC@
 CPP		= @CPP@
 CFLAGS		= @CFLAGS@
 
 INCDIR		= $(srcdir)/../include
-CPPFLAGS	= -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) @CPPFLAGS@
+CPPFLAGS	= -DHAVE_CONFIG_H @CPPFLAGS@
 
 CCFLAGS		= $(CPPFLAGS) $(CFLAGS)
 
-BUILD_CPPFLAGS	= -I../include @BUILD_CPPFLAGS@
+BUILD_CPPFLAGS	= -DHAVE_CONFIG_H -DUSE_BUILD_CC -I../ncurses -I$(srcdir) -I../include -I$(INCDIR) @BUILD_CPPFLAGS@ 
 BUILD_CC	= @BUILD_CC@
-BUILD_CCFLAGS	= -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) -I$(INCDIR) $(BUILD_CPPFLAGS) @BUILD_CFLAGS@
+BUILD_CCFLAGS	= @BUILD_CFLAGS@
 BUILD_LDFLAGS	= @BUILD_LDFLAGS@
 BUILD_LIBS	= @BUILD_LIBS@
 
@@ -102,7 +115,7 @@
 # is compiled into the build, or are test-programs that are not installed.
 
 BUILD_EXEEXT	= @BUILD_EXEEXT@
-x		= @PROG_EXT@
+x		= @EXEEXT@
 
 CFLAGS_LIBTOOL	= $(CCFLAGS)
 CFLAGS_NORMAL	= $(CCFLAGS)
@@ -120,6 +133,9 @@
 TINFO_LIST	= $(SHLIB_DIRS) @TINFO_LIST@
 TICS_LIST	= $(SHLIB_DIRS) @TICS_LIST@
 
+RPATH_LIST	= @RPATH_LIST@
+RESULTING_SYMS	= @RESULTING_SYMS@
+VERSIONED_SYMS	= @VERSIONED_SYMS@
 MK_SHARED_LIB	= @MK_SHARED_LIB@
 
 NCURSES_MAJOR	= @NCURSES_MAJOR@
@@ -129,7 +145,7 @@
 
 RANLIB		= @LIB_PREP@
 
-LIBRARIES	= @LIBS_TO_MAKE@
+LIBRARIES	= @Libs_To_Make@
 
 LINT		= @LINT@
 LINT_OPTS	= @LINT_OPTS@
@@ -140,6 +156,10 @@
 USE_BIG_STRINGS	= @USE_BIG_STRINGS@
 TERMINFO_CAPS	= $(top_srcdir)/include/@TERMINFO_CAPS@
 
+TERMINFO	= @TERMINFO@
+TERMINFO_SRC	= @TERMINFO_SRC@
+TIC_PATH	= @TIC_PATH@
+
 AUTO_SRC = \
 	./codes.c \
 	./comp_captab.c \
@@ -153,6 +173,18 @@
 	init_keytry.h \
 	keys.list
 
+HEADER_DEPS	= \
+	$(srcdir)/curses.priv.h \
+	../include/ncurses_dll.h \
+	../include/ncurses_cfg.h \
+	../include/curses.h \
+	$(INCDIR)/nc_panel.h \
+	../include/term.h \
+	$(INCDIR)/term_entry.h \
+	$(INCDIR)/nc_tparm.h \
+	$(INCDIR)/nc_alloc.h \
+	$(INCDIR)/nc_mingw.h
+
 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@
@@ -164,11 +196,12 @@
 	hashmap$x \
 	lib_mvcur$x
 
-base	= $(srcdir)/base
-serial	= $(srcdir)/tty
-tinfo	= $(srcdir)/tinfo
-trace	= $(srcdir)/trace
-wide	= $(srcdir)/widechar
+base	 = $(srcdir)/base
+serial	 = $(srcdir)/tty
+tinfo	 = $(srcdir)/tinfo
+trace	 = $(srcdir)/trace
+wide	 = $(srcdir)/widechar
+win32con = $(srcdir)/win32con
 
 ################################################################################
 all \
@@ -178,41 +211,41 @@
 
 $(DESTDIR)$(bindir) \
 $(DESTDIR)$(libdir) :
-	sh $(srcdir)/../mkdirs.sh $@
+	mkdir -p $@
 
 ../lib : ; mkdir $@
 
 ./fallback.c : $(tinfo)/MKfallback.sh
-	sh -e $(tinfo)/MKfallback.sh @TERMINFO@ @TERMINFO_SRC@ $(FALLBACK_LIST) >$@
+	$(SHELL) -e $(tinfo)/MKfallback.sh $(TERMINFO) $(TERMINFO_SRC) $(TIC_PATH) $(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 >$@
+	$(SHELL) -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 >$@
+	AWK=$(AWK) $(SHELL) $(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)
+	$(BUILD_CC) -o $@ $(BUILD_CPPFLAGS) $(BUILD_CCFLAGS) $(tinfo)/make_keys.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
 
 make_hash$(BUILD_EXEEXT) : \
-		$(tinfo)/comp_hash.c \
+		$(tinfo)/make_hash.c \
 		../include/hashsize.h
-	$(BUILD_CC) -o $@ $(BUILD_CCFLAGS) -DMAIN_PROGRAM $(tinfo)/comp_hash.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
+	$(BUILD_CC) -o $@ $(BUILD_CPPFLAGS) $(BUILD_CCFLAGS) $(tinfo)/make_hash.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
 
-./expanded.c : $(serial)/MKexpanded.sh
-	sh -e $(serial)/MKexpanded.sh "$(CPP)" $(CPPFLAGS) > $@
+./expanded.c : $(srcdir)/curses.priv.h $(serial)/MKexpanded.sh
+	$(SHELL) -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@ > $@
+	$(SHELL) -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 > $@
@@ -227,10 +260,10 @@
 	echo | $(AWK) -f $(base)/MKunctrl.awk bigstrings=$(USE_BIG_STRINGS) >$@
 
 tags:
-	ctags *.[ch] */*.[ch]
+	$(CTAGS) *.[ch] */*.[ch]
 
 @MAKE_UPPER_TAGS@TAGS:
-@MAKE_UPPER_TAGS@	etags *.[ch] */*.[ch]
+@MAKE_UPPER_TAGS@	$(ETAGS) *.[ch] */*.[ch]
 
 mostlyclean ::
 	-rm -f core tags TAGS *~ *.bak *.i *.ln *.atac trace
@@ -240,7 +273,7 @@
 	-rm -f $(AUTO_SRC)
 	-rm -f make_keys$(BUILD_EXEEXT)
 	-rm -f make_hash$(BUILD_EXEEXT)
-	-rm -rf .libs
+	-rm -rf .libs *.dSYM *.map
 
 distclean :: clean
 	-rm -f Makefile
@@ -257,24 +290,24 @@
 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 >$@
+	$(SHELL) -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)
+	@ECHO_LD@ $(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)
+	@ECHO_LD@ $(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)
+	@ECHO_LD@ $(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)
+	@ECHO_LD@ $(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)
+	@ECHO_LD@ $(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
diff --git a/ncurses/README b/ncurses/README
index 120aa5b..cbde335 100644
--- a/ncurses/README
+++ b/ncurses/README
@@ -1,5 +1,5 @@
 -------------------------------------------------------------------------------
--- Copyright (c) 1998-2000,2006 Free Software Foundation, Inc.               --
+-- Copyright (c) 1998-2006,2009 Free Software Foundation, Inc.               --
 --                                                                           --
 -- Permission is hereby granted, free of charge, to any person obtaining a   --
 -- copy of this software and associated documentation files (the             --
@@ -25,7 +25,26 @@
 -- 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 $
+-- $Id: README,v 1.10 2009/06/27 14:44:30 tom Exp $
 -------------------------------------------------------------------------------
 For discussion of the package internals, see hackguide.html in the doc/html
 directory.
+
+-------------------------------------------------------------------------------
+The llib-lXXXX files could be used as lint-library sources (and were, at one
+time).  However, they are actually used as a documentation aid to keep track
+of changes to the public/private interfaces in ncurses.  Most of the text in
+these files is generated using cproto; some manual cleanup and adjustment of
+types (to reflect #define's in curses.h) is needed.  The functions listed in
+the llib-lXXXX files do not correspond to the default configure options; some
+additional ones are added to include "all" of the entrypoints for each of the
+major configurations (normal, wide-character, threaded):
+
+	--disable-macros
+	--disable-root-environ
+	--enable-expanded
+	--enable-getcap
+	--enable-getcap-cache
+	--enable-sp-funcs
+	--enable-termcap
+	--with-develop
diff --git a/ncurses/base/MKkeyname.awk b/ncurses/base/MKkeyname.awk
index b35ba2a..7901611 100644
--- a/ncurses/base/MKkeyname.awk
+++ b/ncurses/base/MKkeyname.awk
@@ -1,6 +1,6 @@
-# $Id: MKkeyname.awk,v 1.40 2008/07/12 18:40:00 tom Exp $
+# $Id: MKkeyname.awk,v 1.48 2013/08/24 17:37:22 tom Exp $
 ##############################################################################
-# Copyright (c) 1999-2007,2008 Free Software Foundation, Inc.                #
+# Copyright (c) 1999-2012,2013 Free Software Foundation, Inc.                #
 #                                                                            #
 # Permission is hereby granted, free of charge, to any person obtaining a    #
 # copy of this software and associated documentation files (the "Software"), #
@@ -31,7 +31,6 @@
 	print ""
 	print "#include <curses.priv.h>"
 	print "#include <tic.h>"
-	print "#include <term_entry.h>"
 	print ""
 	first = 1;
 }
@@ -66,8 +65,10 @@
 	print ""
 	print "#define SIZEOF_TABLE 256"
 	print "#define MyTable _nc_globals.keyname_table"
+	print "#define MyInit  _nc_globals.init_keyname"
 	print ""
-	print "NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *sp, int c)"
+	print "NCURSES_EXPORT(NCURSES_CONST char *)"
+	print "safe_keyname (SCREEN *sp, int c)"
 	print "{"
 	print "	int i;"
 	print "	char name[20];"
@@ -96,34 +97,49 @@
 	print "		if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {"
 	print "			if (MyTable == 0)"
 	print "				MyTable = typeCalloc(char *, SIZEOF_TABLE);"
+	print ""
 	print "			if (MyTable != 0) {"
+	print "				int m_prefix = (sp == 0 || sp->_use_meta);"
+	print ""
+	print "				/* if sense of meta() changed, discard cached data */"
+	print "				if (MyInit != (m_prefix + 1)) {"
+	print "					MyInit = m_prefix + 1;"
+	print "					for (i = 0; i < SIZEOF_TABLE; ++i) {"
+	print "						if (MyTable[i]) {"
+	print "							FreeAndNull(MyTable[i]);"
+	print "						}"
+	print "					}"
+	print "				}"
+	print ""
+	print "				/* create and cache result as needed */"
 	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 "#define P_LIMIT (sizeof(name) - (size_t) (p - name))"
+	print "					if (cc >= 128 && m_prefix) {"
+	print "						_nc_STRCPY(p, \"M-\", P_LIMIT);"
 	print "						p += 2;"
 	print "						cc -= 128;"
 	print "					}"
 	print "					if (cc < 32)"
-	print "						sprintf(p, \"^%c\", cc + '@');"
+	print "						_nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) \"^%c\", cc + '@');"
 	print "					else if (cc == 127)"
-	print "						strcpy(p, \"^?\");"
+	print "						_nc_STRCPY(p, \"^?\", P_LIMIT);"
 	print "					else"
-	print "						sprintf(p, \"%c\", cc);"
+	print "						_nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) \"%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 "		} else if (result == 0 && HasTerminal(sp)) {"
 	print "			int j, k;"
 	print "			char * bound;"
-	print "			TERMTYPE *tp = &(cur_term->type);"
-	print "			int save_trace = _nc_tracing;"
+	print "			TERMTYPE *tp = &(TerminalOf(sp)->type);"
+	print "			unsigned 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 (j = 0; (bound = NCURSES_SP_NAME(keybound)(NCURSES_SP_ARGx 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);"
@@ -141,9 +157,10 @@
 	print "	return result;"
 	print "}"
 	print ""
-	print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)"
+	print "NCURSES_EXPORT(NCURSES_CONST char *)"
+	print "keyname (int c)"
 	print "{"
-	print "\treturn _nc_keyname(SP, c);"
+	print "	return safe_keyname (CURRENT_SCREEN, c);"
 	print "}"
 	print ""
 	print "#if NO_LEAKS"
diff --git a/ncurses/base/MKlib_gen.sh b/ncurses/base/MKlib_gen.sh
index a984e85..4f7f19d 100755
--- a/ncurses/base/MKlib_gen.sh
+++ b/ncurses/base/MKlib_gen.sh
@@ -2,10 +2,10 @@
 #
 # 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 $)
+# ($Id: MKlib_gen.sh,v 1.50 2015/08/07 00:48:24 tom Exp $)
 #
 ##############################################################################
-# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2014,2015 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"), #
@@ -51,7 +51,7 @@
 #         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
+# 7. sed: squeeze spaces, strip off gen_ prefix.
 #
 
 # keep the editing independent of locale:
@@ -66,6 +66,23 @@
 AWK="$2"
 USE="$3"
 
+# A patch discussed here:
+#	https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
+# introduces spurious #line markers into the preprocessor output.  The result
+# appears in gcc 5.0 and (with modification) in 5.1, making it necessary to
+# determine if we are using gcc, and if so, what version because the proposed
+# solution uses a nonstandard option.
+PRG=`echo "$1" | $AWK '{ sub(/^[[:space:]]*/,""); sub(/[[:space:]].*$/, ""); print; }' || exit 0`
+FSF=`"$PRG" --version 2>/dev/null || exit 0 | fgrep "Free Software Foundation" | head -n 1`
+ALL=`"$PRG" -dumpversion 2>/dev/null || exit 0`
+ONE=`echo "$ALL" | sed -e 's/\..*$//'`
+if test -n "$FSF" && test -n "$ALL" && test -n "$ONE" ; then
+	if test $ONE -ge 5 ; then
+		echo ".. adding -P option to work around $PRG $ALL" >&2
+		preprocessor="$preprocessor -P"
+	fi
+fi
+
 PID=$$
 ED1=sed1_${PID}.sed
 ED2=sed2_${PID}.sed
@@ -82,6 +99,8 @@
 	cat >$ED1 <<EOF1
 /^extern.*implemented/{
 	h
+	s/NCURSES_SP_NAME(\([^)]*\))/NCURSES_SP_NAME___\1/
+	h
 	s/^.*implemented:\([^ 	*]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
 	g
 	s/^extern \([^;]*\);.*/\1/p
@@ -151,14 +170,13 @@
 	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)/
+	s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) (\2) (\3)/
 EOF
 else
 cat >$ED4 <<EOF
@@ -169,6 +187,7 @@
 	g
 	s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/
 	}
+s/\([^_]\)NCURSES_SP_NAME___\([a-zA-Z][a-zA-Z_]*\)/\1NCURSES_SP_NAME(\2)/g
 EOF
 fi
 
@@ -198,14 +217,16 @@
 		}
 	}
 	second = first + 1;
+	returnCast = "";
 	if ( $first == "chtype" ) {
-		returnType = "Char";
+		returnType = "Chtype";
 	} 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";
+		returnType = "IntAttr";
+		returnCast = "(attr_t)";
 	} else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
 		returnType = "Bool";
 	} else if ( $second == "*" ) {
@@ -220,9 +241,6 @@
 			break;
 		}
 	}
-	if (using == "generated") {
-		print "M_" $myfunc
-	}
 	print $0;
 	print "{";
 	argcount = 1;
@@ -247,6 +265,9 @@
 	if ($myfunc ~ /ripoffline/) {
 		dotrace = 0;
 		argcount = 2;
+		if ($myfunc ~ /NCURSES_SP_NAME/) {
+			argcount = 3;
+		}
 	}
 	if ($myfunc ~ /wunctrl/) {
 		dotrace = 0;
@@ -262,24 +283,26 @@
 	argtype = ""
 	for (i = myfunc; i <= NF; i++) {
 		ch = $i;
-		if ( ch == "*" )
+		if ( ch == "*" ) {
 			pointer = 1;
-		else if ( ch == "va_list" )
+		} else if ( ch == "va_list" ) {
 			va_list = 1;
-		else if ( ch == "..." )
+		} else if ( ch == "..." ) {
 			varargs = 1;
-		else if ( ch == "char" )
+		} else if ( ch == "char" ) {
 			argtype = "char";
-		else if ( ch == "int" )
+		} else if ( ch == "int" ) {
 			argtype = "int";
-		else if ( ch == "short" )
+		} else if ( ch == "short" ) {
 			argtype = "short";
-		else if ( ch == "chtype" )
+		} else if ( ch == "chtype" ) {
 			argtype = "chtype";
-		else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" )
+		} else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) {
 			argtype = "attr";
+		}
 
 		if ( ch == "," || ch == ")" ) {
+			argcast = "";
 			if (va_list) {
 				call = call "%s"
 			} else if (varargs) {
@@ -289,8 +312,10 @@
 					call = call "%s"
 					comma = comma "_nc_visbuf2(" num ","
 					pointer = 0;
-				} else
+				} else {
 					call = call "%p"
+					comma = comma "(const void *)"
+				}
 			} else if (argcount != 0) {
 				if ( argtype == "int" || argtype == "short" ) {
 					call = call "%d"
@@ -298,6 +323,9 @@
 				} else if ( argtype != "" ) {
 					call = call "%s"
 					comma = comma "_trace" argtype "2(" num ","
+					if (argtype == "attr") {
+						argcast = "(chtype)";
+					}
 				} else {
 					call = call "%#lx"
 					comma = comma "(long)"
@@ -311,7 +339,7 @@
 				} else if ( varargs ) {
 					args = args comma "\"...\""
 				} else {
-					args = args comma "z"
+					args = args comma argcast "z"
 				}
 			}
 			call = call ch
@@ -322,7 +350,7 @@
 			pointer = 0;
 			argtype = ""
 		}
-		if ( i == 2 || ch == "(" )
+		if ( i == myfunc || ch == "(" )
 			call = call ch
 	}
 	call = call "\")"
@@ -333,12 +361,16 @@
 	if (dotrace)
 		printf "%s", call
 
-	if (match($0, "^void"))
+	if (match($0, "^void")) {
 		call = ""
-	else if (dotrace)
+	} else if (dotrace) {
 		call = sprintf("return%s( ", returnType);
-	else
+		if (returnCast != "") {
+			call = call returnCast;
+		}
+	} else {
 		call = "@@return ";
+	}
 
 	call = call $myfunc "(";
 	for (i = 1; i < argcount; i++) {
@@ -353,8 +385,9 @@
 	}
 	if (!match($0, "^void"))
 		call = call ") ";
-	if (dotrace)
+	if (dotrace) {
 		call = call ")";
+	}
 	print call ";"
 
 	if (match($0, "^void"))
@@ -381,14 +414,58 @@
 		}
 		print " */"
 		print "#define NCURSES_ATTR_T int"
+		print "#include <ncurses_cfg.h>"
+		print ""
+		print "#undef NCURSES_NOMACROS	/* _this_ file uses macros */"
+		print ""
 		print "#include <curses.priv.h>"
 		print ""
+		print "#undef vw_scanw"
+		print "#undef vwscanw"
+		print ""
+		print "#undef vw_printw"
+		print "#undef vwprintw"
 		}
 /^DECLARATIONS/	{start = 1; next;}
-		{if (start) print \$0;}
+		{
+		if (start) {
+			if ( "$USE" == "generated" ) {
+				print \$0;
+			} else if ( \$0 ~ /^[{}]?\$/ ) {
+				print \$0;
+			} else if ( \$0 ~ /;/ ) {
+				print \$0;
+			} else {
+				calls[start] = \$0;
+				print \$0;
+				start++;
+			}
+		}
+		}
 END		{
 		if ( "$USE" != "generated" ) {
-			print "int main(void) { return 0; }"
+			print "int main(void)"
+			print "{"
+			for (n = 1; n < start; ++n) {
+				value = calls[n];
+				if ( value !~ /P_POUNDC/ ) {
+					gsub(/[[:blank:]]+/," ",value);
+					sub(/^[[:alnum:]_]+ /,"",value);
+					sub(/^\* /,"",value);
+					gsub(/[[:alnum:]_]+ \* /,"",value);
+					gsub(/ (const) /," ",value);
+					gsub(/ (int|short|attr_t|chtype|wchar_t|NCURSES_BOOL|NCURSES_OUTC|NCURSES_OUTC_sp|va_list) /," ",value);
+					gsub(/ void /,"",value);
+					sub(/^/,"call_",value);
+					gsub(/ (a[[:digit:]]|z) /, " 0 ", value);
+					gsub(/ int[[:blank:]]*[(][^)]+[)][(][^)]+[)]/, "0", value);
+					printf "\t%s;\n", value;
+				} else {
+					print value;
+				}
+			}
+			print "	return 0;"
+			print "}"
 		}
 		}
 EOF1
@@ -397,6 +474,8 @@
 #include <ncurses_cfg.h>
 #undef NCURSES_NOMACROS
 #include <curses.h>
+#include <term.h>
+#include <unctrl.h>
 
 DECLARATIONS
 
diff --git a/ncurses/base/MKunctrl.awk b/ncurses/base/MKunctrl.awk
index 36fbeec..51ceb63 100644
--- a/ncurses/base/MKunctrl.awk
+++ b/ncurses/base/MKunctrl.awk
@@ -1,6 +1,6 @@
-# $Id: MKunctrl.awk,v 1.23 2008/10/04 21:40:24 tom Exp $
+# $Id: MKunctrl.awk,v 1.27 2012/06/09 20:29:33 tom Exp $
 ##############################################################################
-# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2009,2012 Free Software Foundation, Inc.                #
 #                                                                            #
 # Permission is hereby granted, free of charge, to any person obtaining a    #
 # copy of this software and associated documentation files (the "Software"), #
@@ -36,19 +36,12 @@
 		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 "NCURSES_EXPORT(NCURSES_CONST char *) safe_unctrl(SCREEN *sp, chtype ch)"
 		print "{"
-
 		blob=""
 		offset=0
 		if (bigstrings) {
@@ -147,7 +140,7 @@
 		} else {
 			stringname = "unctrl"
 		}
-		print  "\tint check = ChCharOf(ch);"
+		print  "\tint check = (int) ChCharOf(ch);"
 		print  "\tconst char *result;"
 		print  ""
 		print  "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
@@ -158,16 +151,6 @@
 		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)"
@@ -176,7 +159,6 @@
 		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 {"
@@ -187,6 +169,6 @@
 		print  ""
 		print  "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)"
 		print  "{"
-		print  "\treturn _nc_unctrl(SP, ch);"
+		print  "\treturn safe_unctrl(CURRENT_SCREEN, ch);"
 		print  "}"
 	}
diff --git a/ncurses/base/define_key.c b/ncurses/base/define_key.c
index 3d5815f..c78375a 100644
--- a/ncurses/base/define_key.c
+++ b/ncurses/base/define_key.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,33 +27,40 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey                    1997-on                     *
+ *  Author: Thomas E. Dickey                        1997-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: define_key.c,v 1.13 2006/12/30 23:23:31 tom Exp $")
+MODULE_ID("$Id: define_key.c,v 1.21 2014/03/08 20:32:59 tom Exp $")
 
 NCURSES_EXPORT(int)
-define_key(const char *str, int keycode)
+NCURSES_SP_NAME(define_key) (NCURSES_SP_DCLx const char *str, int keycode)
 {
     int code = ERR;
 
-    T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
-    if (SP == 0) {
+    T((T_CALLED("define_key(%p, %s,%d)"), (void *) SP_PARM, _nc_visbuf(str), keycode));
+    if (SP_PARM == 0 || !HasTInfoTerminal(SP_PARM)) {
 	code = ERR;
     } else if (keycode > 0) {
 	unsigned ukey = (unsigned) keycode;
 
+#ifdef USE_TERM_DRIVER
+#define CallHasKey(keycode) CallDriver_1(SP_PARM, td_kyExist, keycode)
+#else
+#define CallHasKey(keycode) NCURSES_SP_NAME(has_key)(NCURSES_SP_ARGx keycode)
+#endif
+
 	if (str != 0) {
-	    define_key(str, 0);
-	} else if (has_key(keycode)) {
-	    while (_nc_remove_key(&(SP->_keytry), ukey))
+	    NCURSES_SP_NAME(define_key) (NCURSES_SP_ARGx str, 0);
+	} else if (CallHasKey(keycode)) {
+	    while (_nc_remove_key(&(SP_PARM->_keytry), ukey))
 		code = OK;
 	}
 	if (str != 0) {
-	    if (key_defined(str) == 0) {
-		if (_nc_add_to_try(&(SP->_keytry), str, ukey) == OK) {
+	    if (NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx str) == 0) {
+		if (_nc_add_to_try(&(SP_PARM->_keytry), str, ukey) == OK) {
 		    code = OK;
 		} else {
 		    code = ERR;
@@ -63,8 +70,16 @@
 	    }
 	}
     } else {
-	while (_nc_remove_string(&(SP->_keytry), str))
+	while (_nc_remove_string(&(SP_PARM->_keytry), str))
 	    code = OK;
     }
     returnCode(code);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+define_key(const char *str, int keycode)
+{
+    return NCURSES_SP_NAME(define_key) (CURRENT_SCREEN, str, keycode);
+}
+#endif
diff --git a/ncurses/base/key_defined.c b/ncurses/base/key_defined.c
index 759ad82..ef987a5 100644
--- a/ncurses/base/key_defined.c
+++ b/ncurses/base/key_defined.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2003,2006 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2003-2006,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -32,7 +32,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: key_defined.c,v 1.6 2006/12/30 23:22:55 tom Exp $")
+MODULE_ID("$Id: key_defined.c,v 1.9 2009/10/24 22:15:47 tom Exp $")
 
 static int
 find_definition(TRIES * tree, const char *str)
@@ -65,14 +65,22 @@
  * Otherwise, return the keycode's value (neither OK/ERR).
  */
 NCURSES_EXPORT(int)
-key_defined(const char *str)
+NCURSES_SP_NAME(key_defined) (NCURSES_SP_DCLx 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);
+    T((T_CALLED("key_defined(%p, %s)"), (void *) SP_PARM, _nc_visbuf(str)));
+    if (SP_PARM != 0 && str != 0) {
+	code = find_definition(SP_PARM->_keytry, str);
     }
 
     returnCode(code);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+key_defined(const char *str)
+{
+    return NCURSES_SP_NAME(key_defined) (CURRENT_SCREEN, str);
+}
+#endif
diff --git a/ncurses/base/keybound.c b/ncurses/base/keybound.c
index 2995714..72790e8 100644
--- a/ncurses/base/keybound.c
+++ b/ncurses/base/keybound.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1999-2009,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,25 +27,37 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey                 1999-on                        *
+ *  Author: Thomas E. Dickey                        1999-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: keybound.c,v 1.7 2006/06/17 18:19:24 tom Exp $")
+MODULE_ID("$Id: keybound.c,v 1.11 2011/10/22 16:47:05 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)
+NCURSES_SP_NAME(keybound) (NCURSES_SP_DCLx 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);
+    T((T_CALLED("keybound(%p, %d,%d)"), (void *) SP_PARM, code, count));
+    if (SP_PARM != 0 && code >= 0) {
+	result = _nc_expand_try(SP_PARM->_keytry,
+				(unsigned) code,
+				&count,
+				(size_t) 0);
     }
     returnPtr(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char *)
+keybound(int code, int count)
+{
+    return NCURSES_SP_NAME(keybound) (CURRENT_SCREEN, code, count);
+}
+#endif
diff --git a/ncurses/base/keyok.c b/ncurses/base/keyok.c
index ad8988c..37fddec 100644
--- a/ncurses/base/keyok.c
+++ b/ncurses/base/keyok.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,12 +27,13 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey            1997-on                             *
+ *  Author: Thomas E. Dickey                        1997-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: keyok.c,v 1.7 2006/12/30 16:22:33 tom Exp $")
+MODULE_ID("$Id: keyok.c,v 1.14 2014/03/08 20:32:59 tom Exp $")
 
 /*
  * Enable (or disable) ncurses' interpretation of a keycode by adding (or
@@ -45,34 +46,58 @@
  */
 
 NCURSES_EXPORT(int)
-keyok(int c, bool flag)
+NCURSES_SP_NAME(keyok) (NCURSES_SP_DCLx 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;
+    if (HasTerminal(SP_PARM)) {
+	T((T_CALLED("keyok(%p, %d,%d)"), (void *) SP_PARM, c, flag));
+#ifdef USE_TERM_DRIVER
+	code = CallDriver_2(sp, td_kyOk, c, flag);
+#else
+	T((T_CALLED("keyok(%d,%d)"), c, flag));
+	if (c >= 0) {
+	    int count = 0;
+	    char *s;
+	    unsigned ch = (unsigned) c;
+
+	    if (flag) {
+		while ((s = _nc_expand_try(SP_PARM->_key_ok,
+					   ch, &count, (size_t) 0)) != 0) {
+		    if (_nc_remove_key(&(SP_PARM->_key_ok), ch)) {
+			code = _nc_add_to_try(&(SP_PARM->_keytry), s, ch);
+			free(s);
+			count = 0;
+			if (code != OK)
+			    break;
+		    } else {
+			free(s);
+		    }
+		}
+	    } else {
+		while ((s = _nc_expand_try(SP_PARM->_keytry,
+					   ch, &count, (size_t) 0)) != 0) {
+		    if (_nc_remove_key(&(SP_PARM->_keytry), ch)) {
+			code = _nc_add_to_try(&(SP_PARM->_key_ok), s, ch);
+			free(s);
+			count = 0;
+			if (code != OK)
+			    break;
+		    } else {
+			free(s);
+		    }
+		}
 	    }
 	}
+#endif
     }
     returnCode(code);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+keyok(int c, bool flag)
+{
+    return NCURSES_SP_NAME(keyok) (CURRENT_SCREEN, c, flag);
+}
+#endif
diff --git a/ncurses/base/legacy_coding.c b/ncurses/base/legacy_coding.c
index 1c2f160..d8c8020 100644
--- a/ncurses/base/legacy_coding.c
+++ b/ncurses/base/legacy_coding.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2005 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2005,2009 Free Software Foundation, Inc.                   *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,22 +27,31 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey                                                *
+ *  Author: Thomas E. Dickey          2005                                  *
+ *          Juergen Pfeifer           2009                                  *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: legacy_coding.c,v 1.2 2005/12/17 23:38:17 tom Exp $")
+MODULE_ID("$Id: legacy_coding.c,v 1.5 2009/10/24 22:15:00 tom Exp $")
 
 NCURSES_EXPORT(int)
-use_legacy_coding(int level)
+NCURSES_SP_NAME(use_legacy_coding) (NCURSES_SP_DCLx 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;
+    T((T_CALLED("use_legacy_coding(%p,%d)"), (void *) SP_PARM, level));
+    if (level >= 0 && level <= 2 && SP_PARM != 0) {
+	result = SP_PARM->_legacy_coding;
+	SP_PARM->_legacy_coding = level;
     }
     returnCode(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+use_legacy_coding(int level)
+{
+    return NCURSES_SP_NAME(use_legacy_coding) (CURRENT_SCREEN, level);
+}
+#endif
diff --git a/ncurses/base/lib_addch.c b/ncurses/base/lib_addch.c
index 20a97a0..4b16a47 100644
--- a/ncurses/base/lib_addch.c
+++ b/ncurses/base/lib_addch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -36,7 +36,7 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_addch.c,v 1.113 2008/08/16 19:20:04 tom Exp $")
+MODULE_ID("$Id: lib_addch.c,v 1.129 2014/08/16 20:41:04 tom Exp $")
 
 static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
 
@@ -77,12 +77,6 @@
 	    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);
     }
@@ -131,7 +125,7 @@
 	*ypos = win->_regbottom;
 	result = TRUE;
     } else {
-	*ypos += 1;
+	*ypos = (NCURSES_SIZE_T) (*ypos + 1);
     }
     return result;
 }
@@ -176,8 +170,8 @@
 	if (waddch_literal(win, blank) == ERR)
 	    break;
     }
-    win->_curx = save_x;
-    win->_cury = save_y;
+    win->_curx = (NCURSES_SIZE_T) save_x;
+    win->_cury = (NCURSES_SIZE_T) save_y;
 }
 #endif
 
@@ -213,9 +207,10 @@
     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) {
+    if ((len = (int) mbrtowc(&result,
+			     buffer,
+			     (size_t) 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);
@@ -260,20 +255,37 @@
     /*
      * Build up multibyte characters until we have a wide-character.
      */
+#if NCURSES_SP_FUNCS
+#define DeriveSP() SCREEN *sp = _nc_screen_of(win);
+#else
+#define DeriveSP()		/*nothing */
+#endif
     if_WIDEC({
+	DeriveSP();
 	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);
+		attr_t attr = AttrOf(ch);
+
+		/* handle EILSEQ (i.e., when len >= -1) */
+		if (len == -1 && is8bits(CharOf(ch))) {
+		    int rc = OK;
+		    const char *s = NCURSES_SP_NAME(unctrl)
+		      (NCURSES_SP_ARGx (chtype) CharOf(ch));
+
+		    if (s[1] != '\0') {
+			while (*s != '\0') {
+			    rc = waddch(win, UChar(*s) | attr);
+			    if (rc != OK)
+				break;
+			    ++s;
+			}
+			return rc;
 		    }
 		}
 		if (len == -1)
-		    return waddch(win, ' ');
+		    return waddch(win, ' ' | attr);
 	    } else {
 		return OK;
 	    }
@@ -327,6 +339,7 @@
 		    return ERR;
 		x = win->_curx;
 		y = win->_cury;
+		line = win->_line + y;
 	    }
 	    /*
 	     * Check for cells which are orphaned by adding this character, set
@@ -384,7 +397,7 @@
     if (x > win->_maxx) {
 	return wrap_to_next_line(win);
     }
-    win->_curx = x;
+    win->_curx = (NCURSES_SIZE_T) x;
     return OK;
 }
 
@@ -393,30 +406,36 @@
 /* the workhorse function -- add a character to the given window */
 {
     NCURSES_SIZE_T x, y;
-    chtype t = CharOf(ch);
-    const char *s = unctrl(t);
+    chtype t = (chtype) CharOf(ch);
+#if USE_WIDEC_SUPPORT || NCURSES_SP_FUNCS || USE_REENTRANT
+    SCREEN *sp = _nc_screen_of(win);
+#endif
+    const char *s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx t);
+    int tabsize = 8;
 
     /*
      * 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.
+     * claims the code is printable (and not also a control character),
+     * treat it that way.
      */
     if ((AttrOf(ch) & A_ALTCHARSET)
 	|| (
 #if USE_WIDEC_SUPPORT
-	       (SP != 0 && SP->_legacy_coding) &&
+	       (sp != 0 && sp->_legacy_coding) &&
 #endif
 	       s[1] == 0
 	)
 	|| (
-	       isprint(t)
+	       (isprint((int)t) && !iscntrl((int)t))
 #if USE_WIDEC_SUPPORT
-	       || ((SP == 0 || !SP->_legacy_coding) &&
+	       || ((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
@@ -427,8 +446,12 @@
 
     switch (t) {
     case '\t':
-	x += (TABSIZE - (x % TABSIZE));
-
+#if USE_REENTRANT
+	tabsize = *ptrTabsize(sp);
+#else
+	tabsize = TABSIZE;
+#endif
+	x = (NCURSES_SIZE_T) (x + (tabsize - (x % tabsize)));
 	/*
 	 * Space-fill the tab on the bottom line so that we'll get the
 	 * "correct" cursor position.
@@ -478,7 +501,7 @@
     default:
 	while (*s) {
 	    NCURSES_CH_T sch;
-	    SetChar(sch, *s++, AttrOf(ch));
+	    SetChar(sch, UChar(*s++), AttrOf(ch));
 	    if_EXT_COLORS(SetPair(sch, GetPair(ch)));
 	    if (waddch_literal(win, sch) == ERR)
 		return ERR;
@@ -514,7 +537,7 @@
     NCURSES_CH_T wch;
     SetChar2(wch, ch);
 
-    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win,
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), (void *) win,
 				      _tracechtype(ch)));
 
     if (win && (waddch_nosync(win, wch) != ERR)) {
@@ -533,7 +556,8 @@
     NCURSES_CH_T wch;
     SetChar2(wch, ch);
 
-    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win,
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"),
+				      (void *) win,
 				      _tracechtype(ch)));
 
     if (win && (waddch_nosync(win, wch) != ERR)) {
diff --git a/ncurses/base/lib_addstr.c b/ncurses/base/lib_addstr.c
index 4e3a040..a1a55cb 100644
--- a/ncurses/base/lib_addstr.c
+++ b/ncurses/base/lib_addstr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -44,7 +44,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_addstr.c,v 1.48 2007/10/13 19:56:57 tom Exp $")
+MODULE_ID("$Id: lib_addstr.c,v 1.52 2011/05/28 23:02:09 tom Exp $")
 
 NCURSES_EXPORT(int)
 waddnstr(WINDOW *win, const char *astr, int n)
@@ -52,7 +52,7 @@
     const char *str = astr;
     int code = ERR;
 
-    T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbufn(astr, n), n));
+    T((T_CALLED("waddnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(astr, n), n));
 
     if (win && (str != 0)) {
 	TR(TRACE_VIRTPUT | TRACE_ATTRS,
@@ -85,7 +85,7 @@
     int i;
     struct ldat *line;
 
-    T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n));
+    T((T_CALLED("waddchnstr(%p,%p,%d)"), (void *) win, (const void *) astr, n));
 
     if (!win)
 	returnCode(ERR);
@@ -107,7 +107,7 @@
     for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) {
 	SetChar2(line->text[i + x], astr[i]);
     }
-    CHANGED_RANGE(line, x, x + n - 1);
+    CHANGED_RANGE(line, x, (NCURSES_SIZE_T) (x + n - 1));
 
     _nc_synchook(win);
     returnCode(code);
@@ -119,8 +119,10 @@
 _nc_wchstrlen(const cchar_t *s)
 {
     int result = 0;
-    while (CharOf(s[result]) != L'\0') {
-	result++;
+    if (s != 0) {
+	while (CharOf(s[result]) != L'\0') {
+	    result++;
+	}
     }
     return result;
 }
@@ -135,7 +137,10 @@
     struct ldat *line;
     int i, j, start, len, end;
 
-    T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n));
+    T((T_CALLED("wadd_wchnstr(%p,%s,%d)"),
+       (void *) win,
+       _nc_viscbuf(astr, n),
+       n));
 
     if (!win)
 	returnCode(ERR);
@@ -190,7 +195,7 @@
 		    SetWidecExt(line->text[x + j], j);
 		}
 	    }
-	    x += len;
+	    x = (NCURSES_SIZE_T) (x + len);
 	    end += len - 1;
 	} else {
 	    break;
@@ -217,7 +222,7 @@
 {
     int code = ERR;
 
-    T((T_CALLED("waddnwstr(%p,%s,%d)"), win, _nc_viswbufn(str, n), n));
+    T((T_CALLED("waddnwstr(%p,%s,%d)"), (void *) win, _nc_viswbufn(str, n), n));
 
     if (win && (str != 0)) {
 	TR(TRACE_VIRTPUT | TRACE_ATTRS,
diff --git a/ncurses/base/lib_beep.c b/ncurses/base/lib_beep.c
index b478f25..b775d56 100644
--- a/ncurses/base/lib_beep.c
+++ b/ncurses/base/lib_beep.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -40,9 +41,12 @@
  */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_beep.c,v 1.17 2014/03/08 20:32:59 tom Exp $")
 
 /*
  *	beep()
@@ -53,24 +57,34 @@
  */
 
 NCURSES_EXPORT(int)
-beep(void)
+NCURSES_SP_NAME(beep) (NCURSES_SP_DCL0)
 {
     int res = ERR;
 
-    T((T_CALLED("beep()")));
+    T((T_CALLED("beep(%p)"), (void *) SP_PARM));
 
+#ifdef USE_TERM_DRIVER
+    if (SP_PARM != 0)
+	res = CallDriver_1(SP_PARM, td_doBeepOrFlash, TRUE);
+#else
     /* 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();
+	res = NCURSES_PUTP2_FLUSH("bell", bell);
     } else if (flash_screen) {
-	TPUTS_TRACE("flash_screen");
-	res = putp(flash_screen);
+	res = NCURSES_PUTP2_FLUSH("flash_screen", flash_screen);
 	_nc_flush();
     }
+#endif
 
     returnCode(res);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+beep(void)
+{
+    return NCURSES_SP_NAME(beep) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/base/lib_bkgd.c b/ncurses/base/lib_bkgd.c
index c99e0c5..c46ca42 100644
--- a/ncurses/base/lib_bkgd.c
+++ b/ncurses/base/lib_bkgd.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -36,7 +36,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_bkgd.c,v 1.36 2008/03/23 00:09:14 tom Exp $")
+MODULE_ID("$Id: lib_bkgd.c,v 1.49 2014/09/04 09:36:20 tom Exp $")
 
 /*
  * Set the window's background information.
@@ -48,7 +48,7 @@
 #endif
 wbkgrndset(WINDOW *win, const ARG_CH_T ch)
 {
-    T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch)));
+    T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracech_t(ch)));
 
     if (win) {
 	attr_t off = AttrOf(win->_nc_bkgd);
@@ -85,12 +85,13 @@
 	    cchar_t wch;
 	    int tmp;
 
-	    wgetbkgrnd(win, &wch);
+	    memset(&wch, 0, sizeof(wch));
+	    (void) 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)));
+			  | (chtype) ColorPair(GET_WINDOW_PAIR(win)));
 	}
 #endif
     }
@@ -118,16 +119,18 @@
 {
     int code = ERR;
     int x, y;
-    NCURSES_CH_T new_bkgd = CHDEREF(ch);
 
-    T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch)));
+    T((T_CALLED("wbkgd(%p,%s)"), (void *) win, _tracech_t(ch)));
 
     if (win) {
+	NCURSES_CH_T new_bkgd = CHDEREF(ch);
 	NCURSES_CH_T old_bkgrnd;
-	wgetbkgrnd(win, &old_bkgrnd);
 
-	wbkgrndset(win, CHREF(new_bkgd));
-	wattrset(win, AttrOf(win->_nc_bkgd));
+	memset(&old_bkgrnd, 0, sizeof(old_bkgrnd));
+	(void) wgetbkgrnd(win, &old_bkgrnd);
+
+	(void) wbkgrndset(win, CHREF(new_bkgd));
+	(void) wattrset(win, (int) AttrOf(win->_nc_bkgd));
 
 	for (y = 0; y <= win->_maxy; y++) {
 	    for (x = 0; x <= win->_maxx; x++) {
diff --git a/ncurses/base/lib_box.c b/ncurses/base/lib_box.c
index d6cfc6c..6f17c97 100644
--- a/ncurses/base/lib_box.c
+++ b/ncurses/base/lib_box.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2002,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -42,7 +42,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_box.c,v 1.22 2005/11/26 15:39:42 tom Exp $")
+MODULE_ID("$Id: lib_box.c,v 1.24 2010/04/24 23:51:57 tom Exp $")
 
 #if USE_WIDEC_SUPPORT
 static NCURSES_INLINE chtype
@@ -51,8 +51,9 @@
     NCURSES_CH_T wch;
     SetChar2(wch, ch);
     wch = _nc_render(win, wch);
-    return CharOf(wch) | AttrOf(wch);
+    return ((attr_t) 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)
@@ -70,7 +71,7 @@
     chtype wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
 
     T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
-       win,
+       (void *) win,
        _tracechtype2(1, ls),
        _tracechtype2(2, rs),
        _tracechtype2(3, ts),
diff --git a/ncurses/base/lib_chgat.c b/ncurses/base/lib_chgat.c
index 89eefa7..1eb1f59 100644
--- a/ncurses/base/lib_chgat.c
+++ b/ncurses/base/lib_chgat.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -42,19 +42,27 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_chgat.c,v 1.7 2006/07/15 22:07:11 tom Exp $")
+MODULE_ID("$Id: lib_chgat.c,v 1.10 2014/02/01 22:13:31 tom Exp $")
 
 NCURSES_EXPORT(int)
-wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED)
+wchgat(WINDOW *win,
+       int n,
+       attr_t attr,
+       NCURSES_PAIRS_T color,
+       const void *opts GCC_UNUSED)
 {
     int i;
 
-    T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color));
+    T((T_CALLED("wchgat(%p,%d,%s,%d)"),
+       (void *) win,
+       n,
+       _traceattr(attr),
+       (int) color));
 
     if (win) {
 	struct ldat *line = &(win->_line[win->_cury]);
 
-	toggle_attr_on(attr, COLOR_PAIR(color));
+	toggle_attr_on(attr, ColorPair(color));
 
 	for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) {
 	    SetAttr(line->text[i], attr);
diff --git a/ncurses/base/lib_clear.c b/ncurses/base/lib_clear.c
index e0b4edf..008744c 100644
--- a/ncurses/base/lib_clear.c
+++ b/ncurses/base/lib_clear.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,14 +40,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_clear.c,v 1.7 2000/12/10 02:43:26 tom Exp $")
+MODULE_ID("$Id: lib_clear.c,v 1.8 2009/10/24 22:33:29 tom Exp $")
 
 NCURSES_EXPORT(int)
 wclear(WINDOW *win)
 {
     int code = ERR;
 
-    T((T_CALLED("wclear(%p)"), win));
+    T((T_CALLED("wclear(%p)"), (void *) win));
 
     if ((code = werase(win)) != ERR)
 	win->_clear = TRUE;
diff --git a/ncurses/base/lib_clearok.c b/ncurses/base/lib_clearok.c
index 9b56bd1..ffc7d02 100644
--- a/ncurses/base/lib_clearok.c
+++ b/ncurses/base/lib_clearok.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,12 +40,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_clearok.c,v 1.4 2000/12/10 02:43:26 tom Exp $")
+MODULE_ID("$Id: lib_clearok.c,v 1.5 2009/10/24 22:34:53 tom Exp $")
 
 NCURSES_EXPORT(int)
 clearok(WINDOW *win, bool flag)
 {
-    T((T_CALLED("clearok(%p,%d)"), win, flag));
+    T((T_CALLED("clearok(%p,%d)"), (void *) win, flag));
 
     if (win) {
 	win->_clear = flag;
diff --git a/ncurses/base/lib_clrbot.c b/ncurses/base/lib_clrbot.c
index df196e8..cbf2206 100644
--- a/ncurses/base/lib_clrbot.c
+++ b/ncurses/base/lib_clrbot.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2006,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,14 +40,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_clrbot.c,v 1.20 2006/10/14 20:43:31 tom Exp $")
+MODULE_ID("$Id: lib_clrbot.c,v 1.21 2009/10/24 22:33:19 tom Exp $")
 
 NCURSES_EXPORT(int)
 wclrtobot(WINDOW *win)
 {
     int code = ERR;
 
-    T((T_CALLED("wclrtobot(%p)"), win));
+    T((T_CALLED("wclrtobot(%p)"), (void *) win));
 
     if (win) {
 	NCURSES_SIZE_T y;
diff --git a/ncurses/base/lib_clreol.c b/ncurses/base/lib_clreol.c
index c46ebd9..7aff84b 100644
--- a/ncurses/base/lib_clreol.c
+++ b/ncurses/base/lib_clreol.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc.         *
+ * Copyright (c) 1998-2001,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,14 +40,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_clreol.c,v 1.21 2001/12/19 01:06:04 tom Exp $")
+MODULE_ID("$Id: lib_clreol.c,v 1.22 2009/10/24 22:33:06 tom Exp $")
 
 NCURSES_EXPORT(int)
 wclrtoeol(WINDOW *win)
 {
     int code = ERR;
 
-    T((T_CALLED("wclrtoeol(%p)"), win));
+    T((T_CALLED("wclrtoeol(%p)"), (void *) win));
 
     if (win) {
 	NCURSES_CH_T blank;
diff --git a/ncurses/base/lib_color.c b/ncurses/base/lib_color.c
index 9cae495..1322600 100644
--- a/ncurses/base/lib_color.c
+++ b/ncurses/base/lib_color.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /* lib_color.c
@@ -38,12 +39,33 @@
  */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
+MODULE_ID("$Id: lib_color.c,v 1.110 2014/03/08 20:04:44 tom Exp $")
+
+#ifdef USE_TERM_DRIVER
+#define CanChange      InfoOf(SP_PARM).canchange
+#define DefaultPalette InfoOf(SP_PARM).defaultPalette
+#define HasColor       InfoOf(SP_PARM).hascolor
+#define InitColor      InfoOf(SP_PARM).initcolor
+#define MaxColors      InfoOf(SP_PARM).maxcolors
+#define MaxPairs       InfoOf(SP_PARM).maxpairs
+#define UseHlsPalette  (DefaultPalette == _nc_hls_palette)
+#else
+#define CanChange      can_change
+#define DefaultPalette (hue_lightness_saturation ? hls_palette : cga_palette)
+#define HasColor       has_color
+#define InitColor      initialize_color
+#define MaxColors      max_colors
+#define MaxPairs       max_pairs
+#define UseHlsPalette  (hue_lightness_saturation)
+#endif
+
+#ifndef USE_TERM_DRIVER
 /*
  * These should be screen structure members.  They need to be globals for
  * historical reasons.  So we assign them in start_color() and also in
@@ -64,6 +86,7 @@
 NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
 NCURSES_EXPORT_VAR(int) COLORS = 0;
 #endif
+#endif /* !USE_TERM_DRIVER */
 
 #define DATA(r,g,b) {r,g,b, 0,0,0, 0}
 
@@ -71,7 +94,7 @@
 
 #define MAX_PALETTE	8
 
-#define OkColorHi(n)	(((n) < COLORS) && ((n) < max_colors))
+#define OkColorHi(n)	(((n) < COLORS) && ((n) < maxcolors))
 #define InPalette(n)	((n) >= 0 && (n) < MAX_PALETTE)
 
 /*
@@ -106,29 +129,43 @@
     DATA(	300,	50,	100),		/* COLOR_CYAN */
     DATA(	0,	50,	100),		/* COLOR_WHITE */
 };
+
+#ifdef USE_TERM_DRIVER
+NCURSES_EXPORT_VAR(const color_t*) _nc_cga_palette = cga_palette;
+NCURSES_EXPORT_VAR(const color_t*) _nc_hls_palette = hls_palette;
+#endif
+
 /* *INDENT-ON* */
 
+/*
+ * Ensure that we use color pairs only when colors have been started, and also
+ * that the index is within the limits of the table which we allocated.
+ */
+#define ValidPair(pair) \
+    ((SP_PARM != 0) && (pair >= 0) && (pair < SP_PARM->_pair_limit) && SP_PARM->_coloron)
+
 #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.
+ * vidattr - so we have to assume that sp may be null.
  */
 static int
-default_fg(void)
+default_fg(NCURSES_SP_DCL0)
 {
-    return (SP != 0) ? SP->_default_fg : COLOR_WHITE;
+    return (SP_PARM != 0) ? SP_PARM->_default_fg : COLOR_WHITE;
 }
 
 static int
-default_bg(void)
+default_bg(NCURSES_SP_DCL0)
 {
-    return SP != 0 ? SP->_default_bg : COLOR_BLACK;
+    return SP_PARM != 0 ? SP_PARM->_default_bg : COLOR_BLACK;
 }
 #else
-#define default_fg() COLOR_WHITE
-#define default_bg() COLOR_BLACK
+#define default_fg(sp) COLOR_WHITE
+#define default_bg(sp) COLOR_BLACK
 #endif
 
+#ifndef USE_TERM_DRIVER
 /*
  * 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
@@ -145,52 +182,70 @@
     }
     return c;
 }
+#endif
 
 static void
-set_background_color(int bg, int (*outc) (int))
+set_background_color(NCURSES_SP_DCLx int bg, NCURSES_SP_OUTC outc)
 {
+#ifdef USE_TERM_DRIVER
+    CallDriver_3(SP_PARM, td_color, FALSE, bg, outc);
+#else
     if (set_a_background) {
 	TPUTS_TRACE("set_a_background");
-	tputs(TPARM_1(set_a_background, bg), 1, outc);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_1(set_a_background, bg),
+				1, outc);
     } else {
 	TPUTS_TRACE("set_background");
-	tputs(TPARM_1(set_background, toggled_colors(bg)), 1, outc);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_1(set_background, toggled_colors(bg)),
+				1, outc);
     }
+#endif
 }
 
 static void
-set_foreground_color(int fg, int (*outc) (int))
+set_foreground_color(NCURSES_SP_DCLx int fg, NCURSES_SP_OUTC outc)
 {
+#ifdef USE_TERM_DRIVER
+    CallDriver_3(SP_PARM, td_color, TRUE, fg, outc);
+#else
     if (set_a_foreground) {
 	TPUTS_TRACE("set_a_foreground");
-	tputs(TPARM_1(set_a_foreground, fg), 1, outc);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_1(set_a_foreground, fg),
+				1, outc);
     } else {
 	TPUTS_TRACE("set_foreground");
-	tputs(TPARM_1(set_foreground, toggled_colors(fg)), 1, outc);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_1(set_foreground, toggled_colors(fg)),
+				1, outc);
     }
+#endif
 }
 
 static void
-init_color_table(void)
+init_color_table(NCURSES_SP_DCL0)
 {
-    const color_t *tp;
+    const color_t *tp = DefaultPalette;
     int n;
 
-    tp = (hue_lightness_saturation) ? hls_palette : cga_palette;
+    assert(tp != 0);
+
     for (n = 0; n < COLORS; n++) {
 	if (InPalette(n)) {
-	    SP->_color_table[n] = tp[n];
+	    SP_PARM->_color_table[n] = tp[n];
 	} else {
-	    SP->_color_table[n] = tp[n % MAX_PALETTE];
-	    if (hue_lightness_saturation) {
-		SP->_color_table[n].green = 100;
+	    SP_PARM->_color_table[n] = tp[n % MAX_PALETTE];
+	    if (UseHlsPalette) {
+		SP_PARM->_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;
+		if (SP_PARM->_color_table[n].red)
+		    SP_PARM->_color_table[n].red = 1000;
+		if (SP_PARM->_color_table[n].green)
+		    SP_PARM->_color_table[n].green = 1000;
+		if (SP_PARM->_color_table[n].blue)
+		    SP_PARM->_color_table[n].blue = 1000;
 	    }
 	}
     }
@@ -200,16 +255,20 @@
  * Reset the color pair, e.g., to whatever color pair 0 is.
  */
 static bool
-reset_color_pair(void)
+reset_color_pair(NCURSES_SP_DCL0)
 {
+#ifdef USE_TERM_DRIVER
+    return CallDriver(SP_PARM, td_rescol);
+#else
     bool result = FALSE;
 
+    (void) SP_PARM;
     if (orig_pair != 0) {
-	TPUTS_TRACE("orig_pair");
-	putp(orig_pair);
+	(void) NCURSES_PUTP2("orig_pair", orig_pair);
 	result = TRUE;
     }
     return result;
+#endif
 }
 
 /*
@@ -217,65 +276,99 @@
  * badly-written terminal descriptions than for the relatively rare case where
  * someone has changed the color definitions.
  */
-bool
-_nc_reset_colors(void)
+NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_DCL0)
 {
     int result = FALSE;
 
-    T((T_CALLED("_nc_reset_colors()")));
-    if (SP->_color_defs > 0)
-	SP->_color_defs = -(SP->_color_defs);
-
-    if (reset_color_pair())
+    T((T_CALLED("_nc_reset_colors(%p)"), (void *) SP_PARM));
+    if (SP_PARM->_color_defs > 0)
+	SP_PARM->_color_defs = -(SP_PARM->_color_defs);
+    if (reset_color_pair(NCURSES_SP_ARG))
 	result = TRUE;
+
+#ifdef USE_TERM_DRIVER
+    result = CallDriver(SP_PARM, td_rescolors);
+#else
     if (orig_colors != 0) {
-	TPUTS_TRACE("orig_colors");
-	putp(orig_colors);
+	NCURSES_PUTP2("orig_colors", orig_colors);
 	result = TRUE;
     }
+#endif
     returnBool(result);
 }
 
-NCURSES_EXPORT(int)
-start_color(void)
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(bool)
+_nc_reset_colors(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;
+    return NCURSES_SP_NAME(_nc_reset_colors) (CURRENT_SCREEN);
+}
 #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();
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(start_color) (NCURSES_SP_DCL0)
+{
+    int result = ERR;
+    int maxpairs = 0, maxcolors = 0;
+
+    T((T_CALLED("start_color(%p)"), (void *) SP_PARM));
+
+    if (SP_PARM == 0) {
+	result = ERR;
+    } else if (SP_PARM->_coloron) {
+	result = OK;
+    } else {
+	maxpairs = MaxPairs;
+	maxcolors = MaxColors;
+	if (reset_color_pair(NCURSES_SP_ARG) != TRUE) {
+	    set_foreground_color(NCURSES_SP_ARGx
+				 default_fg(NCURSES_SP_ARG),
+				 NCURSES_SP_NAME(_nc_outch));
+	    set_background_color(NCURSES_SP_ARGx
+				 default_bg(NCURSES_SP_ARG),
+				 NCURSES_SP_NAME(_nc_outch));
+	}
+#if !NCURSES_EXT_COLORS
+	/*
+	 * Without ext-colors, we cannot represent more than 256 color pairs.
+	 */
+	if (maxpairs > 256)
+	    maxpairs = 256;
+#endif
+
+	if (maxpairs > 0 && maxcolors > 0) {
+	    SP_PARM->_pair_limit = maxpairs;
+
+#if NCURSES_EXT_FUNCS
+	    /*
+	     * If using default colors, allocate extra space in table to
+	     * allow for default-color as a component of a color-pair.
+	     */
+	    SP_PARM->_pair_limit += (1 + (2 * maxcolors));
+#endif
+	    SP_PARM->_pair_count = maxpairs;
+	    SP_PARM->_color_count = maxcolors;
+#if !USE_REENTRANT
+	    COLOR_PAIRS = maxpairs;
+	    COLORS = maxcolors;
+#endif
+
+	    SP_PARM->_color_pairs = TYPE_CALLOC(colorpair_t, SP_PARM->_pair_limit);
+	    if (SP_PARM->_color_pairs != 0) {
+		SP_PARM->_color_table = TYPE_CALLOC(color_t, maxcolors);
+		if (SP_PARM->_color_table != 0) {
+		    SP_PARM->_color_pairs[0] = PAIR_OF(default_fg(NCURSES_SP_ARG),
+						       default_bg(NCURSES_SP_ARG));
+		    init_color_table(NCURSES_SP_ARG);
 
 		    T(("started color: COLORS = %d, COLOR_PAIRS = %d",
 		       COLORS, COLOR_PAIRS));
 
-		    SP->_coloron = 1;
+		    SP_PARM->_coloron = 1;
 		    result = OK;
-		} else if (SP->_color_pairs != 0) {
-		    FreeAndNull(SP->_color_pairs);
+		} else if (SP_PARM->_color_pairs != 0) {
+		    FreeAndNull(SP_PARM->_color_pairs);
 		}
 	    }
 	} else {
@@ -285,12 +378,20 @@
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+start_color(void)
+{
+    return NCURSES_SP_NAME(start_color) (CURRENT_SCREEN);
+}
+#endif
+
 /* 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)
+rgb2hls(int r, int g, int b, NCURSES_COLOR_T *h, NCURSES_COLOR_T *l, NCURSES_COLOR_T *s)
 /* convert RGB to HLS system */
 {
-    short min, max, t;
+    int min, max, t;
 
     if ((min = g < r ? g : r) > b)
 	min = b;
@@ -298,7 +399,7 @@
 	max = b;
 
     /* calculate lightness */
-    *l = (min + max) / 20;
+    *l = (NCURSES_COLOR_T) ((min + max) / 20);
 
     if (min == max) {		/* black, white and all shades of gray */
 	*h = 0;
@@ -308,19 +409,19 @@
 
     /* calculate saturation */
     if (*l < 50)
-	*s = ((max - min) * 100) / (max + min);
+	*s = (NCURSES_COLOR_T) (((max - min) * 100) / (max + min));
     else
-	*s = ((max - min) * 100) / (2000 - max - min);
+	*s = (NCURSES_COLOR_T) (((max - min) * 100) / (2000 - max - min));
 
     /* calculate hue */
     if (r == max)
-	t = 120 + ((g - b) * 60) / (max - min);
+	t = (NCURSES_COLOR_T) (120 + ((g - b) * 60) / (max - min));
     else if (g == max)
-	t = 240 + ((b - r) * 60) / (max - min);
+	t = (NCURSES_COLOR_T) (240 + ((b - r) * 60) / (max - min));
     else
-	t = 360 + ((r - g) * 60) / (max - min);
+	t = (NCURSES_COLOR_T) (360 + ((r - g) * 60) / (max - min));
 
-    *h = t % 360;
+    *h = (NCURSES_COLOR_T) (t % 360);
 }
 
 /*
@@ -328,31 +429,90 @@
  * values.
  */
 NCURSES_EXPORT(int)
-init_pair(short pair, short f, short b)
+NCURSES_SP_NAME(init_pair) (NCURSES_SP_DCLx
+			    NCURSES_PAIRS_T pair,
+			    NCURSES_COLOR_T f,
+			    NCURSES_COLOR_T b)
 {
     colorpair_t result;
+    colorpair_t previous;
+    int maxcolors;
 
-    T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b));
+    T((T_CALLED("init_pair(%p,%d,%d,%d)"),
+       (void *) SP_PARM,
+       (int) pair,
+       (int) f,
+       (int) b));
 
-    if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron)
+    if (!ValidPair(pair))
 	returnCode(ERR);
+
+    maxcolors = MaxColors;
+
+    previous = SP_PARM->_color_pairs[pair];
 #if NCURSES_EXT_FUNCS
-    if (SP->_default_color) {
-	if (f < 0)
+    if (SP_PARM->_default_color || SP_PARM->_assumed_color) {
+	bool isDefault = FALSE;
+	bool wasDefault = FALSE;
+	int default_pairs = SP_PARM->_default_pairs;
+
+	/*
+	 * Map caller's color number, e.g., -1, 0, 1, .., 7, etc., into
+	 * internal unsigned values which we will store in the _color_pairs[]
+	 * table.
+	 */
+	if (isDefaultColor(f)) {
 	    f = COLOR_DEFAULT;
-	if (b < 0)
+	    isDefault = TRUE;
+	} else if (!OkColorHi(f)) {
+	    returnCode(ERR);
+	}
+
+	if (isDefaultColor(b)) {
 	    b = COLOR_DEFAULT;
-	if (!OkColorHi(f) && !isDefaultColor(f))
+	    isDefault = TRUE;
+	} else if (!OkColorHi(b)) {
 	    returnCode(ERR);
-	if (!OkColorHi(b) && !isDefaultColor(b))
+	}
+
+	/*
+	 * Check if the table entry that we are going to init/update used
+	 * default colors.
+	 */
+	if ((FORE_OF(previous) == COLOR_DEFAULT)
+	    || (BACK_OF(previous) == COLOR_DEFAULT))
+	    wasDefault = TRUE;
+
+	/*
+	 * Keep track of the number of entries in the color pair table which
+	 * used a default color.
+	 */
+	if (isDefault && !wasDefault) {
+	    ++default_pairs;
+	} else if (wasDefault && !isDefault) {
+	    --default_pairs;
+	}
+
+	/*
+	 * As an extension, ncurses allows the pair number to exceed the
+	 * terminal's color_pairs value for pairs using a default color.
+	 *
+	 * Note that updating a pair which used a default color with one
+	 * that does not will decrement the count - and possibly interfere
+	 * with sequentially adding new pairs.
+	 */
+	if (pair > (SP_PARM->_pair_count + default_pairs)) {
 	    returnCode(ERR);
+	}
+	SP_PARM->_default_pairs = default_pairs;
     } else
 #endif
     {
 	if ((f < 0) || !OkColorHi(f)
 	    || (b < 0) || !OkColorHi(b)
-	    || (pair < 1))
+	    || (pair < 1)) {
 	    returnCode(ERR);
+	}
     }
 
     /*
@@ -361,14 +521,14 @@
      * pair colors with the new ones).
      */
     result = PAIR_OF(f, b);
-    if (SP->_color_pairs[pair] != 0
-	&& SP->_color_pairs[pair] != result) {
+    if (previous != 0
+	&& previous != result) {
 	int y, x;
 
-	for (y = 0; y <= curscr->_maxy; y++) {
-	    struct ldat *ptr = &(curscr->_line[y]);
+	for (y = 0; y <= CurScreen(SP_PARM)->_maxy; y++) {
+	    struct ldat *ptr = &(CurScreen(SP_PARM)->_line[y]);
 	    bool changed = FALSE;
-	    for (x = 0; x <= curscr->_maxx; x++) {
+	    for (x = 0; x <= CurScreen(SP_PARM)->_maxx; x++) {
 		if (GetPair(ptr->text[x]) == pair) {
 		    /* Set the old cell to zero to ensure it will be
 		       updated on the next doupdate() */
@@ -378,102 +538,196 @@
 		}
 	    }
 	    if (changed)
-		_nc_make_oldhash(y);
+		NCURSES_SP_NAME(_nc_make_oldhash) (NCURSES_SP_ARGx y);
 	}
     }
-    SP->_color_pairs[pair] = result;
-    if (GET_SCREEN_PAIR(SP) == pair)
-	SET_SCREEN_PAIR(SP, (chtype) (~0));	/* force attribute update */
 
+    SP_PARM->_color_pairs[pair] = result;
+    if (GET_SCREEN_PAIR(SP_PARM) == pair)
+	SET_SCREEN_PAIR(SP_PARM, (chtype) (~0));	/* force attribute update */
+
+#ifdef USE_TERM_DRIVER
+    CallDriver_3(SP_PARM, td_initpair, pair, f, b);
+#else
     if (initialize_pair && InPalette(f) && InPalette(b)) {
-	const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette;
+	const color_t *tp = DefaultPalette;
 
 	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));
+	    (int) pair,
+	    (int) tp[f].red, (int) tp[f].green, (int) tp[f].blue,
+	    (int) tp[b].red, (int) tp[b].green, (int) 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));
+	NCURSES_PUTP2("initialize_pair",
+		      TPARM_7(initialize_pair,
+			      pair,
+			      (int) tp[f].red,
+			      (int) tp[f].green,
+			      (int) tp[f].blue,
+			      (int) tp[b].red,
+			      (int) tp[b].green,
+			      (int) tp[b].blue));
     }
+#endif
 
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+init_pair(NCURSES_COLOR_T pair, NCURSES_COLOR_T f, NCURSES_COLOR_T b)
+{
+    return NCURSES_SP_NAME(init_pair) (CURRENT_SCREEN, pair, f, b);
+}
+#endif
+
 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
 
 NCURSES_EXPORT(int)
-init_color(short color, short r, short g, short b)
+NCURSES_SP_NAME(init_color) (NCURSES_SP_DCLx
+			     NCURSES_COLOR_T color,
+			     NCURSES_COLOR_T r,
+			     NCURSES_COLOR_T g,
+			     NCURSES_COLOR_T b)
 {
     int result = ERR;
+    int maxcolors;
 
-    T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b));
+    T((T_CALLED("init_color(%p,%d,%d,%d,%d)"),
+       (void *) SP_PARM,
+       color,
+       r, g, b));
 
-    if (initialize_color != NULL
-	&& SP != 0
-	&& SP->_coloron
+    if (SP_PARM == 0)
+	returnCode(result);
+
+    maxcolors = MaxColors;
+
+    if (InitColor
+	&& SP_PARM->_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;
+	SP_PARM->_color_table[color].init = 1;
+	SP_PARM->_color_table[color].r = r;
+	SP_PARM->_color_table[color].g = g;
+	SP_PARM->_color_table[color].b = b;
 
-	if (hue_lightness_saturation) {
+	if (UseHlsPalette) {
 	    rgb2hls(r, g, b,
-		    &SP->_color_table[color].red,
-		    &SP->_color_table[color].green,
-		    &SP->_color_table[color].blue);
+		    &SP_PARM->_color_table[color].red,
+		    &SP_PARM->_color_table[color].green,
+		    &SP_PARM->_color_table[color].blue);
 	} else {
-	    SP->_color_table[color].red = r;
-	    SP->_color_table[color].green = g;
-	    SP->_color_table[color].blue = b;
+	    SP_PARM->_color_table[color].red = r;
+	    SP_PARM->_color_table[color].green = g;
+	    SP_PARM->_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);
+#ifdef USE_TERM_DRIVER
+	CallDriver_4(SP_PARM, td_initcolor, color, r, g, b);
+#else
+	NCURSES_PUTP2("initialize_color",
+		      TPARM_4(initialize_color, color, r, g, b));
+#endif
+	SP_PARM->_color_defs = max(color + 1, SP_PARM->_color_defs);
+
 	result = OK;
     }
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+init_color(NCURSES_COLOR_T color,
+	   NCURSES_COLOR_T r,
+	   NCURSES_COLOR_T g,
+	   NCURSES_COLOR_T b)
+{
+    return NCURSES_SP_NAME(init_color) (CURRENT_SCREEN, color, r, g, b);
+}
+#endif
+
+NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(can_change_color) (NCURSES_SP_DCL)
+{
+    int result = FALSE;
+
+    T((T_CALLED("can_change_color(%p)"), (void *) SP_PARM));
+
+    if (HasTerminal(SP_PARM) && (CanChange != 0)) {
+	result = TRUE;
+    }
+
+    returnCode(result);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(bool)
 can_change_color(void)
 {
-    T((T_CALLED("can_change_color()")));
-    returnCode((can_change != 0) ? TRUE : FALSE);
+    return NCURSES_SP_NAME(can_change_color) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(has_colors) (NCURSES_SP_DCL0)
+{
+    int code = FALSE;
+
+    (void) SP_PARM;
+    T((T_CALLED("has_colors()")));
+    if (HasTerminal(SP_PARM)) {
+#ifdef USE_TERM_DRIVER
+	code = HasColor;
+#else
+	code = ((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);
+#endif
+    }
+    returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
 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);
+    return NCURSES_SP_NAME(has_colors) (CURRENT_SCREEN);
 }
+#endif
 
 NCURSES_EXPORT(int)
-color_content(short color, short *r, short *g, short *b)
+NCURSES_SP_NAME(color_content) (NCURSES_SP_DCLx
+				NCURSES_COLOR_T color,
+				NCURSES_COLOR_T *r,
+				NCURSES_COLOR_T *g,
+				NCURSES_COLOR_T *b)
 {
-    int result;
+    int result = ERR;
+    int maxcolors;
 
-    T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b));
-    if (color < 0 || !OkColorHi(color) || SP == 0 || !SP->_coloron) {
+    T((T_CALLED("color_content(%p,%d,%p,%p,%p)"),
+       (void *) SP_PARM,
+       color,
+       (void *) r,
+       (void *) g,
+       (void *) b));
+
+    if (SP_PARM == 0)
+	returnCode(result);
+
+    maxcolors = MaxColors;
+
+    if (color < 0 || !OkColorHi(color) || !SP_PARM->_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;
+	NCURSES_COLOR_T c_r = SP_PARM->_color_table[color].red;
+	NCURSES_COLOR_T c_g = SP_PARM->_color_table[color].green;
+	NCURSES_COLOR_T c_b = SP_PARM->_color_table[color].blue;
 
 	if (r)
 	    *r = c_r;
@@ -489,18 +743,36 @@
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-pair_content(short pair, short *f, short *b)
+color_content(NCURSES_COLOR_T color,
+	      NCURSES_COLOR_T *r,
+	      NCURSES_COLOR_T *g,
+	      NCURSES_COLOR_T *b)
+{
+    return NCURSES_SP_NAME(color_content) (CURRENT_SCREEN, color, r, g, b);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(pair_content) (NCURSES_SP_DCLx
+			       NCURSES_PAIRS_T pair,
+			       NCURSES_COLOR_T *f,
+			       NCURSES_COLOR_T *b)
 {
     int result;
 
-    T((T_CALLED("pair_content(%d,%p,%p)"), pair, f, b));
+    T((T_CALLED("pair_content(%p,%d,%p,%p)"),
+       (void *) SP_PARM,
+       (int) pair,
+       (void *) f,
+       (void *) b));
 
-    if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron) {
+    if (!ValidPair(pair)) {
 	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);
+	NCURSES_COLOR_T fg = (NCURSES_COLOR_T) FORE_OF(SP_PARM->_color_pairs[pair]);
+	NCURSES_COLOR_T bg = (NCURSES_COLOR_T) BACK_OF(SP_PARM->_color_pairs[pair]);
 
 #if NCURSES_EXT_FUNCS
 	if (fg == COLOR_DEFAULT)
@@ -514,34 +786,56 @@
 	if (b)
 	    *b = bg;
 
-	TR(TRACE_ATTRS, ("...pair_content(%d,%d,%d)", pair, fg, bg));
+	TR(TRACE_ATTRS, ("...pair_content(%p,%d,%d,%d)",
+			 (void *) SP_PARM,
+			 (int) pair,
+			 (int) fg, (int) bg));
 	result = OK;
     }
     returnCode(result);
 }
 
-NCURSES_EXPORT(void)
-_nc_do_color(short old_pair, short pair, bool reverse, int (*outc) (int))
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+pair_content(NCURSES_COLOR_T pair, NCURSES_COLOR_T *f, NCURSES_COLOR_T *b)
 {
+    return NCURSES_SP_NAME(pair_content) (CURRENT_SCREEN, pair, f, b);
+}
+#endif
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_DCLx
+			       int old_pair,
+			       int pair,
+			       int reverse,
+			       NCURSES_SP_OUTC outc)
+{
+#ifdef USE_TERM_DRIVER
+    CallDriver_4(SP_PARM, td_docolor, old_pair, pair, reverse, outc);
+#else
     NCURSES_COLOR_T fg = COLOR_DEFAULT;
     NCURSES_COLOR_T bg = COLOR_DEFAULT;
-    NCURSES_COLOR_T old_fg, old_bg;
+    NCURSES_COLOR_T old_fg = -1;
+    NCURSES_COLOR_T old_bg = -1;
 
-    if (pair < 0 || pair >= COLOR_PAIRS) {
+    if (!ValidPair(pair)) {
 	return;
     } else if (pair != 0) {
 	if (set_color_pair) {
 	    TPUTS_TRACE("set_color_pair");
-	    tputs(TPARM_1(set_color_pair, pair), 1, outc);
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    TPARM_1(set_color_pair, pair),
+				    1, outc);
 	    return;
-	} else if (SP != 0) {
-	    pair_content((short) pair, &fg, &bg);
+	} else if (SP_PARM != 0) {
+	    if (pair_content((NCURSES_COLOR_T) pair, &fg, &bg) == ERR)
+		return;
 	}
     }
 
     if (old_pair >= 0
-	&& SP != 0
-	&& pair_content(old_pair, &old_fg, &old_bg) != ERR) {
+	&& SP_PARM != 0
+	&& pair_content((NCURSES_COLOR_T) old_pair, &old_fg, &old_bg) != ERR) {
 	if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
 	    || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
 #if NCURSES_EXT_FUNCS
@@ -550,29 +844,29 @@
 	     * 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
+	    if (SP_PARM->_has_sgr_39_49
 		&& isDefaultColor(old_bg)
 		&& !isDefaultColor(old_fg)) {
-		tputs("\033[39m", 1, outc);
-	    } else if (SP->_has_sgr_39_49
+		NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
+	    } else if (SP_PARM->_has_sgr_39_49
 		       && isDefaultColor(old_fg)
 		       && !isDefaultColor(old_bg)) {
-		tputs("\033[49m", 1, outc);
+		NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
 	    } else
 #endif
-		reset_color_pair();
+		reset_color_pair(NCURSES_SP_ARG);
 	}
     } else {
-	reset_color_pair();
+	reset_color_pair(NCURSES_SP_ARG);
 	if (old_pair < 0)
 	    return;
     }
 
 #if NCURSES_EXT_FUNCS
     if (isDefaultColor(fg))
-	fg = default_fg();
+	fg = (NCURSES_COLOR_T) default_fg(NCURSES_SP_ARG);
     if (isDefaultColor(bg))
-	bg = default_bg();
+	bg = (NCURSES_COLOR_T) default_bg(NCURSES_SP_ARG);
 #endif
 
     if (reverse) {
@@ -585,9 +879,23 @@
 		     fg, bg));
 
     if (!isDefaultColor(fg)) {
-	set_foreground_color(fg, outc);
+	set_foreground_color(NCURSES_SP_ARGx fg, outc);
     }
     if (!isDefaultColor(bg)) {
-	set_background_color(bg, outc);
+	set_background_color(NCURSES_SP_ARGx bg, outc);
     }
+#endif
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_do_color(int old_pair, int pair, int reverse, NCURSES_OUTC outc)
+{
+    SetSafeOutcWrapper(outc);
+    NCURSES_SP_NAME(_nc_do_color) (CURRENT_SCREEN,
+				   old_pair,
+				   pair,
+				   reverse,
+				   _nc_outc_wrapper);
+}
+#endif
diff --git a/ncurses/base/lib_colorset.c b/ncurses/base/lib_colorset.c
index a973c53..e935486 100644
--- a/ncurses/base/lib_colorset.c
+++ b/ncurses/base/lib_colorset.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -28,7 +28,7 @@
 
 /****************************************************************************
  *  Author: Juergen Pfeifer,  1998                                          *
- *     and: Thomas E. Dickey, 2005                                          *
+ *     and: Thomas E. Dickey, 2005-on                                       *
  ****************************************************************************/
 
 /*
@@ -41,20 +41,23 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_colorset.c,v 1.11 2005/01/29 21:40:51 tom Exp $")
+MODULE_ID("$Id: lib_colorset.c,v 1.14 2014/02/01 22:10:42 tom Exp $")
 
 NCURSES_EXPORT(int)
-wcolor_set(WINDOW *win, short color_pair_number, void *opts)
+wcolor_set(WINDOW *win, NCURSES_PAIRS_T color_pair_number, void *opts)
 {
-    T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number));
+    int code = ERR;
+
+    T((T_CALLED("wcolor_set(%p,%d)"), (void *) win, (int) color_pair_number));
     if (win
 	&& !opts
+	&& (SP != 0)
 	&& (color_pair_number >= 0)
-	&& (color_pair_number < COLOR_PAIRS)) {
+	&& (color_pair_number < SP->_pair_limit)) {
 	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);
+	code = OK;
+    }
+    returnCode(code);
 }
diff --git a/ncurses/base/lib_delch.c b/ncurses/base/lib_delch.c
index 0c30f2d..64c9da7 100644
--- a/ncurses/base/lib_delch.c
+++ b/ncurses/base/lib_delch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2001,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,14 +40,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_delch.c,v 1.12 2001/12/19 01:06:09 tom Exp $")
+MODULE_ID("$Id: lib_delch.c,v 1.13 2009/10/24 22:32:47 tom Exp $")
 
 NCURSES_EXPORT(int)
 wdelch(WINDOW *win)
 {
     int code = ERR;
 
-    T((T_CALLED("wdelch(%p)"), win));
+    T((T_CALLED("wdelch(%p)"), (void *) win));
 
     if (win) {
 	NCURSES_CH_T blank = win->_nc_bkgd;
diff --git a/ncurses/base/lib_delwin.c b/ncurses/base/lib_delwin.c
index b92c403..4bb536c 100644
--- a/ncurses/base/lib_delwin.c
+++ b/ncurses/base/lib_delwin.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2008                    *
  ****************************************************************************/
 
 /*
@@ -40,15 +42,18 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_delwin.c,v 1.17 2008/06/07 14:10:56 tom Exp $")
+MODULE_ID("$Id: lib_delwin.c,v 1.20 2009/10/24 22:02:14 tom Exp $")
 
 static bool
 cannot_delete(WINDOW *win)
 {
     WINDOWLIST *p;
     bool result = TRUE;
+#ifdef USE_SP_WINDOWLIST
+    SCREEN *sp = _nc_screen_of(win);
+#endif
 
-    for (each_window(p)) {
+    for (each_window(SP_PARM, p)) {
 	if (&(p->win) == win) {
 	    result = FALSE;
 	} else if ((p->win._flags & _SUBWIN) != 0
@@ -65,18 +70,20 @@
 {
     int result = ERR;
 
-    T((T_CALLED("delwin(%p)"), win));
+    T((T_CALLED("delwin(%p)"), (void *) win));
 
     if (_nc_try_global(curses) == 0) {
 	if (win == 0
 	    || cannot_delete(win)) {
 	    result = ERR;
 	} else {
-
+#if NCURSES_SP_FUNCS
+	    SCREEN *sp = _nc_screen_of(win);
+#endif
 	    if (win->_flags & _SUBWIN)
 		touchwin(win->_parent);
-	    else if (curscr != 0)
-		touchwin(curscr);
+	    else if (CurScreen(SP_PARM) != 0)
+		touchwin(CurScreen(SP_PARM));
 
 	    result = _nc_freewin(win);
 	}
diff --git a/ncurses/base/lib_dft_fgbg.c b/ncurses/base/lib_dft_fgbg.c
index 8953c14..4d7fdd0 100644
--- a/ncurses/base/lib_dft_fgbg.c
+++ b/ncurses/base/lib_dft_fgbg.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,49 +27,74 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey                                                *
+ *  Author: Thomas E. Dickey          1998-on                               *
+ *          Juergen Pfeifer           2009                                  *
  ****************************************************************************/
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_dft_fgbg.c,v 1.27 2014/03/08 20:32:59 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)
+NCURSES_SP_NAME(use_default_colors) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("use_default_colors(%p)"), (void *) SP_PARM));
+    returnCode(NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_ARGx -1, -1));
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
 use_default_colors(void)
 {
-    T((T_CALLED("use_default_colors()")));
-    returnCode(assume_default_colors(-1, -1));
+    return NCURSES_SP_NAME(use_default_colors) (CURRENT_SCREEN);
 }
+#endif
 
 /*
  * 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)
+NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_DCLx int fg, int bg)
+{
+    int code = ERR;
+
+    T((T_CALLED("assume_default_colors(%p,%d,%d)"), (void *) SP_PARM, fg, bg));
+#ifdef USE_TERM_DRIVER
+    if (sp != 0)
+	code = CallDriver_2(sp, td_defaultcolors, fg, bg);
+#else
+    if ((orig_pair || orig_colors) && !initialize_pair) {
+
+	SP_PARM->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
+	SP_PARM->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
+	SP_PARM->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : (fg & C_MASK);
+	SP_PARM->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : (bg & C_MASK);
+	if (SP_PARM->_color_pairs != 0) {
+	    bool save = SP_PARM->_default_color;
+	    SP_PARM->_assumed_color = TRUE;
+	    SP_PARM->_default_color = TRUE;
+	    init_pair(0, (short) fg, (short) bg);
+	    SP_PARM->_default_color = save;
+	}
+	code = OK;
+    }
+#endif
+    returnCode(code);
+}
+
+#if NCURSES_SP_FUNCS
+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);
+    return NCURSES_SP_NAME(assume_default_colors) (CURRENT_SCREEN, fg, bg);
 }
+#endif
diff --git a/ncurses/base/lib_driver.c b/ncurses/base/lib_driver.c
new file mode 100644
index 0000000..fb63b3c
--- /dev/null
+++ b/ncurses/base/lib_driver.c
@@ -0,0 +1,145 @@
+/****************************************************************************
+ * Copyright (c) 2008-2012,2014 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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                                                 *
+ *                                                                          *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_driver.c,v 1.6 2014/04/11 08:21:23 jpf Exp $")
+
+typedef struct DriverEntry {
+    const char *name;
+    TERM_DRIVER *driver;
+} DRIVER_ENTRY;
+
+static DRIVER_ENTRY DriverTable[] =
+{
+#ifdef __MINGW32__
+    {"win32console", &_nc_WIN_DRIVER},
+#endif
+    {"tinfo", &_nc_TINFO_DRIVER}	/* must be last */
+};
+
+NCURSES_EXPORT(int)
+_nc_get_driver(TERMINAL_CONTROL_BLOCK * TCB, const char *name, int *errret)
+{
+    int code = ERR;
+    size_t i;
+    TERM_DRIVER *res = (TERM_DRIVER *) 0;
+    TERM_DRIVER *use = 0;
+
+    T((T_CALLED("_nc_get_driver(%p, %s, %p)"),
+       (void *) TCB, NonNull(name), (void *) errret));
+
+    assert(TCB != 0);
+
+    for (i = 0; i < SIZEOF(DriverTable); i++) {
+	res = DriverTable[i].driver;
+	if (strcmp(DriverTable[i].name, res->td_name(TCB)) == 0) {
+	    if (res->td_CanHandle(TCB, name, errret)) {
+		use = res;
+		break;
+	    }
+	}
+    }
+    if (use != 0) {
+	TCB->drv = use;
+	code = OK;
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(has_key) (SCREEN *sp, int keycode)
+{
+    T((T_CALLED("has_key(%p, %d)"), (void *) sp, keycode));
+    returnCode(IsValidTIScreen(sp) ? CallDriver_1(sp, td_kyExist, keycode) : FALSE);
+}
+
+NCURSES_EXPORT(int)
+has_key(int keycode)
+{
+    return NCURSES_SP_NAME(has_key) (CURRENT_SCREEN, keycode);
+}
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_mcprint) (SCREEN *sp, char *data, int len)
+{
+    int code = ERR;
+
+    if (0 != TerminalOf(sp))
+	code = CallDriver_2(sp, td_print, data, len);
+    return (code);
+}
+
+NCURSES_EXPORT(int)
+mcprint(char *data, int len)
+{
+    return NCURSES_SP_NAME(_nc_mcprint) (CURRENT_SCREEN, data, len);
+}
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(doupdate) (SCREEN *sp)
+{
+    int code = ERR;
+
+    T((T_CALLED("doupdate(%p)"), (void *) sp));
+
+    if (IsValidScreen(sp))
+	code = CallDriver(sp, td_update);
+
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+doupdate(void)
+{
+    return NCURSES_SP_NAME(doupdate) (CURRENT_SCREEN);
+}
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(mvcur) (SCREEN *sp, int yold, int xold, int ynew, int xnew)
+{
+    int code = ERR;
+    TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%p,%d,%d,%d,%d)"),
+				  (void *) sp, yold, xold, ynew, xnew));
+    if (HasTerminal(sp)) {
+	code = CallDriver_4(sp, td_hwcur, yold, xold, ynew, xnew);
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+mvcur(int yold, int xold, int ynew, int xnew)
+/* optimized cursor move from (yold, xold) to (ynew, xnew) */
+{
+    return NCURSES_SP_NAME(mvcur) (CURRENT_SCREEN, yold, xold, ynew, xnew);
+}
diff --git a/ncurses/base/lib_echo.c b/ncurses/base/lib_echo.c
index df44713..9e1d3c2 100644
--- a/ncurses/base/lib_echo.c
+++ b/ncurses/base/lib_echo.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -42,20 +44,40 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_echo.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_echo.c,v 1.8 2009/10/24 22:02:14 tom Exp $")
 
 NCURSES_EXPORT(int)
+NCURSES_SP_NAME(echo) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("echo(%p)"), (void *) SP_PARM));
+    if (0 == SP_PARM)
+	returnCode(ERR);
+    SP_PARM->_echo = TRUE;
+    returnCode(OK);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
 echo(void)
 {
-    T((T_CALLED("echo()")));
-    SP->_echo = TRUE;
+    return NCURSES_SP_NAME(echo) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(noecho) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("noecho(%p)"), (void *) SP_PARM));
+    if (0 == SP_PARM)
+	returnCode(ERR);
+    SP_PARM->_echo = FALSE;
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 noecho(void)
 {
-    T((T_CALLED("noecho()")));
-    SP->_echo = FALSE;
-    returnCode(OK);
+    return NCURSES_SP_NAME(noecho) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/base/lib_endwin.c b/ncurses/base/lib_endwin.c
index 6666287..9ebf769 100644
--- a/ncurses/base/lib_endwin.c
+++ b/ncurses/base/lib_endwin.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2009,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -39,22 +41,39 @@
 */
 
 #include <curses.priv.h>
-#include <term.h>
 
-MODULE_ID("$Id: lib_endwin.c,v 1.19 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_endwin.c,v 1.23 2014/03/08 20:32:59 tom Exp $")
 
 NCURSES_EXPORT(int)
+NCURSES_SP_NAME(endwin) (NCURSES_SP_DCL0)
+{
+    int code = ERR;
+
+    T((T_CALLED("endwin(%p)"), (void *) SP_PARM));
+
+    if (SP_PARM) {
+#ifdef USE_TERM_DRIVER
+	TERMINAL_CONTROL_BLOCK *TCB = TCBOf(SP_PARM);
+
+	SP_PARM->_endwin = TRUE;
+	if (TCB && TCB->drv && TCB->drv->td_scexit)
+	    TCB->drv->td_scexit(SP_PARM);
+#else
+	SP_PARM->_endwin = TRUE;
+	SP_PARM->_mouse_wrap(SP_PARM);
+	_nc_screen_wrap();
+	_nc_mvcur_wrap();	/* wrap up cursor addressing */
+#endif
+	code = NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_ARG);
+    }
+
+    returnCode(code);
+}
+
+#if NCURSES_SP_FUNCS
+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);
+    return NCURSES_SP_NAME(endwin) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/base/lib_erase.c b/ncurses/base/lib_erase.c
index 2566e8b..bbf10ef 100644
--- a/ncurses/base/lib_erase.c
+++ b/ncurses/base/lib_erase.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2005,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,7 +41,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_erase.c,v 1.16 2005/10/30 00:36:36 tom Exp $")
+MODULE_ID("$Id: lib_erase.c,v 1.17 2009/10/24 22:32:29 tom Exp $")
 
 NCURSES_EXPORT(int)
 werase(WINDOW *win)
@@ -51,7 +51,7 @@
     NCURSES_CH_T blank;
     NCURSES_CH_T *sp, *end, *start;
 
-    T((T_CALLED("werase(%p)"), win));
+    T((T_CALLED("werase(%p)"), (void *) win));
 
     if (win) {
 	blank = win->_nc_bkgd;
diff --git a/ncurses/base/lib_flash.c b/ncurses/base/lib_flash.c
index a6b022a..7f25038 100644
--- a/ncurses/base/lib_flash.c
+++ b/ncurses/base/lib_flash.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -39,9 +41,12 @@
  */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_flash.c,v 1.14 2014/03/08 20:32:59 tom Exp $")
 
 /*
  *	flash()
@@ -52,22 +57,31 @@
  */
 
 NCURSES_EXPORT(int)
-flash(void)
+NCURSES_SP_NAME(flash) (NCURSES_SP_DCL0)
 {
     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();
+    T((T_CALLED("flash(%p)"), (void *) SP_PARM));
+#ifdef USE_TERM_DRIVER
+    if (SP_PARM != 0)
+	res = CallDriver_1(SP_PARM, td_doBeepOrFlash, FALSE);
+#else
+    if (HasTerminal(SP_PARM)) {
+	/* FIXME: should make sure that we are not in altchar mode */
+	if (flash_screen) {
+	    res = NCURSES_PUTP2_FLUSH("flash_screen", flash_screen);
+	} else if (bell) {
+	    res = NCURSES_PUTP2_FLUSH("bell", bell);
+	}
     }
-
+#endif
     returnCode(res);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+flash(void)
+{
+    return NCURSES_SP_NAME(flash) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/base/lib_freeall.c b/ncurses/base/lib_freeall.c
index 5640265..3936c92 100644
--- a/ncurses/base/lib_freeall.c
+++ b/ncurses/base/lib_freeall.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2015 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            *
@@ -31,7 +31,6 @@
  ****************************************************************************/
 
 #include <curses.priv.h>
-#include <term_entry.h>
 #include <tic.h>
 
 #if HAVE_NC_FREEALL
@@ -40,50 +39,52 @@
 extern int malloc_errfd;	/* FIXME */
 #endif
 
-MODULE_ID("$Id: lib_freeall.c,v 1.54 2008/09/27 13:09:57 tom Exp $")
+MODULE_ID("$Id: lib_freeall.c,v 1.63 2015/05/02 23:46:26 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)
+NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0)
 {
     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_PARM != 0) {
+	if (SP_PARM->_oldnum_list != 0) {
+	    FreeAndNull(SP_PARM->_oldnum_list);
 	}
-	if (SP->_panelHook.destroy != 0) {
-	    SP->_panelHook.destroy(SP->_panelHook.stdscr_pseudo_panel);
+	if (SP_PARM->_panelHook.destroy != 0) {
+	    SP_PARM->_panelHook.destroy(SP_PARM->_panelHook.stdscr_pseudo_panel);
 	}
     }
 #endif
-    if (SP != 0) {
+    if (SP_PARM != 0) {
 	_nc_lock_global(curses);
 
-	while (_nc_windows != 0) {
+	while (WindowList(SP_PARM) != 0) {
 	    bool deleted = FALSE;
 
 	    /* Delete only windows that're not a parent */
-	    for (each_window(p)) {
+	    for (each_window(SP_PARM, p)) {
+		WINDOW *p_win = &(p->win);
 		bool found = FALSE;
 
-		for (each_window(q)) {
+		for (each_window(SP_PARM, q)) {
+		    WINDOW *q_win = &(q->win);
 		    if ((p != q)
-			&& (q->win._flags & _SUBWIN)
-			&& (&(p->win) == q->win._parent)) {
+			&& (q_win->_flags & _SUBWIN)
+			&& (p_win == q_win->_parent)) {
 			found = TRUE;
 			break;
 		    }
 		}
 
 		if (!found) {
-		    if (delwin(&(p->win)) != ERR)
+		    if (delwin(p_win) != ERR)
 			deleted = TRUE;
 		    break;
 		}
@@ -95,15 +96,13 @@
 	    if (!deleted)
 		break;
 	}
-	delscreen(SP);
+	delscreen(SP_PARM);
 	_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);
+    (void) _nc_trace_buf(-1, (size_t) 0);
 #endif
 #if USE_WIDEC_SUPPORT
     FreeIfNeeded(_nc_wacs);
@@ -121,12 +120,19 @@
     returnVoid;
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(void)
-_nc_free_and_exit(int code)
+_nc_freeall(void)
 {
-    char *last_setbuf = (SP != 0) ? SP->_setbuf : 0;
+    NCURSES_SP_NAME(_nc_freeall) (CURRENT_SCREEN);
+}
+#endif
 
-    _nc_freeall();
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code)
+{
+    NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
+    NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_ARG);
 #ifdef TRACE
     trace(0);			/* close trace file, freeing its setbuf */
     {
@@ -134,8 +140,6 @@
 	free(_nc_varargs("?", fake));
     }
 #endif
-    fclose(stdout);
-    FreeIfNeeded(last_setbuf);
     exit(code);
 }
 
@@ -146,12 +150,21 @@
 }
 
 NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code)
+{
+    if (SP_PARM) {
+	delscreen(SP_PARM);
+	if (SP_PARM->_term)
+	    NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx SP_PARM->_term);
+    }
+    exit(code);
+}
+#endif
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
 _nc_free_and_exit(int code)
 {
-    if (SP)
-	delscreen(SP);
-    if (cur_term != 0)
-	del_curterm(cur_term);
-    exit(code);
+    NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code);
 }
 #endif
diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c
index a3812be..42eb9cc 100644
--- a/ncurses/base/lib_getch.c
+++ b/ncurses/base/lib_getch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -41,40 +42,80 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_getch.c,v 1.99 2008/09/20 19:46:13 tom Exp $")
+MODULE_ID("$Id: lib_getch.c,v 1.132 2015/05/09 17:10:41 tom Exp $")
 
 #include <fifo_defs.h>
 
 #if USE_REENTRANT
-#define GetEscdelay(sp) (sp)->_ESCDELAY
+#define GetEscdelay(sp) *_nc_ptr_Escdelay(sp)
 NCURSES_EXPORT(int)
 NCURSES_PUBLIC_VAR(ESCDELAY) (void)
 {
-    return SP ? GetEscdelay(SP) : 1000;
+    return *(_nc_ptr_Escdelay(CURRENT_SCREEN));
+}
+
+NCURSES_EXPORT(int *)
+_nc_ptr_Escdelay(SCREEN *sp)
+{
+    return ptrEscdelay(sp);
 }
 #else
 #define GetEscdelay(sp) ESCDELAY
-NCURSES_EXPORT_VAR(int)
-ESCDELAY = 1000;		/* max interval betw. chars in funkeys, in millisecs */
+NCURSES_EXPORT_VAR(int) ESCDELAY = 1000;
 #endif
 
 #if NCURSES_EXT_FUNCS
 NCURSES_EXPORT(int)
-set_escdelay(int value)
+NCURSES_SP_NAME(set_escdelay) (NCURSES_SP_DCLx int value)
 {
     int code = OK;
 #if USE_REENTRANT
-    if (SP) {
-	SP->_ESCDELAY = value;
+    if (SP_PARM) {
+	SET_ESCDELAY(value);
     } else {
 	code = ERR;
     }
 #else
+    (void) SP_PARM;
     ESCDELAY = value;
 #endif
     return code;
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+set_escdelay(int value)
+{
+    int code;
+#if USE_REENTRANT
+    code = NCURSES_SP_NAME(set_escdelay) (CURRENT_SCREEN, value);
+#else
+    ESCDELAY = value;
+    code = OK;
 #endif
+    return code;
+}
+#endif
+#endif /* NCURSES_EXT_FUNCS */
+
+#if NCURSES_EXT_FUNCS
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(get_escdelay) (NCURSES_SP_DCL0)
+{
+#if !USE_REENTRANT
+    (void) SP_PARM;
+#endif
+    return GetEscdelay(SP_PARM);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+get_escdelay(void)
+{
+    return NCURSES_SP_NAME(get_escdelay) (CURRENT_SCREEN);
+}
+#endif
+#endif /* NCURSES_EXT_FUNCS */
 
 static int
 _nc_use_meta(WINDOW *win)
@@ -83,10 +124,15 @@
     return (sp ? sp->_use_meta : 0);
 }
 
-#ifdef NCURSES_WGETCH_EVENTS
-#define TWAIT_MASK 7
-#else
-#define TWAIT_MASK 3
+#ifdef USE_TERM_DRIVER
+# ifdef __MINGW32__
+static HANDLE
+_nc_get_handle(int fd)
+{
+    intptr_t value = _get_osfhandle(fd);
+    return (HANDLE) value;
+}
+# endif
 #endif
 
 /*
@@ -97,19 +143,38 @@
 {
     int rc;
 
+#ifdef USE_TERM_DRIVER
+    TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
+    rc = TCBOf(sp)->drv->td_testmouse(TCBOf(sp), delay EVENTLIST_2nd(evl));
+# ifdef __MINGW32__
+    /* if we emulate terminfo on console, we have to use the console routine */
+    if (IsTermInfoOnConsole(sp)) {
+	HANDLE fd = _nc_get_handle(sp->_ifd);
+	rc = _nc_mingw_testmouse(sp, fd, delay EVENTLIST_2nd(evl));
+    } else
+# endif
+	rc = TCB->drv->td_testmouse(TCB, delay EVENTLIST_2nd(evl));
+#else
 #if USE_SYSMOUSE
     if ((sp->_mouse_type == M_SYSMOUSE)
 	&& (sp->_sysmouse_head < sp->_sysmouse_tail)) {
-	return 2;
-    }
+	rc = TW_MOUSE;
+    } else
 #endif
-    rc = _nc_timed_wait(sp, TWAIT_MASK, delay, (int *) 0 EVENTLIST_2nd(evl));
+    {
+	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;
+	if ((sp->_mouse_type == M_SYSMOUSE)
+	    && (sp->_sysmouse_head < sp->_sysmouse_tail)
+	    && (rc == 0)
+	    && (errno == EINTR)) {
+	    rc |= TW_MOUSE;
+	}
+#endif
     }
 #endif
     return rc;
@@ -118,7 +183,7 @@
 static NCURSES_INLINE int
 fifo_peek(SCREEN *sp)
 {
-    int ch = sp->_fifo[peek];
+    int ch = (peek >= 0) ? sp->_fifo[peek] : ERR;
     TR(TRACE_IEVENT, ("peeking at %d", peek));
 
     p_inc();
@@ -128,15 +193,16 @@
 static NCURSES_INLINE int
 fifo_pull(SCREEN *sp)
 {
-    int ch;
-    ch = sp->_fifo[head];
+    int ch = (head >= 0) ? sp->_fifo[head] : ERR;
+
     TR(TRACE_IEVENT, ("pulling %s from %d", _nc_tracechar(sp, ch), head));
 
     if (peek == head) {
 	h_inc();
 	peek = head;
-    } else
+    } else {
 	h_inc();
+    }
 
 #ifdef TRACE
     if (USE_TRACEF(TRACE_IEVENT)) {
@@ -155,7 +221,7 @@
     int mask = 0;
 
     (void) mask;
-    if (tail == -1)
+    if (tail < 0)
 	return ERR;
 
 #ifdef HIDE_EINTR
@@ -173,9 +239,9 @@
     } else
 	mask = 0;
 
-    if (mask & 4) {
+    if (mask & TW_EVENT) {
 	T(("fifo_push: ungetch KEY_EVENT"));
-	_nc_ungetch(sp, KEY_EVENT);
+	safe_ungetch(sp, KEY_EVENT);
 	return KEY_EVENT;
     }
 #elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
@@ -185,7 +251,7 @@
 #endif
 
 #if USE_GPM_SUPPORT || USE_EMX_MOUSE
-    if ((sp->_mouse_fd >= 0) && (mask & 2)) {
+    if ((sp->_mouse_fd >= 0) && (mask & TW_MOUSE)) {
 	sp->_mouse_event(sp);
 	ch = KEY_MOUSE;
 	n = 1;
@@ -204,10 +270,47 @@
 	n = 1;
     } else
 #endif
+#ifdef USE_TERM_DRIVER
+	if ((sp->_mouse_type == M_TERM_DRIVER)
+	    && (sp->_drv_mouse_head < sp->_drv_mouse_tail)) {
+	sp->_mouse_event(sp);
+	ch = KEY_MOUSE;
+	n = 1;
+    } else
+#endif
+#if USE_KLIBC_KBD
+    if (NC_ISATTY(sp->_ifd) && sp->_cbreak) {
+	ch = _read_kbd(0, 1, !sp->_raw);
+	n = (ch == -1) ? -1 : 1;
+	sp->_extended_key = (ch == 0);
+    } else
+#endif
     {				/* Can block... */
+#ifdef USE_TERM_DRIVER
+	int buf;
+#ifdef __MINGW32__
+	if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && sp->_cbreak)
+	    n = _nc_mingw_console_read(sp,
+				       _nc_get_handle(sp->_ifd),
+				       &buf);
+	else
+#endif
+	    n = CallDriver_1(sp, td_read, &buf);
+	ch = buf;
+#else
 	unsigned char c2 = 0;
-	n = read(sp->_ifd, &c2, 1);
+# if USE_PTHREADS_EINTR
+#  if USE_WEAK_SYMBOLS
+	if ((pthread_self) && (pthread_kill) && (pthread_equal))
+#  endif
+	    _nc_globals.read_thread = pthread_self();
+# endif
+	n = (int) read(sp->_ifd, &c2, (size_t) 1);
+#if USE_PTHREADS_EINTR
+	_nc_globals.read_thread = 0;
+#endif
 	ch = c2;
+#endif
     }
 
 #ifdef HIDE_EINTR
@@ -220,7 +323,11 @@
      * 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)
+    if (n <= 0 && errno == EINTR
+# if USE_PTHREADS_EINTR
+	&& (_nc_globals.have_sigwinch == 0)
+# endif
+	)
 	goto again;
 #endif
 
@@ -260,12 +367,12 @@
 {
 #ifdef USE_PTHREADS
     SCREEN *sp = _nc_screen_of(win);
-    if (_nc_use_pthreads && sp != SP) {
+    if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
 	SCREEN *save_SP;
 
 	/* temporarily switch to the window's screen to check/refresh */
 	_nc_lock_global(curses);
-	save_SP = SP;
+	save_SP = CURRENT_SCREEN;
 	_nc_set_screen(sp);
 	recur_wrefresh(win);
 	_nc_set_screen(save_SP);
@@ -286,12 +393,12 @@
 
     if (sp != 0) {
 #ifdef USE_PTHREADS
-	if (_nc_use_pthreads && sp != SP) {
+	if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
 	    SCREEN *save_SP;
 
 	    /* temporarily switch to the window's screen to get cooked input */
 	    _nc_lock_global(curses);
-	    save_SP = SP;
+	    save_SP = CURRENT_SCREEN;
 	    _nc_set_screen(sp);
 	    rc = recur_wgetnstr(win, buf);
 	    _nc_set_screen(save_SP);
@@ -311,17 +418,18 @@
 
 NCURSES_EXPORT(int)
 _nc_wgetch(WINDOW *win,
-	   unsigned long *result,
+	   int *result,
 	   int use_meta
 	   EVENTLIST_2nd(_nc_eventlist * evl))
 {
     SCREEN *sp;
     int ch;
+    int rc = 0;
 #ifdef NCURSES_WGETCH_EVENTS
-    long event_delay = -1;
+    int event_delay = -1;
 #endif
 
-    T((T_CALLED("_nc_wgetch(%p)"), win));
+    T((T_CALLED("_nc_wgetch(%p)"), (void *) win));
 
     *result = 0;
 
@@ -352,19 +460,20 @@
 	!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)
+	rc = recur_wgetnstr(win, buf);
+	if (rc != KEY_EVENT && rc != ERR)
+	    safe_ungetch(sp, '\n');
+#else
+	if (recur_wgetnstr(win, buf) != ERR)
+	    safe_ungetch(sp, '\n');
 #endif
-	    _nc_ungetch(sp, '\n');
 	for (bufp = buf + strlen(buf); bufp > buf; bufp--)
-	    _nc_ungetch(sp, bufp[-1]);
+	    safe_ungetch(sp, bufp[-1]);
 
 #ifdef NCURSES_WGETCH_EVENTS
 	/* Return it first */
@@ -384,7 +493,6 @@
     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)
@@ -402,13 +510,13 @@
 	    rc = check_mouse_activity(sp, delay EVENTLIST_2nd(evl));
 
 #ifdef NCURSES_WGETCH_EVENTS
-	    if (rc & 4) {
+	    if (rc & TW_EVENT) {
 		*result = KEY_EVENT;
 		returnCode(KEY_CODE_YES);
 	    }
 #endif
 	    if (!rc) {
-		returnCode(ERR);
+		goto check_sigwinch;
 	    }
 	}
 	/* else go on to read data available */
@@ -427,7 +535,6 @@
 	 * increase the wait with mouseinterval().
 	 */
 	int runcount = 0;
-	int rc;
 
 	do {
 	    ch = kgetch(sp EVENTLIST_2nd(evl));
@@ -442,11 +549,11 @@
 	    (ch == KEY_MOUSE
 	     && (((rc = check_mouse_activity(sp, sp->_maxclick
 					     EVENTLIST_2nd(evl))) != 0
-		  && !(rc & 4))
+		  && !(rc & TW_EVENT))
 		 || !sp->_mouse_parse(sp, runcount)));
 #ifdef NCURSES_WGETCH_EVENTS
-	if ((rc & 4) && !ch == KEY_EVENT) {
-	    _nc_ungetch(sp, ch);
+	if ((rc & TW_EVENT) && !(ch == KEY_EVENT)) {
+	    safe_ungetch(sp, ch);
 	    ch = KEY_EVENT;
 	}
 #endif
@@ -454,12 +561,12 @@
 #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... */
+		safe_ungetch(sp, KEY_MOUSE);	/* FIXME This interrupts a gesture... */
 	    } else
 #endif
 	    {
 		/* mouse event sequence ended by keystroke, store keystroke */
-		_nc_ungetch(sp, ch);
+		safe_ungetch(sp, ch);
 		ch = KEY_MOUSE;
 	    }
 	}
@@ -470,12 +577,19 @@
     }
 
     if (ch == ERR) {
+      check_sigwinch:
 #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);
+		/*
+		 * Get the ERR from queue -- it is from WINCH,
+		 * so we should take it out, the "error" is handled.
+		 */
+		if (fifo_peek(sp) == -1)
+		    fifo_pull(sp);
 		returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
 	    }
 	}
@@ -490,7 +604,7 @@
      *
      * 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. 
+     * 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.
      *
@@ -502,7 +616,7 @@
      * cursor to the left.
      */
     if (sp->_echo && !(win->_flags & _ISPAD)) {
-	chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch;
+	chtype backup = (chtype) ((ch == KEY_BACKSPACE) ? '\b' : ch);
 	if (backup < KEY_MIN)
 	    wechochar(win, backup);
     }
@@ -533,7 +647,7 @@
 wgetch_events(WINDOW *win, _nc_eventlist * evl)
 {
     int code;
-    unsigned long value;
+    int value;
 
     T((T_CALLED("wgetch_events(%p,%p)"), win, evl));
     code = _nc_wgetch(win,
@@ -550,9 +664,9 @@
 wgetch(WINDOW *win)
 {
     int code;
-    unsigned long value;
+    int value;
 
-    T((T_CALLED("wgetch(%p)"), win));
+    T((T_CALLED("wgetch(%p)"), (void *) win));
     code = _nc_wgetch(win,
 		      &value,
 		      _nc_use_meta(win)
@@ -626,14 +740,15 @@
 	    break;
 	}
 	TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d",
-			  ptr, ptr->ch, ptr->value));
+			  (void *) ptr, ptr->ch, ptr->value));
 
 	if (ptr->value != 0) {	/* sequence terminated */
 	    TR(TRACE_IEVENT, ("end of sequence"));
-	    if (peek == tail)
+	    if (peek == tail) {
 		fifo_clear(sp);
-	    else
+	    } else {
 		head = peek;
+	    }
 	    return (ptr->value);
 	}
 
@@ -645,7 +760,7 @@
 	    TR(TRACE_IEVENT, ("waiting for rest of sequence"));
 	    rc = check_mouse_activity(sp, timeleft EVENTLIST_2nd(evl));
 #ifdef NCURSES_WGETCH_EVENTS
-	    if (rc & 4) {
+	    if (rc & TW_EVENT) {
 		TR(TRACE_IEVENT, ("interrupted by a user event"));
 		/* FIXME Should have preserved remainder timeleft for reuse... */
 		peek = head;	/* Restart interpreting later */
diff --git a/ncurses/base/lib_getstr.c b/ncurses/base/lib_getstr.c
index b17df03..0e44634 100644
--- a/ncurses/base/lib_getstr.c
+++ b/ncurses/base/lib_getstr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,16 +39,15 @@
 */
 
 #include <curses.priv.h>
-#include <term.h>
 
-MODULE_ID("$Id: lib_getstr.c,v 1.27 2008/08/16 19:20:04 tom Exp $")
+MODULE_ID("$Id: lib_getstr.c,v 1.30 2011/10/22 16:31:35 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)
+WipeOut(WINDOW *win, int y, int x, char *first, char *last, int echoed)
 {
     if (last > first) {
 	*--last = '\0';
@@ -84,24 +83,24 @@
     int ch;
     int y, x;
 
-    T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen));
+    T((T_CALLED("wgetnstr(%p,%p,%d)"), (void *) win, (void *) str, maxlen));
 
     if (!win)
 	returnCode(ERR);
 
-    _nc_get_tty_mode(&buf);
+    NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx &buf);
 
     oldnl = sp->_nl;
     oldecho = sp->_echo;
     oldraw = sp->_raw;
     oldcbreak = sp->_cbreak;
-    nl();
-    noecho();
-    noraw();
-    cbreak();
+    NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
+    NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
+    NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
+    NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
 
-    erasec = erasechar();
-    killc = killchar();
+    erasec = NCURSES_SP_NAME(erasechar) (NCURSES_SP_ARG);
+    killc = NCURSES_SP_NAME(killchar) (NCURSES_SP_ARG);
 
     oldstr = str;
     getyx(win, y, x);
@@ -144,7 +143,7 @@
 	    }
 	} else if (ch >= KEY_MIN
 		   || (maxlen >= 0 && str - oldstr >= maxlen)) {
-	    beep();
+	    NCURSES_SP_NAME(beep) (NCURSES_SP_ARG);
 	} else {
 	    *str++ = (char) ch;
 	    if (oldecho == TRUE) {
@@ -193,7 +192,7 @@
     sp->_raw = oldraw;
     sp->_cbreak = oldcbreak;
 
-    _nc_set_tty_mode(&buf);
+    NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 
     *str = '\0';
     if (ch == ERR)
diff --git a/ncurses/base/lib_hline.c b/ncurses/base/lib_hline.c
index 2ef2cc5..1f03808 100644
--- a/ncurses/base/lib_hline.c
+++ b/ncurses/base/lib_hline.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,16 +40,16 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_hline.c,v 1.11 2006/03/11 21:52:27 tom Exp $")
+MODULE_ID("$Id: lib_hline.c,v 1.13 2010/12/19 01:48:39 tom Exp $")
 
 NCURSES_EXPORT(int)
 whline(WINDOW *win, chtype ch, int n)
 {
     int code = ERR;
-    NCURSES_SIZE_T start;
-    NCURSES_SIZE_T end;
+    int start;
+    int end;
 
-    T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n));
+    T((T_CALLED("whline(%p,%s,%d)"), (void *) win, _tracechtype(ch), n));
 
     if (win) {
 	struct ldat *line = &(win->_line[win->_cury]);
diff --git a/ncurses/base/lib_immedok.c b/ncurses/base/lib_immedok.c
index 87988b6..d51b60a 100644
--- a/ncurses/base/lib_immedok.c
+++ b/ncurses/base/lib_immedok.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,12 +40,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_immedok.c,v 1.4 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_immedok.c,v 1.5 2009/10/24 22:32:11 tom Exp $")
 
 NCURSES_EXPORT(void)
 immedok(WINDOW *win, bool flag)
 {
-    T((T_CALLED("immedok(%p,%d)"), win, flag));
+    T((T_CALLED("immedok(%p,%d)"), (void *) win, flag));
 
     if (win)
 	win->_immed = flag;
diff --git a/ncurses/base/lib_inchstr.c b/ncurses/base/lib_inchstr.c
index 6ff0168..aebb6d6 100644
--- a/ncurses/base/lib_inchstr.c
+++ b/ncurses/base/lib_inchstr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -29,6 +29,7 @@
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
  ****************************************************************************/
 
 /*
@@ -40,14 +41,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_inchstr.c,v 1.10 2001/06/02 23:37:58 skimo Exp $")
+MODULE_ID("$Id: lib_inchstr.c,v 1.12 2010/12/20 01:37:41 tom Exp $")
 
 NCURSES_EXPORT(int)
-winchnstr(WINDOW *win, chtype * str, int n)
+winchnstr(WINDOW *win, chtype *str, int n)
 {
     int i = 0;
 
-    T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n));
+    T((T_CALLED("winchnstr(%p,%p,%d)"), (void *) win, (void *) str, n));
 
     if (!str)
 	returnCode(0);
@@ -55,7 +56,7 @@
     if (win) {
 	for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++)
 	    str[i] =
-		CharOf(win->_line[win->_cury].text[win->_curx + i]) |
+		(chtype) CharOf(win->_line[win->_cury].text[win->_curx + i]) |
 		AttrOf(win->_line[win->_cury].text[win->_curx + i]);
     }
     str[i] = (chtype) 0;
diff --git a/ncurses/base/lib_initscr.c b/ncurses/base/lib_initscr.c
index b2fef0c..0e8a297 100644
--- a/ncurses/base/lib_initscr.c
+++ b/ncurses/base/lib_initscr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -45,7 +45,7 @@
 #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 $")
+MODULE_ID("$Id: lib_initscr.c,v 1.40 2014/04/26 18:47:51 juergen Exp $")
 
 NCURSES_EXPORT(WINDOW *)
 initscr(void)
@@ -75,9 +75,9 @@
 	 * core when attempting to write to stdout.  Opening /dev/tty
 	 * explicitly seems to fix the problem.
 	 */
-	if (isatty(fileno(stdout))) {
+	if (NC_ISATTY(fileno(stdout))) {
 	    FILE *fp = fopen("/dev/tty", "w");
-	    if (fp != 0 && isatty(fileno(fp))) {
+	    if (fp != 0 && NC_ISATTY(fileno(fp))) {
 		fclose(stdout);
 		dup2(fileno(fp), STDOUT_FILENO);
 		stdout = fdopen(STDOUT_FILENO, "w");
@@ -90,7 +90,11 @@
 	}
 
 	/* def_shell_mode - done in newterm/_nc_setupscreen */
+#if NCURSES_SP_FUNCS
+	NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
+#else
 	def_prog_mode();
+#endif
     }
     result = stdscr;
     _nc_unlock_global(curses);
diff --git a/ncurses/base/lib_insch.c b/ncurses/base/lib_insch.c
index 9166ea5..32eaed7 100644
--- a/ncurses/base/lib_insch.c
+++ b/ncurses/base/lib_insch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -43,24 +43,32 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_insch.c,v 1.25 2008/02/03 00:14:37 tom Exp $")
+MODULE_ID("$Id: lib_insch.c,v 1.35 2013/05/18 21:58:56 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)
+_nc_insert_ch(SCREEN *sp, WINDOW *win, chtype ch)
 {
     int code = OK;
+    int ch8 = (int) ChCharOf(ch);
     NCURSES_CH_T wch;
     int count;
     NCURSES_CONST char *s;
+    int tabsize = (
+#if USE_REENTRANT
+		      sp->_TABSIZE
+#else
+		      TABSIZE
+#endif
+    );
 
     switch (ch) {
     case '\t':
-	for (count = (TABSIZE - (win->_curx % TABSIZE)); count > 0; count--) {
-	    if ((code = _nc_insert_ch(win, ' ')) != OK)
+	for (count = (tabsize - (win->_curx % tabsize)); count > 0; count--) {
+	    if ((code = _nc_insert_ch(sp, win, ' ')) != OK)
 		break;
 	}
 	break;
@@ -75,8 +83,9 @@
 #if USE_WIDEC_SUPPORT
 	       WINDOW_EXT(win, addch_used) == 0 &&
 #endif
-	       is8bits(ChCharOf(ch)) &&
-	       isprint(ChCharOf(ch))) {
+	       (isprint(ch8) ||
+		(ChAttrOf(ch) & A_ALTCHARSET) ||
+		(sp != 0 && sp->_legacy_coding && !iscntrl(ch8)))) {
 	    if (win->_curx <= win->_maxx) {
 		struct ldat *line = &(win->_line[win->_cury]);
 		NCURSES_CH_T *end = &(line->text[win->_curx]);
@@ -92,10 +101,10 @@
 		*temp1 = _nc_render(win, wch);
 		win->_curx++;
 	    }
-	} else if (is8bits(ChCharOf(ch)) && iscntrl(ChCharOf(ch))) {
-	    s = unctrl(ChCharOf(ch));
+	} else if (iscntrl(ch8)) {
+	    s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
 	    while (*s != '\0') {
-		code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
+		code = _nc_insert_ch(sp, win, ChAttrOf(ch) | UChar(*s));
 		if (code != OK)
 		    break;
 		++s;
@@ -110,13 +119,14 @@
 	    wch = _nc_render(win, wch);
 	    count = _nc_build_wch(win, &wch);
 	    if (count > 0) {
-		code = wins_wch(win, &wch);
+		code = _nc_insert_wch(win, &wch);
 	    } else if (count == -1) {
 		/* handle EILSEQ */
-		if (is8bits(ch)) {
-		    s = unctrl(ChCharOf(ch));
+		s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
+		if (strlen(s) > 1) {
 		    while (*s != '\0') {
-			code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
+			code = _nc_insert_ch(sp, win,
+					     ChAttrOf(ch) | UChar(*s));
 			if (code != OK)
 			    break;
 			++s;
@@ -139,13 +149,13 @@
     NCURSES_SIZE_T ox;
     int code = ERR;
 
-    T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c)));
+    T((T_CALLED("winsch(%p, %s)"), (void *) win, _tracechtype(c)));
 
     if (win != 0) {
 	oy = win->_cury;
 	ox = win->_curx;
 
-	code = _nc_insert_ch(win, c);
+	code = _nc_insert_ch(_nc_screen_of(win), win, c);
 
 	win->_curx = ox;
 	win->_cury = oy;
diff --git a/ncurses/base/lib_insdel.c b/ncurses/base/lib_insdel.c
index 342c654..8f51bbe 100644
--- a/ncurses/base/lib_insdel.c
+++ b/ncurses/base/lib_insdel.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2003,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -42,14 +42,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_insdel.c,v 1.12 2003/07/26 22:40:06 tom Exp $")
+MODULE_ID("$Id: lib_insdel.c,v 1.13 2009/10/24 22:34:41 tom Exp $")
 
 NCURSES_EXPORT(int)
 winsdelln(WINDOW *win, int n)
 {
     int code = ERR;
 
-    T((T_CALLED("winsdelln(%p,%d)"), win, n));
+    T((T_CALLED("winsdelln(%p,%d)"), (void *) win, n));
 
     if (win) {
 	if (n != 0) {
diff --git a/ncurses/base/lib_insnstr.c b/ncurses/base/lib_insnstr.c
index b6ddfde..ce03e64 100644
--- a/ncurses/base/lib_insnstr.c
+++ b/ncurses/base/lib_insnstr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2004 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2004,2009 Free Software Foundation, Inc.                   *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,7 +40,7 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_insnstr.c,v 1.1 2004/02/28 23:44:56 tom Exp $")
+MODULE_ID("$Id: lib_insnstr.c,v 1.3 2009/10/24 22:04:35 tom Exp $")
 
 NCURSES_EXPORT(int)
 winsnstr(WINDOW *win, const char *s, int n)
@@ -51,13 +51,15 @@
     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));
+    T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n));
 
     if (win != 0 && str != 0) {
+	SCREEN *sp = _nc_screen_of(win);
+
 	oy = win->_cury;
 	ox = win->_curx;
 	for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
-	    _nc_insert_ch(win, (chtype) UChar(*cp));
+	    _nc_insert_ch(sp, win, (chtype) UChar(*cp));
 	}
 	win->_curx = ox;
 	win->_cury = oy;
diff --git a/ncurses/base/lib_instr.c b/ncurses/base/lib_instr.c
index 3fb2949..f708ecc 100644
--- a/ncurses/base/lib_instr.c
+++ b/ncurses/base/lib_instr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,14 +41,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_instr.c,v 1.16 2007/07/21 20:18:10 tom Exp $")
+MODULE_ID("$Id: lib_instr.c,v 1.21 2014/02/01 22:09:27 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));
+    T((T_CALLED("winnstr(%p,%p,%d)"), (void *) win, str, n));
 
     if (!str)
 	returnCode(0);
@@ -64,7 +64,7 @@
 	    cchar_t *cell = &(win->_line[row].text[col]);
 	    wchar_t *wch;
 	    attr_t attrs;
-	    short pair;
+	    NCURSES_PAIRS_T pair;
 	    int n2;
 	    bool done = FALSE;
 	    mbstate_t state;
@@ -78,19 +78,23 @@
 		    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);
+			n3 = wcstombs(0, wch, (size_t) 0);
+			if (!isEILSEQ(n3) && (n3 != 0)) {
+			    size_t need = n3 + 10 + (size_t) i;
+			    int have = (int) n3 + i;
+
+			    /* check for loop-done as well as overflow */
+			    if (have > n || (int) need <= 0) {
+				done = TRUE;
+			    } else if ((tmp = typeCalloc(char, need)) == 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);
diff --git a/ncurses/base/lib_isendwin.c b/ncurses/base/lib_isendwin.c
index b337d97..923e35b 100644
--- a/ncurses/base/lib_isendwin.c
+++ b/ncurses/base/lib_isendwin.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -40,12 +42,20 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_isendwin.c,v 1.6 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_isendwin.c,v 1.7 2009/02/15 00:36:24 tom Exp $")
 
 NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(isendwin) (NCURSES_SP_DCL0)
+{
+    if (SP_PARM == NULL)
+	return FALSE;
+    return SP_PARM->_endwin;
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(bool)
 isendwin(void)
 {
-    if (SP == NULL)
-	return FALSE;
-    return SP->_endwin;
+    return NCURSES_SP_NAME(isendwin) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/base/lib_leaveok.c b/ncurses/base/lib_leaveok.c
index 17d095d..e6995f8 100644
--- a/ncurses/base/lib_leaveok.c
+++ b/ncurses/base/lib_leaveok.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,12 +40,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_leaveok.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_leaveok.c,v 1.6 2009/10/24 22:34:23 tom Exp $")
 
 NCURSES_EXPORT(int)
 leaveok(WINDOW *win, bool flag)
 {
-    T((T_CALLED("leaveok(%p,%d)"), win, flag));
+    T((T_CALLED("leaveok(%p,%d)"), (void *) win, flag));
 
     if (win) {
 	win->_leaveok = flag;
diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c
index 95f29aa..36b6e1e 100644
--- a/ncurses/base/lib_mouse.c
+++ b/ncurses/base/lib_mouse.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2008                    *
  ****************************************************************************/
 
 /*
@@ -79,9 +80,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_mouse.c,v 1.102 2008/10/18 21:48:55 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-#include <term.h>
+MODULE_ID("$Id: lib_mouse.c,v 1.166 2015/07/05 00:28:27 tom Exp $")
+
 #include <tic.h>
 
 #if USE_GPM_SUPPORT
@@ -108,7 +112,7 @@
 #undef buttons			/* symbol conflict in consio.h */
 #undef mouse_info		/* symbol conflict in consio.h */
 #include <osreldate.h>
-#if (__FreeBSD_version >= 400017)
+#if defined(__DragonFly_version) || (defined(__FreeBSD__) && (__FreeBSD_version >= 400017))
 #include <sys/consio.h>
 #include <sys/fbio.h>
 #else
@@ -116,14 +120,25 @@
 #endif
 #endif				/* use_SYSMOUSE */
 
+#if USE_KLIBC_MOUSE
+#include <sys/socket.h>
+#define pipe(handles) socketpair(AF_LOCAL, SOCK_STREAM, 0, handles)
+#define DosWrite(hfile, pbuffer, cbwrite, pcbactual) \
+		write(hfile, pbuffer, cbwrite)
+#define DosExit(action, result )	/* do nothing */
+#define DosCreateThread(ptid, pfn, param, flag, cbStack) \
+		(*(ptid) = _beginthread(pfn, NULL, cbStack, \
+					(void *)param), (*(ptid) == -1))
+#endif
+
 #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)
+#define	MASK_RELEASE(x)		(mmask_t) NCURSES_MOUSE_MASK(x, 001)
+#define	MASK_PRESS(x)		(mmask_t) NCURSES_MOUSE_MASK(x, 002)
+#define	MASK_CLICK(x)		(mmask_t) NCURSES_MOUSE_MASK(x, 004)
+#define	MASK_DOUBLE_CLICK(x)	(mmask_t) NCURSES_MOUSE_MASK(x, 010)
+#define	MASK_TRIPLE_CLICK(x)	(mmask_t) NCURSES_MOUSE_MASK(x, 020)
+#define	MASK_RESERVED_EVENT(x)	(mmask_t) NCURSES_MOUSE_MASK(x, 040)
 
 #if NCURSES_MOUSE_VERSION == 1
 #define BUTTON_CLICKED        (BUTTON1_CLICKED        | BUTTON2_CLICKED        | BUTTON3_CLICKED        | BUTTON4_CLICKED)
@@ -144,13 +159,16 @@
 #define INVALID_EVENT	-1
 #define NORMAL_EVENT	0
 
+#define ValidEvent(ep) ((ep)->id != INVALID_EVENT)
+#define Invalidate(ep) (ep)->id = INVALID_EVENT
+
 #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))
+#define GET_DLSYM(name) (my_##name = (TYPE_##name) dlsym(sp->_dlopen_gpm, #name))
 
 #endif				/* USE_GPM_SUPPORT */
 
@@ -164,13 +182,13 @@
 #define LastEV(sp)	((sp)->_mouse_events + EV_MAX - 1)
 
 #undef  NEXT
-#define NEXT(ep)	((ep >= LastEV(sp)) \
-			 ? FirstEV(sp) \
+#define NEXT(ep)	((ep >= LastEV(SP_PARM)) \
+			 ? FirstEV(SP_PARM) \
 			 : ep + 1)
 
 #undef  PREV
-#define PREV(ep)	((ep <= FirstEV(sp)) \
-			 ? LastEV(sp) \
+#define PREV(ep)	((ep <= FirstEV(SP_PARM)) \
+			 ? LastEV(SP_PARM) \
 			 : ep - 1)
 
 #define IndexEV(sp, ep)	(ep - FirstEV(sp))
@@ -185,7 +203,7 @@
 {
     MEVENT *ep;
 
-    _tracef(tag);
+    _tracef("%s", tag);
 
     for (ep = FirstEV(sp); ep <= LastEV(sp); ep++)
 	_tracef("mouse event queue slot %ld = %s",
@@ -207,7 +225,7 @@
     char buf[6];
     unsigned long ignore;
 
-    strncpy(buf, key_mouse, 3);	/* should be "\033[M" */
+    strcpy(buf, "\033[M");	/* should be the same as key_mouse */
     buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40);
     buf[4] = ' ' + x - LEFT_COL + 1;
     buf[5] = ' ' + y - TOP_ROW + 1;
@@ -215,7 +233,11 @@
 }
 
 static void
+#if USE_KLIBC_MOUSE
+mouse_server(void *param)
+#else
 mouse_server(unsigned long param)
+#endif
 {
     SCREEN *sp = (SCREEN *) param;
     unsigned short fWait = MOU_WAIT;
@@ -241,7 +263,8 @@
 		/* 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);
+		    _nc_SPRINTF(err, _nc_SLIMIT(sizeof(err))
+				"Error reading mouse queue, rc=%lu.\r\n", rc);
 		    break;
 		}
 		if (!sp->_emxmouse_activated)
@@ -267,9 +290,11 @@
 	      finish:
 		oldstate = mouev.fs;
 	    }
-	} else
-	    sprintf(err, "Error setting event mask, buttons=%d, rc=%lu.\r\n",
-		    nbuttons, rc);
+	} else {
+	    _nc_SPRINTF(err, _nc_SLIMIT(sizeof(err))
+			"Error setting event mask, buttons=%d, rc=%lu.\r\n",
+			nbuttons, rc);
+	}
 
 	DosWrite(2, err, strlen(err), &rc);
 	MouClose(hmou);
@@ -340,18 +365,59 @@
 static void
 handle_sysmouse(int sig GCC_UNUSED)
 {
-    sysmouse_server(SP);
+    sysmouse_server(CURRENT_SCREEN);
 }
 #endif /* USE_SYSMOUSE */
 
+#ifndef USE_TERM_DRIVER
+#define xterm_kmous "\033[M"
+
 static void
 init_xterm_mouse(SCREEN *sp)
 {
     sp->_mouse_type = M_XTERM;
+    sp->_mouse_format = MF_X10;
     sp->_mouse_xtermcap = tigetstr("XM");
-    if (!VALID_STRING(sp->_mouse_xtermcap))
+    if (VALID_STRING(sp->_mouse_xtermcap)) {
+	char *code = strstr(sp->_mouse_xtermcap, "[?");
+	if (code != 0) {
+	    code += 2;
+	    while ((*code >= '0') && (*code <= '9')) {
+		char *next = code;
+		while ((*next >= '0') && (*next <= '9')) {
+		    ++next;
+		}
+		if (!strncmp(code, "1006", (size_t) (next - code))) {
+		    sp->_mouse_format = MF_SGR1006;
+		}
+#ifdef EXP_XTERM_1005
+		if (!strncmp(code, "1005", (size_t) (next - code))) {
+		    sp->_mouse_format = MF_XTERM_1005;
+		}
+#endif
+		if (*next == ';') {
+		    while (*next == ';') {
+			++next;
+		    }
+		    code = next;
+		} else {
+		    break;
+		}
+	    }
+	}
+    } else {
+	int code = tigetnum("XM");
+	switch (code) {
+	case 1006:
+	    break;
+	default:
+	    code = 1000;
+	    break;
+	}
 	sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
+    }
 }
+#endif
 
 static void
 enable_xterm_mouse(SCREEN *sp, int enable)
@@ -359,21 +425,29 @@
 #if USE_EMX_MOUSE
     sp->_emxmouse_activated = enable;
 #else
-    putp(TPARM_1(sp->_mouse_xtermcap, enable));
+    NCURSES_PUTP2("xterm-mouse", TPARM_1(sp->_mouse_xtermcap, enable));
 #endif
     sp->_mouse_active = enable;
 }
 
 #if USE_GPM_SUPPORT
 static bool
-allow_gpm_mouse(void)
+allow_gpm_mouse(SCREEN *sp GCC_UNUSED)
 {
     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 USE_WEAK_SYMBOLS
+    /* Danger Robinson: do not use dlopen for libgpm if already loaded */
+    if ((Gpm_Wgetch)) {
+	if (!sp->_mouse_gpm_loaded) {
+	    T(("GPM library was already dlopen'd, not by us"));
+	}
+    } else
+#endif
+	/* GPM does printf's without checking if stdout is a terminal */
+    if (NC_ISATTY(fileno(stdout))) {
+	const char *list = getenv("NCURSES_GPM_TERMS");
+	const char *env = getenv("TERM");
 	if (list != 0) {
 	    if (env != 0) {
 		result = _nc_name_match(list, env, "|:");
@@ -398,7 +472,7 @@
 static void
 unload_gpm_library(SCREEN *sp)
 {
-    if (SP->_dlopen_gpm != 0) {
+    if (sp->_dlopen_gpm != 0) {
 	T(("unload GPM library"));
 	sp->_mouse_gpm_loaded = FALSE;
 	sp->_mouse_fd = -1;
@@ -440,6 +514,8 @@
 	}
 #endif
 	if (sp->_mouse_gpm_loaded) {
+	    int code;
+
 	    /* GPM: initialize connection to gpm server */
 	    sp->_mouse_gpm_connect.eventMask = GPM_DOWN | GPM_UP;
 	    sp->_mouse_gpm_connect.defaultMask =
@@ -454,7 +530,16 @@
 	     * 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);
+	    code = my_Gpm_Open(&sp->_mouse_gpm_connect, 0);
+	    result = (code >= 0);
+
+	    /*
+	     * GPM can return a -2 if it is trying to do something with xterm.
+	     * Ignore that, since it conflicts with our use of stdin.
+	     */
+	    if (code == -2) {
+		my_Gpm_Close();
+	    }
 	} else {
 	    result = FALSE;
 	}
@@ -478,8 +563,6 @@
 }
 #endif /* USE_GPM_SUPPORT */
 
-#define xterm_kmous "\033[M"
-
 static void
 initialize_mousetype(SCREEN *sp)
 {
@@ -487,7 +570,7 @@
 
     /* Try gpm first, because gpm may be configured to run in xterm */
 #if USE_GPM_SUPPORT
-    if (allow_gpm_mouse()) {
+    if (allow_gpm_mouse(sp)) {
 	if (!sp->_mouse_gpm_loaded) {
 #ifdef HAVE_LIBDL
 	    load_gpm_library(sp);
@@ -514,7 +597,7 @@
     /* OS/2 VIO */
 #if USE_EMX_MOUSE
     if (!sp->_emxmouse_thread
-	&& strstr(cur_term->type.term_names, "xterm") == 0
+	&& strstr(TerminalOf(sp)->type.term_names, "xterm") == 0
 	&& key_mouse) {
 	int handles[2];
 
@@ -525,7 +608,7 @@
 	    int rc;
 
 	    if (!sp->_emxmouse_buttons[0]) {
-		char *s = getenv("MOUSE_BUTTONS_123");
+		const char *s = getenv("MOUSE_BUTTONS_123");
 
 		sp->_emxmouse_buttons[0] = 1;
 		if (s && strlen(s) >= 3) {
@@ -561,7 +644,7 @@
 	struct mouse_info the_mouse;
 	char *the_device = 0;
 
-	if (isatty(sp->_ifd))
+	if (NC_ISATTY(sp->_ifd))
 	    the_device = ttyname(sp->_ifd);
 	if (the_device == 0)
 	    the_device = "/dev/tty";
@@ -621,16 +704,21 @@
     }
 #endif /* USE_SYSMOUSE */
 
+#ifdef USE_TERM_DRIVER
+    CallDriver(sp, td_initmouse);
+#else
     /* 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) {
+	    || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
 	    init_xterm_mouse(sp);
 	}
-    } else if (strstr(cur_term->type.term_names, "xterm") != 0) {
+    } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
 	if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
 	    init_xterm_mouse(sp);
     }
+#endif
+
     returnVoid;
 }
 
@@ -649,7 +737,7 @@
 
 	    sp->_mouse_eventp = FirstEV(sp);
 	    for (i = 0; i < EV_MAX; i++)
-		sp->_mouse_events[i].id = INVALID_EVENT;
+		Invalidate(sp->_mouse_events + i);
 
 	    initialize_mousetype(sp);
 
@@ -665,7 +753,7 @@
  * fifo_push() in lib_getch.c
  */
 static bool
-_nc_mouse_event(SCREEN *sp GCC_UNUSED)
+_nc_mouse_event(SCREEN *sp)
 {
     MEVENT *eventp = sp->_mouse_eventp;
     bool result = FALSE;
@@ -694,11 +782,16 @@
 
 #if USE_GPM_SUPPORT
     case M_GPM:
-	{
+	if (sp->_mouse_fd >= 0) {
 	    /* query server for event, return TRUE if we find one */
 	    Gpm_Event ev;
 
-	    if (my_Gpm_GetEvent(&ev) == 1) {
+	    switch (my_Gpm_GetEvent(&ev)) {
+	    case 0:
+		/* Connection closed, drop the mouse. */
+		sp->_mouse_fd = -1;
+		break;
+	    case 1:
 		/* there's only one mouse... */
 		eventp->id = NORMAL_EVENT;
 
@@ -721,6 +814,7 @@
 			eventp->bstate |= BUTTON3_RELEASED;
 		    break;
 		default:
+		    eventp->bstate |= REPORT_MOUSE_POSITION;
 		    break;
 		}
 
@@ -729,8 +823,9 @@
 		eventp->z = 0;
 
 		/* bump the next-free pointer into the circular list */
-		sp->_mouse_eventp = eventp = NEXT(eventp);
+		sp->_mouse_eventp = NEXT(eventp);
 		result = TRUE;
+		break;
 	    }
 	}
 	break;
@@ -759,6 +854,28 @@
 	break;
 #endif /* USE_SYSMOUSE */
 
+#ifdef USE_TERM_DRIVER
+    case M_TERM_DRIVER:
+	while (sp->_drv_mouse_head < sp->_drv_mouse_tail) {
+	    *eventp = sp->_drv_mouse_fifo[sp->_drv_mouse_head];
+
+	    /*
+	     * Point the fifo-head to the next possible location.  If there
+	     * are none, reset the indices.
+	     */
+	    sp->_drv_mouse_head += 1;
+	    if (sp->_drv_mouse_head == sp->_drv_mouse_tail) {
+		sp->_drv_mouse_tail = 0;
+		sp->_drv_mouse_head = 0;
+	    }
+
+	    /* bump the next-free pointer into the circular list */
+	    sp->_mouse_eventp = eventp = NEXT(eventp);
+	    result = TRUE;
+	}
+	break;
+#endif
+
     case M_NONE:
 	break;
     }
@@ -766,148 +883,415 @@
     return result;		/* true if we found an event */
 }
 
+#if USE_EMX_MOUSE
+#define PRESS_POSITION(n) \
+    do { \
+	    eventp->bstate = MASK_PRESS(n); \
+	    sp->_mouse_bstate |= MASK_PRESS(n); \
+	    if (kbuf[0] & 0x40) { \
+		    eventp->bstate = MASK_RELEASE(n); \
+		    sp->_mouse_bstate &= ~MASK_PRESS(n); \
+	    } \
+    } while (0)
+#else
+#define PRESS_POSITION(n) \
+    do { \
+	    eventp->bstate = (mmask_t) (sp->_mouse_bstate & MASK_PRESS(n) \
+				    ? REPORT_MOUSE_POSITION \
+				    : MASK_PRESS(n)); \
+	    sp->_mouse_bstate |= MASK_PRESS(n); \
+    } while (0)
+#endif
+
+static bool
+handle_wheel(SCREEN *sp, MEVENT * eventp, int button, int wheel)
+{
+    bool result = TRUE;
+
+    switch (button & 3) {
+    case 0:
+	if (wheel) {
+	    eventp->bstate = MASK_PRESS(4);
+	    /* Do not record in sp->_mouse_bstate; there will be no
+	     * corresponding release event.
+	     */
+	} else {
+	    PRESS_POSITION(1);
+	}
+	break;
+    case 1:
+	if (wheel) {
+#if NCURSES_MOUSE_VERSION == 2
+	    eventp->bstate = MASK_PRESS(5);
+	    /* See comment above for button 4 */
+#else
+	    /* Ignore this event as it is not a true press of the button */
+	    eventp->bstate = REPORT_MOUSE_POSITION;
+#endif
+	} else {
+	    PRESS_POSITION(2);
+	}
+	break;
+    case 2:
+	PRESS_POSITION(3);
+	break;
+    default:
+	result = FALSE;
+	break;
+    }
+    return result;
+}
+
+static bool
+decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro)
+{
+    bool result;
+    int b;
+
+    eventp->bstate = 0;
+
+    if (!handle_wheel(sp, eventp, (int) intro, (intro & 96) == 96)) {
+	/*
+	 * 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 (sp->_mouse_bstate & BUTTON_PRESSED) {
+	    eventp->bstate = BUTTON_RELEASED;
+	    for (b = 1; b <= MAX_BUTTONS; ++b) {
+		if (!(sp->_mouse_bstate & MASK_PRESS(b)))
+		    eventp->bstate &= ~MASK_RELEASE(b);
+	    }
+	    sp->_mouse_bstate = 0;
+	} else {
+	    /*
+	     * xterm will return a stream of release-events to let the
+	     * application know where the mouse is going, if private mode
+	     * 1002 or 1003 is enabled.
+	     */
+	    eventp->bstate = REPORT_MOUSE_POSITION;
+	}
+    }
+
+    if (intro & 4) {
+	eventp->bstate |= BUTTON_SHIFT;
+    }
+    if (intro & 8) {
+	eventp->bstate |= BUTTON_ALT;
+    }
+    if (intro & 16) {
+	eventp->bstate |= BUTTON_CTRL;
+    }
+    result = (eventp->bstate & REPORT_MOUSE_POSITION) ? TRUE : FALSE;
+    return result;
+}
+
+/* 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 ctlseqs.ms document in the XTerm distribution,
+ * describing the 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.
+ */
+static bool
+decode_xterm_X10(SCREEN *sp, MEVENT * eventp)
+{
+    unsigned char kbuf[4];
+    size_t grabbed;
+    int res;
+    bool result;
+
+# if USE_PTHREADS_EINTR
+#  if USE_WEAK_SYMBOLS
+    if ((pthread_self) && (pthread_kill) && (pthread_equal))
+#  endif
+	_nc_globals.read_thread = pthread_self();
+# endif
+    for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) {
+
+	/* For VIO mouse we add extra bit 64 to disambiguate button-up. */
+	res = (int) read(
+#if USE_EMX_MOUSE
+			    (M_FD(sp) >= 0) ? M_FD(sp) : sp->_ifd,
+#else
+			    sp->_ifd,
+#endif
+			    kbuf + grabbed, 3 - grabbed);
+	if (res == -1)
+	    break;
+    }
+#if USE_PTHREADS_EINTR
+    _nc_globals.read_thread = 0;
+#endif
+    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;
+
+    result = decode_X10_bstate(sp, eventp, kbuf[0]);
+
+    eventp->x = (kbuf[1] - ' ') - 1;
+    eventp->y = (kbuf[2] - ' ') - 1;
+
+    return result;
+}
+
+#ifdef EXP_XTERM_1005
+/*
+ * This is identical to X10/X11 responses except that there are two UTF-8
+ * characters storing the ordinates instead of two bytes.
+ */
+static bool
+decode_xterm_1005(SCREEN *sp, MEVENT * eventp)
+{
+    char kbuf[80];
+    size_t grabbed;
+    size_t limit = (sizeof(kbuf) - 1);
+    unsigned coords[2];
+    int res;
+    bool result;
+
+    coords[0] = 0;
+    coords[1] = 0;
+
+# if USE_PTHREADS_EINTR
+#  if USE_WEAK_SYMBOLS
+    if ((pthread_self) && (pthread_kill) && (pthread_equal))
+#  endif
+	_nc_globals.read_thread = pthread_self();
+# endif
+    for (grabbed = 0; grabbed < limit;) {
+
+	res = (int) read(
+#if USE_EMX_MOUSE
+			    (M_FD(sp) >= 0) ? M_FD(sp) : sp->_ifd,
+#else
+			    sp->_ifd,
+#endif
+			    kbuf + grabbed, 1);
+	if (res == -1)
+	    break;
+	grabbed += (size_t) res;
+	if (grabbed > 1) {
+	    size_t check = 1;
+	    int n;
+	    int rc;
+	    for (n = 0; n < 2; ++n) {
+		if (check >= grabbed)
+		    break;
+		rc = _nc_conv_to_utf32(&coords[n], kbuf + check, (unsigned)
+				       (grabbed - check));
+		if (!rc)
+		    break;
+		check += (size_t) rc;
+	    }
+	    if (n >= 2)
+		break;
+	}
+    }
+#if USE_PTHREADS_EINTR
+    _nc_globals.read_thread = 0;
+#endif
+
+    TR(TRACE_IEVENT,
+       ("_nc_mouse_inline sees the following xterm data: %s",
+	_nc_visbufn(kbuf, (int) grabbed)));
+
+    /* there's only one mouse... */
+    eventp->id = NORMAL_EVENT;
+
+    result = decode_X10_bstate(sp, eventp, UChar(kbuf[0]));
+
+    eventp->x = (int) (coords[0] - ' ') - 1;
+    eventp->y = (int) (coords[1] - ' ') - 1;
+
+    return result;
+}
+#endif /* EXP_XTERM_1005 */
+
+/*
+ * ECMA-48 section 5.4
+ */
+#define isInter(c) ((c) >= 0x20 && (c) <= 0x2f)
+#define isParam(c) ((c) >= 0x30 && (c) <= 0x3f)
+#define isFinal(c) ((c) >= 0x40 && (c) <= 0x7e)
+
+#define MAX_PARAMS 9
+
+typedef struct {
+    int nerror;			/* nonzero if there are unexpected chars */
+    int nparam;			/* number of numeric parameters */
+    int params[MAX_PARAMS];
+    int final;			/* the final-character */
+} SGR_DATA;
+
+static bool
+read_SGR(SCREEN *sp, SGR_DATA * result)
+{
+    char kbuf[80];		/* bigger than any possible mouse response */
+    int grabbed = 0;
+    int res;
+    int ch = 0;
+    int now = -1;
+    int marker = 1;
+
+    memset(result, 0, sizeof(*result));
+# if USE_PTHREADS_EINTR
+#  if USE_WEAK_SYMBOLS
+    if ((pthread_self) && (pthread_kill) && (pthread_equal))
+#  endif
+	_nc_globals.read_thread = pthread_self();
+# endif
+    do {
+	res = (int) read(
+#if USE_EMX_MOUSE
+			    (M_FD(sp) >= 0) ? M_FD(sp) : sp->_ifd,
+#else
+			    sp->_ifd,
+#endif
+			    kbuf + grabbed, 1);
+	if (res == -1)
+	    break;
+	if ((grabbed + 3) >= (int) sizeof(kbuf)) {
+	    result->nerror++;
+	    break;
+	}
+	ch = UChar(kbuf[grabbed]);
+	kbuf[grabbed + 1] = 0;
+	switch (ch) {
+	case '0':
+	case '1':
+	case '2':
+	case '3':
+	case '4':
+	case '5':
+	case '6':
+	case '7':
+	case '8':
+	case '9':
+	    if (marker) {
+		++now;
+		result->nparam = (now + 1);
+	    }
+	    marker = 0;
+	    result->params[now] = (result->params[now] * 10) + (ch - '0');
+	    break;
+	case ';':
+	    if (marker) {
+		++now;
+		result->nparam = (now + 1);
+	    }
+	    marker = 1;
+	    break;
+	default:
+	    if (ch < 32 || ch > 126) {
+		/*
+		 * Technically other characters could be interspersed in the
+		 * response.  Ignore those for now.
+		 */
+		result->nerror++;
+		continue;
+	    } else if (isFinal(ch)) {
+		if (marker) {
+		    result->nparam++;
+		}
+		result->final = ch;
+	    } else {
+		result->nerror++;
+	    }
+	    break;
+	}
+	++grabbed;
+    } while (!isFinal(ch));
+#if USE_PTHREADS_EINTR
+    _nc_globals.read_thread = 0;
+#endif
+
+    kbuf[++grabbed] = 0;
+    TR(TRACE_IEVENT,
+       ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
+    return (grabbed > 0) && (result->nerror == 0);
+}
+
+static bool
+decode_xterm_SGR1006(SCREEN *sp, MEVENT * eventp)
+{
+    SGR_DATA data;
+    bool result = FALSE;
+    if (read_SGR(sp, &data)) {
+	int b = data.params[0];
+	int b3 = 1 + (b & 3);
+
+	eventp->id = NORMAL_EVENT;
+	if (data.final == 'M') {
+	    (void) handle_wheel(sp, eventp, b, (b & 64) == 64);
+	} else {
+	    mmask_t pressed = (mmask_t) NCURSES_MOUSE_MASK(b3, NCURSES_BUTTON_PRESSED);
+	    mmask_t release = (mmask_t) NCURSES_MOUSE_MASK(b3, NCURSES_BUTTON_RELEASED);
+	    if (sp->_mouse_bstate & pressed) {
+		eventp->bstate = release;
+		sp->_mouse_bstate &= ~pressed;
+	    } else {
+		eventp->bstate = REPORT_MOUSE_POSITION;
+	    }
+	}
+	result = (eventp->bstate & REPORT_MOUSE_POSITION) ? TRUE : FALSE;
+	eventp->x = (data.params[1] ? (data.params[1] - 1) : 0);
+	eventp->y = (data.params[2] ? (data.params[2] - 1) : 0);
+    }
+    return result;
+}
+
 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);
+	switch (sp->_mouse_format) {
+	case MF_X10:
+	    result = decode_xterm_X10(sp, eventp);
+	    break;
+	case MF_SGR1006:
+	    result = decode_xterm_SGR1006(sp, eventp);
+	    break;
+#ifdef EXP_XTERM_1005
+	case MF_XTERM_1005:
+	    result = decode_xterm_1005(sp, eventp);
+	    break;
 #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),
@@ -915,16 +1299,30 @@
 
 	/* 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
+
+	if (!result) {
+	    /* If this event is from a wheel-mouse, treat it like position
+	     * reports and avoid waiting for the release-events which will
+	     * never come.
+	     */
+	    if (eventp->bstate & BUTTON_PRESSED) {
+		int b;
+
+		for (b = 4; b <= MAX_BUTTONS; ++b) {
+		    if ((eventp->bstate & MASK_PRESS(b))) {
+			result = TRUE;
+			break;
+		    }
+		}
+	    }
+	}
     }
 
     return (result);
 }
 
 static void
-mouse_activate(SCREEN *sp, bool on)
+mouse_activate(SCREEN *sp, int on)
 {
     if (!on && !sp->_mouse_initialized)
 	return;
@@ -933,11 +1331,11 @@
 	return;
 
     if (on) {
-
+	sp->_mouse_bstate = 0;
 	switch (sp->_mouse_type) {
 	case M_XTERM:
 #if NCURSES_EXT_FUNCS
-	    keyok(KEY_MOUSE, on);
+	    NCURSES_SP_NAME(keyok) (NCURSES_SP_ARGx KEY_MOUSE, on);
 #endif
 	    TPUTS_TRACE("xterm mouse initialization");
 	    enable_xterm_mouse(sp, 1);
@@ -956,6 +1354,11 @@
 	    sp->_mouse_active = TRUE;
 	    break;
 #endif
+#ifdef USE_TERM_DRIVER
+	case M_TERM_DRIVER:
+	    sp->_mouse_active = TRUE;
+	    break;
+#endif
 	case M_NONE:
 	    return;
 	}
@@ -985,11 +1388,16 @@
 	    sp->_mouse_active = FALSE;
 	    break;
 #endif
+#ifdef USE_TERM_DRIVER
+	case M_TERM_DRIVER:
+	    sp->_mouse_active = FALSE;
+	    break;
+#endif
 	case M_NONE:
 	    return;
 	}
     }
-    _nc_flush();
+    NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
 }
 
 /**************************************************************************
@@ -1003,10 +1411,13 @@
 /* parse a run of atomic mouse events into a gesture */
 {
     MEVENT *eventp = sp->_mouse_eventp;
-    MEVENT *ep, *runp, *next, *prev = PREV(eventp);
+    MEVENT *next, *ep;
+    MEVENT *first_valid = NULL;
+    MEVENT *first_invalid = NULL;
     int n;
     int b;
     bool merge;
+    bool endLoop;
 
     TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount));
 
@@ -1023,7 +1434,8 @@
      *
      * 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.
+     * in the run are ignored if user does not call getmouse in a loop (getting
+     * them from newest to older).
      *
      * 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
@@ -1031,79 +1443,110 @@
      * 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);
+    /*
+     * Reset all events that were not set, in case the user sometimes calls
+     * getmouse only once and other times until there are no more events in
+     * queue.
+     *
+     * This also allows reaching the beginning of the run.
+     */
+    ep = eventp;
+    for (n = runcount; n < EV_MAX; n++) {
+	Invalidate(ep);
+	ep = NEXT(ep);
     }
 
 #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),
+		RunParams(sp, eventp, ep),
 		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) {
+    endLoop = FALSE;
+    while (!endLoop) {
+	next = NEXT(ep);
+	if (next == eventp) {
+	    /* Will end the loop, but compact before */
+	    endLoop = TRUE;
+	} else {
 
 #define MASK_CHANGED(x) (!(ep->bstate & MASK_PRESS(x)) \
 		      == !(next->bstate & MASK_RELEASE(x)))
 
-	    if (ep->x == next->x && ep->y == next->y
+	    if (ValidEvent(ep) && ValidEvent(next)
+		&& 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
-		) {
+		&& (!(next->bstate & BUTTON_PRESSED))) {
+		bool changed = TRUE;
+
 		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 (!MASK_CHANGED(b)) {
+			changed = FALSE;
+			break;
 		    }
 		}
-		if (merge)
-		    next->id = INVALID_EVENT;
+
+		if (changed) {
+		    merge = FALSE;
+		    for (b = 1; b <= MAX_BUTTONS; ++b) {
+			if ((sp->_mouse_mask & MASK_CLICK(b))
+			    && (ep->bstate & MASK_PRESS(b))) {
+			    next->bstate &= ~MASK_RELEASE(b);
+			    next->bstate |= MASK_CLICK(b);
+			    merge = TRUE;
+			}
+		    }
+		    if (merge) {
+			Invalidate(ep);
+		    }
+		}
 	    }
 	}
-    } while
-	(merge);
 
+	/* Compact valid events */
+	if (!ValidEvent(ep)) {
+	    if ((first_valid != NULL) && (first_invalid == NULL)) {
+		first_invalid = ep;
+	    }
+	} else {
+	    if (first_valid == NULL) {
+		first_valid = ep;
+	    } else if (first_invalid != NULL) {
+		*first_invalid = *ep;
+		Invalidate(ep);
+		first_invalid = NEXT(first_invalid);
+	    }
+	}
+
+	ep = next;
+    }
+
+    if (first_invalid != NULL) {
+	eventp = first_invalid;
+    }
 #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);
+	if (first_valid == NULL) {
+	    _tracef("_nc_mouse_parse: no valid event");
+	} else {
+	    _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
+		    RunParams(sp, eventp, first_valid),
+		    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.
+     * Second pass; merge click runs.  We merge click events forward in the
+     * queue.  For example, double click can be changed to triple click.
      *
      * NOTE: There is a problem with this design!  If the application
      * allows enough click events to pile up in the circular queue so
@@ -1116,87 +1559,102 @@
      * but the timer element would have to have sub-second resolution,
      * which would get us into portability trouble.
      */
-    do {
-	MEVENT *follower;
+    first_invalid = NULL;
+    endLoop = (first_valid == NULL);
+    ep = first_valid;
+    while (!endLoop) {
+	next = NEXT(ep);
 
-	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 (next == eventp) {
+	    /* Will end the loop, but check event type and compact before */
+	    endLoop = TRUE;
+	} else if (!ValidEvent(next)) {
+	    continue;
+	} else {
+	    /* merge click events forward */
+	    if ((ep->bstate & BUTTON_CLICKED)
+		&& (next->bstate & BUTTON_CLICKED)) {
+		merge = FALSE;
+		for (b = 1; b <= MAX_BUTTONS; ++b) {
+		    if ((sp->_mouse_mask & MASK_DOUBLE_CLICK(b))
+			&& (ep->bstate & MASK_CLICK(b))
+			&& (next->bstate & MASK_CLICK(b))) {
+			next->bstate &= ~MASK_CLICK(b);
+			next->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;
+		if (merge) {
+		    Invalidate(ep);
 		}
 	    }
-    } 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;
+	    /* merge double-click events forward */
+	    if ((ep->bstate & BUTTON_DOUBLE_CLICKED)
+		&& (next->bstate & BUTTON_CLICKED)) {
+		merge = FALSE;
+		for (b = 1; b <= MAX_BUTTONS; ++b) {
+		    if ((sp->_mouse_mask & MASK_TRIPLE_CLICK(b))
+			&& (ep->bstate & MASK_DOUBLE_CLICK(b))
+			&& (next->bstate & MASK_CLICK(b))) {
+			next->bstate &= ~MASK_CLICK(b);
+			next->bstate |= MASK_TRIPLE_CLICK(b);
+			merge = TRUE;
+		    }
+		}
+		if (merge) {
+		    Invalidate(ep);
+		}
+	    }
 	}
-#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);
+
+	/* Discard event if it does not match event mask */
+	if (!(ep->bstate & sp->_mouse_mask2)) {
+	    Invalidate(ep);
+	}
+
+	/* Compact valid events */
+	if (!ValidEvent(ep)) {
+	    if (ep == first_valid) {
+		first_valid = next;
+	    } else if (first_invalid == NULL) {
+		first_invalid = ep;
+	    }
+	} else if (first_invalid != NULL) {
+	    *first_invalid = *ep;
+	    Invalidate(ep);
+	    first_invalid = NEXT(first_invalid);
+	}
+
+	ep = next;
     }
-    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)));
+
+    if (first_invalid == NULL) {
+	first_invalid = eventp;
+    }
+    sp->_mouse_eventp = first_invalid;
+
+#ifdef TRACE
+    if (first_valid != NULL) {
+	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, first_invalid, first_valid),
+		    runcount);
+	    _nc_unlock_global(tracef);
+	}
+	for (ep = first_valid; ep != first_invalid; ep = NEXT(ep)) {
+	    if (ValidEvent(ep))
+		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);
+    return ValidEvent(PREV(first_invalid));
 }
 
 static void
@@ -1222,6 +1680,11 @@
 	mouse_activate(sp, FALSE);
 	break;
 #endif
+#ifdef USE_TERM_DRIVER
+    case M_TERM_DRIVER:
+	mouse_activate(sp, FALSE);
+	break;
+#endif
     case M_NONE:
 	break;
     }
@@ -1253,6 +1716,13 @@
 	mouse_activate(sp, TRUE);
 	break;
 #endif
+
+#ifdef USE_TERM_DRIVER
+    case M_TERM_DRIVER:
+	mouse_activate(sp, TRUE);
+	break;
+#endif
+
     case M_NONE:
 	break;
     }
@@ -1264,80 +1734,109 @@
  *
  **************************************************************************/
 
-static int
-_nc_getmouse(SCREEN *sp, MEVENT * aevent)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(getmouse) (NCURSES_SP_DCLx MEVENT * aevent)
 {
-    T((T_CALLED("getmouse(%p)"), aevent));
+    int result = ERR;
 
-    if ((aevent != 0) && (sp != 0) && (sp->_mouse_type != M_NONE)) {
-	MEVENT *eventp = sp->_mouse_eventp;
+    T((T_CALLED("getmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
+
+    if ((aevent != 0) && (SP_PARM != 0) && (SP_PARM->_mouse_type != M_NONE)) {
+	MEVENT *eventp = SP_PARM->_mouse_eventp;
 	/* compute the current-event pointer */
 	MEVENT *prev = PREV(eventp);
 
-	/* copy the event we find there */
-	*aevent = *prev;
+	/*
+	 * Discard events not matching mask (there could be still some if
+	 * _nc_mouse_parse was not called, e.g., when _nc_mouse_inline returns
+	 * false).
+	 */
+	while (ValidEvent(prev) && (!(prev->bstate & SP_PARM->_mouse_mask2))) {
+	    Invalidate(prev);
+	    prev = PREV(prev);
+	}
+	if (ValidEvent(prev)) {
+	    /* 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)));
+	    TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
+			      _nc_tracemouse(SP_PARM, prev),
+			      (long) IndexEV(SP_PARM, prev)));
 
-	prev->id = INVALID_EVENT;	/* so the queue slot becomes free */
-	returnCode(OK);
+	    Invalidate(prev);	/* so the queue slot becomes free */
+	    SP_PARM->_mouse_eventp = prev;
+	    result = OK;
+	} else {
+	    /* Reset the provided event */
+	    aevent->bstate = 0;
+	    Invalidate(aevent);
+	    aevent->x = 0;
+	    aevent->y = 0;
+	    aevent->z = 0;
+	}
     }
-    returnCode(ERR);
+    returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
 /* grab a copy of the current mouse event */
 NCURSES_EXPORT(int)
 getmouse(MEVENT * aevent)
 {
-    return _nc_getmouse(SP, aevent);
+    return NCURSES_SP_NAME(getmouse) (CURRENT_SCREEN, aevent);
 }
+#endif
 
-static int
-_nc_ungetmouse(SCREEN *sp, MEVENT * aevent)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(ungetmouse) (NCURSES_SP_DCLx MEVENT * aevent)
 {
     int result = ERR;
 
-    T((T_CALLED("ungetmouse(%p)"), aevent));
+    T((T_CALLED("ungetmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
 
-    if (aevent != 0 && sp != 0) {
-	MEVENT *eventp = sp->_mouse_eventp;
+    if (aevent != 0 && SP_PARM != 0) {
+	MEVENT *eventp = SP_PARM->_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);
+	SP_PARM->_mouse_eventp = NEXT(eventp);
 
 	/* push back the notification event on the keyboard queue */
-	result = _nc_ungetch(sp, KEY_MOUSE);
+	result = NCURSES_SP_NAME(ungetch) (NCURSES_SP_ARGx KEY_MOUSE);
     }
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
 /* enqueue a synthesized mouse event to be seen by the next wgetch() */
 NCURSES_EXPORT(int)
 ungetmouse(MEVENT * aevent)
 {
-    return _nc_ungetmouse(SP, aevent);
+    return NCURSES_SP_NAME(ungetmouse) (CURRENT_SCREEN, aevent);
 }
+#endif
 
 NCURSES_EXPORT(mmask_t)
-mousemask(mmask_t newmask, mmask_t * oldmask)
+NCURSES_SP_NAME(mousemask) (NCURSES_SP_DCLx mmask_t newmask, mmask_t * oldmask)
 /* set the mouse event mask */
 {
     mmask_t result = 0;
+    int b;
 
-    T((T_CALLED("mousemask(%#lx,%p)"), (unsigned long) newmask, oldmask));
+    T((T_CALLED("mousemask(%p,%#lx,%p)"),
+       (void *) SP_PARM,
+       (unsigned long) newmask,
+       (void *) oldmask));
 
-    if (SP != 0) {
+    if (SP_PARM != 0) {
 	if (oldmask)
-	    *oldmask = SP->_mouse_mask;
+	    *oldmask = SP_PARM->_mouse_mask;
 
-	if (newmask || SP->_mouse_initialized) {
-	    _nc_mouse_init(SP);
-	    if (SP->_mouse_type != M_NONE) {
+	if (newmask || SP_PARM->_mouse_initialized) {
+	    _nc_mouse_init(SP_PARM);
+	    if (SP_PARM->_mouse_type != M_NONE) {
 		result = newmask &
 		    (REPORT_MOUSE_POSITION
 		     | BUTTON_ALT
@@ -1349,22 +1848,46 @@
 		     | BUTTON_DOUBLE_CLICKED
 		     | BUTTON_TRIPLE_CLICKED);
 
-		mouse_activate(SP, (bool) (result != 0));
+		mouse_activate(SP_PARM, (bool) (result != 0));
 
-		SP->_mouse_mask = result;
+		SP_PARM->_mouse_mask = result;
+		SP_PARM->_mouse_mask2 = result;
+
+		/*
+		 * Make a mask corresponding to the states we will need to
+		 * retain (temporarily) while building up the state that the
+		 * user asked for.
+		 */
+		for (b = 1; b <= MAX_BUTTONS; ++b) {
+		    if (SP_PARM->_mouse_mask2 & MASK_TRIPLE_CLICK(b))
+			SP_PARM->_mouse_mask2 |= MASK_DOUBLE_CLICK(b);
+		    if (SP_PARM->_mouse_mask2 & MASK_DOUBLE_CLICK(b))
+			SP_PARM->_mouse_mask2 |= MASK_CLICK(b);
+		    if (SP_PARM->_mouse_mask2 & MASK_CLICK(b))
+			SP_PARM->_mouse_mask2 |= (MASK_PRESS(b) |
+						  MASK_RELEASE(b));
+		}
 	    }
 	}
     }
-    returnBits(result);
+    returnMMask(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(mmask_t)
+mousemask(mmask_t newmask, mmask_t * oldmask)
+{
+    return NCURSES_SP_NAME(mousemask) (CURRENT_SCREEN, newmask, oldmask);
+}
+#endif
+
 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));
+    T((T_CALLED("wenclose(%p,%d,%d)"), (const void *) win, y, x));
 
     if (win != 0) {
 	y -= win->_yoffset;
@@ -1377,17 +1900,17 @@
 }
 
 NCURSES_EXPORT(int)
-mouseinterval(int maxclick)
+NCURSES_SP_NAME(mouseinterval) (NCURSES_SP_DCLx int maxclick)
 /* set the maximum mouse interval within which to recognize a click */
 {
     int oldval;
 
-    T((T_CALLED("mouseinterval(%d)"), maxclick));
+    T((T_CALLED("mouseinterval(%p,%d)"), (void *) SP_PARM, maxclick));
 
-    if (SP != 0) {
-	oldval = SP->_maxclick;
+    if (SP_PARM != 0) {
+	oldval = SP_PARM->_maxclick;
 	if (maxclick >= 0)
-	    SP->_maxclick = maxclick;
+	    SP_PARM->_maxclick = maxclick;
     } else {
 	oldval = DEFAULT_MAXCLICK;
     }
@@ -1395,20 +1918,46 @@
     returnCode(oldval);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+mouseinterval(int maxclick)
+{
+    return NCURSES_SP_NAME(mouseinterval) (CURRENT_SCREEN, maxclick);
+}
+#endif
+
 /* This may be used by other routines to ask for the existence of mouse
    support */
-NCURSES_EXPORT(int)
-_nc_has_mouse(void)
+NCURSES_EXPORT(bool)
+_nc_has_mouse(SCREEN *sp)
 {
-    return (SP->_mouse_type == M_NONE ? 0 : 1);
+    return (((0 == sp) || (sp->_mouse_type == M_NONE)) ? FALSE : TRUE);
 }
 
 NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(has_mouse) (NCURSES_SP_DCL0)
+{
+    return _nc_has_mouse(SP_PARM);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(bool)
+has_mouse(void)
+{
+    return _nc_has_mouse(CURRENT_SCREEN);
+}
+#endif
+
+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));
+    T((T_CALLED("wmouse_trafo(%p,%p,%p,%d)"),
+       (const void *) win,
+       (void *) pY,
+       (void *) pX,
+       to_screen));
 
     if (win && pY && pX) {
 	int y = *pY;
diff --git a/ncurses/base/lib_move.c b/ncurses/base/lib_move.c
index 652c44d..488b195 100644
--- a/ncurses/base/lib_move.c
+++ b/ncurses/base/lib_move.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2004 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2004,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,12 +41,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_move.c,v 1.12 2004/12/04 21:50:07 tom Exp $")
+MODULE_ID("$Id: lib_move.c,v 1.13 2009/10/24 22:34:07 tom Exp $")
 
 NCURSES_EXPORT(int)
 wmove(WINDOW *win, int y, int x)
 {
-    T((T_CALLED("wmove(%p,%d,%d)"), win, y, x));
+    T((T_CALLED("wmove(%p,%d,%d)"), (void *) win, y, x));
 
     if (LEGALYX(win, y, x)) {
 	win->_curx = (NCURSES_SIZE_T) x;
diff --git a/ncurses/base/lib_mvwin.c b/ncurses/base/lib_mvwin.c
index e4dad4a..18d31c1 100644
--- a/ncurses/base/lib_mvwin.c
+++ b/ncurses/base/lib_mvwin.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 /*
@@ -40,12 +42,16 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_mvwin.c,v 1.14 2006/02/25 22:53:46 tom Exp $")
+MODULE_ID("$Id: lib_mvwin.c,v 1.18 2010/12/19 01:22:58 tom Exp $")
 
 NCURSES_EXPORT(int)
 mvwin(WINDOW *win, int by, int bx)
 {
-    T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx));
+#if NCURSES_SP_FUNCS
+    SCREEN *sp = _nc_screen_of(win);
+#endif
+
+    T((T_CALLED("mvwin(%p,%d,%d)"), (void *) win, by, bx));
 
     if (!win || (win->_flags & _ISPAD))
 	returnCode(ERR);
@@ -96,8 +102,8 @@
     }
 #endif
 
-    if (by + win->_maxy > screen_lines - 1
-	|| bx + win->_maxx > screen_columns - 1
+    if (by + win->_maxy > screen_lines(SP_PARM) - 1
+	|| bx + win->_maxx > screen_columns(SP_PARM) - 1
 	|| by < 0
 	|| bx < 0)
 	returnCode(ERR);
@@ -108,7 +114,7 @@
      * 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;
+    win->_begy = (NCURSES_SIZE_T) by;
+    win->_begx = (NCURSES_SIZE_T) bx;
     returnCode(touchwin(win));
 }
diff --git a/ncurses/base/lib_newterm.c b/ncurses/base/lib_newterm.c
index 05982b8..edbf956 100644
--- a/ncurses/base/lib_newterm.c
+++ b/ncurses/base/lib_newterm.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -41,14 +42,19 @@
 
 #include <curses.priv.h>
 
-#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
-#define _POSIX_SOURCE
+#ifndef CUR
+#define CUR SP_TERMTYPE
 #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 $")
+MODULE_ID("$Id: lib_newterm.c,v 1.92 2014/04/26 18:00:39 tom Exp $")
+
+#ifdef USE_TERM_DRIVER
+#define NumLabels      InfoOf(SP_PARM).numlabels
+#else
+#define NumLabels      num_labels
+#endif
 
 #ifndef ONLCR			/* Allows compilation under the QNX 4.2 OS */
 #define ONLCR 0
@@ -63,27 +69,29 @@
  * is supposed to behave as if it calls newterm, we do it here.
  */
 static NCURSES_INLINE int
-_nc_initscr(void)
+_nc_initscr(NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *term = TerminalOf(SP_PARM);
 
     /* for extended XPG4 conformance requires cbreak() at this point */
     /* (SVr4 curses does this anyway) */
-    if (cbreak() == OK) {
+    if (NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG) == OK) {
 	TTY buf;
 
-	buf = cur_term->Nttyb;
+	buf = term->Nttyb;
 #ifdef TERMIOS
-	buf.c_lflag &= ~(ECHO | ECHONL);
-	buf.c_iflag &= ~(ICRNL | INLCR | IGNCR);
-	buf.c_oflag &= ~(ONLCR);
+	buf.c_lflag &= (unsigned) ~(ECHO | ECHONL);
+	buf.c_iflag &= (unsigned) ~(ICRNL | INLCR | IGNCR);
+	buf.c_oflag &= (unsigned) ~(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;
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+	if (result == OK)
+	    term->Nttyb = buf;
     }
     return result;
 }
@@ -95,13 +103,30 @@
  * initialized.
  */
 NCURSES_EXPORT(void)
+NCURSES_SP_NAME(filter) (NCURSES_SP_DCL0)
+{
+    START_TRACE();
+    T((T_CALLED("filter(%p)"), (void *) SP_PARM));
+#if NCURSES_SP_FUNCS
+    if (IsPreScreen(SP_PARM)) {
+	SP_PARM->_filtered = TRUE;
+    }
+#else
+    _nc_prescreen.filter_mode = TRUE;
+#endif
+    returnVoid;
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
 filter(void)
 {
     START_TRACE();
-    T((T_CALLED("filter")));
+    T((T_CALLED("filter()")));
     _nc_prescreen.filter_mode = TRUE;
     returnVoid;
 }
+#endif
 
 #if NCURSES_EXT_FUNCS
 /*
@@ -109,62 +134,122 @@
  * requiring it to also be filtered.
  */
 NCURSES_EXPORT(void)
+NCURSES_SP_NAME(nofilter) (NCURSES_SP_DCL0)
+{
+    START_TRACE();
+    T((T_CALLED("nofilter(%p)"), (void *) SP_PARM));
+#if NCURSES_SP_FUNCS
+    if (IsPreScreen(SP_PARM)) {
+	SP_PARM->_filtered = FALSE;
+    }
+#else
+    _nc_prescreen.filter_mode = FALSE;
+#endif
+    returnVoid;
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
 nofilter(void)
 {
     START_TRACE();
-    T((T_CALLED("nofilter")));
+    T((T_CALLED("nofilter()")));
     _nc_prescreen.filter_mode = FALSE;
     returnVoid;
 }
 #endif
+#endif /* NCURSES_EXT_FUNCS */
 
 NCURSES_EXPORT(SCREEN *)
-newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
+NCURSES_SP_NAME(newterm) (NCURSES_SP_DCLx
+			  NCURSES_CONST char *name,
+			  FILE *ofp,
+			  FILE *ifp)
 {
     int value;
     int errret;
-    SCREEN *current;
     SCREEN *result = 0;
+    SCREEN *current;
     TERMINAL *its_term;
+    FILE *_ofp = ofp ? ofp : stdout;
+    FILE *_ifp = ifp ? ifp : stdin;
+    int cols;
+    int slk_format;
+    int filter_mode;
+    TERMINAL *new_term = 0;
 
     START_TRACE();
-    T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp));
+    T((T_CALLED("newterm(%p, \"%s\", %p,%p)"),
+       (void *) SP_PARM,
+       (name ? name : ""),
+       (void *) ofp,
+       (void *) ifp));
+
+#if NCURSES_SP_FUNCS
+    assert(SP_PARM != 0);
+    if (SP_PARM == 0)
+	returnSP(SP_PARM);
+#endif
 
     _nc_init_pthreads();
     _nc_lock_global(curses);
 
-    current = SP;
-    its_term = (SP ? SP->_term : 0);
+    current = CURRENT_SCREEN;
+    its_term = (current ? current->_term : 0);
 
+    INIT_TERM_DRIVER();
     /* this loads the capability entry, then sets LINES and COLS */
-    if (setupterm(name, fileno(ofp), &errret) != ERR) {
-	int slk_format = _nc_globals.slk_format;
+    if (
+	   TINFO_SETUP_TERM(&new_term, name,
+			    fileno(_ofp), &errret, FALSE) != ERR) {
+
+	_nc_set_screen(0);
+#ifdef USE_TERM_DRIVER
+	assert(new_term != 0);
+#endif
+
+#if NCURSES_SP_FUNCS
+	slk_format = SP_PARM->slk_format;
+	filter_mode = SP_PARM->_filtered;
+#else
+	slk_format = _nc_globals.slk_format;
+	filter_mode = _nc_prescreen.filter_mode;
+#endif
 
 	/*
 	 * 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) {
+	if (NCURSES_SP_NAME(_nc_setupscreen) (
+#if NCURSES_SP_FUNCS
+						 &SP_PARM,
+#endif
+						 *(ptrLines(SP_PARM)),
+						 *(ptrCols(SP_PARM)),
+						 _ofp,
+						 filter_mode,
+						 slk_format) == ERR) {
 	    _nc_set_screen(current);
 	    result = 0;
 	} else {
-	    assert(SP != 0);
+#ifdef USE_TERM_DRIVER
+	    TERMINAL_CONTROL_BLOCK *TCB;
+#elif !NCURSES_SP_FUNCS
+	    _nc_set_screen(CURRENT_SCREEN);
+#endif
+	    assert(SP_PARM != 0);
+	    cols = *(ptrCols(SP_PARM));
+#ifdef USE_TERM_DRIVER
+	    _nc_set_screen(SP_PARM);
+	    TCB = (TERMINAL_CONTROL_BLOCK *) new_term;
+	    TCB->csp = SP_PARM;
+#endif
 	    /*
 	     * 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.
+	     * CURRENT_SCREEN.  So the "current" screen's terminal pointer was
+	     * overwritten with a different terminal.  Later, in
+	     * _nc_setupscreen(), we set CURRENT_SCREEN and the terminal
+	     * pointer in the new screen.
 	     *
 	     * Restore the terminal-pointer for the pre-existing screen, if
 	     * any.
@@ -172,37 +257,54 @@
 	    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));
+#ifdef USE_TERM_DRIVER
+	    SP_PARM->_term = new_term;
 #else
-	    SP->_use_meta = FALSE;
+	    new_term = SP_PARM->_term;
 #endif
-	    SP->_endwin = FALSE;
 
+	    /* allow user to set maximum escape delay from the environment */
+	    if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
+		NCURSES_SP_NAME(set_escdelay) (NCURSES_SP_ARGx value);
+	    }
+
+	    /* if the terminal type has real soft labels, set those up */
+	    if (slk_format && NumLabels > 0 && SLK_STDFMT(slk_format))
+		_nc_slk_initialize(StdScreen(SP_PARM), cols);
+
+	    SP_PARM->_ifd = fileno(_ifp);
+	    NCURSES_SP_NAME(typeahead) (NCURSES_SP_ARGx fileno(_ifp));
+#ifdef TERMIOS
+	    SP_PARM->_use_meta = ((new_term->Ottyb.c_cflag & CSIZE) == CS8 &&
+				  !(new_term->Ottyb.c_iflag & ISTRIP)) ||
+		USE_KLIBC_KBD;
+#else
+	    SP_PARM->_use_meta = FALSE;
+#endif
+	    SP_PARM->_endwin = FALSE;
+#ifndef USE_TERM_DRIVER
 	    /*
 	     * 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)));
+	    SP_PARM->_scrolling = ((scroll_forward && scroll_reverse) ||
+				   ((parm_rindex ||
+				     parm_insert_line ||
+				     insert_line) &&
+				    (parm_index ||
+				     parm_delete_line ||
+				     delete_line)));
+#endif
 
-	    baudrate();		/* sets a field in the SP structure */
+	    NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG);		/* sets a field in the screen structure */
 
-	    SP->_keytry = 0;
+	    SP_PARM->_keytry = 0;
 
+	    /* compute movement costs so we can do better move optimization */
+#ifdef USE_TERM_DRIVER
+	    TCBOf(SP_PARM)->drv->td_scinit(SP_PARM);
+#else /* ! USE_TERM_DRIVER */
 	    /*
 	     * Check for mismatched graphic-rendition capabilities.  Most SVr4
 	     * terminfo trees contain entries that have rmul or rmso equated to
@@ -213,23 +315,34 @@
 	     * 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);
+	    SP_PARM->_use_rmso = SGR0_TEST(exit_standout_mode);
+	    SP_PARM->_use_rmul = SGR0_TEST(exit_underline_mode);
+#if USE_ITALIC
+	    SP_PARM->_use_ritm = SGR0_TEST(exit_italics_mode);
+#endif
 
 	    /* compute movement costs so we can do better move optimization */
 	    _nc_mvcur_init();
 
 	    /* initialize terminal to a sane state */
 	    _nc_screen_init();
+#endif /* USE_TERM_DRIVER */
 
 	    /* Initialize the terminal line settings. */
-	    _nc_initscr();
+	    _nc_initscr(NCURSES_SP_ARG);
 
 	    _nc_signal_handler(TRUE);
-
-	    result = SP;
+	    result = SP_PARM;
 	}
     }
     _nc_unlock_global(curses);
     returnSP(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(SCREEN *)
+newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
+{
+    return NCURSES_SP_NAME(newterm) (CURRENT_SCREEN_PRE, name, ofp, ifp);
+}
+#endif
diff --git a/ncurses/base/lib_newwin.c b/ncurses/base/lib_newwin.c
index 587e83a..a6c64be 100644
--- a/ncurses/base/lib_newwin.c
+++ b/ncurses/base/lib_newwin.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -42,7 +43,7 @@
 #include <curses.priv.h>
 #include <stddef.h>
 
-MODULE_ID("$Id: lib_newwin.c,v 1.52 2008/06/07 13:58:09 tom Exp $")
+MODULE_ID("$Id: lib_newwin.c,v 1.71 2011/05/28 21:32:51 tom Exp $")
 
 #define window_is(name) ((sp)->_##name == win)
 
@@ -61,6 +62,17 @@
 {
     SCREEN *sp;
 
+#ifdef USE_SP_WINDOWLIST
+    if ((sp = _nc_screen_of(win)) != 0) {
+	if (window_is(curscr)) {
+	    remove_window(curscr);
+	} else if (window_is(stdscr)) {
+	    remove_window(stdscr);
+	} else if (window_is(newscr)) {
+	    remove_window(newscr);
+	}
+    }
+#else
     for (each_screen(sp)) {
 	if (window_is(curscr)) {
 	    remove_window(curscr);
@@ -73,6 +85,7 @@
 	    break;
 	}
     }
+#endif
 }
 
 NCURSES_EXPORT(int)
@@ -81,17 +94,20 @@
     WINDOWLIST *p, *q;
     int i;
     int result = ERR;
+#ifdef USE_SP_WINDOWLIST
+    SCREEN *sp = _nc_screen_of(win);	/* pretend this is parameter */
+#endif
 
-    T((T_CALLED("_nc_freewin(%p)"), win));
+    T((T_CALLED("_nc_freewin(%p)"), (void *) win));
 
     if (win != 0) {
-	if (_nc_try_global(curses) == 0) {
+	if (_nc_nonsp_try_global(curses) == 0) {
 	    q = 0;
-	    for (each_window(p)) {
+	    for (each_window(SP_PARM, p)) {
 		if (&(p->win) == win) {
 		    remove_window_from_screen(win);
 		    if (q == 0)
-			_nc_windows = p->next;
+			WindowList(SP_PARM) = p->next;
 		    else
 			q->next = p->next;
 
@@ -103,35 +119,43 @@
 		    free(p);
 
 		    result = OK;
-		    T(("...deleted win=%p", win));
+		    T(("...deleted win=%p", (void *) win));
 		    break;
 		}
 		q = p;
 	    }
-	    _nc_unlock_global(curses);
+	    _nc_nonsp_unlock_global(curses);
 	}
     }
     returnCode(result);
 }
 
 NCURSES_EXPORT(WINDOW *)
-newwin(int num_lines, int num_columns, int begy, int begx)
+NCURSES_SP_NAME(newwin) (NCURSES_SP_DCLx
+			 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));
+    T((T_CALLED("newwin(%p, %d,%d,%d,%d)"), (void *) SP_PARM, num_lines, num_columns,
+       begy, begx));
 
-    if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0)
+    if (begy < 0
+	|| begx < 0
+	|| num_lines < 0
+	|| num_columns < 0
+	|| SP_PARM == 0)
 	returnWin(0);
 
     if (num_lines == 0)
-	num_lines = SP->_lines_avail - begy;
+	num_lines = SP_PARM->_lines_avail - begy;
     if (num_columns == 0)
-	num_columns = screen_columns - begx;
+	num_columns = screen_columns(SP_PARM) - begx;
 
-    if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0)
+    win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx
+					num_lines, num_columns, begy, begx, 0);
+    if (win == 0)
 	returnWin(0);
 
     for (i = 0; i < num_lines; i++) {
@@ -149,14 +173,30 @@
     returnWin(win);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(WINDOW *)
+newwin(int num_lines, int num_columns, int begy, int begx)
+{
+    WINDOW *win;
+    _nc_sp_lock_global(curses);
+    win = NCURSES_SP_NAME(newwin) (CURRENT_SCREEN,
+				   num_lines, num_columns, begy, begx);
+    _nc_sp_unlock_global(curses);
+    return (win);
+}
+#endif
+
 NCURSES_EXPORT(WINDOW *)
 derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
 {
     WINDOW *win;
     int i;
     int flags = _SUBWIN;
+#if NCURSES_SP_FUNCS
+    SCREEN *sp = _nc_screen_of(orig);
+#endif
 
-    T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns,
+    T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), (void *) orig, num_lines, num_columns,
        begy, begx));
 
     /*
@@ -177,8 +217,10 @@
     if (orig->_flags & _ISPAD)
 	flags |= _ISPAD;
 
-    if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
-			   orig->_begx + begx, flags)) == 0)
+    win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx num_lines, num_columns,
+					orig->_begy + begy,
+					orig->_begx + begx, flags);
+    if (win == 0)
 	returnWin(0);
 
     win->_pary = begy;
@@ -197,30 +239,41 @@
 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));
+    WINDOW *result = 0;
 
-    returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx));
+    T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), (void *) w, l, c, y, x));
+    if (w != 0) {
+	T(("parent has begy = %ld, begx = %ld", (long) w->_begy, (long) w->_begx));
+
+	result = derwin(w, l, c, y - w->_begy, x - w->_begx);
+    }
+    returnWin(result);
 }
 
 static bool
 dimension_limit(int value)
 {
-    NCURSES_SIZE_T test = value;
+    NCURSES_SIZE_T test = (NCURSES_SIZE_T) value;
     return (test == value && value > 0);
 }
 
 NCURSES_EXPORT(WINDOW *)
-_nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
+NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_DCLx
+			      int num_lines,
+			      int num_columns,
+			      int begy,
+			      int begx,
+			      int flags)
 {
     int i;
     WINDOWLIST *wp;
     WINDOW *win;
-    bool is_pad = (flags & _ISPAD);
+    bool is_padwin = (flags & _ISPAD);
 
-    T((T_CALLED("_nc_makenew(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx));
+    T((T_CALLED("_nc_makenew(%p,%d,%d,%d,%d)"),
+       (void *) SP_PARM, num_lines, num_columns, begy, begx));
 
-    if (SP == 0)
+    if (SP_PARM == 0)
 	returnWin(0);
 
     if (!dimension_limit(num_lines) || !dimension_limit(num_columns))
@@ -232,26 +285,28 @@
     win = &(wp->win);
 
     if ((win->_line = typeCalloc(struct ldat, ((unsigned) num_lines))) == 0) {
-	free(win);
+	free(wp);
 	returnWin(0);
     }
 
-    _nc_lock_global(curses);
+    _nc_nonsp_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->_maxy = (NCURSES_SIZE_T) (num_lines - 1);
+    win->_maxx = (NCURSES_SIZE_T) (num_columns - 1);
+    win->_begy = (NCURSES_SIZE_T) begy;
+    win->_begx = (NCURSES_SIZE_T) begx;
+    win->_yoffset = SP_PARM->_topstolen;
 
-    win->_flags = flags;
+    win->_flags = (short) 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->_clear = (is_padwin
+		   ? FALSE
+		   : (num_lines == screen_lines(SP_PARM)
+		      && num_columns == screen_columns(SP_PARM)));
     win->_idlok = FALSE;
     win->_idcok = TRUE;
     win->_scroll = FALSE;
@@ -265,7 +320,7 @@
     win->_parent = 0;
 
     win->_regtop = 0;
-    win->_regbottom = num_lines - 1;
+    win->_regbottom = (NCURSES_SIZE_T) (num_lines - 1);
 
     win->_pad._pad_y = -1;
     win->_pad._pad_x = -1;
@@ -295,28 +350,28 @@
 	 * So that's how we want ncurses to behave.
 	 */
 	win->_line[i].firstchar = 0;
-	win->_line[i].lastchar = num_columns - 1;
+	win->_line[i].lastchar = (NCURSES_SIZE_T) (num_columns - 1);
 
 	if_USE_SCROLL_HINTS(win->_line[i].oldindex = i);
     }
 
-    if (!is_pad && (begx + num_columns == screen_columns)) {
+    if (!is_padwin && (begx + num_columns == screen_columns(SP_PARM))) {
 	win->_flags |= _ENDLINE;
 
-	if (begx == 0 && num_lines == screen_lines && begy == 0)
+	if (begx == 0 && num_lines == screen_lines(SP_PARM) && begy == 0)
 	    win->_flags |= _FULLWIN;
 
-	if (begy + num_lines == screen_lines)
+	if (begy + num_lines == screen_lines(SP_PARM))
 	    win->_flags |= _SCROLLWIN;
     }
 
-    wp->next = _nc_windows;
-    wp->screen = SP;
-    _nc_windows = wp;
+    wp->next = WindowList(SP_PARM);
+    wp->screen = SP_PARM;
+    WindowList(SP_PARM) = wp;
 
-    T((T_CREATE("window %p"), win));
+    T((T_CREATE("window %p"), (void *) win));
 
-    _nc_unlock_global(curses);
+    _nc_nonsp_unlock_global(curses);
     returnWin(win);
 }
 
@@ -325,14 +380,22 @@
  * 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)
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(WINDOW *)
+_nc_curscr_of(SCREEN *sp)
 {
-    SCREEN *sp = 0;
-
-    if (win != 0) {
-	WINDOWLIST *wp = (WINDOWLIST *) win;
-	sp = wp->screen;
-    }
-    return (sp);
+    return sp == 0 ? 0 : CurScreen(sp);
 }
+
+NCURSES_EXPORT(WINDOW *)
+_nc_newscr_of(SCREEN *sp)
+{
+    return sp == 0 ? 0 : NewScreen(sp);
+}
+
+NCURSES_EXPORT(WINDOW *)
+_nc_stdscr_of(SCREEN *sp)
+{
+    return sp == 0 ? 0 : StdScreen(sp);
+}
+#endif
diff --git a/ncurses/base/lib_nl.c b/ncurses/base/lib_nl.c
index 32515da..3425487 100644
--- a/ncurses/base/lib_nl.c
+++ b/ncurses/base/lib_nl.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -42,38 +44,52 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_nl.c,v 1.8 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_nl.c,v 1.12 2009/10/24 22:05:55 tom Exp $")
 
 #ifdef __EMX__
 #include <io.h>
 #endif
 
 NCURSES_EXPORT(int)
-nl(void)
+NCURSES_SP_NAME(nl) (NCURSES_SP_DCL0)
 {
-    T((T_CALLED("nl()")));
-
-    SP->_nl = TRUE;
-
+    T((T_CALLED("nl(%p)"), (void *) SP_PARM));
+    if (0 == SP_PARM)
+	returnCode(ERR);
+    SP_PARM->_nl = TRUE;
 #ifdef __EMX__
     _nc_flush();
-    _fsetmode(NC_OUTPUT, "t");
+    _fsetmode(NC_OUTPUT(SP_PARM), "t");
 #endif
-
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+nl(void)
+{
+    return NCURSES_SP_NAME(nl) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(nonl) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("nonl(%p)"), (void *) SP_PARM));
+    if (0 == SP_PARM)
+	returnCode(ERR);
+    SP_PARM->_nl = FALSE;
+#ifdef __EMX__
+    _nc_flush();
+    _fsetmode(NC_OUTPUT(SP_PARM), "b");
+#endif
+    returnCode(OK);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 nonl(void)
 {
-    T((T_CALLED("nonl()")));
-
-    SP->_nl = FALSE;
-
-#ifdef __EMX__
-    _nc_flush();
-    _fsetmode(NC_OUTPUT, "b");
-#endif
-
-    returnCode(OK);
+    return NCURSES_SP_NAME(nonl) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/base/lib_overlay.c b/ncurses/base/lib_overlay.c
index 669e8e7..a206248 100644
--- a/ncurses/base/lib_overlay.c
+++ b/ncurses/base/lib_overlay.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_overlay.c,v 1.27 2008/06/07 23:30:34 tom Exp $")
+MODULE_ID("$Id: lib_overlay.c,v 1.31 2013/04/06 23:47:13 tom Exp $")
 
 static int
 overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
@@ -52,7 +52,7 @@
     int dminrow, dmincol;
     int dmaxrow, dmaxcol;
 
-    T((T_CALLED("overlap(%p,%p,%d)"), src, dst, flag));
+    T((T_CALLED("overlap(%p,%p,%d)"), (const void *) src, (void *) dst, flag));
 
     if (src != 0 && dst != 0) {
 	_nc_lock_global(curses);
@@ -110,7 +110,7 @@
 NCURSES_EXPORT(int)
 overlay(const WINDOW *win1, WINDOW *win2)
 {
-    T((T_CALLED("overlay(%p,%p)"), win1, win2));
+    T((T_CALLED("overlay(%p,%p)"), (const void *) win1, (void *) win2));
     returnCode(overlap(win1, win2, TRUE));
 }
 
@@ -127,7 +127,7 @@
 NCURSES_EXPORT(int)
 overwrite(const WINDOW *win1, WINDOW *win2)
 {
-    T((T_CALLED("overwrite(%p,%p)"), win1, win2));
+    T((T_CALLED("overwrite(%p,%p)"), (const void *) win1, (void *) win2));
     returnCode(overlap(win1, win2, FALSE));
 }
 
@@ -145,9 +145,16 @@
     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));
+       (const void *) src,
+       (void *) dst,
+       sminrow, smincol,
+       dminrow, dmincol,
+       dmaxrow, dmaxcol, over));
 
-    if (src && dst) {
+    if (src != 0
+	&& dst != 0
+	&& dmaxrow >= dminrow
+	&& dmaxcol >= dmincol) {
 	_nc_lock_global(curses);
 
 	bk = AttrOf(dst->_nc_bkgd);
@@ -156,6 +163,7 @@
 	/* make sure rectangle exists in source */
 	if ((sminrow + dmaxrow - dminrow) <= (src->_maxy + 1) &&
 	    (smincol + dmaxcol - dmincol) <= (src->_maxx + 1)) {
+	    bool copied = FALSE;
 
 	    T(("rectangle exists in source"));
 
@@ -168,10 +176,18 @@
 		     dy <= dmaxrow;
 		     sy++, dy++) {
 
+		    if (dy < 0 || sy < 0)
+			continue;
+
 		    touched = FALSE;
 		    for (dx = dmincol, sx = smincol;
 			 dx <= dmaxcol;
 			 sx++, dx++) {
+
+			if (dx < 0 || sx < 0)
+			    continue;
+			copied = TRUE;
+
 			if (over) {
 			    if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
 				(!CharEq(dst->_line[dy].text[dx],
@@ -197,7 +213,8 @@
 		    }
 		}
 		T(("finished copywin"));
-		rc = OK;
+		if (copied)
+		    rc = OK;
 	    }
 	}
 	_nc_unlock_global(curses);
diff --git a/ncurses/base/lib_pad.c b/ncurses/base/lib_pad.c
index 6cad9c5..b87498b 100644
--- a/ncurses/base/lib_pad.c
+++ b/ncurses/base/lib_pad.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -40,21 +42,22 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_pad.c,v 1.41 2006/10/14 20:47:13 tom Exp $")
+MODULE_ID("$Id: lib_pad.c,v 1.46 2010/04/24 23:50:45 tom Exp $")
 
 NCURSES_EXPORT(WINDOW *)
-newpad(int l, int c)
+NCURSES_SP_NAME(newpad) (NCURSES_SP_DCLx int l, int c)
 {
     WINDOW *win;
     NCURSES_CH_T *ptr;
     int i;
 
-    T((T_CALLED("newpad(%d, %d)"), l, c));
+    T((T_CALLED("newpad(%p,%d, %d)"), (void *) SP_PARM, l, c));
 
     if (l <= 0 || c <= 0)
 	returnWin(0);
 
-    if ((win = _nc_makenew(l, c, 0, 0, _ISPAD)) == NULL)
+    win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx l, c, 0, 0, _ISPAD);
+    if (win == NULL)
 	returnWin(0);
 
     for (i = 0; i < l; i++) {
@@ -70,6 +73,14 @@
     returnWin(win);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(WINDOW *)
+newpad(int l, int c)
+{
+    return NCURSES_SP_NAME(newpad) (CURRENT_SCREEN, l, c);
+}
+#endif
+
 NCURSES_EXPORT(WINDOW *)
 subpad(WINDOW *orig, int l, int c, int begy, int begx)
 {
@@ -94,10 +105,14 @@
 	 int smaxrow,
 	 int smaxcol)
 {
+#if NCURSES_SP_FUNCS
+    SCREEN *sp = _nc_screen_of(win);
+#endif
+
     T((T_CALLED("prefresh()")));
     if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow,
 		     smaxcol) != ERR
-	&& doupdate() != ERR) {
+	&& NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG) != ERR) {
 	returnCode(OK);
     }
     returnCode(ERR);
@@ -112,10 +127,11 @@
 	     int smaxrow,
 	     int smaxcol)
 {
-    NCURSES_SIZE_T i, j;
-    NCURSES_SIZE_T m, n;
-    NCURSES_SIZE_T pmaxrow;
-    NCURSES_SIZE_T pmaxcol;
+    int i, j;
+    int m, n;
+    int pmaxrow;
+    int pmaxcol;
+    SCREEN *sp;
 
 #if USE_SCROLL_HINTS
     const int my_len = 2;	/* parameterize the threshold for hardscroll */
@@ -124,7 +140,7 @@
 #endif
 
     T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"),
-       win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol));
+       (void *) win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol));
 
     if (win == 0)
 	returnCode(ERR);
@@ -132,6 +148,8 @@
     if (!(win->_flags & _ISPAD))
 	returnCode(ERR);
 
+    sp = _nc_screen_of(win);
+
     /* negative values are interpreted as zero */
     if (pminrow < 0)
 	pminrow = 0;
@@ -162,8 +180,8 @@
 	pmaxcol = pmincol + smaxcol - smincol;
     }
 
-    if (smaxrow >= screen_lines
-	|| smaxcol >= screen_columns
+    if (smaxrow >= screen_lines(sp)
+	|| smaxcol >= screen_columns(sp)
 	|| sminrow > smaxrow
 	|| smincol > smaxcol)
 	returnCode(ERR);
@@ -194,13 +212,13 @@
      * merely change the costs of various update cases.
      */
 #if USE_SCROLL_HINTS
-    wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len));
+    wide = (smincol < my_len && smaxcol > (NewScreen(sp)->_maxx - my_len));
 #endif
 
     for (i = pminrow, m = sminrow + win->_yoffset;
-	 i <= pmaxrow && m <= newscr->_maxy;
+	 i <= pmaxrow && m <= NewScreen(sp)->_maxy;
 	 i++, m++) {
-	register struct ldat *nline = &newscr->_line[m];
+	register struct ldat *nline = &NewScreen(sp)->_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];
@@ -229,9 +247,9 @@
 		|| nind > smaxrow) {
 		nind = _NEWINDEX;
 	    } else if (displaced) {
-		register struct ldat *pline = &curscr->_line[nind];
+		register struct ldat *pline = &CurScreen(sp)->_line[nind];
 		for (j = 0; j <= my_len; j++) {
-		    int k = newscr->_maxx - j;
+		    int k = NewScreen(sp)->_maxx - j;
 		    if (pline->text[j] != nline->text[j]
 			|| pline->text[k] != nline->text[k]) {
 			nind = _NEWINDEX;
@@ -261,12 +279,12 @@
 	win->_line[i].oldindex = _NEWINDEX;
 #endif
 
-    win->_begx = smincol;
-    win->_begy = sminrow;
+    win->_begx = (NCURSES_SIZE_T) smincol;
+    win->_begy = (NCURSES_SIZE_T) sminrow;
 
     if (win->_clear) {
 	win->_clear = FALSE;
-	newscr->_clear = TRUE;
+	NewScreen(sp)->_clear = TRUE;
     }
 
     /*
@@ -278,10 +296,12 @@
 	&& 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;
+	NewScreen(sp)->_cury = (NCURSES_SIZE_T) (win->_cury - pminrow
+						 + win->_begy + win->_yoffset);
+	NewScreen(sp)->_curx = (NCURSES_SIZE_T) (win->_curx - pmincol
+						 + win->_begx);
     }
-    newscr->_leaveok = win->_leaveok;
+    NewScreen(sp)->_leaveok = win->_leaveok;
     win->_flags &= ~_HASMOVED;
 
     /*
@@ -289,12 +309,12 @@
      * 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;
+    win->_pad._pad_y = (NCURSES_SIZE_T) pminrow;
+    win->_pad._pad_x = (NCURSES_SIZE_T) pmincol;
+    win->_pad._pad_top = (NCURSES_SIZE_T) sminrow;
+    win->_pad._pad_left = (NCURSES_SIZE_T) smincol;
+    win->_pad._pad_bottom = (NCURSES_SIZE_T) smaxrow;
+    win->_pad._pad_right = (NCURSES_SIZE_T) smaxcol;
 
     returnCode(OK);
 }
@@ -302,7 +322,7 @@
 NCURSES_EXPORT(int)
 pechochar(WINDOW *pad, const chtype ch)
 {
-    T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch)));
+    T((T_CALLED("pechochar(%p, %s)"), (void *) pad, _tracechtype(ch)));
 
     if (pad == 0)
 	returnCode(ERR);
diff --git a/ncurses/base/lib_printw.c b/ncurses/base/lib_printw.c
index 62ae921..56528f6 100644
--- a/ncurses/base/lib_printw.c
+++ b/ncurses/base/lib_printw.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ *  Author: Thomas E. Dickey            1997-on                             *
  ****************************************************************************/
 
 /*
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_printw.c,v 1.18 2006/12/17 19:21:39 tom Exp $")
+MODULE_ID("$Id: lib_printw.c,v 1.23 2012/09/03 17:55:28 tom Exp $")
 
 NCURSES_EXPORT(int)
 printw(const char *fmt,...)
@@ -48,10 +48,11 @@
     int code;
 
 #ifdef TRACE
-    va_start(argp, fmt);
+    va_list argq;
+    va_start(argq, fmt);
     T((T_CALLED("printw(%s%s)"),
-       _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
-    va_end(argp);
+       _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
+    va_end(argq);
 #endif
 
     va_start(argp, fmt);
@@ -68,10 +69,11 @@
     int code;
 
 #ifdef TRACE
-    va_start(argp, fmt);
+    va_list argq;
+    va_start(argq, fmt);
     T((T_CALLED("wprintw(%p,%s%s)"),
-       win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
-    va_end(argp);
+       (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
+    va_end(argq);
 #endif
 
     va_start(argp, fmt);
@@ -88,10 +90,11 @@
     int code;
 
 #ifdef TRACE
-    va_start(argp, fmt);
+    va_list argq;
+    va_start(argq, fmt);
     T((T_CALLED("mvprintw(%d,%d,%s%s)"),
-       y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
-    va_end(argp);
+       y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
+    va_end(argq);
 #endif
 
     if ((code = move(y, x)) != ERR) {
@@ -109,10 +112,11 @@
     int code;
 
 #ifdef TRACE
-    va_start(argp, fmt);
+    va_list argq;
+    va_start(argq, fmt);
     T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
-       y, x, win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
-    va_end(argp);
+       y, x, (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
+    va_end(argq);
 #endif
 
     if ((code = wmove(win, y, x)) != ERR) {
@@ -128,10 +132,14 @@
 {
     char *buf;
     int code = ERR;
+#if NCURSES_SP_FUNCS
+    SCREEN *sp = _nc_screen_of(win);
+#endif
 
-    T((T_CALLED("vwprintw(%p,%s,va_list)"), win, _nc_visbuf(fmt)));
+    T((T_CALLED("vwprintw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
 
-    if ((buf = _nc_printf_string(fmt, argp)) != 0) {
+    buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
+    if (buf != 0) {
 	code = waddstr(win, buf);
     }
     returnCode(code);
diff --git a/ncurses/base/lib_redrawln.c b/ncurses/base/lib_redrawln.c
index 6b0905f..72905f8 100644
--- a/ncurses/base/lib_redrawln.c
+++ b/ncurses/base/lib_redrawln.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_redrawln.c,v 1.12 2007/10/13 20:08:56 tom Exp $")
+MODULE_ID("$Id: lib_redrawln.c,v 1.17 2010/12/19 00:03:23 tom Exp $")
 
 NCURSES_EXPORT(int)
 wredrawln(WINDOW *win, int beg, int num)
@@ -47,37 +47,40 @@
     int i;
     int end;
     size_t len;
+    SCREEN *sp;
 
-    T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num));
+    T((T_CALLED("wredrawln(%p,%d,%d)"), (void *) win, beg, num));
 
     if (win == 0)
 	returnCode(ERR);
 
+    sp = _nc_screen_of(win);
+
     if (beg < 0)
 	beg = 0;
 
     if (touchline(win, beg, num) == ERR)
 	returnCode(ERR);
 
-    if (touchline(curscr, beg + win->_begy, num) == ERR)
+    if (touchline(CurScreen(sp), beg + win->_begy, num) == ERR)
 	returnCode(ERR);
 
     end = beg + num;
-    if (end > curscr->_maxy + 1)
-	end = curscr->_maxy + 1;
+    if (end > CurScreen(sp)->_maxy + 1 - win->_begy)
+	end = CurScreen(sp)->_maxy + 1 - win->_begy;
     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]);
+    len = (size_t) (win->_maxx + 1);
+    if (len > (size_t) (CurScreen(sp)->_maxx + 1 - win->_begx))
+	len = (size_t) (CurScreen(sp)->_maxx + 1 - win->_begx);
+    len *= sizeof(CurScreen(sp)->_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);
+	memset(CurScreen(sp)->_line[crow].text + win->_begx, 0, len);
+	NCURSES_SP_NAME(_nc_make_oldhash) (NCURSES_SP_ARGx crow);
     }
 
     returnCode(OK);
diff --git a/ncurses/base/lib_refresh.c b/ncurses/base/lib_refresh.c
index 2a9cafb..a77bc48 100644
--- a/ncurses/base/lib_refresh.c
+++ b/ncurses/base/lib_refresh.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 /*
@@ -41,24 +42,27 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_refresh.c,v 1.41 2007/09/29 20:39:34 tom Exp $")
+MODULE_ID("$Id: lib_refresh.c,v 1.45 2011/06/25 19:02:22 Vassili.Courzakis Exp $")
 
 NCURSES_EXPORT(int)
 wrefresh(WINDOW *win)
 {
     int code;
+#if NCURSES_SP_FUNCS
+    SCREEN *SP_PARM = _nc_screen_of(win);
+#endif
 
-    T((T_CALLED("wrefresh(%p)"), win));
+    T((T_CALLED("wrefresh(%p)"), (void *) win));
 
     if (win == 0) {
 	code = ERR;
-    } else if (win == curscr) {
-	curscr->_clear = TRUE;
-	code = doupdate();
+    } else if (win == CurScreen(SP_PARM)) {
+	CurScreen(SP_PARM)->_clear = TRUE;
+	code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
     } else if ((code = wnoutrefresh(win)) == OK) {
 	if (win->_clear)
-	    newscr->_clear = TRUE;
-	code = doupdate();
+	    NewScreen(SP_PARM)->_clear = TRUE;
+	code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
 	/*
 	 * 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
@@ -73,22 +77,19 @@
 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;
+    int limit_x;
+    int src_row, src_col;
+    int begx;
+    int begy;
+    int dst_row, dst_col;
 #if USE_SCROLL_HINTS
     bool wide;
 #endif
+#if NCURSES_SP_FUNCS
+    SCREEN *SP_PARM = _nc_screen_of(win);
+#endif
 
-    T((T_CALLED("wnoutrefresh(%p)"), win));
-#ifdef TRACE
-    if (USE_TRACEF(TRACE_UPDATE)) {
-	_tracedump("...win", win);
-	_nc_unlock_global(tracef);
-    }
-#endif /* TRACE */
+    T((T_CALLED("wnoutrefresh(%p)"), (void *) win));
 
     /*
      * This function will break badly if we try to refresh a pad.
@@ -97,12 +98,19 @@
 	|| (win->_flags & _ISPAD))
 	returnCode(ERR);
 
+#ifdef TRACE
+    if (USE_TRACEF(TRACE_UPDATE)) {
+	_tracedump("...win", win);
+	_nc_unlock_global(tracef);
+    }
+#endif /* TRACE */
+
     /* 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);
+    NewScreen(SP_PARM)->_nc_bkgd = win->_nc_bkgd;
+    WINDOW_ATTRS(NewScreen(SP_PARM)) = WINDOW_ATTRS(win);
 
     /* merge in change information from all subwindows of this window */
     wsyncdown(win);
@@ -122,7 +130,7 @@
      * 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));
+    wide = (begx <= 1 && win->_maxx >= (NewScreen(SP_PARM)->_maxx - 1));
 #endif
 
     win->_flags &= ~_HASMOVED;
@@ -137,14 +145,14 @@
     /* limit(dst_col) */
     limit_x = win->_maxx;
     /* limit(src_col) */
-    if (limit_x > newscr->_maxx - begx)
-	limit_x = newscr->_maxx - begx;
+    if (limit_x > NewScreen(SP_PARM)->_maxx - begx)
+	limit_x = NewScreen(SP_PARM)->_maxx - begx;
 
     for (src_row = 0, dst_row = begy + win->_yoffset;
-	 src_row <= win->_maxy && dst_row <= newscr->_maxy;
+	 src_row <= win->_maxy && dst_row <= NewScreen(SP_PARM)->_maxy;
 	 src_row++, dst_row++) {
-	register struct ldat *nline = &newscr->_line[dst_row];
-	register struct ldat *oline = &win->_line[src_row];
+	struct ldat *nline = &(NewScreen(SP_PARM)->_line[dst_row]);
+	struct ldat *oline = &win->_line[src_row];
 
 	if (oline->firstchar != _NOCHANGE) {
 	    int last_src = oline->lastchar;
@@ -156,7 +164,7 @@
 	    dst_col = src_col + begx;
 
 	    if_WIDEC({
-		register int j;
+		int j;
 
 		/*
 		 * Ensure that we will copy complete multi-column characters
@@ -197,7 +205,7 @@
 				       : win->_maxx);
 		int fix_left = dst_col;
 		int fix_right = last_dst;
-		register int j;
+		int j;
 
 		/*
 		 * Check for boundary cases where we may overwrite part of a
@@ -225,7 +233,8 @@
 		     * this character.  Find the end of the character.
 		     */
 		    ++j;
-		    while (j <= newscr->_maxx && isWidecExt(nline->text[j])) {
+		    while (j <= NewScreen(SP_PARM)->_maxx &&
+			   isWidecExt(nline->text[j])) {
 			fix_right = j++;
 		    }
 		}
@@ -269,18 +278,19 @@
 
     if (win->_clear) {
 	win->_clear = FALSE;
-	newscr->_clear = TRUE;
+	NewScreen(SP_PARM)->_clear = TRUE;
     }
 
     if (!win->_leaveok) {
-	newscr->_cury = win->_cury + win->_begy + win->_yoffset;
-	newscr->_curx = win->_curx + win->_begx;
+	NewScreen(SP_PARM)->_cury = (NCURSES_SIZE_T) (win->_cury +
+						      win->_begy + win->_yoffset);
+	NewScreen(SP_PARM)->_curx = (NCURSES_SIZE_T) (win->_curx + win->_begx);
     }
-    newscr->_leaveok = win->_leaveok;
+    NewScreen(SP_PARM)->_leaveok = win->_leaveok;
 
 #ifdef TRACE
     if (USE_TRACEF(TRACE_UPDATE)) {
-	_tracedump("newscr", newscr);
+	_tracedump("newscr", NewScreen(SP_PARM));
 	_nc_unlock_global(tracef);
     }
 #endif /* TRACE */
diff --git a/ncurses/base/lib_restart.c b/ncurses/base/lib_restart.c
index da770d4..5bfb078 100644
--- a/ncurses/base/lib_restart.c
+++ b/ncurses/base/lib_restart.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2008                    *
  ****************************************************************************/
 
 /*
@@ -40,53 +41,63 @@
 
 #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 $")
+MODULE_ID("$Id: lib_restart.c,v 1.16 2015/06/27 18:12:15 tom Exp $")
 
 NCURSES_EXPORT(int)
-restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
+NCURSES_SP_NAME(restartterm) (NCURSES_SP_DCLx
+			      NCURSES_CONST char *termp,
+			      int filenum,
+			      int *errret)
 {
     int result;
+#ifdef USE_TERM_DRIVER
+    TERMINAL *new_term = 0;
+#endif
 
-    T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret));
+    START_TRACE();
+    T((T_CALLED("restartterm(%p,%s,%d,%p)"),
+       (void *) SP_PARM,
+       termp,
+       filenum,
+       (void *) errret));
 
-    if (setupterm(termp, filenum, errret) != OK) {
+    if (TINFO_SETUP_TERM(&new_term, termp, filenum, errret, FALSE) != OK) {
 	result = ERR;
-    } else if (SP != 0) {
-	int saveecho = SP->_echo;
-	int savecbreak = SP->_cbreak;
-	int saveraw = SP->_raw;
-	int savenl = SP->_nl;
+    } else if (SP_PARM != 0) {
+	int saveecho = SP_PARM->_echo;
+	int savecbreak = SP_PARM->_cbreak;
+	int saveraw = SP_PARM->_raw;
+	int savenl = SP_PARM->_nl;
 
-	if (saveecho)
-	    echo();
-	else
-	    noecho();
+#ifdef USE_TERM_DRIVER
+	SP_PARM->_term = new_term;
+#endif
+	if (saveecho) {
+	    NCURSES_SP_NAME(echo) (NCURSES_SP_ARG);
+	} else {
+	    NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
+	}
 
 	if (savecbreak) {
-	    cbreak();
-	    noraw();
+	    NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
+	    NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
 	} else if (saveraw) {
-	    nocbreak();
-	    raw();
+	    NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
+	    NCURSES_SP_NAME(raw) (NCURSES_SP_ARG);
 	} else {
-	    nocbreak();
-	    noraw();
+	    NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
+	    NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
 	}
-	if (savenl)
-	    nl();
-	else
-	    nonl();
+	if (savenl) {
+	    NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
+	} else {
+	    NCURSES_SP_NAME(nonl) (NCURSES_SP_ARG);
+	}
 
-	reset_prog_mode();
+	NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
 
 #if USE_SIZECHANGE
-	_nc_update_screensize(SP);
+	_nc_update_screensize(SP_PARM);
 #endif
 
 	result = OK;
@@ -95,3 +106,12 @@
     }
     returnCode(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
+{
+    START_TRACE();
+    return NCURSES_SP_NAME(restartterm) (CURRENT_SCREEN, termp, filenum, errret);
+}
+#endif
diff --git a/ncurses/base/lib_scanw.c b/ncurses/base/lib_scanw.c
index b8a5a22..637aa46 100644
--- a/ncurses/base/lib_scanw.c
+++ b/ncurses/base/lib_scanw.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,14 +40,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_scanw.c,v 1.11 2001/06/30 23:39:41 tom Exp $")
+MODULE_ID("$Id: lib_scanw.c,v 1.13 2011/10/22 16:31:35 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)
+    if (wgetnstr(win, buf, (int) sizeof(buf) - 1) == ERR)
 	return (ERR);
 
     return (vsscanf(buf, fmt, argp));
@@ -73,7 +73,7 @@
     int code;
     va_list ap;
 
-    T(("wscanw(%p,\"%s\",...) called", win, fmt));
+    T(("wscanw(%p,\"%s\",...) called", (void *) win, fmt));
 
     va_start(ap, fmt);
     code = vwscanw(win, fmt, ap);
diff --git a/ncurses/base/lib_screen.c b/ncurses/base/lib_screen.c
index 4aa58ea..a03ceec 100644
--- a/ncurses/base/lib_screen.c
+++ b/ncurses/base/lib_screen.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,35 +30,514 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_screen.c,v 1.31 2008/08/16 19:05:37 tom Exp $")
+#include <ctype.h>
+
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_screen.c,v 1.77 2015/07/04 22:54:14 tom Exp $")
 
 #define MAX_SIZE 0x3fff		/* 16k is big enough for a window or pad */
 
+#define MARKER '\\'
+#define APPEND '+'
+#define GUTTER '|'
+#define L_CURL '{'
+#define R_CURL '}'
+
+/*
+ * Use 0x8888 as the magic number for new-format files, since it cannot be
+ * mistaken for the _cury/_curx pair of 16-bit numbers which start the old
+ * format.  It happens to be unused in the file 5.22 database (2015/03/07).
+ */
+static const char my_magic[] =
+{'\210', '\210', '\210', '\210'};
+
+#if NCURSES_EXT_PUTWIN
+typedef enum {
+    pINT			/* int */
+    ,pSHORT			/* short */
+    ,pBOOL			/* bool */
+    ,pATTR			/* attr_t */
+    ,pCHAR			/* chtype */
+    ,pSIZE			/* NCURSES_SIZE_T */
+#if NCURSES_WIDECHAR
+    ,pCCHAR			/* cchar_t */
+#endif
+} PARAM_TYPE;
+
+typedef struct {
+    const char name[11];
+    attr_t attr;
+} SCR_ATTRS;
+
+typedef struct {
+    const char name[17];
+    PARAM_TYPE type;
+    size_t size;
+    size_t offset;
+} SCR_PARAMS;
+
+#define DATA(name) { { #name }, A_##name }
+static const SCR_ATTRS scr_attrs[] =
+{
+    DATA(NORMAL),
+    DATA(STANDOUT),
+    DATA(UNDERLINE),
+    DATA(REVERSE),
+    DATA(BLINK),
+    DATA(DIM),
+    DATA(BOLD),
+    DATA(ALTCHARSET),
+    DATA(INVIS),
+    DATA(PROTECT),
+    DATA(HORIZONTAL),
+    DATA(LEFT),
+    DATA(LOW),
+    DATA(RIGHT),
+    DATA(TOP),
+    DATA(VERTICAL),
+
+#ifdef A_ITALIC
+    DATA(ITALIC),
+#endif
+};
+#undef DATA
+
+#define sizeof2(type,name) sizeof(((type *)0)->name)
+#define DATA(name, type) { { #name }, type, sizeof2(WINDOW, name), offsetof(WINDOW, name) }
+
+static const SCR_PARAMS scr_params[] =
+{
+    DATA(_cury, pSIZE),
+    DATA(_curx, pSIZE),
+    DATA(_maxy, pSIZE),
+    DATA(_maxx, pSIZE),
+    DATA(_begy, pSIZE),
+    DATA(_begx, pSIZE),
+    DATA(_flags, pSHORT),
+    DATA(_attrs, pATTR),
+    DATA(_bkgd, pCHAR),
+    DATA(_notimeout, pBOOL),
+    DATA(_clear, pBOOL),
+    DATA(_leaveok, pBOOL),
+    DATA(_scroll, pBOOL),
+    DATA(_idlok, pBOOL),
+    DATA(_idcok, pBOOL),
+    DATA(_immed, pBOOL),
+    DATA(_sync, pBOOL),
+    DATA(_use_keypad, pBOOL),
+    DATA(_delay, pINT),
+    DATA(_regtop, pSIZE),
+    DATA(_regbottom, pSIZE),
+    DATA(_pad._pad_y, pSIZE),
+    DATA(_pad._pad_x, pSIZE),
+    DATA(_pad._pad_top, pSIZE),
+    DATA(_pad._pad_left, pSIZE),
+    DATA(_pad._pad_bottom, pSIZE),
+    DATA(_pad._pad_right, pSIZE),
+    DATA(_yoffset, pSIZE),
+#if NCURSES_WIDECHAR
+    DATA(_bkgrnd, pCCHAR),
+#if NCURSES_EXT_COLORS
+    DATA(_color, pINT),
+#endif
+#endif
+};
+#undef DATA
+
+static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+
+/*
+ * Allocate and read a line of text.  Caller must free it.
+ */
+static char *
+read_txt(FILE *fp)
+{
+    size_t limit = 1024;
+    size_t used = 0;
+    char *result = malloc(limit);
+    char *buffer;
+
+    if (result != 0) {
+	int ch = 0;
+
+	clearerr(fp);
+	result[used] = '\0';
+	do {
+	    if (used + 2 >= limit) {
+		limit += 1024;
+		buffer = realloc(result, limit);
+		if (buffer == 0) {
+		    free(result);
+		    result = 0;
+		    break;
+		}
+		result = buffer;
+	    }
+	    ch = fgetc(fp);
+	    if (ch == EOF)
+		break;
+	    result[used++] = (char) ch;
+	    result[used] = '\0';
+	} while (ch != '\n');
+
+	if (ch == '\n') {
+	    result[--used] = '\0';
+	    T(("READ:%s", result));
+	} else if (used == 0) {
+	    free(result);
+	    result = 0;
+	}
+    }
+    return result;
+}
+
+static char *
+decode_attr(char *source, attr_t *target, int *color)
+{
+    bool found = FALSE;
+
+    T(("decode_attr   '%s'", source));
+
+    while (*source) {
+	if (source[0] == MARKER && source[1] == L_CURL) {
+	    source += 2;
+	    found = TRUE;
+	} else if (source[0] == R_CURL) {
+	    source++;
+	    found = FALSE;
+	} else if (found) {
+	    size_t n;
+	    char *next = source;
+
+	    if (source[0] == GUTTER) {
+		++next;
+	    } else if (*next == 'C') {
+		int value = 0;
+		unsigned pair;
+		next++;
+		while (isdigit(UChar(*next))) {
+		    value = value * 10 + (*next++ - '0');
+		}
+		*target &= ~A_COLOR;
+		pair = (unsigned) ((value > 256)
+				   ? COLOR_PAIR(255)
+				   : COLOR_PAIR(value));
+		*target |= pair;
+		*color = value;
+	    } else {
+		while (isalnum(UChar(*next))) {
+		    ++next;
+		}
+		for (n = 0; n < SIZEOF(scr_attrs); ++n) {
+		    if ((size_t) (next - source) == strlen(scr_attrs[n].name)) {
+			if (scr_attrs[n].attr) {
+			    *target |= scr_attrs[n].attr;
+			} else {
+			    *target = A_NORMAL;
+			}
+			break;
+		    }
+		}
+	    }
+	    source = next;
+	} else {
+	    break;
+	}
+    }
+    return source;
+}
+
+static char *
+decode_char(char *source, int *target)
+{
+    int limit = 0;
+    int base = 16;
+    const char digits[] = "0123456789abcdef";
+
+    T(("decode_char   '%s'", source));
+    *target = ' ';
+    switch (*source) {
+    case MARKER:
+	switch (*++source) {
+	case APPEND:
+	    break;
+	case MARKER:
+	    *target = MARKER;
+	    ++source;
+	    break;
+	case 's':
+	    *target = ' ';
+	    ++source;
+	    break;
+	case '0':
+	case '1':
+	case '2':
+	case '3':
+	    base = 8;
+	    limit = 3;
+	    break;
+	case 'u':
+	    limit = 4;
+	    ++source;
+	    break;
+	case 'U':
+	    limit = 8;
+	    ++source;
+	    break;
+	}
+	if (limit) {
+	    *target = 0;
+	    while (limit-- > 0) {
+		char *find = strchr(digits, *source++);
+		int ch = (find != 0) ? (int) (find - digits) : -1;
+		*target *= base;
+		if (ch >= 0 && ch < base) {
+		    *target += ch;
+		}
+	    }
+	}
+	break;
+    default:
+	*target = *source++;
+	break;
+    }
+    return source;
+}
+
+static char *
+decode_chtype(char *source, chtype fillin, chtype *target)
+{
+    attr_t attr = ChAttrOf(fillin);
+    int color = PAIR_NUMBER((int) attr);
+    int value;
+
+    T(("decode_chtype '%s'", source));
+    source = decode_attr(source, &attr, &color);
+    source = decode_char(source, &value);
+    *target = (ChCharOf(value) | attr | (chtype) COLOR_PAIR(color));
+    /* FIXME - ignore combining characters */
+    return source;
+}
+
+#if NCURSES_WIDECHAR
+static char *
+decode_cchar(char *source, cchar_t *fillin, cchar_t *target)
+{
+    int color;
+    attr_t attr = fillin->attr;
+    wchar_t chars[CCHARW_MAX];
+    int append = 0;
+    int value = 0;
+
+    T(("decode_cchar  '%s'", source));
+    *target = blank;
+#if NCURSES_EXT_COLORS
+    color = fillin->ext_color;
+#else
+    color = (int) PAIR_NUMBER(attr);
+#endif
+    source = decode_attr(source, &attr, &color);
+    memset(chars, 0, sizeof(chars));
+    source = decode_char(source, &value);
+    chars[0] = (wchar_t) value;
+    /* handle combining characters */
+    while (source[0] == MARKER && source[1] == APPEND) {
+	source += 2;
+	source = decode_char(source, &value);
+	if (++append < CCHARW_MAX) {
+	    chars[append] = (wchar_t) value;
+	}
+    }
+    setcchar(target, chars, attr, (short) color, NULL);
+    return source;
+}
+#endif
+
+static int
+read_win(WINDOW *win, FILE *fp)
+{
+    int code = ERR;
+    char *txt;
+    char *name;
+    char *value;
+    size_t n;
+    int color;
+#if NCURSES_WIDECHAR
+    NCURSES_CH_T prior;
+#endif
+    chtype prior2;
+
+    memset(win, 0, sizeof(WINDOW));
+    for (;;) {
+	txt = read_txt(fp);
+	if (txt == 0)
+	    break;
+	if (!strcmp(txt, "rows:")) {
+	    free(txt);
+	    code = OK;
+	    break;
+	}
+	if ((value = strchr(txt, '=')) == 0) {
+	    free(txt);
+	    continue;
+	}
+	*value++ = '\0';
+	name = !strcmp(txt, "flag") ? value : txt;
+	for (n = 0; n < SIZEOF(scr_params); ++n) {
+	    if (!strcmp(name, scr_params[n].name)) {
+		void *data = (void *) ((char *) win + scr_params[n].offset);
+
+		switch (scr_params[n].type) {
+		case pATTR:
+		    (void) decode_attr(value, data, &color);
+		    break;
+		case pBOOL:
+		    *(bool *) data = TRUE;
+		    break;
+		case pCHAR:
+		    prior2 = ' ';
+		    decode_chtype(value, prior2, data);
+		    break;
+		case pINT:
+		    *(int *) data = atoi(value);
+		    break;
+		case pSHORT:
+		    *(short *) data = (short) atoi(value);
+		    break;
+		case pSIZE:
+		    *(NCURSES_SIZE_T *) data = (NCURSES_SIZE_T) atoi(value);
+		    break;
+#if NCURSES_WIDECHAR
+		case pCCHAR:
+		    prior = blank;
+		    decode_cchar(value, &prior, data);
+		    break;
+#endif
+		}
+		break;
+	    }
+	}
+	free(txt);
+    }
+    return code;
+}
+
+static int
+read_row(char *source, NCURSES_CH_T * prior, NCURSES_CH_T * target, int length)
+{
+    while (*source != '\0' && length > 0) {
+#if NCURSES_WIDECHAR
+	int n, len;
+	source = decode_cchar(source, prior, target);
+	len = wcwidth(target->chars[0]);
+	if (len > 1) {
+	    SetWidecExt(CHDEREF(target), 0);
+	    for (n = 1; n < len; ++n) {
+		target[n] = target[0];
+		SetWidecExt(CHDEREF(target), n);
+	    }
+	    target += (len - 1);
+	    length -= (len - 1);
+	}
+#else
+	source = decode_chtype(source, *prior, target);
+#endif
+	*prior = *target;
+	++target;
+	--length;
+    }
+    while (length-- > 0) {
+	*target++ = blank;
+    }
+    /* FIXME - see what error conditions should apply if I need to return ERR */
+    return 0;
+}
+#endif /* NCURSES_EXT_PUTWIN */
+
+/*
+ * Originally, getwin/putwin used fread/fwrite, because they used binary data.
+ * The new format uses printable ASCII, which does not have as predictable
+ * sizes.  Consequently, we use buffered I/O, e.g., fgetc/fprintf, which need
+ * special handling if we want to read screen dumps from an older library.
+ */
+static int
+read_block(void *target, size_t length, FILE *fp)
+{
+    int result = 0;
+    char *buffer = target;
+
+    clearerr(fp);
+    while (length-- != 0) {
+	int ch = fgetc(fp);
+	if (ch == EOF) {
+	    result = -1;
+	    break;
+	}
+	*buffer++ = (char) ch;
+    }
+    return result;
+}
+
 NCURSES_EXPORT(WINDOW *)
-getwin(FILE *filep)
+NCURSES_SP_NAME(getwin) (NCURSES_SP_DCLx FILE *filep)
 {
     WINDOW tmp, *nwin;
     int n;
+    bool old_format = FALSE;
 
-    T((T_CALLED("getwin(%p)"), filep));
+    T((T_CALLED("getwin(%p)"), (void *) 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)
+    if (filep == 0) {
 	returnWin(0);
+    }
+
+    /*
+     * Read the first 4 bytes to determine first if this is an old-format
+     * screen-dump, or new-format.
+     */
+    if (read_block(&tmp, 4, filep) < 0) {
+	returnWin(0);
+    }
+    /*
+     * If this is a new-format file, and we do not support it, give up.
+     */
+    if (!memcmp(&tmp, my_magic, 4)) {
+#if NCURSES_EXT_PUTWIN
+	if (read_win(&tmp, filep) < 0)
+#endif
+	    returnWin(0);
+    } else if (read_block(((char *) &tmp) + 4, sizeof(WINDOW) - 4, filep) < 0) {
+	returnWin(0);
+    } else {
+	old_format = TRUE;
+    }
+
+    /*
+     * Check the window-size:
+     */
+    if (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);
+	nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
+					tmp._maxy + 1,
+					tmp._maxx + 1);
     } else {
-	nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0);
+	nwin = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
+					tmp._maxy + 1,
+					tmp._maxx + 1, 0, 0);
     }
 
     /*
@@ -67,6 +546,8 @@
      * made sense is probably gone.
      */
     if (nwin != 0) {
+	size_t linesize = sizeof(NCURSES_CH_T) * (size_t) (tmp._maxx + 1);
+
 	nwin->_curx = tmp._curx;
 	nwin->_cury = tmp._cury;
 	nwin->_maxy = tmp._maxy;
@@ -96,40 +577,306 @@
 	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)) {
+	if (old_format) {
+	    T(("reading old-format screen dump"));
+	    for (n = 0; n <= nwin->_maxy; n++) {
+		if (read_block(nwin->_line[n].text, linesize, filep) < 0) {
+		    delwin(nwin);
+		    returnWin(0);
+		}
+	    }
+	}
+#if NCURSES_EXT_PUTWIN
+	else {
+	    char *txt;
+	    bool success = TRUE;
+	    NCURSES_CH_T prior = blank;
+
+	    T(("reading new-format screen dump"));
+	    for (n = 0; n <= nwin->_maxy; n++) {
+		long row;
+		char *next;
+
+		if ((txt = read_txt(filep)) == 0) {
+		    T(("...failed to read string for row %d", n + 1));
+		    success = FALSE;
+		    break;
+		}
+		row = strtol(txt, &next, 10);
+		if (row != (n + 1) || *next != ':') {
+		    T(("...failed to read row-number %d", n + 1));
+		    success = FALSE;
+		    break;
+		}
+
+		if (read_row(++next, &prior, nwin->_line[n].text, tmp._maxx
+			     + 1) < 0) {
+		    T(("...failed to read cells for row %d", n + 1));
+		    success = FALSE;
+		    break;
+		}
+		free(txt);
+		txt = 0;
+	    }
+
+	    if (!success) {
+		free(txt);
 		delwin(nwin);
 		returnWin(0);
 	    }
 	}
+#endif
 	touchwin(nwin);
     }
     returnWin(nwin);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(WINDOW *)
+getwin(FILE *filep)
+{
+    return NCURSES_SP_NAME(getwin) (CURRENT_SCREEN, filep);
+}
+#endif
+
+#if NCURSES_EXT_PUTWIN
+static void
+encode_attr(char *target, attr_t source, attr_t prior)
+{
+    source &= ~A_CHARTEXT;
+    prior &= ~A_CHARTEXT;
+
+    *target = '\0';
+    if (source != prior) {
+	size_t n;
+	bool first = TRUE;
+
+	*target++ = MARKER;
+	*target++ = L_CURL;
+
+	for (n = 0; n < SIZEOF(scr_attrs); ++n) {
+	    if ((source & scr_attrs[n].attr) != 0 ||
+		((source & ALL_BUT_COLOR) == 0 &&
+		 (scr_attrs[n].attr == A_NORMAL))) {
+		if (first) {
+		    first = FALSE;
+		} else {
+		    *target++ = '|';
+		}
+		strcpy(target, scr_attrs[n].name);
+		target += strlen(target);
+	    }
+	}
+	if ((source & A_COLOR) != (prior & A_COLOR)) {
+	    if (!first)
+		*target++ = '|';
+	    sprintf(target, "C%d", PAIR_NUMBER((int) source));
+	    target += strlen(target);
+	}
+
+	*target++ = R_CURL;
+	*target = '\0';
+    }
+}
+
+static void
+encode_cell(char *target, CARG_CH_T source, CARG_CH_T previous)
+{
+#if NCURSES_WIDECHAR
+    size_t n;
+
+    *target = '\0';
+    if (previous->attr != source->attr) {
+	encode_attr(target, source->attr, previous->attr);
+    }
+    target += strlen(target);
+#if NCURSES_EXT_COLORS
+    if (previous->ext_color != source->ext_color) {
+	sprintf(target, "%c%cC%d%c", MARKER, L_CURL, source->ext_color, R_CURL);
+    }
+#endif
+    for (n = 0; n < SIZEOF(source->chars); ++n) {
+	unsigned uch = (unsigned) source->chars[n];
+	if (uch == 0)
+	    continue;
+	if (n) {
+	    *target++ = MARKER;
+	    *target++ = APPEND;
+	}
+	*target++ = MARKER;
+	if (uch > 0xffff) {
+	    sprintf(target, "U%08x", uch);
+	} else if (uch > 0xff) {
+	    sprintf(target, "u%04x", uch);
+	} else if (uch < 32 || uch >= 127) {
+	    sprintf(target, "%03o", uch & 0xff);
+	} else {
+	    switch (uch) {
+	    case ' ':
+		strcpy(target, "s");
+		break;
+	    case MARKER:
+		*target++ = MARKER;
+		*target = '\0';
+		break;
+	    default:
+		sprintf(--target, "%c", uch);
+		break;
+	    }
+	}
+	target += strlen(target);
+    }
+#else
+    chtype ch = CharOfD(source);
+
+    *target = '\0';
+    if (AttrOfD(previous) != AttrOfD(source)) {
+	encode_attr(target, AttrOfD(source), AttrOfD(previous));
+    }
+    target += strlen(target);
+    *target++ = MARKER;
+    if (ch < 32 || ch >= 127) {
+	sprintf(target, "%03o", UChar(ch));
+    } else {
+	switch (ch) {
+	case ' ':
+	    strcpy(target, "s");
+	    break;
+	case MARKER:
+	    *target++ = MARKER;
+	    *target = '\0';
+	    break;
+	default:
+	    sprintf(--target, "%c", UChar(ch));
+	    break;
+	}
+    }
+    target += strlen(target);
+#endif
+}
+#endif
+
 NCURSES_EXPORT(int)
 putwin(WINDOW *win, FILE *filep)
 {
     int code = ERR;
-    int n;
+    int y;
 
-    T((T_CALLED("putwin(%p,%p)"), win, filep));
+    T((T_CALLED("putwin(%p,%p)"), (void *) win, (void *) filep));
 
+#if NCURSES_EXT_PUTWIN
+    if (win != 0) {
+	const char *version = curses_version();
+	char buffer[1024];
+	NCURSES_CH_T last_cell;
+
+	memset(&last_cell, 0, sizeof(last_cell));
+
+	clearerr(filep);
+
+	/*
+	 * Our magic number is technically nonprinting, but aside from that,
+	 * all of the file is printable ASCII.
+	 */
+#define PUTS(s) if (fputs(s, filep) == EOF || ferror(filep)) returnCode(code)
+	PUTS(my_magic);
+	PUTS(version);
+	PUTS("\n");
+	for (y = 0; y < (int) SIZEOF(scr_params); ++y) {
+	    const char *name = scr_params[y].name;
+	    const char *data = (char *) win + scr_params[y].offset;
+	    const void *dp = (const void *) data;
+
+	    *buffer = '\0';
+	    if (!strncmp(name, "_pad.", 5) && !(win->_flags & _ISPAD)) {
+		continue;
+	    }
+	    switch (scr_params[y].type) {
+	    case pATTR:
+		encode_attr(buffer, (*(const attr_t *) dp) & ~A_CHARTEXT, A_NORMAL);
+		break;
+	    case pBOOL:
+		if (!(*(const bool *) data)) {
+		    continue;
+		}
+		strcpy(buffer, name);
+		name = "flag";
+		break;
+	    case pCHAR:
+		encode_attr(buffer, *(const attr_t *) dp, A_NORMAL);
+		break;
+	    case pINT:
+		if (!(*(const int *) dp))
+		    continue;
+		sprintf(buffer, "%d", *(const int *) dp);
+		break;
+	    case pSHORT:
+		if (!(*(const short *) dp))
+		    continue;
+		sprintf(buffer, "%d", *(const short *) dp);
+		break;
+	    case pSIZE:
+		if (!(*(const NCURSES_SIZE_T *) dp))
+		    continue;
+		sprintf(buffer, "%d", *(const NCURSES_SIZE_T *) dp);
+		break;
+#if NCURSES_WIDECHAR
+	    case pCCHAR:
+		encode_cell(buffer, (CARG_CH_T) dp, CHREF(last_cell));
+		break;
+#endif
+	    }
+	    /*
+	     * Only write non-default data.
+	     */
+	    if (*buffer != '\0') {
+		if (fprintf(filep, "%s=%s\n", name, buffer) <= 0
+		    || ferror(filep))
+		    returnCode(code);
+	    }
+	}
+	/* Write row-data */
+	fprintf(filep, "rows:\n");
+	for (y = 0; y <= win->_maxy; y++) {
+	    NCURSES_CH_T *data = win->_line[y].text;
+	    int x;
+	    if (fprintf(filep, "%d:", y + 1) <= 0
+		|| ferror(filep))
+		returnCode(code);
+	    for (x = 0; x <= win->_maxx; x++) {
+#if NCURSES_WIDECHAR
+		int len = wcwidth(data[x].chars[0]);
+		encode_cell(buffer, CHREF(data[x]), CHREF(last_cell));
+		last_cell = data[x];
+		PUTS(buffer);
+		if (len > 1)
+		    x += (len - 1);
+#else
+		encode_cell(buffer, CHREF(data[x]), CHREF(last_cell));
+		last_cell = data[x];
+		PUTS(buffer);
+#endif
+	    }
+	    PUTS("\n");
+	}
+    }
+#else
+    /*
+     * This is the original putwin():
+     * A straight binary dump is simple, but its format can depend on whether
+     * ncurses is compiled with wide-character support, and also may depend
+     * on the version of ncurses, e.g., if the WINDOW structure is extended.
+     */
     if (win != 0) {
 	size_t len = (size_t) (win->_maxx + 1);
 
 	clearerr(filep);
-	if (fwrite(win, sizeof(WINDOW), 1, filep) != 1
+	if (fwrite(win, sizeof(WINDOW), (size_t) 1, filep) != 1
 	    || ferror(filep))
 	      returnCode(code);
 
-	for (n = 0; n <= win->_maxy; n++) {
-	    if (fwrite(win->_line[n].text,
+	for (y = 0; y <= win->_maxy; y++) {
+	    if (fwrite(win->_line[y].text,
 		       sizeof(NCURSES_CH_T), len, filep) != len
 		|| ferror(filep)) {
 		returnCode(code);
@@ -137,84 +884,123 @@
 	}
 	code = OK;
     }
+#endif
     returnCode(code);
 }
 
 NCURSES_EXPORT(int)
-scr_restore(const char *file)
+NCURSES_SP_NAME(scr_restore) (NCURSES_SP_DCLx const char *file)
 {
     FILE *fp = 0;
+    int code = ERR;
 
-    T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file)));
+    T((T_CALLED("scr_restore(%p,%s)"), (void *) SP_PARM, _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 (_nc_access(file, R_OK) >= 0
+	&& (fp = fopen(file, "rb")) != 0) {
+	delwin(NewScreen(SP_PARM));
+	NewScreen(SP_PARM) = getwin(fp);
 #if !USE_REENTRANT
-	newscr = SP->_newscr;
+	newscr = NewScreen(SP_PARM);
 #endif
 	(void) fclose(fp);
-	returnCode(OK);
+	if (NewScreen(SP_PARM) != 0) {
+	    code = OK;
+	}
     }
+    returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+scr_restore(const char *file)
+{
+    return NCURSES_SP_NAME(scr_restore) (CURRENT_SCREEN, file);
+}
+#endif
+
 NCURSES_EXPORT(int)
 scr_dump(const char *file)
 {
+    int result;
     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);
+	result = ERR;
     } else {
 	(void) putwin(newscr, fp);
 	(void) fclose(fp);
-	returnCode(OK);
+	result = OK;
     }
+    returnCode(result);
 }
 
 NCURSES_EXPORT(int)
+NCURSES_SP_NAME(scr_init) (NCURSES_SP_DCLx const char *file)
+{
+    FILE *fp = 0;
+    int code = ERR;
+
+    T((T_CALLED("scr_init(%p,%s)"), (void *) SP_PARM, _nc_visbuf(file)));
+
+    if (SP_PARM != 0 &&
+#ifdef USE_TERM_DRIVER
+	InfoOf(SP_PARM).caninit
+#else
+	!(exit_ca_mode && non_rev_rmcup)
+#endif
+	) {
+	if (_nc_access(file, R_OK) >= 0
+	    && (fp = fopen(file, "rb")) != 0) {
+	    delwin(CurScreen(SP_PARM));
+	    CurScreen(SP_PARM) = getwin(fp);
+#if !USE_REENTRANT
+	    curscr = CurScreen(SP_PARM);
+#endif
+	    (void) fclose(fp);
+	    if (CurScreen(SP_PARM) != 0) {
+		code = OK;
+	    }
+	}
+    }
+    returnCode(code);
+}
+
+#if NCURSES_SP_FUNCS
+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;
+    return NCURSES_SP_NAME(scr_init) (CURRENT_SCREEN, file);
+}
 #endif
-	(void) fclose(fp);
-	returnCode(OK);
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(scr_set) (NCURSES_SP_DCLx const char *file)
+{
+    int code = ERR;
+
+    T((T_CALLED("scr_set(%p,%s)"), (void *) SP_PARM, _nc_visbuf(file)));
+
+    if (NCURSES_SP_NAME(scr_init) (NCURSES_SP_ARGx file) == OK) {
+	delwin(NewScreen(SP_PARM));
+	NewScreen(SP_PARM) = dupwin(curscr);
+#if !USE_REENTRANT
+	newscr = NewScreen(SP_PARM);
+#endif
+	if (NewScreen(SP_PARM) != 0) {
+	    code = OK;
+	}
     }
+    returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
 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);
-    }
+    return NCURSES_SP_NAME(scr_set) (CURRENT_SCREEN, file);
 }
+#endif
diff --git a/ncurses/base/lib_scroll.c b/ncurses/base/lib_scroll.c
index ac85bd5..8684e25 100644
--- a/ncurses/base/lib_scroll.c
+++ b/ncurses/base/lib_scroll.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -43,22 +43,22 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_scroll.c,v 1.26 2006/10/14 20:46:08 tom Exp $")
+MODULE_ID("$Id: lib_scroll.c,v 1.29 2011/10/22 16:34:50 tom Exp $")
 
 NCURSES_EXPORT(void)
 _nc_scroll_window(WINDOW *win,
 		  int const n,
-		  NCURSES_SIZE_T const top,
-		  NCURSES_SIZE_T const bottom,
+		  int const top,
+		  int 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));
+    size_t to_copy = (sizeof(NCURSES_CH_T) * (size_t) (win->_maxx + 1));
 
     TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %ld, %ld)",
-		    win, n, (long) top, (long) bottom));
+		    (void *) win, n, (long) top, (long) bottom));
 
     if (top < 0
 	|| bottom < top
@@ -135,7 +135,7 @@
 NCURSES_EXPORT(int)
 wscrl(WINDOW *win, int n)
 {
-    T((T_CALLED("wscrl(%p,%d)"), win, n));
+    T((T_CALLED("wscrl(%p,%d)"), (void *) win, n));
 
     if (!win || !win->_scroll) {
 	TR(TRACE_MOVE, ("...scrollok is false"));
diff --git a/ncurses/base/lib_scrollok.c b/ncurses/base/lib_scrollok.c
index f6b3025..6a698a3 100644
--- a/ncurses/base/lib_scrollok.c
+++ b/ncurses/base/lib_scrollok.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,12 +40,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_scrollok.c,v 1.4 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_scrollok.c,v 1.5 2009/10/24 22:35:38 tom Exp $")
 
 NCURSES_EXPORT(int)
 scrollok(WINDOW *win, bool flag)
 {
-    T((T_CALLED("scrollok(%p,%d)"), win, flag));
+    T((T_CALLED("scrollok(%p,%d)"), (void *) win, flag));
 
     if (win) {
 	win->_scroll = flag;
diff --git a/ncurses/base/lib_scrreg.c b/ncurses/base/lib_scrreg.c
index c85d60f..546fbc1 100644
--- a/ncurses/base/lib_scrreg.c
+++ b/ncurses/base/lib_scrreg.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,12 +40,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_scrreg.c,v 1.10 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_scrreg.c,v 1.11 2009/10/24 22:35:28 tom Exp $")
 
 NCURSES_EXPORT(int)
 wsetscrreg(WINDOW *win, int top, int bottom)
 {
-    T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom));
+    T((T_CALLED("wsetscrreg(%p,%d,%d)"), (void *) win, top, bottom));
 
     if (win &&
 	top >= 0 && top <= win->_maxy &&
diff --git a/ncurses/base/lib_set_term.c b/ncurses/base/lib_set_term.c
index aff432b..f787a88 100644
--- a/ncurses/base/lib_set_term.c
+++ b/ncurses/base/lib_set_term.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -40,11 +41,21 @@
 */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_set_term.c,v 1.153 2015/08/07 23:57:58 tom Exp $")
+
+#ifdef USE_TERM_DRIVER
+#define MaxColors      InfoOf(sp).maxcolors
+#define NumLabels      InfoOf(sp).numlabels
+#else
+#define MaxColors      max_colors
+#define NumLabels      num_labels
+#endif
 
 NCURSES_EXPORT(SCREEN *)
 set_term(SCREEN *screenp)
@@ -52,25 +63,25 @@
     SCREEN *oldSP;
     SCREEN *newSP;
 
-    T((T_CALLED("set_term(%p)"), screenp));
+    T((T_CALLED("set_term(%p)"), (void *) screenp));
 
     _nc_lock_global(curses);
 
-    oldSP = SP;
+    oldSP = CURRENT_SCREEN;
     _nc_set_screen(screenp);
-    newSP = SP;
+    newSP = screenp;
 
     if (newSP != 0) {
-	set_curterm(newSP->_term);
+	TINFO_SET_CURTERM(newSP, newSP->_term);
 #if !USE_REENTRANT
-	curscr = newSP->_curscr;
-	newscr = newSP->_newscr;
-	stdscr = newSP->_stdscr;
+	curscr = CurScreen(newSP);
+	newscr = NewScreen(newSP);
+	stdscr = StdScreen(newSP);
 	COLORS = newSP->_color_count;
 	COLOR_PAIRS = newSP->_pair_count;
 #endif
     } else {
-	set_curterm(0);
+	TINFO_SET_CURTERM(oldSP, 0);
 #if !USE_REENTRANT
 	curscr = 0;
 	newscr = 0;
@@ -82,7 +93,7 @@
 
     _nc_unlock_global(curses);
 
-    T((T_RETURN("%p"), oldSP));
+    T((T_RETURN("%p"), (void *) oldSP));
     return (oldSP);
 }
 
@@ -106,7 +117,7 @@
     for (each_screen(temp)) {
 	if (temp == sp) {
 	    if (last)
-		last = sp->_next_screen;
+		last->_next_screen = sp->_next_screen;
 	    else
 		_nc_screen_chain = sp->_next_screen;
 	    result = TRUE;
@@ -125,14 +136,27 @@
 {
     int i;
 
-    T((T_CALLED("delscreen(%p)"), sp));
+    T((T_CALLED("delscreen(%p)"), (void *) sp));
 
     _nc_lock_global(curses);
     if (delink_screen(sp)) {
+#ifdef USE_SP_RIPOFF
+	ripoff_t *rop;
+	if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) {
+	    for (rop = safe_ripoff_stack;
+		 rop != safe_ripoff_sp && (rop - safe_ripoff_stack) < N_RIPS;
+		 rop++) {
+		if (rop->win) {
+		    (void) delwin(rop->win);
+		    rop->win = 0;
+		}
+	    }
+	}
+#endif
 
-	(void) _nc_freewin(sp->_curscr);
-	(void) _nc_freewin(sp->_newscr);
-	(void) _nc_freewin(sp->_stdscr);
+	(void) _nc_freewin(CurScreen(sp));
+	(void) _nc_freewin(NewScreen(sp));
+	(void) _nc_freewin(StdScreen(sp));
 
 	if (sp->_slk != 0) {
 	    if (sp->_slk->ent != 0) {
@@ -164,19 +188,9 @@
 	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);
+	NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
+	NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx sp->_term);
+	FreeIfNeeded(sp->out_buffer);
 	free(sp);
 
 	/*
@@ -184,7 +198,7 @@
 	 * application might try to use (except cur_term, which may have
 	 * multiple references in different screens).
 	 */
-	if (sp == SP) {
+	if (sp == CURRENT_SCREEN) {
 #if !USE_REENTRANT
 	    curscr = 0;
 	    newscr = 0;
@@ -193,6 +207,12 @@
 	    COLOR_PAIRS = 0;
 #endif
 	    _nc_set_screen(0);
+#if USE_WIDEC_SUPPORT
+	    if (SP == 0) {
+		FreeIfNeeded(_nc_wacs);
+		_nc_wacs = 0;
+	    }
+#endif
 	}
     }
     _nc_unlock_global(curses);
@@ -229,13 +249,14 @@
 }
 
 #if NCURSES_EXT_FUNCS && USE_COLORFGBG
-static char *
-extract_fgbg(char *src, int *result)
+static const char *
+extract_fgbg(const char *src, int *result)
 {
-    char *dst = 0;
-    long value = strtol(src, &dst, 0);
+    const char *dst = 0;
+    char *tmp = 0;
+    long value = strtol(src, &tmp, 0);
 
-    if (dst == 0) {
+    if ((dst = tmp) == 0) {
 	dst = src;
     } else if (value >= 0) {
 	*result = value;
@@ -248,50 +269,98 @@
 }
 #endif
 
+#define ReturnScreenError() do { _nc_set_screen(0); \
+                            returnCode(ERR); } while (0)
+
 /* OS-independent screen initializations */
 NCURSES_EXPORT(int)
-_nc_setupscreen(int slines GCC_UNUSED,
-		int scolumns GCC_UNUSED,
-		FILE *output,
-		bool filtered,
-		int slk_format)
+NCURSES_SP_NAME(_nc_setupscreen) (
+#if NCURSES_SP_FUNCS
+				     SCREEN **spp,
+#endif
+				     int slines,
+				     int scolumns,
+				     FILE *output,
+				     int filtered,
+				     int slk_format)
 {
     char *env;
     int bottom_stolen = 0;
-    bool support_cookies = USE_XMC_SUPPORT;
     ripoff_t *rop;
+    SCREEN *sp;
+#ifndef USE_TERM_DRIVER
+    bool support_cookies = USE_XMC_SUPPORT;
+#endif
 
     T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
-       slines, scolumns, output, filtered, slk_format));
+       slines, scolumns, (void *) output, filtered, slk_format));
 
-    assert(SP == 0);		/* has been reset in newterm() ! */
+    assert(CURRENT_SCREEN == 0);	/* has been reset in newterm() ! */
+
+#if NCURSES_SP_FUNCS
+    assert(spp != 0);
+    sp = *spp;
+
+    if (!sp) {
+	sp = _nc_alloc_screen_sp();
+	*spp = sp;
+    }
+    if (!sp
+	|| ((sp->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0)
+	|| ((sp->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) {
+	ReturnScreenError();
+    }
+
+    T(("created SP %p", (void *) sp));
+    sp->_next_screen = _nc_screen_chain;
+    _nc_screen_chain = sp;
+
+    if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) {
+	ReturnScreenError();
+    }
+#else
     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;
+    T(("created SP %p", (void *) SP));
 
-    if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0)
+    sp = SP;			/* fixup so SET_LINES and SET_COLS works */
+    sp->_next_screen = _nc_screen_chain;
+    _nc_screen_chain = sp;
+
+    if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0)
 	returnCode(ERR);
+#endif
 
     /*
      * We should always check the screensize, just in case.
      */
-    _nc_get_screensize(SP, &slines, &scolumns);
+    _nc_set_screen(sp);
+    sp->_term = cur_term;
+#ifdef USE_TERM_DRIVER
+    TCBOf(sp)->csp = sp;
+    _nc_get_screensize(sp, sp->_term, &slines, &scolumns);
+#else
+    _nc_get_screensize(sp, &slines, &scolumns);
+#endif
     SET_LINES(slines);
     SET_COLS(scolumns);
-    T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));
 
-    SP->_filtered = filtered;
+    T((T_CREATE("screen %s %dx%d"),
+       NCURSES_SP_NAME(termname) (NCURSES_SP_ARG), slines, scolumns));
+
+    sp->_filtered = filtered;
 
     /* implement filter mode */
     if (filtered) {
 	slines = 1;
 	SET_LINES(slines);
+#ifdef USE_TERM_DRIVER
+	CallDriver(sp, td_setfilter);
+#else
 	clear_screen = 0;
 	cursor_down = parm_down_cursor = 0;
 	cursor_address = 0;
@@ -299,34 +368,33 @@
 	row_address = 0;
 
 	cursor_home = carriage_return;
-	T(("filter screensize %dx%d", LINES, COLS));
+#endif
+	T(("filter screensize %dx%d", slines, scolumns));
     }
 #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 */
+    NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_ARGx output, TRUE);
+    sp->_lines = (NCURSES_SIZE_T) slines;
+    sp->_lines_avail = (NCURSES_SIZE_T) slines;
+    sp->_columns = (NCURSES_SIZE_T) scolumns;
 
-    SetNoPadding(SP);
+    fflush(output);
+    sp->_ofd = output ? fileno(output) : -1;
+    sp->_ofp = output;
+    sp->out_limit = (size_t) ((2 + slines) * (6 + scolumns));
+    if ((sp->out_buffer = malloc(sp->out_limit)) == 0)
+	sp->out_limit = 0;
+    sp->out_inuse = 0;
+
+    SP_PRE_INIT(sp);
+    SetNoPadding(sp);
 
 #if NCURSES_EXT_FUNCS
-    SP->_default_color = FALSE;
-    SP->_has_sgr_39_49 = FALSE;
+    sp->_default_color = FALSE;
+    sp->_has_sgr_39_49 = FALSE;
 
     /*
      * Set our assumption of the terminal's default foreground and background
@@ -348,11 +416,11 @@
      * 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;
+    sp->_default_fg = COLOR_WHITE;
+    sp->_default_bg = COLOR_BLACK;
 #else
-    SP->_default_fg = C_MASK;
-    SP->_default_bg = C_MASK;
+    sp->_default_fg = C_MASK;
+    sp->_default_bg = C_MASK;
 #endif
 
     /*
@@ -364,14 +432,14 @@
 	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;
+	    sp->_default_fg = ((fg >= 0 && fg < MaxColors) ? fg : C_MASK);
 	    if (count >= 3) {
-		SP->_default_bg = (bg >= 0 && bg < max_colors) ? bg : C_MASK;
+		sp->_default_bg = ((bg >= 0 && bg < MaxColors) ? bg : C_MASK);
 	    }
 	    TR(TRACE_CHARPUT | TRACE_MOVE,
 	       ("from environment assumed fg=%d, bg=%d",
-		SP->_default_fg,
-		SP->_default_bg));
+		sp->_default_fg,
+		sp->_default_bg));
 	}
     }
 #if USE_COLORFGBG
@@ -382,50 +450,53 @@
      * decide later if it is worth having default attributes as well.
      */
     if (getenv("COLORFGBG") != 0) {
-	char *p = getenv("COLORFGBG");
+	const 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));
+	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));
+	    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) {
+					sp->_default_fg, sp->_default_bg));
+	if (sp->_default_fg >= MaxColors) {
 	    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";
+		set_a_foreground = strdup("\033[3%?%p1%{8}%>%t9%e%p1%d%;m");
 	    } else {
-		SP->_default_fg %= max_colors;
+		sp->_default_fg %= MaxColors;
 	    }
 	}
-	if (SP->_default_bg >= max_colors) {
+	if (sp->_default_bg >= MaxColors) {
 	    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";
+		set_a_background = strdup("\033[4%?%p1%{8}%>%t9%e%p1%d%;m");
 	    } else {
-		SP->_default_bg %= max_colors;
+		sp->_default_bg %= MaxColors;
 	    }
 	}
     }
 #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;
+    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;
+    sp->_ok_attributes = NCURSES_SP_NAME(termattrs) (NCURSES_SP_ARG);
+    if (NCURSES_SP_NAME(has_colors) (NCURSES_SP_ARG)) {
+	sp->_ok_attributes |= A_COLOR;
     }
+#ifdef USE_TERM_DRIVER
+    _nc_cookie_init(sp);
+#else
 #if USE_XMC_SUPPORT
     /*
      * If we have no magic-cookie support compiled-in, or if it is suppressed
@@ -444,16 +515,7 @@
 
     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
-	    );
+	sp->_xmc_triggers = sp->_ok_attributes & XMC_CONFLICT;
 #if 0
 	/*
 	 * We "should" treat colors as an attribute.  The wyse350 (and its
@@ -461,12 +523,12 @@
 	 * cookies.
 	 */
 	if (has_colors()) {
-	    SP->_xmc_triggers |= A_COLOR;
+	    sp->_xmc_triggers |= A_COLOR;
 	}
 #endif
-	SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~(A_BOLD);
+	sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
 
-	T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
+	T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
 	/*
 	 * Supporting line-drawing may be possible.  But make the regular
 	 * video attributes work first.
@@ -506,7 +568,7 @@
 
     /* 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)) {
+    if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp->_term)) {
 	acs_chars = NULL;
 	ena_acs = NULL;
 	enter_alt_charset_mode = NULL;
@@ -514,134 +576,202 @@
 	set_attributes = NULL;
     }
 #endif
-    _nc_init_acs();
-#if USE_WIDEC_SUPPORT
-    _nc_init_wacs();
+#endif
 
-    SP->_screen_acs_fix = (_nc_unicode_locale()
-			   && _nc_locale_breaks_acs(cur_term));
+    NCURSES_SP_NAME(_nc_init_acs) (NCURSES_SP_ARG);
+#if USE_WIDEC_SUPPORT
+    sp->_screen_unicode = _nc_unicode_locale();
+    if (_nc_wacs == 0) {
+	_nc_init_wacs();
+    }
+    if (_nc_wacs == 0) {
+	ReturnScreenError();
+    }
+
+    sp->_screen_acs_fix = (sp->_screen_unicode
+			   && _nc_locale_breaks_acs(sp->_term));
 #endif
     env = _nc_get_locale();
-    SP->_legacy_coding = ((env == 0)
+    sp->_legacy_coding = ((env == 0)
 			  || !strcmp(env, "C")
 			  || !strcmp(env, "POSIX"));
-    T(("legacy-coding %d", SP->_legacy_coding));
+    T(("legacy-coding %d", sp->_legacy_coding));
 
-    _nc_idcok = TRUE;
-    _nc_idlok = FALSE;
+    sp->_nc_sp_idcok = TRUE;
+    sp->_nc_sp_idlok = FALSE;
 
-    SP->oldhash = 0;
-    SP->newhash = 0;
+    sp->oldhash = 0;
+    sp->newhash = 0;
 
     T(("creating newscr"));
-    if ((SP->_newscr = newwin(slines, scolumns, 0, 0)) == 0)
-	returnCode(ERR);
-
+    NewScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx slines, scolumns,
+					     0, 0);
+    if (NewScreen(sp) == 0) {
+	ReturnScreenError();
+    }
     T(("creating curscr"));
-    if ((SP->_curscr = newwin(slines, scolumns, 0, 0)) == 0)
-	returnCode(ERR);
-
+    CurScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx slines, scolumns,
+					     0, 0);
+    if (CurScreen(sp) == 0) {
+	ReturnScreenError();
+    }
 #if !USE_REENTRANT
-    newscr = SP->_newscr;
-    curscr = SP->_curscr;
+    newscr = NewScreen(sp);
+    curscr = CurScreen(sp);
 #endif
 #if USE_SIZECHANGE
-    SP->_resize = resizeterm;
+    sp->_resize = NCURSES_SP_NAME(resizeterm);
+    sp->_ungetch = safe_ungetch;
 #endif
 
-    newscr->_clear = TRUE;
-    curscr->_clear = FALSE;
+    NewScreen(sp)->_clear = TRUE;
+    CurScreen(sp)->_clear = FALSE;
 
-    def_shell_mode();
-    def_prog_mode();
+    NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_ARG);
+    NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_ARG);
 
-    for (rop = ripoff_stack;
-	 rop != ripoff_sp && (rop - ripoff_stack) < N_RIPS;
-	 rop++) {
+    if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) {
+	for (rop = safe_ripoff_stack;
+	     rop != safe_ripoff_sp && (rop - safe_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 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 (!(NumLabels <= 0 || !SLK_STDFMT(slk_format))) {
+		    continue;
+		}
 	    }
-	    if (rop->line < 0)
-		bottom_stolen += count;
-	    else
-		SP->_topstolen += count;
-	    SP->_lines_avail -= count;
+	    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 = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
+					     count, scolumns,
+					     ((rop->line < 0)
+					      ? sp->_lines_avail - count
+					      : 0),
+					     0);
+		if (w) {
+		    rop->win = w;
+		    rop->hook(w, scolumns);
+		} else {
+		    ReturnScreenError();
+		}
+		if (rop->line < 0) {
+		    bottom_stolen += count;
+		} else {
+		    sp->_topstolen = (NCURSES_SIZE_T) (sp->_topstolen + count);
+		}
+		sp->_lines_avail = (NCURSES_SIZE_T) (sp->_lines_avail - count);
+	    }
 	}
+	/* reset the stack */
+	safe_ripoff_sp = safe_ripoff_stack;
     }
-    /* 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);
+    assert((sp->_lines_avail + sp->_topstolen + bottom_stolen) == slines);
+    if ((StdScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
+						  sp->_lines_avail,
+						  scolumns, 0, 0)) == 0) {
+	ReturnScreenError();
+    }
+    SET_LINES(sp->_lines_avail);
 #if !USE_REENTRANT
-    stdscr = SP->_stdscr;
+    stdscr = StdScreen(sp);
 #endif
-
+    sp->_prescreen = FALSE;
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_setupscreen(int slines GCC_UNUSED,
+		int scolumns GCC_UNUSED,
+		FILE *output,
+		int filtered,
+		int slk_format)
+{
+    SCREEN *sp = 0;
+    int rc = NCURSES_SP_NAME(_nc_setupscreen) (&sp,
+					       slines,
+					       scolumns,
+					       output,
+					       filtered,
+					       slk_format);
+    if (rc != OK)
+	_nc_set_screen(0);
+    return rc;
+}
+#endif
+
 /*
  * 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))
+NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_DCLx
+				 int line,
+				 int (*init) (WINDOW *, int))
 {
-    T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init));
+    int code = ERR;
 
-    if (line != 0) {
+    START_TRACE();
+    T((T_CALLED("ripoffline(%p,%d,%p)"), (void *) SP_PARM, line, init));
 
-	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++;
+#if NCURSES_SP_FUNCS
+    if (SP_PARM != 0 && SP_PARM->_prescreen)
+#endif
+    {
+	if (line == 0) {
+	    code = OK;
+	} else {
+	    if (safe_ripoff_sp == 0)
+		safe_ripoff_sp = safe_ripoff_stack;
+	    if (safe_ripoff_sp < safe_ripoff_stack + N_RIPS) {
+		safe_ripoff_sp->line = line;
+		safe_ripoff_sp->hook = init;
+		(safe_ripoff_sp)++;
+		code = OK;
+	    }
+	}
     }
 
-    returnCode(OK);
+    returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_ripoffline(int line, int (*init) (WINDOW *, int))
+{
+    return NCURSES_SP_NAME(_nc_ripoffline) (CURRENT_SCREEN_PRE, line, init);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(ripoffline) (NCURSES_SP_DCLx
+			     int line,
+			     int (*init) (WINDOW *, int))
+{
+    START_TRACE();
+    return NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_ARGx
+					    (line < 0) ? -1 : 1,
+					    init);
+}
+
+#if NCURSES_SP_FUNCS
 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));
+    return NCURSES_SP_NAME(ripoffline) (CURRENT_SCREEN_PRE, line, init);
 }
+#endif
diff --git a/ncurses/base/lib_slk.c b/ncurses/base/lib_slk.c
index 662f7e4..84f17ae 100644
--- a/ncurses/base/lib_slk.c
+++ b/ncurses/base/lib_slk.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,26 +41,94 @@
  */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_slk.c,v 1.48 2011/03/05 21:21:52 tom Exp $")
+
+#ifdef USE_TERM_DRIVER
+#define NumLabels    InfoOf(SP_PARM).numlabels
+#define NoColorVideo InfoOf(SP_PARM).nocolorvideo
+#define LabelWidth   InfoOf(SP_PARM).labelwidth
+#define LabelHeight  InfoOf(SP_PARM).labelheight
+#else
+#define NumLabels    num_labels
+#define NoColorVideo no_color_video
+#define LabelWidth   label_width
+#define LabelHeight  label_height
+#endif
 
 /*
  * Free any memory related to soft labels, return an error.
  */
 static int
-slk_failed(void)
+slk_failed(NCURSES_SP_DCL0)
 {
-    if (SP->_slk) {
-	FreeIfNeeded(SP->_slk->ent);
-	free(SP->_slk);
-	SP->_slk = (SLK *) 0;
+    if ((0 != SP_PARM) && SP_PARM->_slk) {
+	FreeIfNeeded(SP_PARM->_slk->ent);
+	free(SP_PARM->_slk);
+	SP_PARM->_slk = (SLK *) 0;
     }
     return ERR;
 }
 
+NCURSES_EXPORT(int)
+_nc_format_slks(NCURSES_SP_DCLx int cols)
+{
+    int gap, i, x;
+    int max_length;
+
+    if (!SP_PARM || !SP_PARM->_slk)
+	return ERR;
+
+    max_length = SP_PARM->_slk->maxlen;
+    if (SP_PARM->slk_format >= 3) {	/* PC style */
+	gap = (cols - 3 * (3 + 4 * max_length)) / 2;
+
+	if (gap < 1)
+	    gap = 1;
+
+	for (i = x = 0; i < SP_PARM->_slk->maxlab; i++) {
+	    SP_PARM->_slk->ent[i].ent_x = x;
+	    x += max_length;
+	    x += (i == 3 || i == 7) ? gap : 1;
+	}
+    } else {
+	if (SP_PARM->slk_format == 2) {		/* 4-4 */
+	    gap = cols - (int) (SP_PARM->_slk->maxlab * max_length) - 6;
+
+	    if (gap < 1)
+		gap = 1;
+	    for (i = x = 0; i < SP_PARM->_slk->maxlab; i++) {
+		SP_PARM->_slk->ent[i].ent_x = x;
+		x += max_length;
+		x += (i == 3) ? gap : 1;
+	    }
+	} else {
+	    if (SP_PARM->slk_format == 1) {	/* 1 -> 3-2-3 */
+		gap = (cols - (SP_PARM->_slk->maxlab * max_length) - 5)
+		    / 2;
+
+		if (gap < 1)
+		    gap = 1;
+		for (i = x = 0; i < SP_PARM->_slk->maxlab; i++) {
+		    SP_PARM->_slk->ent[i].ent_x = x;
+		    x += max_length;
+		    x += (i == 2 || i == 4) ? gap : 1;
+		}
+	    } else {
+		return slk_failed(NCURSES_SP_ARG);
+	    }
+	}
+    }
+    SP_PARM->_slk->dirty = TRUE;
+
+    return OK;
+}
+
 /*
  * Initialize soft labels.
  * Called from newterm()
@@ -68,108 +136,90 @@
 NCURSES_EXPORT(int)
 _nc_slk_initialize(WINDOW *stwin, int cols)
 {
-    int i, x;
+    int i;
     int res = OK;
-    unsigned max_length;
+    size_t max_length;
+    SCREEN *sp;
+    int numlab;
 
     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)
+    assert(stwin);
+
+    sp = _nc_screen_of(stwin);
+    if (0 == sp)
 	returnCode(ERR);
 
-    SP->_slk->ent = NULL;
+    assert(TerminalOf(SP_PARM));
+
+    numlab = NumLabels;
+
+    if (SP_PARM->_slk) {	/* we did this already, so simply return */
+	returnCode(OK);
+    } else if ((SP_PARM->_slk = typeCalloc(SLK, 1)) == 0)
+	returnCode(ERR);
+
+    if (!SP_PARM->slk_format)
+	SP_PARM->slk_format = _nc_globals.slk_format;
 
     /*
      * 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);
+    if ((NoColorVideo & 1) == 0)
+	SetAttr(SP_PARM->_slk->attr, A_STANDOUT);
     else
-	SetAttr(SP->_slk->attr, A_REVERSE);
+	SetAttr(SP_PARM->_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);
+    SP_PARM->_slk->maxlab = (short) ((numlab > 0)
+				     ? numlab
+				     : MAX_SKEY(SP_PARM->slk_format));
+    SP_PARM->_slk->maxlen = (short) ((numlab > 0)
+				     ? LabelWidth * LabelHeight
+				     : MAX_SKEY_LEN(SP_PARM->slk_format));
+    SP_PARM->_slk->labcnt = (short) ((SP_PARM->_slk->maxlab < MAX_SKEY(SP_PARM->slk_format))
+				     ? MAX_SKEY(SP_PARM->slk_format)
+				     : SP_PARM->_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());
+    if (SP_PARM->_slk->maxlen <= 0
+	|| SP_PARM->_slk->labcnt <= 0
+	|| (SP_PARM->_slk->ent = typeCalloc(slk_ent,
+					    (size_t) SP_PARM->_slk->labcnt))
+	== NULL)
+	returnCode(slk_failed(NCURSES_SP_ARG));
 
-    max_length = SP->_slk->maxlen;
-    for (i = 0; i < SP->_slk->labcnt; i++) {
+    max_length = (size_t) SP_PARM->_slk->maxlen;
+    for (i = 0; i < SP_PARM->_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);
+	SP_PARM->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used);
+	if (SP_PARM->_slk->ent[i].ent_text == 0)
+	    returnCode(slk_failed(NCURSES_SP_ARG));
+	memset(SP_PARM->_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);
+	SP_PARM->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used);
+	if (SP_PARM->_slk->ent[i].form_text == 0)
+	    returnCode(slk_failed(NCURSES_SP_ARG));
 
-	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;
+	if (used > 1) {
+	    memset(SP_PARM->_slk->ent[i].form_text, ' ', used - 1);
 	}
-    } else {
-	if (_nc_globals.slk_format == 2) {	/* 4-4 */
-	    int gap = cols - (SP->_slk->maxlab * max_length) - 6;
+	SP_PARM->_slk->ent[i].form_text[used - 1] = '\0';
 
-	    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_PARM->_slk->ent[i].visible = (char) (i < SP_PARM->_slk->maxlab);
     }
-    SP->_slk->dirty = TRUE;
-    if ((SP->_slk->win = stwin) == NULL) {
-	returnCode(slk_failed());
+
+    res = _nc_format_slks(NCURSES_SP_ARGx cols);
+
+    if ((SP_PARM->_slk->win = stwin) == NULL) {
+	returnCode(slk_failed(NCURSES_SP_ARG));
     }
 
     /* 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);
 }
@@ -178,14 +228,24 @@
  * Restore the soft labels on the screen.
  */
 NCURSES_EXPORT(int)
+NCURSES_SP_NAME(slk_restore) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("slk_restore(%p)"), (void *) SP_PARM));
+
+    if (0 == SP_PARM)
+	returnCode(ERR);
+    if (SP_PARM->_slk == NULL)
+	returnCode(ERR);
+    SP_PARM->_slk->hidden = FALSE;
+    SP_PARM->_slk->dirty = TRUE;
+
+    returnCode(NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_ARG));
+}
+
+#if NCURSES_SP_FUNCS
+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());
+    return NCURSES_SP_NAME(slk_restore) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/base/lib_slkatr_set.c b/ncurses/base/lib_slkatr_set.c
index f83616b..a3132e9 100644
--- a/ncurses/base/lib_slkatr_set.c
+++ b/ncurses/base/lib_slkatr_set.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -28,7 +28,7 @@
 
 /****************************************************************************
  *  Author:  Juergen Pfeifer, 1998                                          *
- *     and:  Thomas E. Dickey 2005                                          *
+ *     and:  Thomas E. Dickey 2005-on                                       *
  ****************************************************************************/
 
 /*
@@ -38,22 +38,42 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkatr_set.c,v 1.10 2005/01/28 21:11:53 tom Exp $")
+MODULE_ID("$Id: lib_slkatr_set.c,v 1.15 2014/02/01 22:10:42 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_attr_set(const attr_t attr, short color_pair_number, void *opts)
+NCURSES_SP_NAME(slk_attr_set) (NCURSES_SP_DCLx
+			       const attr_t attr,
+			       NCURSES_PAIRS_T color_pair_number,
+			       void *opts)
 {
-    T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number));
+    int code = ERR;
 
-    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);
+    T((T_CALLED("slk_attr_set(%p,%s,%d)"),
+       (void *) SP_PARM,
+       _traceattr(attr),
+       (int) color_pair_number));
+
+    if (SP_PARM != 0
+	&& SP_PARM->_slk != 0
+	&& !opts
+	&& color_pair_number >= 0
+	&& color_pair_number < SP_PARM->_pair_limit) {
+	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
+	SetAttr(SP_PARM->_slk->attr, attr);
 	if (color_pair_number > 0) {
-	    SetPair(SP->_slk->attr, color_pair_number);
+	    SetPair(SP_PARM->_slk->attr, color_pair_number);
 	}
-	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
-	returnCode(OK);
-    } else
-	returnCode(ERR);
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
+	code = OK;
+    }
+    returnCode(code);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_attr_set(const attr_t attr, NCURSES_COLOR_T color_pair_number, void *opts)
+{
+    return NCURSES_SP_NAME(slk_attr_set) (CURRENT_SCREEN, attr,
+					  color_pair_number, opts);
+}
+#endif
diff --git a/ncurses/base/lib_slkatrof.c b/ncurses/base/lib_slkatrof.c
index 14b4c3b..bb980ab 100644
--- a/ncurses/base/lib_slkatrof.c
+++ b/ncurses/base/lib_slkatrof.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2005,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -38,21 +38,29 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkatrof.c,v 1.8 2005/01/08 23:01:32 tom Exp $")
+MODULE_ID("$Id: lib_slkatrof.c,v 1.11 2009/10/24 22:12:21 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_attroff(const chtype attr)
+NCURSES_SP_NAME(slk_attroff) (NCURSES_SP_DCLx const chtype attr)
 {
-    T((T_CALLED("slk_attroff(%s)"), _traceattr(attr)));
+    T((T_CALLED("slk_attroff(%p,%s)"), (void *) SP_PARM, _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 (SP_PARM != 0 && SP_PARM->_slk != 0) {
+	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
+	RemAttr(SP_PARM->_slk->attr, attr);
 	if ((attr & A_COLOR) != 0) {
-	    SetPair(SP->_slk->attr, 0);
+	    SetPair(SP_PARM->_slk->attr, 0);
 	}
-	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
 	returnCode(OK);
     } else
 	returnCode(ERR);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_attroff(const chtype attr)
+{
+    return NCURSES_SP_NAME(slk_attroff) (CURRENT_SCREEN, attr);
+}
+#endif
diff --git a/ncurses/base/lib_slkatron.c b/ncurses/base/lib_slkatron.c
index 90add86..bc2fb33 100644
--- a/ncurses/base/lib_slkatron.c
+++ b/ncurses/base/lib_slkatron.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -38,21 +38,29 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkatron.c,v 1.8 2005/01/08 23:02:01 tom Exp $")
+MODULE_ID("$Id: lib_slkatron.c,v 1.12 2010/03/31 23:38:02 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_attron(const chtype attr)
+NCURSES_SP_NAME(slk_attron) (NCURSES_SP_DCLx const chtype attr)
 {
-    T((T_CALLED("slk_attron(%s)"), _traceattr(attr)));
+    T((T_CALLED("slk_attron(%p,%s)"), (void *) SP_PARM, _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 (SP_PARM != 0 && SP_PARM->_slk != 0) {
+	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
+	AddAttr(SP_PARM->_slk->attr, attr);
 	if ((attr & A_COLOR) != 0) {
-	    SetPair(SP->_slk->attr, PAIR_NUMBER(attr));
+	    SetPair(SP_PARM->_slk->attr, PairNumber(attr));
 	}
-	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
 	returnCode(OK);
     } else
 	returnCode(ERR);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_attron(const chtype attr)
+{
+    return NCURSES_SP_NAME(slk_attron) (CURRENT_SCREEN, attr);
+}
+#endif
diff --git a/ncurses/base/lib_slkatrset.c b/ncurses/base/lib_slkatrset.c
index 8da9981..544b8d0 100644
--- a/ncurses/base/lib_slkatrset.c
+++ b/ncurses/base/lib_slkatrset.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2005,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -38,16 +38,24 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkatrset.c,v 1.7 2005/01/08 21:46:47 tom Exp $")
+MODULE_ID("$Id: lib_slkatrset.c,v 1.10 2009/10/24 22:12:21 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_attrset(const chtype attr)
+NCURSES_SP_NAME(slk_attrset) (NCURSES_SP_DCLx const chtype attr)
 {
-    T((T_CALLED("slk_attrset(%s)"), _traceattr(attr)));
+    T((T_CALLED("slk_attrset(%p,%s)"), (void *) SP_PARM, _traceattr(attr)));
 
-    if (SP != 0 && SP->_slk != 0) {
-	SetAttr(SP->_slk->attr, attr);
+    if (SP_PARM != 0 && SP_PARM->_slk != 0) {
+	SetAttr(SP_PARM->_slk->attr, attr);
 	returnCode(OK);
     } else
 	returnCode(ERR);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_attrset(const chtype attr)
+{
+    return NCURSES_SP_NAME(slk_attrset) (CURRENT_SCREEN, attr);
+}
+#endif
diff --git a/ncurses/base/lib_slkattr.c b/ncurses/base/lib_slkattr.c
index da82ee5..bec11e8 100644
--- a/ncurses/base/lib_slkattr.c
+++ b/ncurses/base/lib_slkattr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -38,19 +38,27 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkattr.c,v 1.6 2005/01/08 21:44:28 tom Exp $")
+MODULE_ID("$Id: lib_slkattr.c,v 1.11 2010/12/20 01:41:25 tom Exp $")
 
 NCURSES_EXPORT(attr_t)
-slk_attr(void)
+NCURSES_SP_NAME(slk_attr) (NCURSES_SP_DCL0)
 {
-    T((T_CALLED("slk_attr()")));
+    T((T_CALLED("slk_attr(%p)"), (void *) SP_PARM));
 
-    if (SP != 0 && SP->_slk != 0) {
-	attr_t result = AttrOf(SP->_slk->attr) & ALL_BUT_COLOR;
-	int pair = GetPair(SP->_slk->attr);
+    if (SP_PARM != 0 && SP_PARM->_slk != 0) {
+	attr_t result = AttrOf(SP_PARM->_slk->attr) & ALL_BUT_COLOR;
+	int pair = GetPair(SP_PARM->_slk->attr);
 
-	result |= COLOR_PAIR(pair);
+	result |= (attr_t) ColorPair(pair);
 	returnAttr(result);
     } else
 	returnAttr(0);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(attr_t)
+slk_attr(void)
+{
+    return NCURSES_SP_NAME(slk_attr) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/base/lib_slkclear.c b/ncurses/base/lib_slkclear.c
index 946ceea..264c8c4 100644
--- a/ncurses/base/lib_slkclear.c
+++ b/ncurses/base/lib_slkclear.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2007,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,27 +40,35 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkclear.c,v 1.10 2007/12/29 17:51:47 tom Exp $")
+MODULE_ID("$Id: lib_slkclear.c,v 1.14 2009/11/07 16:27:05 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_clear(void)
+NCURSES_SP_NAME(slk_clear) (NCURSES_SP_DCL0)
 {
     int rc = ERR;
 
-    T((T_CALLED("slk_clear()")));
+    T((T_CALLED("slk_clear(%p)"), (void *) SP_PARM));
 
-    if (SP != NULL && SP->_slk != NULL) {
-	SP->_slk->hidden = TRUE;
+    if (SP_PARM != 0 && SP_PARM->_slk != 0) {
+	SP_PARM->_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) {
+	SP_PARM->_slk->win->_nc_bkgd = StdScreen(SP_PARM)->_nc_bkgd;
+	WINDOW_ATTRS(SP_PARM->_slk->win) = WINDOW_ATTRS(StdScreen(SP_PARM));
+	if (SP_PARM->_slk->win == StdScreen(SP_PARM)) {
 	    rc = OK;
 	} else {
-	    werase(SP->_slk->win);
-	    rc = wrefresh(SP->_slk->win);
+	    werase(SP_PARM->_slk->win);
+	    rc = wrefresh(SP_PARM->_slk->win);
 	}
     }
     returnCode(rc);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_clear(void)
+{
+    return NCURSES_SP_NAME(slk_clear) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/base/lib_slkcolor.c b/ncurses/base/lib_slkcolor.c
index b677b65..2cf9e5d 100644
--- a/ncurses/base/lib_slkcolor.c
+++ b/ncurses/base/lib_slkcolor.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,8 +27,8 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author:  Juergen Pfeifer, 1998                                          *
- *     and:  Thomas E. Dickey 2005                                          *
+ *  Author:  Juergen Pfeifer, 1998,2009                                     *
+ *     and:  Thomas E. Dickey 2005-on                                       *
  ****************************************************************************/
 
 /*
@@ -38,19 +38,31 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkcolor.c,v 1.12 2005/01/28 21:11:53 tom Exp $")
+MODULE_ID("$Id: lib_slkcolor.c,v 1.17 2014/02/01 22:10:42 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_color(short color_pair_number)
+NCURSES_SP_NAME(slk_color) (NCURSES_SP_DCLx NCURSES_PAIRS_T color_pair_number)
 {
-    T((T_CALLED("slk_color(%d)"), color_pair_number));
+    int code = ERR;
 
-    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);
+    T((T_CALLED("slk_color(%p,%d)"), (void *) SP_PARM, (int) color_pair_number));
+
+    if (SP_PARM != 0
+	&& SP_PARM->_slk != 0
+	&& color_pair_number >= 0
+	&& color_pair_number < SP_PARM->_pair_limit) {
+	TR(TRACE_ATTRS, ("... current is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
+	SetPair(SP_PARM->_slk->attr, color_pair_number);
+	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
+	code = OK;
+    }
+    returnCode(code);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_color(NCURSES_PAIRS_T color_pair_number)
+{
+    return NCURSES_SP_NAME(slk_color) (CURRENT_SCREEN, color_pair_number);
+}
+#endif
diff --git a/ncurses/base/lib_slkinit.c b/ncurses/base/lib_slkinit.c
index c440109..9cbdfea 100644
--- a/ncurses/base/lib_slkinit.c
+++ b/ncurses/base/lib_slkinit.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -39,17 +40,41 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slkinit.c,v 1.7 2008/01/12 20:23:39 tom Exp $")
+MODULE_ID("$Id: lib_slkinit.c,v 1.13 2009/10/31 00:10:46 tom Exp $")
+
+#ifdef USE_SP_RIPOFF
+#define SoftkeyFormat SP_PARM->slk_format
+#else
+#define SoftkeyFormat _nc_globals.slk_format
+#endif
 
 NCURSES_EXPORT(int)
-slk_init(int format)
+NCURSES_SP_NAME(slk_init) (NCURSES_SP_DCLx 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);
+    START_TRACE();
+    T((T_CALLED("slk_init(%p,%d)"), (void *) SP_PARM, format));
+
+    if (format >= 0
+	&& format <= 3
+#ifdef USE_SP_RIPOFF
+	&& SP_PARM
+	&& SP_PARM->_prescreen
+#endif
+	&& !SoftkeyFormat) {
+	SoftkeyFormat = 1 + format;
+	code = NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_ARGx
+						-SLK_LINES(SoftkeyFormat),
+						_nc_slk_initialize);
     }
     returnCode(code);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_init(int format)
+{
+    return NCURSES_SP_NAME(slk_init) (CURRENT_SCREEN_PRE, format);
+}
+#endif
diff --git a/ncurses/base/lib_slklab.c b/ncurses/base/lib_slklab.c
index 42bb4ac..d0b2a23 100644
--- a/ncurses/base/lib_slklab.c
+++ b/ncurses/base/lib_slklab.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2003,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and:  Juergen Pfeifer,                       1998,2009               *
+ *     and:  Thomas E. Dickey                       1998-on                 *
  ****************************************************************************/
 
 /*
@@ -38,14 +40,22 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slklab.c,v 1.7 2003/03/29 22:53:48 tom Exp $")
+MODULE_ID("$Id: lib_slklab.c,v 1.10 2009/10/24 22:12:21 tom Exp $")
 
 NCURSES_EXPORT(char *)
+NCURSES_SP_NAME(slk_label) (NCURSES_SP_DCLx int n)
+{
+    T((T_CALLED("slk_label(%p,%d)"), (void *) SP_PARM, n));
+
+    if (SP_PARM == 0 || SP_PARM->_slk == 0 || n < 1 || n > SP_PARM->_slk->labcnt)
+	returnPtr(0);
+    returnPtr(SP_PARM->_slk->ent[n - 1].ent_text);
+}
+
+#if NCURSES_SP_FUNCS
+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);
+    return NCURSES_SP_NAME(slk_label) (CURRENT_SCREEN, n);
 }
+#endif
diff --git a/ncurses/base/lib_slkrefr.c b/ncurses/base/lib_slkrefr.c
index cb1beba..382f9c4 100644
--- a/ncurses/base/lib_slkrefr.c
+++ b/ncurses/base/lib_slkrefr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -38,9 +38,18 @@
  *	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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_slkrefr.c,v 1.30 2014/03/08 20:32:59 tom Exp $")
+
+#ifdef USE_TERM_DRIVER
+#define NumLabels    InfoOf(SP_PARM).numlabels
+#else
+#define NumLabels    num_labels
+#endif
 
 /*
  * Paint the info line for the PC style SLK emulation.
@@ -53,7 +62,7 @@
     if (win && sp && (sp->slk_format == 4)) {
 	int i;
 
-	mvwhline(win, 0, 0, 0, getmaxx(win));
+	(void) mvwhline(win, 0, 0, 0, getmaxx(win));
 	wmove(win, 0, 0);
 
 	for (i = 0; i < sp->_slk->maxlab; i++) {
@@ -66,31 +75,47 @@
  * Write the soft labels to the soft-key window.
  */
 static void
-slk_intern_refresh(SLK * slk)
+slk_intern_refresh(SCREEN *sp)
 {
     int i;
-    int fmt = SP->slk_format;
+    int fmt;
+    SLK *slk;
+    int numlab;
+
+    if (sp == 0)
+	return;
+
+    slk = sp->_slk;
+    fmt = sp->slk_format;
+    numlab = NumLabels;
+
+    if (slk->hidden)
+	return;
 
     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 (numlab > 0 && SLK_STDFMT(fmt)) {
+#ifdef USE_TERM_DRIVER
+		    CallDriver_2(sp, td_hwlabel, i + 1, slk->ent[i].form_text);
+#else
 		    if (i < num_labels) {
-			TPUTS_TRACE("plab_norm");
-			putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
+			NCURSES_PUTP2("plab_norm",
+				      TPARM_2(plab_norm,
+					      i + 1,
+					      slk->ent[i].form_text));
 		    }
+#endif
 		} 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));
-		    }
+		    (void) wattrset(slk->win, (int) AttrOf(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));
+		    (void) wattrset(slk->win, (int) WINDOW_ATTRS(StdScreen(sp)));
 		}
 	    }
 	    slk->ent[i].dirty = FALSE;
@@ -98,14 +123,16 @@
     }
     slk->dirty = FALSE;
 
-    if (num_labels > 0) {
+    if (numlab > 0) {
+#ifdef USE_TERM_DRIVER
+	CallDriver_1(sp, td_hwlabelOnOff, slk->hidden ? FALSE : TRUE);
+#else
 	if (slk->hidden) {
-	    TPUTS_TRACE("label_off");
-	    putp(label_off);
+	    NCURSES_PUTP2("label_off", label_off);
 	} else {
-	    TPUTS_TRACE("label_on");
-	    putp(label_on);
+	    NCURSES_PUTP2("label_on", label_on);
 	}
+#endif
     }
 }
 
@@ -113,32 +140,48 @@
  * Refresh the soft labels.
  */
 NCURSES_EXPORT(int)
+NCURSES_SP_NAME(slk_noutrefresh) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("slk_noutrefresh(%p)"), (void *) SP_PARM));
+
+    if (SP_PARM == 0 || SP_PARM->_slk == 0)
+	returnCode(ERR);
+    if (SP_PARM->_slk->hidden)
+	returnCode(OK);
+    slk_intern_refresh(SP_PARM);
+
+    returnCode(wnoutrefresh(SP_PARM->_slk->win));
+}
+
+#if NCURSES_SP_FUNCS
+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));
+    return NCURSES_SP_NAME(slk_noutrefresh) (CURRENT_SCREEN);
 }
+#endif
 
 /*
  * Refresh the soft labels.
  */
 NCURSES_EXPORT(int)
+NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("slk_refresh(%p)"), (void *) SP_PARM));
+
+    if (SP_PARM == 0 || SP_PARM->_slk == 0)
+	returnCode(ERR);
+    if (SP_PARM->_slk->hidden)
+	returnCode(OK);
+    slk_intern_refresh(SP_PARM);
+
+    returnCode(wrefresh(SP_PARM->_slk->win));
+}
+
+#if NCURSES_SP_FUNCS
+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));
+    return NCURSES_SP_NAME(slk_refresh) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/base/lib_slkset.c b/ncurses/base/lib_slkset.c
index e19f88e..9091e00 100644
--- a/ncurses/base/lib_slkset.c
+++ b/ncurses/base/lib_slkset.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -44,33 +44,33 @@
 #endif
 #endif
 
-MODULE_ID("$Id: lib_slkset.c,v 1.17 2007/10/13 20:08:46 tom Exp $")
+MODULE_ID("$Id: lib_slkset.c,v 1.24 2012/12/08 23:09:25 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_set(int i, const char *astr, int format)
+NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format)
 {
     SLK *slk;
-    int offset;
+    int offset = 0;
     int numchrs;
     int numcols;
     int limit;
     const char *str = astr;
     const char *p;
 
-    T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format));
+    T((T_CALLED("slk_set(%p, %d, \"%s\", %d)"), (void *) SP_PARM, i, str, format));
 
-    if (SP == 0
-	|| (slk = SP->_slk) == 0
+    if (SP_PARM == 0
+	|| (slk = SP_PARM->_slk) == 0
 	|| i < 1
 	|| i > slk->labcnt
 	|| format < 0
 	|| format > 2)
 	returnCode(ERR);
-    if (str == NULL)
+    if (str == 0)
 	str = "";
     --i;			/* Adjust numbering of labels */
 
-    limit = MAX_SKEY_LEN(SP->slk_format);
+    limit = MAX_SKEY_LEN(SP_PARM->slk_format);
     while (isspace(UChar(*str)))
 	str++;			/* skip over leading spaces  */
     p = str;
@@ -94,12 +94,12 @@
 	numcols += wcwidth(wc);
 	p += need;
     }
-    numchrs = (p - str);
+    numchrs = (int) (p - str);
 #else
     while (isprint(UChar(*p)))
 	p++;			/* The first non-print stops */
 
-    numcols = (p - str);
+    numcols = (int) (p - str);
     if (numcols > limit)
 	numcols = limit;
     numchrs = numcols;
@@ -111,13 +111,12 @@
     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))
+						      (size_t) (limit +
+								numchrs + 1))
 	) == 0)
 	returnCode(ERR);
 
     switch (format) {
-    default:
     case 0:			/* left-justified */
 	offset = 0;
 	break;
@@ -131,19 +130,27 @@
     if (offset <= 0)
 	offset = 0;
     else
-	memset(slk->ent[i].form_text, ' ', (unsigned) offset);
+	memset(slk->ent[i].form_text, ' ', (size_t) offset);
 
     memcpy(slk->ent[i].form_text + offset,
 	   slk->ent[i].ent_text,
-	   (unsigned) numchrs);
+	   (size_t) numchrs);
 
     if (offset < limit) {
 	memset(slk->ent[i].form_text + offset + numchrs,
 	       ' ',
-	       (unsigned) (limit - (offset + numcols)));
+	       (size_t) (limit - (offset + numcols)));
     }
 
     slk->ent[i].form_text[numchrs - numcols + limit] = 0;
     slk->ent[i].dirty = TRUE;
     returnCode(OK);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_set(int i, const char *astr, int format)
+{
+    return NCURSES_SP_NAME(slk_set) (CURRENT_SCREEN, i, astr, format);
+}
+#endif
diff --git a/ncurses/base/lib_slktouch.c b/ncurses/base/lib_slktouch.c
index 5eb5df3..ba77fd2 100644
--- a/ncurses/base/lib_slktouch.c
+++ b/ncurses/base/lib_slktouch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,8 +27,8 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
- *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *  Author: Juergen Pfeifer                         1997,2009               *
+ *     and: Thomas E. Dickey                        1996-on                 *
  ****************************************************************************/
 
 /*
@@ -38,16 +38,24 @@
  */
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_slktouch.c,v 1.5 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_slktouch.c,v 1.8 2009/10/24 22:12:21 tom Exp $")
 
 NCURSES_EXPORT(int)
-slk_touch(void)
+NCURSES_SP_NAME(slk_touch) (NCURSES_SP_DCL0)
 {
-    T((T_CALLED("slk_touch()")));
+    T((T_CALLED("slk_touch(%p)"), (void *) SP_PARM));
 
-    if (SP == NULL || SP->_slk == NULL)
+    if (SP_PARM == 0 || SP_PARM->_slk == 0)
 	returnCode(ERR);
-    SP->_slk->dirty = TRUE;
+    SP_PARM->_slk->dirty = TRUE;
 
     returnCode(OK);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+slk_touch(void)
+{
+    return NCURSES_SP_NAME(slk_touch) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/base/lib_touch.c b/ncurses/base/lib_touch.c
index 2ac21f2..20ac945 100644
--- a/ncurses/base/lib_touch.c
+++ b/ncurses/base/lib_touch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -43,12 +43,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_touch.c,v 1.9 2000/12/10 02:43:27 tom Exp $")
+MODULE_ID("$Id: lib_touch.c,v 1.12 2012/06/09 20:29:33 tom Exp $")
 
 NCURSES_EXPORT(bool)
 is_linetouched(WINDOW *win, int line)
 {
-    T((T_CALLED("is_linetouched(%p,%d)"), win, line));
+    T((T_CALLED("is_linetouched(%p,%d)"), (void *) win, line));
 
     /* XSI doesn't define any error */
     if (!win || (line > win->_maxy) || (line < 0))
@@ -62,7 +62,7 @@
 {
     int i;
 
-    T((T_CALLED("is_wintouched(%p)"), win));
+    T((T_CALLED("is_wintouched(%p)"), (void *) win));
 
     if (win)
 	for (i = 0; i <= win->_maxy; i++)
@@ -76,7 +76,7 @@
 {
     int i;
 
-    T((T_CALLED("wtouchln(%p,%d,%d,%d)"), win, y, n, changed));
+    T((T_CALLED("wtouchln(%p,%d,%d,%d)"), (void *) win, y, n, changed));
 
     if (!win || (n < 0) || (y < 0) || (y > win->_maxy))
 	returnCode(ERR);
@@ -84,8 +84,10 @@
     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;
+	win->_line[i].firstchar = (NCURSES_SIZE_T) (changed ? 0 : _NOCHANGE);
+	win->_line[i].lastchar = (NCURSES_SIZE_T) (changed
+						   ? win->_maxx
+						   : _NOCHANGE);
     }
     returnCode(OK);
 }
diff --git a/ncurses/base/lib_ungetch.c b/ncurses/base/lib_ungetch.c
index 8742f86..4ee9119 100644
--- a/ncurses/base/lib_ungetch.c
+++ b/ncurses/base/lib_ungetch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -41,7 +42,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_ungetch.c,v 1.11 2008/05/31 16:44:54 tom Exp $")
+MODULE_ID("$Id: lib_ungetch.c,v 1.16 2012/08/04 17:38:53 tom Exp $")
 
 #include <fifo_defs.h>
 
@@ -57,17 +58,20 @@
 #endif /* TRACE */
 
 NCURSES_EXPORT(int)
-_nc_ungetch(SCREEN *sp, int ch)
+safe_ungetch(SCREEN *sp, int ch)
 {
     int rc = ERR;
 
-    if (tail != -1) {
-	if (head == -1) {
+    T((T_CALLED("ungetch(%p,%s)"), (void *) sp, _nc_tracechar(sp, ch)));
+
+    if (sp != 0 && tail >= 0) {
+	if (head < 0) {
 	    head = 0;
 	    t_inc();
 	    peek = tail;	/* no raw keys */
-	} else
+	} else {
 	    h_dec();
+	}
 
 	sp->_fifo[head] = ch;
 	T(("ungetch %s ok", _nc_tracechar(sp, ch)));
@@ -79,12 +83,11 @@
 #endif
 	rc = OK;
     }
-    return rc;
+    returnCode(rc);
 }
 
 NCURSES_EXPORT(int)
 ungetch(int ch)
 {
-    T((T_CALLED("ungetch(%s)"), _nc_tracechar(SP, ch)));
-    returnCode(_nc_ungetch(SP, ch));
+    return safe_ungetch(CURRENT_SCREEN, ch);
 }
diff --git a/ncurses/base/lib_vline.c b/ncurses/base/lib_vline.c
index 1a2537e..2f3148e 100644
--- a/ncurses/base/lib_vline.c
+++ b/ncurses/base/lib_vline.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,16 +40,16 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_vline.c,v 1.10 2006/03/11 21:52:19 tom Exp $")
+MODULE_ID("$Id: lib_vline.c,v 1.12 2010/12/19 01:22:58 tom Exp $")
 
 NCURSES_EXPORT(int)
 wvline(WINDOW *win, chtype ch, int n)
 {
     int code = ERR;
-    NCURSES_SIZE_T row, col;
-    NCURSES_SIZE_T end;
+    int row, col;
+    int end;
 
-    T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n));
+    T((T_CALLED("wvline(%p,%s,%d)"), (void *) win, _tracechtype(ch), n));
 
     if (win) {
 	NCURSES_CH_T wch;
diff --git a/ncurses/base/lib_wattroff.c b/ncurses/base/lib_wattroff.c
index bf2020e..fff0b39 100644
--- a/ncurses/base/lib_wattroff.c
+++ b/ncurses/base/lib_wattroff.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2006,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -42,12 +42,12 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_wattroff.c,v 1.9 2006/05/27 19:30:33 tom Exp $")
+MODULE_ID("$Id: lib_wattroff.c,v 1.10 2009/10/24 22:36:08 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)));
+    T((T_CALLED("wattr_off(%p,%s)"), (void *) win, _traceattr(at)));
     if (win) {
 	T(("... current %s (%d)",
 	   _traceattr(WINDOW_ATTRS(win)),
diff --git a/ncurses/base/lib_wattron.c b/ncurses/base/lib_wattron.c
index 2e17d96..3806285 100644
--- a/ncurses/base/lib_wattron.c
+++ b/ncurses/base/lib_wattron.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -42,12 +42,12 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_wattron.c,v 1.9 2006/05/27 19:30:46 tom Exp $")
+MODULE_ID("$Id: lib_wattron.c,v 1.11 2010/03/31 23:38:02 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)));
+    T((T_CALLED("wattr_on(%p,%s)"), (void *) win, _traceattr(at)));
     if (win != 0) {
 	T(("... current %s (%d)",
 	   _traceattr(WINDOW_ATTRS(win)),
@@ -55,7 +55,7 @@
 
 	if_EXT_COLORS({
 	    if (at & A_COLOR)
-		win->_color = PAIR_NUMBER(at);
+		win->_color = PairNumber(at);
 	});
 	toggle_attr_on(WINDOW_ATTRS(win), at);
 	returnCode(OK);
diff --git a/ncurses/base/lib_winch.c b/ncurses/base/lib_winch.c
index 18da9c5..7e75f85 100644
--- a/ncurses/base/lib_winch.c
+++ b/ncurses/base/lib_winch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,16 +39,16 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_winch.c,v 1.5 2001/06/02 23:42:08 skimo Exp $")
+MODULE_ID("$Id: lib_winch.c,v 1.8 2010/12/19 01:22:58 tom Exp $")
 
 NCURSES_EXPORT(chtype)
 winch(WINDOW *win)
 {
-    T((T_CALLED("winch(%p)"), win));
+    T((T_CALLED("winch(%p)"), (void *) win));
     if (win != 0) {
-	returnChar(CharOf(win->_line[win->_cury].text[win->_curx]) |
-		   AttrOf(win->_line[win->_cury].text[win->_curx]));
+	returnChtype((chtype) CharOf(win->_line[win->_cury].text[win->_curx])
+		     | AttrOf(win->_line[win->_cury].text[win->_curx]));
     } else {
-	returnChar(0);
+	returnChtype(0);
     }
 }
diff --git a/ncurses/base/lib_window.c b/ncurses/base/lib_window.c
index a3236e2..4baa369 100644
--- a/ncurses/base/lib_window.c
+++ b/ncurses/base/lib_window.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_window.c,v 1.25 2008/06/07 14:12:56 tom Exp $")
+MODULE_ID("$Id: lib_window.c,v 1.29 2010/12/19 01:47:22 tom Exp $")
 
 NCURSES_EXPORT(void)
 _nc_synchook(WINDOW *win)
@@ -57,32 +57,30 @@
 {
     WINDOW *orig;
     int i;
+    int rc = ERR;
 
-    T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x));
+    T((T_CALLED("mvderwin(%p,%d,%d)"), (void *) 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);
+    if (win != 0
+	&& (orig = win->_parent) != 0
+	&& (x >= 0 && y >= 0)
+	&& (x + getmaxx(win) <= getmaxx(orig))
+	&& (y + getmaxy(win) <= getmaxy(orig))) {
+	wsyncup(win);
+	win->_parx = x;
+	win->_pary = y;
+	for (i = 0; i < getmaxy(win); i++)
+	    win->_line[i].text = &(orig->_line[y++].text[x]);
+	rc = OK;
+    }
+    returnCode(rc);
 }
 
 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));
+    T((T_CALLED("syncok(%p,%d)"), (void *) win, bf));
 
     if (win) {
 	win->_sync = bf;
@@ -98,7 +96,7 @@
 {
     WINDOW *wp;
 
-    T((T_CALLED("wsyncup(%p)"), win));
+    T((T_CALLED("wsyncup(%p)"), (void *) win));
     if (win && win->_parent) {
 	for (wp = win; wp->_parent; wp = wp->_parent) {
 	    int y;
@@ -128,7 +126,7 @@
 /* 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));
+    T((T_CALLED("wsyncdown(%p)"), (void *) win));
 
     if (win && win->_parent) {
 	WINDOW *pp = win->_parent;
@@ -167,7 +165,7 @@
 {
     WINDOW *wp;
 
-    T((T_CALLED("wcursyncup(%p)"), win));
+    T((T_CALLED("wcursyncup(%p)"), (void *) win));
     for (wp = win; wp && wp->_parent; wp = wp->_parent) {
 	wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx);
     }
@@ -182,19 +180,23 @@
     size_t linesize;
     int i;
 
-    T((T_CALLED("dupwin(%p)"), win));
+    T((T_CALLED("dupwin(%p)"), (void *) win));
 
     if (win != 0) {
-
+#if NCURSES_SP_FUNCS
+	SCREEN *sp = _nc_screen_of(win);
+#endif
 	_nc_lock_global(curses);
 	if (win->_flags & _ISPAD) {
-	    nwin = newpad(win->_maxy + 1,
-			  win->_maxx + 1);
+	    nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
+					    win->_maxy + 1,
+					    win->_maxx + 1);
 	} else {
-	    nwin = newwin(win->_maxy + 1,
-			  win->_maxx + 1,
-			  win->_begy,
-			  win->_begx);
+	    nwin = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
+					    win->_maxy + 1,
+					    win->_maxx + 1,
+					    win->_begy,
+					    win->_begx);
 	}
 
 	if (nwin != 0) {
@@ -237,7 +239,7 @@
 	    if (win->_flags & _ISPAD)
 		nwin->_pad = win->_pad;
 
-	    linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T);
+	    linesize = (unsigned) (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;
diff --git a/ncurses/base/nc_panel.c b/ncurses/base/nc_panel.c
index 59bfbbe..69b10bc 100644
--- a/ncurses/base/nc_panel.c
+++ b/ncurses/base/nc_panel.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -32,10 +32,22 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: nc_panel.c,v 1.4 2000/12/10 02:43:28 tom Exp $")
+MODULE_ID("$Id: nc_panel.c,v 1.5 2009/04/11 21:05:10 tom Exp $")
 
 NCURSES_EXPORT(struct panelhook *)
+NCURSES_SP_NAME(_nc_panelhook) (NCURSES_SP_DCL0)
+{
+    return (SP_PARM
+	    ? &(SP_PARM->_panelHook)
+	    : (CURRENT_SCREEN
+	       ? &(CURRENT_SCREEN->_panelHook)
+	       : 0));
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(struct panelhook *)
 _nc_panelhook(void)
 {
-    return (SP ? &(SP->_panelHook) : NULL);
+    return NCURSES_SP_NAME(_nc_panelhook) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/base/resizeterm.c b/ncurses/base/resizeterm.c
index a94cfc3..1eca279 100644
--- a/ncurses/base/resizeterm.c
+++ b/ncurses/base/resizeterm.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -28,6 +28,7 @@
 
 /****************************************************************************
  *  Author: Thomas E. Dickey                                                *
+ *     and: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 /*
@@ -39,11 +40,12 @@
  */
 
 #include <curses.priv.h>
-#include <term.h>
 
-MODULE_ID("$Id: resizeterm.c,v 1.34 2008/06/07 13:58:40 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-#define stolen_lines (screen_lines - SP->_lines_avail)
+MODULE_ID("$Id: resizeterm.c,v 1.47 2014/10/13 08:56:49 tom Exp $")
 
 /*
  * If we're trying to be reentrant, do not want any local statics.
@@ -64,18 +66,23 @@
 static void
 show_window_sizes(const char *name)
 {
+    SCREEN *sp;
     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);
+    for (each_screen(sp)) {
+	_tracef("%s resizing: %p: %2d x %2d (%2d x %2d)", name, (void *) sp,
+		*(ptrLines(sp)),
+		*(ptrCols(sp)),
+		screen_lines(sp), screen_columns(sp));
+	for (each_window(sp, wp)) {
+	    _tracef("  window %p is %2ld x %2ld at %2ld,%2ld",
+		    (void *) &(wp->win),
+		    (long) wp->win._maxy + 1,
+		    (long) wp->win._maxx + 1,
+		    (long) wp->win._begy,
+		    (long) wp->win._begx);
+	}
     }
     _nc_unlock_global(curses);
 }
@@ -86,15 +93,23 @@
  * structure's size.
  */
 NCURSES_EXPORT(bool)
-is_term_resized(int ToLines, int ToCols)
+NCURSES_SP_NAME(is_term_resized) (NCURSES_SP_DCLx int ToLines, int ToCols)
 {
-    T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols));
+    T((T_CALLED("is_term_resized(%p, %d, %d)"), (void *) SP_PARM, ToLines, ToCols));
     returnCode(ToLines > 0
 	       && ToCols > 0
-	       && (ToLines != screen_lines
-		   || ToCols != screen_columns));
+	       && (ToLines != screen_lines(SP_PARM)
+		   || ToCols != screen_columns(SP_PARM)));
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(bool)
+is_term_resized(int ToLines, int ToCols)
+{
+    return NCURSES_SP_NAME(is_term_resized) (CURRENT_SCREEN, ToLines, ToCols);
+}
+#endif
+
 /*
  */
 static ripoff_t *
@@ -104,6 +119,9 @@
     ripoff_t *rop;
 
     if (win != 0) {
+#ifdef USE_SP_RIPOFF
+	SCREEN *sp = _nc_screen_of(win);
+#endif
 	for (each_ripoff(rop)) {
 	    if (rop->win == win && rop->line != 0) {
 		result = rop;
@@ -125,6 +143,9 @@
     ripoff_t *rop;
 
     if (win != 0) {
+#ifdef USE_SP_RIPOFF
+	SCREEN *sp = _nc_screen_of(win);
+#endif
 	for (each_ripoff(rop)) {
 	    if (rop->line < 0) {
 		result -= rop->line;
@@ -146,9 +167,12 @@
     int depth = 0;
 
     if (cmp != 0) {
+#ifdef USE_SP_WINDOWLIST
+	SCREEN *sp = _nc_screen_of(cmp);
+#endif
 	WINDOWLIST *wp;
 
-	for (each_window(wp)) {
+	for (each_window(sp, wp)) {
 	    WINDOW *tst = &(wp->win);
 	    if (tst->_parent == cmp) {
 		depth = 1 + child_depth(tst);
@@ -184,13 +208,13 @@
 adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
 {
     int result;
-    int bottom = CurLines + SP->_topstolen - stolen;
+    int bottom = CurLines + _nc_screen_of(win)->_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,
+       (void *) win, ToLines, ToCols,
        (rop != 0) ? " (rip)" : "",
        parent_depth(win),
        child_depth(win),
@@ -202,13 +226,19 @@
 	 * 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;
+	win->_begy = (NCURSES_SIZE_T) (ToLines - ripped_bottom(win) - 0 - win->_yoffset);
+	if (rop->hook == _nc_slk_initialize)
+	    _nc_format_slks(
+#if NCURSES_SP_FUNCS
+			       _nc_screen_of(win),
+#endif
+			       ToCols);
     } 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);
+	win->_begy = (NCURSES_SIZE_T) (win->_begy + (ToLines - CurLines));
     } else {
 	if (myLines == (CurLines - stolen)
 	    && ToLines != CurLines) {
@@ -239,19 +269,19 @@
  * children, decrease those to fit, then decrease the containing window, etc.
  */
 static int
-decrease_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
+decrease_size(NCURSES_SP_DCLx int ToLines, int ToCols, int stolen EXTRA_DCLS)
 {
     bool found;
     int depth = 0;
     WINDOWLIST *wp;
 
-    T((T_CALLED("decrease_size(%d, %d)"), ToLines, ToCols));
+    T((T_CALLED("decrease_size(%p, %d, %d)"), (void *) SP_PARM, ToLines, ToCols));
 
     do {
 	found = FALSE;
 	TR(TRACE_UPDATE, ("decreasing size of windows to %dx%d, depth=%d",
 			  ToLines, ToCols, depth));
-	for (each_window(wp)) {
+	for (each_window(SP_PARM, wp)) {
 	    WINDOW *win = &(wp->win);
 
 	    if (!(win->_flags & _ISPAD)) {
@@ -273,19 +303,19 @@
  * parent, increase those to fit, then increase the contained window, etc.
  */
 static int
-increase_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
+increase_size(NCURSES_SP_DCLx int ToLines, int ToCols, int stolen EXTRA_DCLS)
 {
     bool found;
     int depth = 0;
     WINDOWLIST *wp;
 
-    T((T_CALLED("increase_size(%d, %d)"), ToLines, ToCols));
+    T((T_CALLED("increase_size(%p, %d, %d)"), (void *) SP_PARM, ToLines, ToCols));
 
     do {
 	found = FALSE;
 	TR(TRACE_UPDATE, ("increasing size of windows to %dx%d, depth=%d",
 			  ToLines, ToCols, depth));
-	for (each_window(wp)) {
+	for (each_window(SP_PARM, wp)) {
 	    WINDOW *win = &(wp->win);
 
 	    if (!(win->_flags & _ISPAD)) {
@@ -307,25 +337,26 @@
  * such as ungetch().
  */
 NCURSES_EXPORT(int)
-resize_term(int ToLines, int ToCols)
+NCURSES_SP_NAME(resize_term) (NCURSES_SP_DCLx 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));
+    T((T_CALLED("resize_term(%p,%d,%d) old(%d,%d)"),
+       (void *) SP_PARM, ToLines, ToCols,
+       (SP_PARM == 0) ? -1 : screen_lines(SP_PARM),
+       (SP_PARM == 0) ? -1 : screen_columns(SP_PARM)));
 
-    if (SP == 0) {
+    if (SP_PARM == 0 || ToLines <= 0 || ToCols <= 0) {
 	returnCode(ERR);
     }
 
-    _nc_lock_global(curses);
+    _nc_nonsp_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;
+    was_stolen = (screen_lines(SP_PARM) - SP_PARM->_lines_avail);
+    if (NCURSES_SP_NAME(is_term_resized) (NCURSES_SP_ARGx ToLines, ToCols)) {
+	int myLines = CurLines = screen_lines(SP_PARM);
+	int myCols = CurCols = screen_columns(SP_PARM);
 
 #ifdef TRACE
 	if (USE_TRACEF(TRACE_UPDATE)) {
@@ -333,56 +364,90 @@
 	    _nc_unlock_global(tracef);
 	}
 #endif
-	if (ToLines > screen_lines) {
-	    increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS);
+	if (ToLines > screen_lines(SP_PARM)) {
+	    result = increase_size(NCURSES_SP_ARGx
+				   myLines = ToLines,
+				   myCols,
+				   was_stolen EXTRA_ARGS);
 	    CurLines = myLines;
 	    CurCols = myCols;
 	}
 
-	if (ToCols > screen_columns) {
-	    increase_size(myLines, myCols = ToCols, was_stolen EXTRA_ARGS);
+	if ((result == OK)
+	    && (ToCols > screen_columns(SP_PARM))) {
+	    result = increase_size(NCURSES_SP_ARGx
+				   myLines,
+				   myCols = ToCols,
+				   was_stolen EXTRA_ARGS);
 	    CurLines = myLines;
 	    CurCols = myCols;
 	}
 
-	if (ToLines < myLines ||
-	    ToCols < myCols) {
-	    decrease_size(ToLines, ToCols, was_stolen EXTRA_ARGS);
+	if ((result == OK)
+	    && (ToLines < myLines ||
+		ToCols < myCols)) {
+	    result = decrease_size(NCURSES_SP_ARGx
+				   ToLines,
+				   ToCols,
+				   was_stolen EXTRA_ARGS);
 	}
 
-	screen_lines = lines = ToLines;
-	screen_columns = columns = ToCols;
+	if (result == OK) {
+	    screen_lines(SP_PARM) = (NCURSES_SIZE_T) ToLines;
+	    screen_columns(SP_PARM) = (NCURSES_SIZE_T) 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);
-	}
+#ifdef USE_TERM_DRIVER
+	    CallDriver_2(SP_PARM, td_setsize, ToLines, ToCols);
+#else
+	    lines = (NCURSES_SIZE_T) ToLines;
+	    columns = (NCURSES_SIZE_T) ToCols;
 #endif
+
+	    SP_PARM->_lines_avail = (NCURSES_SIZE_T) (ToLines - was_stolen);
+
+	    if (SP_PARM->oldhash) {
+		FreeAndNull(SP_PARM->oldhash);
+	    }
+	    if (SP_PARM->newhash) {
+		FreeAndNull(SP_PARM->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);
+    if (result == OK) {
+	/*
+	 * 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);
+    _nc_nonsp_unlock_global(curses);
 
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+resize_term(int ToLines, int ToCols)
+{
+    int res = ERR;
+    _nc_sp_lock_global(curses);
+    res = NCURSES_SP_NAME(resize_term) (CURRENT_SCREEN, ToLines, ToCols);
+    _nc_sp_unlock_global(curses);
+    return (res);
+}
+#endif
+
 /*
  * This function reallocates NCURSES window structures.  It is invoked in
  * response to a SIGWINCH interrupt.  Other user-defined windows may also need
@@ -392,34 +457,34 @@
  * invoked directly from the signal handler.
  */
 NCURSES_EXPORT(int)
-resizeterm(int ToLines, int ToCols)
+NCURSES_SP_NAME(resizeterm) (NCURSES_SP_DCLx int ToLines, int ToCols)
 {
     int result = ERR;
 
-    T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
-       ToLines, ToCols,
-       screen_lines, screen_columns));
+    T((T_CALLED("resizeterm(%p, %d,%d) old(%d,%d)"),
+       (void *) SP_PARM, ToLines, ToCols,
+       (SP_PARM == 0) ? -1 : screen_lines(SP_PARM),
+       (SP_PARM == 0) ? -1 : screen_columns(SP_PARM)));
 
-    if (SP != 0) {
+    if (SP_PARM != 0 && ToLines > 0 && ToCols > 0) {
 	result = OK;
-	SP->_sig_winch = FALSE;
+	SP_PARM->_sig_winch = FALSE;
 
-	if (is_term_resized(ToLines, ToCols)) {
+	if (NCURSES_SP_NAME(is_term_resized) (NCURSES_SP_ARGx ToLines, ToCols)) {
 #if USE_SIGWINCH
 	    ripoff_t *rop;
-	    bool slk_visible = (SP != 0
-				&& SP->_slk != 0
-				&& !(SP->_slk->hidden));
+	    bool slk_visible = (SP_PARM != 0
+				&& SP_PARM->_slk != 0
+				&& !(SP_PARM->_slk->hidden));
 
 	    if (slk_visible) {
 		slk_clear();
 	    }
 #endif
-	    result = resize_term(ToLines, ToCols);
+	    result = NCURSES_SP_NAME(resize_term) (NCURSES_SP_ARGx ToLines, ToCols);
 
 #if USE_SIGWINCH
-	    _nc_ungetch(SP, KEY_RESIZE);	/* so application can know this */
-	    clearok(curscr, TRUE);	/* screen contents are unknown */
+	    clearok(CurScreen(SP_PARM), 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.
@@ -429,7 +494,7 @@
 	     * not know which are really on top.
 	     */
 	    for (each_ripoff(rop)) {
-		if (rop->win != stdscr
+		if (rop->win != StdScreen(SP_PARM)
 		    && rop->win != 0
 		    && rop->line < 0) {
 
@@ -442,14 +507,24 @@
 
 	    /* soft-keys are a special case: we _know_ how to repaint them */
 	    if (slk_visible) {
-		slk_restore();
-		slk_touch();
-
-		slk_refresh();
+		NCURSES_SP_NAME(slk_restore) (NCURSES_SP_ARG);
+		NCURSES_SP_NAME(slk_touch) (NCURSES_SP_ARG);
+		NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_ARG);
 	    }
 #endif
 	}
+#if USE_SIGWINCH
+	safe_ungetch(SP_PARM, KEY_RESIZE);	/* so application can know this */
+#endif
     }
 
     returnCode(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+resizeterm(int ToLines, int ToCols)
+{
+    return NCURSES_SP_NAME(resizeterm) (CURRENT_SCREEN, ToLines, ToCols);
+}
+#endif
diff --git a/ncurses/base/safe_sprintf.c b/ncurses/base/safe_sprintf.c
index 8fc5d89..34abd2f 100644
--- a/ncurses/base/safe_sprintf.c
+++ b/ncurses/base/safe_sprintf.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,13 +27,13 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ *  Author: Thomas E. Dickey        1997-on                                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: safe_sprintf.c,v 1.20 2007/04/21 22:28:06 tom Exp $")
+MODULE_ID("$Id: safe_sprintf.c,v 1.27 2013/01/20 01:04:32 tom Exp $")
 
 #if USE_SAFE_SPRINTF
 
@@ -109,12 +109,16 @@
 		    } else if (state == Prec) {
 			prec = ival;
 		    }
-		    sprintf(fmt_arg, "%d", ival);
+		    _nc_SPRINTF(fmt_arg,
+				_nc_SLIMIT(sizeof(fmt_arg))
+				"%d", ival);
 		    fmt_len += strlen(fmt_arg);
-		    if ((format = realloc(format, fmt_len)) == 0) {
+		    if ((format = _nc_doalloc(format, fmt_len)) == 0) {
+			free(buffer);
 			return -1;
 		    }
-		    strcpy(&format[--f], fmt_arg);
+		    --f;
+		    _nc_STRCPY(&format[f], fmt_arg, fmt_len - f);
 		    f = strlen(format);
 		} else if (isalpha(UChar(*fmt))) {
 		    done = TRUE;
@@ -185,13 +189,13 @@
 	    format[f] = '\0';
 	    switch (used) {
 	    case 'i':
-		sprintf(buffer, format, ival);
+		_nc_SPRINTF(buffer, _nc_SLIMIT(length) format, ival);
 		break;
 	    case 'f':
-		sprintf(buffer, format, fval);
+		_nc_SPRINTF(buffer, _nc_SLIMIT(length) format, fval);
 		break;
 	    default:
-		sprintf(buffer, format, pval);
+		_nc_SPRINTF(buffer, _nc_SLIMIT(length) format, pval);
 		break;
 	    }
 	    len += (int) strlen(buffer);
@@ -214,13 +218,20 @@
  * 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)
+NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_DCLx
+				    const char *fmt,
+				    va_list ap)
 {
     char *result = 0;
 
     if (fmt != 0) {
 #if USE_SAFE_SPRINTF
-	int len = _nc_printf_length(fmt, ap);
+	va_list ap2;
+	int len;
+
+	begin_va_copy(ap2, ap);
+	len = _nc_printf_length(fmt, ap2);
+	end_va_copy(ap2);
 
 	if ((int) my_length < len + 1) {
 	    my_length = 2 * (len + 1);
@@ -237,12 +248,12 @@
 #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;
+	if (screen_lines(SP_PARM) > MyRows || screen_columns(SP_PARM) > MyCols) {
+	    if (screen_lines(SP_PARM) > MyRows)
+		MyRows = screen_lines(SP_PARM);
+	    if (screen_columns(SP_PARM) > MyCols)
+		MyCols = screen_columns(SP_PARM);
+	    my_length = (size_t) (MyRows * (MyCols + 1)) + 1;
 	    my_buffer = typeRealloc(char, my_length, my_buffer);
 	}
 
@@ -262,3 +273,11 @@
     }
     return result;
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char *)
+_nc_printf_string(const char *fmt, va_list ap)
+{
+    return NCURSES_SP_NAME(_nc_printf_string) (CURRENT_SCREEN, fmt, ap);
+}
+#endif
diff --git a/ncurses/base/tries.c b/ncurses/base/tries.c
index c4263c7..ad85d22 100644
--- a/ncurses/base/tries.c
+++ b/ncurses/base/tries.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: tries.c,v 1.27 2008/08/16 19:22:55 tom Exp $")
+MODULE_ID("$Id: tries.c,v 1.30 2010/08/28 21:08:23 tom Exp $")
 
 /*
  * Expand a keycode into the string that it corresponds to, returning null if
@@ -72,7 +72,9 @@
 	    *((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));
+	    _tracef("expand_key %s %s",
+		    _nc_tracechar(CURRENT_SCREEN, (int) code),
+		    _nc_visbuf(result));
 	    _nc_unlock_global(tracef);
 	}
 #endif
@@ -87,7 +89,7 @@
 NCURSES_EXPORT(int)
 _nc_remove_key(TRIES ** tree, unsigned code)
 {
-    T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code));
+    T((T_CALLED("_nc_remove_key(%p,%d)"), (void *) tree, code));
 
     if (code == 0)
 	returnCode(FALSE);
@@ -119,7 +121,7 @@
 NCURSES_EXPORT(int)
 _nc_remove_string(TRIES ** tree, const char *string)
 {
-    T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string)));
+    T((T_CALLED("_nc_remove_string(%p,%s)"), (void *) tree, _nc_visbuf(string)));
 
     if (string == 0 || *string == 0)
 	returnCode(FALSE);
diff --git a/ncurses/base/use_window.c b/ncurses/base/use_window.c
index f6408c3..8eb7339 100644
--- a/ncurses/base/use_window.c
+++ b/ncurses/base/use_window.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2007,2008 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2007-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -32,14 +32,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: use_window.c,v 1.8 2008/06/07 14:13:46 tom Exp $")
+MODULE_ID("$Id: use_window.c,v 1.9 2009/10/24 22:40:24 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));
+    T((T_CALLED("use_window(%p,%p,%p)"), (void *) win, func, data));
     _nc_lock_global(curses);
     code = func(win, data);
     _nc_unlock_global(curses);
diff --git a/ncurses/base/vsscanf.c b/ncurses/base/vsscanf.c
index e6253c3..38c7926 100644
--- a/ncurses/base/vsscanf.c
+++ b/ncurses/base/vsscanf.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2004,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -38,7 +38,7 @@
 
 #if !HAVE_VSSCANF
 
-MODULE_ID("$Id: vsscanf.c,v 1.18 2004/04/03 20:27:02 tom Exp $")
+MODULE_ID("$Id: vsscanf.c,v 1.20 2012/02/22 22:26:58 tom Exp $")
 
 #if !(HAVE_VFSCANF || HAVE__DOSCAN)
 
@@ -293,12 +293,12 @@
 
 		/* add %n, if the format was not that */
 		if (chunk != cAssigned) {
-		    strcat(my_fmt, "%n");
+		    _nc_STRCAT(my_fmt, "%n", len_fmt);
 		}
 
 		switch (chunk) {
 		case cAssigned:
-		    strcat(my_fmt, "%n");
+		    _nc_STRCAT(my_fmt, "%n", len_fmt);
 		    pointer = &eaten;
 		    break;
 		case cInt:
diff --git a/ncurses/base/wresize.c b/ncurses/base/wresize.c
index f46085a..bc6b573 100644
--- a/ncurses/base/wresize.c
+++ b/ncurses/base/wresize.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,12 +27,13 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey 1996-2002                                      *
+ *  Author: Thomas E. Dickey 1996-on                                        *
+ *     and: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: wresize.c,v 1.29 2008/06/07 13:59:01 tom Exp $")
+MODULE_ID("$Id: wresize.c,v 1.35 2011/05/21 18:55:07 tom Exp $")
 
 static int
 cleanup_lines(struct ldat *data, int length)
@@ -53,10 +54,13 @@
     WINDOWLIST *wp;
     struct ldat *pline = cmp->_line;
     int row;
+#ifdef USE_SP_WINDOWLIST
+    SCREEN *sp = _nc_screen_of(cmp);
+#endif
 
     _nc_lock_global(curses);
 
-    for (each_window(wp)) {
+    for (each_window(SP_PARM, wp)) {
 	WINDOW *tst = &(wp->win);
 
 	if (tst->_parent == cmp) {
@@ -67,9 +71,9 @@
 		tst->_parx = cmp->_maxx;
 
 	    if (tst->_maxy + tst->_pary > cmp->_maxy)
-		tst->_maxy = cmp->_maxy - tst->_pary;
+		tst->_maxy = (NCURSES_SIZE_T) (cmp->_maxy - tst->_pary);
 	    if (tst->_maxx + tst->_parx > cmp->_maxx)
-		tst->_maxx = cmp->_maxx - tst->_parx;
+		tst->_maxx = (NCURSES_SIZE_T) (cmp->_maxx - tst->_parx);
 
 	    for (row = 0; row <= tst->_maxy; ++row) {
 		tst->_line[row].text = &pline[tst->_pary + row].text[tst->_parx];
@@ -93,7 +97,7 @@
     struct ldat *new_lines = 0;
 
 #ifdef TRACE
-    T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols));
+    T((T_CALLED("wresize(%p,%d,%d)"), (void *) win, ToLines, ToCols));
     if (win) {
 	TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)",
 			  (long) win->_begy, (long) win->_begx,
@@ -153,7 +157,8 @@
 	if (!(win->_flags & _SUBWIN)) {
 	    if (row <= size_y) {
 		if (ToCols != size_x) {
-		    if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
+		    s = typeMalloc(NCURSES_CH_T, (unsigned) ToCols + 1);
+		    if (s == 0)
 			returnCode(cleanup_lines(new_lines, row));
 		    for (col = 0; col <= ToCols; ++col) {
 			s[col] = (col <= size_x
@@ -164,13 +169,16 @@
 		    s = win->_line[row].text;
 		}
 	    } else {
-		if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
+		s = typeMalloc(NCURSES_CH_T, (unsigned) ToCols + 1);
+		if (s == 0)
 		    returnCode(cleanup_lines(new_lines, row));
 		for (col = 0; col <= ToCols; ++col)
 		    s[col] = win->_nc_bkgd;
 	    }
-	} else {
+	} else if (pline != 0 && pline[win->_pary + row].text != 0) {
 	    s = &pline[win->_pary + row].text[win->_parx];
+	} else {
+	    s = 0;
 	}
 
 	if_USE_SCROLL_HINTS(new_lines[row].oldindex = row);
@@ -181,11 +189,11 @@
 	if ((ToCols != size_x) || (row > size_y)) {
 	    if (end >= begin) {	/* growing */
 		if (new_lines[row].firstchar < begin)
-		    new_lines[row].firstchar = begin;
+		    new_lines[row].firstchar = (NCURSES_SIZE_T) begin;
 	    } else {		/* shrinking */
 		new_lines[row].firstchar = 0;
 	    }
-	    new_lines[row].lastchar = ToCols;
+	    new_lines[row].lastchar = (NCURSES_SIZE_T) ToCols;
 	}
 	new_lines[row].text = s;
     }
@@ -212,8 +220,8 @@
      * Finally, adjust the parameters showing screen size and cursor
      * position:
      */
-    win->_maxx = ToCols;
-    win->_maxy = ToLines;
+    win->_maxx = (NCURSES_SIZE_T) ToCols;
+    win->_maxy = (NCURSES_SIZE_T) ToLines;
 
     if (win->_regtop > win->_maxy)
 	win->_regtop = win->_maxy;
diff --git a/ncurses/build.priv.h b/ncurses/build.priv.h
new file mode 100644
index 0000000..096a443
--- /dev/null
+++ b/ncurses/build.priv.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+ * Copyright (c) 2010,2012 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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                        2010                    *
+ ****************************************************************************/
+
+/*
+ * $Id: build.priv.h,v 1.9 2012/02/22 22:17:02 tom Exp $
+ *
+ *	build.priv.h
+ *
+ *	This is a reduced version of curses.priv.h, for build-time utilties.
+ *	Because it has fewer dependencies, this simplifies cross-compiling.
+ *
+ */
+
+#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>
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <errno.h>
+
+#include <curses.h>	/* we'll use -Ipath directive to get the right one! */
+
+/* usually in <unistd.h> */
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+#define FreeAndNull(p)   free(p); p = 0
+#define UChar(c)         ((unsigned char)(c))
+#define SIZEOF(v)        (sizeof(v) / sizeof(v[0]))
+
+#include <nc_alloc.h>
+#include <nc_string.h>
+
+/* declare these, to avoid needing term.h */
+#if BROKEN_LINKER || USE_REENTRANT
+#define NCURSES_ARRAY(name) \
+	NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, name)
+
+NCURSES_ARRAY(boolnames);
+NCURSES_ARRAY(boolfnames);
+NCURSES_ARRAY(numnames);
+NCURSES_ARRAY(numfnames);
+NCURSES_ARRAY(strnames);
+NCURSES_ARRAY(strfnames);
+#endif
+
+#if NO_LEAKS
+NCURSES_EXPORT(void) _nc_names_leaks(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CURSES_PRIV_H */
diff --git a/ncurses/codes.c b/ncurses/codes.c
deleted file mode 100644
index 14c785a..0000000
--- a/ncurses/codes.c
+++ /dev/null
@@ -1,666 +0,0 @@
-/* This file was generated by MKcodes.awk */
-
-#include <curses.priv.h>
-
-#define IT NCURSES_CONST char * const
-
-
-#if BROKEN_LINKER || USE_REENTRANT
-
-#include <term.h>
-
-static const char _nc_code_blob[] = 
-"bw\0" "am\0" "xb\0" "xs\0" "xn\0" "eo\0" "gn\0" "hc\0" "km\0" "hs\0" "in\0" \
-"da\0" "db\0" "mi\0" "ms\0" "os\0" "es\0" "xt\0" "hz\0" "ul\0" "xo\0" "nx\0" \
-"5i\0" "HC\0" "NR\0" "NP\0" "ND\0" "cc\0" "ut\0" "hl\0" "YA\0" "YB\0" "YC\0" \
-"YD\0" "YE\0" "YF\0" "YG\0" "co\0" "it\0" "li\0" "lm\0" "sg\0" "pb\0" "vt\0" \
-"ws\0" "Nl\0" "lh\0" "lw\0" "ma\0" "MW\0" "Co\0" "pa\0" "NC\0" "Ya\0" "Yb\0" \
-"Yc\0" "Yd\0" "Ye\0" "Yf\0" "Yg\0" "Yh\0" "Yi\0" "Yj\0" "Yk\0" "Yl\0" "Ym\0" \
-"Yn\0" "BT\0" "Yo\0" "Yp\0" "bt\0" "bl\0" "cr\0" "cs\0" "ct\0" "cl\0" "ce\0" \
-"cd\0" "ch\0" "CC\0" "cm\0" "do\0" "ho\0" "vi\0" "le\0" "CM\0" "ve\0" "nd\0" \
-"ll\0" "up\0" "vs\0" "dc\0" "dl\0" "ds\0" "hd\0" "as\0" "mb\0" "md\0" "ti\0" \
-"dm\0" "mh\0" "im\0" "mk\0" "mp\0" "mr\0" "so\0" "us\0" "ec\0" "ae\0" "me\0" \
-"te\0" "ed\0" "ei\0" "se\0" "ue\0" "vb\0" "ff\0" "fs\0" "i1\0" "is\0" "i3\0" \
-"if\0" "ic\0" "al\0" "ip\0" "kb\0" "ka\0" "kC\0" "kt\0" "kD\0" "kL\0" "kd\0" \
-"kM\0" "kE\0" "kS\0" "k0\0" "k1\0" "k;\0" "k2\0" "k3\0" "k4\0" "k5\0" "k6\0" \
-"k7\0" "k8\0" "k9\0" "kh\0" "kI\0" "kA\0" "kl\0" "kH\0" "kN\0" "kP\0" "kr\0" \
-"kF\0" "kR\0" "kT\0" "ku\0" "ke\0" "ks\0" "l0\0" "l1\0" "la\0" "l2\0" "l3\0" \
-"l4\0" "l5\0" "l6\0" "l7\0" "l8\0" "l9\0" "mo\0" "mm\0" "nw\0" "pc\0" "DC\0" \
-"DL\0" "DO\0" "IC\0" "SF\0" "AL\0" "LE\0" "RI\0" "SR\0" "UP\0" "pk\0" "pl\0" \
-"px\0" "ps\0" "pf\0" "po\0" "rp\0" "r1\0" "r2\0" "r3\0" "rf\0" "rc\0" "cv\0" \
-"sc\0" "sf\0" "sr\0" "sa\0" "st\0" "wi\0" "ta\0" "ts\0" "uc\0" "hu\0" "iP\0" \
-"K1\0" "K3\0" "K2\0" "K4\0" "K5\0" "pO\0" "rP\0" "ac\0" "pn\0" "kB\0" "SX\0" \
-"RX\0" "SA\0" "RA\0" "XN\0" "XF\0" "eA\0" "LO\0" "LF\0" "@1\0" "@2\0" "@3\0" \
-"@4\0" "@5\0" "@6\0" "@7\0" "@8\0" "@9\0" "@0\0" "%1\0" "%2\0" "%3\0" "%4\0" \
-"%5\0" "%6\0" "%7\0" "%8\0" "%9\0" "%0\0" "&1\0" "&2\0" "&3\0" "&4\0" "&5\0" \
-"&6\0" "&7\0" "&8\0" "&9\0" "&0\0" "*1\0" "*2\0" "*3\0" "*4\0" "*5\0" "*6\0" \
-"*7\0" "*8\0" "*9\0" "*0\0" "#1\0" "#2\0" "#3\0" "#4\0" "%a\0" "%b\0" "%c\0" \
-"%d\0" "%e\0" "%f\0" "%g\0" "%h\0" "%i\0" "%j\0" "!1\0" "!2\0" "!3\0" "RF\0" \
-"F1\0" "F2\0" "F3\0" "F4\0" "F5\0" "F6\0" "F7\0" "F8\0" "F9\0" "FA\0" "FB\0" \
-"FC\0" "FD\0" "FE\0" "FF\0" "FG\0" "FH\0" "FI\0" "FJ\0" "FK\0" "FL\0" "FM\0" \
-"FN\0" "FO\0" "FP\0" "FQ\0" "FR\0" "FS\0" "FT\0" "FU\0" "FV\0" "FW\0" "FX\0" \
-"FY\0" "FZ\0" "Fa\0" "Fb\0" "Fc\0" "Fd\0" "Fe\0" "Ff\0" "Fg\0" "Fh\0" "Fi\0" \
-"Fj\0" "Fk\0" "Fl\0" "Fm\0" "Fn\0" "Fo\0" "Fp\0" "Fq\0" "Fr\0" "cb\0" "MC\0" \
-"ML\0" "MR\0" "Lf\0" "SC\0" "DK\0" "RC\0" "CW\0" "WG\0" "HU\0" "DI\0" "QD\0" \
-"TO\0" "PU\0" "fh\0" "PA\0" "WA\0" "u0\0" "u1\0" "u2\0" "u3\0" "u4\0" "u5\0" \
-"u6\0" "u7\0" "u8\0" "u9\0" "op\0" "oc\0" "Ic\0" "Ip\0" "sp\0" "Sf\0" "Sb\0" \
-"ZA\0" "ZB\0" "ZC\0" "ZD\0" "ZE\0" "ZF\0" "ZG\0" "ZH\0" "ZI\0" "ZJ\0" "ZK\0" \
-"ZL\0" "ZM\0" "ZN\0" "ZO\0" "ZP\0" "ZQ\0" "ZR\0" "ZS\0" "ZT\0" "ZU\0" "ZV\0" \
-"ZW\0" "ZX\0" "ZY\0" "ZZ\0" "Za\0" "Zb\0" "Zc\0" "Zd\0" "Ze\0" "Zf\0" "Zg\0" \
-"Zh\0" "Zi\0" "Zj\0" "Zk\0" "Zl\0" "Zm\0" "Zn\0" "Zo\0" "Zp\0" "Zq\0" "Zr\0" \
-"Zs\0" "Zt\0" "Zu\0" "Zv\0" "Zw\0" "Zx\0" "Zy\0" "Km\0" "Mi\0" "RQ\0" "Gm\0" \
-"AF\0" "AB\0" "xl\0" "dv\0" "ci\0" "s0\0" "s1\0" "s2\0" "s3\0" "ML\0" "MT\0" \
-"Xy\0" "Zz\0" "Yv\0" "Yw\0" "Yx\0" "Yy\0" "Yz\0" "YZ\0" "S1\0" "S2\0" "S3\0" \
-"S4\0" "S5\0" "S6\0" "S7\0" "S8\0" "Xh\0" "Xl\0" "Xo\0" "Xr\0" "Xt\0" "Xv\0" \
-"sA\0" "sL\0" "i2\0" "rs\0" "ug\0" "bs\0" "ns\0" "nc\0" "dC\0" "dN\0" "nl\0" \
-"bc\0" "MT\0" "NL\0" "dB\0" "dT\0" "kn\0" "ko\0" "ma\0" "pt\0" "xr\0" "G2\0" \
-"G3\0" "G1\0" "G4\0" "GR\0" "GL\0" "GU\0" "GD\0" "GH\0" "GV\0" "GC\0" "ml\0" \
-"mu\0" "bx\0" ;
-static const short _nc_offset_boolcodes[] = {
-0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42,
-45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87,
-90, 93, 96, 99, 102, 105, 108, 1401, 1404, 1407, 1422, 1425, 1443, 1446, };
-
-static NCURSES_CONST char ** ptr_boolcodes = 0;
-
-static const short _nc_offset_numcodes[] = {
-111, 114, 117, 120, 123, 126,
-129, 132, 135, 138, 141, 144, 147, 150, 153, 156, 159, 162,
-165, 168, 171, 174, 177, 180, 183, 186, 189, 192, 195, 198,
-201, 204, 207, 1398, 1410, 1413, 1428, 1431, 1434, };
-
-static NCURSES_CONST char ** ptr_numcodes = 0;
-
-static const short _nc_offset_strcodes[] = {
-210, 213, 216, 219, 222, 225, 228, 231, 234,
-237, 240, 243, 246, 249, 252, 255, 258, 261, 264, 267, 270,
-273, 276, 279, 282, 285, 288, 291, 294, 297, 300, 303, 306,
-309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342,
-345, 348, 351, 354, 357, 360, 363, 366, 369, 372, 375, 378,
-381, 384, 387, 390, 393, 396, 399, 402, 405, 408, 411, 414,
-417, 420, 423, 426, 429, 432, 435, 438, 441, 444, 447, 450,
-453, 456, 459, 462, 465, 468, 471, 474, 477, 480, 483, 486,
-489, 492, 495, 498, 501, 504, 507, 510, 513, 516, 519, 522,
-525, 528, 531, 534, 537, 540, 543, 546, 549, 552, 555, 558,
-561, 564, 567, 570, 573, 576, 579, 582, 585, 588, 591, 594,
-597, 600, 603, 606, 609, 612, 615, 618, 621, 624, 627, 630,
-633, 636, 639, 642, 645, 648, 651, 654, 657, 660, 663, 666,
-669, 672, 675, 678, 681, 684, 687, 690, 693, 696, 699, 702,
-705, 708, 711, 714, 717, 720, 723, 726, 729, 732, 735, 738,
-741, 744, 747, 750, 753, 756, 759, 762, 765, 768, 771, 774,
-777, 780, 783, 786, 789, 792, 795, 798, 801, 804, 807, 810,
-813, 816, 819, 822, 825, 828, 831, 834, 837, 840, 843, 846,
-849, 852, 855, 858, 861, 864, 867, 870, 873, 876, 879, 882,
-885, 888, 891, 894, 897, 900, 903, 906, 909, 912, 915, 918,
-921, 924, 927, 930, 933, 936, 939, 942, 945, 948, 951, 954,
-957, 960, 963, 966, 969, 972, 975, 978, 981, 984, 987, 990,
-993, 996, 999, 1002, 1005, 1008, 1011, 1014, 1017, 1020, 1023,
-1026, 1029, 1032, 1035, 1038, 1041, 1044, 1047, 1050, 1053, 1056,
-1059, 1062, 1065, 1068, 1071, 1074, 1077, 1080, 1083, 1086, 1089,
-1092, 1095, 1098, 1101, 1104, 1107, 1110, 1113, 1116, 1119, 1122,
-1125, 1128, 1131, 1134, 1137, 1140, 1143, 1146, 1149, 1152, 1155,
-1158, 1161, 1164, 1167, 1170, 1173, 1176, 1179, 1182, 1185, 1188,
-1191, 1194, 1197, 1200, 1203, 1206, 1209, 1212, 1215, 1218, 1221,
-1224, 1227, 1230, 1233, 1236, 1239, 1242, 1245, 1248, 1251, 1254,
-1257, 1260, 1263, 1266, 1269, 1272, 1275, 1278, 1281, 1284, 1287,
-1290, 1293, 1296, 1299, 1302, 1305, 1308, 1311, 1314, 1317, 1320,
-1323, 1326, 1329, 1332, 1335, 1338, 1341, 1344, 1347, 1350, 1353,
-1356, 1359, 1362, 1365, 1368, 1371, 1374, 1377, 1380, 1383, 1386,
-1389, 1392, 1395, 1416, 1419,
-1437, 1440, 1449, 1452,
-1455, 1458, 1461, 1464, 1467, 1470, 1473, 1476, 1479, 1482, 1485,
-1488, };
-
-static NCURSES_CONST char ** ptr_strcodes = 0;
-
-
-static IT *
-alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)
-{
-	if (*value == 0) {
-		if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {
-			unsigned n;
-			for (n = 0; n < size; ++n) {
-				(*value)[n] = _nc_code_blob + offsets[n];
-			}
-		}
-	}
-	return *value;
-}
-
-#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }
-
-FIX(boolcodes)
-FIX(numcodes)
-FIX(strcodes)
-
-#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }
-
-#if NO_LEAKS
-NCURSES_EXPORT(void)
-_nc_codes_leaks(void)
-{
-FREE_FIX(boolcodes)
-FREE_FIX(numcodes)
-FREE_FIX(strcodes)
-}
-#endif
-
-#else
-
-#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]
-
-DCL(boolcodes) = {
-		"bw",
-		"am",
-		"xb",
-		"xs",
-		"xn",
-		"eo",
-		"gn",
-		"hc",
-		"km",
-		"hs",
-		"in",
-		"da",
-		"db",
-		"mi",
-		"ms",
-		"os",
-		"es",
-		"xt",
-		"hz",
-		"ul",
-		"xo",
-		"nx",
-		"5i",
-		"HC",
-		"NR",
-		"NP",
-		"ND",
-		"cc",
-		"ut",
-		"hl",
-		"YA",
-		"YB",
-		"YC",
-		"YD",
-		"YE",
-		"YF",
-		"YG",
-		"bs",
-		"ns",
-		"nc",
-		"MT",
-		"NL",
-		"pt",
-		"xr",
-
-		(NCURSES_CONST char *)0,
-};
-
-DCL(numcodes) = {
-		"co",
-		"it",
-		"li",
-		"lm",
-		"sg",
-		"pb",
-		"vt",
-		"ws",
-		"Nl",
-		"lh",
-		"lw",
-		"ma",
-		"MW",
-		"Co",
-		"pa",
-		"NC",
-		"Ya",
-		"Yb",
-		"Yc",
-		"Yd",
-		"Ye",
-		"Yf",
-		"Yg",
-		"Yh",
-		"Yi",
-		"Yj",
-		"Yk",
-		"Yl",
-		"Ym",
-		"Yn",
-		"BT",
-		"Yo",
-		"Yp",
-		"ug",
-		"dC",
-		"dN",
-		"dB",
-		"dT",
-		"kn",
-
-		(NCURSES_CONST char *)0,
-};
-
-DCL(strcodes) = {
-		"bt",
-		"bl",
-		"cr",
-		"cs",
-		"ct",
-		"cl",
-		"ce",
-		"cd",
-		"ch",
-		"CC",
-		"cm",
-		"do",
-		"ho",
-		"vi",
-		"le",
-		"CM",
-		"ve",
-		"nd",
-		"ll",
-		"up",
-		"vs",
-		"dc",
-		"dl",
-		"ds",
-		"hd",
-		"as",
-		"mb",
-		"md",
-		"ti",
-		"dm",
-		"mh",
-		"im",
-		"mk",
-		"mp",
-		"mr",
-		"so",
-		"us",
-		"ec",
-		"ae",
-		"me",
-		"te",
-		"ed",
-		"ei",
-		"se",
-		"ue",
-		"vb",
-		"ff",
-		"fs",
-		"i1",
-		"is",
-		"i3",
-		"if",
-		"ic",
-		"al",
-		"ip",
-		"kb",
-		"ka",
-		"kC",
-		"kt",
-		"kD",
-		"kL",
-		"kd",
-		"kM",
-		"kE",
-		"kS",
-		"k0",
-		"k1",
-		"k;",
-		"k2",
-		"k3",
-		"k4",
-		"k5",
-		"k6",
-		"k7",
-		"k8",
-		"k9",
-		"kh",
-		"kI",
-		"kA",
-		"kl",
-		"kH",
-		"kN",
-		"kP",
-		"kr",
-		"kF",
-		"kR",
-		"kT",
-		"ku",
-		"ke",
-		"ks",
-		"l0",
-		"l1",
-		"la",
-		"l2",
-		"l3",
-		"l4",
-		"l5",
-		"l6",
-		"l7",
-		"l8",
-		"l9",
-		"mo",
-		"mm",
-		"nw",
-		"pc",
-		"DC",
-		"DL",
-		"DO",
-		"IC",
-		"SF",
-		"AL",
-		"LE",
-		"RI",
-		"SR",
-		"UP",
-		"pk",
-		"pl",
-		"px",
-		"ps",
-		"pf",
-		"po",
-		"rp",
-		"r1",
-		"r2",
-		"r3",
-		"rf",
-		"rc",
-		"cv",
-		"sc",
-		"sf",
-		"sr",
-		"sa",
-		"st",
-		"wi",
-		"ta",
-		"ts",
-		"uc",
-		"hu",
-		"iP",
-		"K1",
-		"K3",
-		"K2",
-		"K4",
-		"K5",
-		"pO",
-		"rP",
-		"ac",
-		"pn",
-		"kB",
-		"SX",
-		"RX",
-		"SA",
-		"RA",
-		"XN",
-		"XF",
-		"eA",
-		"LO",
-		"LF",
-		"@1",
-		"@2",
-		"@3",
-		"@4",
-		"@5",
-		"@6",
-		"@7",
-		"@8",
-		"@9",
-		"@0",
-		"%1",
-		"%2",
-		"%3",
-		"%4",
-		"%5",
-		"%6",
-		"%7",
-		"%8",
-		"%9",
-		"%0",
-		"&1",
-		"&2",
-		"&3",
-		"&4",
-		"&5",
-		"&6",
-		"&7",
-		"&8",
-		"&9",
-		"&0",
-		"*1",
-		"*2",
-		"*3",
-		"*4",
-		"*5",
-		"*6",
-		"*7",
-		"*8",
-		"*9",
-		"*0",
-		"#1",
-		"#2",
-		"#3",
-		"#4",
-		"%a",
-		"%b",
-		"%c",
-		"%d",
-		"%e",
-		"%f",
-		"%g",
-		"%h",
-		"%i",
-		"%j",
-		"!1",
-		"!2",
-		"!3",
-		"RF",
-		"F1",
-		"F2",
-		"F3",
-		"F4",
-		"F5",
-		"F6",
-		"F7",
-		"F8",
-		"F9",
-		"FA",
-		"FB",
-		"FC",
-		"FD",
-		"FE",
-		"FF",
-		"FG",
-		"FH",
-		"FI",
-		"FJ",
-		"FK",
-		"FL",
-		"FM",
-		"FN",
-		"FO",
-		"FP",
-		"FQ",
-		"FR",
-		"FS",
-		"FT",
-		"FU",
-		"FV",
-		"FW",
-		"FX",
-		"FY",
-		"FZ",
-		"Fa",
-		"Fb",
-		"Fc",
-		"Fd",
-		"Fe",
-		"Ff",
-		"Fg",
-		"Fh",
-		"Fi",
-		"Fj",
-		"Fk",
-		"Fl",
-		"Fm",
-		"Fn",
-		"Fo",
-		"Fp",
-		"Fq",
-		"Fr",
-		"cb",
-		"MC",
-		"ML",
-		"MR",
-		"Lf",
-		"SC",
-		"DK",
-		"RC",
-		"CW",
-		"WG",
-		"HU",
-		"DI",
-		"QD",
-		"TO",
-		"PU",
-		"fh",
-		"PA",
-		"WA",
-		"u0",
-		"u1",
-		"u2",
-		"u3",
-		"u4",
-		"u5",
-		"u6",
-		"u7",
-		"u8",
-		"u9",
-		"op",
-		"oc",
-		"Ic",
-		"Ip",
-		"sp",
-		"Sf",
-		"Sb",
-		"ZA",
-		"ZB",
-		"ZC",
-		"ZD",
-		"ZE",
-		"ZF",
-		"ZG",
-		"ZH",
-		"ZI",
-		"ZJ",
-		"ZK",
-		"ZL",
-		"ZM",
-		"ZN",
-		"ZO",
-		"ZP",
-		"ZQ",
-		"ZR",
-		"ZS",
-		"ZT",
-		"ZU",
-		"ZV",
-		"ZW",
-		"ZX",
-		"ZY",
-		"ZZ",
-		"Za",
-		"Zb",
-		"Zc",
-		"Zd",
-		"Ze",
-		"Zf",
-		"Zg",
-		"Zh",
-		"Zi",
-		"Zj",
-		"Zk",
-		"Zl",
-		"Zm",
-		"Zn",
-		"Zo",
-		"Zp",
-		"Zq",
-		"Zr",
-		"Zs",
-		"Zt",
-		"Zu",
-		"Zv",
-		"Zw",
-		"Zx",
-		"Zy",
-		"Km",
-		"Mi",
-		"RQ",
-		"Gm",
-		"AF",
-		"AB",
-		"xl",
-		"dv",
-		"ci",
-		"s0",
-		"s1",
-		"s2",
-		"s3",
-		"ML",
-		"MT",
-		"Xy",
-		"Zz",
-		"Yv",
-		"Yw",
-		"Yx",
-		"Yy",
-		"Yz",
-		"YZ",
-		"S1",
-		"S2",
-		"S3",
-		"S4",
-		"S5",
-		"S6",
-		"S7",
-		"S8",
-		"Xh",
-		"Xl",
-		"Xo",
-		"Xr",
-		"Xt",
-		"Xv",
-		"sA",
-		"sL",
-		"i2",
-		"rs",
-		"nl",
-		"bc",
-		"ko",
-		"ma",
-		"G2",
-		"G3",
-		"G1",
-		"G4",
-		"GR",
-		"GL",
-		"GU",
-		"GD",
-		"GH",
-		"GV",
-		"GC",
-		"ml",
-		"mu",
-		"bx",
-
-		(NCURSES_CONST char *)0,
-};
-
-
-#endif /* BROKEN_LINKER */
diff --git a/ncurses/comp_captab.c b/ncurses/comp_captab.c
deleted file mode 100644
index bb50ac3..0000000
--- a/ncurses/comp_captab.c
+++ /dev/null
@@ -1,3355 +0,0 @@
-/*
- *	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>
-
-static const char info_names_text[] = \
-"bw\0" "am\0" "xsb\0" "xhp\0" "xenl\0" "eo\0" "gn\0" "hc\0" "km\0" \
-"hs\0" "in\0" "da\0" "db\0" "mir\0" "msgr\0" "os\0" "eslok\0" "xt\0" \
-"hz\0" "ul\0" "xon\0" "nxon\0" "mc5i\0" "chts\0" "nrrmc\0" "npc\0" \
-"ndscr\0" "ccc\0" "bce\0" "hls\0" "xhpa\0" "crxm\0" "daisy\0" "xvpa\0" \
-"sam\0" "cpix\0" "lpix\0" "cols\0" "it\0" "lines\0" "lm\0" "xmc\0" \
-"pb\0" "vt\0" "wsl\0" "nlab\0" "lh\0" "lw\0" "ma\0" "wnum\0" "colors\0" \
-"pairs\0" "ncv\0" "bufsz\0" "spinv\0" "spinh\0" "maddr\0" "mjump\0" \
-"mcs\0" "mls\0" "npins\0" "orc\0" "orl\0" "orhi\0" "orvi\0" "cps\0" \
-"widcs\0" "btns\0" "bitwin\0" "bitype\0" "cbt\0" "bel\0" "cr\0" "csr\0" \
-"tbc\0" "clear\0" "el\0" "ed\0" "hpa\0" "cmdch\0" "cup\0" "cud1\0" \
-"home\0" "civis\0" "cub1\0" "mrcup\0" "cnorm\0" "cuf1\0" "ll\0" \
-"cuu1\0" "cvvis\0" "dch1\0" "dl1\0" "dsl\0" "hd\0" "smacs\0" "blink\0" \
-"bold\0" "smcup\0" "smdc\0" "dim\0" "smir\0" "invis\0" "prot\0" "rev\0" \
-"smso\0" "smul\0" "ech\0" "rmacs\0" "sgr0\0" "rmcup\0" "rmdc\0" \
-"rmir\0" "rmso\0" "rmul\0" "flash\0" "ff\0" "fsl\0" "is1\0" "is2\0" \
-"is3\0" "if\0" "ich1\0" "il1\0" "ip\0" "kbs\0" "ktbc\0" "kclr\0" \
-"kctab\0" "kdch1\0" "kdl1\0" "kcud1\0" "krmir\0" "kel\0" "ked\0" \
-"kf0\0" "kf1\0" "kf10\0" "kf2\0" "kf3\0" "kf4\0" "kf5\0" "kf6\0" \
-"kf7\0" "kf8\0" "kf9\0" "khome\0" "kich1\0" "kil1\0" "kcub1\0" "kll\0" \
-"knp\0" "kpp\0" "kcuf1\0" "kind\0" "kri\0" "khts\0" "kcuu1\0" "rmkx\0" \
-"smkx\0" "lf0\0" "lf1\0" "lf10\0" "lf2\0" "lf3\0" "lf4\0" "lf5\0" \
-"lf6\0" "lf7\0" "lf8\0" "lf9\0" "rmm\0" "smm\0" "nel\0" "pad\0" "dch\0" \
-"dl\0" "cud\0" "ich\0" "indn\0" "il\0" "cub\0" "cuf\0" "rin\0" "cuu\0" \
-"pfkey\0" "pfloc\0" "pfx\0" "mc0\0" "mc4\0" "mc5\0" "rep\0" "rs1\0" \
-"rs2\0" "rs3\0" "rf\0" "rc\0" "vpa\0" "sc\0" "ind\0" "ri\0" "sgr\0" \
-"hts\0" "wind\0" "ht\0" "tsl\0" "uc\0" "hu\0" "iprog\0" "ka1\0" "ka3\0" \
-"kb2\0" "kc1\0" "kc3\0" "mc5p\0" "rmp\0" "acsc\0" "pln\0" "kcbt\0" \
-"smxon\0" "rmxon\0" "smam\0" "rmam\0" "xonc\0" "xoffc\0" "enacs\0" \
-"smln\0" "rmln\0" "kbeg\0" "kcan\0" "kclo\0" "kcmd\0" "kcpy\0" "kcrt\0" \
-"kend\0" "kent\0" "kext\0" "kfnd\0" "khlp\0" "kmrk\0" "kmsg\0" "kmov\0" \
-"knxt\0" "kopn\0" "kopt\0" "kprv\0" "kprt\0" "krdo\0" "kref\0" "krfr\0" \
-"krpl\0" "krst\0" "kres\0" "ksav\0" "kspd\0" "kund\0" "kBEG\0" "kCAN\0" \
-"kCMD\0" "kCPY\0" "kCRT\0" "kDC\0" "kDL\0" "kslt\0" "kEND\0" "kEOL\0" \
-"kEXT\0" "kFND\0" "kHLP\0" "kHOM\0" "kIC\0" "kLFT\0" "kMSG\0" "kMOV\0" \
-"kNXT\0" "kOPT\0" "kPRV\0" "kPRT\0" "kRDO\0" "kRPL\0" "kRIT\0" "kRES\0" \
-"kSAV\0" "kSPD\0" "kUND\0" "rfi\0" "kf11\0" "kf12\0" "kf13\0" "kf14\0" \
-"kf15\0" "kf16\0" "kf17\0" "kf18\0" "kf19\0" "kf20\0" "kf21\0" "kf22\0" \
-"kf23\0" "kf24\0" "kf25\0" "kf26\0" "kf27\0" "kf28\0" "kf29\0" "kf30\0" \
-"kf31\0" "kf32\0" "kf33\0" "kf34\0" "kf35\0" "kf36\0" "kf37\0" "kf38\0" \
-"kf39\0" "kf40\0" "kf41\0" "kf42\0" "kf43\0" "kf44\0" "kf45\0" "kf46\0" \
-"kf47\0" "kf48\0" "kf49\0" "kf50\0" "kf51\0" "kf52\0" "kf53\0" "kf54\0" \
-"kf55\0" "kf56\0" "kf57\0" "kf58\0" "kf59\0" "kf60\0" "kf61\0" "kf62\0" \
-"kf63\0" "el1\0" "mgc\0" "smgl\0" "smgr\0" "fln\0" "sclk\0" "dclk\0" \
-"rmclk\0" "cwin\0" "wingo\0" "hup\0" "dial\0" "qdial\0" "tone\0" \
-"pulse\0" "hook\0" "pause\0" "wait\0" "u0\0" "u1\0" "u2\0" "u3\0" \
-"u4\0" "u5\0" "u6\0" "u7\0" "u8\0" "u9\0" "op\0" "oc\0" "initc\0" \
-"initp\0" "scp\0" "setf\0" "setb\0" "cpi\0" "lpi\0" "chr\0" "cvr\0" \
-"defc\0" "swidm\0" "sdrfq\0" "sitm\0" "slm\0" "smicm\0" "snlq\0" \
-"snrmq\0" "sshm\0" "ssubm\0" "ssupm\0" "sum\0" "rwidm\0" "ritm\0" \
-"rlm\0" "rmicm\0" "rshm\0" "rsubm\0" "rsupm\0" "rum\0" "mhpa\0" \
-"mcud1\0" "mcub1\0" "mcuf1\0" "mvpa\0" "mcuu1\0" "porder\0" "mcud\0" \
-"mcub\0" "mcuf\0" "mcuu\0" "scs\0" "smgb\0" "smgbp\0" "smglp\0" \
-"smgrp\0" "smgt\0" "smgtp\0" "sbim\0" "scsd\0" "rbim\0" "rcsd\0" \
-"subcs\0" "supcs\0" "docr\0" "zerom\0" "csnm\0" "kmous\0" "minfo\0" \
-"reqmp\0" "getm\0" "setaf\0" "setab\0" "pfxl\0" "devt\0" "csin\0" \
-"s0ds\0" "s1ds\0" "s2ds\0" "s3ds\0" "smglr\0" "smgtb\0" "birep\0" \
-"binel\0" "bicr\0" "colornm\0" "defbi\0" "endbi\0" "setcolor\0" \
-"slines\0" "dispc\0" "smpch\0" "rmpch\0" "smsc\0" "rmsc\0" "pctrm\0" \
-"scesc\0" "scesa\0" "ehhlm\0" "elhlm\0" "elohlm\0" "erhlm\0" "ethlm\0" \
-"evhlm\0" "sgr1\0" "slength\0" "OTi2\0" "OTrs\0" "OTug\0" "OTbs\0" \
-"OTns\0" "OTnc\0" "OTdC\0" "OTdN\0" "OTnl\0" "OTbc\0" "OTMT\0" "OTNL\0" \
-"OTdB\0" "OTdT\0" "OTkn\0" "OTko\0" "OTma\0" "OTpt\0" "OTxr\0" "OTG2\0" \
-"OTG3\0" "OTG1\0" "OTG4\0" "OTGR\0" "OTGL\0" "OTGU\0" "OTGD\0" "OTGH\0" \
-"OTGV\0" "OTGC\0" "meml\0" "memu\0" "box1\0" ;
-
-static name_table_data const info_names_data[] =
-{
-	{               0,	   BOOLEAN,	  0,  -1 },
-	{               3,	   BOOLEAN,	  1,  -1 },
-	{               6,	   BOOLEAN,	  2,  -1 },
-	{              10,	   BOOLEAN,	  3,  -1 },
-	{              14,	   BOOLEAN,	  4,  -1 },
-	{              19,	   BOOLEAN,	  5,  -1 },
-	{              22,	   BOOLEAN,	  6,  -1 },
-	{              25,	   BOOLEAN,	  7,  -1 },
-	{              28,	   BOOLEAN,	  8,  -1 },
-	{              31,	   BOOLEAN,	  9,  -1 },
-	{              34,	   BOOLEAN,	 10,  -1 },
-	{              37,	   BOOLEAN,	 11,  -1 },
-	{              40,	   BOOLEAN,	 12,  -1 },
-	{              43,	   BOOLEAN,	 13,  -1 },
-	{              47,	   BOOLEAN,	 14,  -1 },
-	{              52,	   BOOLEAN,	 15,  -1 },
-	{              55,	   BOOLEAN,	 16,  -1 },
-	{              61,	   BOOLEAN,	 17,  -1 },
-	{              64,	   BOOLEAN,	 18,  -1 },
-	{              67,	   BOOLEAN,	 19,  -1 },
-	{              70,	   BOOLEAN,	 20,  -1 },
-	{              74,	   BOOLEAN,	 21,  -1 },
-	{              79,	   BOOLEAN,	 22,  -1 },
-	{              84,	   BOOLEAN,	 23,  -1 },
-	{              89,	   BOOLEAN,	 24,  -1 },
-	{              95,	   BOOLEAN,	 25,  -1 },
-	{              99,	   BOOLEAN,	 26,  -1 },
-	{             105,	   BOOLEAN,	 27,  -1 },
-	{             109,	   BOOLEAN,	 28,  -1 },
-	{             113,	   BOOLEAN,	 29,  -1 },
-	{             117,	   BOOLEAN,	 30,  -1 },
-	{             122,	   BOOLEAN,	 31,  -1 },
-	{             127,	   BOOLEAN,	 32,  -1 },
-	{             133,	   BOOLEAN,	 33,  -1 },
-	{             138,	   BOOLEAN,	 34,  -1 },
-	{             142,	   BOOLEAN,	 35,  -1 },
-	{             147,	   BOOLEAN,	 36,  -1 },
-	{             152,	    NUMBER,	  0,  -1 },
-	{             157,	    NUMBER,	  1,  -1 },
-	{             160,	    NUMBER,	  2,   6 },
-	{             166,	    NUMBER,	  3,  -1 },
-	{             169,	    NUMBER,	  4,  -1 },
-	{             173,	    NUMBER,	  5,  -1 },
-	{             176,	    NUMBER,	  6,  -1 },
-	{             179,	    NUMBER,	  7,  -1 },
-	{             183,	    NUMBER,	  8,  -1 },
-	{             188,	    NUMBER,	  9,  -1 },
-	{             191,	    NUMBER,	 10,  -1 },
-	{             194,	    NUMBER,	 11,  -1 },
-	{             197,	    NUMBER,	 12,  -1 },
-	{             202,	    NUMBER,	 13,  -1 },
-	{             209,	    NUMBER,	 14,  -1 },
-	{             215,	    NUMBER,	 15,  -1 },
-	{             219,	    NUMBER,	 16,  46 },
-	{             225,	    NUMBER,	 17,  -1 },
-	{             231,	    NUMBER,	 18,  -1 },
-	{             237,	    NUMBER,	 19,  -1 },
-	{             243,	    NUMBER,	 20,  -1 },
-	{             249,	    NUMBER,	 21,  -1 },
-	{             253,	    NUMBER,	 22,  -1 },
-	{             257,	    NUMBER,	 23,  -1 },
-	{             263,	    NUMBER,	 24,  -1 },
-	{             267,	    NUMBER,	 25,  -1 },
-	{             271,	    NUMBER,	 26,  -1 },
-	{             276,	    NUMBER,	 27,  -1 },
-	{             281,	    NUMBER,	 28,  -1 },
-	{             285,	    NUMBER,	 29,  -1 },
-	{             291,	    NUMBER,	 30,  -1 },
-	{             296,	    NUMBER,	 31,  -1 },
-	{             303,	    NUMBER,	 32,  68 },
-	{             310,	    STRING,	  0,  -1 },
-	{             314,	    STRING,	  1,  -1 },
-	{             318,	    STRING,	  2,  -1 },
-	{             321,	    STRING,	  3,  -1 },
-	{             325,	    STRING,	  4,  -1 },
-	{             329,	    STRING,	  5,  -1 },
-	{             335,	    STRING,	  6,  -1 },
-	{             338,	    STRING,	  7,  -1 },
-	{             341,	    STRING,	  8,  -1 },
-	{             345,	    STRING,	  9,  -1 },
-	{             351,	    STRING,	 10,  73 },
-	{             355,	    STRING,	 11,  -1 },
-	{             360,	    STRING,	 12,  -1 },
-	{             365,	    STRING,	 13,  -1 },
-	{             371,	    STRING,	 14,  -1 },
-	{             376,	    STRING,	 15,  -1 },
-	{             382,	    STRING,	 16,  -1 },
-	{             388,	    STRING,	 17,  -1 },
-	{             393,	    STRING,	 18,  -1 },
-	{             396,	    STRING,	 19,  -1 },
-	{             401,	    STRING,	 20,  -1 },
-	{             407,	    STRING,	 21,  -1 },
-	{             412,	    STRING,	 22,  -1 },
-	{             416,	    STRING,	 23,  -1 },
-	{             420,	    STRING,	 24,  -1 },
-	{             423,	    STRING,	 25,  -1 },
-	{             429,	    STRING,	 26,  -1 },
-	{             435,	    STRING,	 27,  -1 },
-	{             440,	    STRING,	 28,  -1 },
-	{             446,	    STRING,	 29,  -1 },
-	{             451,	    STRING,	 30,  -1 },
-	{             455,	    STRING,	 31,  -1 },
-	{             460,	    STRING,	 32,  -1 },
-	{             466,	    STRING,	 33,  -1 },
-	{             471,	    STRING,	 34,  -1 },
-	{             475,	    STRING,	 35,  -1 },
-	{             480,	    STRING,	 36,  -1 },
-	{             485,	    STRING,	 37,  -1 },
-	{             489,	    STRING,	 38,  -1 },
-	{             495,	    STRING,	 39,  -1 },
-	{             500,	    STRING,	 40,  -1 },
-	{             506,	    STRING,	 41,  -1 },
-	{             511,	    STRING,	 42,  -1 },
-	{             516,	    STRING,	 43,  -1 },
-	{             521,	    STRING,	 44,  -1 },
-	{             526,	    STRING,	 45,  -1 },
-	{             532,	    STRING,	 46,  -1 },
-	{             535,	    STRING,	 47,  -1 },
-	{             539,	    STRING,	 48,  -1 },
-	{             543,	    STRING,	 49,  59 },
-	{             547,	    STRING,	 50,  76 },
-	{             551,	    STRING,	 51,  -1 },
-	{             554,	    STRING,	 52,  20 },
-	{             559,	    STRING,	 53,  -1 },
-	{             563,	    STRING,	 54,  -1 },
-	{             566,	    STRING,	 55,  -1 },
-	{             570,	    STRING,	 56,  -1 },
-	{             575,	    STRING,	 57,  98 },
-	{             580,	    STRING,	 58,  -1 },
-	{             586,	    STRING,	 59,  -1 },
-	{             592,	    STRING,	 60,  -1 },
-	{             597,	    STRING,	 61,  -1 },
-	{             603,	    STRING,	 62,  -1 },
-	{             609,	    STRING,	 63,  -1 },
-	{             613,	    STRING,	 64,  -1 },
-	{             617,	    STRING,	 65,  -1 },
-	{             621,	    STRING,	 66,  -1 },
-	{             625,	    STRING,	 67,  -1 },
-	{             630,	    STRING,	 68,  -1 },
-	{             634,	    STRING,	 69,  -1 },
-	{             638,	    STRING,	 70,  -1 },
-	{             642,	    STRING,	 71,  61 },
-	{             646,	    STRING,	 72,  -1 },
-	{             650,	    STRING,	 73,  -1 },
-	{             654,	    STRING,	 74,  -1 },
-	{             658,	    STRING,	 75,  -1 },
-	{             662,	    STRING,	 76,  -1 },
-	{             668,	    STRING,	 77,  -1 },
-	{             674,	    STRING,	 78,  -1 },
-	{             679,	    STRING,	 79,  -1 },
-	{             685,	    STRING,	 80,  -1 },
-	{             689,	    STRING,	 81,  -1 },
-	{             693,	    STRING,	 82,  -1 },
-	{             697,	    STRING,	 83,  -1 },
-	{             703,	    STRING,	 84,  55 },
-	{             708,	    STRING,	 85, 105 },
-	{             712,	    STRING,	 86,  -1 },
-	{             717,	    STRING,	 87,  81 },
-	{             723,	    STRING,	 88,  -1 },
-	{             728,	    STRING,	 89,  -1 },
-	{             733,	    STRING,	 90,  -1 },
-	{             737,	    STRING,	 91,  -1 },
-	{             741,	    STRING,	 92,  -1 },
-	{             746,	    STRING,	 93,  -1 },
-	{             750,	    STRING,	 94,  33 },
-	{             754,	    STRING,	 95,  -1 },
-	{             758,	    STRING,	 96,  -1 },
-	{             762,	    STRING,	 97,  -1 },
-	{             766,	    STRING,	 98,   7 },
-	{             770,	    STRING,	 99,  94 },
-	{             774,	    STRING,	100,  -1 },
-	{             778,	    STRING,	101, 131 },
-	{             782,	    STRING,	102,  -1 },
-	{             786,	    STRING,	103,  -1 },
-	{             790,	    STRING,	104,  30 },
-	{             794,	    STRING,	105,  -1 },
-	{             798,	    STRING,	106,  -1 },
-	{             801,	    STRING,	107,  -1 },
-	{             805,	    STRING,	108,  -1 },
-	{             809,	    STRING,	109,  -1 },
-	{             814,	    STRING,	110,  -1 },
-	{             817,	    STRING,	111,  -1 },
-	{             821,	    STRING,	112, 156 },
-	{             825,	    STRING,	113,  -1 },
-	{             829,	    STRING,	114,  -1 },
-	{             833,	    STRING,	115,  51 },
-	{             839,	    STRING,	116,  -1 },
-	{             845,	    STRING,	117,  -1 },
-	{             849,	    STRING,	118,  -1 },
-	{             853,	    STRING,	119,  -1 },
-	{             857,	    STRING,	120,  -1 },
-	{             861,	    STRING,	121,  -1 },
-	{             865,	    STRING,	122,  -1 },
-	{             869,	    STRING,	123,  -1 },
-	{             873,	    STRING,	124, 126 },
-	{             877,	    STRING,	125,  -1 },
-	{             880,	    STRING,	126,  -1 },
-	{             883,	    STRING,	127,  -1 },
-	{             887,	    STRING,	128,  -1 },
-	{             890,	    STRING,	129,  -1 },
-	{             894,	    STRING,	130,  -1 },
-	{             897,	    STRING,	131,  -1 },
-	{             901,	    STRING,	132,  -1 },
-	{             905,	    STRING,	133,  -1 },
-	{             910,	    STRING,	134,  -1 },
-	{             913,	    STRING,	135,  -1 },
-	{             917,	    STRING,	136,  23 },
-	{             920,	    STRING,	137,  -1 },
-	{             923,	    STRING,	138,  -1 },
-	{             929,	    STRING,	139,  -1 },
-	{             933,	    STRING,	140,  -1 },
-	{             937,	    STRING,	141, 210 },
-	{             941,	    STRING,	142, 211 },
-	{             945,	    STRING,	143, 135 },
-	{             949,	    STRING,	144,  -1 },
-	{             954,	    STRING,	145,  -1 },
-	{             958,	    STRING,	146, 176 },
-	{             963,	    STRING,	147,  -1 },
-	{             967,	    STRING,	148, 194 },
-	{             972,	    STRING,	149,  -1 },
-	{             978,	    STRING,	150,  -1 },
-	{             984,	    STRING,	151, 137 },
-	{             989,	    STRING,	152,  -1 },
-	{             994,	    STRING,	153,  -1 },
-	{             999,	    STRING,	154,  -1 },
-	{            1005,	    STRING,	155,  -1 },
-	{            1011,	    STRING,	156,  -1 },
-	{            1016,	    STRING,	157,  -1 },
-	{            1021,	    STRING,	158,  -1 },
-	{            1026,	    STRING,	159,  -1 },
-	{            1031,	    STRING,	160,  -1 },
-	{            1036,	    STRING,	161,  -1 },
-	{            1041,	    STRING,	162,  -1 },
-	{            1046,	    STRING,	163,  54 },
-	{            1051,	    STRING,	164, 192 },
-	{            1056,	    STRING,	165,  -1 },
-	{            1061,	    STRING,	166,  -1 },
-	{            1066,	    STRING,	167, 193 },
-	{            1071,	    STRING,	168,  -1 },
-	{            1076,	    STRING,	169,  70 },
-	{            1081,	    STRING,	170, 235 },
-	{            1086,	    STRING,	171,  -1 },
-	{            1091,	    STRING,	172,  -1 },
-	{            1096,	    STRING,	173, 177 },
-	{            1101,	    STRING,	174,  -1 },
-	{            1106,	    STRING,	175,  -1 },
-	{            1111,	    STRING,	176,  -1 },
-	{            1116,	    STRING,	177,  -1 },
-	{            1121,	    STRING,	178,  -1 },
-	{            1126,	    STRING,	179, 239 },
-	{            1131,	    STRING,	180, 219 },
-	{            1136,	    STRING,	181,  80 },
-	{            1141,	    STRING,	182, 249 },
-	{            1146,	    STRING,	183, 252 },
-	{            1151,	    STRING,	184, 240 },
-	{            1156,	    STRING,	185, 254 },
-	{            1161,	    STRING,	186,  -1 },
-	{            1166,	    STRING,	187,  -1 },
-	{            1171,	    STRING,	188, 101 },
-	{            1176,	    STRING,	189,  -1 },
-	{            1181,	    STRING,	190,  -1 },
-	{            1186,	    STRING,	191,  -1 },
-	{            1190,	    STRING,	192,  -1 },
-	{            1194,	    STRING,	193, 244 },
-	{            1199,	    STRING,	194,  -1 },
-	{            1204,	    STRING,	195, 152 },
-	{            1209,	    STRING,	196,  -1 },
-	{            1214,	    STRING,	197, 150 },
-	{            1219,	    STRING,	198,  -1 },
-	{            1224,	    STRING,	199, 268 },
-	{            1229,	    STRING,	200,  -1 },
-	{            1233,	    STRING,	201,  72 },
-	{            1238,	    STRING,	202,  -1 },
-	{            1243,	    STRING,	203,  -1 },
-	{            1248,	    STRING,	204,  -1 },
-	{            1253,	    STRING,	205,  -1 },
-	{            1258,	    STRING,	206,  -1 },
-	{            1263,	    STRING,	207, 196 },
-	{            1268,	    STRING,	208,  -1 },
-	{            1273,	    STRING,	209,  -1 },
-	{            1278,	    STRING,	210,  -1 },
-	{            1283,	    STRING,	211,  -1 },
-	{            1288,	    STRING,	212, 281 },
-	{            1293,	    STRING,	213, 272 },
-	{            1298,	    STRING,	214, 283 },
-	{            1303,	    STRING,	215,  -1 },
-	{            1307,	    STRING,	216,  -1 },
-	{            1312,	    STRING,	217, 134 },
-	{            1317,	    STRING,	218,  -1 },
-	{            1322,	    STRING,	219,  -1 },
-	{            1327,	    STRING,	220,  -1 },
-	{            1332,	    STRING,	221,  43 },
-	{            1337,	    STRING,	222, 256 },
-	{            1342,	    STRING,	223,  -1 },
-	{            1347,	    STRING,	224,  -1 },
-	{            1352,	    STRING,	225, 286 },
-	{            1357,	    STRING,	226, 287 },
-	{            1362,	    STRING,	227, 288 },
-	{            1367,	    STRING,	228, 289 },
-	{            1372,	    STRING,	229, 290 },
-	{            1377,	    STRING,	230, 291 },
-	{            1382,	    STRING,	231, 292 },
-	{            1387,	    STRING,	232, 293 },
-	{            1392,	    STRING,	233, 294 },
-	{            1397,	    STRING,	234, 133 },
-	{            1402,	    STRING,	235, 296 },
-	{            1407,	    STRING,	236, 297 },
-	{            1412,	    STRING,	237, 298 },
-	{            1417,	    STRING,	238, 299 },
-	{            1422,	    STRING,	239, 300 },
-	{            1427,	    STRING,	240, 301 },
-	{            1432,	    STRING,	241, 302 },
-	{            1437,	    STRING,	242, 303 },
-	{            1442,	    STRING,	243, 304 },
-	{            1447,	    STRING,	244, 257 },
-	{            1452,	    STRING,	245, 306 },
-	{            1457,	    STRING,	246, 307 },
-	{            1462,	    STRING,	247, 308 },
-	{            1467,	    STRING,	248, 309 },
-	{            1472,	    STRING,	249, 310 },
-	{            1477,	    STRING,	250, 311 },
-	{            1482,	    STRING,	251, 312 },
-	{            1487,	    STRING,	252, 313 },
-	{            1492,	    STRING,	253, 314 },
-	{            1497,	    STRING,	254, 226 },
-	{            1502,	    STRING,	255, 316 },
-	{            1507,	    STRING,	256, 317 },
-	{            1512,	    STRING,	257, 318 },
-	{            1517,	    STRING,	258, 319 },
-	{            1522,	    STRING,	259, 320 },
-	{            1527,	    STRING,	260, 321 },
-	{            1532,	    STRING,	261, 322 },
-	{            1537,	    STRING,	262, 323 },
-	{            1542,	    STRING,	263, 324 },
-	{            1547,	    STRING,	264, 258 },
-	{            1552,	    STRING,	265, 326 },
-	{            1557,	    STRING,	266, 327 },
-	{            1562,	    STRING,	267, 328 },
-	{            1567,	    STRING,	268, 329 },
-	{            1572,	    STRING,	269,  -1 },
-	{            1576,	    STRING,	270,  -1 },
-	{            1580,	    STRING,	271, 335 },
-	{            1585,	    STRING,	272, 332 },
-	{            1590,	    STRING,	273,  -1 },
-	{            1594,	    STRING,	274,  -1 },
-	{            1599,	    STRING,	275,  -1 },
-	{            1604,	    STRING,	276,  -1 },
-	{            1610,	    STRING,	277,  37 },
-	{            1615,	    STRING,	278,  -1 },
-	{            1621,	    STRING,	279,  -1 },
-	{            1625,	    STRING,	280,  -1 },
-	{            1630,	    STRING,	281,  -1 },
-	{            1636,	    STRING,	282,  -1 },
-	{            1641,	    STRING,	283,  -1 },
-	{            1647,	    STRING,	284,  -1 },
-	{            1652,	    STRING,	285,   8 },
-	{            1658,	    STRING,	286, 262 },
-	{            1663,	    STRING,	287,  -1 },
-	{            1666,	    STRING,	288,  -1 },
-	{            1669,	    STRING,	289,  -1 },
-	{            1672,	    STRING,	290,  -1 },
-	{            1675,	    STRING,	291,  -1 },
-	{            1678,	    STRING,	292,  -1 },
-	{            1681,	    STRING,	293,  -1 },
-	{            1684,	    STRING,	294,  -1 },
-	{            1687,	    STRING,	295,  -1 },
-	{            1690,	    STRING,	296,  -1 },
-	{            1693,	    STRING,	297,  -1 },
-	{            1696,	    STRING,	298,  -1 },
-	{            1699,	    STRING,	299,  -1 },
-	{            1705,	    STRING,	300,  -1 },
-	{            1711,	    STRING,	301,  -1 },
-	{            1715,	    STRING,	302, 325 },
-	{            1720,	    STRING,	303, 221 },
-	{            1725,	    STRING,	304, 243 },
-	{            1729,	    STRING,	305,  -1 },
-	{            1733,	    STRING,	306, 250 },
-	{            1737,	    STRING,	307,  -1 },
-	{            1741,	    STRING,	308, 141 },
-	{            1746,	    STRING,	309, 248 },
-	{            1752,	    STRING,	310, 218 },
-	{            1758,	    STRING,	311,  -1 },
-	{            1763,	    STRING,	312, 201 },
-	{            1767,	    STRING,	313, 229 },
-	{            1773,	    STRING,	314, 264 },
-	{            1778,	    STRING,	315, 253 },
-	{            1784,	    STRING,	316, 334 },
-	{            1789,	    STRING,	317,  -1 },
-	{            1795,	    STRING,	318, 236 },
-	{            1801,	    STRING,	319, 185 },
-	{            1805,	    STRING,	320,  -1 },
-	{            1811,	    STRING,	321,  -1 },
-	{            1816,	    STRING,	322,  -1 },
-	{            1820,	    STRING,	323,  -1 },
-	{            1826,	    STRING,	324, 112 },
-	{            1831,	    STRING,	325,  -1 },
-	{            1837,	    STRING,	326,  -1 },
-	{            1843,	    STRING,	327,  -1 },
-	{            1847,	    STRING,	328,  -1 },
-	{            1852,	    STRING,	329,  -1 },
-	{            1858,	    STRING,	330,  -1 },
-	{            1864,	    STRING,	331,  53 },
-	{            1870,	    STRING,	332,  -1 },
-	{            1875,	    STRING,	333,  47 },
-	{            1881,	    STRING,	334, 155 },
-	{            1888,	    STRING,	335,  -1 },
-	{            1893,	    STRING,	336,  -1 },
-	{            1898,	    STRING,	337,  -1 },
-	{            1903,	    STRING,	338,  -1 },
-	{            1908,	    STRING,	339,  -1 },
-	{            1912,	    STRING,	340,  -1 },
-	{            1917,	    STRING,	341, 383 },
-	{            1923,	    STRING,	342,  -1 },
-	{            1929,	    STRING,	343,  -1 },
-	{            1935,	    STRING,	344, 386 },
-	{            1940,	    STRING,	345, 238 },
-	{            1946,	    STRING,	346,  -1 },
-	{            1951,	    STRING,	347, 344 },
-	{            1956,	    STRING,	348,  31 },
-	{            1961,	    STRING,	349,  -1 },
-	{            1966,	    STRING,	350, 380 },
-	{            1972,	    STRING,	351, 255 },
-	{            1978,	    STRING,	352,  -1 },
-	{            1983,	    STRING,	353,  -1 },
-	{            1989,	    STRING,	354, 347 },
-	{            1994,	    STRING,	355,  -1 },
-	{            2000,	    STRING,	356,  -1 },
-	{            2006,	    STRING,	357,  -1 },
-	{            2012,	    STRING,	358,  87 },
-	{            2017,	    STRING,	359,  -1 },
-	{            2023,	    STRING,	360,  -1 },
-	{            2029,	    STRING,	361,  -1 },
-	{            2034,	    STRING,	362,  -1 },
-	{            2039,	    STRING,	363,  -1 },
-	{            2044,	    STRING,	364,  -1 },
-	{            2049,	    STRING,	365, 212 },
-	{            2054,	    STRING,	366, 109 },
-	{            2059,	    STRING,	367, 213 },
-	{            2064,	    STRING,	368, 230 },
-	{            2070,	    STRING,	369,  -1 },
-	{            2076,	    STRING,	370,  -1 },
-	{            2082,	    STRING,	371,  -1 },
-	{            2088,	    STRING,	372,  -1 },
-	{            2093,	    STRING,	373,  -1 },
-	{            2101,	    STRING,	374,  -1 },
-	{            2107,	    STRING,	375,  -1 },
-	{            2113,	    STRING,	376,  -1 },
-	{            2122,	    STRING,	377, 116 },
-	{            2129,	    STRING,	378,  -1 },
-	{            2135,	    STRING,	379, 231 },
-	{            2141,	    STRING,	380,  -1 },
-	{            2147,	    STRING,	381, 338 },
-	{            2152,	    STRING,	382,  -1 },
-	{            2157,	    STRING,	383,  -1 },
-	{            2163,	    STRING,	384, 197 },
-	{            2169,	    STRING,	385, 430 },
-	{            2175,	    STRING,	386,  -1 },
-	{            2181,	    STRING,	387,  -1 },
-	{            2187,	    STRING,	388,  -1 },
-	{            2194,	    STRING,	389,  -1 },
-	{            2200,	    STRING,	390,  -1 },
-	{            2206,	    STRING,	391,  -1 },
-	{            2212,	    STRING,	392, 437 },
-	{            2217,	    STRING,	393,  -1 },
-	{            2225,	    STRING,	394,  -1 },
-	{            2230,	    STRING,	395,  -1 },
-	{            2235,	    NUMBER,	 33,  -1 },
-	{            2240,	   BOOLEAN,	 37,  -1 },
-	{            2245,	   BOOLEAN,	 38,  -1 },
-	{            2250,	   BOOLEAN,	 39,  -1 },
-	{            2255,	    NUMBER,	 34,  -1 },
-	{            2260,	    NUMBER,	 35,  -1 },
-	{            2265,	    STRING,	396,  -1 },
-	{            2270,	    STRING,	397,  13 },
-	{            2275,	   BOOLEAN,	 40,  -1 },
-	{            2280,	   BOOLEAN,	 41, 446 },
-	{            2285,	    NUMBER,	 36,  -1 },
-	{            2290,	    NUMBER,	 37,  -1 },
-	{            2295,	    NUMBER,	 38,  -1 },
-	{            2300,	    STRING,	398, 472 },
-	{            2305,	    STRING,	399,  -1 },
-	{            2310,	   BOOLEAN,	 42,  -1 },
-	{            2315,	   BOOLEAN,	 43,  -1 },
-	{            2320,	    STRING,	400,  -1 },
-	{            2325,	    STRING,	401,  -1 },
-	{            2330,	    STRING,	402,  -1 },
-	{            2335,	    STRING,	403,  -1 },
-	{            2340,	    STRING,	404,  -1 },
-	{            2345,	    STRING,	405,  -1 },
-	{            2350,	    STRING,	406,  -1 },
-	{            2355,	    STRING,	407,  -1 },
-	{            2360,	    STRING,	408,  26 },
-	{            2365,	    STRING,	409,  60 },
-	{            2370,	    STRING,	410, 121 },
-	{            2375,	    STRING,	411, 407 },
-	{            2380,	    STRING,	412, 402 },
-	{            2385,	    STRING,	413,  -1 } 
-};
-
-static struct name_table_entry *_nc_info_table = 0;
-
-static const short _nc_info_hash_table[995] =
-{
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	465,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	261,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	457,
-	 -1,
-	 -1,
-	265,
-	216,
-	120,
-	 -1,
-	 -1,
-	 -1,
-	180,
-	 -1,
-	 -1,
-	 88,
-	 -1,
-	420,
-	 -1,
-	398,
-	 -1,
-	348,
-	 -1,
-	 -1,
-	 19,
-	 -1,
-	 -1,
-	 -1,
-	359,
-	 -1,
-	174,
-	 -1,
-	245,
-	 -1,
-	 74,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	269,
-	 -1,
-	480,
-	 -1,
-	 -1,
-	 -1,
-	124,
-	 -1,
-	 -1,
-	 -1,
-	390,
-	379,
-	367,
-	 -1,
-	 -1,
-	444,
-	 -1,
-	 -1,
-	 -1,
-	305,
-	 -1,
-	 -1,
-	363,
-	 -1,
-	 -1,
-	483,
-	377,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	460,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	204,
-	 38,
-	 -1,
-	 82,
-	 -1,
-	110,
-	127,
-	 -1,
-	 -1,
-	463,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	336,
-	 -1,
-	 17,
-	128,
-	434,
-	 -1,
-	188,
-	129,
-	 -1,
-	351,
-	 -1,
-	 -1,
-	 16,
-	 -1,
-	 -1,
-	259,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	489,
-	 -1,
-	353,
-	 -1,
-	 71,
-	247,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 78,
-	 -1,
-	 -1,
-	331,
-	 -1,
-	 -1,
-	173,
-	136,
-	161,
-	189,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	454,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	224,
-	479,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	354,
-	 -1,
-	 -1,
-	233,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	125,
-	 11,
-	 -1,
-	 -1,
-	378,
-	166,
-	 -1,
-	191,
-	 -1,
-	 -1,
-	 48,
-	228,
-	 -1,
-	  2,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	374,
-	 -1,
-	408,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	375,
-	 -1,
-	 52,
-	145,
-	170,
-	 -1,
-	392,
-	382,
-	 -1,
-	393,
-	411,
-	 -1,
-	 -1,
-	 -1,
-	276,
-	 -1,
-	 -1,
-	 35,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	396,
-	388,
-	 36,
-	 -1,
-	 -1,
-	 64,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	350,
-	 -1,
-	 -1,
-	215,
-	 91,
-	 -1,
-	 -1,
-	439,
-	 -1,
-	122,
-	 -1,
-	200,
-	 -1,
-	 67,
-	 -1,
-	410,
-	 -1,
-	 -1,
-	 89,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 96,
-	 21,
-	 -1,
-	103,
-	  1,
-	 -1,
-	 -1,
-	369,
-	 -1,
-	 -1,
-	345,
-	 -1,
-	 -1,
-	 -1,
-	355,
-	 40,
-	 -1,
-	 27,
-	 -1,
-	406,
-	 -1,
-	 -1,
-	 -1,
-	482,
-	419,
-	417,
-	 -1,
-	 -1,
-	360,
-	270,
-	 -1,
-	 -1,
-	251,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	349,
-	 -1,
-	 -1,
-	278,
-	 -1,
-	442,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	438,
-	 -1,
-	494,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	315,
-	 -1,
-	340,
-	364,
-	356,
-	 -1,
-	484,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 32,
-	 -1,
-	 -1,
-	 -1,
-	260,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	207,
-	487,
-	 84,
-	453,
-	 -1,
-	 -1,
-	413,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	214,
-	 -1,
-	337,
-	352,
-	477,
-	 -1,
-	435,
-	 56,
-	 -1,
-	 -1,
-	 34,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	132,
-	 -1,
-	 85,
-	492,
-	428,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	199,
-	 -1,
-	342,
-	 -1,
-	 -1,
-	 -1,
-	138,
-	163,
-	190,
-	147,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	266,
-	 -1,
-	 -1,
-	433,
-	 -1,
-	 -1,
-	474,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	385,
-	100,
-	 -1,
-	 -1,
-	 -1,
-	431,
-	 -1,
-	391,
-	381,
-	 12,
-	 58,
-	 -1,
-	142,
-	167,
-	 -1,
-	 -1,
-	409,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 42,
-	 45,
-	 66,
-	 -1,
-	 -1,
-	424,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	220,
-	376,
-	 -1,
-	 -1,
-	343,
-	 -1,
-	 -1,
-	 -1,
-	114,
-	106,
-	 -1,
-	 -1,
-	447,
-	 -1,
-	217,
-	493,
-	171,
-	172,
-	399,
-	346,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	195,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	496,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	241,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	151,
-	 -1,
-	118,
-	 -1,
-	 62,
-	187,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	234,
-	 -1,
-	443,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	357,
-	 -1,
-	 -1,
-	 -1,
-	246,
-	 -1,
-	 -1,
-	 -1,
-	448,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 39,
-	 -1,
-	 10,
-	397,
-	389,
-	 -1,
-	 -1,
-	154,
-	 -1,
-	 -1,
-	 -1,
-	130,
-	 -1,
-	 22,
-	222,
-	373,
-	162,
-	 -1,
-	361,
-	203,
-	 -1,
-	 -1,
-	242,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	459,
-	 -1,
-	 -1,
-	271,
-	 -1,
-	 97,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	427,
-	 -1,
-	175,
-	107,
-	 -1,
-	 -1,
-	 -1,
-	178,
-	423,
-	372,
-	 69,
-	 -1,
-	365,
-	 -1,
-	  4,
-	486,
-	184,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	461,
-	 -1,
-	 -1,
-	282,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	475,
-	 -1,
-	 -1,
-	 -1,
-	395,
-	387,
-	 -1,
-	 -1,
-	 79,
-	 63,
-	 -1,
-	 -1,
-	452,
-	451,
-	 -1,
-	 50,
-	 -1,
-	436,
-	 -1,
-	 -1,
-	285,
-	 -1,
-	 -1,
-	 83,
-	455,
-	 -1,
-	 -1,
-	 -1,
-	279,
-	370,
-	 -1,
-	 -1,
-	 -1,
-	 18,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	421,
-	 -1,
-	495,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	227,
-	333,
-	 -1,
-	 -1,
-	 25,
-	139,
-	164,
-	 -1,
-	 -1,
-	371,
-	 -1,
-	 -1,
-	429,
-	 -1,
-	 -1,
-	 -1,
-	273,
-	 -1,
-	466,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	181,
-	 -1,
-	 -1,
-	 75,
-	 -1,
-	 92,
-	339,
-	 -1,
-	384,
-	 -1,
-	123,
-	 -1,
-	143,
-	168,
-	 -1,
-	183,
-	186,
-	 -1,
-	108,
-	 95,
-	368,
-	 -1,
-	 -1,
-	277,
-	198,
-	 -1,
-	206,
-	432,
-	 -1,
-	476,
-	 -1,
-	458,
-	 -1,
-	 -1,
-	182,
-	 -1,
-	441,
-	 -1,
-	 -1,
-	 -1,
-	115,
-	113,
-	404,
-	 -1,
-	473,
-	 -1,
-	 -1,
-	 -1,
-	490,
-	104,
-	 -1,
-	 -1,
-	450,
-	449,
-	 -1,
-	 -1,
-	 -1,
-	274,
-	 -1,
-	481,
-	111,
-	 99,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	263,
-	 93,
-	 -1,
-	117,
-	 -1,
-	 29,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	119,
-	 -1,
-	 -1,
-	426,
-	491,
-	 -1,
-	 -1,
-	205,
-	 -1,
-	237,
-	 44,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	418,
-	416,
-	 -1,
-	 -1,
-	358,
-	 -1,
-	 -1,
-	 -1,
-	 65,
-	 -1,
-	440,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	  5,
-	 -1,
-	 -1,
-	 -1,
-	488,
-	 -1,
-	 -1,
-	 -1,
-	 28,
-	412,
-	 -1,
-	405,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	295,
-	 -1,
-	471,
-	362,
-	 -1,
-	 -1,
-	485,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	202,
-	 -1,
-	 -1,
-	284,
-	 -1,
-	469,
-	 -1,
-	 -1,
-	  9,
-	 24,
-	 -1,
-	 -1,
-	179,
-	 -1,
-	 -1,
-	 15,
-	 -1,
-	 -1,
-	148,
-	 -1,
-	 -1,
-	 -1,
-	341,
-	 -1,
-	 -1,
-	366,
-	209,
-	223,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	  0,
-	 -1,
-	208,
-	467,
-	 -1,
-	422,
-	 -1,
-	464,
-	157,
-	 -1,
-	403,
-	 -1,
-	415,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	445,
-	 -1,
-	 -1,
-	330,
-	 -1,
-	 -1,
-	 -1,
-	462,
-	160,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 86,
-	 -1,
-	 -1,
-	 41,
-	 -1,
-	280,
-	 -1,
-	478,
-	 -1,
-	 -1,
-	 57,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	394,
-	414,
-	 -1,
-	 -1,
-	 -1,
-	140,
-	165,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	275,
-	102,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	232,
-	 -1,
-	 14,
-	 -1,
-	 -1,
-	225,
-	 -1,
-	 -1,
-	267,
-	 -1,
-	 77,
-	 -1,
-	144,
-	169,
-	 -1,
-	149,
-	 -1,
-	400,
-	 -1,
-	 -1,
-	 -1,
-	  3,
-	 -1,
-	 -1,
-	 -1,
-	468,
-	425,
-	 -1,
-	 -1,
-	470,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	456,
-	 -1,
-	158,
-	159,
-	 -1,
-	 -1,
-	146,
-	 49,
-	 -1,
-	 -1,
-	153,
-	 -1,
-	401,
-	 90,
-	0	/* base-of-table */
-};
-
-#if (BOOLCOUNT!=44)||(NUMCOUNT!=39)||(STRCOUNT!=414)
-#error	--> term.h and comp_captab.c disagree about the <--
-#error	--> numbers of booleans, numbers and/or strings <--
-#endif
-
-static const char cap_names_text[] = \
-"bw\0" "am\0" "xb\0" "xs\0" "xn\0" "eo\0" "gn\0" "hc\0" "km\0" "hs\0" \
-"in\0" "da\0" "db\0" "mi\0" "ms\0" "os\0" "es\0" "xt\0" "hz\0" "ul\0" \
-"xo\0" "nx\0" "5i\0" "HC\0" "NR\0" "NP\0" "ND\0" "cc\0" "ut\0" "hl\0" \
-"YA\0" "YB\0" "YC\0" "YD\0" "YE\0" "YF\0" "YG\0" "co\0" "it\0" "li\0" \
-"lm\0" "sg\0" "pb\0" "vt\0" "ws\0" "Nl\0" "lh\0" "lw\0" "ma\0" "MW\0" \
-"Co\0" "pa\0" "NC\0" "Ya\0" "Yb\0" "Yc\0" "Yd\0" "Ye\0" "Yf\0" "Yg\0" \
-"Yh\0" "Yi\0" "Yj\0" "Yk\0" "Yl\0" "Ym\0" "Yn\0" "BT\0" "Yo\0" "Yp\0" \
-"bt\0" "bl\0" "cr\0" "cs\0" "ct\0" "cl\0" "ce\0" "cd\0" "ch\0" "CC\0" \
-"cm\0" "do\0" "ho\0" "vi\0" "le\0" "CM\0" "ve\0" "nd\0" "ll\0" "up\0" \
-"vs\0" "dc\0" "dl\0" "ds\0" "hd\0" "as\0" "mb\0" "md\0" "ti\0" "dm\0" \
-"mh\0" "im\0" "mk\0" "mp\0" "mr\0" "so\0" "us\0" "ec\0" "ae\0" "me\0" \
-"te\0" "ed\0" "ei\0" "se\0" "ue\0" "vb\0" "ff\0" "fs\0" "i1\0" "is\0" \
-"i3\0" "if\0" "ic\0" "al\0" "ip\0" "kb\0" "ka\0" "kC\0" "kt\0" "kD\0" \
-"kL\0" "kd\0" "kM\0" "kE\0" "kS\0" "k0\0" "k1\0" "k;\0" "k2\0" "k3\0" \
-"k4\0" "k5\0" "k6\0" "k7\0" "k8\0" "k9\0" "kh\0" "kI\0" "kA\0" "kl\0" \
-"kH\0" "kN\0" "kP\0" "kr\0" "kF\0" "kR\0" "kT\0" "ku\0" "ke\0" "ks\0" \
-"l0\0" "l1\0" "la\0" "l2\0" "l3\0" "l4\0" "l5\0" "l6\0" "l7\0" "l8\0" \
-"l9\0" "mo\0" "mm\0" "nw\0" "pc\0" "DC\0" "DL\0" "DO\0" "IC\0" "SF\0" \
-"AL\0" "LE\0" "RI\0" "SR\0" "UP\0" "pk\0" "pl\0" "px\0" "ps\0" "pf\0" \
-"po\0" "rp\0" "r1\0" "r2\0" "r3\0" "rf\0" "rc\0" "cv\0" "sc\0" "sf\0" \
-"sr\0" "sa\0" "st\0" "wi\0" "ta\0" "ts\0" "uc\0" "hu\0" "iP\0" "K1\0" \
-"K3\0" "K2\0" "K4\0" "K5\0" "pO\0" "rP\0" "ac\0" "pn\0" "kB\0" "SX\0" \
-"RX\0" "SA\0" "RA\0" "XN\0" "XF\0" "eA\0" "LO\0" "LF\0" "@1\0" "@2\0" \
-"@3\0" "@4\0" "@5\0" "@6\0" "@7\0" "@8\0" "@9\0" "@0\0" "%1\0" "%2\0" \
-"%3\0" "%4\0" "%5\0" "%6\0" "%7\0" "%8\0" "%9\0" "%0\0" "&1\0" "&2\0" \
-"&3\0" "&4\0" "&5\0" "&6\0" "&7\0" "&8\0" "&9\0" "&0\0" "*1\0" "*2\0" \
-"*3\0" "*4\0" "*5\0" "*6\0" "*7\0" "*8\0" "*9\0" "*0\0" "#1\0" "#2\0" \
-"#3\0" "#4\0" "%a\0" "%b\0" "%c\0" "%d\0" "%e\0" "%f\0" "%g\0" "%h\0" \
-"%i\0" "%j\0" "!1\0" "!2\0" "!3\0" "RF\0" "F1\0" "F2\0" "F3\0" "F4\0" \
-"F5\0" "F6\0" "F7\0" "F8\0" "F9\0" "FA\0" "FB\0" "FC\0" "FD\0" "FE\0" \
-"FF\0" "FG\0" "FH\0" "FI\0" "FJ\0" "FK\0" "FL\0" "FM\0" "FN\0" "FO\0" \
-"FP\0" "FQ\0" "FR\0" "FS\0" "FT\0" "FU\0" "FV\0" "FW\0" "FX\0" "FY\0" \
-"FZ\0" "Fa\0" "Fb\0" "Fc\0" "Fd\0" "Fe\0" "Ff\0" "Fg\0" "Fh\0" "Fi\0" \
-"Fj\0" "Fk\0" "Fl\0" "Fm\0" "Fn\0" "Fo\0" "Fp\0" "Fq\0" "Fr\0" "cb\0" \
-"MC\0" "ML\0" "MR\0" "Lf\0" "SC\0" "DK\0" "RC\0" "CW\0" "WG\0" "HU\0" \
-"DI\0" "QD\0" "TO\0" "PU\0" "fh\0" "PA\0" "WA\0" "u0\0" "u1\0" "u2\0" \
-"u3\0" "u4\0" "u5\0" "u6\0" "u7\0" "u8\0" "u9\0" "op\0" "oc\0" "Ic\0" \
-"Ip\0" "sp\0" "Sf\0" "Sb\0" "ZA\0" "ZB\0" "ZC\0" "ZD\0" "ZE\0" "ZF\0" \
-"ZG\0" "ZH\0" "ZI\0" "ZJ\0" "ZK\0" "ZL\0" "ZM\0" "ZN\0" "ZO\0" "ZP\0" \
-"ZQ\0" "ZR\0" "ZS\0" "ZT\0" "ZU\0" "ZV\0" "ZW\0" "ZX\0" "ZY\0" "ZZ\0" \
-"Za\0" "Zb\0" "Zc\0" "Zd\0" "Ze\0" "Zf\0" "Zg\0" "Zh\0" "Zi\0" "Zj\0" \
-"Zk\0" "Zl\0" "Zm\0" "Zn\0" "Zo\0" "Zp\0" "Zq\0" "Zr\0" "Zs\0" "Zt\0" \
-"Zu\0" "Zv\0" "Zw\0" "Zx\0" "Zy\0" "Km\0" "Mi\0" "RQ\0" "Gm\0" "AF\0" \
-"AB\0" "xl\0" "dv\0" "ci\0" "s0\0" "s1\0" "s2\0" "s3\0" "ML\0" "MT\0" \
-"Xy\0" "Zz\0" "Yv\0" "Yw\0" "Yx\0" "Yy\0" "Yz\0" "YZ\0" "S1\0" "S2\0" \
-"S3\0" "S4\0" "S5\0" "S6\0" "S7\0" "S8\0" "Xh\0" "Xl\0" "Xo\0" "Xr\0" \
-"Xt\0" "Xv\0" "sA\0" "sL\0" "i2\0" "rs\0" "ug\0" "bs\0" "ns\0" "nc\0" \
-"dC\0" "dN\0" "nl\0" "bc\0" "MT\0" "NL\0" "dB\0" "dT\0" "kn\0" "ko\0" \
-"ma\0" "pt\0" "xr\0" "G2\0" "G3\0" "G1\0" "G4\0" "GR\0" "GL\0" "GU\0" \
-"GD\0" "GH\0" "GV\0" "GC\0" "ml\0" "mu\0" "bx\0" ;
-
-static name_table_data const cap_names_data[] =
-{
-	{               0,	   BOOLEAN,	  0,  -1 },
-	{               3,	   BOOLEAN,	  1,  -1 },
-	{               6,	   BOOLEAN,	  2,  -1 },
-	{               9,	   BOOLEAN,	  3,  -1 },
-	{              12,	   BOOLEAN,	  4,  -1 },
-	{              15,	   BOOLEAN,	  5,  -1 },
-	{              18,	   BOOLEAN,	  6,  -1 },
-	{              21,	   BOOLEAN,	  7,  -1 },
-	{              24,	   BOOLEAN,	  8,  -1 },
-	{              27,	   BOOLEAN,	  9,  -1 },
-	{              30,	   BOOLEAN,	 10,  -1 },
-	{              33,	   BOOLEAN,	 11,  -1 },
-	{              36,	   BOOLEAN,	 12,  -1 },
-	{              39,	   BOOLEAN,	 13,  -1 },
-	{              42,	   BOOLEAN,	 14,  -1 },
-	{              45,	   BOOLEAN,	 15,  -1 },
-	{              48,	   BOOLEAN,	 16,  -1 },
-	{              51,	   BOOLEAN,	 17,  -1 },
-	{              54,	   BOOLEAN,	 18,  -1 },
-	{              57,	   BOOLEAN,	 19,  -1 },
-	{              60,	   BOOLEAN,	 20,  -1 },
-	{              63,	   BOOLEAN,	 21,  -1 },
-	{              66,	   BOOLEAN,	 22,  -1 },
-	{              69,	   BOOLEAN,	 23,  -1 },
-	{              72,	   BOOLEAN,	 24,   1 },
-	{              75,	   BOOLEAN,	 25,  -1 },
-	{              78,	   BOOLEAN,	 26,  -1 },
-	{              81,	   BOOLEAN,	 27,  -1 },
-	{              84,	   BOOLEAN,	 28,  -1 },
-	{              87,	   BOOLEAN,	 29,  -1 },
-	{              90,	   BOOLEAN,	 30,  -1 },
-	{              93,	   BOOLEAN,	 31,  -1 },
-	{              96,	   BOOLEAN,	 32,  -1 },
-	{              99,	   BOOLEAN,	 33,  -1 },
-	{             102,	   BOOLEAN,	 34,  -1 },
-	{             105,	   BOOLEAN,	 35,  -1 },
-	{             108,	   BOOLEAN,	 36,  -1 },
-	{             111,	    NUMBER,	  0,  -1 },
-	{             114,	    NUMBER,	  1,  -1 },
-	{             117,	    NUMBER,	  2,  -1 },
-	{             120,	    NUMBER,	  3,  -1 },
-	{             123,	    NUMBER,	  4,  -1 },
-	{             126,	    NUMBER,	  5,  -1 },
-	{             129,	    NUMBER,	  6,  -1 },
-	{             132,	    NUMBER,	  7,  -1 },
-	{             135,	    NUMBER,	  8,  -1 },
-	{             138,	    NUMBER,	  9,  -1 },
-	{             141,	    NUMBER,	 10,  -1 },
-	{             144,	    NUMBER,	 11,  -1 },
-	{             147,	    NUMBER,	 12,  -1 },
-	{             150,	    NUMBER,	 13,  -1 },
-	{             153,	    NUMBER,	 14,  -1 },
-	{             156,	    NUMBER,	 15,  -1 },
-	{             159,	    NUMBER,	 16,  -1 },
-	{             162,	    NUMBER,	 17,  -1 },
-	{             165,	    NUMBER,	 18,  -1 },
-	{             168,	    NUMBER,	 19,  -1 },
-	{             171,	    NUMBER,	 20,  -1 },
-	{             174,	    NUMBER,	 21,  -1 },
-	{             177,	    NUMBER,	 22,  -1 },
-	{             180,	    NUMBER,	 23,  -1 },
-	{             183,	    NUMBER,	 24,  -1 },
-	{             186,	    NUMBER,	 25,  -1 },
-	{             189,	    NUMBER,	 26,  -1 },
-	{             192,	    NUMBER,	 27,  -1 },
-	{             195,	    NUMBER,	 28,  -1 },
-	{             198,	    NUMBER,	 29,  -1 },
-	{             201,	    NUMBER,	 30,  -1 },
-	{             204,	    NUMBER,	 31,  -1 },
-	{             207,	    NUMBER,	 32,  -1 },
-	{             210,	    STRING,	  0,  -1 },
-	{             213,	    STRING,	  1,  -1 },
-	{             216,	    STRING,	  2,  -1 },
-	{             219,	    STRING,	  3,  -1 },
-	{             222,	    STRING,	  4,  -1 },
-	{             225,	    STRING,	  5,  -1 },
-	{             228,	    STRING,	  6,  -1 },
-	{             231,	    STRING,	  7,  -1 },
-	{             234,	    STRING,	  8,  -1 },
-	{             237,	    STRING,	  9,  -1 },
-	{             240,	    STRING,	 10,  -1 },
-	{             243,	    STRING,	 11,  -1 },
-	{             246,	    STRING,	 12,  -1 },
-	{             249,	    STRING,	 13,  -1 },
-	{             252,	    STRING,	 14,  -1 },
-	{             255,	    STRING,	 15,  -1 },
-	{             258,	    STRING,	 16,  -1 },
-	{             261,	    STRING,	 17,  -1 },
-	{             264,	    STRING,	 18,  -1 },
-	{             267,	    STRING,	 19,  -1 },
-	{             270,	    STRING,	 20,  -1 },
-	{             273,	    STRING,	 21,  -1 },
-	{             276,	    STRING,	 22,  -1 },
-	{             279,	    STRING,	 23,  -1 },
-	{             282,	    STRING,	 24,  -1 },
-	{             285,	    STRING,	 25,  -1 },
-	{             288,	    STRING,	 26,  -1 },
-	{             291,	    STRING,	 27,  -1 },
-	{             294,	    STRING,	 28,  -1 },
-	{             297,	    STRING,	 29,  -1 },
-	{             300,	    STRING,	 30,  -1 },
-	{             303,	    STRING,	 31,  -1 },
-	{             306,	    STRING,	 32,  -1 },
-	{             309,	    STRING,	 33,  -1 },
-	{             312,	    STRING,	 34,  -1 },
-	{             315,	    STRING,	 35,  -1 },
-	{             318,	    STRING,	 36,  -1 },
-	{             321,	    STRING,	 37,  -1 },
-	{             324,	    STRING,	 38,  -1 },
-	{             327,	    STRING,	 39,  -1 },
-	{             330,	    STRING,	 40,  -1 },
-	{             333,	    STRING,	 41,  -1 },
-	{             336,	    STRING,	 42,  -1 },
-	{             339,	    STRING,	 43,  -1 },
-	{             342,	    STRING,	 44,  -1 },
-	{             345,	    STRING,	 45,  -1 },
-	{             348,	    STRING,	 46,  -1 },
-	{             351,	    STRING,	 47,  -1 },
-	{             354,	    STRING,	 48, 102 },
-	{             357,	    STRING,	 49,  -1 },
-	{             360,	    STRING,	 50,  -1 },
-	{             363,	    STRING,	 51,  -1 },
-	{             366,	    STRING,	 52,  -1 },
-	{             369,	    STRING,	 53,  -1 },
-	{             372,	    STRING,	 54,  -1 },
-	{             375,	    STRING,	 55,  -1 },
-	{             378,	    STRING,	 56,  -1 },
-	{             381,	    STRING,	 57,  -1 },
-	{             384,	    STRING,	 58,  -1 },
-	{             387,	    STRING,	 59,  -1 },
-	{             390,	    STRING,	 60,  -1 },
-	{             393,	    STRING,	 61,  -1 },
-	{             396,	    STRING,	 62,  -1 },
-	{             399,	    STRING,	 63,  -1 },
-	{             402,	    STRING,	 64,  -1 },
-	{             405,	    STRING,	 65,  -1 },
-	{             408,	    STRING,	 66,  -1 },
-	{             411,	    STRING,	 67,  -1 },
-	{             414,	    STRING,	 68,  -1 },
-	{             417,	    STRING,	 69,  -1 },
-	{             420,	    STRING,	 70,  -1 },
-	{             423,	    STRING,	 71,  -1 },
-	{             426,	    STRING,	 72,  -1 },
-	{             429,	    STRING,	 73,  -1 },
-	{             432,	    STRING,	 74,  -1 },
-	{             435,	    STRING,	 75,  15 },
-	{             438,	    STRING,	 76,  -1 },
-	{             441,	    STRING,	 77,  -1 },
-	{             444,	    STRING,	 78,  -1 },
-	{             447,	    STRING,	 79,  -1 },
-	{             450,	    STRING,	 80,  -1 },
-	{             453,	    STRING,	 81,  -1 },
-	{             456,	    STRING,	 82,  -1 },
-	{             459,	    STRING,	 83,  -1 },
-	{             462,	    STRING,	 84,  -1 },
-	{             465,	    STRING,	 85,  -1 },
-	{             468,	    STRING,	 86,  -1 },
-	{             471,	    STRING,	 87,  -1 },
-	{             474,	    STRING,	 88,  -1 },
-	{             477,	    STRING,	 89,  -1 },
-	{             480,	    STRING,	 90,  -1 },
-	{             483,	    STRING,	 91,  -1 },
-	{             486,	    STRING,	 92,  35 },
-	{             489,	    STRING,	 93,  -1 },
-	{             492,	    STRING,	 94,  -1 },
-	{             495,	    STRING,	 95,  -1 },
-	{             498,	    STRING,	 96,  -1 },
-	{             501,	    STRING,	 97,  -1 },
-	{             504,	    STRING,	 98,  -1 },
-	{             507,	    STRING,	 99,  -1 },
-	{             510,	    STRING,	100,  -1 },
-	{             513,	    STRING,	101,  -1 },
-	{             516,	    STRING,	102, 120 },
-	{             519,	    STRING,	103,  -1 },
-	{             522,	    STRING,	104,  -1 },
-	{             525,	    STRING,	105,  -1 },
-	{             528,	    STRING,	106,  -1 },
-	{             531,	    STRING,	107,  -1 },
-	{             534,	    STRING,	108,  -1 },
-	{             537,	    STRING,	109,  -1 },
-	{             540,	    STRING,	110,  -1 },
-	{             543,	    STRING,	111,  -1 },
-	{             546,	    STRING,	112, 111 },
-	{             549,	    STRING,	113,  -1 },
-	{             552,	    STRING,	114,  -1 },
-	{             555,	    STRING,	115, 161 },
-	{             558,	    STRING,	116, 163 },
-	{             561,	    STRING,	117,  -1 },
-	{             564,	    STRING,	118, 170 },
-	{             567,	    STRING,	119,  -1 },
-	{             570,	    STRING,	120, 166 },
-	{             573,	    STRING,	121,  -1 },
-	{             576,	    STRING,	122,  -1 },
-	{             579,	    STRING,	123,  -1 },
-	{             582,	    STRING,	124,  -1 },
-	{             585,	    STRING,	125,  -1 },
-	{             588,	    STRING,	126,  -1 },
-	{             591,	    STRING,	127,  -1 },
-	{             594,	    STRING,	128,  -1 },
-	{             597,	    STRING,	129,  -1 },
-	{             600,	    STRING,	130,  -1 },
-	{             603,	    STRING,	131,  -1 },
-	{             606,	    STRING,	132,  -1 },
-	{             609,	    STRING,	133,  -1 },
-	{             612,	    STRING,	134,  -1 },
-	{             615,	    STRING,	135,  -1 },
-	{             618,	    STRING,	136,  -1 },
-	{             621,	    STRING,	137,  -1 },
-	{             624,	    STRING,	138,  -1 },
-	{             627,	    STRING,	139,  -1 },
-	{             630,	    STRING,	140,  -1 },
-	{             633,	    STRING,	141,  -1 },
-	{             636,	    STRING,	142,  -1 },
-	{             639,	    STRING,	143,  -1 },
-	{             642,	    STRING,	144,  -1 },
-	{             645,	    STRING,	145,  37 },
-	{             648,	    STRING,	146,  -1 },
-	{             651,	    STRING,	147, 165 },
-	{             654,	    STRING,	148,  -1 },
-	{             657,	    STRING,	149, 117 },
-	{             660,	    STRING,	150,  16 },
-	{             663,	    STRING,	151,  -1 },
-	{             666,	    STRING,	152,  -1 },
-	{             669,	    STRING,	153,  -1 },
-	{             672,	    STRING,	154, 126 },
-	{             675,	    STRING,	155,  -1 },
-	{             678,	    STRING,	156,  -1 },
-	{             681,	    STRING,	157,  -1 },
-	{             684,	    STRING,	158,  -1 },
-	{             687,	    STRING,	159,  -1 },
-	{             690,	    STRING,	160,  -1 },
-	{             693,	    STRING,	161,  -1 },
-	{             696,	    STRING,	162,  -1 },
-	{             699,	    STRING,	163,  -1 },
-	{             702,	    STRING,	164, 183 },
-	{             705,	    STRING,	165,  -1 },
-	{             708,	    STRING,	166,  -1 },
-	{             711,	    STRING,	167, 116 },
-	{             714,	    STRING,	168,  -1 },
-	{             717,	    STRING,	169,  97 },
-	{             720,	    STRING,	170, 109 },
-	{             723,	    STRING,	171,  -1 },
-	{             726,	    STRING,	172,  -1 },
-	{             729,	    STRING,	173, 100 },
-	{             732,	    STRING,	174,  13 },
-	{             735,	    STRING,	175,  -1 },
-	{             738,	    STRING,	176, 118 },
-	{             741,	    STRING,	177,  96 },
-	{             744,	    STRING,	178,  -1 },
-	{             747,	    STRING,	179,  87 },
-	{             750,	    STRING,	180,  -1 },
-	{             753,	    STRING,	181,  -1 },
-	{             756,	    STRING,	182,  -1 },
-	{             759,	    STRING,	183,  -1 },
-	{             762,	    STRING,	184,  -1 },
-	{             765,	    STRING,	185,  -1 },
-	{             768,	    STRING,	186,  -1 },
-	{             771,	    STRING,	187,  -1 },
-	{             774,	    STRING,	188, 196 },
-	{             777,	    STRING,	189,  -1 },
-	{             780,	    STRING,	190,  -1 },
-	{             783,	    STRING,	191, 195 },
-	{             786,	    STRING,	192,  -1 },
-	{             789,	    STRING,	193,  -1 },
-	{             792,	    STRING,	194,  -1 },
-	{             795,	    STRING,	195,  -1 },
-	{             798,	    STRING,	196,  -1 },
-	{             801,	    STRING,	197,  -1 },
-	{             804,	    STRING,	198,  -1 },
-	{             807,	    STRING,	199, 131 },
-	{             810,	    STRING,	200, 158 },
-	{             813,	    STRING,	201,  -1 },
-	{             816,	    STRING,	202,  -1 },
-	{             819,	    STRING,	203,  -1 },
-	{             822,	    STRING,	204,  -1 },
-	{             825,	    STRING,	205,  -1 },
-	{             828,	    STRING,	206,  -1 },
-	{             831,	    STRING,	207,  -1 },
-	{             834,	    STRING,	208,  -1 },
-	{             837,	    STRING,	209,  -1 },
-	{             840,	    STRING,	210,  -1 },
-	{             843,	    STRING,	211,  -1 },
-	{             846,	    STRING,	212, 122 },
-	{             849,	    STRING,	213,  -1 },
-	{             852,	    STRING,	214,  -1 },
-	{             855,	    STRING,	215,  -1 },
-	{             858,	    STRING,	216,  -1 },
-	{             861,	    STRING,	217,  46 },
-	{             864,	    STRING,	218,  39 },
-	{             867,	    STRING,	219,  -1 },
-	{             870,	    STRING,	220,  -1 },
-	{             873,	    STRING,	221,  88 },
-	{             876,	    STRING,	222,  40 },
-	{             879,	    STRING,	223,  -1 },
-	{             882,	    STRING,	224,  -1 },
-	{             885,	    STRING,	225,  47 },
-	{             888,	    STRING,	226,  -1 },
-	{             891,	    STRING,	227,  -1 },
-	{             894,	    STRING,	228,  -1 },
-	{             897,	    STRING,	229,  -1 },
-	{             900,	    STRING,	230,  53 },
-	{             903,	    STRING,	231,  54 },
-	{             906,	    STRING,	232,  55 },
-	{             909,	    STRING,	233,  56 },
-	{             912,	    STRING,	234,  57 },
-	{             915,	    STRING,	235,  58 },
-	{             918,	    STRING,	236,  59 },
-	{             921,	    STRING,	237,  60 },
-	{             924,	    STRING,	238,  61 },
-	{             927,	    STRING,	239,  62 },
-	{             930,	    STRING,	240,  63 },
-	{             933,	    STRING,	241,  64 },
-	{             936,	    STRING,	242,  65 },
-	{             939,	    STRING,	243,  66 },
-	{             942,	    STRING,	244,  68 },
-	{             945,	    STRING,	245,  69 },
-	{             948,	    STRING,	246,  -1 },
-	{             951,	    STRING,	247,  -1 },
-	{             954,	    STRING,	248,  -1 },
-	{             957,	    STRING,	249,  -1 },
-	{             960,	    STRING,	250,  -1 },
-	{             963,	    STRING,	251,  -1 },
-	{             966,	    STRING,	252,  -1 },
-	{             969,	    STRING,	253,  -1 },
-	{             972,	    STRING,	254,  -1 },
-	{             975,	    STRING,	255,  -1 },
-	{             978,	    STRING,	256,  -1 },
-	{             981,	    STRING,	257,   7 },
-	{             984,	    STRING,	258,  94 },
-	{             987,	    STRING,	259,  -1 },
-	{             990,	    STRING,	260,  -1 },
-	{             993,	    STRING,	261,  -1 },
-	{             996,	    STRING,	262,  -1 },
-	{             999,	    STRING,	263,  -1 },
-	{            1002,	    STRING,	264,  -1 },
-	{            1005,	    STRING,	265, 184 },
-	{            1008,	    STRING,	266,  29 },
-	{            1011,	    STRING,	267,  -1 },
-	{            1014,	    STRING,	268,  -1 },
-	{            1017,	    STRING,	269,  -1 },
-	{            1020,	    STRING,	270,  -1 },
-	{            1023,	    STRING,	271,  -1 },
-	{            1026,	    STRING,	272,  -1 },
-	{            1029,	    STRING,	273, 257 },
-	{            1032,	    STRING,	274,  -1 },
-	{            1035,	    STRING,	275,  -1 },
-	{            1038,	    STRING,	276,  -1 },
-	{            1041,	    STRING,	277,   4 },
-	{            1044,	    STRING,	278,  -1 },
-	{            1047,	    STRING,	279,  -1 },
-	{            1050,	    STRING,	280,  -1 },
-	{            1053,	    STRING,	281,  -1 },
-	{            1056,	    STRING,	282,  -1 },
-	{            1059,	    STRING,	283,  -1 },
-	{            1062,	    STRING,	284, 229 },
-	{            1065,	    STRING,	285,  -1 },
-	{            1068,	    STRING,	286,  -1 },
-	{            1071,	    STRING,	287,  -1 },
-	{            1074,	    STRING,	288,  -1 },
-	{            1077,	    STRING,	289,  -1 },
-	{            1080,	    STRING,	290,  -1 },
-	{            1083,	    STRING,	291,  -1 },
-	{            1086,	    STRING,	292,  -1 },
-	{            1089,	    STRING,	293,  -1 },
-	{            1092,	    STRING,	294,  -1 },
-	{            1095,	    STRING,	295,  -1 },
-	{            1098,	    STRING,	296,  -1 },
-	{            1101,	    STRING,	297, 142 },
-	{            1104,	    STRING,	298,  -1 },
-	{            1107,	    STRING,	299,  -1 },
-	{            1110,	    STRING,	300, 149 },
-	{            1113,	    STRING,	301,  -1 },
-	{            1116,	    STRING,	302,  -1 },
-	{            1119,	    STRING,	303,  -1 },
-	{            1122,	    STRING,	304,  -1 },
-	{            1125,	    STRING,	305,  -1 },
-	{            1128,	    STRING,	306,  -1 },
-	{            1131,	    STRING,	307,  -1 },
-	{            1134,	    STRING,	308,  -1 },
-	{            1137,	    STRING,	309,  48 },
-	{            1140,	    STRING,	310, 247 },
-	{            1143,	    STRING,	311, 238 },
-	{            1146,	    STRING,	312, 239 },
-	{            1149,	    STRING,	313, 240 },
-	{            1152,	    STRING,	314, 241 },
-	{            1155,	    STRING,	315, 242 },
-	{            1158,	    STRING,	316, 243 },
-	{            1161,	    STRING,	317, 244 },
-	{            1164,	    STRING,	318, 245 },
-	{            1167,	    STRING,	319, 246 },
-	{            1170,	    STRING,	320,  -1 },
-	{            1173,	    STRING,	321, 172 },
-	{            1176,	    STRING,	322,  -1 },
-	{            1179,	    STRING,	323, 171 },
-	{            1182,	    STRING,	324, 103 },
-	{            1185,	    STRING,	325,  -1 },
-	{            1188,	    STRING,	326, 104 },
-	{            1191,	    STRING,	327,  14 },
-	{            1194,	    STRING,	328,  -1 },
-	{            1197,	    STRING,	329,  -1 },
-	{            1200,	    STRING,	330,  -1 },
-	{            1203,	    STRING,	331,  -1 },
-	{            1206,	    STRING,	332,  -1 },
-	{            1209,	    STRING,	333,  -1 },
-	{            1212,	    STRING,	334,  -1 },
-	{            1215,	    STRING,	335,  -1 },
-	{            1218,	    STRING,	336,  -1 },
-	{            1221,	    STRING,	337,  -1 },
-	{            1224,	    STRING,	338,  -1 },
-	{            1227,	    STRING,	339,  -1 },
-	{            1230,	    STRING,	340,  -1 },
-	{            1233,	    STRING,	341,  -1 },
-	{            1236,	    STRING,	342,  -1 },
-	{            1239,	    STRING,	343,  -1 },
-	{            1242,	    STRING,	344, 208 },
-	{            1245,	    STRING,	345,  -1 },
-	{            1248,	    STRING,	346,  -1 },
-	{            1251,	    STRING,	347,  -1 },
-	{            1254,	    STRING,	348,  -1 },
-	{            1257,	    STRING,	349,  -1 },
-	{            1260,	    STRING,	350,  -1 },
-	{            1263,	    STRING,	351,  -1 },
-	{            1266,	    STRING,	352,  -1 },
-	{            1269,	    STRING,	353, 272 },
-	{            1272,	    STRING,	354, 273 },
-	{            1275,	    STRING,	355, 387 },
-	{            1278,	    STRING,	356,  -1 },
-	{            1281,	    STRING,	357,  -1 },
-	{            1284,	    STRING,	358,  -1 },
-	{            1287,	    STRING,	359,  -1 },
-	{            1290,	    STRING,	360,  -1 },
-	{            1293,	    STRING,	361,  -1 },
-	{            1296,	    STRING,	362,  -1 },
-	{            1299,	    STRING,	363,  -1 },
-	{            1302,	    STRING,	364,  -1 },
-	{            1305,	    STRING,	365,  67 },
-	{            1308,	    STRING,	366,  -1 },
-	{            1311,	    STRING,	367,  -1 },
-	{            1314,	    STRING,	368, 341 },
-	{            1317,	    STRING,	369,  -1 },
-	{            1320,	    STRING,	370,  -1 },
-	{            1323,	    STRING,	371, 274 },
-	{            1326,	    STRING,	372,  -1 },
-	{            1329,	    STRING,	373,  -1 },
-	{            1332,	    STRING,	374,  -1 },
-	{            1335,	    STRING,	375,  -1 },
-	{            1338,	    STRING,	376,  -1 },
-	{            1341,	    STRING,	377,  -1 },
-	{            1344,	    STRING,	378,  -1 },
-	{            1347,	    STRING,	379,  -1 },
-	{            1350,	    STRING,	380,  -1 },
-	{            1353,	    STRING,	381, 357 },
-	{            1356,	    STRING,	382, 358 },
-	{            1359,	    STRING,	383, 359 },
-	{            1362,	    STRING,	384, 360 },
-	{            1365,	    STRING,	385, 361 },
-	{            1368,	    STRING,	386,  -1 },
-	{            1371,	    STRING,	387,  -1 },
-	{            1374,	    STRING,	388,  -1 },
-	{            1377,	    STRING,	389,  -1 },
-	{            1380,	    STRING,	390,  -1 },
-	{            1383,	    STRING,	391,  -1 },
-	{            1386,	    STRING,	392,  -1 },
-	{            1389,	    STRING,	393,  -1 },
-	{            1392,	    STRING,	394, 390 },
-	{            1395,	    STRING,	395,  -1 },
-	{            1398,	    NUMBER,	 33,  -1 },
-	{            1401,	   BOOLEAN,	 37,  -1 },
-	{            1404,	   BOOLEAN,	 38,  -1 },
-	{            1407,	   BOOLEAN,	 39, 248 },
-	{            1410,	    NUMBER,	 34,  -1 },
-	{            1413,	    NUMBER,	 35, 203 },
-	{            1416,	    STRING,	396,  -1 },
-	{            1419,	    STRING,	397,  -1 },
-	{            1422,	   BOOLEAN,	 40, 439 },
-	{            1425,	   BOOLEAN,	 41,  -1 },
-	{            1428,	    NUMBER,	 36,  -1 },
-	{            1431,	    NUMBER,	 37,  -1 },
-	{            1434,	    NUMBER,	 38,  -1 },
-	{            1437,	    STRING,	398,  -1 },
-	{            1440,	    STRING,	399, 379 },
-	{            1443,	   BOOLEAN,	 42,  -1 },
-	{            1446,	   BOOLEAN,	 43,  -1 },
-	{            1449,	    STRING,	400, 386 },
-	{            1452,	    STRING,	401, 425 },
-	{            1455,	    STRING,	402, 385 },
-	{            1458,	    STRING,	403, 388 },
-	{            1461,	    STRING,	404, 412 },
-	{            1464,	    STRING,	405, 406 },
-	{            1467,	    STRING,	406, 415 },
-	{            1470,	    STRING,	407,  -1 },
-	{            1473,	    STRING,	408, 402 },
-	{            1476,	    STRING,	409, 416 },
-	{            1479,	    STRING,	410,  -1 },
-	{            1482,	    STRING,	411, 464 },
-	{            1485,	    STRING,	412, 399 },
-	{            1488,	    STRING,	413,  -1 } 
-};
-
-static struct name_table_entry *_nc_cap_table = 0;
-
-static const short _nc_cap_hash_table[995] =
-{
-	253,
-	 -1,
-	 45,
-	211,
-	263,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	449,
-	457,
-	311,
-	411,
-	 -1,
-	132,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	123,
-	 71,
-	 75,
-	 92,
-	427,
-	233,
-	 -1,
-	336,
-	 -1,
-	 -1,
-	370,
-	291,
-	494,
-	472,
-	138,
-	186,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 19,
-	193,
-	436,
-	431,
-	453,
-	 -1,
-	315,
-	489,
-	349,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	353,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	124,
-	 -1,
-	 -1,
-	 -1,
-	394,
-	 -1,
-	367,
-	167,
-	 -1,
-	191,
-	371,
-	 -1,
-	 89,
-	 -1,
-	 -1,
-	 -1,
-	363,
-	460,
-	319,
-	419,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 70,
-	 74,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 38,
-	 -1,
-	128,
-	 -1,
-	398,
-	 -1,
-	 -1,
-	481,
-	 -1,
-	 -1,
-	202,
-	 -1,
-	 28,
-	 43,
-	 -1,
-	 17,
-	 -1,
-	 -1,
-	444,
-	423,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	496,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	430,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	296,
-	 -1,
-	 21,
-	 -1,
-	187,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	321,
-	276,
-	 -1,
-	 -1,
-	 31,
-	375,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	429,
-	476,
-	 -1,
-	 -1,
-	 -1,
-	300,
-	400,
-	 -1,
-	218,
-	 -1,
-	 -1,
-	227,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 11,
-	285,
-	179,
-	 -1,
-	325,
-	280,
-	 -1,
-	224,
-	162,
-	480,
-	 -1,
-	 -1,
-	 51,
-	 -1,
-	 -1,
-	201,
-	204,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 22,
-	 -1,
-	304,
-	404,
-	 -1,
-	154,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	108,
-	 -1,
-	 76,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	329,
-	284,
-	 -1,
-	270,
-	 84,
-	383,
-	250,
-	426,
-	 -1,
-	 -1,
-	260,
-	113,
-	110,
-	114,
-	 86,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	308,
-	408,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	433,
-	 -1,
-	112,
-	230,
-	 -1,
-	333,
-	428,
-	 -1,
-	223,
-	288,
-	484,
-	254,
-	 -1,
-	 -1,
-	210,
-	264,
-	 -1,
-	 98,
-	 -1,
-	 83,
-	471,
-	 -1,
-	450,
-	 -1,
-	312,
-	487,
-	 -1,
-	151,
-	 -1,
-	 -1,
-	 -1,
-	342,
-	 24,
-	 -1,
-	 80,
-	 99,
-	 -1,
-	234,
-	 -1,
-	337,
-	101,
-	 -1,
-	  8,
-	292,
-	391,
-	 -1,
-	139,
-	164,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	194,
-	437,
-	 -1,
-	454,
-	 -1,
-	316,
-	492,
-	 -1,
-	155,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	395,
-	 -1,
-	143,
-	168,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	364,
-	 -1,
-	320,
-	420,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	207,
-	 -1,
-	 -1,
-	157,
-	447,
-	495,
-	 -1,
-	137,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	440,
-	445,
-	424,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 79,
-	175,
-	 -1,
-	297,
-	493,
-	 23,
-	178,
-	 -1,
-	 -1,
-	 -1,
-	340,
-	 52,
-	 -1,
-	 -1,
-	 -1,
-	346,
-	344,
-	 -1,
-	322,
-	277,
-	 -1,
-	 -1,
-	 32,
-	376,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	373,
-	 -1,
-	470,
-	 -1,
-	 -1,
-	 -1,
-	301,
-	401,
-	 -1,
-	127,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	339,
-	 12,
-	 -1,
-	 -1,
-	 -1,
-	326,
-	281,
-	348,
-	125,
-	 36,
-	380,
-	343,
-	 -1,
-	 42,
-	 -1,
-	267,
-	 -1,
-	 -1,
-	372,
-	115,
-	 -1,
-	  2,
-	345,
-	 -1,
-	305,
-	405,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	237,
-	 -1,
-	330,
-	121,
-	 -1,
-	271,
-	 -1,
-	384,
-	251,
-	 -1,
-	189,
-	 -1,
-	261,
-	199,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	177,
-	 -1,
-	309,
-	409,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	226,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	231,
-	352,
-	334,
-	 -1,
-	 -1,
-	 -1,
-	289,
-	486,
-	255,
-	135,
-	160,
-	212,
-	265,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	434,
-	 -1,
-	451,
-	 -1,
-	313,
-	413,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	214,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	235,
-	  6,
-	338,
-	 10,
-	 -1,
-	478,
-	293,
-	392,
-	 -1,
-	140,
-	217,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	347,
-	455,
-	459,
-	317,
-	417,
-	 -1,
-	134,
-	 -1,
-	 -1,
-	 -1,
-	 49,
-	 -1,
-	 -1,
-	 72,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	153,
-	 -1,
-	396,
-	 -1,
-	144,
-	169,
-	 -1,
-	 -1,
-	200,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	482,
-	365,
-	461,
-	442,
-	421,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	197,
-	432,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	446,
-	441,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 18,
-	 -1,
-	 -1,
-	 -1,
-	298,
-	490,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 26,
-	 -1,
-	 -1,
-	351,
-	 -1,
-	 -1,
-	 -1,
-	323,
-	278,
-	 -1,
-	369,
-	 33,
-	377,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	302,
-	491,
-	 -1,
-	129,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	216,
-	473,
-	 27,
-	 91,
-	107,
-	 -1,
-	 -1,
-	327,
-	282,
-	 -1,
-	268,
-	 -1,
-	381,
-	469,
-	368,
-	174,
-	 -1,
-	258,
-	198,
-	 -1,
-	206,
-	180,
-	 -1,
-	 -1,
-	176,
-	 -1,
-	306,
-	488,
-	 -1,
-	150,
-	 -1,
-	 -1,
-	 -1,
-	438,
-	475,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	228,
-	 -1,
-	331,
-	 -1,
-	 -1,
-	 -1,
-	286,
-	485,
-	252,
-	 -1,
-	 -1,
-	209,
-	262,
-	 41,
-	 -1,
-	466,
-	 -1,
-	 -1,
-	 -1,
-	448,
-	 -1,
-	310,
-	410,
-	 -1,
-	130,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 25,
-	 -1,
-	 -1,
-	463,
-	 50,
-	232,
-	 -1,
-	335,
-	 -1,
-	 -1,
-	 -1,
-	290,
-	389,
-	256,
-	136,
-	185,
-	213,
-	266,
-	 -1,
-	 -1,
-	 -1,
-	192,
-	435,
-	 -1,
-	452,
-	458,
-	314,
-	414,
-	 -1,
-	152,
-	 -1,
-	 -1,
-	 -1,
-	474,
-	 -1,
-	 -1,
-	215,
-	 81,
-	  5,
-	236,
-	 -1,
-	 82,
-	 -1,
-	 -1,
-	479,
-	294,
-	393,
-	 -1,
-	141,
-	190,
-	 -1,
-	 -1,
-	105,
-	 -1,
-	 -1,
-	 -1,
-	477,
-	 20,
-	362,
-	 -1,
-	318,
-	418,
-	 -1,
-	156,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 95,
-	467,
-	 73,
-	 93,
-	220,
-	219,
-	 -1,
-	  9,
-	119,
-	 -1,
-	159,
-	 -1,
-	397,
-	468,
-	145,
-	188,
-	 -1,
-	465,
-	 -1,
-	205,
-	106,
-	 90,
-	 44,
-	  3,
-	366,
-	 -1,
-	443,
-	422,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	  0,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	295,
-	 -1,
-	173,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	355,
-	 -1,
-	222,
-	221,
-	 -1,
-	 -1,
-	275,
-	356,
-	 -1,
-	 30,
-	374,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	225,
-	 -1,
-	 -1,
-	299,
-	 -1,
-	 -1,
-	148,
-	 -1,
-	 -1,
-	181,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	462,
-	 -1,
-	 -1,
-	 -1,
-	324,
-	279,
-	 -1,
-	 -1,
-	 34,
-	378,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	350,
-	 -1,
-	303,
-	403,
-	 -1,
-	133,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 77,
-	 -1,
-	182,
-	 -1,
-	 -1,
-	328,
-	283,
-	 -1,
-	269,
-	 -1,
-	382,
-	249,
-	 -1,
-	 -1,
-	 -1,
-	259,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 85,
-	 -1,
-	456,
-	307,
-	407,
-	 -1,
-	147,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 -1,
-	 78,
-	 -1,
-	 -1,
-	354,
-	 -1,
-	332,
-	 -1,
-	 -1,
-	146,
-	287,
-	483,
-	0	/* base-of-table */
-};
-
-#if (BOOLCOUNT!=44)||(NUMCOUNT!=39)||(STRCOUNT!=414)
-#error	--> term.h and comp_captab.c disagree about the <--
-#error	--> numbers of booleans, numbers and/or strings <--
-#endif
-
-/* generated by MKcaptab.awk capalias(1) */
-
-static struct alias *_nc_capalias_table = 0;
-
-static const char capalias_text[] = "\
-sb\0sr\0BSD\0\
-BO\0mr\0AT&T\0\
-CI\0vi\0AT&T\0\
-CV\0ve\0AT&T\0\
-DS\0mh\0AT&T\0\
-FE\0LF\0AT&T\0\
-FL\0LO\0AT&T\0\
-XS\0mk\0AT&T\0\
-EE\0mh\0XENIX\0\
-GE\0ae\0XENIX\0\
-GS\0as\0XENIX\0\
-CF\0vi\0XENIX\0\
-CO\0ve\0XENIX\0\
-EN\0@7\0XENIX\0\
-HM\0kh\0XENIX\0\
-LD\0kL\0XENIX\0\
-PD\0kN\0XENIX\0\
-PN\0po\0XENIX\0\
-PS\0pf\0XENIX\0\
-PU\0kP\0XENIX\0\
-RT\0@8\0XENIX\0\
-UP\0ku\0XENIX\0\
-G6\0XENIX\0\
-G7\0XENIX\0\
-G5\0XENIX\0\
-G8\0XENIX\0\
-Gr\0XENIX\0\
-Gr\0XENIX\0\
-Gu\0XENIX\0\
-Gd\0XENIX\0\
-Gh\0XENIX\0\
-Gv\0XENIX\0\
-Gc\0XENIX\0\
-GG\0XENIX\0\
-kq\0%1\0IBM\0\
-HS\0mh\0IRIS\0\
-KA\0k;\0Tek\0\
-KB\0F1\0Tek\0\
-KC\0F2\0Tek\0\
-KD\0F3\0Tek\0\
-KE\0F4\0Tek\0\
-KF\0F5\0Tek\0\
-BC\0Sb\0Tek\0\
-FC\0Sf\0Tek\0\
-";
-
-static const alias_table_data capalias_data[] = {
-	{    0,     3,     6},	 /* scroll */
-	{   10,    13,    16},	 /* enter_reverse_mode */
-	{   21,    24,    27},	 /* cursor_invisible */
-	{   32,    35,    38},	 /* cursor_normal */
-	{   43,    46,    49},	 /* enter_dim_mode */
-	{   54,    57,    60},	 /* label_on */
-	{   65,    68,    71},	 /* label_off */
-	{   76,    79,    82},	 /* enter_secure_mode */
-	{   87,    90,    93},	 /* exit_attribute_mode */
-	{   99,   102,   105},	 /* exit_alt_charset_mode */
-	{  111,   114,   117},	 /* enter_alt_charset_mode */
-	{  123,   126,   129},	 /* cursor_invis */
-	{  135,   138,   141},	 /* cursor_normal */
-	{  147,   150,   153},	 /* key_end */
-	{  159,   162,   165},	 /* key_home */
-	{  171,   174,   177},	 /* key_dl */
-	{  183,   186,   189},	 /* key_npage */
-	{  195,   198,   201},	 /* prtr_off */
-	{  207,   210,   213},	 /* prtr_on */
-	{  219,   222,   225},	 /* key_ppage */
-	{  231,   234,   237},	 /* kent */
-	{  243,   246,   249},	 /* kcuu1 */
-	{  255,    -1,   258},	 /* double-ACS_ULCORNER */
-	{  264,    -1,   267},	 /* double-ACS_LLCORNER */
-	{  273,    -1,   276},	 /* double-ACS_URCORNER */
-	{  282,    -1,   285},	 /* double-ACS_LRCORNER */
-	{  291,    -1,   294},	 /* double-ACS_LTEE */
-	{  300,    -1,   303},	 /* double-ACS_RTEE */
-	{  309,    -1,   312},	 /* double-ACS_BTEE */
-	{  318,    -1,   321},	 /* double */
-	{  327,    -1,   330},	 /* double-ACS_HLINE */
-	{  336,    -1,   339},	 /* double-ACS_VLINE */
-	{  345,    -1,   348},	 /* double-ACS_PLUS */
-	{  354,    -1,   357},	 /* acs-glitch */
-	{  363,   366,   369},	 /* key_help */
-	{  373,   376,   379},	 /* enter_dim_mode */
-	{  384,   387,   390},	 /* key_f10 */
-	{  394,   397,   400},	 /* key_f11 */
-	{  404,   407,   410},	 /* key_f12 */
-	{  414,   417,   420},	 /* key_f13 */
-	{  424,   427,   430},	 /* key_f14 */
-	{  434,   437,   440},	 /* key_f15 */
-	{  444,   447,   450},	 /* set_background */
-	{  454,   457,   460},	 /* set_foreground */
-};
-
-/* generated by MKcaptab.awk infoalias(1) */
-
-static struct alias *_nc_infoalias_table = 0;
-
-static const char infoalias_text[] = "\
-font0\0s0ds\0IBM\0\
-font1\0s1ds\0IBM\0\
-font2\0s2ds\0IBM\0\
-font3\0s3ds\0IBM\0\
-kbtab\0kcbt\0IBM\0\
-ksel\0kslt\0IBM\0\
-";
-
-static const alias_table_data infoalias_data[] = {
-	{    0,     6,    11},	 /* set0_des_seq */
-	{   15,    21,    26},	 /* set1_des_seq */
-	{   30,    36,    41},	 /* set2_des_seq */
-	{   45,    51,    56},	 /* set3_des_seq */
-	{   60,    66,    71},	 /* key_backtab */
-	{   75,    80,    85},	 /* key_select */
-};
-
-
-#if 1
-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 1
-	FreeIfNeeded(_nc_cap_table);
-	FreeIfNeeded(_nc_info_table);
-	FreeIfNeeded(_nc_capalias_table);
-	FreeIfNeeded(_nc_infoalias_table);
-#endif
-}
-#endif /* NO_LEAKS */
diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h
index 29e1319..ec17d88 100644
--- a/ncurses/curses.priv.h
+++ b/ncurses/curses.priv.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,11 +30,11 @@
  *  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: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
-
 /*
- * $Id: curses.priv.h,v 1.394 2008/10/04 21:37:45 tom Exp $
+ * $Id: curses.priv.h,v 1.547 2015/06/27 01:22:16 tom Exp $
  *
  *	curses.priv.h
  *
@@ -45,6 +45,7 @@
 
 #ifndef CURSES_PRIV_H
 #define CURSES_PRIV_H 1
+/* *INDENT-OFF* */
 
 #include <ncurses_dll.h>
 
@@ -60,9 +61,11 @@
 #define MODULE_ID(id) /*nothing*/
 #endif
 
+#include <stddef.h>		/* for offsetof */
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -83,6 +86,12 @@
 
 #include <errno.h>
 
+#if defined __hpux
+#  ifndef EILSEQ
+#    define EILSEQ 47
+#  endif
+#endif
+
 #ifndef PATH_MAX
 # if defined(_POSIX_PATH_MAX)
 #  define PATH_MAX _POSIX_PATH_MAX
@@ -97,8 +106,6 @@
 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
@@ -111,6 +118,14 @@
 #define USE_FUNC_POLL 0
 #endif
 
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+
 /* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
 #include <signal.h>
 
@@ -135,6 +150,15 @@
 #define USE_EMX_MOUSE 0
 #endif
 
+/* kLIBC keyboard/mouse support */
+#if defined(__OS2__) && defined(__KLIBC__)
+#define USE_KLIBC_KBD   1
+#define USE_KLIBC_MOUSE 1
+#else
+#define USE_KLIBC_KBD   0
+#define USE_KLIBC_MOUSE 0
+#endif
+
 #define DEFAULT_MAXCLICK 166
 #define EV_MAX		8	/* size of mouse circular event queue */
 
@@ -156,6 +180,18 @@
 #endif
 
 /*
+ * When building in the MSYS2 environment, the automatic discovery of
+ * the path separator in configure doesn't work properly. So, if building
+ * for MinGW, we enforce the correct Windows PATH separator
+ */
+#ifdef __MINGW32__
+#  ifdef NCURSES_PATHSEP
+#    undef NCURSES_PATHSEP
+#  endif
+#  define NCURSES_PATHSEP ';'
+#endif
+
+/*
  * If desired, one can configure this, disabling environment variables that
  * point to custom terminfo/termcap locations.
  */
@@ -178,6 +214,32 @@
 #endif
 
 /*
+ * If we have va_copy(), use it for assigning va_list's.
+ */
+#if defined(HAVE___VA_COPY)
+#define begin_va_copy(dst,src)	__va_copy(dst, src)
+#define end_va_copy(dst)	va_end(dst)
+#elif defined(va_copy) || defined(HAVE_VA_COPY)
+#define begin_va_copy(dst,src)	va_copy(dst, src)
+#define end_va_copy(dst)	va_end(dst)
+#else
+#define begin_va_copy(dst,src) (dst) = (src)
+#define end_va_copy(dst)	/* nothing */
+#endif
+
+/*
+ * Either/both S_ISxxx and/or S_IFxxx are defined in sys/types.h; some systems
+ * lack one or the other.
+ */
+#ifndef S_ISDIR
+#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG)
+#endif
+
+/*
  * Scroll hints are useless when hashmap is used
  */
 #if !USE_SCROLL_HINTS
@@ -194,6 +256,17 @@
 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
 #endif
 
+#include <nc_string.h>
+
+/*
+ * Options for terminal drivers, etc...
+ */
+#ifdef USE_TERM_DRIVER
+#define USE_SP_RIPOFF     1
+#define USE_SP_TERMTYPE   1
+#define USE_SP_WINDOWLIST 1
+#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
@@ -227,14 +300,6 @@
  * 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 */
@@ -247,8 +312,9 @@
 #define _nc_bkgd    _bkgrnd
 #else
 #undef _XOPEN_SOURCE_EXTENDED
+#undef _XPG5
 #define _nc_bkgd    _bkgd
-#define wgetbkgrnd(win, wch)	*wch = win->_bkgd
+#define wgetbkgrnd(win, wch)	((*wch = win->_bkgd) != 0 ? OK : ERR)
 #define wbkgrnd	    wbkgd
 #endif
 
@@ -257,39 +323,142 @@
 #define NCURSES_OPAQUE 0
 
 #include <curses.h>	/* we'll use -Ipath directive to get the right one! */
+
+typedef struct
+{
+    NCURSES_COLOR_T red, green, blue;	/* what color_content() returns */
+    NCURSES_COLOR_T r, g, b;		/* params to init_color() */
+    int init;			/* true if we called init_color() */
+}
+color_t;
+
+/*
+ * If curses.h did not expose the SCREEN-functions, then we do not need the
+ * parameter in the corresponding unextended functions.
+ */
+
+#define USE_SP_FUNC_SUPPORT     NCURSES_SP_FUNCS
+#define USE_EXT_SP_FUNC_SUPPORT (NCURSES_SP_FUNCS && NCURSES_EXT_FUNCS)
+
+#if NCURSES_SP_FUNCS
+#define SP_PARM         sp	/* use parameter */
+#define NCURSES_SP_ARG          SP_PARM
+#define NCURSES_SP_DCL  SCREEN *NCURSES_SP_ARG
+#define NCURSES_SP_DCL0 NCURSES_SP_DCL
+#define NCURSES_SP_ARGx         NCURSES_SP_ARG,
+#define NCURSES_SP_DCLx SCREEN *NCURSES_SP_ARGx
+#else
+#define SP_PARM         SP	/* use global variable */
+#define NCURSES_SP_ARG
+#define NCURSES_SP_DCL
+#define NCURSES_SP_DCL0 void
+#define NCURSES_SP_ARGx
+#define NCURSES_SP_DCLx
+#endif
+
+#include <nc_panel.h>
+
+#define IsPreScreen(sp)      (((sp) != 0) && sp->_prescreen)
+#define HasTerminal(sp)      (((sp) != 0) && (0 != ((sp)->_term)))
+#define IsValidScreen(sp)    (HasTerminal(sp) && !IsPreScreen(sp))
+
+#if USE_REENTRANT
+#define CurTerm              _nc_prescreen._cur_term
+#else
+#define CurTerm              cur_term
+#endif
+
+#if NCURSES_SP_FUNCS
+#define TerminalOf(sp)       ((sp) ? ((sp)->_term ? (sp)->_term : CurTerm) : CurTerm)
+#else
+#define TerminalOf(sp)       CurTerm
+#endif
+
 #include <term.h>
+#include <nc_termios.h>
+
+/*
+ * Reduce dependency on cur_term global by using terminfo data from SCREEN's
+ * pointer to this data.
+ */
+#ifdef USE_SP_TERMTYPE
+#undef CUR
+#endif
+
+#define SP_TERMTYPE TerminalOf(sp)->type.
+
 #include <term_entry.h>
+
 #include <nc_tparm.h>
 
-#if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT
+/*
+ * Simplify ifdef's for the "*_ATTR" macros in case italics are not configured.
+ */
+#ifdef A_ITALIC
+#define USE_ITALIC 1
+#else
+#define USE_ITALIC 0
+#define A_ITALIC 0
+#endif
+
+/*
+ * Use these macros internally, to make tracing less verbose.  But leave the
+ * option for compiling the tracing into the library.
+ */
+#if 1
+#define ColorPair(n)		NCURSES_BITS(n, 0)
+#define PairNumber(a)		(NCURSES_CAST(int,(((unsigned long)(a) & A_COLOR) >> NCURSES_ATTR_SHIFT)))
+#else
+#define ColorPair(pair)		COLOR_PAIR(pair)
+#define PairNumber(attr)	PAIR_NUMBER(attr)
+#endif
+
+#define unColor(n)		unColor2(AttrOf(n))
+#define unColor2(a)		((a) & ALL_BUT_COLOR)
+
+/*
+ * Extended-colors stores the color pair in a separate struct-member than the
+ * attributes.  But for compatibility, we handle most cases where a program
+ * written for non-extended colors stores the color in the attributes by
+ * checking for a color pair in both places.
+ */
+#if NCURSES_EXT_COLORS
 #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 SetPair(value,p)	SetPair2((value).ext_color, AttrOf(value), p)
+#define SetPair2(c,a,p)		c = (p), \
+				a = (unColor2(a) | (A_COLOR & (unsigned) ColorPair(oldColor(c))))
+#define GetPair(value)		GetPair2((value).ext_color, AttrOf(value))
+#define GetPair2(c,a)		((c) ? (c) : PairNumber(a))
+#define oldColor(p)		(((p) > 255) ? 255 : (p))
+#define GET_WINDOW_PAIR(w)	GetPair2((w)->_color, (w)->_attrs)
 #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 VIDATTR(sp,attr,pair)	NCURSES_SP_NAME(vid_puts)(NCURSES_SP_ARGx attr, (short) pair, 0, NCURSES_OUTC_FUNC)
+
+#else /* !NCURSES_EXT_COLORS */
+
 #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))
+				SetAttr(value, AttrOf(value) | (A_COLOR & (attr_t) ColorPair(p)))
+#define GetPair(value)		PairNumber(AttrOf(value))
+#define GET_WINDOW_PAIR(w)	PairNumber(WINDOW_ATTRS(w))
 #define SET_WINDOW_PAIR(w,p)	WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \
-				WINDOW_ATTRS(w) |= (A_COLOR & COLOR_PAIR(p))
+				WINDOW_ATTRS(w) |= (A_COLOR & (attr_t) ColorPair(p))
 #define SameAttrOf(a,b)		(AttrOf(a) == AttrOf(b))
-#define VIDATTR(attr, pair)	vidattr(attr)
-#endif
+
+#define VIDATTR(sp,attr,pair)	NCURSES_SP_NAME(vidputs)(NCURSES_SP_ARGx attr, NCURSES_OUTC_FUNC)
+
+#endif /* NCURSES_EXT_COLORS */
+
+#define NCURSES_OUTC_FUNC       NCURSES_SP_NAME(_nc_outch)
+#define NCURSES_PUTP2(name,value)    NCURSES_SP_NAME(_nc_putp)(NCURSES_SP_ARGx name, value)
+#define NCURSES_PUTP2_FLUSH(name,value)    NCURSES_SP_NAME(_nc_putp_flush)(NCURSES_SP_ARGx name, value)
 
 #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 *);
+extern NCURSES_EXPORT(void)     _nc_set_no_padding(SCREEN *);
 #else
 #define GetNoPadding(sp)	FALSE
 #define SetNoPadding(sp)	/*nothing*/
@@ -301,18 +470,37 @@
 #define GET_SCREEN_PAIR(s)	GetPair(SCREEN_ATTRS(s))
 #define SET_SCREEN_PAIR(s,p)	SetPair(SCREEN_ATTRS(s), p)
 
+#if USE_REENTRANT || NCURSES_SP_FUNCS
+NCURSES_EXPORT(int *)        _nc_ptr_Lines (SCREEN *);
+NCURSES_EXPORT(int *)        _nc_ptr_Cols (SCREEN *);
+NCURSES_EXPORT(int *)        _nc_ptr_Tabsize (SCREEN *);
+NCURSES_EXPORT(int *)        _nc_ptr_Escdelay (SCREEN *);
+#endif
+
 #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
+
+#define ptrLines(sp)         (sp ? &(sp->_LINES) : &(_nc_prescreen._LINES))
+#define ptrCols(sp)          (sp ? &(sp->_COLS) : &(_nc_prescreen._COLS))
+#define ptrTabsize(sp)       (sp ? &(sp->_TABSIZE) : &(_nc_prescreen._TABSIZE))
+#define ptrEscdelay(sp)      (sp ? &(sp->_ESCDELAY) : &(_nc_prescreen._ESCDELAY))
+
+#define SET_LINES(value)     *_nc_ptr_Lines(SP_PARM) = value
+#define SET_COLS(value)      *_nc_ptr_Cols(SP_PARM) = value
+#define SET_TABSIZE(value)   *_nc_ptr_Tabsize(SP_PARM) = value
+#define SET_ESCDELAY(value)  *_nc_ptr_Escdelay(SP_PARM) = value
+
 #else
-#define ptrLines() &LINES
-#define ptrCols()  &COLS
-#define SET_LINES(value) LINES = value
-#define SET_COLS(value)  COLS = value
+
+#define ptrLines(sp)         &LINES
+#define ptrCols(sp)          &COLS
+#define ptrTabsize(sp)       &TABSIZE
+#define ptrEscdelay(sp)      &ESCDELAY
+
+#define SET_LINES(value)     LINES = value
+#define SET_COLS(value)      COLS = value
+#define SET_TABSIZE(value)   TABSIZE = value
+#define SET_ESCDELAY(value)  ESCDELAY = value
+
 #endif
 
 #define TR_MUTEX(data) _tracef("%s@%d: me:%08lX COUNT:%2u/%2d/%6d/%2d/%s%9u: " #data, \
@@ -326,6 +514,22 @@
 	    data.__data.__nusers)
 #define TR_GLOBAL_MUTEX(name) TR_MUTEX(_nc_globals.mutex_##name)
 
+#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))
+#else
+#  undef USE_WEAK_SYMBOLS
+#  define USE_WEAK_SYMBOLS 0
+#endif
+#endif
+
 #ifdef USE_PTHREADS
 
 #if USE_REENTRANT
@@ -343,22 +547,10 @@
 #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_kill);
 weak_symbol(pthread_self);
 weak_symbol(pthread_equal);
 weak_symbol(pthread_mutex_init);
@@ -380,6 +572,19 @@
 
 #else /* !USE_PTHREADS */
 
+#if USE_PTHREADS_EINTR
+#  if USE_WEAK_SYMBOLS
+#include <pthread.h>
+weak_symbol(pthread_sigmask);
+weak_symbol(pthread_kill);
+weak_symbol(pthread_self);
+weak_symbol(pthread_equal);
+extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
+#    undef  sigprocmask
+#    define sigprocmask _nc_sigprocmask
+#  endif
+#endif /* USE_PTHREADS_EINTR */
+
 #define _nc_init_pthreads()	/* nothing */
 #define _nc_mutex_init(obj)	/* nothing */
 
@@ -389,6 +594,36 @@
 
 #endif /* USE_PTHREADS */
 
+/*
+ * When using sp-funcs, locks are targeted to SCREEN-level granularity.
+ * So the locking is done in the non-sp-func (which calls the sp-func) rather
+ * than in the sp-func itself.
+ *
+ * Use the _nc_nonsp_XXX functions in the function using "NCURSES_SP_NAME()".
+ * Use the _nc_sp_XXX functions in the function using "#if NCURSES_SP_FUNCS".
+ */
+#if NCURSES_SP_FUNCS
+
+#define _nc_nonsp_lock_global(name)	/* nothing */
+#define _nc_nonsp_try_global(name)    0
+#define _nc_nonsp_unlock_global(name)	/* nothing */
+
+#define _nc_sp_lock_global(name)	_nc_lock_global(name)
+#define _nc_sp_try_global(name)         _nc_try_global(name)
+#define _nc_sp_unlock_global(name)	_nc_unlock_global(name)
+
+#else
+
+#define _nc_nonsp_lock_global(name)	_nc_lock_global(name)
+#define _nc_nonsp_try_global(name)      _nc_try_global(name)
+#define _nc_nonsp_unlock_global(name)	_nc_unlock_global(name)
+
+#define _nc_sp_lock_global(name)	/* nothing */
+#define _nc_sp_try_global(name)    0
+#define _nc_sp_unlock_global(name)	/* nothing */
+
+#endif
+
 #if HAVE_GETTIMEOFDAY
 # define PRECISE_GETTIME 1
 # define TimeType struct timeval
@@ -403,12 +638,14 @@
 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 PAIR_OF(fg, bg)		(colorpair_t) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
+#define FORE_OF(c)		(((c) >> C_SHIFT) & C_MASK)
+#define BACK_OF(c)		((c) & C_MASK)
 #define isDefaultColor(c)	((c) >= COLOR_DEFAULT || (c) < 0)
 
 #define COLOR_DEFAULT		C_MASK
 
-#if defined(USE_TERMLIB) && !defined(NEED_NCURSES_CH_T)
+#if defined(USE_BUILD_CC) || (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 */
@@ -434,8 +671,19 @@
 #if USE_SYSMOUSE
 	,M_SYSMOUSE		/* FreeBSD sysmouse on console */
 #endif
+#ifdef USE_TERM_DRIVER
+	,M_TERM_DRIVER		/* Win32 console, etc */
+#endif
 } MouseType;
 
+typedef enum {
+    	MF_X10 = 0		/* conventional 3-byte format */
+	, MF_SGR1006		/* xterm private mode 1006, SGR-style */
+#ifdef EXP_XTERM_1005
+	, MF_XTERM_1005		/* xterm UTF-8 private mode 1005 */
+#endif
+} MouseFormat;
+
 /*
  * Structures for scrolling.
  */
@@ -452,7 +700,7 @@
 
 struct _SLK;
 
-#ifndef USE_TERMLIB
+#if !(defined(USE_TERMLIB) || defined(USE_BUILD_CC))
 
 typedef struct
 {
@@ -464,13 +712,13 @@
 } slk_ent;
 
 typedef struct _SLK {
-	char dirty;		/* all labels have changed */
-	char hidden;		/* soft labels are hidden */
-	WINDOW *win;
+	bool    dirty;		/* all labels have changed */
+	bool    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 */
+	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;
 
@@ -485,6 +733,9 @@
 #if USE_GPM_SUPPORT
 #undef buttons			/* term.h defines this, and gpm uses it! */
 #include <gpm.h>
+#if USE_WEAK_SYMBOLS
+weak_symbol(Gpm_Wgetch);
+#endif
 
 #ifdef HAVE_LIBDL
 /* link dynamically to GPM */
@@ -493,10 +744,10 @@
 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
+#define my_gpm_fd       SP_PARM->_mouse_gpm_fd
+#define my_Gpm_Open     SP_PARM->_mouse_Gpm_Open
+#define my_Gpm_Close    SP_PARM->_mouse_Gpm_Close
+#define my_Gpm_GetEvent SP_PARM->_mouse_Gpm_GetEvent
 #else
 /* link statically to GPM */
 #define my_gpm_fd       &gpm_fd
@@ -563,8 +814,10 @@
  */
 #if MIXEDCASE_FILENAMES
 #define LEAF_FMT "%c"
+#define LEAF_LEN 1
 #else
 #define LEAF_FMT "%02x"
+#define LEAF_LEN 2
 #endif
 
 /*
@@ -577,17 +830,30 @@
 #define TRACEMSE_MAX	(80 + (5 * 10) + (32 * 15))
 #define TRACEMSE_FMT	"id %2d  at (%2d, %2d, %2d) state %4lx = {" /* } */
 
+#ifdef USE_TERM_DRIVER
+struct DriverTCB; /* Terminal Control Block forward declaration */
+#define INIT_TERM_DRIVER()	_nc_globals.term_driver = _nc_get_driver
+#else
+#define INIT_TERM_DRIVER()	/* nothing */
+#endif
+
+typedef struct {
+    const char *name;
+    char *value;
+} ITERATOR_VARS;
+
 /*
  * Global data which is not specific to a screen.
  */
 typedef struct {
+	SIG_ATOMIC_T	have_sigtstp;
 	SIG_ATOMIC_T	have_sigwinch;
 	SIG_ATOMIC_T	cleanup_nested;
 
 	bool		init_signals;
 	bool		init_screen;
 
-	const char	*comp_sourcename;
+	char		*comp_sourcename;
 	char		*comp_termtype;
 
 	bool		have_tic_directory;
@@ -599,6 +865,7 @@
 
 	char		*first_name;
 	char		**keyname_table;
+	int		init_keyname;
 
 	int		slk_format;
 
@@ -609,8 +876,16 @@
 	int		tgetent_index;
 	long		tgetent_sequence;
 
+	char		*dbd_blob;	/* string-heap for dbd_list[] */
+	char		**dbd_list;	/* distinct places to look for data */
+	int		dbd_size;	/* length of dbd_list[] */
+	time_t		dbd_time;	/* cache last updated */
+	ITERATOR_VARS	dbd_vars[dbdLAST];
+
+#ifndef USE_SP_WINDOWLIST
 	WINDOWLIST	*_nc_windowlist;
-#define _nc_windows	_nc_globals._nc_windowlist
+#define WindowList(sp)	_nc_globals._nc_windowlist
+#endif
 
 #if USE_HOME_TERMINFO
 	char		*home_terminfo;
@@ -621,6 +896,10 @@
 	int		safeprint_rows;
 #endif
 
+#ifdef USE_TERM_DRIVER
+	int		(*term_driver)(struct DriverTCB*, const char*, int*);
+#endif
+
 #ifdef TRACE
 	bool		init_trace;
 	char		trace_fname[PATH_MAX];
@@ -644,7 +923,9 @@
 	char		traceatr_color_buf[2][80];
 	int		traceatr_color_sel;
 	int		traceatr_color_last;
-
+#if !defined(USE_PTHREADS) && USE_REENTRANT
+	int		nested_tracef;
+#endif
 #endif	/* TRACE */
 
 #ifdef USE_PTHREADS
@@ -655,6 +936,9 @@
 	int		use_pthreads;
 #define _nc_use_pthreads	_nc_globals.use_pthreads
 #endif
+#if USE_PTHREADS_EINTR
+	pthread_t	read_thread;		/* The reading thread */
+#endif
 } NCURSES_GLOBALS;
 
 extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
@@ -669,27 +953,41 @@
 	bool		use_env;
 	bool		filter_mode;
 	attr_t		previous_attr;
+#ifndef USE_SP_RIPOFF
 	ripoff_t	rippedoff[N_RIPS];
 	ripoff_t	*rsp;
+#endif
 	TPARM_STATE	tparm_state;
 	TTY		*saved_tty;	/* savetty/resetty information	    */
 #if NCURSES_NO_PADDING
 	bool		_no_padding;	/* flag to set if padding disabled  */
 #endif
+	NCURSES_SP_OUTC	_outch;		/* output handler if not putc */
 #if BROKEN_LINKER || USE_REENTRANT
 	chtype		*real_acs_map;
 	int		_LINES;
 	int		_COLS;
+	int		_TABSIZE;
+	int		_ESCDELAY;
 	TERMINAL	*_cur_term;
 #ifdef TRACE
 	long		_outchars;
 	const char	*_tputs_trace;
 #endif
 #endif
+	bool		use_tioctl;
 } NCURSES_PRESCREEN;
 
-#define ripoff_sp	_nc_prescreen.rsp
-#define ripoff_stack	_nc_prescreen.rippedoff
+/*
+ * Use screen-specific ripoff data (for softkeys) rather than global.
+ */
+#ifdef USE_SP_RIPOFF
+#define safe_ripoff_sp     (sp)->rsp
+#define safe_ripoff_stack  (sp)->rippedoff
+#else
+#define safe_ripoff_sp	   _nc_prescreen.rsp
+#define safe_ripoff_stack  _nc_prescreen.rippedoff
+#endif
 
 extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
 
@@ -698,11 +996,15 @@
  */
 
 struct screen {
-	int		_ifd;		/* input file ptr for screen	    */
+	int		_ifd;		/* input file descriptor for screen */
+	int		_ofd;		/* output file descriptor for screen */
 	FILE		*_ofp;		/* output file ptr for screen	    */
-	char		*_setbuf;	/* buffered I/O for output	    */
+	char		*out_buffer;	/* output buffer		    */
+	size_t		out_limit;	/* output buffer size		    */
+	size_t		out_inuse;	/* output buffer current use	    */
 	bool		_filtered;	/* filter() was called		    */
-	bool		_buffered;	/* setvbuf uses _setbuf data	    */
+	bool		_prescreen;	/* is in prescreen phase	    */
+	bool		_use_env;	/* LINES & COLS from environment?   */
 	int		_checkfd;	/* filedesc for typeahead check	    */
 	TERMINAL	*_term;		/* terminal type information	    */
 	TTY		_saved_tty;	/* savetty/resetty information	    */
@@ -716,6 +1018,10 @@
 	WINDOW		*_newscr;	/* virtual screen to be updated to  */
 	WINDOW		*_stdscr;	/* screen's full-window context	    */
 
+#define CurScreen(sp)  (sp)->_curscr
+#define NewScreen(sp)  (sp)->_newscr
+#define StdScreen(sp)  (sp)->_stdscr
+
 	TRIES		*_keytry;	/* "Try" for use with keypad mode   */
 	TRIES		*_key_ok;	/* Disabled keys via keyok(,FALSE)  */
 	bool		_tried;		/* keypad mode was initialized	    */
@@ -794,11 +1100,14 @@
 	int		_color_count;	/* count of colors in palette	     */
 	colorpair_t	*_color_pairs;	/* screen's color pair list	     */
 	int		_pair_count;	/* count of color pairs		     */
+	int		_pair_limit;	/* actual limit of color-pairs       */
 #if NCURSES_EXT_FUNCS
+	bool		_assumed_color; /* use assumed colors		     */
 	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	     */
+	int		_default_pairs;	/* count pairs using default color   */
 #endif
 	chtype		_ok_attributes; /* valid attributes for terminal     */
 	chtype		_xmc_suppress;	/* attributes to suppress if xmc     */
@@ -810,6 +1119,13 @@
 	/* used in lib_vidattr.c */
 	bool		_use_rmso;	/* true if we may use 'rmso'	     */
 	bool		_use_rmul;	/* true if we may use 'rmul'	     */
+#if USE_ITALIC
+	bool		_use_ritm;	/* true if we may use 'ritm'	     */
+#endif
+
+#if USE_KLIBC_KBD
+	bool		_extended_key;	/* true if an extended key	     */
+#endif
 
 	/*
 	 * These data correspond to the state of the idcok() and idlok()
@@ -820,8 +1136,6 @@
 	 */
 	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.
@@ -836,7 +1150,10 @@
 	void		(*_mouse_wrap)	(SCREEN *);
 	int		_mouse_fd;	/* file-descriptor, if any */
 	bool		_mouse_active;	/* true if initialized */
-	mmask_t		_mouse_mask;
+	mmask_t		_mouse_mask;	/* set via mousemask() */
+	mmask_t		_mouse_mask2;	/* OR's in press/release bits */
+	mmask_t		_mouse_bstate;
+	MouseFormat	_mouse_format;	/* type of xterm mouse protocol */
 	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 */
@@ -871,11 +1188,19 @@
 	int		_sysmouse_new_buttons;
 #endif
 
+#ifdef USE_TERM_DRIVER
+	MEVENT		_drv_mouse_fifo[FIFO_SIZE];
+	int		_drv_mouse_head;
+	int		_drv_mouse_tail;
+	int		_drv_mouse_old_buttons;
+	int		_drv_mouse_new_buttons;
+#endif
 	/*
 	 * This supports automatic resizing
 	 */
 #if USE_SIZECHANGE
-	int		(*_resize)(int,int);
+	int		(*_resize)(NCURSES_SP_DCLx int y, int x);
+	int		(*_ungetch)(SCREEN *, int);
 #endif
 
 	/*
@@ -894,8 +1219,7 @@
 	int		*_oldnum_list;
 	int		_oldnum_size;
 
-	bool		_cleanup;	/* cleanup after int/quit signal */
-	int		(*_outch)(int); /* output handler if not putc */
+	NCURSES_SP_OUTC	_outch;		/* output handler if not putc */
 
 	int		_legacy_coding;	/* see use_legacy_coding() */
 
@@ -915,6 +1239,15 @@
 	char		tracechr_buf[40];
 	char		tracemse_buf[TRACEMSE_MAX];
 #endif
+#ifdef USE_SP_WINDOWLIST
+	WINDOWLIST*	_windowlist;
+#define WindowList(sp)  (sp)->_windowlist
+#endif
+	NCURSES_OUTC	jump;
+
+	ripoff_t	rippedoff[N_RIPS];
+	ripoff_t	*rsp;
+
 	/*
 	 * ncurses/ncursesw are the same up to this point.
 	 */
@@ -923,17 +1256,20 @@
 	 * UTF-8, but do not permit ACS at the same time (see tty_update.c).
 	 */
 	bool		_screen_acs_fix;
+	bool		_screen_unicode;
 #endif
+
+	bool		_use_tioctl;
 };
 
 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
+	WINDOW	win;		/* WINDOW_EXT() needs to account for offset */
+#if NCURSES_WIDECHAR
 	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[] */
@@ -941,7 +1277,21 @@
 #endif
 };
 
-#define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
+#define WINDOW_EXT(w,m) (((WINDOWLIST *)((void *)((char *)(w) - offsetof(WINDOWLIST, win))))->m)
+
+#define SP_PRE_INIT(sp)                         \
+    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->_cursor = -1;                           \
+    WindowList(sp) = 0;                         \
+    sp->_outch = NCURSES_OUTC_FUNC;             \
+    sp->jump = 0                                \
 
 /* usually in <limits.h> */
 #ifndef UCHAR_MAX
@@ -1017,8 +1367,9 @@
 #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)
+#define UShort(c)	((unsigned short)(c))
+#define ChCharOf(c)	((chtype)(c) & (chtype)A_CHARTEXT)
+#define ChAttrOf(c)	((chtype)(c) & (chtype)A_ATTRIBUTES)
 
 #ifndef MB_LEN_MAX
 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
@@ -1061,9 +1412,9 @@
 #define SetChar(ch,c,a) do {							    \
 			    NCURSES_CH_T *_cp = &ch;				    \
 			    memset(_cp, 0, sizeof(ch));				    \
-			    _cp->chars[0] = (c);					    \
+			    _cp->chars[0] = (wchar_t) (c);			    \
 			    _cp->attr = (a);					    \
-			    if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a)));		    \
+			    if_EXT_COLORS(SetPair(ch, PairNumber(a)));		    \
 			} while (0)
 #define CHREF(wch)	(&wch)
 #define CHDEREF(wch)	(*wch)
@@ -1072,9 +1423,9 @@
 #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)) {				    \
+#define PUTC(ch)	do { if(!isWidecExt(ch)) {				    \
 			if (Charable(ch)) {					    \
-			    fputc(CharOf(ch), b);				    \
+			    NCURSES_OUTC_FUNC (NCURSES_SP_ARGx CharOf(ch)); \
 			    COUNT_OUTCHARS(1);					    \
 			} else {						    \
 			    PUTC_INIT;						    \
@@ -1082,14 +1433,18 @@
 				PUTC_ch = (ch).chars[PUTC_i];			    \
 				if (PUTC_ch == L'\0')				    \
 				    break;					    \
-				PUTC_n = wcrtomb(PUTC_buf,			    \
-						 (ch).chars[PUTC_i], &PUT_st);	    \
+				PUTC_n = (int) 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);			    \
+					NCURSES_OUTC_FUNC (NCURSES_SP_ARGx CharOf(ch)); \
 				    break;					    \
+				} else {					    \
+				    int PUTC_j;					    \
+				    for (PUTC_j = 0; PUTC_j < PUTC_n; ++PUTC_j) {   \
+					NCURSES_OUTC_FUNC (NCURSES_SP_ARGx PUTC_buf[PUTC_j]); \
+				    }						    \
 				}						    \
-				fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b);	    \
 			    }							    \
 			    COUNT_OUTCHARS(PUTC_i);				    \
 			} } } while (0)
@@ -1105,18 +1460,18 @@
 	 * 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 WidecExt(ch)	(int) (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)
+				AttrOf(dst) |= (attr_t) (ext + 1)
 
 #define if_WIDEC(code)  code
-#define Charable(ch)	((SP != 0 && SP->_legacy_coding)		\
+#define Charable(ch)	(((SP_PARM->_legacy_coding)			\
 			 || (AttrOf(ch) & A_ALTCHARSET)			\
-			 || (!isWidecExt(ch) &&				\
+			 || (!isWidecExt(ch))) &&			\
 			     (ch).chars[1] == L'\0' &&			\
-			     _nc_is_charable(CharOf(ch))))
+			     _nc_is_charable(CharOf(ch)))
 
 #define L(ch)		L ## ch
 #else /* }{ */
@@ -1133,8 +1488,8 @@
 #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 PUTC_DATA	/* nothing */
+#define PUTC(ch)	NCURSES_OUTC_FUNC (NCURSES_SP_ARGx (int) ch)
 
 #define BLANK		(' '|A_NORMAL)
 #define ZEROS		('\0'|A_NORMAL)
@@ -1162,25 +1517,25 @@
 
 #define CHANGED_CELL(line,col) \
 	if (line->firstchar == _NOCHANGE) \
-		line->firstchar = line->lastchar = col; \
+		line->firstchar = line->lastchar = (NCURSES_SIZE_T) (col); \
 	else if ((col) < line->firstchar) \
-		line->firstchar = col; \
+		line->firstchar = (NCURSES_SIZE_T) (col); \
 	else if ((col) > line->lastchar) \
-		line->lastchar = col
+		line->lastchar = (NCURSES_SIZE_T) (col)
 
 #define CHANGED_RANGE(line,start,end) \
 	if (line->firstchar == _NOCHANGE \
 	 || line->firstchar > (start)) \
-		line->firstchar = start; \
+		line->firstchar = (NCURSES_SIZE_T) (start); \
 	if (line->lastchar == _NOCHANGE \
 	 || line->lastchar < (end)) \
-		line->lastchar = end
+		line->lastchar = (NCURSES_SIZE_T) (end)
 
 #define CHANGED_TO_EOL(line,start,end) \
 	if (line->firstchar == _NOCHANGE \
 	 || line->firstchar > (start)) \
-		line->firstchar = start; \
-	line->lastchar = end
+		line->firstchar = (NCURSES_SIZE_T) (start); \
+	line->lastchar = (NCURSES_SIZE_T) (end)
 
 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
 
@@ -1194,6 +1549,20 @@
 #include <nc_alloc.h>
 
 /*
+ * Use these for tic/infocmp malloc failures.  Generally the ncurses library
+ * tries to limp along after a failure.
+ */
+#define TYPE_MALLOC(type, size, name) \
+	name = typeMalloc(type, size); \
+	if (name == 0) \
+	    _nc_err_abort(MSG_NO_MEMORY)
+
+#define TYPE_REALLOC(type, size, name) \
+	name = typeRealloc(type, size, name); \
+	if (name == 0) \
+	    _nc_err_abort(MSG_NO_MEMORY)
+
+/*
  * TTY bit definition for converting tabs to spaces.
  */
 #ifdef TAB3
@@ -1214,8 +1583,8 @@
  * 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
+#define each_window(sp,p) p = WindowList(sp); p != 0; p = (p)->next
+#define each_ripoff(p) p = safe_ripoff_stack; (p - safe_ripoff_stack) < N_RIPS; ++p
 
 /*
  * Prefixes for call/return points of library function traces.  We use these to
@@ -1256,22 +1625,30 @@
 
 #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 TRACE_RETURN(value,type)     return _nc_retrace_##type((type)(value))
+#define TRACE_RETURN1(value,dst)     return _nc_retrace_##dst(value)
+#define TRACE_RETURN2(value,dst,src) return _nc_retrace_##dst##_##src(value)
+#define TRACE_RETURN_SP(value,type)  return _nc_retrace_##type(SP_PARM, value)
+
+#define NonNull(s)	((s) != 0 ? s : "<null>")
 
 #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 returnCPtr(code)	TRACE_RETURN1(code,cptr)
+#define returnCVoidPtr(code)	TRACE_RETURN1(code,cvoid_ptr)
+#define returnChar(code)	TRACE_RETURN(code,char)
+#define returnChtype(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 returnIntAttr(code)	TRACE_RETURN2(code,int,attr_t)
+#define returnMMask(code)	TRACE_RETURN_SP(code,mmask_t)
+#define returnPtr(code)		TRACE_RETURN1(code,ptr)
+#define returnSP(code)		TRACE_RETURN1(code,sp)
 #define returnVoid		T((T_RETURN(""))); return
-#define returnVoidPtr(code)	TRACE_RETURN(code,void_ptr)
-#define returnWin(code)		TRACE_RETURN(code,win)
+#define returnVoidPtr(code)	TRACE_RETURN1(code,void_ptr)
+#define returnWin(code)		TRACE_RETURN1(code,win)
 
-extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (NCURSES_BOOL);
+extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (int);
 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 *);
@@ -1282,7 +1659,10 @@
 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(char)             _nc_retrace_char (int);
 extern NCURSES_EXPORT(int)              _nc_retrace_int (int);
+extern NCURSES_EXPORT(int)              _nc_retrace_int_attr_t (attr_t);
+extern NCURSES_EXPORT(mmask_t)          _nc_retrace_mmask_t (SCREEN *, mmask_t);
 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 *);
@@ -1322,8 +1702,11 @@
 #define returnBool(code)	return code
 #define returnCPtr(code)	return code
 #define returnCVoidPtr(code)	return code
-#define returnChar(code)	return code
+#define returnChar(code)	return ((char) code)
+#define returnChtype(code)	return code
 #define returnCode(code)	return code
+#define returnIntAttr(code)	return code
+#define returnMMask(code)	return code
 #define returnPtr(code)		return code
 #define returnSP(code)		return code
 #define returnVoid		return
@@ -1333,6 +1716,15 @@
 #endif /* TRACE/!TRACE */
 
 /*
+ * Workaround for defective implementation of gcc attribute warn_unused_result
+ */
+#if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
+#define IGNORE_RC(func) errno = (int) func
+#else
+#define IGNORE_RC(func) (void) func
+#endif /* gcc workarounds */
+
+/*
  * Return-codes for tgetent() and friends.
  */
 #define TGETENT_YES  1		/* entry is found */
@@ -1347,58 +1739,61 @@
 	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 NONBLANK_ATTR (A_BOLD | A_DIM | A_BLINK | A_ITALIC)
+#define TPARM_ATTR    (A_STANDOUT | A_UNDERLINE | A_REVERSE | A_BLINK | A_DIM | A_BOLD | A_ALTCHARSET | A_INVIS | A_PROTECT)
+#define XMC_CONFLICT  (A_STANDOUT | A_UNDERLINE | A_REVERSE | A_BLINK | A_DIM | A_BOLD | A_INVIS | A_PROTECT | A_ITALIC)
+#define XMC_CHANGES(c) ((c) & SP_PARM->_xmc_suppress)
 
 #define toggle_attr_on(S,at) {\
-   if (PAIR_NUMBER(at) > 0) {\
-      (S) = ((S) & ALL_BUT_COLOR) | (at);\
+   if (PairNumber(at) > 0) {\
+      (S) = ((S) & ALL_BUT_COLOR) | (attr_t) (at);\
    } else {\
-      (S) |= (at);\
+      (S) |= (attr_t) (at);\
    }\
    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
 
 
 #define toggle_attr_off(S,at) {\
-   if (PAIR_NUMBER(at) > 0) {\
+   if (PairNumber(at) > 0) {\
       (S) &= ~(at|A_COLOR);\
    } else {\
       (S) &= ~(at);\
    }\
    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
 
-#define DelCharCost(count) \
+#define DelCharCost(sp,count) \
 		((parm_dch != 0) \
-		? SP->_dch_cost \
+		? sp->_dch_cost \
 		: ((delete_character != 0) \
-			? (SP->_dch1_cost * count) \
+			? (sp->_dch1_cost * count) \
 			: INFINITY))
 
-#define InsCharCost(count) \
+#define InsCharCost(sp,count) \
 		((parm_ich != 0) \
-		? SP->_ich_cost \
+		? sp->_ich_cost \
 		: ((enter_insert_mode && exit_insert_mode) \
-		  ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
+		  ? sp->_smir_cost + sp->_rmir_cost + (sp->_ip_cost * count) \
 		  : ((insert_character != 0) \
-		    ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
+		    ? ((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)); \
+#define UpdateAttrs(sp,c) if (!SameAttrOf(SCREEN_ATTRS(sp), c)) { \
+				attr_t chg = AttrOf(SCREEN_ATTRS(sp)); \
+				VIDATTR(sp, AttrOf(c), GetPair(c)); \
 				if (magic_cookie_glitch > 0 \
-				 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
+				 && 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); \
+						sp->_cursrow, \
+						sp->_curscol)); \
+					NCURSES_SP_NAME(_nc_do_xmc_glitch)(NCURSES_SP_ARGx chg); \
 				} \
 			}
 #else
-#define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
-				VIDATTR(AttrOf(c), GetPair(c));
+#define UpdateAttrs(sp,c) if (!SameAttrOf(SCREEN_ATTRS(sp), c)) { \
+				    VIDATTR(sp, AttrOf(c), GetPair(c)); \
+			}
 #endif
 
 /*
@@ -1408,10 +1803,12 @@
 #define EVENTLIST_0th(param) param
 #define EVENTLIST_1st(param) param
 #define EVENTLIST_2nd(param) , param
+#define TWAIT_MASK (TW_ANY | TW_EVENT)
 #else
 #define EVENTLIST_0th(param) void
 #define EVENTLIST_1st(param) /* nothing */
 #define EVENTLIST_2nd(param) /* nothing */
+#define TWAIT_MASK TW_ANY
 #endif
 
 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
@@ -1425,16 +1822,28 @@
 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);
+#define DelCharCost(sp, count) NCURSES_SP_NAME(_nc_DelCharCost)(NCURSES_SP_ARGx count)
 
 #undef  InsCharCost
-#define InsCharCost(count) _nc_InsCharCost(count)
-extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
+#define InsCharCost(sp, count) NCURSES_SP_NAME(_nc_InsCharCost)(NCURSES_SP_ARGx count)
+
+extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_DelCharCost) (NCURSES_SP_DCLx int _c);
+extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_InsCharCost) (NCURSES_SP_DCLx int _c);
 
 #undef  UpdateAttrs
-#define UpdateAttrs(c) _nc_UpdateAttrs(c)
-extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
+#define UpdateAttrs(sp,c) NCURSES_SP_NAME(_nc_UpdateAttrs)(NCURSES_SP_ARGx CHREF(c))
+
+#if USE_WIDEC_SUPPORT || defined(NEED_NCURSES_CH_T)
+extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_UpdateAttrs) (NCURSES_SP_DCLx CARG_CH_T _c);
+#else
+extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_UpdateAttrs) (NCURSES_SP_DCLx chtype c);
+#endif
+
+#if NCURSES_SP_FUNCS
+extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
+extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
+extern NCURSES_EXPORT(void) _nc_UpdateAttrs (CARG_CH_T);
+#endif /* NCURSES_SP_FUNCS */
 
 #else
 
@@ -1483,8 +1892,8 @@
 #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 */
+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
@@ -1492,7 +1901,7 @@
 #endif
 
 /* lib_addstr.c */
-#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
+#if USE_WIDEC_SUPPORT && !(defined(USE_TERMLIB) || defined(USE_BUILD_CC))
 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
 #endif
 
@@ -1500,14 +1909,16 @@
 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 *));
+extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, int *, int EVENTLIST_2nd(_nc_eventlist *));
 
 /* lib_insch.c */
-extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
+extern NCURSES_EXPORT(int) _nc_insert_ch(SCREEN *, WINDOW *, chtype);
 
 /* lib_mvcur.c */
 #define INFINITY	1000000	/* cost: too high to use */
 
+extern NCURSES_EXPORT(int) _nc_mvcur(int yold, int xold, int ynew, int xnew);
+
 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
@@ -1519,7 +1930,7 @@
 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
 
 /* lib_mouse.c */
-extern NCURSES_EXPORT(int) _nc_has_mouse (void);
+extern NCURSES_EXPORT(bool) _nc_has_mouse (SCREEN *);
 
 /* lib_mvcur.c */
 #define INFINITY	1000000	/* cost: too high to use */
@@ -1527,10 +1938,33 @@
 
 /* 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 *);
+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 *, int);
+extern NCURSES_EXPORT(void)   _nc_tinfo_cmdch(TERMINAL *, int);
+
+/* lib_set_term.c */
+extern NCURSES_EXPORT(int)    _nc_ripoffline(int, int(*)(WINDOW*, int));
+
+/* lib_setup.c */
+#define SETUP_FAIL ERR
+#define ret_error(code, fmt, arg)	if (errret) {\
+					    *errret = code;\
+					    returnCode(SETUP_FAIL);\
+					} else {\
+					    fprintf(stderr, fmt, arg);\
+					    exit(EXIT_FAILURE);\
+					}
+
+#define ret_error1(code, fmt, arg)	ret_error(code, "'%s': " fmt, arg)
+
+#define ret_error0(code, msg)		if (errret) {\
+					    *errret = code;\
+					    returnCode(SETUP_FAIL);\
+					} else {\
+					    fprintf(stderr, msg);\
+					    exit(EXIT_FAILURE);\
+					}
 
 /* lib_tstp.c */
 #if USE_SIGWINCH
@@ -1539,9 +1973,6 @@
 #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);
@@ -1577,27 +2008,31 @@
 
 /* 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(TERMINAL*) _nc_get_cur_term (void);
 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(char *) _nc_trace_mmask_t (SCREEN *, mmask_t);
 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_keypad (SCREEN *, int);
 extern NCURSES_EXPORT(int) _nc_ospeed (int);
 extern NCURSES_EXPORT(int) _nc_outch (int);
+extern NCURSES_EXPORT(int) _nc_putchar (int);
+extern NCURSES_EXPORT(int) _nc_putp(const char *, const char *);
+extern NCURSES_EXPORT(int) _nc_putp_flush(const char *, const char *);
 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_setup_tinfo(const char *, TERMTYPE *);
+extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, int, 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_do_color (int, int, int, NCURSES_OUTC);
 extern NCURSES_EXPORT(void) _nc_flush (void);
-extern NCURSES_EXPORT(void) _nc_free_and_exit (int);
+extern NCURSES_EXPORT(void) _nc_free_and_exit (int) GCC_NORETURN;
 extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *);
 extern NCURSES_EXPORT(void) _nc_freeall (void);
 extern NCURSES_EXPORT(void) _nc_hash_map (void);
@@ -1606,8 +2041,9 @@
 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_set_buffer (FILE *, int);
+extern NCURSES_EXPORT(void) _nc_setenv_num (const char *, int);
+extern NCURSES_EXPORT(void) _nc_signal_handler (int);
 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
 extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *);
 
@@ -1616,19 +2052,25 @@
 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_error_leaks(void);
 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
+extern NCURSES_EXPORT(void) _nc_db_iterator_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
+#if !(defined(USE_TERMLIB) || defined(USE_BUILD_CC))
 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);
+extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, int const, int const, NCURSES_CH_T);
 #endif
 
-#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(int) _nc_insert_wch(WINDOW *, const cchar_t *);
+#endif
+
+#if USE_WIDEC_SUPPORT && !(defined(USE_TERMLIB) || defined(USE_BUILD_CC))
 extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
 #endif
 
@@ -1650,6 +2092,45 @@
 #endif
 
 /*
+ * Wide-character macros to hide some platform-differences.
+ */
+#if USE_WIDEC_SUPPORT
+
+#if defined(__MINGW32__)
+/*
+ * MinGW has wide-character functions, but they do not work correctly.
+ */
+
+extern int __MINGW_NOTHROW _nc_wctomb(char *, wchar_t);
+#define wctomb(s,wc) _nc_wctomb(s,wc)
+#define wcrtomb(s,wc,n) _nc_wctomb(s,wc)
+
+extern int __MINGW_NOTHROW _nc_mbtowc(wchar_t *, const char *, size_t);
+#define mbtowc(pwc,s,n) _nc_mbtowc(pwc,s,n)
+
+extern int __MINGW_NOTHROW _nc_mblen(const char *, size_t);
+#define mblen(s,n) _nc_mblen(s, n)
+
+#endif /* __MINGW32__ */
+
+#if HAVE_MBTOWC && HAVE_MBLEN
+#define reset_mbytes(state) IGNORE_RC(mblen(NULL, (size_t) 0)), IGNORE_RC(mbtowc(NULL, NULL, (size_t) 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
+
+#endif /* USE_WIDEC_SUPPORT */
+
+/*
  * Not everyone has vsscanf(), but we'd like to use it for scanw().
  */
 #if !HAVE_VSSCANF
@@ -1661,24 +2142,32 @@
 
 #define USE_SETBUF_0 0
 
-#define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
-
-#define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout)
+#define NC_OUTPUT(sp) ((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'.
  */
+#define _nc_alloc_screen_sp() typeCalloc(SCREEN, 1)
+
 #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 *);
+extern NCURSES_EXPORT(int)      _nc_alloc_screen (void);
+extern NCURSES_EXPORT(void)     _nc_set_screen (SCREEN *);
+#define CURRENT_SCREEN          _nc_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
+#define CURRENT_SCREEN SP
+#define _nc_alloc_screen()      ((SP = _nc_alloc_screen_sp()) != 0)
+#define _nc_set_screen(sp)      SP = sp
+#endif
+
+#if NCURSES_SP_FUNCS
+#define CURRENT_SCREEN_PRE      (IsPreScreen(CURRENT_SCREEN) ? CURRENT_SCREEN : new_prescr())
+#else
+#define CURRENT_SCREEN_PRE      CURRENT_SCREEN
 #endif
 
 /*
@@ -1686,10 +2175,11 @@
  * 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
+#define screen_lines(sp)        (sp)->_lines
+#define screen_columns(sp)      (sp)->_columns
 
 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
+extern NCURSES_EXPORT(int) _nc_format_slks (NCURSES_SP_DCLx int _c);
 
 /*
  * Some constants related to SLK's
@@ -1707,16 +2197,311 @@
 #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"
 
+extern NCURSES_EXPORT(int) _nc_set_tty_mode(TTY *);
+extern NCURSES_EXPORT(int) _nc_get_tty_mode(TTY *);
+
+/* timed_wait flag definitions */
+#define TW_NONE    0
+#define TW_INPUT   1
+#define TW_MOUSE   2
+#define TW_ANY     (TW_INPUT | TW_MOUSE)
+#define TW_EVENT   4
+
+#define SetSafeOutcWrapper(outc)	    \
+    SCREEN* sp = CURRENT_SCREEN;            \
+    struct screen outc_wrapper;		    \
+    if (sp==0) {                            \
+	sp = &outc_wrapper;                 \
+	memset(sp,0,sizeof(struct screen)); \
+	sp->_outch = _nc_outc_wrapper;      \
+    }\
+    sp->jump = outc
+
+#ifdef USE_TERM_DRIVER
+
+typedef struct _termInfo
+{
+    bool caninit;
+
+    bool hascolor;
+    bool initcolor;
+    bool canchange;
+
+    int  tabsize;
+
+    int  maxcolors;
+    int  maxpairs;
+    int  nocolorvideo;
+
+    int  numbuttons;
+    int  numlabels;
+    int  labelwidth;
+    int  labelheight;
+
+    const color_t* defaultPalette;
+} TerminalInfo;
+
+typedef struct term_driver {
+    bool   isTerminfo;
+    const char* (*td_name)(struct DriverTCB*);
+    bool   (*td_CanHandle)(struct DriverTCB*, const char*, int*);
+    void   (*td_init)(struct DriverTCB*);
+    void   (*td_release)(struct DriverTCB*);
+    int    (*td_size)(struct DriverTCB*, int* Line, int *Cols);
+    int    (*td_sgmode)(struct DriverTCB*, int setFlag, TTY*);
+    chtype (*td_conattr)(struct DriverTCB*);
+    int    (*td_hwcur)(struct DriverTCB*, int yold, int xold, int y, int x);
+    int    (*td_mode)(struct DriverTCB*, int progFlag, int defFlag);
+    bool   (*td_rescol)(struct DriverTCB*);
+    bool   (*td_rescolors)(struct DriverTCB*);
+    void   (*td_color)(struct DriverTCB*, int fore, int color, int(*)(SCREEN*, int));
+    int    (*td_doBeepOrFlash)(struct DriverTCB*, int);
+    void   (*td_initpair)(struct DriverTCB*, int, int, int);
+    void   (*td_initcolor)(struct DriverTCB*, int, int, int, int);
+    void   (*td_docolor)(struct DriverTCB*, int, int, int, int(*)(SCREEN*, int));
+    void   (*td_initmouse)(struct DriverTCB*);
+    int    (*td_testmouse)(struct DriverTCB*, int EVENTLIST_2nd(_nc_eventlist*));
+    void   (*td_setfilter)(struct DriverTCB*);
+    void   (*td_hwlabel)(struct DriverTCB*, int, char*);
+    void   (*td_hwlabelOnOff)(struct DriverTCB*, int);
+    int    (*td_update)(struct DriverTCB*);
+    int    (*td_defaultcolors)(struct DriverTCB*, int, int);
+    int    (*td_print)(struct DriverTCB*, char*, int);
+    int    (*td_getsize)(struct DriverTCB*, int*, int*);
+    int    (*td_setsize)(struct DriverTCB*, int, int);
+    void   (*td_initacs)(struct DriverTCB*, chtype*, chtype*);
+    void   (*td_scinit)(SCREEN *);
+    void   (*td_scexit)(SCREEN *);
+    int    (*td_twait)(struct DriverTCB*, int, int, int* EVENTLIST_2nd(_nc_eventlist*));
+    int    (*td_read)(struct DriverTCB*, int*);
+    int    (*td_nap)(struct DriverTCB*, int);
+    int    (*td_kpad)(struct DriverTCB*, int);
+    int    (*td_kyOk)(struct DriverTCB*, int, int);
+    bool   (*td_kyExist)(struct DriverTCB*, int);
+    int    (*td_cursorSet)(struct DriverTCB*, int);
+} TERM_DRIVER;
+
+typedef struct DriverTCB
+{
+    TERMINAL      term;   /* needs to be the first Element !!! */
+    TERM_DRIVER*  drv;    /* The driver for that Terminal */
+    SCREEN*       csp;    /* The screen that owns that Terminal */
+    TerminalInfo  info;   /* Driver independent core capabilities of the Terminal */
+    void*         prop;   /* Driver dependent property storage to be used by the Driver */
+    long          magic;
+} TERMINAL_CONTROL_BLOCK;
+
+#define NCDRV_MAGIC(id) (0x47110000 | (id&0xffff))
+#define NCDRV_TINFO      0x01
+#define NCDRV_WINCONSOLE 0x02
+
+#define TCBOf(sp)    ((TERMINAL_CONTROL_BLOCK*)(TerminalOf(sp)))
+#define InfoOf(sp)   TCBOf(sp)->info
+#define CallDriver(sp,method)                        TCBOf(sp)->drv->method(TCBOf(sp))
+#define CallDriver_1(sp,method,arg1)                 TCBOf(sp)->drv->method(TCBOf(sp),arg1)
+#define CallDriver_2(sp,method,arg1,arg2)            TCBOf(sp)->drv->method(TCBOf(sp),arg1,arg2)
+#define CallDriver_3(sp,method,arg1,arg2,arg3)       TCBOf(sp)->drv->method(TCBOf(sp),arg1,arg2,arg3)
+#define CallDriver_4(sp,method,arg1,arg2,arg3,arg4)  TCBOf(sp)->drv->method(TCBOf(sp),arg1,arg2,arg3,arg4)
+
+extern NCURSES_EXPORT_VAR(const color_t*) _nc_cga_palette;
+extern NCURSES_EXPORT_VAR(const color_t*) _nc_hls_palette;
+
+extern NCURSES_EXPORT(int)      _nc_get_driver(TERMINAL_CONTROL_BLOCK*, const char*, int*);
+extern NCURSES_EXPORT(void)     _nc_get_screensize_ex(SCREEN *, TERMINAL *, int *, int *);
+#endif /* USE_TERM_DRIVER */
+
+/*
+ * Entrypoints which are actually provided in the terminal driver, which would
+ * be an sp-name otherwise.
+ */
+#ifdef USE_TERM_DRIVER
+#define TINFO_HAS_KEY           _nc_tinfo_has_key
+#define TINFO_DOUPDATE          _nc_tinfo_doupdate
+#define TINFO_MVCUR             _nc_tinfo_mvcur
+extern NCURSES_EXPORT(int)      TINFO_HAS_KEY(SCREEN*, int);
+extern NCURSES_EXPORT(int)      TINFO_DOUPDATE(SCREEN *);
+extern NCURSES_EXPORT(int)      TINFO_MVCUR(SCREEN*, int, int, int, int);
+#else
+#define TINFO_HAS_KEY           NCURSES_SP_NAME(has_key)
+#define TINFO_DOUPDATE          NCURSES_SP_NAME(doupdate)
+#define TINFO_MVCUR             NCURSES_SP_NAME(_nc_mvcur)
+#endif
+
+/*
+ * Entrypoints using an extra parameter with the terminal driver.
+ */
+#ifdef USE_TERM_DRIVER
+extern NCURSES_EXPORT(void)   _nc_get_screensize(SCREEN *, TERMINAL *, int *, int *);
+extern NCURSES_EXPORT(int)    _nc_setupterm_ex(TERMINAL **, NCURSES_CONST char *, int , int *, int);
+#define TINFO_GET_SIZE(sp, tp, lp, cp) \
+	_nc_get_screensize(sp, tp, lp, cp)
+#define TINFO_SET_CURTERM(sp, tp) \
+	NCURSES_SP_NAME(set_curterm)(sp, tp)
+#define TINFO_SETUP_TERM(tpp, name, fd, err, reuse) \
+	_nc_setupterm_ex(tpp, name, fd, err, reuse)
+#else /* !USE_TERM_DRIVER */
+extern NCURSES_EXPORT(void)   _nc_get_screensize(SCREEN *, int *, int *);
+#define TINFO_GET_SIZE(sp, tp, lp, cp) \
+	_nc_get_screensize(sp, lp, cp)
+#define TINFO_SET_CURTERM(sp, tp) \
+	set_curterm(tp)
+#define TINFO_SETUP_TERM(tpp, name, fd, err, reuse) \
+	_nc_setupterm(name, fd, err, reuse)
+#endif /* !USE_TERM_DRIVER */
+
+#ifdef USE_TERM_DRIVER
+#if defined(USE_WIN32CON_DRIVER)
+#include <nc_mingw.h>
+extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER;
+extern NCURSES_EXPORT(int)  _nc_mingw_isatty(int fd);
+extern NCURSES_EXPORT(int)  _nc_mingw_isconsole(int fd);
+extern NCURSES_EXPORT(int) _nc_mingw_console_read(
+    SCREEN *sp,
+    HANDLE  fd,
+    int *buf);
+extern NCURSES_EXPORT(int) _nc_mingw_testmouse(
+    SCREEN * sp,
+    HANDLE fd,
+    int delay);
+#else
+#endif
+extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;
+#endif
+
+#if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
+#define NC_ISATTY(fd) _nc_mingw_isatty(fd)
+#else
+#define NC_ISATTY(fd) isatty(fd)
+#endif
+
+#ifdef USE_TERM_DRIVER
+#  define IsTermInfo(sp)       ((TCBOf(sp) != 0) && ((TCBOf(sp)->drv->isTerminfo)))
+#  define HasTInfoTerminal(sp) ((0 != TerminalOf(sp)) && IsTermInfo(sp))
+#  if defined(USE_WIN32CON_DRIVER)
+#    define IsTermInfoOnConsole(sp) (IsTermInfo(sp)&&_nc_mingw_isconsole(TerminalOf(sp)->Filedes))
+#else
+#    define IsTermInfoOnConsole(sp) FALSE
+#  endif
+#else
+#  define IsTermInfo(sp)       TRUE
+#  define HasTInfoTerminal(sp) (0 != TerminalOf(sp))
+#  define IsTermInfoOnConsole(sp) FALSE
+#endif
+
+#define IsValidTIScreen(sp)  (HasTInfoTerminal(sp))
+
+/*
+ * Exported entrypoints beyond the published API
+ */
+#if NCURSES_SP_FUNCS
+extern NCURSES_EXPORT(WINDOW *) _nc_curscr_of(SCREEN*);
+extern NCURSES_EXPORT(WINDOW *) _nc_newscr_of(SCREEN*);
+extern NCURSES_EXPORT(WINDOW *) _nc_stdscr_of(SCREEN*);
+extern NCURSES_EXPORT(int)      _nc_outc_wrapper(SCREEN*,int);
+
+#if USE_REENTRANT
+extern NCURSES_EXPORT(int)       NCURSES_SP_NAME(_nc_TABSIZE)(SCREEN*);
+extern NCURSES_EXPORT(char *)    NCURSES_SP_NAME(longname)(SCREEN*);
+#endif
+
+#if NCURSES_EXT_FUNCS
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_set_tabsize)(SCREEN*, int);
+#endif
+
+/*
+ * We put the safe versions of various calls here as they are not published
+ * part of the API up to now
+ */
+extern NCURSES_EXPORT(TERMINAL*) NCURSES_SP_NAME(_nc_get_cur_term) (SCREEN *sp);
+extern NCURSES_EXPORT(WINDOW *) NCURSES_SP_NAME(_nc_makenew) (SCREEN*, int, int, int, int, int);
+extern NCURSES_EXPORT(bool)     NCURSES_SP_NAME(_nc_reset_colors)(SCREEN*);
+extern NCURSES_EXPORT(char *)   NCURSES_SP_NAME(_nc_printf_string)(SCREEN*, const char *, va_list);
+extern NCURSES_EXPORT(chtype)   NCURSES_SP_NAME(_nc_acs_char)(SCREEN*,int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_curs_set)(SCREEN*,int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_get_tty_mode)(SCREEN*,TTY*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_mcprint)(SCREEN*,char*, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_msec_cost)(SCREEN*, const char *, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_mvcur)(SCREEN*, int, int, int, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_outch)(SCREEN*, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_putchar)(SCREEN*, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_putp)(SCREEN*, const char *, const char*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_putp_flush)(SCREEN*, const char *, const char *);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_resetty)(SCREEN*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_resize_term)(SCREEN*,int,int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_ripoffline)(SCREEN*, int, int (*)(WINDOW *,int));
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_savetty)(SCREEN*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_scr_init)(SCREEN*,const char*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_scr_restore)(SCREEN*, const char*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_scrolln)(SCREEN*, int, int, int, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_set_tty_mode)(SCREEN*, TTY*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_setupscreen)(SCREEN**, int, int, FILE *, int, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_tgetent)(SCREEN*,char*,const char *);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_tigetnum)(SCREEN*,NCURSES_CONST char*);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_vid_attr)(SCREEN *, attr_t, NCURSES_COLOR_T, void *);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_vidputs)(SCREEN*,chtype,int(*) (SCREEN*, int));
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_do_color)(SCREEN*, int, int, int, NCURSES_SP_OUTC);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_do_xmc_glitch)(SCREEN*, attr_t);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_flush)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_free_and_exit)(SCREEN*, int) GCC_NORETURN;
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_freeall)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_hash_map)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_init_acs)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_make_oldhash)(SCREEN*, int i);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_mvcur_init)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_mvcur_resume)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_mvcur_wrap)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_screen_init)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_screen_resume)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_screen_wrap)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_scroll_oldhash)(SCREEN*, int n, int top, int bot);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_scroll_optimize)(SCREEN*);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_set_buffer)(SCREEN*, FILE *, int);
+
+extern NCURSES_EXPORT(void)     _nc_cookie_init(SCREEN *sp);
+
+#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_linedump)(SCREEN*);
+#endif
+
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(wchar_t *) NCURSES_SP_NAME(_nc_wunctrl)(SCREEN*, cchar_t *);
+#endif
+
+#endif /* NCURSES_SP_FUNCS */
+
+#if NCURSES_SP_FUNCS
+
+#define safe_keyname NCURSES_SP_NAME(keyname)
+#define safe_unctrl  NCURSES_SP_NAME(unctrl)
+#define safe_ungetch NCURSES_SP_NAME(ungetch)
+
+#else
+
+#define safe_keyname _nc_keyname
+#define safe_unctrl  _nc_unctrl
+#define safe_ungetch _nc_ungetch
+
+extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *, int);
+extern NCURSES_EXPORT(int) _nc_ungetch (SCREEN *, int);
+extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
+
+#endif
+
+#ifdef EXP_XTERM_1005
+NCURSES_EXPORT(int) _nc_conv_to_utf8(unsigned char *, unsigned, unsigned);
+NCURSES_EXPORT(int) _nc_conv_to_utf32(unsigned *, const char *, unsigned);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
 
+/* *INDENT-ON* */
+
 #endif /* CURSES_PRIV_H */
diff --git a/ncurses/expanded.c b/ncurses/expanded.c
deleted file mode 100644
index d96ddef..0000000
--- a/ncurses/expanded.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* generated by MKexpanded.sh */
-#include <curses.priv.h>
-#include <term.h>
-#if NCURSES_EXPANDED
- void _nc_toggle_attr_on (attr_t *S, attr_t at)
-{
- { if (PAIR_NUMBER(at) > 0) { (*S) = ((*S) & ALL_BUT_COLOR) | (at); } else { (*S) |= (at); } ;};
-}
- void _nc_toggle_attr_off (attr_t *S, attr_t at)
-{
- { if (PAIR_NUMBER(at) > 0) { (*S) &= ~(at|((((1UL) << 8) - 1UL) << ((0) + 8))); } else { (*S) &= ~(at); } ;};
-}
- int _nc_DelCharCost (int count)
-{
- return ((cur_term->type. Strings[105] != 0) ? SP->_dch_cost : ((cur_term->type. Strings[21] != 0) ? (SP->_dch1_cost * count) : 1000000));
-}
- int _nc_InsCharCost (int count)
-{
- return ((cur_term->type. Strings[108] != 0) ? SP->_ich_cost : ((cur_term->type. Strings[31] && cur_term->type. Strings[42]) ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) : ((cur_term->type. Strings[52] != 0) ? ((SP->_ich1_cost + SP->_ip_cost) * count) : 1000000)));
-}
- void _nc_UpdateAttrs (chtype c)
-{
- if (!((((*((SP)->_current_attr))) & (chtype)((~(1UL - 1UL)) << ((0) + 8))) == ((c) & (chtype)((~(1UL - 1UL)) << ((0) + 8))))) vidattr(((c) & (chtype)((~(1UL - 1UL)) << ((0) + 8))));;
-}
-#else /* ! NCURSES_EXPANDED */
-NCURSES_EXPORT(void) _nc_expanded (void) { }
-#endif /* NCURSES_EXPANDED */
diff --git a/ncurses/fallback.c b/ncurses/fallback.c
deleted file mode 100644
index a94e4ae..0000000
--- a/ncurses/fallback.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * DO NOT EDIT THIS FILE BY HAND!  It is generated by MKfallback.sh.
- */
-
-#include <curses.priv.h>
-#include <term.h>
-
-NCURSES_EXPORT(const TERMTYPE *) _nc_fallback (const char *name GCC_UNUSED)
-{
-	/* the fallback list is empty */
-	return((TERMTYPE *)0);
-}
diff --git a/ncurses/fifo_defs.h b/ncurses/fifo_defs.h
index fa9ae22..c0c795a 100644
--- a/ncurses/fifo_defs.h
+++ b/ncurses/fifo_defs.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2002,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -34,7 +34,7 @@
 /*
  * Common macros for lib_getch.c, lib_ungetch.c
  *
- * $Id: fifo_defs.h,v 1.6 2008/06/28 15:52:32 tom Exp $
+ * $Id: fifo_defs.h,v 1.7 2012/08/04 15:59:17 tom Exp $
  */
 
 #ifndef FIFO_DEFS_H
@@ -45,14 +45,42 @@
 /* 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 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))
+#define cooked_key_in_fifo()	((head >= 0) && (peek != head))
+#define raw_key_in_fifo()	((head >= 0) && (peek != tail))
 
 #undef HIDE_EINTR
 
diff --git a/ncurses/init_keytry.h b/ncurses/init_keytry.h
deleted file mode 100644
index c89150d..0000000
--- a/ncurses/init_keytry.h
+++ /dev/null
@@ -1,162 +0,0 @@
-#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[] = {
-	{  139, KEY_A1           },	/* key_a1 */
-	{  140, KEY_A3           },	/* key_a3 */
-	{  141, KEY_B2           },	/* key_b2 */
-	{   55, KEY_BACKSPACE    },	/* key_backspace */
-	{  158, KEY_BEG          },	/* key_beg */
-	{  148, KEY_BTAB         },	/* key_btab */
-	{  142, KEY_C1           },	/* key_c1 */
-	{  143, KEY_C3           },	/* key_c3 */
-	{  159, KEY_CANCEL       },	/* key_cancel */
-	{   56, KEY_CATAB        },	/* key_catab */
-	{   57, KEY_CLEAR        },	/* key_clear */
-	{  160, KEY_CLOSE        },	/* key_close */
-	{  161, KEY_COMMAND      },	/* key_command */
-	{  162, KEY_COPY         },	/* key_copy */
-	{  163, KEY_CREATE       },	/* key_create */
-	{   58, KEY_CTAB         },	/* key_ctab */
-	{   59, KEY_DC           },	/* key_dc */
-	{   60, KEY_DL           },	/* key_dl */
-	{   61, KEY_DOWN         },	/* key_down */
-	{   62, KEY_EIC          },	/* key_eic */
-	{  164, KEY_END          },	/* key_end */
-	{  165, KEY_ENTER        },	/* key_enter */
-	{   63, KEY_EOL          },	/* key_eol */
-	{   64, KEY_EOS          },	/* key_eos */
-	{  166, KEY_EXIT         },	/* key_exit */
-	{   65, KEY_F(0)         },	/* key_f0 */
-	{   67, KEY_F(10)        },	/* key_f10 */
-	{  216, KEY_F(11)        },	/* key_f11 */
-	{  217, KEY_F(12)        },	/* key_f12 */
-	{  218, KEY_F(13)        },	/* key_f13 */
-	{  219, KEY_F(14)        },	/* key_f14 */
-	{  220, KEY_F(15)        },	/* key_f15 */
-	{  221, KEY_F(16)        },	/* key_f16 */
-	{  222, KEY_F(17)        },	/* key_f17 */
-	{  223, KEY_F(18)        },	/* key_f18 */
-	{  224, KEY_F(19)        },	/* key_f19 */
-	{   66, KEY_F(1)         },	/* key_f1 */
-	{  225, KEY_F(20)        },	/* key_f20 */
-	{  226, KEY_F(21)        },	/* key_f21 */
-	{  227, KEY_F(22)        },	/* key_f22 */
-	{  228, KEY_F(23)        },	/* key_f23 */
-	{  229, KEY_F(24)        },	/* key_f24 */
-	{  230, KEY_F(25)        },	/* key_f25 */
-	{  231, KEY_F(26)        },	/* key_f26 */
-	{  232, KEY_F(27)        },	/* key_f27 */
-	{  233, KEY_F(28)        },	/* key_f28 */
-	{  234, KEY_F(29)        },	/* key_f29 */
-	{   68, KEY_F(2)         },	/* key_f2 */
-	{  235, KEY_F(30)        },	/* key_f30 */
-	{  236, KEY_F(31)        },	/* key_f31 */
-	{  237, KEY_F(32)        },	/* key_f32 */
-	{  238, KEY_F(33)        },	/* key_f33 */
-	{  239, KEY_F(34)        },	/* key_f34 */
-	{  240, KEY_F(35)        },	/* key_f35 */
-	{  241, KEY_F(36)        },	/* key_f36 */
-	{  242, KEY_F(37)        },	/* key_f37 */
-	{  243, KEY_F(38)        },	/* key_f38 */
-	{  244, KEY_F(39)        },	/* key_f39 */
-	{   69, KEY_F(3)         },	/* key_f3 */
-	{  245, KEY_F(40)        },	/* key_f40 */
-	{  246, KEY_F(41)        },	/* key_f41 */
-	{  247, KEY_F(42)        },	/* key_f42 */
-	{  248, KEY_F(43)        },	/* key_f43 */
-	{  249, KEY_F(44)        },	/* key_f44 */
-	{  250, KEY_F(45)        },	/* key_f45 */
-	{  251, KEY_F(46)        },	/* key_f46 */
-	{  252, KEY_F(47)        },	/* key_f47 */
-	{  253, KEY_F(48)        },	/* key_f48 */
-	{  254, KEY_F(49)        },	/* key_f49 */
-	{   70, KEY_F(4)         },	/* key_f4 */
-	{  255, KEY_F(50)        },	/* key_f50 */
-	{  256, KEY_F(51)        },	/* key_f51 */
-	{  257, KEY_F(52)        },	/* key_f52 */
-	{  258, KEY_F(53)        },	/* key_f53 */
-	{  259, KEY_F(54)        },	/* key_f54 */
-	{  260, KEY_F(55)        },	/* key_f55 */
-	{  261, KEY_F(56)        },	/* key_f56 */
-	{  262, KEY_F(57)        },	/* key_f57 */
-	{  263, KEY_F(58)        },	/* key_f58 */
-	{  264, KEY_F(59)        },	/* key_f59 */
-	{   71, KEY_F(5)         },	/* key_f5 */
-	{  265, KEY_F(60)        },	/* key_f60 */
-	{  266, KEY_F(61)        },	/* key_f61 */
-	{  267, KEY_F(62)        },	/* key_f62 */
-	{  268, KEY_F(63)        },	/* key_f63 */
-	{   72, KEY_F(6)         },	/* key_f6 */
-	{   73, KEY_F(7)         },	/* key_f7 */
-	{   74, KEY_F(8)         },	/* key_f8 */
-	{   75, KEY_F(9)         },	/* key_f9 */
-	{  167, KEY_FIND         },	/* key_find */
-	{  168, KEY_HELP         },	/* key_help */
-	{   76, KEY_HOME         },	/* key_home */
-	{   77, KEY_IC           },	/* key_ic */
-	{   78, KEY_IL           },	/* key_il */
-	{   79, KEY_LEFT         },	/* key_left */
-	{   80, KEY_LL           },	/* key_ll */
-	{  169, KEY_MARK         },	/* key_mark */
-	{  170, KEY_MESSAGE      },	/* key_message */
-	{  355, KEY_MOUSE        },	/* key_mouse */
-	{  171, KEY_MOVE         },	/* key_move */
-	{  172, KEY_NEXT         },	/* key_next */
-	{   81, KEY_NPAGE        },	/* key_npage */
-	{  173, KEY_OPEN         },	/* key_open */
-	{  174, KEY_OPTIONS      },	/* key_options */
-	{   82, KEY_PPAGE        },	/* key_ppage */
-	{  175, KEY_PREVIOUS     },	/* key_previous */
-	{  176, KEY_PRINT        },	/* key_print */
-	{  177, KEY_REDO         },	/* key_redo */
-	{  178, KEY_REFERENCE    },	/* key_reference */
-	{  179, KEY_REFRESH      },	/* key_refresh */
-	{  180, KEY_REPLACE      },	/* key_replace */
-	{  181, KEY_RESTART      },	/* key_restart */
-	{  182, KEY_RESUME       },	/* key_resume */
-	{   83, KEY_RIGHT        },	/* key_right */
-	{  183, KEY_SAVE         },	/* key_save */
-	{  186, KEY_SBEG         },	/* key_sbeg */
-	{  187, KEY_SCANCEL      },	/* key_scancel */
-	{  188, KEY_SCOMMAND     },	/* key_scommand */
-	{  189, KEY_SCOPY        },	/* key_scopy */
-	{  190, KEY_SCREATE      },	/* key_screate */
-	{  191, KEY_SDC          },	/* key_sdc */
-	{  192, KEY_SDL          },	/* key_sdl */
-	{  193, KEY_SELECT       },	/* key_select */
-	{  194, KEY_SEND         },	/* key_send */
-	{  195, KEY_SEOL         },	/* key_seol */
-	{  196, KEY_SEXIT        },	/* key_sexit */
-	{  197, KEY_SFIND        },	/* key_sfind */
-	{   84, KEY_SF           },	/* key_sf */
-	{  198, KEY_SHELP        },	/* key_shelp */
-	{  199, KEY_SHOME        },	/* key_shome */
-	{  200, KEY_SIC          },	/* key_sic */
-	{  201, KEY_SLEFT        },	/* key_sleft */
-	{  202, KEY_SMESSAGE     },	/* key_smessage */
-	{  203, KEY_SMOVE        },	/* key_smove */
-	{  204, KEY_SNEXT        },	/* key_snext */
-	{  205, KEY_SOPTIONS     },	/* key_soptions */
-	{  206, KEY_SPREVIOUS    },	/* key_sprevious */
-	{  207, KEY_SPRINT       },	/* key_sprint */
-	{  208, KEY_SREDO        },	/* key_sredo */
-	{  209, KEY_SREPLACE     },	/* key_sreplace */
-	{  210, KEY_SRIGHT       },	/* key_sright */
-	{   85, KEY_SR           },	/* key_sr */
-	{  211, KEY_SRSUME       },	/* key_srsume */
-	{  212, KEY_SSAVE        },	/* key_ssave */
-	{  213, KEY_SSUSPEND     },	/* key_ssuspend */
-	{   86, KEY_STAB         },	/* key_stab */
-	{  214, KEY_SUNDO        },	/* key_sundo */
-	{  184, KEY_SUSPEND      },	/* key_suspend */
-	{  185, KEY_UNDO         },	/* key_undo */
-	{   87, KEY_UP           },	/* key_up */
-	{ 0, 0} };
-
-#endif /* NCU_KEYS_H */
diff --git a/ncurses/keys.list b/ncurses/keys.list
deleted file mode 100644
index 1bca98f..0000000
--- a/ncurses/keys.list
+++ /dev/null
@@ -1,155 +0,0 @@
-KEY_A1	key_a1
-KEY_A3	key_a3
-KEY_B2	key_b2
-KEY_BACKSPACE	key_backspace
-KEY_BEG	key_beg
-KEY_BREAK
-KEY_BTAB	key_btab
-KEY_C1	key_c1
-KEY_C3	key_c3
-KEY_CANCEL	key_cancel
-KEY_CATAB	key_catab
-KEY_CLEAR	key_clear
-KEY_CLOSE	key_close
-KEY_COMMAND	key_command
-KEY_COPY	key_copy
-KEY_CREATE	key_create
-KEY_CTAB	key_ctab
-KEY_DC	key_dc
-KEY_DL	key_dl
-KEY_DOWN	key_down
-KEY_EIC	key_eic
-KEY_END	key_end
-KEY_ENTER	key_enter
-KEY_EOL	key_eol
-KEY_EOS	key_eos
-KEY_EXIT	key_exit
-KEY_F(0)	key_f0
-KEY_F(10)	key_f10
-KEY_F(11)	key_f11
-KEY_F(12)	key_f12
-KEY_F(13)	key_f13
-KEY_F(14)	key_f14
-KEY_F(15)	key_f15
-KEY_F(16)	key_f16
-KEY_F(17)	key_f17
-KEY_F(18)	key_f18
-KEY_F(19)	key_f19
-KEY_F(1)	key_f1
-KEY_F(20)	key_f20
-KEY_F(21)	key_f21
-KEY_F(22)	key_f22
-KEY_F(23)	key_f23
-KEY_F(24)	key_f24
-KEY_F(25)	key_f25
-KEY_F(26)	key_f26
-KEY_F(27)	key_f27
-KEY_F(28)	key_f28
-KEY_F(29)	key_f29
-KEY_F(2)	key_f2
-KEY_F(30)	key_f30
-KEY_F(31)	key_f31
-KEY_F(32)	key_f32
-KEY_F(33)	key_f33
-KEY_F(34)	key_f34
-KEY_F(35)	key_f35
-KEY_F(36)	key_f36
-KEY_F(37)	key_f37
-KEY_F(38)	key_f38
-KEY_F(39)	key_f39
-KEY_F(3)	key_f3
-KEY_F(40)	key_f40
-KEY_F(41)	key_f41
-KEY_F(42)	key_f42
-KEY_F(43)	key_f43
-KEY_F(44)	key_f44
-KEY_F(45)	key_f45
-KEY_F(46)	key_f46
-KEY_F(47)	key_f47
-KEY_F(48)	key_f48
-KEY_F(49)	key_f49
-KEY_F(4)	key_f4
-KEY_F(50)	key_f50
-KEY_F(51)	key_f51
-KEY_F(52)	key_f52
-KEY_F(53)	key_f53
-KEY_F(54)	key_f54
-KEY_F(55)	key_f55
-KEY_F(56)	key_f56
-KEY_F(57)	key_f57
-KEY_F(58)	key_f58
-KEY_F(59)	key_f59
-KEY_F(5)	key_f5
-KEY_F(60)	key_f60
-KEY_F(61)	key_f61
-KEY_F(62)	key_f62
-KEY_F(63)	key_f63
-KEY_F(6)	key_f6
-KEY_F(7)	key_f7
-KEY_F(8)	key_f8
-KEY_F(9)	key_f9
-KEY_FIND	key_find
-KEY_HELP	key_help
-KEY_HOME	key_home
-KEY_IC	key_ic
-KEY_IL	key_il
-KEY_LEFT	key_left
-KEY_LL	key_ll
-KEY_MARK	key_mark
-KEY_MESSAGE	key_message
-KEY_MOUSE	key_mouse
-KEY_MOVE	key_move
-KEY_NEXT	key_next
-KEY_NPAGE	key_npage
-KEY_OPEN	key_open
-KEY_OPTIONS	key_options
-KEY_PPAGE	key_ppage
-KEY_PREVIOUS	key_previous
-KEY_PRINT	key_print
-KEY_REDO	key_redo
-KEY_REFERENCE	key_reference
-KEY_REFRESH	key_refresh
-KEY_REPLACE	key_replace
-KEY_RESET
-KEY_RESIZE
-KEY_RESTART	key_restart
-KEY_RESUME	key_resume
-KEY_RIGHT	key_right
-KEY_SAVE	key_save
-KEY_SBEG	key_sbeg
-KEY_SCANCEL	key_scancel
-KEY_SCOMMAND	key_scommand
-KEY_SCOPY	key_scopy
-KEY_SCREATE	key_screate
-KEY_SDC	key_sdc
-KEY_SDL	key_sdl
-KEY_SELECT	key_select
-KEY_SEND	key_send
-KEY_SEOL	key_seol
-KEY_SEXIT	key_sexit
-KEY_SFIND	key_sfind
-KEY_SF	key_sf
-KEY_SHELP	key_shelp
-KEY_SHOME	key_shome
-KEY_SIC	key_sic
-KEY_SLEFT	key_sleft
-KEY_SMESSAGE	key_smessage
-KEY_SMOVE	key_smove
-KEY_SNEXT	key_snext
-KEY_SOPTIONS	key_soptions
-KEY_SPREVIOUS	key_sprevious
-KEY_SPRINT	key_sprint
-KEY_SREDO	key_sredo
-KEY_SREPLACE	key_sreplace
-KEY_SRESET
-KEY_SRIGHT	key_sright
-KEY_SR	key_sr
-KEY_SRSUME	key_srsume
-KEY_SSAVE	key_ssave
-KEY_SSUSPEND	key_ssuspend
-KEY_STAB	key_stab
-KEY_SUNDO	key_sundo
-KEY_SUSPEND	key_suspend
-KEY_UNDO	key_undo
-KEY_UP	key_up
-# These definitions were generated by ./tinfo/MKkeys_list.sh ../include/Caps
diff --git a/ncurses/lib_gen.c b/ncurses/lib_gen.c
deleted file mode 100644
index e36b89f..0000000
--- a/ncurses/lib_gen.c
+++ /dev/null
@@ -1,973 +0,0 @@
-/*
- * DO NOT EDIT THIS FILE BY HAND!
- * It is generated by ./base/MKlib_gen.sh generated.
- *
- * This is a file of trivial functions generated from macro
- * definitions in curses.h to satisfy the XSI Curses requirement
- * that every macro also exist as a callable function.
- *
- * It will never be linked unless you call one of the entry
- * points with its normal macro definition disabled. In that
- * case, if you have no shared libraries, it will indirectly
- * pull most of the rest of the library into your link image.
- */
-#define NCURSES_ATTR_T int
-#include <curses.priv.h>
-
-
-#undef addch
-NCURSES_EXPORT(int) addch (const chtype z)
-{
-	T((T_CALLED("addch(%s)"), _tracechtype2(0,z))); returnCode(waddch(stdscr,z));
-}
-
-
-#undef addchnstr
-NCURSES_EXPORT(int) addchnstr (const chtype * a1, int z)
-{
-	T((T_CALLED("addchnstr(%p,%d)"), a1, z)); returnCode(waddchnstr(stdscr,a1,z));
-}
-
-
-#undef addchstr
-NCURSES_EXPORT(int) addchstr (const chtype * z)
-{
-	T((T_CALLED("addchstr(%p)"), z)); returnCode(waddchnstr(stdscr,z,-1));
-}
-
-
-#undef addnstr
-NCURSES_EXPORT(int) addnstr (const char * a1, int z)
-{
-	T((T_CALLED("addnstr(%s,%d)"), _nc_visbuf2(0,a1), z)); returnCode(waddnstr(stdscr,a1,z));
-}
-
-
-#undef addstr
-NCURSES_EXPORT(int) addstr (const char * z)
-{
-	T((T_CALLED("addstr(%s)"), _nc_visbuf2(0,z))); returnCode(waddnstr(stdscr,z,-1));
-}
-
-
-#undef attroff
-NCURSES_EXPORT(int) attroff (int z)
-{
-	T((T_CALLED("attroff(%s)"), _traceattr2(0,z))); returnCode(wattr_off(stdscr, (attr_t)(z), ((void *)0)));
-}
-
-
-#undef attron
-NCURSES_EXPORT(int) attron (int z)
-{
-	T((T_CALLED("attron(%s)"), _traceattr2(0,z))); returnCode(wattr_on(stdscr, (attr_t)(z), ((void *)0)));
-}
-
-
-#undef attrset
-NCURSES_EXPORT(int) attrset (int z)
-{
-	T((T_CALLED("attrset(%s)"), _traceattr2(0,z))); returnAttr(((stdscr)->_attrs = (z)));
-}
-
-
-#undef attr_get
-NCURSES_EXPORT(int) attr_get (attr_t * a1, short * a2, void * z)
-{
-	T((T_CALLED("attr_get(%p,%p,%p)"), a1, a2, z)); returnCode(((void)((a1) != (void *)0 && (*(a1) = (stdscr)->_attrs)), (void)((a2) != (void *)0 && (*(a2) = ((int)(((((stdscr)->_attrs) & ((((1UL) << 8) - 1UL) << ((0) + 8))) >> 8))))), (0)));
-}
-
-
-#undef attr_off
-NCURSES_EXPORT(int) attr_off (attr_t a1, void * z)
-{
-	T((T_CALLED("attr_off(%s,%p)"), _traceattr2(0,a1), z)); returnCode(wattr_off(stdscr,a1,z));
-}
-
-
-#undef attr_on
-NCURSES_EXPORT(int) attr_on (attr_t a1, void * z)
-{
-	T((T_CALLED("attr_on(%s,%p)"), _traceattr2(0,a1), z)); returnCode(wattr_on(stdscr,a1,z));
-}
-
-
-#undef attr_set
-NCURSES_EXPORT(int) attr_set (attr_t a1, short a2, void * z)
-{
-	T((T_CALLED("attr_set(%s,%d,%p)"), _traceattr2(0,a1), a2, z)); returnCode(((stdscr)->_attrs = (((a1) & ~((((1UL) << 8) - 1UL) << ((0) + 8))) | ((a2) << ((0) + 8))), (0)));
-}
-
-
-#undef bkgd
-NCURSES_EXPORT(int) bkgd (chtype z)
-{
-	T((T_CALLED("bkgd(%s)"), _tracechtype2(0,z))); returnCode(wbkgd(stdscr,z));
-}
-
-
-#undef bkgdset
-NCURSES_EXPORT(void) bkgdset (chtype z)
-{
-	T((T_CALLED("bkgdset(%s)"), _tracechtype2(0,z))); wbkgdset(stdscr,z);
-	returnVoid;
-}
-
-
-#undef border
-NCURSES_EXPORT(int) border (chtype a1, chtype a2, chtype a3, chtype a4, chtype a5, chtype a6, chtype a7, chtype z)
-{
-	T((T_CALLED("border(%s,%s,%s,%s,%s,%s,%s,%s)"), _tracechtype2(0,a1), _tracechtype2(1,a2), _tracechtype2(2,a3), _tracechtype2(3,a4), _tracechtype2(4,a5), _tracechtype2(5,a6), _tracechtype2(6,a7), _tracechtype2(7,z))); returnCode(wborder(stdscr, a1, a2, a3, a4, a5, a6, a7, z));
-}
-
-
-#undef box
-NCURSES_EXPORT(int) box (WINDOW * a1, chtype a2, chtype z)
-{
-	T((T_CALLED("box(%p,%s,%s)"), a1, _tracechtype2(1,a2), _tracechtype2(2,z))); returnCode(wborder(a1, a2, a2, z, z, 0, 0, 0, 0));
-}
-
-
-#undef chgat
-NCURSES_EXPORT(int) chgat (int a1, attr_t a2, short a3, const void * z)
-{
-	T((T_CALLED("chgat(%d,%s,%d,%p)"), a1, _traceattr2(1,a2), a3, z)); returnCode(wchgat(stdscr,a1,a2,a3,z));
-}
-
-
-#undef clear
-NCURSES_EXPORT(int) clear (void)
-{
-	T((T_CALLED("clear()"))); returnCode(wclear(stdscr));
-}
-
-
-#undef clrtobot
-NCURSES_EXPORT(int) clrtobot (void)
-{
-	T((T_CALLED("clrtobot()"))); returnCode(wclrtobot(stdscr));
-}
-
-
-#undef clrtoeol
-NCURSES_EXPORT(int) clrtoeol (void)
-{
-	T((T_CALLED("clrtoeol()"))); returnCode(wclrtoeol(stdscr));
-}
-
-
-#undef color_set
-NCURSES_EXPORT(int) color_set (short a1, void * z)
-{
-	T((T_CALLED("color_set(%d,%p)"), a1, z)); returnCode(wcolor_set(stdscr,a1,z));
-}
-
-
-#undef COLOR_PAIR
-NCURSES_EXPORT(int) COLOR_PAIR (int z)
-{
-	T((T_CALLED("COLOR_PAIR(%d)"), z)); returnCode(((z) << ((0) + 8)));
-}
-
-
-#undef delch
-NCURSES_EXPORT(int) delch (void)
-{
-	T((T_CALLED("delch()"))); returnCode(wdelch(stdscr));
-}
-
-
-#undef deleteln
-NCURSES_EXPORT(int) deleteln (void)
-{
-	T((T_CALLED("deleteln()"))); returnCode(winsdelln(stdscr,-1));
-}
-
-
-#undef echochar
-NCURSES_EXPORT(int) echochar (const chtype z)
-{
-	T((T_CALLED("echochar(%s)"), _tracechtype2(0,z))); returnCode(wechochar(stdscr,z));
-}
-
-
-#undef erase
-NCURSES_EXPORT(int) erase (void)
-{
-	T((T_CALLED("erase()"))); returnCode(werase(stdscr));
-}
-
-
-#undef getbkgd
-NCURSES_EXPORT(chtype) getbkgd (WINDOW * z)
-{
-	T((T_CALLED("getbkgd(%p)"), z)); returnChar(((z)->_bkgd));
-}
-
-
-#undef getch
-NCURSES_EXPORT(int) getch (void)
-{
-	T((T_CALLED("getch()"))); returnCode(wgetch(stdscr));
-}
-
-
-#undef getnstr
-NCURSES_EXPORT(int) getnstr (char * a1, int z)
-{
-	T((T_CALLED("getnstr(%s,%d)"), _nc_visbuf2(0,a1), z)); returnCode(wgetnstr(stdscr, a1, z));
-}
-
-
-#undef getstr
-NCURSES_EXPORT(int) getstr (char * z)
-{
-	T((T_CALLED("getstr(%s)"), _nc_visbuf2(0,z))); returnCode(wgetnstr(stdscr, z, -1));
-}
-
-
-#undef hline
-NCURSES_EXPORT(int) hline (chtype a1, int z)
-{
-	T((T_CALLED("hline(%s,%d)"), _tracechtype2(0,a1), z)); returnCode(whline(stdscr, a1, z));
-}
-
-
-#undef inch
-NCURSES_EXPORT(chtype) inch (void)
-{
-	T((T_CALLED("inch()"))); returnChar(winch(stdscr));
-}
-
-
-#undef inchnstr
-NCURSES_EXPORT(int) inchnstr (chtype * a1, int z)
-{
-	T((T_CALLED("inchnstr(%p,%d)"), a1, z)); returnCode(winchnstr(stdscr,a1,z));
-}
-
-
-#undef inchstr
-NCURSES_EXPORT(int) inchstr (chtype * z)
-{
-	T((T_CALLED("inchstr(%p)"), z)); returnCode(winchnstr(stdscr, z, -1));
-}
-
-
-#undef innstr
-NCURSES_EXPORT(int) innstr (char * a1, int z)
-{
-	return winnstr(stdscr,a1,z) ;
-}
-
-
-#undef insch
-NCURSES_EXPORT(int) insch (chtype z)
-{
-	T((T_CALLED("insch(%s)"), _tracechtype2(0,z))); returnCode(winsch(stdscr,z));
-}
-
-
-#undef insdelln
-NCURSES_EXPORT(int) insdelln (int z)
-{
-	T((T_CALLED("insdelln(%d)"), z)); returnCode(winsdelln(stdscr,z));
-}
-
-
-#undef insertln
-NCURSES_EXPORT(int) insertln (void)
-{
-	T((T_CALLED("insertln()"))); returnCode(winsdelln(stdscr,1));
-}
-
-
-#undef insnstr
-NCURSES_EXPORT(int) insnstr (const char * a1, int z)
-{
-	T((T_CALLED("insnstr(%s,%d)"), _nc_visbuf2(0,a1), z)); returnCode(winsnstr(stdscr,a1,z));
-}
-
-
-#undef insstr
-NCURSES_EXPORT(int) insstr (const char * z)
-{
-	T((T_CALLED("insstr(%s)"), _nc_visbuf2(0,z))); returnCode(winsnstr(stdscr, z, -1));
-}
-
-
-#undef instr
-NCURSES_EXPORT(int) instr (char * z)
-{
-	T((T_CALLED("instr(%s)"), _nc_visbuf2(0,z))); returnCode(winnstr(stdscr, z, -1));
-}
-
-
-#undef move
-NCURSES_EXPORT(int) move (int a1, int z)
-{
-	T((T_CALLED("move(%d,%d)"), a1, z)); returnCode(wmove(stdscr,a1,z));
-}
-
-
-#undef mvaddch
-NCURSES_EXPORT(int) mvaddch (int a1, int a2, const chtype z)
-{
-	T((T_CALLED("mvaddch(%d,%d,%s)"), a1, a2, _tracechtype2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddch(stdscr,z)));
-}
-
-
-#undef mvaddchnstr
-NCURSES_EXPORT(int) mvaddchnstr (int a1, int a2, const chtype * a3, int z)
-{
-	T((T_CALLED("mvaddchnstr(%d,%d,%p,%d)"), a1, a2, a3, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddchnstr(stdscr,a3,z)));
-}
-
-
-#undef mvaddchstr
-NCURSES_EXPORT(int) mvaddchstr (int a1, int a2, const chtype * z)
-{
-	T((T_CALLED("mvaddchstr(%d,%d,%p)"), a1, a2, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddchnstr(stdscr,z,-1)));
-}
-
-
-#undef mvaddnstr
-NCURSES_EXPORT(int) mvaddnstr (int a1, int a2, const char * a3, int z)
-{
-	T((T_CALLED("mvaddnstr(%d,%d,%s,%d)"), a1, a2, _nc_visbuf2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddnstr(stdscr,a3,z)));
-}
-
-
-#undef mvaddstr
-NCURSES_EXPORT(int) mvaddstr (int a1, int a2, const char * z)
-{
-	T((T_CALLED("mvaddstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddnstr(stdscr,z,-1)));
-}
-
-
-#undef mvchgat
-NCURSES_EXPORT(int) mvchgat (int a1, int a2, int a3, attr_t a4, short a5, const void * z)
-{
-	T((T_CALLED("mvchgat(%d,%d,%d,%s,%d,%p)"), a1, a2, a3, _traceattr2(3,a4), a5, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wchgat(stdscr,a3,a4,a5,z)));
-}
-
-
-#undef mvdelch
-NCURSES_EXPORT(int) mvdelch (int a1, int z)
-{
-	T((T_CALLED("mvdelch(%d,%d)"), a1, z)); returnCode((wmove(stdscr,a1,z) == (-1) ? (-1) : wdelch(stdscr)));
-}
-
-
-#undef mvgetch
-NCURSES_EXPORT(int) mvgetch (int a1, int z)
-{
-	T((T_CALLED("mvgetch(%d,%d)"), a1, z)); returnCode((wmove(stdscr,a1,z) == (-1) ? (-1) : wgetch(stdscr)));
-}
-
-
-#undef mvgetnstr
-NCURSES_EXPORT(int) mvgetnstr (int a1, int a2, char * a3, int z)
-{
-	T((T_CALLED("mvgetnstr(%d,%d,%s,%d)"), a1, a2, _nc_visbuf2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wgetnstr(stdscr,a3,z)));
-}
-
-
-#undef mvgetstr
-NCURSES_EXPORT(int) mvgetstr (int a1, int a2, char * z)
-{
-	T((T_CALLED("mvgetstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wgetnstr(stdscr, z, -1)));
-}
-
-
-#undef mvhline
-NCURSES_EXPORT(int) mvhline (int a1, int a2, chtype a3, int z)
-{
-	T((T_CALLED("mvhline(%d,%d,%s,%d)"), a1, a2, _tracechtype2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : whline(stdscr,a3,z)));
-}
-
-
-#undef mvinch
-NCURSES_EXPORT(chtype) mvinch (int a1, int z)
-{
-	T((T_CALLED("mvinch(%d,%d)"), a1, z)); returnChar((wmove(stdscr,a1,z) == (-1) ? (chtype)((-1)) : winch(stdscr)));
-}
-
-
-#undef mvinchnstr
-NCURSES_EXPORT(int) mvinchnstr (int a1, int a2, chtype * a3, int z)
-{
-	T((T_CALLED("mvinchnstr(%d,%d,%p,%d)"), a1, a2, a3, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winchnstr(stdscr,a3,z)));
-}
-
-
-#undef mvinchstr
-NCURSES_EXPORT(int) mvinchstr (int a1, int a2, chtype * z)
-{
-	T((T_CALLED("mvinchstr(%d,%d,%p)"), a1, a2, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winchnstr(stdscr, z, -1)));
-}
-
-
-#undef mvinnstr
-NCURSES_EXPORT(int) mvinnstr (int a1, int a2, char * a3, int z)
-{
-	return (wmove(stdscr,a1,a2) == (-1) ? (-1) : winnstr(stdscr,a3,z)) ;
-}
-
-
-#undef mvinsch
-NCURSES_EXPORT(int) mvinsch (int a1, int a2, chtype z)
-{
-	T((T_CALLED("mvinsch(%d,%d,%s)"), a1, a2, _tracechtype2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winsch(stdscr,z)));
-}
-
-
-#undef mvinsnstr
-NCURSES_EXPORT(int) mvinsnstr (int a1, int a2, const char * a3, int z)
-{
-	T((T_CALLED("mvinsnstr(%d,%d,%s,%d)"), a1, a2, _nc_visbuf2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winsnstr(stdscr,a3,z)));
-}
-
-
-#undef mvinsstr
-NCURSES_EXPORT(int) mvinsstr (int a1, int a2, const char * z)
-{
-	T((T_CALLED("mvinsstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winsnstr(stdscr, z, -1)));
-}
-
-
-#undef mvinstr
-NCURSES_EXPORT(int) mvinstr (int a1, int a2, char * z)
-{
-	T((T_CALLED("mvinstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winnstr(stdscr, z, -1)));
-}
-
-
-#undef mvvline
-NCURSES_EXPORT(int) mvvline (int a1, int a2, chtype a3, int z)
-{
-	T((T_CALLED("mvvline(%d,%d,%s,%d)"), a1, a2, _tracechtype2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wvline(stdscr,a3,z)));
-}
-
-
-#undef mvwaddch
-NCURSES_EXPORT(int) mvwaddch (WINDOW * a1, int a2, int a3, const chtype z)
-{
-	T((T_CALLED("mvwaddch(%p,%d,%d,%s)"), a1, a2, a3, _tracechtype2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddch(a1,z)));
-}
-
-
-#undef mvwaddchnstr
-NCURSES_EXPORT(int) mvwaddchnstr (WINDOW * a1, int a2, int a3, const chtype * a4, int z)
-{
-	T((T_CALLED("mvwaddchnstr(%p,%d,%d,%p,%d)"), a1, a2, a3, a4, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddchnstr(a1,a4,z)));
-}
-
-
-#undef mvwaddchstr
-NCURSES_EXPORT(int) mvwaddchstr (WINDOW * a1, int a2, int a3, const chtype * z)
-{
-	T((T_CALLED("mvwaddchstr(%p,%d,%d,%p)"), a1, a2, a3, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddchnstr(a1,z,-1)));
-}
-
-
-#undef mvwaddnstr
-NCURSES_EXPORT(int) mvwaddnstr (WINDOW * a1, int a2, int a3, const char * a4, int z)
-{
-	T((T_CALLED("mvwaddnstr(%p,%d,%d,%s,%d)"), a1, a2, a3, _nc_visbuf2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddnstr(a1,a4,z)));
-}
-
-
-#undef mvwaddstr
-NCURSES_EXPORT(int) mvwaddstr (WINDOW * a1, int a2, int a3, const char * z)
-{
-	T((T_CALLED("mvwaddstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddnstr(a1,z,-1)));
-}
-
-
-#undef mvwchgat
-NCURSES_EXPORT(int) mvwchgat (WINDOW * a1, int a2, int a3, int a4, attr_t a5, short a6, const void * z)
-{
-	T((T_CALLED("mvwchgat(%p,%d,%d,%d,%s,%d,%p)"), a1, a2, a3, a4, _traceattr2(4,a5), a6, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wchgat(a1,a4,a5,a6,z)));
-}
-
-
-#undef mvwdelch
-NCURSES_EXPORT(int) mvwdelch (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvwdelch(%p,%d,%d)"), a1, a2, z)); returnCode((wmove(a1,a2,z) == (-1) ? (-1) : wdelch(a1)));
-}
-
-
-#undef mvwgetch
-NCURSES_EXPORT(int) mvwgetch (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvwgetch(%p,%d,%d)"), a1, a2, z)); returnCode((wmove(a1,a2,z) == (-1) ? (-1) : wgetch(a1)));
-}
-
-
-#undef mvwgetnstr
-NCURSES_EXPORT(int) mvwgetnstr (WINDOW * a1, int a2, int a3, char * a4, int z)
-{
-	T((T_CALLED("mvwgetnstr(%p,%d,%d,%s,%d)"), a1, a2, a3, _nc_visbuf2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wgetnstr(a1,a4,z)));
-}
-
-
-#undef mvwgetstr
-NCURSES_EXPORT(int) mvwgetstr (WINDOW * a1, int a2, int a3, char * z)
-{
-	T((T_CALLED("mvwgetstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wgetnstr(a1, z, -1)));
-}
-
-
-#undef mvwhline
-NCURSES_EXPORT(int) mvwhline (WINDOW * a1, int a2, int a3, chtype a4, int z)
-{
-	T((T_CALLED("mvwhline(%p,%d,%d,%s,%d)"), a1, a2, a3, _tracechtype2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : whline(a1,a4,z)));
-}
-
-
-#undef mvwinch
-NCURSES_EXPORT(chtype) mvwinch (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvwinch(%p,%d,%d)"), a1, a2, z)); returnChar((wmove(a1,a2,z) == (-1) ? (chtype)((-1)) : winch(a1)));
-}
-
-
-#undef mvwinchnstr
-NCURSES_EXPORT(int) mvwinchnstr (WINDOW * a1, int a2, int a3, chtype * a4, int z)
-{
-	T((T_CALLED("mvwinchnstr(%p,%d,%d,%p,%d)"), a1, a2, a3, a4, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winchnstr(a1,a4,z)));
-}
-
-
-#undef mvwinchstr
-NCURSES_EXPORT(int) mvwinchstr (WINDOW * a1, int a2, int a3, chtype * z)
-{
-	T((T_CALLED("mvwinchstr(%p,%d,%d,%p)"), a1, a2, a3, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winchnstr(a1, z, -1)));
-}
-
-
-#undef mvwinnstr
-NCURSES_EXPORT(int) mvwinnstr (WINDOW * a1, int a2, int a3, char * a4, int z)
-{
-	return (wmove(a1,a2,a3) == (-1) ? (-1) : winnstr(a1,a4,z)) ;
-}
-
-
-#undef mvwinsch
-NCURSES_EXPORT(int) mvwinsch (WINDOW * a1, int a2, int a3, chtype z)
-{
-	T((T_CALLED("mvwinsch(%p,%d,%d,%s)"), a1, a2, a3, _tracechtype2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winsch(a1,z)));
-}
-
-
-#undef mvwinsnstr
-NCURSES_EXPORT(int) mvwinsnstr (WINDOW * a1, int a2, int a3, const char * a4, int z)
-{
-	T((T_CALLED("mvwinsnstr(%p,%d,%d,%s,%d)"), a1, a2, a3, _nc_visbuf2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winsnstr(a1,a4,z)));
-}
-
-
-#undef mvwinsstr
-NCURSES_EXPORT(int) mvwinsstr (WINDOW * a1, int a2, int a3, const char * z)
-{
-	T((T_CALLED("mvwinsstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winsnstr(a1, z, -1)));
-}
-
-
-#undef mvwinstr
-NCURSES_EXPORT(int) mvwinstr (WINDOW * a1, int a2, int a3, char * z)
-{
-	T((T_CALLED("mvwinstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winnstr(a1, z, -1)));
-}
-
-
-#undef mvwvline
-NCURSES_EXPORT(int) mvwvline (WINDOW * a1, int a2, int a3, chtype a4, int z)
-{
-	T((T_CALLED("mvwvline(%p,%d,%d,%s,%d)"), a1, a2, a3, _tracechtype2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wvline(a1,a4,z)));
-}
-
-
-#undef PAIR_NUMBER
-NCURSES_EXPORT(int) PAIR_NUMBER (int z)
-{
-	T((T_CALLED("PAIR_NUMBER(%d)"), z)); returnCode(((int)((((z) & ((((1UL) << 8) - 1UL) << ((0) + 8))) >> 8))));
-}
-
-
-#undef redrawwin
-NCURSES_EXPORT(int) redrawwin (WINDOW * z)
-{
-	T((T_CALLED("redrawwin(%p)"), z)); returnCode(wredrawln(z, 0, (z)->_maxy+1));
-}
-
-
-#undef refresh
-NCURSES_EXPORT(int) refresh (void)
-{
-	T((T_CALLED("refresh()"))); returnCode(wrefresh(stdscr));
-}
-
-
-#undef scrl
-NCURSES_EXPORT(int) scrl (int z)
-{
-	T((T_CALLED("scrl(%d)"), z)); returnCode(wscrl(stdscr,z));
-}
-
-
-#undef scroll
-NCURSES_EXPORT(int) scroll (WINDOW * z)
-{
-	T((T_CALLED("scroll(%p)"), z)); returnCode(wscrl(z,1));
-}
-
-
-#undef setscrreg
-NCURSES_EXPORT(int) setscrreg (int a1, int z)
-{
-	T((T_CALLED("setscrreg(%d,%d)"), a1, z)); returnCode(wsetscrreg(stdscr,a1,z));
-}
-
-
-#if USE_WIDEC_SUPPORT
-#undef slk_attr_off
-NCURSES_EXPORT(int) slk_attr_off (const attr_t a1, void * z)
-{
-	T((T_CALLED("slk_attr_off(%s,%p)"), _traceattr2(0,a1), z)); returnCode(((z) ? (-1) : slk_attroff(a1)));
-}
-#endif
-
-
-#if USE_WIDEC_SUPPORT
-#undef slk_attr_on
-NCURSES_EXPORT(int) slk_attr_on (attr_t a1, void * z)
-{
-	T((T_CALLED("slk_attr_on(%s,%p)"), _traceattr2(0,a1), z)); returnCode(((z) ? (-1) : slk_attron(a1)));
-}
-#endif
-
-
-#undef standout
-NCURSES_EXPORT(int) standout (void)
-{
-	T((T_CALLED("standout()"))); returnAttr((((stdscr)->_attrs = (((1UL) << ((8) + 8))))));
-}
-
-
-#undef standend
-NCURSES_EXPORT(int) standend (void)
-{
-	T((T_CALLED("standend()"))); returnAttr((((stdscr)->_attrs = ((1UL - 1UL)))));
-}
-
-
-#undef timeout
-NCURSES_EXPORT(void) timeout (int z)
-{
-	T((T_CALLED("timeout(%d)"), z)); wtimeout(stdscr,z);
-	returnVoid;
-}
-
-
-#undef touchline
-NCURSES_EXPORT(int) touchline (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("touchline(%p,%d,%d)"), a1, a2, z)); returnCode(wtouchln((a1), a2, z, 1));
-}
-
-
-#undef touchwin
-NCURSES_EXPORT(int) touchwin (WINDOW * z)
-{
-	T((T_CALLED("touchwin(%p)"), z)); returnCode(wtouchln((z), 0, ((z) ? ((z)->_maxy + 1) : (-1)), 1));
-}
-
-
-#undef untouchwin
-NCURSES_EXPORT(int) untouchwin (WINDOW * z)
-{
-	T((T_CALLED("untouchwin(%p)"), z)); returnCode(wtouchln((z), 0, ((z) ? ((z)->_maxy + 1) : (-1)), 0));
-}
-
-
-#undef vline
-NCURSES_EXPORT(int) vline (chtype a1, int z)
-{
-	T((T_CALLED("vline(%s,%d)"), _tracechtype2(0,a1), z)); returnCode(wvline(stdscr, a1, z));
-}
-
-
-#undef vw_printw
-NCURSES_EXPORT(int) vw_printw (WINDOW * a1, const char * a2, va_list z)
-{
-	T((T_CALLED("vw_printw(%p,%s,%s)"), a1, _nc_visbuf2(1,a2), "va_list")); returnCode(vwprintw(a1, a2, z));
-}
-
-
-#undef vw_scanw
-NCURSES_EXPORT(int) vw_scanw (WINDOW * a1, char * a2, va_list z)
-{
-	T((T_CALLED("vw_scanw(%p,%s,%s)"), a1, _nc_visbuf2(1,a2), "va_list")); returnCode(vwscanw(a1, a2, z));
-}
-
-
-#undef waddchstr
-NCURSES_EXPORT(int) waddchstr (WINDOW * a1, const chtype * z)
-{
-	T((T_CALLED("waddchstr(%p,%p)"), a1, z)); returnCode(waddchnstr(a1,z,-1));
-}
-
-
-#undef waddstr
-NCURSES_EXPORT(int) waddstr (WINDOW * a1, const char * z)
-{
-	T((T_CALLED("waddstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(waddnstr(a1,z,-1));
-}
-
-
-#undef wattron
-NCURSES_EXPORT(int) wattron (WINDOW * a1, int z)
-{
-	T((T_CALLED("wattron(%p,%d)"), a1, z)); returnCode(wattr_on(a1, (attr_t)(z), ((void *)0)));
-}
-
-
-#undef wattroff
-NCURSES_EXPORT(int) wattroff (WINDOW * a1, int z)
-{
-	T((T_CALLED("wattroff(%p,%d)"), a1, z)); returnCode(wattr_off(a1, (attr_t)(z), ((void *)0)));
-}
-
-
-#undef wattrset
-NCURSES_EXPORT(int) wattrset (WINDOW * a1, int z)
-{
-	T((T_CALLED("wattrset(%p,%d)"), a1, z)); returnAttr(((a1)->_attrs = (z)));
-}
-
-
-#undef wattr_get
-NCURSES_EXPORT(int) wattr_get (WINDOW * a1, attr_t * a2, short * a3, void * z)
-{
-	T((T_CALLED("wattr_get(%p,%p,%p,%p)"), a1, a2, a3, z)); returnCode(((void)((a2) != (void *)0 && (*(a2) = (a1)->_attrs)), (void)((a3) != (void *)0 && (*(a3) = ((int)(((((a1)->_attrs) & ((((1UL) << 8) - 1UL) << ((0) + 8))) >> 8))))), (0)));
-}
-
-
-#undef wattr_set
-NCURSES_EXPORT(int) wattr_set (WINDOW * a1, attr_t a2, short a3, void * z)
-{
-	T((T_CALLED("wattr_set(%p,%s,%d,%p)"), a1, _traceattr2(1,a2), a3, z)); returnCode(((a1)->_attrs = (((a2) & ~((((1UL) << 8) - 1UL) << ((0) + 8))) | ((a3) << ((0) + 8))), (0)));
-}
-
-
-#undef wdeleteln
-NCURSES_EXPORT(int) wdeleteln (WINDOW * z)
-{
-	T((T_CALLED("wdeleteln(%p)"), z)); returnCode(winsdelln(z,-1));
-}
-
-
-#undef wgetstr
-NCURSES_EXPORT(int) wgetstr (WINDOW * a1, char * z)
-{
-	T((T_CALLED("wgetstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(wgetnstr(a1, z, -1));
-}
-
-
-#undef winchstr
-NCURSES_EXPORT(int) winchstr (WINDOW * a1, chtype * z)
-{
-	T((T_CALLED("winchstr(%p,%p)"), a1, z)); returnCode(winchnstr(a1, z, -1));
-}
-
-
-#undef winsertln
-NCURSES_EXPORT(int) winsertln (WINDOW * z)
-{
-	T((T_CALLED("winsertln(%p)"), z)); returnCode(winsdelln(z,1));
-}
-
-
-#undef winsstr
-NCURSES_EXPORT(int) winsstr (WINDOW * a1, const char * z)
-{
-	T((T_CALLED("winsstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(winsnstr(a1, z, -1));
-}
-
-
-#undef winstr
-NCURSES_EXPORT(int) winstr (WINDOW * a1, char * z)
-{
-	T((T_CALLED("winstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(winnstr(a1, z, -1));
-}
-
-
-#undef wstandout
-NCURSES_EXPORT(int) wstandout (WINDOW * z)
-{
-	T((T_CALLED("wstandout(%p)"), z)); returnAttr((((z)->_attrs = (((1UL) << ((8) + 8))))));
-}
-
-
-#undef wstandend
-NCURSES_EXPORT(int) wstandend (WINDOW * z)
-{
-	T((T_CALLED("wstandend(%p)"), z)); returnAttr((((z)->_attrs = ((1UL - 1UL)))));
-}
-
-
-#undef getattrs
-NCURSES_EXPORT(int) getattrs (const WINDOW * z)
-{
-	T((T_CALLED("getattrs(%p)"), z)); returnCode(((z) ? (z)->_attrs : (1UL - 1UL)));
-}
-
-
-#undef getcurx
-NCURSES_EXPORT(int) getcurx (const WINDOW * z)
-{
-	T((T_CALLED("getcurx(%p)"), z)); returnCode(((z) ? (z)->_curx : (-1)));
-}
-
-
-#undef getcury
-NCURSES_EXPORT(int) getcury (const WINDOW * z)
-{
-	T((T_CALLED("getcury(%p)"), z)); returnCode(((z) ? (z)->_cury : (-1)));
-}
-
-
-#undef getbegx
-NCURSES_EXPORT(int) getbegx (const WINDOW * z)
-{
-	T((T_CALLED("getbegx(%p)"), z)); returnCode(((z) ? (z)->_begx : (-1)));
-}
-
-
-#undef getbegy
-NCURSES_EXPORT(int) getbegy (const WINDOW * z)
-{
-	T((T_CALLED("getbegy(%p)"), z)); returnCode(((z) ? (z)->_begy : (-1)));
-}
-
-
-#undef getmaxx
-NCURSES_EXPORT(int) getmaxx (const WINDOW * z)
-{
-	T((T_CALLED("getmaxx(%p)"), z)); returnCode(((z) ? ((z)->_maxx + 1) : (-1)));
-}
-
-
-#undef getmaxy
-NCURSES_EXPORT(int) getmaxy (const WINDOW * z)
-{
-	T((T_CALLED("getmaxy(%p)"), z)); returnCode(((z) ? ((z)->_maxy + 1) : (-1)));
-}
-
-
-#undef getparx
-NCURSES_EXPORT(int) getparx (const WINDOW * z)
-{
-	T((T_CALLED("getparx(%p)"), z)); returnCode(((z) ? (z)->_parx : (-1)));
-}
-
-
-#undef getpary
-NCURSES_EXPORT(int) getpary (const WINDOW * z)
-{
-	T((T_CALLED("getpary(%p)"), z)); returnCode(((z) ? (z)->_pary : (-1)));
-}
-
-
-#undef wgetparent
-NCURSES_EXPORT(WINDOW *) wgetparent (const WINDOW * z)
-{
-	T((T_CALLED("(%p)"), z)); returnWin(((z) ? (z)->_parent : 0));
-}
-
-
-#undef is_cleared
-NCURSES_EXPORT(NCURSES_BOOL) is_cleared (const WINDOW * z)
-{
-	T((T_CALLED("is_cleared(%p)"), z)); returnBool(((z)->_clear));
-}
-
-
-#undef is_idcok
-NCURSES_EXPORT(NCURSES_BOOL) is_idcok (const WINDOW * z)
-{
-	T((T_CALLED("is_idcok(%p)"), z)); returnBool(((z)->_idcok));
-}
-
-
-#undef is_idlok
-NCURSES_EXPORT(NCURSES_BOOL) is_idlok (const WINDOW * z)
-{
-	T((T_CALLED("is_idlok(%p)"), z)); returnBool(((z)->_idlok));
-}
-
-
-#undef is_immedok
-NCURSES_EXPORT(NCURSES_BOOL) is_immedok (const WINDOW * z)
-{
-	T((T_CALLED("is_immedok(%p)"), z)); returnBool(((z)->_immed));
-}
-
-
-#undef is_keypad
-NCURSES_EXPORT(NCURSES_BOOL) is_keypad (const WINDOW * z)
-{
-	T((T_CALLED("is_keypad(%p)"), z)); returnBool(((z)->_use_keypad));
-}
-
-
-#undef is_leaveok
-NCURSES_EXPORT(NCURSES_BOOL) is_leaveok (const WINDOW * z)
-{
-	T((T_CALLED("is_leaveok(%p)"), z)); returnBool(((z)->_leaveok));
-}
-
-
-#undef is_nodelay
-NCURSES_EXPORT(NCURSES_BOOL) is_nodelay (const WINDOW * z)
-{
-	T((T_CALLED("is_nodelay(%p)"), z)); returnBool(((z)->_delay == 0));
-}
-
-
-#undef is_notimeout
-NCURSES_EXPORT(NCURSES_BOOL) is_notimeout (const WINDOW * z)
-{
-	T((T_CALLED("is_notimeout(%p)"), z)); returnBool(((z)->_notimeout));
-}
-
-
-#undef is_scrollok
-NCURSES_EXPORT(NCURSES_BOOL) is_scrollok (const WINDOW * z)
-{
-	T((T_CALLED("is_scrollok(%p)"), z)); returnBool(((z)->_scroll));
-}
-
-
-#undef is_syncok
-NCURSES_EXPORT(NCURSES_BOOL) is_syncok (const WINDOW * z)
-{
-	T((T_CALLED("is_syncok(%p)"), z)); returnBool(((z)->_sync));
-}
-
-
-#undef wgetscrreg
-NCURSES_EXPORT(int) wgetscrreg (const WINDOW * a1, int * a2, int * z)
-{
-	T((T_CALLED("wgetscrreg(%p,%p,%p)"), a1, a2, z)); returnCode(((a1) ? (*(a2) = (a1)->_regtop, *(z) = (a1)->_regbottom, (0)) : (-1)));
-}
-
-
-#undef mouse_trafo
-NCURSES_EXPORT(NCURSES_BOOL) mouse_trafo (int * a1, int * a2, NCURSES_BOOL z)
-{
-	T((T_CALLED("mouse_trafo(%p,%p,%#lx)"), a1, a2, (long)z)); returnBool(wmouse_trafo(stdscr,a1,a2,z));
-}
diff --git a/ncurses/lib_keyname.c b/ncurses/lib_keyname.c
deleted file mode 100644
index ae2a95a..0000000
--- a/ncurses/lib_keyname.c
+++ /dev/null
@@ -1,405 +0,0 @@
-/* generated by MKkeyname.awk */
-
-#include <curses.priv.h>
-#include <tic.h>
-#include <term_entry.h>
-
-struct kn { short offset; int code; };
-static const struct kn _nc_key_names[] = {
-	{ 0, KEY_A1 },
-	{ 7, KEY_A3 },
-	{ 14, KEY_B2 },
-	{ 21, KEY_BACKSPACE },
-	{ 35, KEY_BEG },
-	{ 43, KEY_BREAK },
-	{ 53, KEY_BTAB },
-	{ 62, KEY_C1 },
-	{ 69, KEY_C3 },
-	{ 76, KEY_CANCEL },
-	{ 87, KEY_CATAB },
-	{ 97, KEY_CLEAR },
-	{ 107, KEY_CLOSE },
-	{ 117, KEY_COMMAND },
-	{ 129, KEY_COPY },
-	{ 138, KEY_CREATE },
-	{ 149, KEY_CTAB },
-	{ 158, KEY_DC },
-	{ 165, KEY_DL },
-	{ 172, KEY_DOWN },
-	{ 181, KEY_EIC },
-	{ 189, KEY_END },
-	{ 197, KEY_ENTER },
-	{ 207, KEY_EOL },
-	{ 215, KEY_EOS },
-	{ 223, KEY_EXIT },
-	{ 232, KEY_F(0) },
-	{ 241, KEY_F(10) },
-	{ 251, KEY_F(11) },
-	{ 261, KEY_F(12) },
-	{ 271, KEY_F(13) },
-	{ 281, KEY_F(14) },
-	{ 291, KEY_F(15) },
-	{ 301, KEY_F(16) },
-	{ 311, KEY_F(17) },
-	{ 321, KEY_F(18) },
-	{ 331, KEY_F(19) },
-	{ 341, KEY_F(1) },
-	{ 350, KEY_F(20) },
-	{ 360, KEY_F(21) },
-	{ 370, KEY_F(22) },
-	{ 380, KEY_F(23) },
-	{ 390, KEY_F(24) },
-	{ 400, KEY_F(25) },
-	{ 410, KEY_F(26) },
-	{ 420, KEY_F(27) },
-	{ 430, KEY_F(28) },
-	{ 440, KEY_F(29) },
-	{ 450, KEY_F(2) },
-	{ 459, KEY_F(30) },
-	{ 469, KEY_F(31) },
-	{ 479, KEY_F(32) },
-	{ 489, KEY_F(33) },
-	{ 499, KEY_F(34) },
-	{ 509, KEY_F(35) },
-	{ 519, KEY_F(36) },
-	{ 529, KEY_F(37) },
-	{ 539, KEY_F(38) },
-	{ 549, KEY_F(39) },
-	{ 559, KEY_F(3) },
-	{ 568, KEY_F(40) },
-	{ 578, KEY_F(41) },
-	{ 588, KEY_F(42) },
-	{ 598, KEY_F(43) },
-	{ 608, KEY_F(44) },
-	{ 618, KEY_F(45) },
-	{ 628, KEY_F(46) },
-	{ 638, KEY_F(47) },
-	{ 648, KEY_F(48) },
-	{ 658, KEY_F(49) },
-	{ 668, KEY_F(4) },
-	{ 677, KEY_F(50) },
-	{ 687, KEY_F(51) },
-	{ 697, KEY_F(52) },
-	{ 707, KEY_F(53) },
-	{ 717, KEY_F(54) },
-	{ 727, KEY_F(55) },
-	{ 737, KEY_F(56) },
-	{ 747, KEY_F(57) },
-	{ 757, KEY_F(58) },
-	{ 767, KEY_F(59) },
-	{ 777, KEY_F(5) },
-	{ 786, KEY_F(60) },
-	{ 796, KEY_F(61) },
-	{ 806, KEY_F(62) },
-	{ 816, KEY_F(63) },
-	{ 826, KEY_F(6) },
-	{ 835, KEY_F(7) },
-	{ 844, KEY_F(8) },
-	{ 853, KEY_F(9) },
-	{ 862, KEY_FIND },
-	{ 871, KEY_HELP },
-	{ 880, KEY_HOME },
-	{ 889, KEY_IC },
-	{ 896, KEY_IL },
-	{ 903, KEY_LEFT },
-	{ 912, KEY_LL },
-	{ 919, KEY_MARK },
-	{ 928, KEY_MESSAGE },
-	{ 940, KEY_MOUSE },
-	{ 950, KEY_MOVE },
-	{ 959, KEY_NEXT },
-	{ 968, KEY_NPAGE },
-	{ 978, KEY_OPEN },
-	{ 987, KEY_OPTIONS },
-	{ 999, KEY_PPAGE },
-	{ 1009, KEY_PREVIOUS },
-	{ 1022, KEY_PRINT },
-	{ 1032, KEY_REDO },
-	{ 1041, KEY_REFERENCE },
-	{ 1055, KEY_REFRESH },
-	{ 1067, KEY_REPLACE },
-	{ 1079, KEY_RESET },
-	{ 1089, KEY_RESIZE },
-	{ 1100, KEY_RESTART },
-	{ 1112, KEY_RESUME },
-	{ 1123, KEY_RIGHT },
-	{ 1133, KEY_SAVE },
-	{ 1142, KEY_SBEG },
-	{ 1151, KEY_SCANCEL },
-	{ 1163, KEY_SCOMMAND },
-	{ 1176, KEY_SCOPY },
-	{ 1186, KEY_SCREATE },
-	{ 1198, KEY_SDC },
-	{ 1206, KEY_SDL },
-	{ 1214, KEY_SELECT },
-	{ 1225, KEY_SEND },
-	{ 1234, KEY_SEOL },
-	{ 1243, KEY_SEXIT },
-	{ 1253, KEY_SFIND },
-	{ 1263, KEY_SF },
-	{ 1270, KEY_SHELP },
-	{ 1280, KEY_SHOME },
-	{ 1290, KEY_SIC },
-	{ 1298, KEY_SLEFT },
-	{ 1308, KEY_SMESSAGE },
-	{ 1321, KEY_SMOVE },
-	{ 1331, KEY_SNEXT },
-	{ 1341, KEY_SOPTIONS },
-	{ 1354, KEY_SPREVIOUS },
-	{ 1368, KEY_SPRINT },
-	{ 1379, KEY_SREDO },
-	{ 1389, KEY_SREPLACE },
-	{ 1402, KEY_SRESET },
-	{ 1413, KEY_SRIGHT },
-	{ 1424, KEY_SR },
-	{ 1431, KEY_SRSUME },
-	{ 1442, KEY_SSAVE },
-	{ 1452, KEY_SSUSPEND },
-	{ 1465, KEY_STAB },
-	{ 1474, KEY_SUNDO },
-	{ 1484, KEY_SUSPEND },
-	{ 1496, KEY_UNDO },
-	{ 1505, KEY_UP },
-	{ -1, 0 }};
-
-static const char key_names[] = 
-	"KEY_A1\0"
-	"KEY_A3\0"
-	"KEY_B2\0"
-	"KEY_BACKSPACE\0"
-	"KEY_BEG\0"
-	"KEY_BREAK\0"
-	"KEY_BTAB\0"
-	"KEY_C1\0"
-	"KEY_C3\0"
-	"KEY_CANCEL\0"
-	"KEY_CATAB\0"
-	"KEY_CLEAR\0"
-	"KEY_CLOSE\0"
-	"KEY_COMMAND\0"
-	"KEY_COPY\0"
-	"KEY_CREATE\0"
-	"KEY_CTAB\0"
-	"KEY_DC\0"
-	"KEY_DL\0"
-	"KEY_DOWN\0"
-	"KEY_EIC\0"
-	"KEY_END\0"
-	"KEY_ENTER\0"
-	"KEY_EOL\0"
-	"KEY_EOS\0"
-	"KEY_EXIT\0"
-	"KEY_F(0)\0"
-	"KEY_F(10)\0"
-	"KEY_F(11)\0"
-	"KEY_F(12)\0"
-	"KEY_F(13)\0"
-	"KEY_F(14)\0"
-	"KEY_F(15)\0"
-	"KEY_F(16)\0"
-	"KEY_F(17)\0"
-	"KEY_F(18)\0"
-	"KEY_F(19)\0"
-	"KEY_F(1)\0"
-	"KEY_F(20)\0"
-	"KEY_F(21)\0"
-	"KEY_F(22)\0"
-	"KEY_F(23)\0"
-	"KEY_F(24)\0"
-	"KEY_F(25)\0"
-	"KEY_F(26)\0"
-	"KEY_F(27)\0"
-	"KEY_F(28)\0"
-	"KEY_F(29)\0"
-	"KEY_F(2)\0"
-	"KEY_F(30)\0"
-	"KEY_F(31)\0"
-	"KEY_F(32)\0"
-	"KEY_F(33)\0"
-	"KEY_F(34)\0"
-	"KEY_F(35)\0"
-	"KEY_F(36)\0"
-	"KEY_F(37)\0"
-	"KEY_F(38)\0"
-	"KEY_F(39)\0"
-	"KEY_F(3)\0"
-	"KEY_F(40)\0"
-	"KEY_F(41)\0"
-	"KEY_F(42)\0"
-	"KEY_F(43)\0"
-	"KEY_F(44)\0"
-	"KEY_F(45)\0"
-	"KEY_F(46)\0"
-	"KEY_F(47)\0"
-	"KEY_F(48)\0"
-	"KEY_F(49)\0"
-	"KEY_F(4)\0"
-	"KEY_F(50)\0"
-	"KEY_F(51)\0"
-	"KEY_F(52)\0"
-	"KEY_F(53)\0"
-	"KEY_F(54)\0"
-	"KEY_F(55)\0"
-	"KEY_F(56)\0"
-	"KEY_F(57)\0"
-	"KEY_F(58)\0"
-	"KEY_F(59)\0"
-	"KEY_F(5)\0"
-	"KEY_F(60)\0"
-	"KEY_F(61)\0"
-	"KEY_F(62)\0"
-	"KEY_F(63)\0"
-	"KEY_F(6)\0"
-	"KEY_F(7)\0"
-	"KEY_F(8)\0"
-	"KEY_F(9)\0"
-	"KEY_FIND\0"
-	"KEY_HELP\0"
-	"KEY_HOME\0"
-	"KEY_IC\0"
-	"KEY_IL\0"
-	"KEY_LEFT\0"
-	"KEY_LL\0"
-	"KEY_MARK\0"
-	"KEY_MESSAGE\0"
-	"KEY_MOUSE\0"
-	"KEY_MOVE\0"
-	"KEY_NEXT\0"
-	"KEY_NPAGE\0"
-	"KEY_OPEN\0"
-	"KEY_OPTIONS\0"
-	"KEY_PPAGE\0"
-	"KEY_PREVIOUS\0"
-	"KEY_PRINT\0"
-	"KEY_REDO\0"
-	"KEY_REFERENCE\0"
-	"KEY_REFRESH\0"
-	"KEY_REPLACE\0"
-	"KEY_RESET\0"
-	"KEY_RESIZE\0"
-	"KEY_RESTART\0"
-	"KEY_RESUME\0"
-	"KEY_RIGHT\0"
-	"KEY_SAVE\0"
-	"KEY_SBEG\0"
-	"KEY_SCANCEL\0"
-	"KEY_SCOMMAND\0"
-	"KEY_SCOPY\0"
-	"KEY_SCREATE\0"
-	"KEY_SDC\0"
-	"KEY_SDL\0"
-	"KEY_SELECT\0"
-	"KEY_SEND\0"
-	"KEY_SEOL\0"
-	"KEY_SEXIT\0"
-	"KEY_SFIND\0"
-	"KEY_SF\0"
-	"KEY_SHELP\0"
-	"KEY_SHOME\0"
-	"KEY_SIC\0"
-	"KEY_SLEFT\0"
-	"KEY_SMESSAGE\0"
-	"KEY_SMOVE\0"
-	"KEY_SNEXT\0"
-	"KEY_SOPTIONS\0"
-	"KEY_SPREVIOUS\0"
-	"KEY_SPRINT\0"
-	"KEY_SREDO\0"
-	"KEY_SREPLACE\0"
-	"KEY_SRESET\0"
-	"KEY_SRIGHT\0"
-	"KEY_SR\0"
-	"KEY_SRSUME\0"
-	"KEY_SSAVE\0"
-	"KEY_SSUSPEND\0"
-	"KEY_STAB\0"
-	"KEY_SUNDO\0"
-	"KEY_SUSPEND\0"
-	"KEY_UNDO\0"
-	"KEY_UP\0";
-
-#define SIZEOF_TABLE 256
-#define MyTable _nc_globals.keyname_table
-
-NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *sp, int c)
-{
-	int i;
-	char name[20];
-	char *p;
-	NCURSES_CONST char *result = 0;
-
-	if (c == -1) {
-		result = "-1";
-	} else {
-		for (i = 0; _nc_key_names[i].offset != -1; i++) {
-			if (_nc_key_names[i].code == c) {
-				result = (NCURSES_CONST char *)key_names + _nc_key_names[i].offset;
-				break;
-			}
-		}
-
-		if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {
-			if (MyTable == 0)
-				MyTable = typeCalloc(char *, SIZEOF_TABLE);
-			if (MyTable != 0) {
-				if (MyTable[c] == 0) {
-					int cc = c;
-					p = name;
-					if (cc >= 128 && (sp == 0 || sp->_use_meta)) {
-						strcpy(p, "M-");
-						p += 2;
-						cc -= 128;
-					}
-					if (cc < 32)
-						sprintf(p, "^%c", cc + '@');
-					else if (cc == 127)
-						strcpy(p, "^?");
-					else
-						sprintf(p, "%c", cc);
-					MyTable[c] = strdup(name);
-				}
-				result = MyTable[c];
-			}
-#if NCURSES_EXT_FUNCS && NCURSES_XNAMES
-		} else if (result == 0 && cur_term != 0) {
-			int j, k;
-			char * bound;
-			TERMTYPE *tp = &(cur_term->type);
-			int save_trace = _nc_tracing;
-
-			_nc_tracing = 0;	/* prevent recursion via keybound() */
-			for (j = 0; (bound = keybound(c, j)) != 0; ++j) {
-				for(k = STRCOUNT; k < (int) NUM_STRINGS(tp);  k++) {
-					if (tp->Strings[k] != 0 && !strcmp(bound, tp->Strings[k])) {
-						result = ExtStrname(tp, k, strnames);
-						break;
-					}
-				}
-				free(bound);
-				if (result != 0)
-					break;
-			}
-			_nc_tracing = save_trace;
-#endif
-		}
-	}
-	return result;
-}
-
-NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)
-{
-	return _nc_keyname(SP, c);
-}
-
-#if NO_LEAKS
-void _nc_keyname_leaks(void)
-{
-	int j;
-	if (MyTable != 0) {
-		for (j = 0; j < SIZEOF_TABLE; ++j) {
-			FreeIfNeeded(MyTable[j]);
-		}
-		FreeAndNull(MyTable);
-	}
-}
-#endif /* NO_LEAKS */
diff --git a/ncurses/link_test.c b/ncurses/link_test.c
deleted file mode 100644
index 588a754..0000000
--- a/ncurses/link_test.c
+++ /dev/null
@@ -1,1999 +0,0 @@
-/*
- * DO NOT EDIT THIS FILE BY HAND!
- * It is generated by ./base/MKlib_gen.sh implemented.
- */
-#define NCURSES_ATTR_T int
-#include <curses.priv.h>
-
-
-extern int call_addch (const chtype z);
-int call_addch (const chtype z)
-{
-	T((T_CALLED("addch(%s)"), _tracechtype2(0,z))); returnCode(waddch(stdscr,z));
-}
-
-
-extern int call_addchnstr (const chtype * a1, int z);
-int call_addchnstr (const chtype * a1, int z)
-{
-	T((T_CALLED("addchnstr(%p,%d)"), a1, z)); returnCode(waddchnstr(stdscr,a1,z));
-}
-
-
-extern int call_addchstr (const chtype * z);
-int call_addchstr (const chtype * z)
-{
-	T((T_CALLED("addchstr(%p)"), z)); returnCode(waddchnstr(stdscr,z,-1));
-}
-
-
-extern int call_addnstr (const char * a1, int z);
-int call_addnstr (const char * a1, int z)
-{
-	T((T_CALLED("addnstr(%s,%d)"), _nc_visbuf2(0,a1), z)); returnCode(waddnstr(stdscr,a1,z));
-}
-
-
-extern int call_addstr (const char * z);
-int call_addstr (const char * z)
-{
-	T((T_CALLED("addstr(%s)"), _nc_visbuf2(0,z))); returnCode(waddnstr(stdscr,z,-1));
-}
-
-
-extern int call_attroff (int z);
-int call_attroff (int z)
-{
-	T((T_CALLED("attroff(%s)"), _traceattr2(0,z))); returnCode(wattr_off(stdscr, (attr_t)(z), ((void *)0)));
-}
-
-
-extern int call_attron (int z);
-int call_attron (int z)
-{
-	T((T_CALLED("attron(%s)"), _traceattr2(0,z))); returnCode(wattr_on(stdscr, (attr_t)(z), ((void *)0)));
-}
-
-
-extern int call_attrset (int z);
-int call_attrset (int z)
-{
-	T((T_CALLED("attrset(%s)"), _traceattr2(0,z))); returnAttr(((stdscr)->_attrs = (z)));
-}
-
-
-extern int call_attr_get (attr_t * a1, short * a2, void * z);
-int call_attr_get (attr_t * a1, short * a2, void * z)
-{
-	T((T_CALLED("attr_get(%p,%p,%p)"), a1, a2, z)); returnCode(((void)((a1) != (void *)0 && (*(a1) = (stdscr)->_attrs)), (void)((a2) != (void *)0 && (*(a2) = ((int)(((((stdscr)->_attrs) & ((((1UL) << 8) - 1UL) << ((0) + 8))) >> 8))))), (0)));
-}
-
-
-extern int call_attr_off (attr_t a1, void * z);
-int call_attr_off (attr_t a1, void * z)
-{
-	T((T_CALLED("attr_off(%s,%p)"), _traceattr2(0,a1), z)); returnCode(wattr_off(stdscr,a1,z));
-}
-
-
-extern int call_attr_on (attr_t a1, void * z);
-int call_attr_on (attr_t a1, void * z)
-{
-	T((T_CALLED("attr_on(%s,%p)"), _traceattr2(0,a1), z)); returnCode(wattr_on(stdscr,a1,z));
-}
-
-
-extern int call_attr_set (attr_t a1, short a2, void * z);
-int call_attr_set (attr_t a1, short a2, void * z)
-{
-	T((T_CALLED("attr_set(%s,%d,%p)"), _traceattr2(0,a1), a2, z)); returnCode(((stdscr)->_attrs = (((a1) & ~((((1UL) << 8) - 1UL) << ((0) + 8))) | ((a2) << ((0) + 8))), (0)));
-}
-
-
-extern int call_baudrate (void);
-int call_baudrate (void)
-{
-	T((T_CALLED("baudrate()"))); returnCode(baudrate());
-}
-
-
-extern int call_beep (void);
-int call_beep (void)
-{
-	T((T_CALLED("beep()"))); returnCode(beep());
-}
-
-
-extern int call_bkgd (chtype z);
-int call_bkgd (chtype z)
-{
-	T((T_CALLED("bkgd(%s)"), _tracechtype2(0,z))); returnCode(wbkgd(stdscr,z));
-}
-
-
-extern void call_bkgdset (chtype z);
-void call_bkgdset (chtype z)
-{
-	T((T_CALLED("bkgdset(%s)"), _tracechtype2(0,z))); wbkgdset(stdscr,z);
-	returnVoid;
-}
-
-
-extern int call_border (chtype a1, chtype a2, chtype a3, chtype a4, chtype a5, chtype a6, chtype a7, chtype z);
-int call_border (chtype a1, chtype a2, chtype a3, chtype a4, chtype a5, chtype a6, chtype a7, chtype z)
-{
-	T((T_CALLED("border(%s,%s,%s,%s,%s,%s,%s,%s)"), _tracechtype2(0,a1), _tracechtype2(1,a2), _tracechtype2(2,a3), _tracechtype2(3,a4), _tracechtype2(4,a5), _tracechtype2(5,a6), _tracechtype2(6,a7), _tracechtype2(7,z))); returnCode(wborder(stdscr, a1, a2, a3, a4, a5, a6, a7, z));
-}
-
-
-extern int call_box (WINDOW * a1, chtype a2, chtype z);
-int call_box (WINDOW * a1, chtype a2, chtype z)
-{
-	T((T_CALLED("box(%p,%s,%s)"), a1, _tracechtype2(1,a2), _tracechtype2(2,z))); returnCode(wborder(a1, a2, a2, z, z, 0, 0, 0, 0));
-}
-
-
-extern NCURSES_BOOL call_can_change_color (void);
-NCURSES_BOOL call_can_change_color (void)
-{
-	T((T_CALLED("can_change_color()"))); returnBool(can_change_color());
-}
-
-
-extern int call_cbreak (void);
-int call_cbreak (void)
-{
-	T((T_CALLED("cbreak()"))); returnCode(cbreak());
-}
-
-
-extern int call_chgat (int a1, attr_t a2, short a3, const void * z);
-int call_chgat (int a1, attr_t a2, short a3, const void * z)
-{
-	T((T_CALLED("chgat(%d,%s,%d,%p)"), a1, _traceattr2(1,a2), a3, z)); returnCode(wchgat(stdscr,a1,a2,a3,z));
-}
-
-
-extern int call_clear (void);
-int call_clear (void)
-{
-	T((T_CALLED("clear()"))); returnCode(wclear(stdscr));
-}
-
-
-extern int call_clearok (WINDOW * a1, NCURSES_BOOL z);
-int call_clearok (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("clearok(%p,%#lx)"), a1, (long)z)); returnCode(clearok(a1, z));
-}
-
-
-extern int call_clrtobot (void);
-int call_clrtobot (void)
-{
-	T((T_CALLED("clrtobot()"))); returnCode(wclrtobot(stdscr));
-}
-
-
-extern int call_clrtoeol (void);
-int call_clrtoeol (void)
-{
-	T((T_CALLED("clrtoeol()"))); returnCode(wclrtoeol(stdscr));
-}
-
-
-extern int call_color_content (short a1, short * a2, short * a3, short * z);
-int call_color_content (short a1, short * a2, short * a3, short * z)
-{
-	T((T_CALLED("color_content(%d,%p,%p,%p)"), a1, a2, a3, z)); returnCode(color_content(a1, a2, a3, z));
-}
-
-
-extern int call_color_set (short a1, void * z);
-int call_color_set (short a1, void * z)
-{
-	T((T_CALLED("color_set(%d,%p)"), a1, z)); returnCode(wcolor_set(stdscr,a1,z));
-}
-
-
-extern int call_COLOR_PAIR (int z);
-int call_COLOR_PAIR (int z)
-{
-	T((T_CALLED("COLOR_PAIR(%d)"), z)); returnCode(((z) << ((0) + 8)));
-}
-
-
-extern int call_copywin (const WINDOW * a1, WINDOW * a2, int a3, int a4, int a5, int a6, int a7, int a8, int z);
-int call_copywin (const WINDOW * a1, WINDOW * a2, int a3, int a4, int a5, int a6, int a7, int a8, int z)
-{
-	T((T_CALLED("copywin(%p,%p,%d,%d,%d,%d,%d,%d,%d)"), a1, a2, a3, a4, a5, a6, a7, a8, z)); returnCode(copywin(a1, a2, a3, a4, a5, a6, a7, a8, z));
-}
-
-
-extern int call_curs_set (int z);
-int call_curs_set (int z)
-{
-	T((T_CALLED("curs_set(%d)"), z)); returnCode(curs_set(z));
-}
-
-
-extern int call_def_prog_mode (void);
-int call_def_prog_mode (void)
-{
-	T((T_CALLED("def_prog_mode()"))); returnCode(def_prog_mode());
-}
-
-
-extern int call_def_shell_mode (void);
-int call_def_shell_mode (void)
-{
-	T((T_CALLED("def_shell_mode()"))); returnCode(def_shell_mode());
-}
-
-
-extern int call_delay_output (int z);
-int call_delay_output (int z)
-{
-	T((T_CALLED("delay_output(%d)"), z)); returnCode(delay_output(z));
-}
-
-
-extern int call_delch (void);
-int call_delch (void)
-{
-	T((T_CALLED("delch()"))); returnCode(wdelch(stdscr));
-}
-
-
-extern void call_delscreen (SCREEN * z);
-void call_delscreen (SCREEN * z)
-{
-	T((T_CALLED("delscreen(%p)"), z)); delscreen(z);
-	returnVoid;
-}
-
-
-extern int call_delwin (WINDOW * z);
-int call_delwin (WINDOW * z)
-{
-	T((T_CALLED("delwin(%p)"), z)); returnCode(delwin(z));
-}
-
-
-extern int call_deleteln (void);
-int call_deleteln (void)
-{
-	T((T_CALLED("deleteln()"))); returnCode(winsdelln(stdscr,-1));
-}
-
-
-extern WINDOW * call_derwin (WINDOW * a1, int a2, int a3, int a4, int z);
-WINDOW * call_derwin (WINDOW * a1, int a2, int a3, int a4, int z)
-{
-	T((T_CALLED("(%p,%d,%d,%d,%d)"), a1, a2, a3, a4, z)); returnWin(derwin(a1, a2, a3, a4, z));
-}
-
-
-extern int call_doupdate (void);
-int call_doupdate (void)
-{
-	T((T_CALLED("doupdate()"))); returnCode(doupdate());
-}
-
-
-extern WINDOW * call_dupwin (WINDOW * z);
-WINDOW * call_dupwin (WINDOW * z)
-{
-	T((T_CALLED("(%p)"), z)); returnWin(dupwin(z));
-}
-
-
-extern int call_echo (void);
-int call_echo (void)
-{
-	T((T_CALLED("echo()"))); returnCode(echo());
-}
-
-
-extern int call_echochar (const chtype z);
-int call_echochar (const chtype z)
-{
-	T((T_CALLED("echochar(%s)"), _tracechtype2(0,z))); returnCode(wechochar(stdscr,z));
-}
-
-
-extern int call_erase (void);
-int call_erase (void)
-{
-	T((T_CALLED("erase()"))); returnCode(werase(stdscr));
-}
-
-
-extern int call_endwin (void);
-int call_endwin (void)
-{
-	T((T_CALLED("endwin()"))); returnCode(endwin());
-}
-
-
-extern char call_erasechar (void);
-char call_erasechar (void)
-{
-	T((T_CALLED("erasechar()"))); returnCode(erasechar());
-}
-
-
-extern void call_filter (void);
-void call_filter (void)
-{
-	T((T_CALLED("filter()"))); filter();
-	returnVoid;
-}
-
-
-extern int call_flash (void);
-int call_flash (void)
-{
-	T((T_CALLED("flash()"))); returnCode(flash());
-}
-
-
-extern int call_flushinp (void);
-int call_flushinp (void)
-{
-	T((T_CALLED("flushinp()"))); returnCode(flushinp());
-}
-
-
-extern chtype call_getbkgd (WINDOW * z);
-chtype call_getbkgd (WINDOW * z)
-{
-	T((T_CALLED("getbkgd(%p)"), z)); returnChar(((z)->_bkgd));
-}
-
-
-extern int call_getch (void);
-int call_getch (void)
-{
-	T((T_CALLED("getch()"))); returnCode(wgetch(stdscr));
-}
-
-
-extern int call_getnstr (char * a1, int z);
-int call_getnstr (char * a1, int z)
-{
-	T((T_CALLED("getnstr(%s,%d)"), _nc_visbuf2(0,a1), z)); returnCode(wgetnstr(stdscr, a1, z));
-}
-
-
-extern int call_getstr (char * z);
-int call_getstr (char * z)
-{
-	T((T_CALLED("getstr(%s)"), _nc_visbuf2(0,z))); returnCode(wgetnstr(stdscr, z, -1));
-}
-
-
-extern WINDOW * call_getwin (FILE * z);
-WINDOW * call_getwin (FILE * z)
-{
-	T((T_CALLED("(%p)"), z)); returnWin(getwin(z));
-}
-
-
-extern int call_halfdelay (int z);
-int call_halfdelay (int z)
-{
-	T((T_CALLED("halfdelay(%d)"), z)); returnCode(halfdelay(z));
-}
-
-
-extern NCURSES_BOOL call_has_colors (void);
-NCURSES_BOOL call_has_colors (void)
-{
-	T((T_CALLED("has_colors()"))); returnBool(has_colors());
-}
-
-
-extern NCURSES_BOOL call_has_ic (void);
-NCURSES_BOOL call_has_ic (void)
-{
-	T((T_CALLED("has_ic()"))); returnBool(has_ic());
-}
-
-
-extern NCURSES_BOOL call_has_il (void);
-NCURSES_BOOL call_has_il (void)
-{
-	T((T_CALLED("has_il()"))); returnBool(has_il());
-}
-
-
-extern int call_hline (chtype a1, int z);
-int call_hline (chtype a1, int z)
-{
-	T((T_CALLED("hline(%s,%d)"), _tracechtype2(0,a1), z)); returnCode(whline(stdscr, a1, z));
-}
-
-
-extern void call_idcok (WINDOW * a1, NCURSES_BOOL z);
-void call_idcok (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("idcok(%p,%#lx)"), a1, (long)z)); idcok(a1, z);
-	returnVoid;
-}
-
-
-extern int call_idlok (WINDOW * a1, NCURSES_BOOL z);
-int call_idlok (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("idlok(%p,%#lx)"), a1, (long)z)); returnCode(idlok(a1, z));
-}
-
-
-extern void call_immedok (WINDOW * a1, NCURSES_BOOL z);
-void call_immedok (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("immedok(%p,%#lx)"), a1, (long)z)); immedok(a1, z);
-	returnVoid;
-}
-
-
-extern chtype call_inch (void);
-chtype call_inch (void)
-{
-	T((T_CALLED("inch()"))); returnChar(winch(stdscr));
-}
-
-
-extern int call_inchnstr (chtype * a1, int z);
-int call_inchnstr (chtype * a1, int z)
-{
-	T((T_CALLED("inchnstr(%p,%d)"), a1, z)); returnCode(winchnstr(stdscr,a1,z));
-}
-
-
-extern int call_inchstr (chtype * z);
-int call_inchstr (chtype * z)
-{
-	T((T_CALLED("inchstr(%p)"), z)); returnCode(winchnstr(stdscr, z, -1));
-}
-
-
-extern WINDOW * call_initscr (void);
-WINDOW * call_initscr (void)
-{
-	T((T_CALLED("()"))); returnWin(initscr());
-}
-
-
-extern int call_init_color (short a1, short a2, short a3, short z);
-int call_init_color (short a1, short a2, short a3, short z)
-{
-	T((T_CALLED("init_color(%d,%d,%d,%d)"), a1, a2, a3, z)); returnCode(init_color(a1, a2, a3, z));
-}
-
-
-extern int call_init_pair (short a1, short a2, short z);
-int call_init_pair (short a1, short a2, short z)
-{
-	T((T_CALLED("init_pair(%d,%d,%d)"), a1, a2, z)); returnCode(init_pair(a1, a2, z));
-}
-
-
-extern int call_innstr (char * a1, int z);
-int call_innstr (char * a1, int z)
-{
-	return winnstr(stdscr,a1,z) ;
-}
-
-
-extern int call_insch (chtype z);
-int call_insch (chtype z)
-{
-	T((T_CALLED("insch(%s)"), _tracechtype2(0,z))); returnCode(winsch(stdscr,z));
-}
-
-
-extern int call_insdelln (int z);
-int call_insdelln (int z)
-{
-	T((T_CALLED("insdelln(%d)"), z)); returnCode(winsdelln(stdscr,z));
-}
-
-
-extern int call_insertln (void);
-int call_insertln (void)
-{
-	T((T_CALLED("insertln()"))); returnCode(winsdelln(stdscr,1));
-}
-
-
-extern int call_insnstr (const char * a1, int z);
-int call_insnstr (const char * a1, int z)
-{
-	T((T_CALLED("insnstr(%s,%d)"), _nc_visbuf2(0,a1), z)); returnCode(winsnstr(stdscr,a1,z));
-}
-
-
-extern int call_insstr (const char * z);
-int call_insstr (const char * z)
-{
-	T((T_CALLED("insstr(%s)"), _nc_visbuf2(0,z))); returnCode(winsnstr(stdscr, z, -1));
-}
-
-
-extern int call_instr (char * z);
-int call_instr (char * z)
-{
-	T((T_CALLED("instr(%s)"), _nc_visbuf2(0,z))); returnCode(winnstr(stdscr, z, -1));
-}
-
-
-extern int call_intrflush (WINDOW * a1, NCURSES_BOOL z);
-int call_intrflush (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("intrflush(%p,%#lx)"), a1, (long)z)); returnCode(intrflush(a1, z));
-}
-
-
-extern NCURSES_BOOL call_isendwin (void);
-NCURSES_BOOL call_isendwin (void)
-{
-	T((T_CALLED("isendwin()"))); returnBool(isendwin());
-}
-
-
-extern NCURSES_BOOL call_is_linetouched (WINDOW * a1, int z);
-NCURSES_BOOL call_is_linetouched (WINDOW * a1, int z)
-{
-	T((T_CALLED("is_linetouched(%p,%d)"), a1, z)); returnBool(is_linetouched(a1, z));
-}
-
-
-extern NCURSES_BOOL call_is_wintouched (WINDOW * z);
-NCURSES_BOOL call_is_wintouched (WINDOW * z)
-{
-	T((T_CALLED("is_wintouched(%p)"), z)); returnBool(is_wintouched(z));
-}
-
-
-extern char * call_keyname (int z);
-char * call_keyname (int z)
-{
-	T((T_CALLED("(%d)"), z)); returnPtr(keyname(z));
-}
-
-
-extern int call_keypad (WINDOW * a1, NCURSES_BOOL z);
-int call_keypad (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("keypad(%p,%#lx)"), a1, (long)z)); returnCode(keypad(a1, z));
-}
-
-
-extern char call_killchar (void);
-char call_killchar (void)
-{
-	T((T_CALLED("killchar()"))); returnCode(killchar());
-}
-
-
-extern int call_leaveok (WINDOW * a1, NCURSES_BOOL z);
-int call_leaveok (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("leaveok(%p,%#lx)"), a1, (long)z)); returnCode(leaveok(a1, z));
-}
-
-
-extern char * call_longname (void);
-char * call_longname (void)
-{
-	T((T_CALLED("()"))); returnPtr(longname());
-}
-
-
-extern int call_meta (WINDOW * a1, NCURSES_BOOL z);
-int call_meta (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("meta(%p,%#lx)"), a1, (long)z)); returnCode(meta(a1, z));
-}
-
-
-extern int call_move (int a1, int z);
-int call_move (int a1, int z)
-{
-	T((T_CALLED("move(%d,%d)"), a1, z)); returnCode(wmove(stdscr,a1,z));
-}
-
-
-extern int call_mvaddch (int a1, int a2, const chtype z);
-int call_mvaddch (int a1, int a2, const chtype z)
-{
-	T((T_CALLED("mvaddch(%d,%d,%s)"), a1, a2, _tracechtype2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddch(stdscr,z)));
-}
-
-
-extern int call_mvaddchnstr (int a1, int a2, const chtype * a3, int z);
-int call_mvaddchnstr (int a1, int a2, const chtype * a3, int z)
-{
-	T((T_CALLED("mvaddchnstr(%d,%d,%p,%d)"), a1, a2, a3, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddchnstr(stdscr,a3,z)));
-}
-
-
-extern int call_mvaddchstr (int a1, int a2, const chtype * z);
-int call_mvaddchstr (int a1, int a2, const chtype * z)
-{
-	T((T_CALLED("mvaddchstr(%d,%d,%p)"), a1, a2, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddchnstr(stdscr,z,-1)));
-}
-
-
-extern int call_mvaddnstr (int a1, int a2, const char * a3, int z);
-int call_mvaddnstr (int a1, int a2, const char * a3, int z)
-{
-	T((T_CALLED("mvaddnstr(%d,%d,%s,%d)"), a1, a2, _nc_visbuf2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddnstr(stdscr,a3,z)));
-}
-
-
-extern int call_mvaddstr (int a1, int a2, const char * z);
-int call_mvaddstr (int a1, int a2, const char * z)
-{
-	T((T_CALLED("mvaddstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : waddnstr(stdscr,z,-1)));
-}
-
-
-extern int call_mvchgat (int a1, int a2, int a3, attr_t a4, short a5, const void * z);
-int call_mvchgat (int a1, int a2, int a3, attr_t a4, short a5, const void * z)
-{
-	T((T_CALLED("mvchgat(%d,%d,%d,%s,%d,%p)"), a1, a2, a3, _traceattr2(3,a4), a5, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wchgat(stdscr,a3,a4,a5,z)));
-}
-
-
-extern int call_mvcur (int a1, int a2, int a3, int z);
-int call_mvcur (int a1, int a2, int a3, int z)
-{
-	T((T_CALLED("mvcur(%d,%d,%d,%d)"), a1, a2, a3, z)); returnCode(mvcur(a1, a2, a3, z));
-}
-
-
-extern int call_mvdelch (int a1, int z);
-int call_mvdelch (int a1, int z)
-{
-	T((T_CALLED("mvdelch(%d,%d)"), a1, z)); returnCode((wmove(stdscr,a1,z) == (-1) ? (-1) : wdelch(stdscr)));
-}
-
-
-extern int call_mvderwin (WINDOW * a1, int a2, int z);
-int call_mvderwin (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvderwin(%p,%d,%d)"), a1, a2, z)); returnCode(mvderwin(a1, a2, z));
-}
-
-
-extern int call_mvgetch (int a1, int z);
-int call_mvgetch (int a1, int z)
-{
-	T((T_CALLED("mvgetch(%d,%d)"), a1, z)); returnCode((wmove(stdscr,a1,z) == (-1) ? (-1) : wgetch(stdscr)));
-}
-
-
-extern int call_mvgetnstr (int a1, int a2, char * a3, int z);
-int call_mvgetnstr (int a1, int a2, char * a3, int z)
-{
-	T((T_CALLED("mvgetnstr(%d,%d,%s,%d)"), a1, a2, _nc_visbuf2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wgetnstr(stdscr,a3,z)));
-}
-
-
-extern int call_mvgetstr (int a1, int a2, char * z);
-int call_mvgetstr (int a1, int a2, char * z)
-{
-	T((T_CALLED("mvgetstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wgetnstr(stdscr, z, -1)));
-}
-
-
-extern int call_mvhline (int a1, int a2, chtype a3, int z);
-int call_mvhline (int a1, int a2, chtype a3, int z)
-{
-	T((T_CALLED("mvhline(%d,%d,%s,%d)"), a1, a2, _tracechtype2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : whline(stdscr,a3,z)));
-}
-
-
-extern chtype call_mvinch (int a1, int z);
-chtype call_mvinch (int a1, int z)
-{
-	T((T_CALLED("mvinch(%d,%d)"), a1, z)); returnChar((wmove(stdscr,a1,z) == (-1) ? (chtype)((-1)) : winch(stdscr)));
-}
-
-
-extern int call_mvinchnstr (int a1, int a2, chtype * a3, int z);
-int call_mvinchnstr (int a1, int a2, chtype * a3, int z)
-{
-	T((T_CALLED("mvinchnstr(%d,%d,%p,%d)"), a1, a2, a3, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winchnstr(stdscr,a3,z)));
-}
-
-
-extern int call_mvinchstr (int a1, int a2, chtype * z);
-int call_mvinchstr (int a1, int a2, chtype * z)
-{
-	T((T_CALLED("mvinchstr(%d,%d,%p)"), a1, a2, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winchnstr(stdscr, z, -1)));
-}
-
-
-extern int call_mvinnstr (int a1, int a2, char * a3, int z);
-int call_mvinnstr (int a1, int a2, char * a3, int z)
-{
-	return (wmove(stdscr,a1,a2) == (-1) ? (-1) : winnstr(stdscr,a3,z)) ;
-}
-
-
-extern int call_mvinsch (int a1, int a2, chtype z);
-int call_mvinsch (int a1, int a2, chtype z)
-{
-	T((T_CALLED("mvinsch(%d,%d,%s)"), a1, a2, _tracechtype2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winsch(stdscr,z)));
-}
-
-
-extern int call_mvinsnstr (int a1, int a2, const char * a3, int z);
-int call_mvinsnstr (int a1, int a2, const char * a3, int z)
-{
-	T((T_CALLED("mvinsnstr(%d,%d,%s,%d)"), a1, a2, _nc_visbuf2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winsnstr(stdscr,a3,z)));
-}
-
-
-extern int call_mvinsstr (int a1, int a2, const char * z);
-int call_mvinsstr (int a1, int a2, const char * z)
-{
-	T((T_CALLED("mvinsstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winsnstr(stdscr, z, -1)));
-}
-
-
-extern int call_mvinstr (int a1, int a2, char * z);
-int call_mvinstr (int a1, int a2, char * z)
-{
-	T((T_CALLED("mvinstr(%d,%d,%s)"), a1, a2, _nc_visbuf2(2,z))); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : winnstr(stdscr, z, -1)));
-}
-
-
-extern int call_mvvline (int a1, int a2, chtype a3, int z);
-int call_mvvline (int a1, int a2, chtype a3, int z)
-{
-	T((T_CALLED("mvvline(%d,%d,%s,%d)"), a1, a2, _tracechtype2(2,a3), z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wvline(stdscr,a3,z)));
-}
-
-
-extern int call_mvwaddch (WINDOW * a1, int a2, int a3, const chtype z);
-int call_mvwaddch (WINDOW * a1, int a2, int a3, const chtype z)
-{
-	T((T_CALLED("mvwaddch(%p,%d,%d,%s)"), a1, a2, a3, _tracechtype2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddch(a1,z)));
-}
-
-
-extern int call_mvwaddchnstr (WINDOW * a1, int a2, int a3, const chtype * a4, int z);
-int call_mvwaddchnstr (WINDOW * a1, int a2, int a3, const chtype * a4, int z)
-{
-	T((T_CALLED("mvwaddchnstr(%p,%d,%d,%p,%d)"), a1, a2, a3, a4, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddchnstr(a1,a4,z)));
-}
-
-
-extern int call_mvwaddchstr (WINDOW * a1, int a2, int a3, const chtype * z);
-int call_mvwaddchstr (WINDOW * a1, int a2, int a3, const chtype * z)
-{
-	T((T_CALLED("mvwaddchstr(%p,%d,%d,%p)"), a1, a2, a3, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddchnstr(a1,z,-1)));
-}
-
-
-extern int call_mvwaddnstr (WINDOW * a1, int a2, int a3, const char * a4, int z);
-int call_mvwaddnstr (WINDOW * a1, int a2, int a3, const char * a4, int z)
-{
-	T((T_CALLED("mvwaddnstr(%p,%d,%d,%s,%d)"), a1, a2, a3, _nc_visbuf2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddnstr(a1,a4,z)));
-}
-
-
-extern int call_mvwaddstr (WINDOW * a1, int a2, int a3, const char * z);
-int call_mvwaddstr (WINDOW * a1, int a2, int a3, const char * z)
-{
-	T((T_CALLED("mvwaddstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : waddnstr(a1,z,-1)));
-}
-
-
-extern int call_mvwchgat (WINDOW * a1, int a2, int a3, int a4, attr_t a5, short a6, const void * z);
-int call_mvwchgat (WINDOW * a1, int a2, int a3, int a4, attr_t a5, short a6, const void * z)
-{
-	T((T_CALLED("mvwchgat(%p,%d,%d,%d,%s,%d,%p)"), a1, a2, a3, a4, _traceattr2(4,a5), a6, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wchgat(a1,a4,a5,a6,z)));
-}
-
-
-extern int call_mvwdelch (WINDOW * a1, int a2, int z);
-int call_mvwdelch (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvwdelch(%p,%d,%d)"), a1, a2, z)); returnCode((wmove(a1,a2,z) == (-1) ? (-1) : wdelch(a1)));
-}
-
-
-extern int call_mvwgetch (WINDOW * a1, int a2, int z);
-int call_mvwgetch (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvwgetch(%p,%d,%d)"), a1, a2, z)); returnCode((wmove(a1,a2,z) == (-1) ? (-1) : wgetch(a1)));
-}
-
-
-extern int call_mvwgetnstr (WINDOW * a1, int a2, int a3, char * a4, int z);
-int call_mvwgetnstr (WINDOW * a1, int a2, int a3, char * a4, int z)
-{
-	T((T_CALLED("mvwgetnstr(%p,%d,%d,%s,%d)"), a1, a2, a3, _nc_visbuf2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wgetnstr(a1,a4,z)));
-}
-
-
-extern int call_mvwgetstr (WINDOW * a1, int a2, int a3, char * z);
-int call_mvwgetstr (WINDOW * a1, int a2, int a3, char * z)
-{
-	T((T_CALLED("mvwgetstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wgetnstr(a1, z, -1)));
-}
-
-
-extern int call_mvwhline (WINDOW * a1, int a2, int a3, chtype a4, int z);
-int call_mvwhline (WINDOW * a1, int a2, int a3, chtype a4, int z)
-{
-	T((T_CALLED("mvwhline(%p,%d,%d,%s,%d)"), a1, a2, a3, _tracechtype2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : whline(a1,a4,z)));
-}
-
-
-extern int call_mvwin (WINDOW * a1, int a2, int z);
-int call_mvwin (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvwin(%p,%d,%d)"), a1, a2, z)); returnCode(mvwin(a1, a2, z));
-}
-
-
-extern chtype call_mvwinch (WINDOW * a1, int a2, int z);
-chtype call_mvwinch (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("mvwinch(%p,%d,%d)"), a1, a2, z)); returnChar((wmove(a1,a2,z) == (-1) ? (chtype)((-1)) : winch(a1)));
-}
-
-
-extern int call_mvwinchnstr (WINDOW * a1, int a2, int a3, chtype * a4, int z);
-int call_mvwinchnstr (WINDOW * a1, int a2, int a3, chtype * a4, int z)
-{
-	T((T_CALLED("mvwinchnstr(%p,%d,%d,%p,%d)"), a1, a2, a3, a4, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winchnstr(a1,a4,z)));
-}
-
-
-extern int call_mvwinchstr (WINDOW * a1, int a2, int a3, chtype * z);
-int call_mvwinchstr (WINDOW * a1, int a2, int a3, chtype * z)
-{
-	T((T_CALLED("mvwinchstr(%p,%d,%d,%p)"), a1, a2, a3, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winchnstr(a1, z, -1)));
-}
-
-
-extern int call_mvwinnstr (WINDOW * a1, int a2, int a3, char * a4, int z);
-int call_mvwinnstr (WINDOW * a1, int a2, int a3, char * a4, int z)
-{
-	return (wmove(a1,a2,a3) == (-1) ? (-1) : winnstr(a1,a4,z)) ;
-}
-
-
-extern int call_mvwinsch (WINDOW * a1, int a2, int a3, chtype z);
-int call_mvwinsch (WINDOW * a1, int a2, int a3, chtype z)
-{
-	T((T_CALLED("mvwinsch(%p,%d,%d,%s)"), a1, a2, a3, _tracechtype2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winsch(a1,z)));
-}
-
-
-extern int call_mvwinsnstr (WINDOW * a1, int a2, int a3, const char * a4, int z);
-int call_mvwinsnstr (WINDOW * a1, int a2, int a3, const char * a4, int z)
-{
-	T((T_CALLED("mvwinsnstr(%p,%d,%d,%s,%d)"), a1, a2, a3, _nc_visbuf2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winsnstr(a1,a4,z)));
-}
-
-
-extern int call_mvwinsstr (WINDOW * a1, int a2, int a3, const char * z);
-int call_mvwinsstr (WINDOW * a1, int a2, int a3, const char * z)
-{
-	T((T_CALLED("mvwinsstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winsnstr(a1, z, -1)));
-}
-
-
-extern int call_mvwinstr (WINDOW * a1, int a2, int a3, char * z);
-int call_mvwinstr (WINDOW * a1, int a2, int a3, char * z)
-{
-	T((T_CALLED("mvwinstr(%p,%d,%d,%s)"), a1, a2, a3, _nc_visbuf2(3,z))); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : winnstr(a1, z, -1)));
-}
-
-
-extern int call_mvwvline (WINDOW * a1, int a2, int a3, chtype a4, int z);
-int call_mvwvline (WINDOW * a1, int a2, int a3, chtype a4, int z)
-{
-	T((T_CALLED("mvwvline(%p,%d,%d,%s,%d)"), a1, a2, a3, _tracechtype2(3,a4), z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wvline(a1,a4,z)));
-}
-
-
-extern int call_napms (int z);
-int call_napms (int z)
-{
-	T((T_CALLED("napms(%d)"), z)); returnCode(napms(z));
-}
-
-
-extern WINDOW * call_newpad (int a1, int z);
-WINDOW * call_newpad (int a1, int z)
-{
-	T((T_CALLED("(%d,%d)"), a1, z)); returnWin(newpad(a1, z));
-}
-
-
-extern SCREEN * call_newterm (char * a1, FILE * a2, FILE * z);
-SCREEN * call_newterm (char * a1, FILE * a2, FILE * z)
-{
-	T((T_CALLED("(%s,%p,%p)"), _nc_visbuf2(0,a1), a2, z)); returnSP(newterm(a1, a2, z));
-}
-
-
-extern WINDOW * call_newwin (int a1, int a2, int a3, int z);
-WINDOW * call_newwin (int a1, int a2, int a3, int z)
-{
-	T((T_CALLED("(%d,%d,%d,%d)"), a1, a2, a3, z)); returnWin(newwin(a1, a2, a3, z));
-}
-
-
-extern int call_nl (void);
-int call_nl (void)
-{
-	T((T_CALLED("nl()"))); returnCode(nl());
-}
-
-
-extern int call_nocbreak (void);
-int call_nocbreak (void)
-{
-	T((T_CALLED("nocbreak()"))); returnCode(nocbreak());
-}
-
-
-extern int call_nodelay (WINDOW * a1, NCURSES_BOOL z);
-int call_nodelay (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("nodelay(%p,%#lx)"), a1, (long)z)); returnCode(nodelay(a1, z));
-}
-
-
-extern int call_noecho (void);
-int call_noecho (void)
-{
-	T((T_CALLED("noecho()"))); returnCode(noecho());
-}
-
-
-extern int call_nonl (void);
-int call_nonl (void)
-{
-	T((T_CALLED("nonl()"))); returnCode(nonl());
-}
-
-
-extern void call_noqiflush (void);
-void call_noqiflush (void)
-{
-	T((T_CALLED("noqiflush()"))); noqiflush();
-	returnVoid;
-}
-
-
-extern int call_noraw (void);
-int call_noraw (void)
-{
-	T((T_CALLED("noraw()"))); returnCode(noraw());
-}
-
-
-extern int call_notimeout (WINDOW * a1, NCURSES_BOOL z);
-int call_notimeout (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("notimeout(%p,%#lx)"), a1, (long)z)); returnCode(notimeout(a1, z));
-}
-
-
-extern int call_overlay (const WINDOW * a1, WINDOW * z);
-int call_overlay (const WINDOW * a1, WINDOW * z)
-{
-	T((T_CALLED("overlay(%p,%p)"), a1, z)); returnCode(overlay(a1, z));
-}
-
-
-extern int call_overwrite (const WINDOW * a1, WINDOW * z);
-int call_overwrite (const WINDOW * a1, WINDOW * z)
-{
-	T((T_CALLED("overwrite(%p,%p)"), a1, z)); returnCode(overwrite(a1, z));
-}
-
-
-extern int call_pair_content (short a1, short * a2, short * z);
-int call_pair_content (short a1, short * a2, short * z)
-{
-	T((T_CALLED("pair_content(%d,%p,%p)"), a1, a2, z)); returnCode(pair_content(a1, a2, z));
-}
-
-
-extern int call_PAIR_NUMBER (int z);
-int call_PAIR_NUMBER (int z)
-{
-	T((T_CALLED("PAIR_NUMBER(%d)"), z)); returnCode(((int)((((z) & ((((1UL) << 8) - 1UL) << ((0) + 8))) >> 8))));
-}
-
-
-extern int call_pechochar (WINDOW * a1, const chtype z);
-int call_pechochar (WINDOW * a1, const chtype z)
-{
-	T((T_CALLED("pechochar(%p,%s)"), a1, _tracechtype2(1,z))); returnCode(pechochar(a1, z));
-}
-
-
-extern int call_pnoutrefresh (WINDOW * a1, int a2, int a3, int a4, int a5, int a6, int z);
-int call_pnoutrefresh (WINDOW * a1, int a2, int a3, int a4, int a5, int a6, int z)
-{
-	T((T_CALLED("pnoutrefresh(%p,%d,%d,%d,%d,%d,%d)"), a1, a2, a3, a4, a5, a6, z)); returnCode(pnoutrefresh(a1, a2, a3, a4, a5, a6, z));
-}
-
-
-extern int call_prefresh (WINDOW * a1, int a2, int a3, int a4, int a5, int a6, int z);
-int call_prefresh (WINDOW * a1, int a2, int a3, int a4, int a5, int a6, int z)
-{
-	T((T_CALLED("prefresh(%p,%d,%d,%d,%d,%d,%d)"), a1, a2, a3, a4, a5, a6, z)); returnCode(prefresh(a1, a2, a3, a4, a5, a6, z));
-}
-
-
-extern int call_putwin (WINDOW * a1, FILE * z);
-int call_putwin (WINDOW * a1, FILE * z)
-{
-	T((T_CALLED("putwin(%p,%p)"), a1, z)); returnCode(putwin(a1, z));
-}
-
-
-extern void call_qiflush (void);
-void call_qiflush (void)
-{
-	T((T_CALLED("qiflush()"))); qiflush();
-	returnVoid;
-}
-
-
-extern int call_raw (void);
-int call_raw (void)
-{
-	T((T_CALLED("raw()"))); returnCode(raw());
-}
-
-
-extern int call_redrawwin (WINDOW * z);
-int call_redrawwin (WINDOW * z)
-{
-	T((T_CALLED("redrawwin(%p)"), z)); returnCode(wredrawln(z, 0, (z)->_maxy+1));
-}
-
-
-extern int call_refresh (void);
-int call_refresh (void)
-{
-	T((T_CALLED("refresh()"))); returnCode(wrefresh(stdscr));
-}
-
-
-extern int call_resetty (void);
-int call_resetty (void)
-{
-	T((T_CALLED("resetty()"))); returnCode(resetty());
-}
-
-
-extern int call_reset_prog_mode (void);
-int call_reset_prog_mode (void)
-{
-	T((T_CALLED("reset_prog_mode()"))); returnCode(reset_prog_mode());
-}
-
-
-extern int call_reset_shell_mode (void);
-int call_reset_shell_mode (void)
-{
-	T((T_CALLED("reset_shell_mode()"))); returnCode(reset_shell_mode());
-}
-
-
-extern int call_ripoffline (int a1, int(* z)(WINDOW * a2, int));
-int call_ripoffline (int a1, int(* z)(WINDOW * a2, int))
-{
-	return ripoffline(a1, z) ;
-}
-
-
-extern int call_savetty (void);
-int call_savetty (void)
-{
-	T((T_CALLED("savetty()"))); returnCode(savetty());
-}
-
-
-extern int call_scr_dump (const char * z);
-int call_scr_dump (const char * z)
-{
-	T((T_CALLED("scr_dump(%s)"), _nc_visbuf2(0,z))); returnCode(scr_dump(z));
-}
-
-
-extern int call_scr_init (const char * z);
-int call_scr_init (const char * z)
-{
-	T((T_CALLED("scr_init(%s)"), _nc_visbuf2(0,z))); returnCode(scr_init(z));
-}
-
-
-extern int call_scrl (int z);
-int call_scrl (int z)
-{
-	T((T_CALLED("scrl(%d)"), z)); returnCode(wscrl(stdscr,z));
-}
-
-
-extern int call_scroll (WINDOW * z);
-int call_scroll (WINDOW * z)
-{
-	T((T_CALLED("scroll(%p)"), z)); returnCode(wscrl(z,1));
-}
-
-
-extern int call_scrollok (WINDOW * a1, NCURSES_BOOL z);
-int call_scrollok (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("scrollok(%p,%#lx)"), a1, (long)z)); returnCode(scrollok(a1, z));
-}
-
-
-extern int call_scr_restore (const char * z);
-int call_scr_restore (const char * z)
-{
-	T((T_CALLED("scr_restore(%s)"), _nc_visbuf2(0,z))); returnCode(scr_restore(z));
-}
-
-
-extern int call_scr_set (const char * z);
-int call_scr_set (const char * z)
-{
-	T((T_CALLED("scr_set(%s)"), _nc_visbuf2(0,z))); returnCode(scr_set(z));
-}
-
-
-extern int call_setscrreg (int a1, int z);
-int call_setscrreg (int a1, int z)
-{
-	T((T_CALLED("setscrreg(%d,%d)"), a1, z)); returnCode(wsetscrreg(stdscr,a1,z));
-}
-
-
-extern SCREEN * call_set_term (SCREEN * z);
-SCREEN * call_set_term (SCREEN * z)
-{
-	T((T_CALLED("(%p)"), z)); returnSP(set_term(z));
-}
-
-
-extern int call_slk_attroff (const chtype z);
-int call_slk_attroff (const chtype z)
-{
-	T((T_CALLED("slk_attroff(%s)"), _tracechtype2(0,z))); returnCode(slk_attroff(z));
-}
-
-
-#if USE_WIDEC_SUPPORT
-extern int call_slk_attr_off (const attr_t a1, void * z);
-int call_slk_attr_off (const attr_t a1, void * z)
-{
-	T((T_CALLED("slk_attr_off(%s,%p)"), _traceattr2(0,a1), z)); returnCode(((z) ? (-1) : slk_attroff(a1)));
-}
-#endif
-
-
-extern int call_slk_attron (const chtype z);
-int call_slk_attron (const chtype z)
-{
-	T((T_CALLED("slk_attron(%s)"), _tracechtype2(0,z))); returnCode(slk_attron(z));
-}
-
-
-#if USE_WIDEC_SUPPORT
-extern int call_slk_attr_on (attr_t a1, void * z);
-int call_slk_attr_on (attr_t a1, void * z)
-{
-	T((T_CALLED("slk_attr_on(%s,%p)"), _traceattr2(0,a1), z)); returnCode(((z) ? (-1) : slk_attron(a1)));
-}
-#endif
-
-
-extern int call_slk_attrset (const chtype z);
-int call_slk_attrset (const chtype z)
-{
-	T((T_CALLED("slk_attrset(%s)"), _tracechtype2(0,z))); returnCode(slk_attrset(z));
-}
-
-
-extern attr_t call_slk_attr (void);
-attr_t call_slk_attr (void)
-{
-	T((T_CALLED("slk_attr()"))); returnAttr(slk_attr());
-}
-
-
-extern int call_slk_attr_set (const attr_t a1, short a2, void * z);
-int call_slk_attr_set (const attr_t a1, short a2, void * z)
-{
-	T((T_CALLED("slk_attr_set(%s,%d,%p)"), _traceattr2(0,a1), a2, z)); returnCode(slk_attr_set(a1, a2, z));
-}
-
-
-extern int call_slk_clear (void);
-int call_slk_clear (void)
-{
-	T((T_CALLED("slk_clear()"))); returnCode(slk_clear());
-}
-
-
-extern int call_slk_color (short z);
-int call_slk_color (short z)
-{
-	T((T_CALLED("slk_color(%d)"), z)); returnCode(slk_color(z));
-}
-
-
-extern int call_slk_init (int z);
-int call_slk_init (int z)
-{
-	T((T_CALLED("slk_init(%d)"), z)); returnCode(slk_init(z));
-}
-
-
-extern char * call_slk_label (int z);
-char * call_slk_label (int z)
-{
-	T((T_CALLED("(%d)"), z)); returnPtr(slk_label(z));
-}
-
-
-extern int call_slk_noutrefresh (void);
-int call_slk_noutrefresh (void)
-{
-	T((T_CALLED("slk_noutrefresh()"))); returnCode(slk_noutrefresh());
-}
-
-
-extern int call_slk_refresh (void);
-int call_slk_refresh (void)
-{
-	T((T_CALLED("slk_refresh()"))); returnCode(slk_refresh());
-}
-
-
-extern int call_slk_restore (void);
-int call_slk_restore (void)
-{
-	T((T_CALLED("slk_restore()"))); returnCode(slk_restore());
-}
-
-
-extern int call_slk_set (int a1, const char * a2, int z);
-int call_slk_set (int a1, const char * a2, int z)
-{
-	T((T_CALLED("slk_set(%d,%s,%d)"), a1, _nc_visbuf2(1,a2), z)); returnCode(slk_set(a1, a2, z));
-}
-
-
-extern int call_slk_touch (void);
-int call_slk_touch (void)
-{
-	T((T_CALLED("slk_touch()"))); returnCode(slk_touch());
-}
-
-
-extern int call_standout (void);
-int call_standout (void)
-{
-	T((T_CALLED("standout()"))); returnAttr((((stdscr)->_attrs = (((1UL) << ((8) + 8))))));
-}
-
-
-extern int call_standend (void);
-int call_standend (void)
-{
-	T((T_CALLED("standend()"))); returnAttr((((stdscr)->_attrs = ((1UL - 1UL)))));
-}
-
-
-extern int call_start_color (void);
-int call_start_color (void)
-{
-	T((T_CALLED("start_color()"))); returnCode(start_color());
-}
-
-
-extern WINDOW * call_subpad (WINDOW * a1, int a2, int a3, int a4, int z);
-WINDOW * call_subpad (WINDOW * a1, int a2, int a3, int a4, int z)
-{
-	T((T_CALLED("(%p,%d,%d,%d,%d)"), a1, a2, a3, a4, z)); returnWin(subpad(a1, a2, a3, a4, z));
-}
-
-
-extern WINDOW * call_subwin (WINDOW * a1, int a2, int a3, int a4, int z);
-WINDOW * call_subwin (WINDOW * a1, int a2, int a3, int a4, int z)
-{
-	T((T_CALLED("(%p,%d,%d,%d,%d)"), a1, a2, a3, a4, z)); returnWin(subwin(a1, a2, a3, a4, z));
-}
-
-
-extern int call_syncok (WINDOW * a1, NCURSES_BOOL z);
-int call_syncok (WINDOW * a1, NCURSES_BOOL z)
-{
-	T((T_CALLED("syncok(%p,%#lx)"), a1, (long)z)); returnCode(syncok(a1, z));
-}
-
-
-extern chtype call_termattrs (void);
-chtype call_termattrs (void)
-{
-	T((T_CALLED("termattrs()"))); returnChar(termattrs());
-}
-
-
-extern char * call_termname (void);
-char * call_termname (void)
-{
-	T((T_CALLED("()"))); returnPtr(termname());
-}
-
-
-extern void call_timeout (int z);
-void call_timeout (int z)
-{
-	T((T_CALLED("timeout(%d)"), z)); wtimeout(stdscr,z);
-	returnVoid;
-}
-
-
-extern int call_touchline (WINDOW * a1, int a2, int z);
-int call_touchline (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("touchline(%p,%d,%d)"), a1, a2, z)); returnCode(wtouchln((a1), a2, z, 1));
-}
-
-
-extern int call_touchwin (WINDOW * z);
-int call_touchwin (WINDOW * z)
-{
-	T((T_CALLED("touchwin(%p)"), z)); returnCode(wtouchln((z), 0, ((z) ? ((z)->_maxy + 1) : (-1)), 1));
-}
-
-
-extern int call_typeahead (int z);
-int call_typeahead (int z)
-{
-	T((T_CALLED("typeahead(%d)"), z)); returnCode(typeahead(z));
-}
-
-
-extern int call_ungetch (int z);
-int call_ungetch (int z)
-{
-	T((T_CALLED("ungetch(%d)"), z)); returnCode(ungetch(z));
-}
-
-
-extern int call_untouchwin (WINDOW * z);
-int call_untouchwin (WINDOW * z)
-{
-	T((T_CALLED("untouchwin(%p)"), z)); returnCode(wtouchln((z), 0, ((z) ? ((z)->_maxy + 1) : (-1)), 0));
-}
-
-
-extern void call_use_env (NCURSES_BOOL z);
-void call_use_env (NCURSES_BOOL z)
-{
-	T((T_CALLED("use_env(%#lx)"), (long)z)); use_env(z);
-	returnVoid;
-}
-
-
-extern int call_vidattr (chtype z);
-int call_vidattr (chtype z)
-{
-	T((T_CALLED("vidattr(%s)"), _tracechtype2(0,z))); returnCode(vidattr(z));
-}
-
-
-extern int call_vidputs (chtype a1, int(* z)(int));
-int call_vidputs (chtype a1, int(* z)(int))
-{
-	T((T_CALLED("vidputs(%s,"), _tracechtype2(0,a1))); returnCode(vidputs(a1, z));
-}
-
-
-extern int call_vline (chtype a1, int z);
-int call_vline (chtype a1, int z)
-{
-	T((T_CALLED("vline(%s,%d)"), _tracechtype2(0,a1), z)); returnCode(wvline(stdscr, a1, z));
-}
-
-
-extern int call_vwprintw (WINDOW * a1, const char * a2, va_list z);
-int call_vwprintw (WINDOW * a1, const char * a2, va_list z)
-{
-	T((T_CALLED("vwprintw(%p,%s,%s)"), a1, _nc_visbuf2(1,a2), "va_list")); returnCode(vwprintw(a1, a2, z));
-}
-
-
-extern int call_vw_printw (WINDOW * a1, const char * a2, va_list z);
-int call_vw_printw (WINDOW * a1, const char * a2, va_list z)
-{
-	T((T_CALLED("vw_printw(%p,%s,%s)"), a1, _nc_visbuf2(1,a2), "va_list")); returnCode(vwprintw(a1, a2, z));
-}
-
-
-extern int call_vwscanw (WINDOW * a1, char * a2, va_list z);
-int call_vwscanw (WINDOW * a1, char * a2, va_list z)
-{
-	T((T_CALLED("vwscanw(%p,%s,%s)"), a1, _nc_visbuf2(1,a2), "va_list")); returnCode(vwscanw(a1, a2, z));
-}
-
-
-extern int call_vw_scanw (WINDOW * a1, char * a2, va_list z);
-int call_vw_scanw (WINDOW * a1, char * a2, va_list z)
-{
-	T((T_CALLED("vw_scanw(%p,%s,%s)"), a1, _nc_visbuf2(1,a2), "va_list")); returnCode(vwscanw(a1, a2, z));
-}
-
-
-extern int call_waddch (WINDOW * a1, const chtype z);
-int call_waddch (WINDOW * a1, const chtype z)
-{
-	T((T_CALLED("waddch(%p,%s)"), a1, _tracechtype2(1,z))); returnCode(waddch(a1, z));
-}
-
-
-extern int call_waddchnstr (WINDOW * a1, const chtype * a2, int z);
-int call_waddchnstr (WINDOW * a1, const chtype * a2, int z)
-{
-	T((T_CALLED("waddchnstr(%p,%p,%d)"), a1, a2, z)); returnCode(waddchnstr(a1, a2, z));
-}
-
-
-extern int call_waddchstr (WINDOW * a1, const chtype * z);
-int call_waddchstr (WINDOW * a1, const chtype * z)
-{
-	T((T_CALLED("waddchstr(%p,%p)"), a1, z)); returnCode(waddchnstr(a1,z,-1));
-}
-
-
-extern int call_waddnstr (WINDOW * a1, const char * a2, int z);
-int call_waddnstr (WINDOW * a1, const char * a2, int z)
-{
-	T((T_CALLED("waddnstr(%p,%s,%d)"), a1, _nc_visbuf2(1,a2), z)); returnCode(waddnstr(a1, a2, z));
-}
-
-
-extern int call_waddstr (WINDOW * a1, const char * z);
-int call_waddstr (WINDOW * a1, const char * z)
-{
-	T((T_CALLED("waddstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(waddnstr(a1,z,-1));
-}
-
-
-extern int call_wattron (WINDOW * a1, int z);
-int call_wattron (WINDOW * a1, int z)
-{
-	T((T_CALLED("wattron(%p,%d)"), a1, z)); returnCode(wattr_on(a1, (attr_t)(z), ((void *)0)));
-}
-
-
-extern int call_wattroff (WINDOW * a1, int z);
-int call_wattroff (WINDOW * a1, int z)
-{
-	T((T_CALLED("wattroff(%p,%d)"), a1, z)); returnCode(wattr_off(a1, (attr_t)(z), ((void *)0)));
-}
-
-
-extern int call_wattrset (WINDOW * a1, int z);
-int call_wattrset (WINDOW * a1, int z)
-{
-	T((T_CALLED("wattrset(%p,%d)"), a1, z)); returnAttr(((a1)->_attrs = (z)));
-}
-
-
-extern int call_wattr_get (WINDOW * a1, attr_t * a2, short * a3, void * z);
-int call_wattr_get (WINDOW * a1, attr_t * a2, short * a3, void * z)
-{
-	T((T_CALLED("wattr_get(%p,%p,%p,%p)"), a1, a2, a3, z)); returnCode(((void)((a2) != (void *)0 && (*(a2) = (a1)->_attrs)), (void)((a3) != (void *)0 && (*(a3) = ((int)(((((a1)->_attrs) & ((((1UL) << 8) - 1UL) << ((0) + 8))) >> 8))))), (0)));
-}
-
-
-extern int call_wattr_on (WINDOW * a1, attr_t a2, void * z);
-int call_wattr_on (WINDOW * a1, attr_t a2, void * z)
-{
-	T((T_CALLED("wattr_on(%p,%s,%p)"), a1, _traceattr2(1,a2), z)); returnCode(wattr_on(a1, a2, z));
-}
-
-
-extern int call_wattr_off (WINDOW * a1, attr_t a2, void * z);
-int call_wattr_off (WINDOW * a1, attr_t a2, void * z)
-{
-	T((T_CALLED("wattr_off(%p,%s,%p)"), a1, _traceattr2(1,a2), z)); returnCode(wattr_off(a1, a2, z));
-}
-
-
-extern int call_wattr_set (WINDOW * a1, attr_t a2, short a3, void * z);
-int call_wattr_set (WINDOW * a1, attr_t a2, short a3, void * z)
-{
-	T((T_CALLED("wattr_set(%p,%s,%d,%p)"), a1, _traceattr2(1,a2), a3, z)); returnCode(((a1)->_attrs = (((a2) & ~((((1UL) << 8) - 1UL) << ((0) + 8))) | ((a3) << ((0) + 8))), (0)));
-}
-
-
-extern int call_wbkgd (WINDOW * a1, chtype z);
-int call_wbkgd (WINDOW * a1, chtype z)
-{
-	T((T_CALLED("wbkgd(%p,%s)"), a1, _tracechtype2(1,z))); returnCode(wbkgd(a1, z));
-}
-
-
-extern void call_wbkgdset (WINDOW * a1, chtype z);
-void call_wbkgdset (WINDOW * a1, chtype z)
-{
-	T((T_CALLED("wbkgdset(%p,%s)"), a1, _tracechtype2(1,z))); wbkgdset(a1, z);
-	returnVoid;
-}
-
-
-extern int call_wborder (WINDOW * a1, chtype a2, chtype a3, chtype a4, chtype a5, chtype a6, chtype a7, chtype a8, chtype z);
-int call_wborder (WINDOW * a1, chtype a2, chtype a3, chtype a4, chtype a5, chtype a6, chtype a7, chtype a8, chtype z)
-{
-	T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"), a1, _tracechtype2(1,a2), _tracechtype2(2,a3), _tracechtype2(3,a4), _tracechtype2(4,a5), _tracechtype2(5,a6), _tracechtype2(6,a7), _tracechtype2(7,a8), _tracechtype2(8,z))); returnCode(wborder(a1, a2, a3, a4, a5, a6, a7, a8, z));
-}
-
-
-extern int call_wchgat (WINDOW * a1, int a2, attr_t a3, short a4, const void * z);
-int call_wchgat (WINDOW * a1, int a2, attr_t a3, short a4, const void * z)
-{
-	T((T_CALLED("wchgat(%p,%d,%s,%d,%p)"), a1, a2, _traceattr2(2,a3), a4, z)); returnCode(wchgat(a1, a2, a3, a4, z));
-}
-
-
-extern int call_wclear (WINDOW * z);
-int call_wclear (WINDOW * z)
-{
-	T((T_CALLED("wclear(%p)"), z)); returnCode(wclear(z));
-}
-
-
-extern int call_wclrtobot (WINDOW * z);
-int call_wclrtobot (WINDOW * z)
-{
-	T((T_CALLED("wclrtobot(%p)"), z)); returnCode(wclrtobot(z));
-}
-
-
-extern int call_wclrtoeol (WINDOW * z);
-int call_wclrtoeol (WINDOW * z)
-{
-	T((T_CALLED("wclrtoeol(%p)"), z)); returnCode(wclrtoeol(z));
-}
-
-
-extern int call_wcolor_set (WINDOW * a1, short a2, void * z);
-int call_wcolor_set (WINDOW * a1, short a2, void * z)
-{
-	T((T_CALLED("wcolor_set(%p,%d,%p)"), a1, a2, z)); returnCode(wcolor_set(a1, a2, z));
-}
-
-
-extern void call_wcursyncup (WINDOW * z);
-void call_wcursyncup (WINDOW * z)
-{
-	T((T_CALLED("wcursyncup(%p)"), z)); wcursyncup(z);
-	returnVoid;
-}
-
-
-extern int call_wdelch (WINDOW * z);
-int call_wdelch (WINDOW * z)
-{
-	T((T_CALLED("wdelch(%p)"), z)); returnCode(wdelch(z));
-}
-
-
-extern int call_wdeleteln (WINDOW * z);
-int call_wdeleteln (WINDOW * z)
-{
-	T((T_CALLED("wdeleteln(%p)"), z)); returnCode(winsdelln(z,-1));
-}
-
-
-extern int call_wechochar (WINDOW * a1, const chtype z);
-int call_wechochar (WINDOW * a1, const chtype z)
-{
-	T((T_CALLED("wechochar(%p,%s)"), a1, _tracechtype2(1,z))); returnCode(wechochar(a1, z));
-}
-
-
-extern int call_werase (WINDOW * z);
-int call_werase (WINDOW * z)
-{
-	T((T_CALLED("werase(%p)"), z)); returnCode(werase(z));
-}
-
-
-extern int call_wgetch (WINDOW * z);
-int call_wgetch (WINDOW * z)
-{
-	T((T_CALLED("wgetch(%p)"), z)); returnCode(wgetch(z));
-}
-
-
-extern int call_wgetnstr (WINDOW * a1, char * a2, int z);
-int call_wgetnstr (WINDOW * a1, char * a2, int z)
-{
-	T((T_CALLED("wgetnstr(%p,%s,%d)"), a1, _nc_visbuf2(1,a2), z)); returnCode(wgetnstr(a1, a2, z));
-}
-
-
-extern int call_wgetstr (WINDOW * a1, char * z);
-int call_wgetstr (WINDOW * a1, char * z)
-{
-	T((T_CALLED("wgetstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(wgetnstr(a1, z, -1));
-}
-
-
-extern int call_whline (WINDOW * a1, chtype a2, int z);
-int call_whline (WINDOW * a1, chtype a2, int z)
-{
-	T((T_CALLED("whline(%p,%s,%d)"), a1, _tracechtype2(1,a2), z)); returnCode(whline(a1, a2, z));
-}
-
-
-extern chtype call_winch (WINDOW * z);
-chtype call_winch (WINDOW * z)
-{
-	T((T_CALLED("winch(%p)"), z)); returnChar(winch(z));
-}
-
-
-extern int call_winchnstr (WINDOW * a1, chtype * a2, int z);
-int call_winchnstr (WINDOW * a1, chtype * a2, int z)
-{
-	T((T_CALLED("winchnstr(%p,%p,%d)"), a1, a2, z)); returnCode(winchnstr(a1, a2, z));
-}
-
-
-extern int call_winchstr (WINDOW * a1, chtype * z);
-int call_winchstr (WINDOW * a1, chtype * z)
-{
-	T((T_CALLED("winchstr(%p,%p)"), a1, z)); returnCode(winchnstr(a1, z, -1));
-}
-
-
-extern int call_winnstr (WINDOW * a1, char * a2, int z);
-int call_winnstr (WINDOW * a1, char * a2, int z)
-{
-	return winnstr(a1, a2, z) ;
-}
-
-
-extern int call_winsch (WINDOW * a1, chtype z);
-int call_winsch (WINDOW * a1, chtype z)
-{
-	T((T_CALLED("winsch(%p,%s)"), a1, _tracechtype2(1,z))); returnCode(winsch(a1, z));
-}
-
-
-extern int call_winsdelln (WINDOW * a1, int z);
-int call_winsdelln (WINDOW * a1, int z)
-{
-	T((T_CALLED("winsdelln(%p,%d)"), a1, z)); returnCode(winsdelln(a1, z));
-}
-
-
-extern int call_winsertln (WINDOW * z);
-int call_winsertln (WINDOW * z)
-{
-	T((T_CALLED("winsertln(%p)"), z)); returnCode(winsdelln(z,1));
-}
-
-
-extern int call_winsnstr (WINDOW * a1, const char * a2, int z);
-int call_winsnstr (WINDOW * a1, const char * a2, int z)
-{
-	T((T_CALLED("winsnstr(%p,%s,%d)"), a1, _nc_visbuf2(1,a2), z)); returnCode(winsnstr(a1, a2, z));
-}
-
-
-extern int call_winsstr (WINDOW * a1, const char * z);
-int call_winsstr (WINDOW * a1, const char * z)
-{
-	T((T_CALLED("winsstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(winsnstr(a1, z, -1));
-}
-
-
-extern int call_winstr (WINDOW * a1, char * z);
-int call_winstr (WINDOW * a1, char * z)
-{
-	T((T_CALLED("winstr(%p,%s)"), a1, _nc_visbuf2(1,z))); returnCode(winnstr(a1, z, -1));
-}
-
-
-extern int call_wmove (WINDOW * a1, int a2, int z);
-int call_wmove (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("wmove(%p,%d,%d)"), a1, a2, z)); returnCode(wmove(a1, a2, z));
-}
-
-
-extern int call_wnoutrefresh (WINDOW * z);
-int call_wnoutrefresh (WINDOW * z)
-{
-	T((T_CALLED("wnoutrefresh(%p)"), z)); returnCode(wnoutrefresh(z));
-}
-
-
-extern int call_wredrawln (WINDOW * a1, int a2, int z);
-int call_wredrawln (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("wredrawln(%p,%d,%d)"), a1, a2, z)); returnCode(wredrawln(a1, a2, z));
-}
-
-
-extern int call_wrefresh (WINDOW * z);
-int call_wrefresh (WINDOW * z)
-{
-	T((T_CALLED("wrefresh(%p)"), z)); returnCode(wrefresh(z));
-}
-
-
-extern int call_wscrl (WINDOW * a1, int z);
-int call_wscrl (WINDOW * a1, int z)
-{
-	T((T_CALLED("wscrl(%p,%d)"), a1, z)); returnCode(wscrl(a1, z));
-}
-
-
-extern int call_wsetscrreg (WINDOW * a1, int a2, int z);
-int call_wsetscrreg (WINDOW * a1, int a2, int z)
-{
-	T((T_CALLED("wsetscrreg(%p,%d,%d)"), a1, a2, z)); returnCode(wsetscrreg(a1, a2, z));
-}
-
-
-extern int call_wstandout (WINDOW * z);
-int call_wstandout (WINDOW * z)
-{
-	T((T_CALLED("wstandout(%p)"), z)); returnAttr((((z)->_attrs = (((1UL) << ((8) + 8))))));
-}
-
-
-extern int call_wstandend (WINDOW * z);
-int call_wstandend (WINDOW * z)
-{
-	T((T_CALLED("wstandend(%p)"), z)); returnAttr((((z)->_attrs = ((1UL - 1UL)))));
-}
-
-
-extern void call_wsyncdown (WINDOW * z);
-void call_wsyncdown (WINDOW * z)
-{
-	T((T_CALLED("wsyncdown(%p)"), z)); wsyncdown(z);
-	returnVoid;
-}
-
-
-extern void call_wsyncup (WINDOW * z);
-void call_wsyncup (WINDOW * z)
-{
-	T((T_CALLED("wsyncup(%p)"), z)); wsyncup(z);
-	returnVoid;
-}
-
-
-extern void call_wtimeout (WINDOW * a1, int z);
-void call_wtimeout (WINDOW * a1, int z)
-{
-	T((T_CALLED("wtimeout(%p,%d)"), a1, z)); wtimeout(a1, z);
-	returnVoid;
-}
-
-
-extern int call_wtouchln (WINDOW * a1, int a2, int a3, int z);
-int call_wtouchln (WINDOW * a1, int a2, int a3, int z)
-{
-	T((T_CALLED("wtouchln(%p,%d,%d,%d)"), a1, a2, a3, z)); returnCode(wtouchln(a1, a2, a3, z));
-}
-
-
-extern int call_wvline (WINDOW * a1, chtype a2, int z);
-int call_wvline (WINDOW * a1, chtype a2, int z)
-{
-	T((T_CALLED("wvline(%p,%s,%d)"), a1, _tracechtype2(1,a2), z)); returnCode(wvline(a1, a2, z));
-}
-
-
-extern int call_tigetflag (char * z);
-int call_tigetflag (char * z)
-{
-	T((T_CALLED("tigetflag(%s)"), _nc_visbuf2(0,z))); returnCode(tigetflag(z));
-}
-
-
-extern int call_tigetnum (char * z);
-int call_tigetnum (char * z)
-{
-	T((T_CALLED("tigetnum(%s)"), _nc_visbuf2(0,z))); returnCode(tigetnum(z));
-}
-
-
-extern char * call_tigetstr (char * z);
-char * call_tigetstr (char * z)
-{
-	T((T_CALLED("(%s)"), _nc_visbuf2(0,z))); returnPtr(tigetstr(z));
-}
-
-
-extern int call_putp (const char * z);
-int call_putp (const char * z)
-{
-	T((T_CALLED("putp(%s)"), _nc_visbuf2(0,z))); returnCode(putp(z));
-}
-
-
-extern int call_getattrs (const WINDOW * z);
-int call_getattrs (const WINDOW * z)
-{
-	T((T_CALLED("getattrs(%p)"), z)); returnCode(((z) ? (z)->_attrs : (1UL - 1UL)));
-}
-
-
-extern int call_getcurx (const WINDOW * z);
-int call_getcurx (const WINDOW * z)
-{
-	T((T_CALLED("getcurx(%p)"), z)); returnCode(((z) ? (z)->_curx : (-1)));
-}
-
-
-extern int call_getcury (const WINDOW * z);
-int call_getcury (const WINDOW * z)
-{
-	T((T_CALLED("getcury(%p)"), z)); returnCode(((z) ? (z)->_cury : (-1)));
-}
-
-
-extern int call_getbegx (const WINDOW * z);
-int call_getbegx (const WINDOW * z)
-{
-	T((T_CALLED("getbegx(%p)"), z)); returnCode(((z) ? (z)->_begx : (-1)));
-}
-
-
-extern int call_getbegy (const WINDOW * z);
-int call_getbegy (const WINDOW * z)
-{
-	T((T_CALLED("getbegy(%p)"), z)); returnCode(((z) ? (z)->_begy : (-1)));
-}
-
-
-extern int call_getmaxx (const WINDOW * z);
-int call_getmaxx (const WINDOW * z)
-{
-	T((T_CALLED("getmaxx(%p)"), z)); returnCode(((z) ? ((z)->_maxx + 1) : (-1)));
-}
-
-
-extern int call_getmaxy (const WINDOW * z);
-int call_getmaxy (const WINDOW * z)
-{
-	T((T_CALLED("getmaxy(%p)"), z)); returnCode(((z) ? ((z)->_maxy + 1) : (-1)));
-}
-
-
-extern int call_getparx (const WINDOW * z);
-int call_getparx (const WINDOW * z)
-{
-	T((T_CALLED("getparx(%p)"), z)); returnCode(((z) ? (z)->_parx : (-1)));
-}
-
-
-extern int call_getpary (const WINDOW * z);
-int call_getpary (const WINDOW * z)
-{
-	T((T_CALLED("getpary(%p)"), z)); returnCode(((z) ? (z)->_pary : (-1)));
-}
-
-
-extern WINDOW * call_wgetparent (const WINDOW * z);
-WINDOW * call_wgetparent (const WINDOW * z)
-{
-	T((T_CALLED("(%p)"), z)); returnWin(((z) ? (z)->_parent : 0));
-}
-
-
-extern NCURSES_BOOL call_is_cleared (const WINDOW * z);
-NCURSES_BOOL call_is_cleared (const WINDOW * z)
-{
-	T((T_CALLED("is_cleared(%p)"), z)); returnBool(((z)->_clear));
-}
-
-
-extern NCURSES_BOOL call_is_idcok (const WINDOW * z);
-NCURSES_BOOL call_is_idcok (const WINDOW * z)
-{
-	T((T_CALLED("is_idcok(%p)"), z)); returnBool(((z)->_idcok));
-}
-
-
-extern NCURSES_BOOL call_is_idlok (const WINDOW * z);
-NCURSES_BOOL call_is_idlok (const WINDOW * z)
-{
-	T((T_CALLED("is_idlok(%p)"), z)); returnBool(((z)->_idlok));
-}
-
-
-extern NCURSES_BOOL call_is_immedok (const WINDOW * z);
-NCURSES_BOOL call_is_immedok (const WINDOW * z)
-{
-	T((T_CALLED("is_immedok(%p)"), z)); returnBool(((z)->_immed));
-}
-
-
-extern NCURSES_BOOL call_is_keypad (const WINDOW * z);
-NCURSES_BOOL call_is_keypad (const WINDOW * z)
-{
-	T((T_CALLED("is_keypad(%p)"), z)); returnBool(((z)->_use_keypad));
-}
-
-
-extern NCURSES_BOOL call_is_leaveok (const WINDOW * z);
-NCURSES_BOOL call_is_leaveok (const WINDOW * z)
-{
-	T((T_CALLED("is_leaveok(%p)"), z)); returnBool(((z)->_leaveok));
-}
-
-
-extern NCURSES_BOOL call_is_nodelay (const WINDOW * z);
-NCURSES_BOOL call_is_nodelay (const WINDOW * z)
-{
-	T((T_CALLED("is_nodelay(%p)"), z)); returnBool(((z)->_delay == 0));
-}
-
-
-extern NCURSES_BOOL call_is_notimeout (const WINDOW * z);
-NCURSES_BOOL call_is_notimeout (const WINDOW * z)
-{
-	T((T_CALLED("is_notimeout(%p)"), z)); returnBool(((z)->_notimeout));
-}
-
-
-extern NCURSES_BOOL call_is_scrollok (const WINDOW * z);
-NCURSES_BOOL call_is_scrollok (const WINDOW * z)
-{
-	T((T_CALLED("is_scrollok(%p)"), z)); returnBool(((z)->_scroll));
-}
-
-
-extern NCURSES_BOOL call_is_syncok (const WINDOW * z);
-NCURSES_BOOL call_is_syncok (const WINDOW * z)
-{
-	T((T_CALLED("is_syncok(%p)"), z)); returnBool(((z)->_sync));
-}
-
-
-extern int call_wgetscrreg (const WINDOW * a1, int * a2, int * z);
-int call_wgetscrreg (const WINDOW * a1, int * a2, int * z)
-{
-	T((T_CALLED("wgetscrreg(%p,%p,%p)"), a1, a2, z)); returnCode(((a1) ? (*(a2) = (a1)->_regtop, *(z) = (a1)->_regbottom, (0)) : (-1)));
-}
-
-
-extern NCURSES_BOOL call_mouse_trafo (int * a1, int * a2, NCURSES_BOOL z);
-NCURSES_BOOL call_mouse_trafo (int * a1, int * a2, NCURSES_BOOL z)
-{
-	T((T_CALLED("mouse_trafo(%p,%p,%#lx)"), a1, a2, (long)z)); returnBool(wmouse_trafo(stdscr,a1,a2,z));
-}
-int main(void) { return 0; }
diff --git a/ncurses/llib-lncurses b/ncurses/llib-lncurses
index cc0e366..4604fdd 100644
--- a/ncurses/llib-lncurses
+++ b/ncurses/llib-lncurses
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2015 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            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey 1996-2008                                      *
+ *  Author: Thomas E. Dickey       1996-on                                  *
  ****************************************************************************/
 /* LINTLIBRARY */
 
@@ -38,27 +38,54 @@
 #undef _nc_oldnums
 int	*_nc_oldnums;
 
+#undef _nc_scroll_optimize_sp
+void	_nc_scroll_optimize_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_scroll_optimize
 void	_nc_scroll_optimize(void)
 		{ /* void */ }
 
+#undef _nc_linedump_sp
+void	_nc_linedump_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_linedump
 void	_nc_linedump(void)
 		{ /* void */ }
 
 /* ./tty/hashmap.c */
 
-#include <term.h>
+#undef _nc_hash_map_sp
+void	_nc_hash_map_sp(
+		SCREEN	*sp)
+		{ /* void */ }
 
 #undef _nc_hash_map
 void	_nc_hash_map(void)
 		{ /* void */ }
 
+#undef _nc_make_oldhash_sp
+void	_nc_make_oldhash_sp(
+		SCREEN	*sp, 
+		int	i)
+		{ /* void */ }
+
 #undef _nc_make_oldhash
 void	_nc_make_oldhash(
 		int	i)
 		{ /* void */ }
 
+#undef _nc_scroll_oldhash_sp
+void	_nc_scroll_oldhash_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
 #undef _nc_scroll_oldhash
 void	_nc_scroll_oldhash(
 		int	n, 
@@ -68,8 +95,6 @@
 
 /* ./base/lib_addch.c */
 
-#include <ctype.h>
-
 #undef _nc_render
 chtype	_nc_render(
 		WINDOW	*win, 
@@ -112,6 +137,11 @@
 
 /* ./base/lib_beep.c */
 
+#undef beep_sp
+int	beep_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef beep
 int	beep(void)
 		{ return(*(int *)0); }
@@ -187,21 +217,37 @@
 
 /* ./base/lib_color.c */
 
-#include <tic.h>
-
 #undef COLOR_PAIRS
 int	COLOR_PAIRS;
 #undef COLORS
 int	COLORS;
 
+#undef _nc_reset_colors_sp
+NCURSES_BOOL _nc_reset_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef _nc_reset_colors
 NCURSES_BOOL _nc_reset_colors(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef start_color_sp
+int	start_color_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef start_color
 int	start_color(void)
 		{ return(*(int *)0); }
 
+#undef init_pair_sp
+int	init_pair_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
 #undef init_pair
 int	init_pair(
 		short	pair, 
@@ -209,6 +255,15 @@
 		short	b)
 		{ return(*(int *)0); }
 
+#undef init_color_sp
+int	init_color_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	r, 
+		short	g, 
+		short	b)
+		{ return(*(int *)0); }
+
 #undef init_color
 int	init_color(
 		short	color, 
@@ -217,14 +272,33 @@
 		short	b)
 		{ return(*(int *)0); }
 
+#undef can_change_color_sp
+NCURSES_BOOL can_change_color_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef can_change_color
 NCURSES_BOOL can_change_color(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef has_colors_sp
+NCURSES_BOOL has_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_colors
 NCURSES_BOOL has_colors(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef color_content_sp
+int	color_content_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
 #undef color_content
 int	color_content(
 		short	color, 
@@ -233,6 +307,14 @@
 		short	*b)
 		{ return(*(int *)0); }
 
+#undef pair_content_sp
+int	pair_content_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
 #undef pair_content
 int	pair_content(
 		short	pair, 
@@ -240,13 +322,21 @@
 		short	*b)
 		{ return(*(int *)0); }
 
+#undef _nc_do_color_sp
+void	_nc_do_color_sp(
+		SCREEN	*sp, 
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC_sp outc)
+		{ /* void */ }
+
 #undef _nc_do_color
 void	_nc_do_color(
-		short	old_pair, 
-		short	pair, 
-		NCURSES_BOOL reverse, 
-		int	(*outc)(
-		int	p1))
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC outc)
 		{ /* void */ }
 
 /* ./base/lib_colorset.c */
@@ -274,16 +364,31 @@
 
 /* ./base/lib_echo.c */
 
+#undef echo_sp
+int	echo_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef echo
 int	echo(void)
 		{ return(*(int *)0); }
 
+#undef noecho_sp
+int	noecho_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef noecho
 int	noecho(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_endwin.c */
 
+#undef endwin_sp
+int	endwin_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef endwin
 int	endwin(void)
 		{ return(*(int *)0); }
@@ -297,6 +402,11 @@
 
 /* ./base/lib_flash.c */
 
+#undef flash_sp
+int	flash_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef flash
 int	flash(void)
 		{ return(*(int *)0); }
@@ -304,85 +414,85 @@
 /* ./lib_gen.c */
 
 #undef addch
-int	addch(
+int	(addch)(
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef addchnstr
-int	addchnstr(
+int	(addchnstr)(
 		const chtype *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef addchstr
-int	addchstr(
+int	(addchstr)(
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef addnstr
-int	addnstr(
+int	(addnstr)(
 		const char *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef addstr
-int	addstr(
+int	(addstr)(
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef attroff
-int	attroff(
+int	(attroff)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attron
-int	attron(
+int	(attron)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attrset
-int	attrset(
+int	(attrset)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attr_get
-int	attr_get(
+int	(attr_get)(
 		attr_t	*a1, 
 		short	*a2, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_off
-int	attr_off(
+int	(attr_off)(
 		attr_t	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_on
-int	attr_on(
+int	(attr_on)(
 		attr_t	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_set
-int	attr_set(
+int	(attr_set)(
 		attr_t	a1, 
 		short	a2, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef bkgd
-int	bkgd(
+int	(bkgd)(
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef bkgdset
-void	bkgdset(
+void	(bkgdset)(
 		chtype	z)
 		{ /* void */ }
 
 #undef border
-int	border(
+int	(border)(
 		chtype	a1, 
 		chtype	a2, 
 		chtype	a3, 
@@ -394,14 +504,14 @@
 		{ return(*(int *)0); }
 
 #undef box
-int	box(
+int	(box)(
 		WINDOW	*a1, 
 		chtype	a2, 
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef chgat
-int	chgat(
+int	(chgat)(
 		int	a1, 
 		attr_t	a2, 
 		short	a3, 
@@ -409,137 +519,137 @@
 		{ return(*(int *)0); }
 
 #undef clear
-int	clear(void)
+int	(clear)(void)
 		{ return(*(int *)0); }
 
 #undef clrtobot
-int	clrtobot(void)
+int	(clrtobot)(void)
 		{ return(*(int *)0); }
 
 #undef clrtoeol
-int	clrtoeol(void)
+int	(clrtoeol)(void)
 		{ return(*(int *)0); }
 
 #undef color_set
-int	color_set(
+int	(color_set)(
 		short	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef COLOR_PAIR
-int	COLOR_PAIR(
+int	(COLOR_PAIR)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef delch
-int	delch(void)
+int	(delch)(void)
 		{ return(*(int *)0); }
 
 #undef deleteln
-int	deleteln(void)
+int	(deleteln)(void)
 		{ return(*(int *)0); }
 
 #undef echochar
-int	echochar(
+int	(echochar)(
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef erase
-int	erase(void)
+int	(erase)(void)
 		{ return(*(int *)0); }
 
 #undef getbkgd
-chtype	getbkgd(
+chtype	(getbkgd)(
 		WINDOW	*z)
 		{ return(*(chtype *)0); }
 
 #undef getch
-int	getch(void)
+int	(getch)(void)
 		{ return(*(int *)0); }
 
 #undef getnstr
-int	getnstr(
+int	(getnstr)(
 		char	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef getstr
-int	getstr(
+int	(getstr)(
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef hline
-int	hline(
+int	(hline)(
 		chtype	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef inch
-chtype	inch(void)
+chtype	(inch)(void)
 		{ return(*(chtype *)0); }
 
 #undef inchnstr
-int	inchnstr(
+int	(inchnstr)(
 		chtype	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef inchstr
-int	inchstr(
+int	(inchstr)(
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef innstr
-int	innstr(
+int	(innstr)(
 		char	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insch
-int	insch(
+int	(insch)(
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef insdelln
-int	insdelln(
+int	(insdelln)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insertln
-int	insertln(void)
+int	(insertln)(void)
 		{ return(*(int *)0); }
 
 #undef insnstr
-int	insnstr(
+int	(insnstr)(
 		const char *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insstr
-int	insstr(
+int	(insstr)(
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef instr
-int	instr(
+int	(instr)(
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef move
-int	move(
+int	(move)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvaddch
-int	mvaddch(
+int	(mvaddch)(
 		int	a1, 
 		int	a2, 
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef mvaddchnstr
-int	mvaddchnstr(
+int	(mvaddchnstr)(
 		int	a1, 
 		int	a2, 
 		const chtype *a3, 
@@ -547,14 +657,14 @@
 		{ return(*(int *)0); }
 
 #undef mvaddchstr
-int	mvaddchstr(
+int	(mvaddchstr)(
 		int	a1, 
 		int	a2, 
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef mvaddnstr
-int	mvaddnstr(
+int	(mvaddnstr)(
 		int	a1, 
 		int	a2, 
 		const char *a3, 
@@ -562,14 +672,14 @@
 		{ return(*(int *)0); }
 
 #undef mvaddstr
-int	mvaddstr(
+int	(mvaddstr)(
 		int	a1, 
 		int	a2, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef mvchgat
-int	mvchgat(
+int	(mvchgat)(
 		int	a1, 
 		int	a2, 
 		int	a3, 
@@ -579,19 +689,19 @@
 		{ return(*(int *)0); }
 
 #undef mvdelch
-int	mvdelch(
+int	(mvdelch)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvgetch
-int	mvgetch(
+int	(mvgetch)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvgetnstr
-int	mvgetnstr(
+int	(mvgetnstr)(
 		int	a1, 
 		int	a2, 
 		char	*a3, 
@@ -599,14 +709,14 @@
 		{ return(*(int *)0); }
 
 #undef mvgetstr
-int	mvgetstr(
+int	(mvgetstr)(
 		int	a1, 
 		int	a2, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef mvhline
-int	mvhline(
+int	(mvhline)(
 		int	a1, 
 		int	a2, 
 		chtype	a3, 
@@ -614,13 +724,13 @@
 		{ return(*(int *)0); }
 
 #undef mvinch
-chtype	mvinch(
+chtype	(mvinch)(
 		int	a1, 
 		int	z)
 		{ return(*(chtype *)0); }
 
 #undef mvinchnstr
-int	mvinchnstr(
+int	(mvinchnstr)(
 		int	a1, 
 		int	a2, 
 		chtype	*a3, 
@@ -628,14 +738,14 @@
 		{ return(*(int *)0); }
 
 #undef mvinchstr
-int	mvinchstr(
+int	(mvinchstr)(
 		int	a1, 
 		int	a2, 
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef mvinnstr
-int	mvinnstr(
+int	(mvinnstr)(
 		int	a1, 
 		int	a2, 
 		char	*a3, 
@@ -643,14 +753,14 @@
 		{ return(*(int *)0); }
 
 #undef mvinsch
-int	mvinsch(
+int	(mvinsch)(
 		int	a1, 
 		int	a2, 
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef mvinsnstr
-int	mvinsnstr(
+int	(mvinsnstr)(
 		int	a1, 
 		int	a2, 
 		const char *a3, 
@@ -658,21 +768,21 @@
 		{ return(*(int *)0); }
 
 #undef mvinsstr
-int	mvinsstr(
+int	(mvinsstr)(
 		int	a1, 
 		int	a2, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef mvinstr
-int	mvinstr(
+int	(mvinstr)(
 		int	a1, 
 		int	a2, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef mvvline
-int	mvvline(
+int	(mvvline)(
 		int	a1, 
 		int	a2, 
 		chtype	a3, 
@@ -680,7 +790,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddch
-int	mvwaddch(
+int	(mvwaddch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -688,7 +798,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddchnstr
-int	mvwaddchnstr(
+int	(mvwaddchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -697,7 +807,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddchstr
-int	mvwaddchstr(
+int	(mvwaddchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -705,7 +815,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddnstr
-int	mvwaddnstr(
+int	(mvwaddnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -714,7 +824,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddstr
-int	mvwaddstr(
+int	(mvwaddstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -722,7 +832,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwchgat
-int	mvwchgat(
+int	(mvwchgat)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -733,21 +843,21 @@
 		{ return(*(int *)0); }
 
 #undef mvwdelch
-int	mvwdelch(
+int	(mvwdelch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvwgetch
-int	mvwgetch(
+int	(mvwgetch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvwgetnstr
-int	mvwgetnstr(
+int	(mvwgetnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -756,7 +866,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwgetstr
-int	mvwgetstr(
+int	(mvwgetstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -764,7 +874,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwhline
-int	mvwhline(
+int	(mvwhline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -773,14 +883,14 @@
 		{ return(*(int *)0); }
 
 #undef mvwinch
-chtype	mvwinch(
+chtype	(mvwinch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(chtype *)0); }
 
 #undef mvwinchnstr
-int	mvwinchnstr(
+int	(mvwinchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -789,7 +899,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinchstr
-int	mvwinchstr(
+int	(mvwinchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -797,7 +907,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinnstr
-int	mvwinnstr(
+int	(mvwinnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -806,7 +916,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsch
-int	mvwinsch(
+int	(mvwinsch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -814,7 +924,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsnstr
-int	mvwinsnstr(
+int	(mvwinsnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -823,7 +933,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsstr
-int	mvwinsstr(
+int	(mvwinsstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -831,7 +941,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinstr
-int	mvwinstr(
+int	(mvwinstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -839,7 +949,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwvline
-int	mvwvline(
+int	(mvwvline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -848,117 +958,117 @@
 		{ return(*(int *)0); }
 
 #undef PAIR_NUMBER
-int	PAIR_NUMBER(
+int	(PAIR_NUMBER)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef redrawwin
-int	redrawwin(
+int	(redrawwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef refresh
-int	refresh(void)
+int	(refresh)(void)
 		{ return(*(int *)0); }
 
 #undef scrl
-int	scrl(
+int	(scrl)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef scroll
-int	scroll(
+int	(scroll)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef setscrreg
-int	setscrreg(
+int	(setscrreg)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef standout
-int	standout(void)
+int	(standout)(void)
 		{ return(*(int *)0); }
 
 #undef standend
-int	standend(void)
+int	(standend)(void)
 		{ return(*(int *)0); }
 
 #undef timeout
-void	timeout(
+void	(timeout)(
 		int	z)
 		{ /* void */ }
 
 #undef touchline
-int	touchline(
+int	(touchline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef touchwin
-int	touchwin(
+int	(touchwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef untouchwin
-int	untouchwin(
+int	(untouchwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef vline
-int	vline(
+int	(vline)(
 		chtype	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef vw_printw
-int	vw_printw(
+int	(vw_printw)(
 		WINDOW	*a1, 
 		const char *a2, 
 		va_list	z)
 		{ return(*(int *)0); }
 
 #undef vw_scanw
-int	vw_scanw(
+int	(vw_scanw)(
 		WINDOW	*a1, 
-		char	*a2, 
+		const char *a2, 
 		va_list	z)
 		{ return(*(int *)0); }
 
 #undef waddchstr
-int	waddchstr(
+int	(waddchstr)(
 		WINDOW	*a1, 
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef waddstr
-int	waddstr(
+int	(waddstr)(
 		WINDOW	*a1, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef wattron
-int	wattron(
+int	(wattron)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattroff
-int	wattroff(
+int	(wattroff)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattrset
-int	wattrset(
+int	(wattrset)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattr_get
-int	wattr_get(
+int	(wattr_get)(
 		WINDOW	*a1, 
 		attr_t	*a2, 
 		short	*a3, 
@@ -966,7 +1076,7 @@
 		{ return(*(int *)0); }
 
 #undef wattr_set
-int	wattr_set(
+int	(wattr_set)(
 		WINDOW	*a1, 
 		attr_t	a2, 
 		short	a3, 
@@ -974,158 +1084,173 @@
 		{ return(*(int *)0); }
 
 #undef wdeleteln
-int	wdeleteln(
+int	(wdeleteln)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef wgetstr
-int	wgetstr(
+int	(wgetstr)(
 		WINDOW	*a1, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef winchstr
-int	winchstr(
+int	(winchstr)(
 		WINDOW	*a1, 
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef winsertln
-int	winsertln(
+int	(winsertln)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef winsstr
-int	winsstr(
+int	(winsstr)(
 		WINDOW	*a1, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef winstr
-int	winstr(
+int	(winstr)(
 		WINDOW	*a1, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef wstandout
-int	wstandout(
+int	(wstandout)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef wstandend
-int	wstandend(
+int	(wstandend)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef getattrs
-int	getattrs(
+int	(getattrs)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getcurx
-int	getcurx(
+int	(getcurx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getcury
-int	getcury(
+int	(getcury)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getbegx
-int	getbegx(
+int	(getbegx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getbegy
-int	getbegy(
+int	(getbegy)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getmaxx
-int	getmaxx(
+int	(getmaxx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getmaxy
-int	getmaxy(
+int	(getmaxy)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getparx
-int	getparx(
+int	(getparx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getpary
-int	getpary(
+int	(getpary)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef wgetparent
-WINDOW	*wgetparent(
+WINDOW	*(wgetparent)(
 		const WINDOW *z)
 		{ return(*(WINDOW **)0); }
 
 #undef is_cleared
-NCURSES_BOOL is_cleared(
+NCURSES_BOOL (is_cleared)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_idcok
-NCURSES_BOOL is_idcok(
+NCURSES_BOOL (is_idcok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_idlok
-NCURSES_BOOL is_idlok(
+NCURSES_BOOL (is_idlok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_immedok
-NCURSES_BOOL is_immedok(
+NCURSES_BOOL (is_immedok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_keypad
-NCURSES_BOOL is_keypad(
+NCURSES_BOOL (is_keypad)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_leaveok
-NCURSES_BOOL is_leaveok(
+NCURSES_BOOL (is_leaveok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_nodelay
-NCURSES_BOOL is_nodelay(
+NCURSES_BOOL (is_nodelay)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_notimeout
-NCURSES_BOOL is_notimeout(
+NCURSES_BOOL (is_notimeout)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_pad
+NCURSES_BOOL (is_pad)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_scrollok
-NCURSES_BOOL is_scrollok(
+NCURSES_BOOL (is_scrollok)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_subwin
+NCURSES_BOOL (is_subwin)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_syncok
-NCURSES_BOOL is_syncok(
+NCURSES_BOOL (is_syncok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef wgetdelay
+int	(wgetdelay)(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
 #undef wgetscrreg
-int	wgetscrreg(
+int	(wgetscrreg)(
 		const WINDOW *a1, 
 		int	*a2, 
 		int	*z)
 		{ return(*(int *)0); }
 
 #undef mouse_trafo
-NCURSES_BOOL mouse_trafo(
+NCURSES_BOOL (mouse_trafo)(
 		int	*a1, 
 		int	*a2, 
 		NCURSES_BOOL z)
@@ -1133,20 +1258,33 @@
 
 /* ./base/lib_getch.c */
 
-#include <fifo_defs.h>
-
 #undef ESCDELAY
 int	ESCDELAY;
 
+#undef set_escdelay_sp
+int	set_escdelay_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ return(*(int *)0); }
+
 #undef set_escdelay
 int	set_escdelay(
 		int	value)
 		{ return(*(int *)0); }
 
+#undef get_escdelay_sp
+int	get_escdelay_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef get_escdelay
+int	get_escdelay(void)
+		{ return(*(int *)0); }
+
 #undef _nc_wgetch
 int	_nc_wgetch(
 		WINDOW	*win, 
-		unsigned long *result, 
+		int	*result, 
 		int	use_meta)
 		{ return(*(int *)0); }
 
@@ -1200,6 +1338,7 @@
 
 #undef _nc_insert_ch
 int	_nc_insert_ch(
+		SCREEN	*sp, 
 		WINDOW	*win, 
 		chtype	ch)
 		{ return(*(int *)0); }
@@ -1238,6 +1377,11 @@
 
 /* ./base/lib_isendwin.c */
 
+#undef isendwin_sp
+NCURSES_BOOL isendwin_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef isendwin
 NCURSES_BOOL isendwin(void)
 		{ return(*(NCURSES_BOOL *)0); }
@@ -1252,16 +1396,35 @@
 
 /* ./base/lib_mouse.c */
 
+#undef getmouse_sp
+int	getmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
 #undef getmouse
 int	getmouse(
 		MEVENT	*aevent)
 		{ return(*(int *)0); }
 
+#undef ungetmouse_sp
+int	ungetmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
 #undef ungetmouse
 int	ungetmouse(
 		MEVENT	*aevent)
 		{ return(*(int *)0); }
 
+#undef mousemask_sp
+mmask_t	mousemask_sp(
+		SCREEN	*sp, 
+		mmask_t	newmask, 
+		mmask_t	*oldmask)
+		{ return(*(mmask_t *)0); }
+
 #undef mousemask
 mmask_t	mousemask(
 		mmask_t	newmask, 
@@ -1275,14 +1438,30 @@
 		int	x)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef mouseinterval_sp
+int	mouseinterval_sp(
+		SCREEN	*sp, 
+		int	maxclick)
+		{ return(*(int *)0); }
+
 #undef mouseinterval
 int	mouseinterval(
 		int	maxclick)
 		{ return(*(int *)0); }
 
 #undef _nc_has_mouse
-int	_nc_has_mouse(void)
-		{ return(*(int *)0); }
+NCURSES_BOOL _nc_has_mouse(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse_sp
+NCURSES_BOOL has_mouse_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse
+NCURSES_BOOL has_mouse(void)
+		{ return(*(NCURSES_BOOL *)0); }
 
 #undef wmouse_trafo
 NCURSES_BOOL wmouse_trafo(
@@ -1303,24 +1482,72 @@
 
 /* ./tty/lib_mvcur.c */
 
+#undef _nc_msec_cost_sp
+int	_nc_msec_cost_sp(
+		SCREEN	*sp, 
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
 #undef _nc_msec_cost
 int	_nc_msec_cost(
 		const char *const cap, 
 		int	affcnt)
 		{ return(*(int *)0); }
 
+#undef _nc_mvcur_resume_sp
+void	_nc_mvcur_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_resume
 void	_nc_mvcur_resume(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_init_sp
+void	_nc_mvcur_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_init
 void	_nc_mvcur_init(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_wrap_sp
+void	_nc_mvcur_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_wrap
 void	_nc_mvcur_wrap(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_sp
+int	_nc_mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur
+int	_nc_mvcur(
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef mvcur_sp
+int	mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
 #undef mvcur
 int	mvcur(
 		int	yold, 
@@ -1343,17 +1570,35 @@
 
 /* ./base/lib_newterm.c */
 
+#undef filter_sp
+void	filter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef filter
 void	filter(void)
 		{ /* void */ }
 
+#undef nofilter_sp
+void	nofilter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef nofilter
 void	nofilter(void)
 		{ /* void */ }
 
+#undef newterm_sp
+SCREEN	*newterm_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		FILE	*ofp, 
+		FILE	*ifp)
+		{ return(*(SCREEN **)0); }
+
 #undef newterm
 SCREEN	*newterm(
-		char	*name, 
+		const char *name, 
 		FILE	*ofp, 
 		FILE	*ifp)
 		{ return(*(SCREEN **)0); }
@@ -1365,6 +1610,15 @@
 		WINDOW	*win)
 		{ return(*(int *)0); }
 
+#undef newwin_sp
+WINDOW	*newwin_sp(
+		SCREEN	*sp, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
 #undef newwin
 WINDOW	*newwin(
 		int	num_lines, 
@@ -1391,8 +1645,9 @@
 		int	x)
 		{ return(*(WINDOW **)0); }
 
-#undef _nc_makenew
-WINDOW	*_nc_makenew(
+#undef _nc_makenew_sp
+WINDOW	*_nc_makenew_sp(
+		SCREEN	*sp, 
 		int	num_lines, 
 		int	num_columns, 
 		int	begy, 
@@ -1400,17 +1655,37 @@
 		int	flags)
 		{ return(*(WINDOW **)0); }
 
-#undef _nc_screen_of
-SCREEN	*_nc_screen_of(
-		WINDOW	*win)
-		{ return(*(SCREEN **)0); }
+#undef _nc_curscr_of
+WINDOW	*_nc_curscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_newscr_of
+WINDOW	*_nc_newscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_stdscr_of
+WINDOW	*_nc_stdscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
 
 /* ./base/lib_nl.c */
 
+#undef nl_sp
+int	nl_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nl
 int	nl(void)
 		{ return(*(int *)0); }
 
+#undef nonl_sp
+int	nonl_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nonl
 int	nonl(void)
 		{ return(*(int *)0); }
@@ -1444,6 +1719,13 @@
 
 /* ./base/lib_pad.c */
 
+#undef newpad_sp
+WINDOW	*newpad_sp(
+		SCREEN	*sp, 
+		int	l, 
+		int	c)
+		{ return(*(WINDOW **)0); }
+
 #undef newpad
 WINDOW	*newpad(
 		int	l, 
@@ -1549,9 +1831,17 @@
 
 /* ./base/lib_restart.c */
 
+#undef restartterm_sp
+int	restartterm_sp(
+		SCREEN	*sp, 
+		const char *termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
 #undef restartterm
 int	restartterm(
-		char	*termp, 
+		const char *termp, 
 		int	filenum, 
 		int	*errret)
 		{ return(*(int *)0); }
@@ -1561,20 +1851,20 @@
 #undef vwscanw
 int	vwscanw(
 		WINDOW	*win, 
-		char	*fmt, 
+		const char *fmt, 
 		va_list	argp)
 		{ return(*(int *)0); }
 
 #undef scanw
 int	scanw(
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
 #undef wscanw
 int	wscanw(
 		WINDOW	*win, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
@@ -1582,7 +1872,7 @@
 int	mvscanw(
 		int	y, 
 		int	x, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
@@ -1591,12 +1881,18 @@
 		WINDOW	*win, 
 		int	y, 
 		int	x, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
 /* ./base/lib_screen.c */
 
+#undef getwin_sp
+WINDOW	*getwin_sp(
+		SCREEN	*sp, 
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
 #undef getwin
 WINDOW	*getwin(
 		FILE	*filep)
@@ -1608,6 +1904,12 @@
 		FILE	*filep)
 		{ return(*(int *)0); }
 
+#undef scr_restore_sp
+int	scr_restore_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_restore
 int	scr_restore(
 		const char *file)
@@ -1618,11 +1920,23 @@
 		const char *file)
 		{ return(*(int *)0); }
 
+#undef scr_init_sp
+int	scr_init_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_init
 int	scr_init(
 		const char *file)
 		{ return(*(int *)0); }
 
+#undef scr_set_sp
+int	scr_set_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_set
 int	scr_set(
 		const char *file)
@@ -1634,8 +1948,8 @@
 void	_nc_scroll_window(
 		WINDOW	*win, 
 		int const n, 
-		short const top, 
-		short const bottom, 
+		int const top, 
+		int const bottom, 
 		chtype	blank)
 		{ /* void */ }
 
@@ -1674,15 +1988,34 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef _nc_setupscreen_sp
+int	_nc_setupscreen_sp(
+		SCREEN	**spp, 
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		int	filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
 #undef _nc_setupscreen
 int	_nc_setupscreen(
 		int	slines, 
 		int	scolumns, 
 		FILE	*output, 
-		NCURSES_BOOL filtered, 
+		int	filtered, 
 		int	slk_format)
 		{ return(*(int *)0); }
 
+#undef _nc_ripoffline_sp
+int	_nc_ripoffline_sp(
+		SCREEN	*sp, 
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
 #undef _nc_ripoffline
 int	_nc_ripoffline(
 		int	line, 
@@ -1691,6 +2024,15 @@
 		int	p2))
 		{ return(*(int *)0); }
 
+#undef ripoffline_sp
+int	ripoffline_sp(
+		SCREEN	*sp, 
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
 #undef ripoffline
 int	ripoffline(
 		int	line, 
@@ -1701,18 +2043,37 @@
 
 /* ./base/lib_slk.c */
 
+#undef _nc_format_slks
+int	_nc_format_slks(
+		SCREEN	*sp, 
+		int	cols)
+		{ return(*(int *)0); }
+
 #undef _nc_slk_initialize
 int	_nc_slk_initialize(
 		WINDOW	*stwin, 
 		int	cols)
 		{ return(*(int *)0); }
 
+#undef slk_restore_sp
+int	slk_restore_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_restore
 int	slk_restore(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkatr_set.c */
 
+#undef slk_attr_set_sp
+int	slk_attr_set_sp(
+		SCREEN	*sp, 
+		const attr_t attr, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
 #undef slk_attr_set
 int	slk_attr_set(
 		const attr_t attr, 
@@ -1722,6 +2083,12 @@
 
 /* ./base/lib_slkatrof.c */
 
+#undef slk_attroff_sp
+int	slk_attroff_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attroff
 int	slk_attroff(
 		const chtype attr)
@@ -1729,6 +2096,12 @@
 
 /* ./base/lib_slkatron.c */
 
+#undef slk_attron_sp
+int	slk_attron_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attron
 int	slk_attron(
 		const chtype attr)
@@ -1736,6 +2109,12 @@
 
 /* ./base/lib_slkatrset.c */
 
+#undef slk_attrset_sp
+int	slk_attrset_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attrset
 int	slk_attrset(
 		const chtype attr)
@@ -1743,18 +2122,34 @@
 
 /* ./base/lib_slkattr.c */
 
+#undef slk_attr_sp
+attr_t	slk_attr_sp(
+		SCREEN	*sp)
+		{ return(*(attr_t *)0); }
+
 #undef slk_attr
 attr_t	slk_attr(void)
 		{ return(*(attr_t *)0); }
 
 /* ./base/lib_slkclear.c */
 
+#undef slk_clear_sp
+int	slk_clear_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_clear
 int	slk_clear(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkcolor.c */
 
+#undef slk_color_sp
+int	slk_color_sp(
+		SCREEN	*sp, 
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
 #undef slk_color
 int	slk_color(
 		short	color_pair_number)
@@ -1762,6 +2157,12 @@
 
 /* ./base/lib_slkinit.c */
 
+#undef slk_init_sp
+int	slk_init_sp(
+		SCREEN	*sp, 
+		int	format)
+		{ return(*(int *)0); }
+
 #undef slk_init
 int	slk_init(
 		int	format)
@@ -1769,6 +2170,12 @@
 
 /* ./base/lib_slklab.c */
 
+#undef slk_label_sp
+char	*slk_label_sp(
+		SCREEN	*sp, 
+		int	n)
+		{ return(*(char **)0); }
+
 #undef slk_label
 char	*slk_label(
 		int	n)
@@ -1776,16 +2183,34 @@
 
 /* ./base/lib_slkrefr.c */
 
+#undef slk_noutrefresh_sp
+int	slk_noutrefresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_noutrefresh
 int	slk_noutrefresh(void)
 		{ return(*(int *)0); }
 
+#undef slk_refresh_sp
+int	slk_refresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_refresh
 int	slk_refresh(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkset.c */
 
+#undef slk_set_sp
+int	slk_set_sp(
+		SCREEN	*sp, 
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
 #undef slk_set
 int	slk_set(
 		int	i, 
@@ -1795,6 +2220,11 @@
 
 /* ./base/lib_slktouch.c */
 
+#undef slk_touch_sp
+int	slk_touch_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_touch
 int	slk_touch(void)
 		{ return(*(int *)0); }
@@ -1830,12 +2260,24 @@
 
 /* ./trace/lib_tracemse.c */
 
+#undef _nc_trace_mmask_t
+char	*_nc_trace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(char **)0); }
+
 #undef _nc_tracemouse
 char	*_nc_tracemouse(
 		SCREEN	*sp, 
 		MEVENT const *ep)
 		{ return(*(char **)0); }
 
+#undef _nc_retrace_mmask_t
+mmask_t	_nc_retrace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(mmask_t *)0); }
+
 #undef _tracemouse
 char	*_tracemouse(
 		MEVENT const *ep)
@@ -1843,11 +2285,9 @@
 
 /* ./tty/lib_tstp.c */
 
-#include <SigAction.h>
-
 #undef _nc_signal_handler
 void	_nc_signal_handler(
-		NCURSES_BOOL enable)
+		int	enable)
 		{ /* void */ }
 
 /* ./base/lib_ungetch.c */
@@ -1857,8 +2297,8 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
-#undef _nc_ungetch
-int	_nc_ungetch(
+#undef ungetch_sp
+int	ungetch_sp(
 		SCREEN	*sp, 
 		int	ch)
 		{ return(*(int *)0); }
@@ -1870,11 +2310,23 @@
 
 /* ./tty/lib_vidattr.c */
 
+#undef vidputs_sp
+int	vidputs_sp(
+		SCREEN	*sp, 
+		chtype	newmode, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
 #undef vidputs
 int	vidputs(
 		chtype	newmode, 
-		int	(*outc)(
-		int	p1))
+		NCURSES_OUTC outc)
+		{ return(*(int *)0); }
+
+#undef vidattr_sp
+int	vidattr_sp(
+		SCREEN	*sp, 
+		chtype	newmode)
 		{ return(*(int *)0); }
 
 #undef vidattr
@@ -1882,6 +2334,11 @@
 		chtype	newmode)
 		{ return(*(int *)0); }
 
+#undef termattrs_sp
+chtype	termattrs_sp(
+		SCREEN	*sp)
+		{ return(*(chtype *)0); }
+
 #undef termattrs
 chtype	termattrs(void)
 		{ return(*(chtype *)0); }
@@ -1962,12 +2419,24 @@
 
 /* ./base/nc_panel.c */
 
+#undef _nc_panelhook_sp
+struct panelhook *_nc_panelhook_sp(
+		SCREEN	*sp)
+		{ return(*(struct panelhook **)0); }
+
 #undef _nc_panelhook
 struct panelhook *_nc_panelhook(void)
 		{ return(*(struct panelhook **)0); }
 
 /* ./base/safe_sprintf.c */
 
+#undef _nc_printf_string_sp
+char	*_nc_printf_string_sp(
+		SCREEN	*sp, 
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
 #undef _nc_printf_string
 char	*_nc_printf_string(
 		const char *fmt, 
@@ -1976,13 +2445,24 @@
 
 /* ./tty/tty_update.c */
 
-#include <sys/time.h>
-#include <sys/times.h>
+#undef doupdate_sp
+int	doupdate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
 
 #undef doupdate
 int	doupdate(void)
 		{ return(*(int *)0); }
 
+#undef _nc_scrolln_sp
+int	_nc_scrolln_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
 #undef _nc_scrolln
 int	_nc_scrolln(
 		int	n, 
@@ -1991,18 +2471,39 @@
 		int	maxy)
 		{ return(*(int *)0); }
 
+#undef _nc_screen_resume_sp
+void	_nc_screen_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_resume
 void	_nc_screen_resume(void)
 		{ /* void */ }
 
+#undef _nc_screen_init_sp
+void	_nc_screen_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_init
 void	_nc_screen_init(void)
 		{ /* void */ }
 
+#undef _nc_screen_wrap_sp
+void	_nc_screen_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_wrap
 void	_nc_screen_wrap(void)
 		{ /* void */ }
 
+#undef _nc_do_xmc_glitch_sp
+void	_nc_do_xmc_glitch_sp(
+		SCREEN	*sp, 
+		attr_t	previous)
+		{ /* void */ }
+
 #undef _nc_do_xmc_glitch
 void	_nc_do_xmc_glitch(
 		attr_t	previous)
@@ -2020,12 +2521,6 @@
 		va_list	ap)
 		{ return(*(char **)0); }
 
-/* ./base/memmove.c */
-
-#undef _nc_memmove
-void	_nc_memmove(void)
-		{ /* void */ }
-
 /* ./base/vsscanf.c */
 
 #undef _nc_vsscanf
@@ -2034,12 +2529,16 @@
 
 /* ./base/lib_freeall.c */
 
-#include <term_entry.h>
-
 #undef _nc_freeall
 void	_nc_freeall(void)
 		{ /* void */ }
 
+#undef _nc_free_and_exit_sp
+void	_nc_free_and_exit_sp(
+		SCREEN	*sp, 
+		int	code)
+		{ /* void */ }
+
 #undef _nc_free_and_exit
 void	_nc_free_and_exit(
 		int	code)
@@ -2059,6 +2558,24 @@
 		attr_t	at)
 		{ /* void */ }
 
+#undef _nc_DelCharCost_sp
+int	_nc_DelCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_InsCharCost_sp
+int	_nc_InsCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_UpdateAttrs_sp
+void	_nc_UpdateAttrs_sp(
+		SCREEN	*sp, 
+		chtype	c)
+		{ /* void */ }
+
 #undef _nc_DelCharCost
 int	_nc_DelCharCost(
 		int	count)
@@ -2076,6 +2593,12 @@
 
 /* ./base/legacy_coding.c */
 
+#undef use_legacy_coding_sp
+int	use_legacy_coding_sp(
+		SCREEN	*sp, 
+		int	level)
+		{ return(*(int *)0); }
+
 #undef use_legacy_coding
 int	use_legacy_coding(
 		int	level)
@@ -2083,10 +2606,22 @@
 
 /* ./base/lib_dft_fgbg.c */
 
+#undef use_default_colors_sp
+int	use_default_colors_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef use_default_colors
 int	use_default_colors(void)
 		{ return(*(int *)0); }
 
+#undef assume_default_colors_sp
+int	assume_default_colors_sp(
+		SCREEN	*sp, 
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
 #undef assume_default_colors
 int	assume_default_colors(
 		int	fg, 
@@ -2095,6 +2630,13 @@
 
 /* ./tinfo/lib_print.c */
 
+#undef mcprint_sp
+int	mcprint_sp(
+		SCREEN	*sp, 
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
 #undef mcprint
 int	mcprint(
 		char	*data, 
@@ -2103,18 +2645,39 @@
 
 /* ./base/resizeterm.c */
 
+#undef is_term_resized_sp
+NCURSES_BOOL is_term_resized_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef is_term_resized
 NCURSES_BOOL is_term_resized(
 		int	ToLines, 
 		int	ToCols)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef resize_term_sp
+int	resize_term_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
 #undef resize_term
 int	resize_term(
 		int	ToLines, 
 		int	ToCols)
 		{ return(*(int *)0); }
 
+#undef resizeterm_sp
+int	resizeterm_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
 #undef resizeterm
 int	resizeterm(
 		int	ToLines, 
@@ -2157,9 +2720,6 @@
 
 /* ./tinfo/access.c */
 
-#include <sys/stat.h>
-#include <nc_alloc.h>
-
 #undef _nc_rootname
 char	*_nc_rootname(
 		char	*path)
@@ -2220,19 +2780,42 @@
 #undef _nc_copy_termtype
 void	_nc_copy_termtype(
 		TERMTYPE *dst, 
-		TERMTYPE *src)
+		const TERMTYPE *src)
 		{ /* void */ }
 
 /* ./codes.c */
 
 #undef boolcodes
-char	*const boolcodes[] = {0};
+const char *const boolcodes[] = {0};
 #undef numcodes
-char	*const numcodes[] = {0};
+const char *const numcodes[] = {0};
 #undef strcodes
-char	*const strcodes[] = {0};
+const char *const strcodes[] = {0};
+
+/* ./comp_captab.c */
+
+#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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)0); }
 
 /* ./tinfo/comp_error.c */
+
 #undef _nc_suppress_warnings
 NCURSES_BOOL _nc_suppress_warnings;
 #undef _nc_curr_line
@@ -2277,6 +2860,21 @@
 		...)
 		{ /* void */ }
 
+/* ./tinfo/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
 /* ./tinfo/db_iterator.c */
 
 #undef _nc_tic_dir
@@ -2370,6 +2968,12 @@
 		const char *name)
 		{ return(*(int *)0); }
 
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
 /* ./tinfo/home_terminfo.c */
 
 #undef _nc_home_terminfo
@@ -2378,15 +2982,6 @@
 
 /* ./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)
@@ -2397,16 +2992,19 @@
 #undef acs_map
 chtype	acs_map[128];
 
+#undef _nc_init_acs_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_init_acs
 void	_nc_init_acs(void)
 		{ /* void */ }
 
 /* ./tinfo/lib_baudrate.c */
 
-#include <termcap.h>
-
 struct speed {
-    int s; 
+    short s; 
     int sp; 
 };
 
@@ -2420,6 +3018,11 @@
 		int	BaudRate)
 		{ return(*(int *)0); }
 
+#undef baudrate_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef baudrate
 int	baudrate(void)
 		{ return(*(int *)0); }
@@ -2429,11 +3032,23 @@
 #undef cur_term
 TERMINAL *cur_term;
 
+#undef set_curterm_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
 #undef set_curterm
 TERMINAL *set_curterm(
 		TERMINAL *termp)
 		{ return(*(TERMINAL **)0); }
 
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
 #undef del_curterm
 int	del_curterm(
 		TERMINAL *termp)
@@ -2456,26 +3071,56 @@
 #undef _nc_prescreen
 NCURSES_PRESCREEN _nc_prescreen;
 
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
 /* ./tinfo/lib_has_cap.c */
 
+#undef has_ic_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_ic
 NCURSES_BOOL has_ic(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_il
 NCURSES_BOOL has_il(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
 /* ./tinfo/lib_kernel.c */
 
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
 #undef erasechar
 char	erasechar(void)
 		{ return(*(char *)0); }
 
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
 #undef killchar
 char	killchar(void)
 		{ return(*(char *)0); }
 
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef flushinp
 int	flushinp(void)
 		{ return(*(int *)0); }
@@ -2484,26 +3129,35 @@
 
 struct kn { short offset; int code; };
 
-#undef _nc_keyname
-char	*_nc_keyname(
+#undef keyname_sp
+const char *keyname_sp(
 		SCREEN	*sp, 
 		int	c)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 #undef keyname
-char	*keyname(
+const char *keyname(
 		int	c)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 /* ./tinfo/lib_longname.c */
 
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
 #undef longname
 char	*longname(void)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_napms.c */
 
-#include <time.h>
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
 
 #undef napms
 int	napms(
@@ -2524,6 +3178,12 @@
 		NCURSES_BOOL flag)
 		{ /* void */ }
 
+#undef halfdelay_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
 #undef halfdelay
 int	halfdelay(
 		int	t)
@@ -2559,53 +3219,115 @@
 		NCURSES_BOOL flag)
 		{ return(*(int *)0); }
 
+#undef curs_set_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
 #undef curs_set
 int	curs_set(
 		int	vis)
 		{ return(*(int *)0); }
 
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
 #undef typeahead
 int	typeahead(
 		int	fd)
 		{ return(*(int *)0); }
 
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
 #undef has_key
 int	has_key(
 		int	keycode)
 		{ return(*(int *)0); }
 
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
 #undef _nc_keypad
 int	_nc_keypad(
 		SCREEN	*sp, 
-		NCURSES_BOOL flag)
+		int	flag)
 		{ return(*(int *)0); }
 
 /* ./tinfo/lib_raw.c */
 
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef raw
 int	raw(void)
 		{ return(*(int *)0); }
 
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef cbreak
 int	cbreak(void)
 		{ return(*(int *)0); }
 
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef qiflush
 void	qiflush(void)
 		{ /* void */ }
 
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef noraw
 int	noraw(void)
 		{ return(*(int *)0); }
 
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nocbreak
 int	nocbreak(void)
 		{ return(*(int *)0); }
 
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef noqiflush
 void	noqiflush(void)
 		{ /* void */ }
 
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
 #undef intrflush
 int	intrflush(
 		WINDOW	*win, 
@@ -2614,10 +3336,6 @@
 
 /* ./tinfo/lib_setup.c */
 
-#include <locale.h>
-#include <sys/ioctl.h>
-#include <langinfo.h>
-
 #undef ttytype
 char	ttytype[256];
 #undef LINES
@@ -2627,6 +3345,12 @@
 #undef TABSIZE
 int	TABSIZE;
 
+#undef set_tabsize_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ return(*(int *)0); }
+
 #undef set_tabsize
 int	set_tabsize(
 		int	value)
@@ -2637,11 +3361,28 @@
 		SCREEN	*sp)
 		{ return(*(int *)0); }
 
+#undef use_env_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
 #undef use_env
 void	use_env(
 		NCURSES_BOOL f)
 		{ /* void */ }
 
+#undef use_tioctl
+void	use_tioctl(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
 #undef _nc_get_screensize
 void	_nc_get_screensize(
 		SCREEN	*sp, 
@@ -2654,6 +3395,18 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef _nc_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* void */ }
+
 #undef _nc_get_locale
 char	*_nc_get_locale(void)
 		{ return(*(char **)0); }
@@ -2669,15 +3422,19 @@
 
 #undef _nc_setupterm
 int	_nc_setupterm(
-		char	*tname, 
+		const char *tname, 
 		int	Filedes, 
 		int	*errret, 
-		NCURSES_BOOL reuse)
+		int	reuse)
 		{ return(*(int *)0); }
 
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
 #undef setupterm
 int	setupterm(
-		char	*tname, 
+		const char *tname, 
 		int	Filedes, 
 		int	*errret)
 		{ return(*(int *)0); }
@@ -2689,36 +3446,61 @@
 #undef BC
 char	*BC;
 
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
 #undef tgetent
 int	tgetent(
 		char	*bufp, 
 		const char *name)
 		{ return(*(int *)0); }
 
-#if 0
-
-#include <capdefaults.c>
-
-#endif
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
 
 #undef tgetflag
 int	tgetflag(
-		char	*id)
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
 		{ return(*(int *)0); }
 
 #undef tgetnum
 int	tgetnum(
-		char	*id)
+		const char *id)
 		{ return(*(int *)0); }
 
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
 #undef tgetstr
 char	*tgetstr(
-		char	*id, 
+		const char *id, 
 		char	**area)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_termname.c */
 
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
 #undef termname
 char	*termname(void)
 		{ return(*(char **)0); }
@@ -2734,19 +3516,37 @@
 
 /* ./tinfo/lib_ti.c */
 
+#undef tigetflag_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
 #undef tigetflag
 int	tigetflag(
-		char	*str)
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
 		{ return(*(int *)0); }
 
 #undef tigetnum
 int	tigetnum(
-		char	*str)
+		const char *str)
 		{ return(*(int *)0); }
 
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
 #undef tigetstr
 char	*tigetstr(
-		char	*str)
+		const char *str)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_tparm.c */
@@ -2758,12 +3558,18 @@
 int	_nc_tparm_analyze(
 		const char *string, 
 		char	*p_is_s[9], 
-		int	*popcount)
+		int	*_nc_popcount)
 		{ return(*(int *)0); }
 
 #undef tparm
 char	*tparm(
-		char	*string, 
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
 		...)
 		{ return(*(char **)0); }
 
@@ -2772,7 +3578,7 @@
 #undef PC
 char	PC;
 #undef ospeed
-NCURSES_OSPEED	ospeed;
+short	ospeed;
 #undef _nc_nulls_sent
 int	_nc_nulls_sent;
 
@@ -2781,25 +3587,86 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef delay_output_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
 #undef delay_output
 int	delay_output(
 		int	ms)
 		{ return(*(int *)0); }
 
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_flush
 void	_nc_flush(void)
 		{ /* void */ }
 
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
 #undef _nc_outch
 int	_nc_outch(
 		int	ch)
 		{ return(*(int *)0); }
 
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
 #undef putp
 int	putp(
 		const char *string)
 		{ return(*(int *)0); }
 
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(int *)0); }
+
 #undef tputs
 int	tputs(
 		const char *string, 
@@ -2830,9 +3697,14 @@
 
 #undef _nc_retrace_bool
 NCURSES_BOOL _nc_retrace_bool(
-		NCURSES_BOOL code)
+		int	code)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)0); }
+
 #undef _nc_retrace_int
 int	_nc_retrace_int(
 		int	code)
@@ -2854,9 +3726,9 @@
 		{ return(*(const char **)0); }
 
 #undef _nc_retrace_cvoid_ptr
-void	*_nc_retrace_cvoid_ptr(
-		void	*code)
-		{ return(*(void **)0); }
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const void **)0); }
 
 #undef _nc_retrace_void_ptr
 void	*_nc_retrace_void_ptr(
@@ -2886,6 +3758,11 @@
 		attr_t	newmode)
 		{ return(*(char **)0); }
 
+#undef _nc_retrace_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)0); }
+
 #undef _nc_retrace_attr_t
 attr_t	_nc_retrace_attr_t(
 		attr_t	code)
@@ -2917,7 +3794,7 @@
 
 typedef struct {
     unsigned int val;
-    const char *name;
+    const char name[8];
 } BITNAMES;
 
 #undef _nc_trace_ttymode
@@ -2944,36 +3821,78 @@
 
 /* ./tinfo/lib_ttyflags.c */
 
+#undef _nc_get_tty_mode_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
 #undef _nc_get_tty_mode
 int	_nc_get_tty_mode(
 		struct termios *buf)
 		{ return(*(int *)0); }
 
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef def_shell_mode
 int	def_shell_mode(void)
 		{ return(*(int *)0); }
 
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef def_prog_mode
 int	def_prog_mode(void)
 		{ return(*(int *)0); }
 
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef reset_prog_mode
 int	reset_prog_mode(void)
 		{ return(*(int *)0); }
 
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef reset_shell_mode
 int	reset_shell_mode(void)
 		{ return(*(int *)0); }
 
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef savetty
 int	savetty(void)
 		{ return(*(int *)0); }
 
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef resetty
 int	resetty(void)
 		{ return(*(int *)0); }
@@ -3005,21 +3924,39 @@
 /* ./names.c */
 
 #undef boolnames
-char	*const boolnames[] = {0};
+const char *const boolnames[] = {0};
 #undef boolfnames
-char	*const boolfnames[] = {0};
+const char *const boolfnames[] = {0};
 #undef numnames
-char	*const numnames[] = {0};
+const char *const numnames[] = {0};
 #undef numfnames
-char	*const numfnames[] = {0};
+const char *const numfnames[] = {0};
 #undef strnames
-char	*const strnames[] = {0};
+const char *const strnames[] = {0};
 #undef strfnames
-char	*const strfnames[] = {0};
+const char *const strfnames[] = {0};
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
 
 /* ./tinfo/read_entry.c */
 
-#include <hashed_db.h>
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
 
 #undef _nc_read_termtype
 int	_nc_read_termtype(
@@ -3043,20 +3980,8 @@
 
 /* ./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)
+#undef _nc_read_termcap
+void	_nc_read_termcap(void)
 		{ /* void */ }
 
 /* ./tinfo/strings.c */
@@ -3144,16 +4069,16 @@
 
 /* ./unctrl.c */
 
-#undef _nc_unctrl
-char	*_nc_unctrl(
+#undef unctrl_sp
+const char *unctrl_sp(
 		SCREEN	*sp, 
 		chtype	ch)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 #undef unctrl
-char	*unctrl(
+const char *unctrl(
 		chtype	ch)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 /* ./trace/visbuf.c */
 
@@ -3232,25 +4157,6 @@
 		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
@@ -3260,21 +4166,6 @@
 		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
@@ -3316,6 +4207,8 @@
 
 #undef _nc_syntax
 int	_nc_syntax;
+#undef _nc_strict_bsd
+int	_nc_strict_bsd;
 #undef _nc_curr_file_pos
 long	_nc_curr_file_pos;
 #undef _nc_comment_start
@@ -3372,15 +4265,15 @@
 		{ return(*(int *)0); }
 
 typedef struct {
-    const char *from;
-    const char *to;
+    const char from[3];
+    const char to[6];
 } assoc;
 
 /* ./tinfo/write_entry.c */
 
 #undef _nc_set_writedir
 void	_nc_set_writedir(
-		char	*dir)
+		const char *dir)
 		{ /* void */ }
 
 #undef _nc_write_entry
@@ -3394,6 +4287,13 @@
 
 /* ./base/define_key.c */
 
+#undef define_key_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
 #undef define_key
 int	define_key(
 		const char *str, 
@@ -3408,6 +4308,12 @@
 
 /* ./base/key_defined.c */
 
+#undef key_defined_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
 #undef key_defined
 int	key_defined(
 		const char *str)
@@ -3415,6 +4321,13 @@
 
 /* ./base/keybound.c */
 
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
 #undef keybound
 char	*keybound(
 		int	code, 
@@ -3423,6 +4336,13 @@
 
 /* ./base/keyok.c */
 
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
 #undef keyok
 int	keyok(
 		int	c, 
diff --git a/ncurses/llib-lncursest b/ncurses/llib-lncursest
index d29ef60..c787f30 100644
--- a/ncurses/llib-lncursest
+++ b/ncurses/llib-lncursest
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2008 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2008-2013,2015 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            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey 2008                                           *
+ *  Author: Thomas E. Dickey       2008-on                                  *
  ****************************************************************************/
 /* LINTLIBRARY */
 
@@ -38,27 +38,54 @@
 #undef _nc_oldnums
 int	*_nc_oldnums;
 
+#undef _nc_scroll_optimize_sp
+void	_nc_scroll_optimize_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_scroll_optimize
 void	_nc_scroll_optimize(void)
 		{ /* void */ }
 
+#undef _nc_linedump_sp
+void	_nc_linedump_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_linedump
 void	_nc_linedump(void)
 		{ /* void */ }
 
 /* ./tty/hashmap.c */
 
-#include <term.h>
+#undef _nc_hash_map_sp
+void	_nc_hash_map_sp(
+		SCREEN	*sp)
+		{ /* void */ }
 
 #undef _nc_hash_map
 void	_nc_hash_map(void)
 		{ /* void */ }
 
+#undef _nc_make_oldhash_sp
+void	_nc_make_oldhash_sp(
+		SCREEN	*sp, 
+		int	i)
+		{ /* void */ }
+
 #undef _nc_make_oldhash
 void	_nc_make_oldhash(
 		int	i)
 		{ /* void */ }
 
+#undef _nc_scroll_oldhash_sp
+void	_nc_scroll_oldhash_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
 #undef _nc_scroll_oldhash
 void	_nc_scroll_oldhash(
 		int	n, 
@@ -68,8 +95,6 @@
 
 /* ./base/lib_addch.c */
 
-#include <ctype.h>
-
 #undef _nc_render
 chtype	_nc_render(
 		WINDOW	*win, 
@@ -112,6 +137,11 @@
 
 /* ./base/lib_beep.c */
 
+#undef beep_sp
+int	beep_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef beep
 int	beep(void)
 		{ return(*(int *)0); }
@@ -187,8 +217,6 @@
 
 /* ./base/lib_color.c */
 
-#include <tic.h>
-
 #undef _nc_COLOR_PAIRS
 int	_nc_COLOR_PAIRS(void)
 		{ return(*(int *)0); }
@@ -197,14 +225,32 @@
 int	_nc_COLORS(void)
 		{ return(*(int *)0); }
 
+#undef _nc_reset_colors_sp
+NCURSES_BOOL _nc_reset_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef _nc_reset_colors
 NCURSES_BOOL _nc_reset_colors(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef start_color_sp
+int	start_color_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef start_color
 int	start_color(void)
 		{ return(*(int *)0); }
 
+#undef init_pair_sp
+int	init_pair_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
 #undef init_pair
 int	init_pair(
 		short	pair, 
@@ -212,6 +258,15 @@
 		short	b)
 		{ return(*(int *)0); }
 
+#undef init_color_sp
+int	init_color_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	r, 
+		short	g, 
+		short	b)
+		{ return(*(int *)0); }
+
 #undef init_color
 int	init_color(
 		short	color, 
@@ -220,14 +275,33 @@
 		short	b)
 		{ return(*(int *)0); }
 
+#undef can_change_color_sp
+NCURSES_BOOL can_change_color_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef can_change_color
 NCURSES_BOOL can_change_color(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef has_colors_sp
+NCURSES_BOOL has_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_colors
 NCURSES_BOOL has_colors(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef color_content_sp
+int	color_content_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
 #undef color_content
 int	color_content(
 		short	color, 
@@ -236,6 +310,14 @@
 		short	*b)
 		{ return(*(int *)0); }
 
+#undef pair_content_sp
+int	pair_content_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
 #undef pair_content
 int	pair_content(
 		short	pair, 
@@ -243,13 +325,21 @@
 		short	*b)
 		{ return(*(int *)0); }
 
+#undef _nc_do_color_sp
+void	_nc_do_color_sp(
+		SCREEN	*sp, 
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC_sp outc)
+		{ /* void */ }
+
 #undef _nc_do_color
 void	_nc_do_color(
-		short	old_pair, 
-		short	pair, 
-		NCURSES_BOOL reverse, 
-		int	(*outc)(
-		int	p1))
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC outc)
 		{ /* void */ }
 
 /* ./base/lib_colorset.c */
@@ -277,16 +367,31 @@
 
 /* ./base/lib_echo.c */
 
+#undef echo_sp
+int	echo_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef echo
 int	echo(void)
 		{ return(*(int *)0); }
 
+#undef noecho_sp
+int	noecho_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef noecho
 int	noecho(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_endwin.c */
 
+#undef endwin_sp
+int	endwin_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef endwin
 int	endwin(void)
 		{ return(*(int *)0); }
@@ -300,6 +405,11 @@
 
 /* ./base/lib_flash.c */
 
+#undef flash_sp
+int	flash_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef flash
 int	flash(void)
 		{ return(*(int *)0); }
@@ -307,85 +417,85 @@
 /* ./lib_gen.c */
 
 #undef addch
-int	addch(
+int	(addch)(
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef addchnstr
-int	addchnstr(
+int	(addchnstr)(
 		const chtype *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef addchstr
-int	addchstr(
+int	(addchstr)(
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef addnstr
-int	addnstr(
+int	(addnstr)(
 		const char *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef addstr
-int	addstr(
+int	(addstr)(
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef attroff
-int	attroff(
+int	(attroff)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attron
-int	attron(
+int	(attron)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attrset
-int	attrset(
+int	(attrset)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attr_get
-int	attr_get(
+int	(attr_get)(
 		attr_t	*a1, 
 		short	*a2, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_off
-int	attr_off(
+int	(attr_off)(
 		attr_t	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_on
-int	attr_on(
+int	(attr_on)(
 		attr_t	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_set
-int	attr_set(
+int	(attr_set)(
 		attr_t	a1, 
 		short	a2, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef bkgd
-int	bkgd(
+int	(bkgd)(
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef bkgdset
-void	bkgdset(
+void	(bkgdset)(
 		chtype	z)
 		{ /* void */ }
 
 #undef border
-int	border(
+int	(border)(
 		chtype	a1, 
 		chtype	a2, 
 		chtype	a3, 
@@ -397,14 +507,14 @@
 		{ return(*(int *)0); }
 
 #undef box
-int	box(
+int	(box)(
 		WINDOW	*a1, 
 		chtype	a2, 
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef chgat
-int	chgat(
+int	(chgat)(
 		int	a1, 
 		attr_t	a2, 
 		short	a3, 
@@ -412,137 +522,137 @@
 		{ return(*(int *)0); }
 
 #undef clear
-int	clear(void)
+int	(clear)(void)
 		{ return(*(int *)0); }
 
 #undef clrtobot
-int	clrtobot(void)
+int	(clrtobot)(void)
 		{ return(*(int *)0); }
 
 #undef clrtoeol
-int	clrtoeol(void)
+int	(clrtoeol)(void)
 		{ return(*(int *)0); }
 
 #undef color_set
-int	color_set(
+int	(color_set)(
 		short	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef COLOR_PAIR
-int	COLOR_PAIR(
+int	(COLOR_PAIR)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef delch
-int	delch(void)
+int	(delch)(void)
 		{ return(*(int *)0); }
 
 #undef deleteln
-int	deleteln(void)
+int	(deleteln)(void)
 		{ return(*(int *)0); }
 
 #undef echochar
-int	echochar(
+int	(echochar)(
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef erase
-int	erase(void)
+int	(erase)(void)
 		{ return(*(int *)0); }
 
 #undef getbkgd
-chtype	getbkgd(
+chtype	(getbkgd)(
 		WINDOW	*z)
 		{ return(*(chtype *)0); }
 
 #undef getch
-int	getch(void)
+int	(getch)(void)
 		{ return(*(int *)0); }
 
 #undef getnstr
-int	getnstr(
+int	(getnstr)(
 		char	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef getstr
-int	getstr(
+int	(getstr)(
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef hline
-int	hline(
+int	(hline)(
 		chtype	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef inch
-chtype	inch(void)
+chtype	(inch)(void)
 		{ return(*(chtype *)0); }
 
 #undef inchnstr
-int	inchnstr(
+int	(inchnstr)(
 		chtype	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef inchstr
-int	inchstr(
+int	(inchstr)(
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef innstr
-int	innstr(
+int	(innstr)(
 		char	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insch
-int	insch(
+int	(insch)(
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef insdelln
-int	insdelln(
+int	(insdelln)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insertln
-int	insertln(void)
+int	(insertln)(void)
 		{ return(*(int *)0); }
 
 #undef insnstr
-int	insnstr(
+int	(insnstr)(
 		const char *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insstr
-int	insstr(
+int	(insstr)(
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef instr
-int	instr(
+int	(instr)(
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef move
-int	move(
+int	(move)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvaddch
-int	mvaddch(
+int	(mvaddch)(
 		int	a1, 
 		int	a2, 
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef mvaddchnstr
-int	mvaddchnstr(
+int	(mvaddchnstr)(
 		int	a1, 
 		int	a2, 
 		const chtype *a3, 
@@ -550,14 +660,14 @@
 		{ return(*(int *)0); }
 
 #undef mvaddchstr
-int	mvaddchstr(
+int	(mvaddchstr)(
 		int	a1, 
 		int	a2, 
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef mvaddnstr
-int	mvaddnstr(
+int	(mvaddnstr)(
 		int	a1, 
 		int	a2, 
 		const char *a3, 
@@ -565,14 +675,14 @@
 		{ return(*(int *)0); }
 
 #undef mvaddstr
-int	mvaddstr(
+int	(mvaddstr)(
 		int	a1, 
 		int	a2, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef mvchgat
-int	mvchgat(
+int	(mvchgat)(
 		int	a1, 
 		int	a2, 
 		int	a3, 
@@ -582,19 +692,19 @@
 		{ return(*(int *)0); }
 
 #undef mvdelch
-int	mvdelch(
+int	(mvdelch)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvgetch
-int	mvgetch(
+int	(mvgetch)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvgetnstr
-int	mvgetnstr(
+int	(mvgetnstr)(
 		int	a1, 
 		int	a2, 
 		char	*a3, 
@@ -602,14 +712,14 @@
 		{ return(*(int *)0); }
 
 #undef mvgetstr
-int	mvgetstr(
+int	(mvgetstr)(
 		int	a1, 
 		int	a2, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef mvhline
-int	mvhline(
+int	(mvhline)(
 		int	a1, 
 		int	a2, 
 		chtype	a3, 
@@ -617,13 +727,13 @@
 		{ return(*(int *)0); }
 
 #undef mvinch
-chtype	mvinch(
+chtype	(mvinch)(
 		int	a1, 
 		int	z)
 		{ return(*(chtype *)0); }
 
 #undef mvinchnstr
-int	mvinchnstr(
+int	(mvinchnstr)(
 		int	a1, 
 		int	a2, 
 		chtype	*a3, 
@@ -631,14 +741,14 @@
 		{ return(*(int *)0); }
 
 #undef mvinchstr
-int	mvinchstr(
+int	(mvinchstr)(
 		int	a1, 
 		int	a2, 
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef mvinnstr
-int	mvinnstr(
+int	(mvinnstr)(
 		int	a1, 
 		int	a2, 
 		char	*a3, 
@@ -646,14 +756,14 @@
 		{ return(*(int *)0); }
 
 #undef mvinsch
-int	mvinsch(
+int	(mvinsch)(
 		int	a1, 
 		int	a2, 
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef mvinsnstr
-int	mvinsnstr(
+int	(mvinsnstr)(
 		int	a1, 
 		int	a2, 
 		const char *a3, 
@@ -661,21 +771,21 @@
 		{ return(*(int *)0); }
 
 #undef mvinsstr
-int	mvinsstr(
+int	(mvinsstr)(
 		int	a1, 
 		int	a2, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef mvinstr
-int	mvinstr(
+int	(mvinstr)(
 		int	a1, 
 		int	a2, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef mvvline
-int	mvvline(
+int	(mvvline)(
 		int	a1, 
 		int	a2, 
 		chtype	a3, 
@@ -683,7 +793,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddch
-int	mvwaddch(
+int	(mvwaddch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -691,7 +801,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddchnstr
-int	mvwaddchnstr(
+int	(mvwaddchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -700,7 +810,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddchstr
-int	mvwaddchstr(
+int	(mvwaddchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -708,7 +818,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddnstr
-int	mvwaddnstr(
+int	(mvwaddnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -717,7 +827,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddstr
-int	mvwaddstr(
+int	(mvwaddstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -725,7 +835,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwchgat
-int	mvwchgat(
+int	(mvwchgat)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -736,21 +846,21 @@
 		{ return(*(int *)0); }
 
 #undef mvwdelch
-int	mvwdelch(
+int	(mvwdelch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvwgetch
-int	mvwgetch(
+int	(mvwgetch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvwgetnstr
-int	mvwgetnstr(
+int	(mvwgetnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -759,7 +869,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwgetstr
-int	mvwgetstr(
+int	(mvwgetstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -767,7 +877,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwhline
-int	mvwhline(
+int	(mvwhline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -776,14 +886,14 @@
 		{ return(*(int *)0); }
 
 #undef mvwinch
-chtype	mvwinch(
+chtype	(mvwinch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(chtype *)0); }
 
 #undef mvwinchnstr
-int	mvwinchnstr(
+int	(mvwinchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -792,7 +902,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinchstr
-int	mvwinchstr(
+int	(mvwinchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -800,7 +910,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinnstr
-int	mvwinnstr(
+int	(mvwinnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -809,7 +919,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsch
-int	mvwinsch(
+int	(mvwinsch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -817,7 +927,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsnstr
-int	mvwinsnstr(
+int	(mvwinsnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -826,7 +936,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsstr
-int	mvwinsstr(
+int	(mvwinsstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -834,7 +944,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinstr
-int	mvwinstr(
+int	(mvwinstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -842,7 +952,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwvline
-int	mvwvline(
+int	(mvwvline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -851,117 +961,117 @@
 		{ return(*(int *)0); }
 
 #undef PAIR_NUMBER
-int	PAIR_NUMBER(
+int	(PAIR_NUMBER)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef redrawwin
-int	redrawwin(
+int	(redrawwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef refresh
-int	refresh(void)
+int	(refresh)(void)
 		{ return(*(int *)0); }
 
 #undef scrl
-int	scrl(
+int	(scrl)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef scroll
-int	scroll(
+int	(scroll)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef setscrreg
-int	setscrreg(
+int	(setscrreg)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef standout
-int	standout(void)
+int	(standout)(void)
 		{ return(*(int *)0); }
 
 #undef standend
-int	standend(void)
+int	(standend)(void)
 		{ return(*(int *)0); }
 
 #undef timeout
-void	timeout(
+void	(timeout)(
 		int	z)
 		{ /* void */ }
 
 #undef touchline
-int	touchline(
+int	(touchline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef touchwin
-int	touchwin(
+int	(touchwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef untouchwin
-int	untouchwin(
+int	(untouchwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef vline
-int	vline(
+int	(vline)(
 		chtype	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef vw_printw
-int	vw_printw(
+int	(vw_printw)(
 		WINDOW	*a1, 
 		const char *a2, 
 		va_list	z)
 		{ return(*(int *)0); }
 
 #undef vw_scanw
-int	vw_scanw(
+int	(vw_scanw)(
 		WINDOW	*a1, 
-		char	*a2, 
+		const char *a2, 
 		va_list	z)
 		{ return(*(int *)0); }
 
 #undef waddchstr
-int	waddchstr(
+int	(waddchstr)(
 		WINDOW	*a1, 
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef waddstr
-int	waddstr(
+int	(waddstr)(
 		WINDOW	*a1, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef wattron
-int	wattron(
+int	(wattron)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattroff
-int	wattroff(
+int	(wattroff)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattrset
-int	wattrset(
+int	(wattrset)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattr_get
-int	wattr_get(
+int	(wattr_get)(
 		WINDOW	*a1, 
 		attr_t	*a2, 
 		short	*a3, 
@@ -969,7 +1079,7 @@
 		{ return(*(int *)0); }
 
 #undef wattr_set
-int	wattr_set(
+int	(wattr_set)(
 		WINDOW	*a1, 
 		attr_t	a2, 
 		short	a3, 
@@ -977,158 +1087,173 @@
 		{ return(*(int *)0); }
 
 #undef wdeleteln
-int	wdeleteln(
+int	(wdeleteln)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef wgetstr
-int	wgetstr(
+int	(wgetstr)(
 		WINDOW	*a1, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef winchstr
-int	winchstr(
+int	(winchstr)(
 		WINDOW	*a1, 
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef winsertln
-int	winsertln(
+int	(winsertln)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef winsstr
-int	winsstr(
+int	(winsstr)(
 		WINDOW	*a1, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef winstr
-int	winstr(
+int	(winstr)(
 		WINDOW	*a1, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef wstandout
-int	wstandout(
+int	(wstandout)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef wstandend
-int	wstandend(
+int	(wstandend)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef getattrs
-int	getattrs(
+int	(getattrs)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getcurx
-int	getcurx(
+int	(getcurx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getcury
-int	getcury(
+int	(getcury)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getbegx
-int	getbegx(
+int	(getbegx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getbegy
-int	getbegy(
+int	(getbegy)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getmaxx
-int	getmaxx(
+int	(getmaxx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getmaxy
-int	getmaxy(
+int	(getmaxy)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getparx
-int	getparx(
+int	(getparx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getpary
-int	getpary(
+int	(getpary)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef wgetparent
-WINDOW	*wgetparent(
+WINDOW	*(wgetparent)(
 		const WINDOW *z)
 		{ return(*(WINDOW **)0); }
 
 #undef is_cleared
-NCURSES_BOOL is_cleared(
+NCURSES_BOOL (is_cleared)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_idcok
-NCURSES_BOOL is_idcok(
+NCURSES_BOOL (is_idcok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_idlok
-NCURSES_BOOL is_idlok(
+NCURSES_BOOL (is_idlok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_immedok
-NCURSES_BOOL is_immedok(
+NCURSES_BOOL (is_immedok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_keypad
-NCURSES_BOOL is_keypad(
+NCURSES_BOOL (is_keypad)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_leaveok
-NCURSES_BOOL is_leaveok(
+NCURSES_BOOL (is_leaveok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_nodelay
-NCURSES_BOOL is_nodelay(
+NCURSES_BOOL (is_nodelay)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_notimeout
-NCURSES_BOOL is_notimeout(
+NCURSES_BOOL (is_notimeout)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_pad
+NCURSES_BOOL (is_pad)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_scrollok
-NCURSES_BOOL is_scrollok(
+NCURSES_BOOL (is_scrollok)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_subwin
+NCURSES_BOOL (is_subwin)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_syncok
-NCURSES_BOOL is_syncok(
+NCURSES_BOOL (is_syncok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef wgetdelay
+int	(wgetdelay)(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
 #undef wgetscrreg
-int	wgetscrreg(
+int	(wgetscrreg)(
 		const WINDOW *a1, 
 		int	*a2, 
 		int	*z)
 		{ return(*(int *)0); }
 
 #undef mouse_trafo
-NCURSES_BOOL mouse_trafo(
+NCURSES_BOOL (mouse_trafo)(
 		int	*a1, 
 		int	*a2, 
 		NCURSES_BOOL z)
@@ -1136,21 +1261,39 @@
 
 /* ./base/lib_getch.c */
 
-#include <fifo_defs.h>
-
 #undef _nc_ESCDELAY
 int	_nc_ESCDELAY(void)
 		{ return(*(int *)0); }
 
+#undef _nc_ptr_Escdelay
+int	*_nc_ptr_Escdelay(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef set_escdelay_sp
+int	set_escdelay_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ return(*(int *)0); }
+
 #undef set_escdelay
 int	set_escdelay(
 		int	value)
 		{ return(*(int *)0); }
 
+#undef get_escdelay_sp
+int	get_escdelay_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef get_escdelay
+int	get_escdelay(void)
+		{ return(*(int *)0); }
+
 #undef _nc_wgetch
 int	_nc_wgetch(
 		WINDOW	*win, 
-		unsigned long *result, 
+		int	*result, 
 		int	use_meta)
 		{ return(*(int *)0); }
 
@@ -1204,6 +1347,7 @@
 
 #undef _nc_insert_ch
 int	_nc_insert_ch(
+		SCREEN	*sp, 
 		WINDOW	*win, 
 		chtype	ch)
 		{ return(*(int *)0); }
@@ -1242,6 +1386,11 @@
 
 /* ./base/lib_isendwin.c */
 
+#undef isendwin_sp
+NCURSES_BOOL isendwin_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef isendwin
 NCURSES_BOOL isendwin(void)
 		{ return(*(NCURSES_BOOL *)0); }
@@ -1256,16 +1405,35 @@
 
 /* ./base/lib_mouse.c */
 
+#undef getmouse_sp
+int	getmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
 #undef getmouse
 int	getmouse(
 		MEVENT	*aevent)
 		{ return(*(int *)0); }
 
+#undef ungetmouse_sp
+int	ungetmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
 #undef ungetmouse
 int	ungetmouse(
 		MEVENT	*aevent)
 		{ return(*(int *)0); }
 
+#undef mousemask_sp
+mmask_t	mousemask_sp(
+		SCREEN	*sp, 
+		mmask_t	newmask, 
+		mmask_t	*oldmask)
+		{ return(*(mmask_t *)0); }
+
 #undef mousemask
 mmask_t	mousemask(
 		mmask_t	newmask, 
@@ -1279,14 +1447,30 @@
 		int	x)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef mouseinterval_sp
+int	mouseinterval_sp(
+		SCREEN	*sp, 
+		int	maxclick)
+		{ return(*(int *)0); }
+
 #undef mouseinterval
 int	mouseinterval(
 		int	maxclick)
 		{ return(*(int *)0); }
 
 #undef _nc_has_mouse
-int	_nc_has_mouse(void)
-		{ return(*(int *)0); }
+NCURSES_BOOL _nc_has_mouse(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse_sp
+NCURSES_BOOL has_mouse_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse
+NCURSES_BOOL has_mouse(void)
+		{ return(*(NCURSES_BOOL *)0); }
 
 #undef wmouse_trafo
 NCURSES_BOOL wmouse_trafo(
@@ -1307,24 +1491,72 @@
 
 /* ./tty/lib_mvcur.c */
 
+#undef _nc_msec_cost_sp
+int	_nc_msec_cost_sp(
+		SCREEN	*sp, 
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
 #undef _nc_msec_cost
 int	_nc_msec_cost(
 		const char *const cap, 
 		int	affcnt)
 		{ return(*(int *)0); }
 
+#undef _nc_mvcur_resume_sp
+void	_nc_mvcur_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_resume
 void	_nc_mvcur_resume(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_init_sp
+void	_nc_mvcur_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_init
 void	_nc_mvcur_init(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_wrap_sp
+void	_nc_mvcur_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_wrap
 void	_nc_mvcur_wrap(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_sp
+int	_nc_mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur
+int	_nc_mvcur(
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef mvcur_sp
+int	mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
 #undef mvcur
 int	mvcur(
 		int	yold, 
@@ -1347,17 +1579,35 @@
 
 /* ./base/lib_newterm.c */
 
+#undef filter_sp
+void	filter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef filter
 void	filter(void)
 		{ /* void */ }
 
+#undef nofilter_sp
+void	nofilter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef nofilter
 void	nofilter(void)
 		{ /* void */ }
 
+#undef newterm_sp
+SCREEN	*newterm_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		FILE	*ofp, 
+		FILE	*ifp)
+		{ return(*(SCREEN **)0); }
+
 #undef newterm
 SCREEN	*newterm(
-		char	*name, 
+		const char *name, 
 		FILE	*ofp, 
 		FILE	*ifp)
 		{ return(*(SCREEN **)0); }
@@ -1369,6 +1619,15 @@
 		WINDOW	*win)
 		{ return(*(int *)0); }
 
+#undef newwin_sp
+WINDOW	*newwin_sp(
+		SCREEN	*sp, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
 #undef newwin
 WINDOW	*newwin(
 		int	num_lines, 
@@ -1395,8 +1654,9 @@
 		int	x)
 		{ return(*(WINDOW **)0); }
 
-#undef _nc_makenew
-WINDOW	*_nc_makenew(
+#undef _nc_makenew_sp
+WINDOW	*_nc_makenew_sp(
+		SCREEN	*sp, 
 		int	num_lines, 
 		int	num_columns, 
 		int	begy, 
@@ -1404,17 +1664,37 @@
 		int	flags)
 		{ return(*(WINDOW **)0); }
 
-#undef _nc_screen_of
-SCREEN	*_nc_screen_of(
-		WINDOW	*win)
-		{ return(*(SCREEN **)0); }
+#undef _nc_curscr_of
+WINDOW	*_nc_curscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_newscr_of
+WINDOW	*_nc_newscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_stdscr_of
+WINDOW	*_nc_stdscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
 
 /* ./base/lib_nl.c */
 
+#undef nl_sp
+int	nl_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nl
 int	nl(void)
 		{ return(*(int *)0); }
 
+#undef nonl_sp
+int	nonl_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nonl
 int	nonl(void)
 		{ return(*(int *)0); }
@@ -1448,6 +1728,13 @@
 
 /* ./base/lib_pad.c */
 
+#undef newpad_sp
+WINDOW	*newpad_sp(
+		SCREEN	*sp, 
+		int	l, 
+		int	c)
+		{ return(*(WINDOW **)0); }
+
 #undef newpad
 WINDOW	*newpad(
 		int	l, 
@@ -1553,9 +1840,17 @@
 
 /* ./base/lib_restart.c */
 
+#undef restartterm_sp
+int	restartterm_sp(
+		SCREEN	*sp, 
+		const char *termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
 #undef restartterm
 int	restartterm(
-		char	*termp, 
+		const char *termp, 
 		int	filenum, 
 		int	*errret)
 		{ return(*(int *)0); }
@@ -1565,20 +1860,20 @@
 #undef vwscanw
 int	vwscanw(
 		WINDOW	*win, 
-		char	*fmt, 
+		const char *fmt, 
 		va_list	argp)
 		{ return(*(int *)0); }
 
 #undef scanw
 int	scanw(
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
 #undef wscanw
 int	wscanw(
 		WINDOW	*win, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
@@ -1586,7 +1881,7 @@
 int	mvscanw(
 		int	y, 
 		int	x, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
@@ -1595,12 +1890,18 @@
 		WINDOW	*win, 
 		int	y, 
 		int	x, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
 /* ./base/lib_screen.c */
 
+#undef getwin_sp
+WINDOW	*getwin_sp(
+		SCREEN	*sp, 
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
 #undef getwin
 WINDOW	*getwin(
 		FILE	*filep)
@@ -1612,6 +1913,12 @@
 		FILE	*filep)
 		{ return(*(int *)0); }
 
+#undef scr_restore_sp
+int	scr_restore_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_restore
 int	scr_restore(
 		const char *file)
@@ -1622,11 +1929,23 @@
 		const char *file)
 		{ return(*(int *)0); }
 
+#undef scr_init_sp
+int	scr_init_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_init
 int	scr_init(
 		const char *file)
 		{ return(*(int *)0); }
 
+#undef scr_set_sp
+int	scr_set_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_set
 int	scr_set(
 		const char *file)
@@ -1678,15 +1997,34 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef _nc_setupscreen_sp
+int	_nc_setupscreen_sp(
+		SCREEN	**spp, 
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		int	filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
 #undef _nc_setupscreen
 int	_nc_setupscreen(
 		int	slines, 
 		int	scolumns, 
 		FILE	*output, 
-		NCURSES_BOOL filtered, 
+		int	filtered, 
 		int	slk_format)
 		{ return(*(int *)0); }
 
+#undef _nc_ripoffline_sp
+int	_nc_ripoffline_sp(
+		SCREEN	*sp, 
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
 #undef _nc_ripoffline
 int	_nc_ripoffline(
 		int	line, 
@@ -1695,6 +2033,15 @@
 		int	p2))
 		{ return(*(int *)0); }
 
+#undef ripoffline_sp
+int	ripoffline_sp(
+		SCREEN	*sp, 
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
 #undef ripoffline
 int	ripoffline(
 		int	line, 
@@ -1705,18 +2052,37 @@
 
 /* ./base/lib_slk.c */
 
+#undef _nc_format_slks
+int	_nc_format_slks(
+		SCREEN	*sp, 
+		int	cols)
+		{ return(*(int *)0); }
+
 #undef _nc_slk_initialize
 int	_nc_slk_initialize(
 		WINDOW	*stwin, 
 		int	cols)
 		{ return(*(int *)0); }
 
+#undef slk_restore_sp
+int	slk_restore_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_restore
 int	slk_restore(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkatr_set.c */
 
+#undef slk_attr_set_sp
+int	slk_attr_set_sp(
+		SCREEN	*sp, 
+		const attr_t attr, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
 #undef slk_attr_set
 int	slk_attr_set(
 		const attr_t attr, 
@@ -1726,6 +2092,12 @@
 
 /* ./base/lib_slkatrof.c */
 
+#undef slk_attroff_sp
+int	slk_attroff_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attroff
 int	slk_attroff(
 		const chtype attr)
@@ -1733,6 +2105,12 @@
 
 /* ./base/lib_slkatron.c */
 
+#undef slk_attron_sp
+int	slk_attron_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attron
 int	slk_attron(
 		const chtype attr)
@@ -1740,6 +2118,12 @@
 
 /* ./base/lib_slkatrset.c */
 
+#undef slk_attrset_sp
+int	slk_attrset_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attrset
 int	slk_attrset(
 		const chtype attr)
@@ -1747,18 +2131,34 @@
 
 /* ./base/lib_slkattr.c */
 
+#undef slk_attr_sp
+attr_t	slk_attr_sp(
+		SCREEN	*sp)
+		{ return(*(attr_t *)0); }
+
 #undef slk_attr
 attr_t	slk_attr(void)
 		{ return(*(attr_t *)0); }
 
 /* ./base/lib_slkclear.c */
 
+#undef slk_clear_sp
+int	slk_clear_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_clear
 int	slk_clear(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkcolor.c */
 
+#undef slk_color_sp
+int	slk_color_sp(
+		SCREEN	*sp, 
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
 #undef slk_color
 int	slk_color(
 		short	color_pair_number)
@@ -1766,6 +2166,12 @@
 
 /* ./base/lib_slkinit.c */
 
+#undef slk_init_sp
+int	slk_init_sp(
+		SCREEN	*sp, 
+		int	format)
+		{ return(*(int *)0); }
+
 #undef slk_init
 int	slk_init(
 		int	format)
@@ -1773,6 +2179,12 @@
 
 /* ./base/lib_slklab.c */
 
+#undef slk_label_sp
+char	*slk_label_sp(
+		SCREEN	*sp, 
+		int	n)
+		{ return(*(char **)0); }
+
 #undef slk_label
 char	*slk_label(
 		int	n)
@@ -1780,16 +2192,34 @@
 
 /* ./base/lib_slkrefr.c */
 
+#undef slk_noutrefresh_sp
+int	slk_noutrefresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_noutrefresh
 int	slk_noutrefresh(void)
 		{ return(*(int *)0); }
 
+#undef slk_refresh_sp
+int	slk_refresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_refresh
 int	slk_refresh(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkset.c */
 
+#undef slk_set_sp
+int	slk_set_sp(
+		SCREEN	*sp, 
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
 #undef slk_set
 int	slk_set(
 		int	i, 
@@ -1799,6 +2229,11 @@
 
 /* ./base/lib_slktouch.c */
 
+#undef slk_touch_sp
+int	slk_touch_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_touch
 int	slk_touch(void)
 		{ return(*(int *)0); }
@@ -1834,12 +2269,24 @@
 
 /* ./trace/lib_tracemse.c */
 
+#undef _nc_trace_mmask_t
+char	*_nc_trace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(char **)0); }
+
 #undef _nc_tracemouse
 char	*_nc_tracemouse(
 		SCREEN	*sp, 
 		MEVENT const *ep)
 		{ return(*(char **)0); }
 
+#undef _nc_retrace_mmask_t
+mmask_t	_nc_retrace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(mmask_t *)0); }
+
 #undef _tracemouse
 char	*_tracemouse(
 		MEVENT const *ep)
@@ -1847,11 +2294,9 @@
 
 /* ./tty/lib_tstp.c */
 
-#include <SigAction.h>
-
 #undef _nc_signal_handler
 void	_nc_signal_handler(
-		NCURSES_BOOL enable)
+		int	enable)
 		{ /* void */ }
 
 /* ./base/lib_ungetch.c */
@@ -1861,8 +2306,8 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
-#undef _nc_ungetch
-int	_nc_ungetch(
+#undef ungetch_sp
+int	ungetch_sp(
 		SCREEN	*sp, 
 		int	ch)
 		{ return(*(int *)0); }
@@ -1874,11 +2319,23 @@
 
 /* ./tty/lib_vidattr.c */
 
+#undef vidputs_sp
+int	vidputs_sp(
+		SCREEN	*sp, 
+		chtype	newmode, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
 #undef vidputs
 int	vidputs(
 		chtype	newmode, 
-		int	(*outc)(
-		int	p1))
+		NCURSES_OUTC outc)
+		{ return(*(int *)0); }
+
+#undef vidattr_sp
+int	vidattr_sp(
+		SCREEN	*sp, 
+		chtype	newmode)
 		{ return(*(int *)0); }
 
 #undef vidattr
@@ -1886,6 +2343,11 @@
 		chtype	newmode)
 		{ return(*(int *)0); }
 
+#undef termattrs_sp
+chtype	termattrs_sp(
+		SCREEN	*sp)
+		{ return(*(chtype *)0); }
+
 #undef termattrs
 chtype	termattrs(void)
 		{ return(*(chtype *)0); }
@@ -1966,12 +2428,24 @@
 
 /* ./base/nc_panel.c */
 
+#undef _nc_panelhook_sp
+struct panelhook *_nc_panelhook_sp(
+		SCREEN	*sp)
+		{ return(*(struct panelhook **)0); }
+
 #undef _nc_panelhook
 struct panelhook *_nc_panelhook(void)
 		{ return(*(struct panelhook **)0); }
 
 /* ./base/safe_sprintf.c */
 
+#undef _nc_printf_string_sp
+char	*_nc_printf_string_sp(
+		SCREEN	*sp, 
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
 #undef _nc_printf_string
 char	*_nc_printf_string(
 		const char *fmt, 
@@ -1980,13 +2454,24 @@
 
 /* ./tty/tty_update.c */
 
-#include <sys/time.h>
-#include <sys/times.h>
+#undef doupdate_sp
+int	doupdate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
 
 #undef doupdate
 int	doupdate(void)
 		{ return(*(int *)0); }
 
+#undef _nc_scrolln_sp
+int	_nc_scrolln_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
 #undef _nc_scrolln
 int	_nc_scrolln(
 		int	n, 
@@ -1995,18 +2480,39 @@
 		int	maxy)
 		{ return(*(int *)0); }
 
+#undef _nc_screen_resume_sp
+void	_nc_screen_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_resume
 void	_nc_screen_resume(void)
 		{ /* void */ }
 
+#undef _nc_screen_init_sp
+void	_nc_screen_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_init
 void	_nc_screen_init(void)
 		{ /* void */ }
 
+#undef _nc_screen_wrap_sp
+void	_nc_screen_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_wrap
 void	_nc_screen_wrap(void)
 		{ /* void */ }
 
+#undef _nc_do_xmc_glitch_sp
+void	_nc_do_xmc_glitch_sp(
+		SCREEN	*sp, 
+		attr_t	previous)
+		{ /* void */ }
+
 #undef _nc_do_xmc_glitch
 void	_nc_do_xmc_glitch(
 		attr_t	previous)
@@ -2024,12 +2530,6 @@
 		va_list	ap)
 		{ return(*(char **)0); }
 
-/* ./base/memmove.c */
-
-#undef _nc_memmove
-void	_nc_memmove(void)
-		{ /* void */ }
-
 /* ./base/vsscanf.c */
 
 #undef _nc_vsscanf
@@ -2038,12 +2538,16 @@
 
 /* ./base/lib_freeall.c */
 
-#include <term_entry.h>
-
 #undef _nc_freeall
 void	_nc_freeall(void)
 		{ /* void */ }
 
+#undef _nc_free_and_exit_sp
+void	_nc_free_and_exit_sp(
+		SCREEN	*sp, 
+		int	code)
+		{ /* void */ }
+
 #undef _nc_free_and_exit
 void	_nc_free_and_exit(
 		int	code)
@@ -2063,6 +2567,24 @@
 		attr_t	at)
 		{ /* void */ }
 
+#undef _nc_DelCharCost_sp
+int	_nc_DelCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_InsCharCost_sp
+int	_nc_InsCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_UpdateAttrs_sp
+void	_nc_UpdateAttrs_sp(
+		SCREEN	*sp, 
+		chtype	c)
+		{ /* void */ }
+
 #undef _nc_DelCharCost
 int	_nc_DelCharCost(
 		int	count)
@@ -2080,6 +2602,12 @@
 
 /* ./base/legacy_coding.c */
 
+#undef use_legacy_coding_sp
+int	use_legacy_coding_sp(
+		SCREEN	*sp, 
+		int	level)
+		{ return(*(int *)0); }
+
 #undef use_legacy_coding
 int	use_legacy_coding(
 		int	level)
@@ -2087,10 +2615,22 @@
 
 /* ./base/lib_dft_fgbg.c */
 
+#undef use_default_colors_sp
+int	use_default_colors_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef use_default_colors
 int	use_default_colors(void)
 		{ return(*(int *)0); }
 
+#undef assume_default_colors_sp
+int	assume_default_colors_sp(
+		SCREEN	*sp, 
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
 #undef assume_default_colors
 int	assume_default_colors(
 		int	fg, 
@@ -2099,6 +2639,13 @@
 
 /* ./tinfo/lib_print.c */
 
+#undef mcprint_sp
+int	mcprint_sp(
+		SCREEN	*sp, 
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
 #undef mcprint
 int	mcprint(
 		char	*data, 
@@ -2107,18 +2654,39 @@
 
 /* ./base/resizeterm.c */
 
+#undef is_term_resized_sp
+NCURSES_BOOL is_term_resized_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef is_term_resized
 NCURSES_BOOL is_term_resized(
 		int	ToLines, 
 		int	ToCols)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef resize_term_sp
+int	resize_term_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
 #undef resize_term
 int	resize_term(
 		int	ToLines, 
 		int	ToCols)
 		{ return(*(int *)0); }
 
+#undef resizeterm_sp
+int	resizeterm_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
 #undef resizeterm
 int	resizeterm(
 		int	ToLines, 
@@ -2161,9 +2729,6 @@
 
 /* ./tinfo/access.c */
 
-#include <sys/stat.h>
-#include <nc_alloc.h>
-
 #undef _nc_rootname
 char	*_nc_rootname(
 		char	*path)
@@ -2224,22 +2789,44 @@
 #undef _nc_copy_termtype
 void	_nc_copy_termtype(
 		TERMTYPE *dst, 
-		TERMTYPE *src)
+		const TERMTYPE *src)
 		{ /* void */ }
 
 /* ./codes.c */
 
 #undef _nc_boolcodes
-char	*const *_nc_boolcodes(void)
-		{ return(*(char **)0); }
+const char *const *_nc_boolcodes(void)
+		{ return(*(const char **)0); }
 
 #undef _nc_numcodes
-char	*const *_nc_numcodes(void)
-		{ return(*(char **)0); }
+const char *const *_nc_numcodes(void)
+		{ return(*(const char **)0); }
 
 #undef _nc_strcodes
-char	*const *_nc_strcodes(void)
-		{ return(*(char **)0); }
+const char *const *_nc_strcodes(void)
+		{ return(*(const char **)0); }
+
+/* ./comp_captab.c */
+
+#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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)0); }
 
 /* ./tinfo/comp_error.c */
 
@@ -2287,6 +2874,21 @@
 		...)
 		{ /* void */ }
 
+/* ./tinfo/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
 /* ./tinfo/db_iterator.c */
 
 #undef _nc_tic_dir
@@ -2380,6 +2982,12 @@
 		const char *name)
 		{ return(*(int *)0); }
 
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
 /* ./tinfo/home_terminfo.c */
 
 #undef _nc_home_terminfo
@@ -2388,15 +2996,6 @@
 
 /* ./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)
@@ -2408,16 +3007,19 @@
 chtype	*_nc_acs_map(void)
 		{ return(*(chtype **)0); }
 
+#undef _nc_init_acs_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_init_acs
 void	_nc_init_acs(void)
 		{ /* void */ }
 
 /* ./tinfo/lib_baudrate.c */
 
-#include <termcap.h>
-
 struct speed {
-    int s; 
+    short s; 
     int sp; 
 };
 
@@ -2431,21 +3033,47 @@
 		int	BaudRate)
 		{ return(*(int *)0); }
 
+#undef baudrate_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef baudrate
 int	baudrate(void)
 		{ return(*(int *)0); }
 
 /* ./tinfo/lib_cur_term.c */
 
+#undef _nc_get_cur_term_sp
+TERMINAL *_nc_get_cur_term_sp(
+		SCREEN	*sp)
+		{ return(*(TERMINAL **)0); }
+
+#undef _nc_get_cur_term
+TERMINAL *_nc_get_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
 #undef _nc_cur_term
 TERMINAL *_nc_cur_term(void)
 		{ return(*(TERMINAL **)0); }
 
+#undef set_curterm_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
 #undef set_curterm
 TERMINAL *set_curterm(
 		TERMINAL *termp)
 		{ return(*(TERMINAL **)0); }
 
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
 #undef del_curterm
 int	del_curterm(
 		TERMINAL *termp)
@@ -2474,6 +3102,11 @@
 #undef _nc_prescreen
 NCURSES_PRESCREEN _nc_prescreen;
 
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
 #undef _nc_init_pthreads
 void	_nc_init_pthreads(void)
 		{ /* void */ }
@@ -2500,24 +3133,49 @@
 
 /* ./tinfo/lib_has_cap.c */
 
+#undef has_ic_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_ic
 NCURSES_BOOL has_ic(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_il
 NCURSES_BOOL has_il(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
 /* ./tinfo/lib_kernel.c */
 
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
 #undef erasechar
 char	erasechar(void)
 		{ return(*(char *)0); }
 
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
 #undef killchar
 char	killchar(void)
 		{ return(*(char *)0); }
 
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef flushinp
 int	flushinp(void)
 		{ return(*(int *)0); }
@@ -2526,25 +3184,36 @@
 
 struct kn { short offset; int code; };
 
-#undef _nc_keyname
-char	*_nc_keyname(
+#undef keyname_sp
+const char *keyname_sp(
 		SCREEN	*sp, 
 		int	c)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 #undef keyname
-char	*keyname(
+const char *keyname(
 		int	c)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 /* ./tinfo/lib_longname.c */
 
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
 #undef longname
 char	*longname(void)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_napms.c */
 
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
 #undef napms
 int	napms(
 		int	ms)
@@ -2564,6 +3233,12 @@
 		NCURSES_BOOL flag)
 		{ /* void */ }
 
+#undef halfdelay_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
 #undef halfdelay
 int	halfdelay(
 		int	t)
@@ -2599,53 +3274,115 @@
 		NCURSES_BOOL flag)
 		{ return(*(int *)0); }
 
+#undef curs_set_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
 #undef curs_set
 int	curs_set(
 		int	vis)
 		{ return(*(int *)0); }
 
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
 #undef typeahead
 int	typeahead(
 		int	fd)
 		{ return(*(int *)0); }
 
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
 #undef has_key
 int	has_key(
 		int	keycode)
 		{ return(*(int *)0); }
 
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
 #undef _nc_keypad
 int	_nc_keypad(
 		SCREEN	*sp, 
-		NCURSES_BOOL flag)
+		int	flag)
 		{ return(*(int *)0); }
 
 /* ./tinfo/lib_raw.c */
 
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef raw
 int	raw(void)
 		{ return(*(int *)0); }
 
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef cbreak
 int	cbreak(void)
 		{ return(*(int *)0); }
 
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef qiflush
 void	qiflush(void)
 		{ /* void */ }
 
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef noraw
 int	noraw(void)
 		{ return(*(int *)0); }
 
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nocbreak
 int	nocbreak(void)
 		{ return(*(int *)0); }
 
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef noqiflush
 void	noqiflush(void)
 		{ /* void */ }
 
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
 #undef intrflush
 int	intrflush(
 		WINDOW	*win, 
@@ -2654,16 +3391,13 @@
 
 /* ./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)
+int	*_nc_ptr_Lines(
+		SCREEN	*sp)
 		{ return(*(int **)0); }
 
 #undef _nc_LINES
@@ -2671,17 +3405,29 @@
 		{ return(*(int *)0); }
 
 #undef _nc_ptr_Cols
-int	*_nc_ptr_Cols(void)
+int	*_nc_ptr_Cols(
+		SCREEN	*sp)
 		{ return(*(int **)0); }
 
 #undef _nc_COLS
 int	_nc_COLS(void)
 		{ return(*(int *)0); }
 
+#undef _nc_ptr_Tabsize
+int	*_nc_ptr_Tabsize(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
 #undef _nc_TABSIZE
 int	_nc_TABSIZE(void)
 		{ return(*(int *)0); }
 
+#undef set_tabsize_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ return(*(int *)0); }
+
 #undef set_tabsize
 int	set_tabsize(
 		int	value)
@@ -2692,11 +3438,28 @@
 		SCREEN	*sp)
 		{ return(*(int *)0); }
 
+#undef use_env_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
 #undef use_env
 void	use_env(
 		NCURSES_BOOL f)
 		{ /* void */ }
 
+#undef use_tioctl
+void	use_tioctl(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
 #undef _nc_get_screensize
 void	_nc_get_screensize(
 		SCREEN	*sp, 
@@ -2709,6 +3472,18 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef _nc_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* void */ }
+
 #undef _nc_get_locale
 char	*_nc_get_locale(void)
 		{ return(*(char **)0); }
@@ -2724,15 +3499,19 @@
 
 #undef _nc_setupterm
 int	_nc_setupterm(
-		char	*tname, 
+		const char *tname, 
 		int	Filedes, 
 		int	*errret, 
-		NCURSES_BOOL reuse)
+		int	reuse)
 		{ return(*(int *)0); }
 
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
 #undef setupterm
 int	setupterm(
-		char	*tname, 
+		const char *tname, 
 		int	Filedes, 
 		int	*errret)
 		{ return(*(int *)0); }
@@ -2744,36 +3523,61 @@
 #undef BC
 char	*BC;
 
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
 #undef tgetent
 int	tgetent(
 		char	*bufp, 
 		const char *name)
 		{ return(*(int *)0); }
 
-#if 0
-
-#include <capdefaults.c>
-
-#endif
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
 
 #undef tgetflag
 int	tgetflag(
-		char	*id)
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
 		{ return(*(int *)0); }
 
 #undef tgetnum
 int	tgetnum(
-		char	*id)
+		const char *id)
 		{ return(*(int *)0); }
 
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
 #undef tgetstr
 char	*tgetstr(
-		char	*id, 
+		const char *id, 
 		char	**area)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_termname.c */
 
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
 #undef termname
 char	*termname(void)
 		{ return(*(char **)0); }
@@ -2789,19 +3593,37 @@
 
 /* ./tinfo/lib_ti.c */
 
+#undef tigetflag_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
 #undef tigetflag
 int	tigetflag(
-		char	*str)
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
 		{ return(*(int *)0); }
 
 #undef tigetnum
 int	tigetnum(
-		char	*str)
+		const char *str)
 		{ return(*(int *)0); }
 
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
 #undef tigetstr
 char	*tigetstr(
-		char	*str)
+		const char *str)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_tparm.c */
@@ -2813,12 +3635,18 @@
 int	_nc_tparm_analyze(
 		const char *string, 
 		char	*p_is_s[9], 
-		int	*popcount)
+		int	*_nc_popcount)
 		{ return(*(int *)0); }
 
 #undef tparm
 char	*tparm(
-		char	*string, 
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
 		...)
 		{ return(*(char **)0); }
 
@@ -2827,7 +3655,7 @@
 #undef PC
 char	PC;
 #undef ospeed
-NCURSES_OSPEED	ospeed;
+short	ospeed;
 #undef _nc_nulls_sent
 int	_nc_nulls_sent;
 
@@ -2836,25 +3664,86 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef delay_output_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
 #undef delay_output
 int	delay_output(
 		int	ms)
 		{ return(*(int *)0); }
 
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_flush
 void	_nc_flush(void)
 		{ /* void */ }
 
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
 #undef _nc_outch
 int	_nc_outch(
 		int	ch)
 		{ return(*(int *)0); }
 
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
 #undef putp
 int	putp(
 		const char *string)
 		{ return(*(int *)0); }
 
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(int *)0); }
+
 #undef tputs
 int	tputs(
 		const char *string, 
@@ -2899,9 +3788,14 @@
 
 #undef _nc_retrace_bool
 NCURSES_BOOL _nc_retrace_bool(
-		NCURSES_BOOL code)
+		int	code)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)0); }
+
 #undef _nc_retrace_int
 int	_nc_retrace_int(
 		int	code)
@@ -2923,9 +3817,9 @@
 		{ return(*(const char **)0); }
 
 #undef _nc_retrace_cvoid_ptr
-void	*_nc_retrace_cvoid_ptr(
-		void	*code)
-		{ return(*(void **)0); }
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const void **)0); }
 
 #undef _nc_retrace_void_ptr
 void	*_nc_retrace_void_ptr(
@@ -2966,6 +3860,11 @@
 		attr_t	newmode)
 		{ return(*(char **)0); }
 
+#undef _nc_retrace_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)0); }
+
 #undef _nc_retrace_attr_t
 attr_t	_nc_retrace_attr_t(
 		attr_t	code)
@@ -2997,7 +3896,7 @@
 
 typedef struct {
     unsigned int val;
-    const char *name;
+    const char name[8];
 } BITNAMES;
 
 #undef _nc_trace_ttymode
@@ -3024,36 +3923,78 @@
 
 /* ./tinfo/lib_ttyflags.c */
 
+#undef _nc_get_tty_mode_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
 #undef _nc_get_tty_mode
 int	_nc_get_tty_mode(
 		struct termios *buf)
 		{ return(*(int *)0); }
 
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef def_shell_mode
 int	def_shell_mode(void)
 		{ return(*(int *)0); }
 
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef def_prog_mode
 int	def_prog_mode(void)
 		{ return(*(int *)0); }
 
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef reset_prog_mode
 int	reset_prog_mode(void)
 		{ return(*(int *)0); }
 
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef reset_shell_mode
 int	reset_shell_mode(void)
 		{ return(*(int *)0); }
 
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef savetty
 int	savetty(void)
 		{ return(*(int *)0); }
 
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef resetty
 int	resetty(void)
 		{ return(*(int *)0); }
@@ -3085,32 +4026,50 @@
 /* ./names.c */
 
 #undef _nc_boolnames
-char	*const *_nc_boolnames(void)
-		{ return(*(char **)0); }
+const char *const *_nc_boolnames(void)
+		{ return(*(const char **)0); }
 
 #undef _nc_boolfnames
-char	*const *_nc_boolfnames(void)
-		{ return(*(char **)0); }
+const char *const *_nc_boolfnames(void)
+		{ return(*(const char **)0); }
 
 #undef _nc_numnames
-char	*const *_nc_numnames(void)
-		{ return(*(char **)0); }
+const char *const *_nc_numnames(void)
+		{ return(*(const char **)0); }
 
 #undef _nc_numfnames
-char	*const *_nc_numfnames(void)
-		{ return(*(char **)0); }
+const char *const *_nc_numfnames(void)
+		{ return(*(const char **)0); }
 
 #undef _nc_strnames
-char	*const *_nc_strnames(void)
-		{ return(*(char **)0); }
+const char *const *_nc_strnames(void)
+		{ return(*(const char **)0); }
 
 #undef _nc_strfnames
-char	*const *_nc_strfnames(void)
-		{ return(*(char **)0); }
+const char *const *_nc_strfnames(void)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
 
 /* ./tinfo/read_entry.c */
 
-#include <hashed_db.h>
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
 
 #undef _nc_read_termtype
 int	_nc_read_termtype(
@@ -3134,20 +4093,8 @@
 
 /* ./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)
+#undef _nc_read_termcap
+void	_nc_read_termcap(void)
 		{ /* void */ }
 
 /* ./tinfo/strings.c */
@@ -3235,16 +4182,16 @@
 
 /* ./unctrl.c */
 
-#undef _nc_unctrl
-char	*_nc_unctrl(
+#undef unctrl_sp
+const char *unctrl_sp(
 		SCREEN	*sp, 
 		chtype	ch)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 #undef unctrl
-char	*unctrl(
+const char *unctrl(
 		chtype	ch)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 /* ./trace/visbuf.c */
 
@@ -3323,25 +4270,6 @@
 		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
@@ -3351,21 +4279,6 @@
 		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
@@ -3407,6 +4320,8 @@
 
 #undef _nc_syntax
 int	_nc_syntax;
+#undef _nc_strict_bsd
+int	_nc_strict_bsd;
 #undef _nc_curr_file_pos
 long	_nc_curr_file_pos;
 #undef _nc_comment_start
@@ -3463,15 +4378,15 @@
 		{ return(*(int *)0); }
 
 typedef struct {
-    const char *from;
-    const char *to;
+    const char from[3];
+    const char to[6];
 } assoc;
 
 /* ./tinfo/write_entry.c */
 
 #undef _nc_set_writedir
 void	_nc_set_writedir(
-		char	*dir)
+		const char *dir)
 		{ /* void */ }
 
 #undef _nc_write_entry
@@ -3485,6 +4400,13 @@
 
 /* ./base/define_key.c */
 
+#undef define_key_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
 #undef define_key
 int	define_key(
 		const char *str, 
@@ -3499,6 +4421,12 @@
 
 /* ./base/key_defined.c */
 
+#undef key_defined_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
 #undef key_defined
 int	key_defined(
 		const char *str)
@@ -3506,6 +4434,13 @@
 
 /* ./base/keybound.c */
 
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
 #undef keybound
 char	*keybound(
 		int	code, 
@@ -3514,6 +4449,13 @@
 
 /* ./base/keyok.c */
 
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
 #undef keyok
 int	keyok(
 		int	c, 
diff --git a/ncurses/llib-lncursestw b/ncurses/llib-lncursestw
new file mode 100644
index 0000000..9871dcc
--- /dev/null
+++ b/ncurses/llib-lncursestw
@@ -0,0 +1,5285 @@
+/****************************************************************************
+ * Copyright (c) 2009-2013,2015 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       2009-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tty/hardscroll.c */
+
+#include <curses.priv.h>
+
+#undef _nc_oldnums
+int	*_nc_oldnums;
+
+#undef _nc_scroll_optimize_sp
+void	_nc_scroll_optimize_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_scroll_optimize
+void	_nc_scroll_optimize(void)
+		{ /* void */ }
+
+#undef _nc_linedump_sp
+void	_nc_linedump_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_linedump
+void	_nc_linedump(void)
+		{ /* void */ }
+
+/* ./tty/hashmap.c */
+
+#undef _nc_hash_map_sp
+void	_nc_hash_map_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_hash_map
+void	_nc_hash_map(void)
+		{ /* void */ }
+
+#undef _nc_make_oldhash_sp
+void	_nc_make_oldhash_sp(
+		SCREEN	*sp, 
+		int	i)
+		{ /* void */ }
+
+#undef _nc_make_oldhash
+void	_nc_make_oldhash(
+		int	i)
+		{ /* void */ }
+
+#undef _nc_scroll_oldhash_sp
+void	_nc_scroll_oldhash_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
+#undef _nc_scroll_oldhash
+void	_nc_scroll_oldhash(
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
+/* ./base/lib_addch.c */
+
+#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_sp
+int	beep_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#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 */
+
+#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_sp
+NCURSES_BOOL _nc_reset_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_reset_colors
+NCURSES_BOOL _nc_reset_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef start_color_sp
+int	start_color_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef start_color
+int	start_color(void)
+		{ return(*(int *)0); }
+
+#undef init_pair_sp
+int	init_pair_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef init_pair
+int	init_pair(
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
+#undef init_color_sp
+int	init_color_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	r, 
+		short	g, 
+		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_sp
+NCURSES_BOOL can_change_color_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef can_change_color
+NCURSES_BOOL can_change_color(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_colors_sp
+NCURSES_BOOL has_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_colors
+NCURSES_BOOL has_colors(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef color_content_sp
+int	color_content_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef color_content
+int	color_content(
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef pair_content_sp
+int	pair_content_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef pair_content
+int	pair_content(
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
+#undef _nc_do_color_sp
+void	_nc_do_color_sp(
+		SCREEN	*sp, 
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC_sp outc)
+		{ /* void */ }
+
+#undef _nc_do_color
+void	_nc_do_color(
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC outc)
+		{ /* 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_sp
+int	echo_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef echo
+int	echo(void)
+		{ return(*(int *)0); }
+
+#undef noecho_sp
+int	noecho_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef noecho
+int	noecho(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_endwin.c */
+
+#undef endwin_sp
+int	endwin_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#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_sp
+int	flash_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#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, 
+		const 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_pad
+NCURSES_BOOL (is_pad)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_scrollok
+NCURSES_BOOL (is_scrollok)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_subwin
+NCURSES_BOOL (is_subwin)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_syncok
+NCURSES_BOOL (is_syncok)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef wgetdelay
+int	(wgetdelay)(
+		const WINDOW *z)
+		{ return(*(int *)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 */
+
+#undef _nc_ESCDELAY
+int	_nc_ESCDELAY(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Escdelay
+int	*_nc_ptr_Escdelay(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef set_escdelay_sp
+int	set_escdelay_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ return(*(int *)0); }
+
+#undef set_escdelay
+int	set_escdelay(
+		int	value)
+		{ return(*(int *)0); }
+
+#undef get_escdelay_sp
+int	get_escdelay_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef get_escdelay
+int	get_escdelay(void)
+		{ return(*(int *)0); }
+
+#undef _nc_wgetch
+int	_nc_wgetch(
+		WINDOW	*win, 
+		int	*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(
+		SCREEN	*sp, 
+		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_sp
+NCURSES_BOOL isendwin_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#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_sp
+int	getmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef getmouse
+int	getmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef ungetmouse_sp
+int	ungetmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef ungetmouse
+int	ungetmouse(
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
+#undef mousemask_sp
+mmask_t	mousemask_sp(
+		SCREEN	*sp, 
+		mmask_t	newmask, 
+		mmask_t	*oldmask)
+		{ return(*(mmask_t *)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_sp
+int	mouseinterval_sp(
+		SCREEN	*sp, 
+		int	maxclick)
+		{ return(*(int *)0); }
+
+#undef mouseinterval
+int	mouseinterval(
+		int	maxclick)
+		{ return(*(int *)0); }
+
+#undef _nc_has_mouse
+NCURSES_BOOL _nc_has_mouse(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse_sp
+NCURSES_BOOL has_mouse_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse
+NCURSES_BOOL has_mouse(void)
+		{ return(*(NCURSES_BOOL *)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_sp
+int	_nc_msec_cost_sp(
+		SCREEN	*sp, 
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
+#undef _nc_msec_cost
+int	_nc_msec_cost(
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur_resume_sp
+void	_nc_mvcur_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_mvcur_resume
+void	_nc_mvcur_resume(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_init_sp
+void	_nc_mvcur_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_mvcur_init
+void	_nc_mvcur_init(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_wrap_sp
+void	_nc_mvcur_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_mvcur_wrap
+void	_nc_mvcur_wrap(void)
+		{ /* void */ }
+
+#undef _nc_mvcur_sp
+int	_nc_mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur
+int	_nc_mvcur(
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef mvcur_sp
+int	mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#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_sp
+void	filter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef filter
+void	filter(void)
+		{ /* void */ }
+
+#undef nofilter_sp
+void	nofilter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef nofilter
+void	nofilter(void)
+		{ /* void */ }
+
+#undef newterm_sp
+SCREEN	*newterm_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		FILE	*ofp, 
+		FILE	*ifp)
+		{ return(*(SCREEN **)0); }
+
+#undef newterm
+SCREEN	*newterm(
+		const 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_sp
+WINDOW	*newwin_sp(
+		SCREEN	*sp, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)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_sp
+WINDOW	*_nc_makenew_sp(
+		SCREEN	*sp, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx, 
+		int	flags)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_curscr_of
+WINDOW	*_nc_curscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_newscr_of
+WINDOW	*_nc_newscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_stdscr_of
+WINDOW	*_nc_stdscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+/* ./base/lib_nl.c */
+
+#undef nl_sp
+int	nl_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef nl
+int	nl(void)
+		{ return(*(int *)0); }
+
+#undef nonl_sp
+int	nonl_sp(
+		SCREEN	*sp)
+		{ 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_sp
+WINDOW	*newpad_sp(
+		SCREEN	*sp, 
+		int	l, 
+		int	c)
+		{ return(*(WINDOW **)0); }
+
+#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_sp
+int	restartterm_sp(
+		SCREEN	*sp, 
+		const char *termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+#undef restartterm
+int	restartterm(
+		const char *termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./base/lib_scanw.c */
+
+#undef vwscanw
+int	vwscanw(
+		WINDOW	*win, 
+		const char *fmt, 
+		va_list	argp)
+		{ return(*(int *)0); }
+
+#undef scanw
+int	scanw(
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef wscanw
+int	wscanw(
+		WINDOW	*win, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvscanw
+int	mvscanw(
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+#undef mvwscanw
+int	mvwscanw(
+		WINDOW	*win, 
+		int	y, 
+		int	x, 
+		const char *fmt, 
+		...)
+		{ return(*(int *)0); }
+
+/* ./base/lib_screen.c */
+
+#undef getwin_sp
+WINDOW	*getwin_sp(
+		SCREEN	*sp, 
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
+#undef getwin
+WINDOW	*getwin(
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
+#undef putwin
+int	putwin(
+		WINDOW	*win, 
+		FILE	*filep)
+		{ return(*(int *)0); }
+
+#undef scr_restore_sp
+int	scr_restore_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ 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_sp
+int	scr_init_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_init
+int	scr_init(
+		const char *file)
+		{ return(*(int *)0); }
+
+#undef scr_set_sp
+int	scr_set_sp(
+		SCREEN	*sp, 
+		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, 
+		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_sp
+int	_nc_setupscreen_sp(
+		SCREEN	**spp, 
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		int	filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
+#undef _nc_setupscreen
+int	_nc_setupscreen(
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		int	filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
+#undef _nc_ripoffline_sp
+int	_nc_ripoffline_sp(
+		SCREEN	*sp, 
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+#undef _nc_ripoffline
+int	_nc_ripoffline(
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
+#undef ripoffline_sp
+int	ripoffline_sp(
+		SCREEN	*sp, 
+		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_format_slks
+int	_nc_format_slks(
+		SCREEN	*sp, 
+		int	cols)
+		{ return(*(int *)0); }
+
+#undef _nc_slk_initialize
+int	_nc_slk_initialize(
+		WINDOW	*stwin, 
+		int	cols)
+		{ return(*(int *)0); }
+
+#undef slk_restore_sp
+int	slk_restore_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef slk_restore
+int	slk_restore(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatr_set.c */
+
+#undef slk_attr_set_sp
+int	slk_attr_set_sp(
+		SCREEN	*sp, 
+		const attr_t attr, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+#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_sp
+int	slk_attroff_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
+#undef slk_attroff
+int	slk_attroff(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatron.c */
+
+#undef slk_attron_sp
+int	slk_attron_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
+#undef slk_attron
+int	slk_attron(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkatrset.c */
+
+#undef slk_attrset_sp
+int	slk_attrset_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
+#undef slk_attrset
+int	slk_attrset(
+		const chtype attr)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkattr.c */
+
+#undef slk_attr_sp
+attr_t	slk_attr_sp(
+		SCREEN	*sp)
+		{ return(*(attr_t *)0); }
+
+#undef slk_attr
+attr_t	slk_attr(void)
+		{ return(*(attr_t *)0); }
+
+/* ./base/lib_slkclear.c */
+
+#undef slk_clear_sp
+int	slk_clear_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef slk_clear
+int	slk_clear(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkcolor.c */
+
+#undef slk_color_sp
+int	slk_color_sp(
+		SCREEN	*sp, 
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
+#undef slk_color
+int	slk_color(
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkinit.c */
+
+#undef slk_init_sp
+int	slk_init_sp(
+		SCREEN	*sp, 
+		int	format)
+		{ return(*(int *)0); }
+
+#undef slk_init
+int	slk_init(
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slklab.c */
+
+#undef slk_label_sp
+char	*slk_label_sp(
+		SCREEN	*sp, 
+		int	n)
+		{ return(*(char **)0); }
+
+#undef slk_label
+char	*slk_label(
+		int	n)
+		{ return(*(char **)0); }
+
+/* ./base/lib_slkrefr.c */
+
+#undef slk_noutrefresh_sp
+int	slk_noutrefresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef slk_noutrefresh
+int	slk_noutrefresh(void)
+		{ return(*(int *)0); }
+
+#undef slk_refresh_sp
+int	slk_refresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef slk_refresh
+int	slk_refresh(void)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slkset.c */
+
+#undef slk_set_sp
+int	slk_set_sp(
+		SCREEN	*sp, 
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
+#undef slk_set
+int	slk_set(
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
+
+/* ./base/lib_slktouch.c */
+
+#undef slk_touch_sp
+int	slk_touch_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#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_trace_mmask_t
+char	*_nc_trace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(char **)0); }
+
+#undef _nc_tracemouse
+char	*_nc_tracemouse(
+		SCREEN	*sp, 
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+#undef _nc_retrace_mmask_t
+mmask_t	_nc_retrace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(mmask_t *)0); }
+
+#undef _tracemouse
+char	*_tracemouse(
+		MEVENT const *ep)
+		{ return(*(char **)0); }
+
+/* ./tty/lib_tstp.c */
+
+#undef _nc_signal_handler
+void	_nc_signal_handler(
+		int	enable)
+		{ /* void */ }
+
+/* ./base/lib_ungetch.c */
+
+#undef _nc_fifo_dump
+void	_nc_fifo_dump(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef ungetch_sp
+int	ungetch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef ungetch
+int	ungetch(
+		int	ch)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_vidattr.c */
+
+#undef vidputs_sp
+int	vidputs_sp(
+		SCREEN	*sp, 
+		chtype	newmode, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef vidputs
+int	vidputs(
+		chtype	newmode, 
+		NCURSES_OUTC outc)
+		{ return(*(int *)0); }
+
+#undef vidattr_sp
+int	vidattr_sp(
+		SCREEN	*sp, 
+		chtype	newmode)
+		{ return(*(int *)0); }
+
+#undef vidattr
+int	vidattr(
+		chtype	newmode)
+		{ return(*(int *)0); }
+
+#undef termattrs_sp
+chtype	termattrs_sp(
+		SCREEN	*sp)
+		{ return(*(chtype *)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_sp
+struct panelhook *_nc_panelhook_sp(
+		SCREEN	*sp)
+		{ return(*(struct panelhook **)0); }
+
+#undef _nc_panelhook
+struct panelhook *_nc_panelhook(void)
+		{ return(*(struct panelhook **)0); }
+
+/* ./base/safe_sprintf.c */
+
+#undef _nc_printf_string_sp
+char	*_nc_printf_string_sp(
+		SCREEN	*sp, 
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+#undef _nc_printf_string
+char	*_nc_printf_string(
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
+/* ./tty/tty_update.c */
+
+#undef doupdate_sp
+int	doupdate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef doupdate
+int	doupdate(void)
+		{ return(*(int *)0); }
+
+#undef _nc_scrolln_sp
+int	_nc_scrolln_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
+#undef _nc_scrolln
+int	_nc_scrolln(
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
+#undef _nc_screen_resume_sp
+void	_nc_screen_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_screen_resume
+void	_nc_screen_resume(void)
+		{ /* void */ }
+
+#undef _nc_screen_init_sp
+void	_nc_screen_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_screen_init
+void	_nc_screen_init(void)
+		{ /* void */ }
+
+#undef _nc_screen_wrap_sp
+void	_nc_screen_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_screen_wrap
+void	_nc_screen_wrap(void)
+		{ /* void */ }
+
+#undef _nc_do_xmc_glitch_sp
+void	_nc_do_xmc_glitch_sp(
+		SCREEN	*sp, 
+		attr_t	previous)
+		{ /* 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/vsscanf.c */
+
+#undef _nc_vsscanf
+void	_nc_vsscanf(void)
+		{ /* void */ }
+
+/* ./base/lib_freeall.c */
+
+#undef _nc_freeall
+void	_nc_freeall(void)
+		{ /* void */ }
+
+#undef _nc_free_and_exit_sp
+void	_nc_free_and_exit_sp(
+		SCREEN	*sp, 
+		int	code)
+		{ /* 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 _nc_insert_wch
+int	_nc_insert_wch(
+		WINDOW	*win, 
+		const cchar_t *wch)
+		{ return(*(int *)0); }
+
+#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
+const char *key_name(
+		wchar_t	c)
+		{ return(*(const 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_sp
+int	unget_wch_sp(
+		SCREEN	*sp, 
+		const wchar_t wch)
+		{ return(*(int *)0); }
+
+#undef unget_wch
+int	unget_wch(
+		const wchar_t wch)
+		{ return(*(int *)0); }
+
+/* ./widechar/lib_vid_attr.c */
+
+#undef vid_puts_sp
+int	vid_puts_sp(
+		SCREEN	*sp, 
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef vid_puts
+int	vid_puts(
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts, 
+		NCURSES_OUTC outc)
+		{ return(*(int *)0); }
+
+#undef vid_attr_sp
+int	vid_attr_sp(
+		SCREEN	*sp, 
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+#undef vid_attr
+int	vid_attr(
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts)
+		{ return(*(int *)0); }
+
+#undef term_attrs_sp
+attr_t	term_attrs_sp(
+		SCREEN	*sp)
+		{ return(*(attr_t *)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_sp
+wchar_t	*wunctrl_sp(
+		SCREEN	*sp, 
+		cchar_t	*wc)
+		{ return(*(wchar_t **)0); }
+
+#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_sp
+int	_nc_DelCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_InsCharCost_sp
+int	_nc_InsCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_UpdateAttrs_sp
+void	_nc_UpdateAttrs_sp(
+		SCREEN	*sp, 
+		const cchar_t *c)
+		{ /* 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(
+		const cchar_t *c)
+		{ /* void */ }
+
+/* ./base/legacy_coding.c */
+
+#undef use_legacy_coding_sp
+int	use_legacy_coding_sp(
+		SCREEN	*sp, 
+		int	level)
+		{ return(*(int *)0); }
+
+#undef use_legacy_coding
+int	use_legacy_coding(
+		int	level)
+		{ return(*(int *)0); }
+
+/* ./base/lib_dft_fgbg.c */
+
+#undef use_default_colors_sp
+int	use_default_colors_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef use_default_colors
+int	use_default_colors(void)
+		{ return(*(int *)0); }
+
+#undef assume_default_colors_sp
+int	assume_default_colors_sp(
+		SCREEN	*sp, 
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
+#undef assume_default_colors
+int	assume_default_colors(
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_print.c */
+
+#undef mcprint_sp
+int	mcprint_sp(
+		SCREEN	*sp, 
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
+#undef mcprint
+int	mcprint(
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
+/* ./base/resizeterm.c */
+
+#undef is_term_resized_sp
+NCURSES_BOOL is_term_resized_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_term_resized
+NCURSES_BOOL is_term_resized(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef resize_term_sp
+int	resize_term_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+#undef resize_term
+int	resize_term(
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
+#undef resizeterm_sp
+int	resizeterm_sp(
+		SCREEN	*sp, 
+		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 */
+
+#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, 
+		const TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef _nc_boolcodes
+const char *const *_nc_boolcodes(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numcodes
+const char *const *_nc_numcodes(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strcodes
+const char *const *_nc_strcodes(void)
+		{ return(*(const char **)0); }
+
+/* ./comp_captab.c */
+
+#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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)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/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./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); }
+
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
+/* ./tinfo/home_terminfo.c */
+
+#undef _nc_home_terminfo
+char	*_nc_home_terminfo(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/init_keytry.c */
+
+#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_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+struct speed {
+    short 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_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef baudrate
+int	baudrate(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_cur_term.c */
+
+#undef _nc_get_cur_term_sp
+TERMINAL *_nc_get_cur_term_sp(
+		SCREEN	*sp)
+		{ return(*(TERMINAL **)0); }
+
+#undef _nc_get_cur_term
+TERMINAL *_nc_get_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
+#undef _nc_cur_term
+TERMINAL *_nc_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)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_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+#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_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef keyname_sp
+const char *keyname_sp(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(const char **)0); }
+
+#undef keyname
+const char *keyname(
+		int	c)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#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_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
+#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_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		int	flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#undef intrflush
+int	intrflush(
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_setup.c */
+
+#undef _nc_ttytype
+char	*_nc_ttytype(void)
+		{ return(*(char **)0); }
+
+#undef _nc_ptr_Lines
+int	*_nc_ptr_Lines(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_LINES
+int	_nc_LINES(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Cols
+int	*_nc_ptr_Cols(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_COLS
+int	_nc_COLS(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Tabsize
+int	*_nc_ptr_Tabsize(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_TABSIZE
+int	_nc_TABSIZE(void)
+		{ return(*(int *)0); }
+
+#undef set_tabsize_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ 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_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl
+void	use_tioctl(
+		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_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* 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(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret, 
+		int	reuse)
+		{ return(*(int *)0); }
+
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
+#undef setupterm
+int	setupterm(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetflag
+int	tgetflag(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#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_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetflag
+int	tigetflag(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		const 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	*_nc_popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+short	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_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ 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(
+		int	code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)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
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const 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_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)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[8];
+} 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_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ 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
+const char *const *_nc_boolnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_boolfnames
+const char *const *_nc_boolfnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numnames
+const char *const *_nc_numnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numfnames
+const char *const *_nc_numfnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strnames
+const char *const *_nc_strnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strfnames
+const char *const *_nc_strfnames(void)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+/* ./tinfo/read_entry.c */
+
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#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 */
+
+#undef _nc_read_termcap
+void	_nc_read_termcap(void)
+		{ /* 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 unctrl_sp
+const char *unctrl_sp(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef unctrl
+const char *unctrl(
+		chtype	ch)
+		{ return(*(const 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); }
+
+/* ./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_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_strict_bsd
+int	_nc_strict_bsd;
+#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[3];
+    const char to[6];
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		const 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_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#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_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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
index 96e7257..217ae1b 100644
--- a/ncurses/llib-lncursesw
+++ b/ncurses/llib-lncursesw
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2001-2013,2015 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            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey 2001-2008                                      *
+ *  Author: Thomas E. Dickey       2001-on                                  *
  ****************************************************************************/
 /* LINTLIBRARY */
 
@@ -38,27 +38,54 @@
 #undef _nc_oldnums
 int	*_nc_oldnums;
 
+#undef _nc_scroll_optimize_sp
+void	_nc_scroll_optimize_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_scroll_optimize
 void	_nc_scroll_optimize(void)
 		{ /* void */ }
 
+#undef _nc_linedump_sp
+void	_nc_linedump_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_linedump
 void	_nc_linedump(void)
 		{ /* void */ }
 
 /* ./tty/hashmap.c */
 
-#include <term.h>
+#undef _nc_hash_map_sp
+void	_nc_hash_map_sp(
+		SCREEN	*sp)
+		{ /* void */ }
 
 #undef _nc_hash_map
 void	_nc_hash_map(void)
 		{ /* void */ }
 
+#undef _nc_make_oldhash_sp
+void	_nc_make_oldhash_sp(
+		SCREEN	*sp, 
+		int	i)
+		{ /* void */ }
+
 #undef _nc_make_oldhash
 void	_nc_make_oldhash(
 		int	i)
 		{ /* void */ }
 
+#undef _nc_scroll_oldhash_sp
+void	_nc_scroll_oldhash_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot)
+		{ /* void */ }
+
 #undef _nc_scroll_oldhash
 void	_nc_scroll_oldhash(
 		int	n, 
@@ -68,8 +95,6 @@
 
 /* ./base/lib_addch.c */
 
-#include <ctype.h>
-
 #undef _nc_render
 cchar_t	_nc_render(
 		WINDOW	*win, 
@@ -137,6 +162,11 @@
 
 /* ./base/lib_beep.c */
 
+#undef beep_sp
+int	beep_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef beep
 int	beep(void)
 		{ return(*(int *)0); }
@@ -224,21 +254,37 @@
 
 /* ./base/lib_color.c */
 
-#include <tic.h>
-
 #undef COLOR_PAIRS
 int	COLOR_PAIRS;
 #undef COLORS
 int	COLORS;
 
+#undef _nc_reset_colors_sp
+NCURSES_BOOL _nc_reset_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef _nc_reset_colors
 NCURSES_BOOL _nc_reset_colors(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef start_color_sp
+int	start_color_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef start_color
 int	start_color(void)
 		{ return(*(int *)0); }
 
+#undef init_pair_sp
+int	init_pair_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	f, 
+		short	b)
+		{ return(*(int *)0); }
+
 #undef init_pair
 int	init_pair(
 		short	pair, 
@@ -246,6 +292,15 @@
 		short	b)
 		{ return(*(int *)0); }
 
+#undef init_color_sp
+int	init_color_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	r, 
+		short	g, 
+		short	b)
+		{ return(*(int *)0); }
+
 #undef init_color
 int	init_color(
 		short	color, 
@@ -254,14 +309,33 @@
 		short	b)
 		{ return(*(int *)0); }
 
+#undef can_change_color_sp
+NCURSES_BOOL can_change_color_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef can_change_color
 NCURSES_BOOL can_change_color(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef has_colors_sp
+NCURSES_BOOL has_colors_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_colors
 NCURSES_BOOL has_colors(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef color_content_sp
+int	color_content_sp(
+		SCREEN	*sp, 
+		short	color, 
+		short	*r, 
+		short	*g, 
+		short	*b)
+		{ return(*(int *)0); }
+
 #undef color_content
 int	color_content(
 		short	color, 
@@ -270,6 +344,14 @@
 		short	*b)
 		{ return(*(int *)0); }
 
+#undef pair_content_sp
+int	pair_content_sp(
+		SCREEN	*sp, 
+		short	pair, 
+		short	*f, 
+		short	*b)
+		{ return(*(int *)0); }
+
 #undef pair_content
 int	pair_content(
 		short	pair, 
@@ -277,13 +359,21 @@
 		short	*b)
 		{ return(*(int *)0); }
 
+#undef _nc_do_color_sp
+void	_nc_do_color_sp(
+		SCREEN	*sp, 
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC_sp outc)
+		{ /* void */ }
+
 #undef _nc_do_color
 void	_nc_do_color(
-		short	old_pair, 
-		short	pair, 
-		NCURSES_BOOL reverse, 
-		int	(*outc)(
-		int	p1))
+		int	old_pair, 
+		int	pair, 
+		int	reverse, 
+		NCURSES_OUTC outc)
 		{ /* void */ }
 
 /* ./base/lib_colorset.c */
@@ -311,16 +401,31 @@
 
 /* ./base/lib_echo.c */
 
+#undef echo_sp
+int	echo_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef echo
 int	echo(void)
 		{ return(*(int *)0); }
 
+#undef noecho_sp
+int	noecho_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef noecho
 int	noecho(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_endwin.c */
 
+#undef endwin_sp
+int	endwin_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef endwin
 int	endwin(void)
 		{ return(*(int *)0); }
@@ -334,6 +439,11 @@
 
 /* ./base/lib_flash.c */
 
+#undef flash_sp
+int	flash_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef flash
 int	flash(void)
 		{ return(*(int *)0); }
@@ -341,85 +451,85 @@
 /* ./lib_gen.c */
 
 #undef addch
-int	addch(
+int	(addch)(
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef addchnstr
-int	addchnstr(
+int	(addchnstr)(
 		const chtype *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef addchstr
-int	addchstr(
+int	(addchstr)(
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef addnstr
-int	addnstr(
+int	(addnstr)(
 		const char *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef addstr
-int	addstr(
+int	(addstr)(
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef attroff
-int	attroff(
+int	(attroff)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attron
-int	attron(
+int	(attron)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attrset
-int	attrset(
+int	(attrset)(
 		NCURSES_ATTR_T	z)
 		{ return(*(int *)0); }
 
 #undef attr_get
-int	attr_get(
+int	(attr_get)(
 		attr_t	*a1, 
 		short	*a2, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_off
-int	attr_off(
+int	(attr_off)(
 		attr_t	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_on
-int	attr_on(
+int	(attr_on)(
 		attr_t	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef attr_set
-int	attr_set(
+int	(attr_set)(
 		attr_t	a1, 
 		short	a2, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef bkgd
-int	bkgd(
+int	(bkgd)(
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef bkgdset
-void	bkgdset(
+void	(bkgdset)(
 		chtype	z)
 		{ /* void */ }
 
 #undef border
-int	border(
+int	(border)(
 		chtype	a1, 
 		chtype	a2, 
 		chtype	a3, 
@@ -431,14 +541,14 @@
 		{ return(*(int *)0); }
 
 #undef box
-int	box(
+int	(box)(
 		WINDOW	*a1, 
 		chtype	a2, 
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef chgat
-int	chgat(
+int	(chgat)(
 		int	a1, 
 		attr_t	a2, 
 		short	a3, 
@@ -446,137 +556,137 @@
 		{ return(*(int *)0); }
 
 #undef clear
-int	clear(void)
+int	(clear)(void)
 		{ return(*(int *)0); }
 
 #undef clrtobot
-int	clrtobot(void)
+int	(clrtobot)(void)
 		{ return(*(int *)0); }
 
 #undef clrtoeol
-int	clrtoeol(void)
+int	(clrtoeol)(void)
 		{ return(*(int *)0); }
 
 #undef color_set
-int	color_set(
+int	(color_set)(
 		short	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef COLOR_PAIR
-int	COLOR_PAIR(
+int	(COLOR_PAIR)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef delch
-int	delch(void)
+int	(delch)(void)
 		{ return(*(int *)0); }
 
 #undef deleteln
-int	deleteln(void)
+int	(deleteln)(void)
 		{ return(*(int *)0); }
 
 #undef echochar
-int	echochar(
+int	(echochar)(
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef erase
-int	erase(void)
+int	(erase)(void)
 		{ return(*(int *)0); }
 
 #undef getbkgd
-chtype	getbkgd(
+chtype	(getbkgd)(
 		WINDOW	*z)
 		{ return(*(chtype *)0); }
 
 #undef getch
-int	getch(void)
+int	(getch)(void)
 		{ return(*(int *)0); }
 
 #undef getnstr
-int	getnstr(
+int	(getnstr)(
 		char	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef getstr
-int	getstr(
+int	(getstr)(
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef hline
-int	hline(
+int	(hline)(
 		chtype	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef inch
-chtype	inch(void)
+chtype	(inch)(void)
 		{ return(*(chtype *)0); }
 
 #undef inchnstr
-int	inchnstr(
+int	(inchnstr)(
 		chtype	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef inchstr
-int	inchstr(
+int	(inchstr)(
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef innstr
-int	innstr(
+int	(innstr)(
 		char	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insch
-int	insch(
+int	(insch)(
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef insdelln
-int	insdelln(
+int	(insdelln)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insertln
-int	insertln(void)
+int	(insertln)(void)
 		{ return(*(int *)0); }
 
 #undef insnstr
-int	insnstr(
+int	(insnstr)(
 		const char *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef insstr
-int	insstr(
+int	(insstr)(
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef instr
-int	instr(
+int	(instr)(
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef move
-int	move(
+int	(move)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvaddch
-int	mvaddch(
+int	(mvaddch)(
 		int	a1, 
 		int	a2, 
 		const chtype z)
 		{ return(*(int *)0); }
 
 #undef mvaddchnstr
-int	mvaddchnstr(
+int	(mvaddchnstr)(
 		int	a1, 
 		int	a2, 
 		const chtype *a3, 
@@ -584,14 +694,14 @@
 		{ return(*(int *)0); }
 
 #undef mvaddchstr
-int	mvaddchstr(
+int	(mvaddchstr)(
 		int	a1, 
 		int	a2, 
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef mvaddnstr
-int	mvaddnstr(
+int	(mvaddnstr)(
 		int	a1, 
 		int	a2, 
 		const char *a3, 
@@ -599,14 +709,14 @@
 		{ return(*(int *)0); }
 
 #undef mvaddstr
-int	mvaddstr(
+int	(mvaddstr)(
 		int	a1, 
 		int	a2, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef mvchgat
-int	mvchgat(
+int	(mvchgat)(
 		int	a1, 
 		int	a2, 
 		int	a3, 
@@ -616,19 +726,19 @@
 		{ return(*(int *)0); }
 
 #undef mvdelch
-int	mvdelch(
+int	(mvdelch)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvgetch
-int	mvgetch(
+int	(mvgetch)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvgetnstr
-int	mvgetnstr(
+int	(mvgetnstr)(
 		int	a1, 
 		int	a2, 
 		char	*a3, 
@@ -636,14 +746,14 @@
 		{ return(*(int *)0); }
 
 #undef mvgetstr
-int	mvgetstr(
+int	(mvgetstr)(
 		int	a1, 
 		int	a2, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef mvhline
-int	mvhline(
+int	(mvhline)(
 		int	a1, 
 		int	a2, 
 		chtype	a3, 
@@ -651,13 +761,13 @@
 		{ return(*(int *)0); }
 
 #undef mvinch
-chtype	mvinch(
+chtype	(mvinch)(
 		int	a1, 
 		int	z)
 		{ return(*(chtype *)0); }
 
 #undef mvinchnstr
-int	mvinchnstr(
+int	(mvinchnstr)(
 		int	a1, 
 		int	a2, 
 		chtype	*a3, 
@@ -665,14 +775,14 @@
 		{ return(*(int *)0); }
 
 #undef mvinchstr
-int	mvinchstr(
+int	(mvinchstr)(
 		int	a1, 
 		int	a2, 
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef mvinnstr
-int	mvinnstr(
+int	(mvinnstr)(
 		int	a1, 
 		int	a2, 
 		char	*a3, 
@@ -680,14 +790,14 @@
 		{ return(*(int *)0); }
 
 #undef mvinsch
-int	mvinsch(
+int	(mvinsch)(
 		int	a1, 
 		int	a2, 
 		chtype	z)
 		{ return(*(int *)0); }
 
 #undef mvinsnstr
-int	mvinsnstr(
+int	(mvinsnstr)(
 		int	a1, 
 		int	a2, 
 		const char *a3, 
@@ -695,21 +805,21 @@
 		{ return(*(int *)0); }
 
 #undef mvinsstr
-int	mvinsstr(
+int	(mvinsstr)(
 		int	a1, 
 		int	a2, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef mvinstr
-int	mvinstr(
+int	(mvinstr)(
 		int	a1, 
 		int	a2, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef mvvline
-int	mvvline(
+int	(mvvline)(
 		int	a1, 
 		int	a2, 
 		chtype	a3, 
@@ -717,7 +827,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddch
-int	mvwaddch(
+int	(mvwaddch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -725,7 +835,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddchnstr
-int	mvwaddchnstr(
+int	(mvwaddchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -734,7 +844,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddchstr
-int	mvwaddchstr(
+int	(mvwaddchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -742,7 +852,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddnstr
-int	mvwaddnstr(
+int	(mvwaddnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -751,7 +861,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddstr
-int	mvwaddstr(
+int	(mvwaddstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -759,7 +869,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwchgat
-int	mvwchgat(
+int	(mvwchgat)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -770,21 +880,21 @@
 		{ return(*(int *)0); }
 
 #undef mvwdelch
-int	mvwdelch(
+int	(mvwdelch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvwgetch
-int	mvwgetch(
+int	(mvwgetch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef mvwgetnstr
-int	mvwgetnstr(
+int	(mvwgetnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -793,7 +903,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwgetstr
-int	mvwgetstr(
+int	(mvwgetstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -801,7 +911,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwhline
-int	mvwhline(
+int	(mvwhline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -810,14 +920,14 @@
 		{ return(*(int *)0); }
 
 #undef mvwinch
-chtype	mvwinch(
+chtype	(mvwinch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(chtype *)0); }
 
 #undef mvwinchnstr
-int	mvwinchnstr(
+int	(mvwinchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -826,7 +936,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinchstr
-int	mvwinchstr(
+int	(mvwinchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -834,7 +944,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinnstr
-int	mvwinnstr(
+int	(mvwinnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -843,7 +953,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsch
-int	mvwinsch(
+int	(mvwinsch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -851,7 +961,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsnstr
-int	mvwinsnstr(
+int	(mvwinsnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -860,7 +970,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinsstr
-int	mvwinsstr(
+int	(mvwinsstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -868,7 +978,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinstr
-int	mvwinstr(
+int	(mvwinstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -876,7 +986,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwvline
-int	mvwvline(
+int	(mvwvline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -885,129 +995,129 @@
 		{ return(*(int *)0); }
 
 #undef PAIR_NUMBER
-int	PAIR_NUMBER(
+int	(PAIR_NUMBER)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef redrawwin
-int	redrawwin(
+int	(redrawwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef refresh
-int	refresh(void)
+int	(refresh)(void)
 		{ return(*(int *)0); }
 
 #undef scrl
-int	scrl(
+int	(scrl)(
 		int	z)
 		{ return(*(int *)0); }
 
 #undef scroll
-int	scroll(
+int	(scroll)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef setscrreg
-int	setscrreg(
+int	(setscrreg)(
 		int	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef slk_attr_off
-int	slk_attr_off(
+int	(slk_attr_off)(
 		const attr_t a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef slk_attr_on
-int	slk_attr_on(
+int	(slk_attr_on)(
 		attr_t	a1, 
 		void	*z)
 		{ return(*(int *)0); }
 
 #undef standout
-int	standout(void)
+int	(standout)(void)
 		{ return(*(int *)0); }
 
 #undef standend
-int	standend(void)
+int	(standend)(void)
 		{ return(*(int *)0); }
 
 #undef timeout
-void	timeout(
+void	(timeout)(
 		int	z)
 		{ /* void */ }
 
 #undef touchline
-int	touchline(
+int	(touchline)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef touchwin
-int	touchwin(
+int	(touchwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef untouchwin
-int	untouchwin(
+int	(untouchwin)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef vline
-int	vline(
+int	(vline)(
 		chtype	a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef vw_printw
-int	vw_printw(
+int	(vw_printw)(
 		WINDOW	*a1, 
 		const char *a2, 
 		va_list	z)
 		{ return(*(int *)0); }
 
 #undef vw_scanw
-int	vw_scanw(
+int	(vw_scanw)(
 		WINDOW	*a1, 
-		char	*a2, 
+		const char *a2, 
 		va_list	z)
 		{ return(*(int *)0); }
 
 #undef waddchstr
-int	waddchstr(
+int	(waddchstr)(
 		WINDOW	*a1, 
 		const chtype *z)
 		{ return(*(int *)0); }
 
 #undef waddstr
-int	waddstr(
+int	(waddstr)(
 		WINDOW	*a1, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef wattron
-int	wattron(
+int	(wattron)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattroff
-int	wattroff(
+int	(wattroff)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattrset
-int	wattrset(
+int	(wattrset)(
 		WINDOW	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wattr_get
-int	wattr_get(
+int	(wattr_get)(
 		WINDOW	*a1, 
 		attr_t	*a2, 
 		short	*a3, 
@@ -1015,7 +1125,7 @@
 		{ return(*(int *)0); }
 
 #undef wattr_set
-int	wattr_set(
+int	(wattr_set)(
 		WINDOW	*a1, 
 		attr_t	a2, 
 		short	a3, 
@@ -1023,195 +1133,210 @@
 		{ return(*(int *)0); }
 
 #undef wdeleteln
-int	wdeleteln(
+int	(wdeleteln)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef wgetstr
-int	wgetstr(
+int	(wgetstr)(
 		WINDOW	*a1, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef winchstr
-int	winchstr(
+int	(winchstr)(
 		WINDOW	*a1, 
 		chtype	*z)
 		{ return(*(int *)0); }
 
 #undef winsertln
-int	winsertln(
+int	(winsertln)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef winsstr
-int	winsstr(
+int	(winsstr)(
 		WINDOW	*a1, 
 		const char *z)
 		{ return(*(int *)0); }
 
 #undef winstr
-int	winstr(
+int	(winstr)(
 		WINDOW	*a1, 
 		char	*z)
 		{ return(*(int *)0); }
 
 #undef wstandout
-int	wstandout(
+int	(wstandout)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef wstandend
-int	wstandend(
+int	(wstandend)(
 		WINDOW	*z)
 		{ return(*(int *)0); }
 
 #undef getattrs
-int	getattrs(
+int	(getattrs)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getcurx
-int	getcurx(
+int	(getcurx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getcury
-int	getcury(
+int	(getcury)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getbegx
-int	getbegx(
+int	(getbegx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getbegy
-int	getbegy(
+int	(getbegy)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getmaxx
-int	getmaxx(
+int	(getmaxx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getmaxy
-int	getmaxy(
+int	(getmaxy)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getparx
-int	getparx(
+int	(getparx)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef getpary
-int	getpary(
+int	(getpary)(
 		const WINDOW *z)
 		{ return(*(int *)0); }
 
 #undef wgetparent
-WINDOW	*wgetparent(
+WINDOW	*(wgetparent)(
 		const WINDOW *z)
 		{ return(*(WINDOW **)0); }
 
 #undef is_cleared
-NCURSES_BOOL is_cleared(
+NCURSES_BOOL (is_cleared)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_idcok
-NCURSES_BOOL is_idcok(
+NCURSES_BOOL (is_idcok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_idlok
-NCURSES_BOOL is_idlok(
+NCURSES_BOOL (is_idlok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_immedok
-NCURSES_BOOL is_immedok(
+NCURSES_BOOL (is_immedok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_keypad
-NCURSES_BOOL is_keypad(
+NCURSES_BOOL (is_keypad)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_leaveok
-NCURSES_BOOL is_leaveok(
+NCURSES_BOOL (is_leaveok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_nodelay
-NCURSES_BOOL is_nodelay(
+NCURSES_BOOL (is_nodelay)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_notimeout
-NCURSES_BOOL is_notimeout(
+NCURSES_BOOL (is_notimeout)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_pad
+NCURSES_BOOL (is_pad)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_scrollok
-NCURSES_BOOL is_scrollok(
+NCURSES_BOOL (is_scrollok)(
+		const WINDOW *z)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef is_subwin
+NCURSES_BOOL (is_subwin)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
 #undef is_syncok
-NCURSES_BOOL is_syncok(
+NCURSES_BOOL (is_syncok)(
 		const WINDOW *z)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef wgetdelay
+int	(wgetdelay)(
+		const WINDOW *z)
+		{ return(*(int *)0); }
+
 #undef wgetscrreg
-int	wgetscrreg(
+int	(wgetscrreg)(
 		const WINDOW *a1, 
 		int	*a2, 
 		int	*z)
 		{ return(*(int *)0); }
 
 #undef add_wch
-int	add_wch(
+int	(add_wch)(
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef add_wchnstr
-int	add_wchnstr(
+int	(add_wchnstr)(
 		const cchar_t *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef add_wchstr
-int	add_wchstr(
+int	(add_wchstr)(
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef addnwstr
-int	addnwstr(
+int	(addnwstr)(
 		const wchar_t *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef addwstr
-int	addwstr(
+int	(addwstr)(
 		const wchar_t *z)
 		{ return(*(int *)0); }
 
 #undef bkgrnd
-int	bkgrnd(
+int	(bkgrnd)(
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef bkgrndset
-void	bkgrndset(
+void	(bkgrndset)(
 		const cchar_t *z)
 		{ /* void */ }
 
 #undef border_set
-int	border_set(
+int	(border_set)(
 		const cchar_t *a1, 
 		const cchar_t *a2, 
 		const cchar_t *a3, 
@@ -1223,96 +1348,96 @@
 		{ return(*(int *)0); }
 
 #undef box_set
-int	box_set(
+int	(box_set)(
 		WINDOW	*a1, 
 		const cchar_t *a2, 
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef echo_wchar
-int	echo_wchar(
+int	(echo_wchar)(
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef get_wch
-int	get_wch(
+int	(get_wch)(
 		wint_t	*z)
 		{ return(*(int *)0); }
 
 #undef get_wstr
-int	get_wstr(
+int	(get_wstr)(
 		wint_t	*z)
 		{ return(*(int *)0); }
 
 #undef getbkgrnd
-int	getbkgrnd(
+int	(getbkgrnd)(
 		cchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef getn_wstr
-int	getn_wstr(
+int	(getn_wstr)(
 		wint_t	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef hline_set
-int	hline_set(
+int	(hline_set)(
 		const cchar_t *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef in_wch
-int	in_wch(
+int	(in_wch)(
 		cchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef in_wchnstr
-int	in_wchnstr(
+int	(in_wchnstr)(
 		cchar_t	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef in_wchstr
-int	in_wchstr(
+int	(in_wchstr)(
 		cchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef innwstr
-int	innwstr(
+int	(innwstr)(
 		wchar_t	*a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef ins_nwstr
-int	ins_nwstr(
+int	(ins_nwstr)(
 		const wchar_t *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef ins_wch
-int	ins_wch(
+int	(ins_wch)(
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef ins_wstr
-int	ins_wstr(
+int	(ins_wstr)(
 		const wchar_t *z)
 		{ return(*(int *)0); }
 
 #undef inwstr
-int	inwstr(
+int	(inwstr)(
 		wchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef mvadd_wch
-int	mvadd_wch(
+int	(mvadd_wch)(
 		int	a1, 
 		int	a2, 
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef mvadd_wchnstr
-int	mvadd_wchnstr(
+int	(mvadd_wchnstr)(
 		int	a1, 
 		int	a2, 
 		const cchar_t *a3, 
@@ -1320,14 +1445,14 @@
 		{ return(*(int *)0); }
 
 #undef mvadd_wchstr
-int	mvadd_wchstr(
+int	(mvadd_wchstr)(
 		int	a1, 
 		int	a2, 
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef mvaddnwstr
-int	mvaddnwstr(
+int	(mvaddnwstr)(
 		int	a1, 
 		int	a2, 
 		const wchar_t *a3, 
@@ -1335,28 +1460,28 @@
 		{ return(*(int *)0); }
 
 #undef mvaddwstr
-int	mvaddwstr(
+int	(mvaddwstr)(
 		int	a1, 
 		int	a2, 
 		const wchar_t *z)
 		{ return(*(int *)0); }
 
 #undef mvget_wch
-int	mvget_wch(
+int	(mvget_wch)(
 		int	a1, 
 		int	a2, 
 		wint_t	*z)
 		{ return(*(int *)0); }
 
 #undef mvget_wstr
-int	mvget_wstr(
+int	(mvget_wstr)(
 		int	a1, 
 		int	a2, 
 		wint_t	*z)
 		{ return(*(int *)0); }
 
 #undef mvgetn_wstr
-int	mvgetn_wstr(
+int	(mvgetn_wstr)(
 		int	a1, 
 		int	a2, 
 		wint_t	*a3, 
@@ -1364,7 +1489,7 @@
 		{ return(*(int *)0); }
 
 #undef mvhline_set
-int	mvhline_set(
+int	(mvhline_set)(
 		int	a1, 
 		int	a2, 
 		const cchar_t *a3, 
@@ -1372,14 +1497,14 @@
 		{ return(*(int *)0); }
 
 #undef mvin_wch
-int	mvin_wch(
+int	(mvin_wch)(
 		int	a1, 
 		int	a2, 
 		cchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef mvin_wchnstr
-int	mvin_wchnstr(
+int	(mvin_wchnstr)(
 		int	a1, 
 		int	a2, 
 		cchar_t	*a3, 
@@ -1387,14 +1512,14 @@
 		{ return(*(int *)0); }
 
 #undef mvin_wchstr
-int	mvin_wchstr(
+int	(mvin_wchstr)(
 		int	a1, 
 		int	a2, 
 		cchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef mvinnwstr
-int	mvinnwstr(
+int	(mvinnwstr)(
 		int	a1, 
 		int	a2, 
 		wchar_t	*a3, 
@@ -1402,7 +1527,7 @@
 		{ return(*(int *)0); }
 
 #undef mvins_nwstr
-int	mvins_nwstr(
+int	(mvins_nwstr)(
 		int	a1, 
 		int	a2, 
 		const wchar_t *a3, 
@@ -1410,28 +1535,28 @@
 		{ return(*(int *)0); }
 
 #undef mvins_wch
-int	mvins_wch(
+int	(mvins_wch)(
 		int	a1, 
 		int	a2, 
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef mvins_wstr
-int	mvins_wstr(
+int	(mvins_wstr)(
 		int	a1, 
 		int	a2, 
 		const wchar_t *z)
 		{ return(*(int *)0); }
 
 #undef mvinwstr
-int	mvinwstr(
+int	(mvinwstr)(
 		int	a1, 
 		int	a2, 
 		wchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef mvvline_set
-int	mvvline_set(
+int	(mvvline_set)(
 		int	a1, 
 		int	a2, 
 		const cchar_t *a3, 
@@ -1439,7 +1564,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwadd_wch
-int	mvwadd_wch(
+int	(mvwadd_wch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1447,7 +1572,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwadd_wchnstr
-int	mvwadd_wchnstr(
+int	(mvwadd_wchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1456,7 +1581,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwadd_wchstr
-int	mvwadd_wchstr(
+int	(mvwadd_wchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1464,7 +1589,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddnwstr
-int	mvwaddnwstr(
+int	(mvwaddnwstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1473,7 +1598,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwaddwstr
-int	mvwaddwstr(
+int	(mvwaddwstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1481,7 +1606,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwget_wch
-int	mvwget_wch(
+int	(mvwget_wch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1489,7 +1614,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwget_wstr
-int	mvwget_wstr(
+int	(mvwget_wstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1497,7 +1622,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwgetn_wstr
-int	mvwgetn_wstr(
+int	(mvwgetn_wstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1506,7 +1631,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwhline_set
-int	mvwhline_set(
+int	(mvwhline_set)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1515,7 +1640,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwin_wch
-int	mvwin_wch(
+int	(mvwin_wch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1523,7 +1648,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwin_wchnstr
-int	mvwin_wchnstr(
+int	(mvwin_wchnstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1532,7 +1657,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwin_wchstr
-int	mvwin_wchstr(
+int	(mvwin_wchstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1540,7 +1665,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinnwstr
-int	mvwinnwstr(
+int	(mvwinnwstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1549,7 +1674,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwins_nwstr
-int	mvwins_nwstr(
+int	(mvwins_nwstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1558,7 +1683,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwins_wch
-int	mvwins_wch(
+int	(mvwins_wch)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1566,7 +1691,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwins_wstr
-int	mvwins_wstr(
+int	(mvwins_wstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1574,7 +1699,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwinwstr
-int	mvwinwstr(
+int	(mvwinwstr)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1582,7 +1707,7 @@
 		{ return(*(int *)0); }
 
 #undef mvwvline_set
-int	mvwvline_set(
+int	(mvwvline_set)(
 		WINDOW	*a1, 
 		int	a2, 
 		int	a3, 
@@ -1591,49 +1716,49 @@
 		{ return(*(int *)0); }
 
 #undef vline_set
-int	vline_set(
+int	(vline_set)(
 		const cchar_t *a1, 
 		int	z)
 		{ return(*(int *)0); }
 
 #undef wadd_wchstr
-int	wadd_wchstr(
+int	(wadd_wchstr)(
 		WINDOW	*a1, 
 		const cchar_t *z)
 		{ return(*(int *)0); }
 
 #undef waddwstr
-int	waddwstr(
+int	(waddwstr)(
 		WINDOW	*a1, 
 		const wchar_t *z)
 		{ return(*(int *)0); }
 
 #undef wget_wstr
-int	wget_wstr(
+int	(wget_wstr)(
 		WINDOW	*a1, 
 		wint_t	*z)
 		{ return(*(int *)0); }
 
 #undef wgetbkgrnd
-int	wgetbkgrnd(
+int	(wgetbkgrnd)(
 		WINDOW	*a1, 
 		cchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef win_wchstr
-int	win_wchstr(
+int	(win_wchstr)(
 		WINDOW	*a1, 
 		cchar_t	*z)
 		{ return(*(int *)0); }
 
 #undef wins_wstr
-int	wins_wstr(
+int	(wins_wstr)(
 		WINDOW	*a1, 
 		const wchar_t *z)
 		{ return(*(int *)0); }
 
 #undef mouse_trafo
-NCURSES_BOOL mouse_trafo(
+NCURSES_BOOL (mouse_trafo)(
 		int	*a1, 
 		int	*a2, 
 		NCURSES_BOOL z)
@@ -1641,20 +1766,33 @@
 
 /* ./base/lib_getch.c */
 
-#include <fifo_defs.h>
-
 #undef ESCDELAY
 int	ESCDELAY;
 
+#undef set_escdelay_sp
+int	set_escdelay_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ return(*(int *)0); }
+
 #undef set_escdelay
 int	set_escdelay(
 		int	value)
 		{ return(*(int *)0); }
 
+#undef get_escdelay_sp
+int	get_escdelay_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef get_escdelay
+int	get_escdelay(void)
+		{ return(*(int *)0); }
+
 #undef _nc_wgetch
 int	_nc_wgetch(
 		WINDOW	*win, 
-		unsigned long *result, 
+		int	*result, 
 		int	use_meta)
 		{ return(*(int *)0); }
 
@@ -1708,6 +1846,7 @@
 
 #undef _nc_insert_ch
 int	_nc_insert_ch(
+		SCREEN	*sp, 
 		WINDOW	*win, 
 		chtype	ch)
 		{ return(*(int *)0); }
@@ -1746,6 +1885,11 @@
 
 /* ./base/lib_isendwin.c */
 
+#undef isendwin_sp
+NCURSES_BOOL isendwin_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef isendwin
 NCURSES_BOOL isendwin(void)
 		{ return(*(NCURSES_BOOL *)0); }
@@ -1760,16 +1904,42 @@
 
 /* ./base/lib_mouse.c */
 
+typedef struct {
+    int nerror; 
+    int nparam; 
+    int params[9];
+    int final; 
+} SGR_DATA;
+
+#undef getmouse_sp
+int	getmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
 #undef getmouse
 int	getmouse(
 		MEVENT	*aevent)
 		{ return(*(int *)0); }
 
+#undef ungetmouse_sp
+int	ungetmouse_sp(
+		SCREEN	*sp, 
+		MEVENT	*aevent)
+		{ return(*(int *)0); }
+
 #undef ungetmouse
 int	ungetmouse(
 		MEVENT	*aevent)
 		{ return(*(int *)0); }
 
+#undef mousemask_sp
+mmask_t	mousemask_sp(
+		SCREEN	*sp, 
+		mmask_t	newmask, 
+		mmask_t	*oldmask)
+		{ return(*(mmask_t *)0); }
+
 #undef mousemask
 mmask_t	mousemask(
 		mmask_t	newmask, 
@@ -1783,14 +1953,30 @@
 		int	x)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef mouseinterval_sp
+int	mouseinterval_sp(
+		SCREEN	*sp, 
+		int	maxclick)
+		{ return(*(int *)0); }
+
 #undef mouseinterval
 int	mouseinterval(
 		int	maxclick)
 		{ return(*(int *)0); }
 
 #undef _nc_has_mouse
-int	_nc_has_mouse(void)
-		{ return(*(int *)0); }
+NCURSES_BOOL _nc_has_mouse(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse_sp
+NCURSES_BOOL has_mouse_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_mouse
+NCURSES_BOOL has_mouse(void)
+		{ return(*(NCURSES_BOOL *)0); }
 
 #undef wmouse_trafo
 NCURSES_BOOL wmouse_trafo(
@@ -1811,24 +1997,72 @@
 
 /* ./tty/lib_mvcur.c */
 
+#undef _nc_msec_cost_sp
+int	_nc_msec_cost_sp(
+		SCREEN	*sp, 
+		const char *const cap, 
+		int	affcnt)
+		{ return(*(int *)0); }
+
 #undef _nc_msec_cost
 int	_nc_msec_cost(
 		const char *const cap, 
 		int	affcnt)
 		{ return(*(int *)0); }
 
+#undef _nc_mvcur_resume_sp
+void	_nc_mvcur_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_resume
 void	_nc_mvcur_resume(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_init_sp
+void	_nc_mvcur_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_init
 void	_nc_mvcur_init(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_wrap_sp
+void	_nc_mvcur_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_mvcur_wrap
 void	_nc_mvcur_wrap(void)
 		{ /* void */ }
 
+#undef _nc_mvcur_sp
+int	_nc_mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef _nc_mvcur
+int	_nc_mvcur(
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
+#undef mvcur_sp
+int	mvcur_sp(
+		SCREEN	*sp, 
+		int	yold, 
+		int	xold, 
+		int	ynew, 
+		int	xnew)
+		{ return(*(int *)0); }
+
 #undef mvcur
 int	mvcur(
 		int	yold, 
@@ -1851,17 +2085,35 @@
 
 /* ./base/lib_newterm.c */
 
+#undef filter_sp
+void	filter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef filter
 void	filter(void)
 		{ /* void */ }
 
+#undef nofilter_sp
+void	nofilter_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef nofilter
 void	nofilter(void)
 		{ /* void */ }
 
+#undef newterm_sp
+SCREEN	*newterm_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		FILE	*ofp, 
+		FILE	*ifp)
+		{ return(*(SCREEN **)0); }
+
 #undef newterm
 SCREEN	*newterm(
-		char	*name, 
+		const char *name, 
 		FILE	*ofp, 
 		FILE	*ifp)
 		{ return(*(SCREEN **)0); }
@@ -1873,6 +2125,15 @@
 		WINDOW	*win)
 		{ return(*(int *)0); }
 
+#undef newwin_sp
+WINDOW	*newwin_sp(
+		SCREEN	*sp, 
+		int	num_lines, 
+		int	num_columns, 
+		int	begy, 
+		int	begx)
+		{ return(*(WINDOW **)0); }
+
 #undef newwin
 WINDOW	*newwin(
 		int	num_lines, 
@@ -1899,8 +2160,9 @@
 		int	x)
 		{ return(*(WINDOW **)0); }
 
-#undef _nc_makenew
-WINDOW	*_nc_makenew(
+#undef _nc_makenew_sp
+WINDOW	*_nc_makenew_sp(
+		SCREEN	*sp, 
 		int	num_lines, 
 		int	num_columns, 
 		int	begy, 
@@ -1908,17 +2170,37 @@
 		int	flags)
 		{ return(*(WINDOW **)0); }
 
-#undef _nc_screen_of
-SCREEN	*_nc_screen_of(
-		WINDOW	*win)
-		{ return(*(SCREEN **)0); }
+#undef _nc_curscr_of
+WINDOW	*_nc_curscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_newscr_of
+WINDOW	*_nc_newscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
+
+#undef _nc_stdscr_of
+WINDOW	*_nc_stdscr_of(
+		SCREEN	*sp)
+		{ return(*(WINDOW **)0); }
 
 /* ./base/lib_nl.c */
 
+#undef nl_sp
+int	nl_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nl
 int	nl(void)
 		{ return(*(int *)0); }
 
+#undef nonl_sp
+int	nonl_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nonl
 int	nonl(void)
 		{ return(*(int *)0); }
@@ -1952,6 +2234,13 @@
 
 /* ./base/lib_pad.c */
 
+#undef newpad_sp
+WINDOW	*newpad_sp(
+		SCREEN	*sp, 
+		int	l, 
+		int	c)
+		{ return(*(WINDOW **)0); }
+
 #undef newpad
 WINDOW	*newpad(
 		int	l, 
@@ -2057,9 +2346,17 @@
 
 /* ./base/lib_restart.c */
 
+#undef restartterm_sp
+int	restartterm_sp(
+		SCREEN	*sp, 
+		const char *termp, 
+		int	filenum, 
+		int	*errret)
+		{ return(*(int *)0); }
+
 #undef restartterm
 int	restartterm(
-		char	*termp, 
+		const char *termp, 
 		int	filenum, 
 		int	*errret)
 		{ return(*(int *)0); }
@@ -2069,20 +2366,20 @@
 #undef vwscanw
 int	vwscanw(
 		WINDOW	*win, 
-		char	*fmt, 
+		const char *fmt, 
 		va_list	argp)
 		{ return(*(int *)0); }
 
 #undef scanw
 int	scanw(
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
 #undef wscanw
 int	wscanw(
 		WINDOW	*win, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
@@ -2090,7 +2387,7 @@
 int	mvscanw(
 		int	y, 
 		int	x, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
@@ -2099,12 +2396,40 @@
 		WINDOW	*win, 
 		int	y, 
 		int	x, 
-		char	*fmt, 
+		const char *fmt, 
 		...)
 		{ return(*(int *)0); }
 
 /* ./base/lib_screen.c */
 
+typedef enum {
+    pINT 
+    ,pSHORT 
+    ,pBOOL 
+    ,pATTR 
+    ,pCHAR 
+    ,pSIZE 
+    ,pCCHAR 
+} PARAM_TYPE;
+
+typedef struct {
+    const char name[11];
+    attr_t attr;
+} SCR_ATTRS;
+
+typedef struct {
+    const char name[17];
+    PARAM_TYPE type;
+    size_t size;
+    size_t offset;
+} SCR_PARAMS;
+
+#undef getwin_sp
+WINDOW	*getwin_sp(
+		SCREEN	*sp, 
+		FILE	*filep)
+		{ return(*(WINDOW **)0); }
+
 #undef getwin
 WINDOW	*getwin(
 		FILE	*filep)
@@ -2116,6 +2441,12 @@
 		FILE	*filep)
 		{ return(*(int *)0); }
 
+#undef scr_restore_sp
+int	scr_restore_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_restore
 int	scr_restore(
 		const char *file)
@@ -2126,11 +2457,23 @@
 		const char *file)
 		{ return(*(int *)0); }
 
+#undef scr_init_sp
+int	scr_init_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_init
 int	scr_init(
 		const char *file)
 		{ return(*(int *)0); }
 
+#undef scr_set_sp
+int	scr_set_sp(
+		SCREEN	*sp, 
+		const char *file)
+		{ return(*(int *)0); }
+
 #undef scr_set
 int	scr_set(
 		const char *file)
@@ -2142,8 +2485,8 @@
 void	_nc_scroll_window(
 		WINDOW	*win, 
 		int const n, 
-		short const top, 
-		short const bottom, 
+		int const top, 
+		int const bottom, 
 		cchar_t	blank)
 		{ /* void */ }
 
@@ -2182,15 +2525,34 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef _nc_setupscreen_sp
+int	_nc_setupscreen_sp(
+		SCREEN	**spp, 
+		int	slines, 
+		int	scolumns, 
+		FILE	*output, 
+		int	filtered, 
+		int	slk_format)
+		{ return(*(int *)0); }
+
 #undef _nc_setupscreen
 int	_nc_setupscreen(
 		int	slines, 
 		int	scolumns, 
 		FILE	*output, 
-		NCURSES_BOOL filtered, 
+		int	filtered, 
 		int	slk_format)
 		{ return(*(int *)0); }
 
+#undef _nc_ripoffline_sp
+int	_nc_ripoffline_sp(
+		SCREEN	*sp, 
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
 #undef _nc_ripoffline
 int	_nc_ripoffline(
 		int	line, 
@@ -2199,6 +2561,15 @@
 		int	p2))
 		{ return(*(int *)0); }
 
+#undef ripoffline_sp
+int	ripoffline_sp(
+		SCREEN	*sp, 
+		int	line, 
+		int	(*init)(
+		WINDOW	*p1, 
+		int	p2))
+		{ return(*(int *)0); }
+
 #undef ripoffline
 int	ripoffline(
 		int	line, 
@@ -2209,18 +2580,37 @@
 
 /* ./base/lib_slk.c */
 
+#undef _nc_format_slks
+int	_nc_format_slks(
+		SCREEN	*sp, 
+		int	cols)
+		{ return(*(int *)0); }
+
 #undef _nc_slk_initialize
 int	_nc_slk_initialize(
 		WINDOW	*stwin, 
 		int	cols)
 		{ return(*(int *)0); }
 
+#undef slk_restore_sp
+int	slk_restore_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_restore
 int	slk_restore(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkatr_set.c */
 
+#undef slk_attr_set_sp
+int	slk_attr_set_sp(
+		SCREEN	*sp, 
+		const attr_t attr, 
+		short	color_pair_number, 
+		void	*opts)
+		{ return(*(int *)0); }
+
 #undef slk_attr_set
 int	slk_attr_set(
 		const attr_t attr, 
@@ -2230,6 +2620,12 @@
 
 /* ./base/lib_slkatrof.c */
 
+#undef slk_attroff_sp
+int	slk_attroff_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attroff
 int	slk_attroff(
 		const chtype attr)
@@ -2237,6 +2633,12 @@
 
 /* ./base/lib_slkatron.c */
 
+#undef slk_attron_sp
+int	slk_attron_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attron
 int	slk_attron(
 		const chtype attr)
@@ -2244,6 +2646,12 @@
 
 /* ./base/lib_slkatrset.c */
 
+#undef slk_attrset_sp
+int	slk_attrset_sp(
+		SCREEN	*sp, 
+		const chtype attr)
+		{ return(*(int *)0); }
+
 #undef slk_attrset
 int	slk_attrset(
 		const chtype attr)
@@ -2251,18 +2659,34 @@
 
 /* ./base/lib_slkattr.c */
 
+#undef slk_attr_sp
+attr_t	slk_attr_sp(
+		SCREEN	*sp)
+		{ return(*(attr_t *)0); }
+
 #undef slk_attr
 attr_t	slk_attr(void)
 		{ return(*(attr_t *)0); }
 
 /* ./base/lib_slkclear.c */
 
+#undef slk_clear_sp
+int	slk_clear_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_clear
 int	slk_clear(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkcolor.c */
 
+#undef slk_color_sp
+int	slk_color_sp(
+		SCREEN	*sp, 
+		short	color_pair_number)
+		{ return(*(int *)0); }
+
 #undef slk_color
 int	slk_color(
 		short	color_pair_number)
@@ -2270,6 +2694,12 @@
 
 /* ./base/lib_slkinit.c */
 
+#undef slk_init_sp
+int	slk_init_sp(
+		SCREEN	*sp, 
+		int	format)
+		{ return(*(int *)0); }
+
 #undef slk_init
 int	slk_init(
 		int	format)
@@ -2277,6 +2707,12 @@
 
 /* ./base/lib_slklab.c */
 
+#undef slk_label_sp
+char	*slk_label_sp(
+		SCREEN	*sp, 
+		int	n)
+		{ return(*(char **)0); }
+
 #undef slk_label
 char	*slk_label(
 		int	n)
@@ -2284,17 +2720,33 @@
 
 /* ./base/lib_slkrefr.c */
 
+#undef slk_noutrefresh_sp
+int	slk_noutrefresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_noutrefresh
 int	slk_noutrefresh(void)
 		{ return(*(int *)0); }
 
+#undef slk_refresh_sp
+int	slk_refresh_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_refresh
 int	slk_refresh(void)
 		{ return(*(int *)0); }
 
 /* ./base/lib_slkset.c */
 
-#include <wctype.h>
+#undef slk_set_sp
+int	slk_set_sp(
+		SCREEN	*sp, 
+		int	i, 
+		const char *astr, 
+		int	format)
+		{ return(*(int *)0); }
 
 #undef slk_set
 int	slk_set(
@@ -2305,6 +2757,11 @@
 
 /* ./base/lib_slktouch.c */
 
+#undef slk_touch_sp
+int	slk_touch_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef slk_touch
 int	slk_touch(void)
 		{ return(*(int *)0); }
@@ -2340,12 +2797,24 @@
 
 /* ./trace/lib_tracemse.c */
 
+#undef _nc_trace_mmask_t
+char	*_nc_trace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(char **)0); }
+
 #undef _nc_tracemouse
 char	*_nc_tracemouse(
 		SCREEN	*sp, 
 		MEVENT const *ep)
 		{ return(*(char **)0); }
 
+#undef _nc_retrace_mmask_t
+mmask_t	_nc_retrace_mmask_t(
+		SCREEN	*sp, 
+		mmask_t	code)
+		{ return(*(mmask_t *)0); }
+
 #undef _tracemouse
 char	*_tracemouse(
 		MEVENT const *ep)
@@ -2353,11 +2822,9 @@
 
 /* ./tty/lib_tstp.c */
 
-#include <SigAction.h>
-
 #undef _nc_signal_handler
 void	_nc_signal_handler(
-		NCURSES_BOOL enable)
+		int	enable)
 		{ /* void */ }
 
 /* ./base/lib_ungetch.c */
@@ -2367,8 +2834,8 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
-#undef _nc_ungetch
-int	_nc_ungetch(
+#undef ungetch_sp
+int	ungetch_sp(
 		SCREEN	*sp, 
 		int	ch)
 		{ return(*(int *)0); }
@@ -2380,11 +2847,23 @@
 
 /* ./tty/lib_vidattr.c */
 
+#undef vidputs_sp
+int	vidputs_sp(
+		SCREEN	*sp, 
+		chtype	newmode, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
 #undef vidputs
 int	vidputs(
 		chtype	newmode, 
-		int	(*outc)(
-		int	p1))
+		NCURSES_OUTC outc)
+		{ return(*(int *)0); }
+
+#undef vidattr_sp
+int	vidattr_sp(
+		SCREEN	*sp, 
+		chtype	newmode)
 		{ return(*(int *)0); }
 
 #undef vidattr
@@ -2392,6 +2871,11 @@
 		chtype	newmode)
 		{ return(*(int *)0); }
 
+#undef termattrs_sp
+chtype	termattrs_sp(
+		SCREEN	*sp)
+		{ return(*(chtype *)0); }
+
 #undef termattrs
 chtype	termattrs(void)
 		{ return(*(chtype *)0); }
@@ -2472,12 +2956,24 @@
 
 /* ./base/nc_panel.c */
 
+#undef _nc_panelhook_sp
+struct panelhook *_nc_panelhook_sp(
+		SCREEN	*sp)
+		{ return(*(struct panelhook **)0); }
+
 #undef _nc_panelhook
 struct panelhook *_nc_panelhook(void)
 		{ return(*(struct panelhook **)0); }
 
 /* ./base/safe_sprintf.c */
 
+#undef _nc_printf_string_sp
+char	*_nc_printf_string_sp(
+		SCREEN	*sp, 
+		const char *fmt, 
+		va_list	ap)
+		{ return(*(char **)0); }
+
 #undef _nc_printf_string
 char	*_nc_printf_string(
 		const char *fmt, 
@@ -2486,13 +2982,24 @@
 
 /* ./tty/tty_update.c */
 
-#include <sys/time.h>
-#include <sys/times.h>
+#undef doupdate_sp
+int	doupdate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
 
 #undef doupdate
 int	doupdate(void)
 		{ return(*(int *)0); }
 
+#undef _nc_scrolln_sp
+int	_nc_scrolln_sp(
+		SCREEN	*sp, 
+		int	n, 
+		int	top, 
+		int	bot, 
+		int	maxy)
+		{ return(*(int *)0); }
+
 #undef _nc_scrolln
 int	_nc_scrolln(
 		int	n, 
@@ -2501,18 +3008,39 @@
 		int	maxy)
 		{ return(*(int *)0); }
 
+#undef _nc_screen_resume_sp
+void	_nc_screen_resume_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_resume
 void	_nc_screen_resume(void)
 		{ /* void */ }
 
+#undef _nc_screen_init_sp
+void	_nc_screen_init_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_init
 void	_nc_screen_init(void)
 		{ /* void */ }
 
+#undef _nc_screen_wrap_sp
+void	_nc_screen_wrap_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_screen_wrap
 void	_nc_screen_wrap(void)
 		{ /* void */ }
 
+#undef _nc_do_xmc_glitch_sp
+void	_nc_do_xmc_glitch_sp(
+		SCREEN	*sp, 
+		attr_t	previous)
+		{ /* void */ }
+
 #undef _nc_do_xmc_glitch
 void	_nc_do_xmc_glitch(
 		attr_t	previous)
@@ -2530,12 +3058,6 @@
 		va_list	ap)
 		{ return(*(char **)0); }
 
-/* ./base/memmove.c */
-
-#undef _nc_memmove
-void	_nc_memmove(void)
-		{ /* void */ }
-
 /* ./base/vsscanf.c */
 
 #undef _nc_vsscanf
@@ -2544,12 +3066,16 @@
 
 /* ./base/lib_freeall.c */
 
-#include <term_entry.h>
-
 #undef _nc_freeall
 void	_nc_freeall(void)
 		{ /* void */ }
 
+#undef _nc_free_and_exit_sp
+void	_nc_free_and_exit_sp(
+		SCREEN	*sp, 
+		int	code)
+		{ /* void */ }
+
 #undef _nc_free_and_exit
 void	_nc_free_and_exit(
 		int	code)
@@ -2678,6 +3204,12 @@
 
 /* ./widechar/lib_ins_wch.c */
 
+#undef _nc_insert_wch
+int	_nc_insert_wch(
+		WINDOW	*win, 
+		const cchar_t *wch)
+		{ return(*(int *)0); }
+
 #undef wins_wch
 int	wins_wch(
 		WINDOW	*win, 
@@ -2709,9 +3241,9 @@
 /* ./widechar/lib_key_name.c */
 
 #undef key_name
-char	*key_name(
+const char *key_name(
 		wchar_t	c)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 /* ./widechar/lib_pecho_wchar.c */
 
@@ -2739,6 +3271,12 @@
 		mbstate_t *state)
 		{ return(*(size_t *)0); }
 
+#undef unget_wch_sp
+int	unget_wch_sp(
+		SCREEN	*sp, 
+		const wchar_t wch)
+		{ return(*(int *)0); }
+
 #undef unget_wch
 int	unget_wch(
 		const wchar_t wch)
@@ -2746,13 +3284,29 @@
 
 /* ./widechar/lib_vid_attr.c */
 
+#undef vid_puts_sp
+int	vid_puts_sp(
+		SCREEN	*sp, 
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
 #undef vid_puts
 int	vid_puts(
 		attr_t	newmode, 
 		short	pair, 
 		void	*opts, 
-		int	(*outc)(
-		int	p1))
+		NCURSES_OUTC outc)
+		{ return(*(int *)0); }
+
+#undef vid_attr_sp
+int	vid_attr_sp(
+		SCREEN	*sp, 
+		attr_t	newmode, 
+		short	pair, 
+		void	*opts)
 		{ return(*(int *)0); }
 
 #undef vid_attr
@@ -2762,6 +3316,11 @@
 		void	*opts)
 		{ return(*(int *)0); }
 
+#undef term_attrs_sp
+attr_t	term_attrs_sp(
+		SCREEN	*sp)
+		{ return(*(attr_t *)0); }
+
 #undef term_attrs
 attr_t	term_attrs(void)
 		{ return(*(attr_t *)0); }
@@ -2786,6 +3345,12 @@
 
 /* ./widechar/lib_wunctrl.c */
 
+#undef wunctrl_sp
+wchar_t	*wunctrl_sp(
+		SCREEN	*sp, 
+		cchar_t	*wc)
+		{ return(*(wchar_t **)0); }
+
 #undef wunctrl
 wchar_t	*wunctrl(
 		cchar_t	*wc)
@@ -2805,6 +3370,24 @@
 		attr_t	at)
 		{ /* void */ }
 
+#undef _nc_DelCharCost_sp
+int	_nc_DelCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_InsCharCost_sp
+int	_nc_InsCharCost_sp(
+		SCREEN	*sp, 
+		int	count)
+		{ return(*(int *)0); }
+
+#undef _nc_UpdateAttrs_sp
+void	_nc_UpdateAttrs_sp(
+		SCREEN	*sp, 
+		const cchar_t *c)
+		{ /* void */ }
+
 #undef _nc_DelCharCost
 int	_nc_DelCharCost(
 		int	count)
@@ -2817,11 +3400,17 @@
 
 #undef _nc_UpdateAttrs
 void	_nc_UpdateAttrs(
-		cchar_t	c)
+		const cchar_t *c)
 		{ /* void */ }
 
 /* ./base/legacy_coding.c */
 
+#undef use_legacy_coding_sp
+int	use_legacy_coding_sp(
+		SCREEN	*sp, 
+		int	level)
+		{ return(*(int *)0); }
+
 #undef use_legacy_coding
 int	use_legacy_coding(
 		int	level)
@@ -2829,10 +3418,22 @@
 
 /* ./base/lib_dft_fgbg.c */
 
+#undef use_default_colors_sp
+int	use_default_colors_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef use_default_colors
 int	use_default_colors(void)
 		{ return(*(int *)0); }
 
+#undef assume_default_colors_sp
+int	assume_default_colors_sp(
+		SCREEN	*sp, 
+		int	fg, 
+		int	bg)
+		{ return(*(int *)0); }
+
 #undef assume_default_colors
 int	assume_default_colors(
 		int	fg, 
@@ -2841,6 +3442,13 @@
 
 /* ./tinfo/lib_print.c */
 
+#undef mcprint_sp
+int	mcprint_sp(
+		SCREEN	*sp, 
+		char	*data, 
+		int	len)
+		{ return(*(int *)0); }
+
 #undef mcprint
 int	mcprint(
 		char	*data, 
@@ -2849,18 +3457,39 @@
 
 /* ./base/resizeterm.c */
 
+#undef is_term_resized_sp
+NCURSES_BOOL is_term_resized_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef is_term_resized
 NCURSES_BOOL is_term_resized(
 		int	ToLines, 
 		int	ToCols)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef resize_term_sp
+int	resize_term_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
 #undef resize_term
 int	resize_term(
 		int	ToLines, 
 		int	ToCols)
 		{ return(*(int *)0); }
 
+#undef resizeterm_sp
+int	resizeterm_sp(
+		SCREEN	*sp, 
+		int	ToLines, 
+		int	ToCols)
+		{ return(*(int *)0); }
+
 #undef resizeterm
 int	resizeterm(
 		int	ToLines, 
@@ -2903,9 +3532,6 @@
 
 /* ./tinfo/access.c */
 
-#include <sys/stat.h>
-#include <nc_alloc.h>
-
 #undef _nc_rootname
 char	*_nc_rootname(
 		char	*path)
@@ -2966,19 +3592,42 @@
 #undef _nc_copy_termtype
 void	_nc_copy_termtype(
 		TERMTYPE *dst, 
-		TERMTYPE *src)
+		const TERMTYPE *src)
 		{ /* void */ }
 
 /* ./codes.c */
 
 #undef boolcodes
-char	*const boolcodes[] = {0};
+const char *const boolcodes[] = {0};
 #undef numcodes
-char	*const numcodes[] = {0};
+const char *const numcodes[] = {0};
 #undef strcodes
-char	*const strcodes[] = {0};
+const char *const strcodes[] = {0};
+
+/* ./comp_captab.c */
+
+#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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)0); }
 
 /* ./tinfo/comp_error.c */
+
 #undef _nc_suppress_warnings
 NCURSES_BOOL _nc_suppress_warnings;
 #undef _nc_curr_line
@@ -3023,6 +3672,21 @@
 		...)
 		{ /* void */ }
 
+/* ./tinfo/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
 /* ./tinfo/db_iterator.c */
 
 #undef _nc_tic_dir
@@ -3116,6 +3780,12 @@
 		const char *name)
 		{ return(*(int *)0); }
 
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
 /* ./tinfo/home_terminfo.c */
 
 #undef _nc_home_terminfo
@@ -3124,15 +3794,6 @@
 
 /* ./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)
@@ -3143,16 +3804,19 @@
 #undef acs_map
 chtype	acs_map[128];
 
+#undef _nc_init_acs_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_init_acs
 void	_nc_init_acs(void)
 		{ /* void */ }
 
 /* ./tinfo/lib_baudrate.c */
 
-#include <termcap.h>
-
 struct speed {
-    int s; 
+    short s; 
     int sp; 
 };
 
@@ -3166,6 +3830,11 @@
 		int	BaudRate)
 		{ return(*(int *)0); }
 
+#undef baudrate_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef baudrate
 int	baudrate(void)
 		{ return(*(int *)0); }
@@ -3175,11 +3844,23 @@
 #undef cur_term
 TERMINAL *cur_term;
 
+#undef set_curterm_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
 #undef set_curterm
 TERMINAL *set_curterm(
 		TERMINAL *termp)
 		{ return(*(TERMINAL **)0); }
 
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)0); }
+
 #undef del_curterm
 int	del_curterm(
 		TERMINAL *termp)
@@ -3202,26 +3883,56 @@
 #undef _nc_prescreen
 NCURSES_PRESCREEN _nc_prescreen;
 
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
 /* ./tinfo/lib_has_cap.c */
 
+#undef has_ic_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_ic
 NCURSES_BOOL has_ic(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
 #undef has_il
 NCURSES_BOOL has_il(void)
 		{ return(*(NCURSES_BOOL *)0); }
 
 /* ./tinfo/lib_kernel.c */
 
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
 #undef erasechar
 char	erasechar(void)
 		{ return(*(char *)0); }
 
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
 #undef killchar
 char	killchar(void)
 		{ return(*(char *)0); }
 
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef flushinp
 int	flushinp(void)
 		{ return(*(int *)0); }
@@ -3230,26 +3941,35 @@
 
 struct kn { short offset; int code; };
 
-#undef _nc_keyname
-char	*_nc_keyname(
+#undef keyname_sp
+const char *keyname_sp(
 		SCREEN	*sp, 
 		int	c)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 #undef keyname
-char	*keyname(
+const char *keyname(
 		int	c)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 /* ./tinfo/lib_longname.c */
 
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
 #undef longname
 char	*longname(void)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_napms.c */
 
-#include <time.h>
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
 
 #undef napms
 int	napms(
@@ -3270,6 +3990,12 @@
 		NCURSES_BOOL flag)
 		{ /* void */ }
 
+#undef halfdelay_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
 #undef halfdelay
 int	halfdelay(
 		int	t)
@@ -3305,53 +4031,115 @@
 		NCURSES_BOOL flag)
 		{ return(*(int *)0); }
 
+#undef curs_set_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
 #undef curs_set
 int	curs_set(
 		int	vis)
 		{ return(*(int *)0); }
 
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
 #undef typeahead
 int	typeahead(
 		int	fd)
 		{ return(*(int *)0); }
 
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
 #undef has_key
 int	has_key(
 		int	keycode)
 		{ return(*(int *)0); }
 
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
 #undef _nc_keypad
 int	_nc_keypad(
 		SCREEN	*sp, 
-		NCURSES_BOOL flag)
+		int	flag)
 		{ return(*(int *)0); }
 
 /* ./tinfo/lib_raw.c */
 
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef raw
 int	raw(void)
 		{ return(*(int *)0); }
 
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef cbreak
 int	cbreak(void)
 		{ return(*(int *)0); }
 
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef qiflush
 void	qiflush(void)
 		{ /* void */ }
 
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef noraw
 int	noraw(void)
 		{ return(*(int *)0); }
 
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef nocbreak
 int	nocbreak(void)
 		{ return(*(int *)0); }
 
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef noqiflush
 void	noqiflush(void)
 		{ /* void */ }
 
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
 #undef intrflush
 int	intrflush(
 		WINDOW	*win, 
@@ -3360,10 +4148,6 @@
 
 /* ./tinfo/lib_setup.c */
 
-#include <locale.h>
-#include <sys/ioctl.h>
-#include <langinfo.h>
-
 #undef ttytype
 char	ttytype[256];
 #undef LINES
@@ -3373,6 +4157,12 @@
 #undef TABSIZE
 int	TABSIZE;
 
+#undef set_tabsize_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ return(*(int *)0); }
+
 #undef set_tabsize
 int	set_tabsize(
 		int	value)
@@ -3383,11 +4173,28 @@
 		SCREEN	*sp)
 		{ return(*(int *)0); }
 
+#undef use_env_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
 #undef use_env
 void	use_env(
 		NCURSES_BOOL f)
 		{ /* void */ }
 
+#undef use_tioctl
+void	use_tioctl(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
 #undef _nc_get_screensize
 void	_nc_get_screensize(
 		SCREEN	*sp, 
@@ -3400,6 +4207,18 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef _nc_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* void */ }
+
 #undef _nc_get_locale
 char	*_nc_get_locale(void)
 		{ return(*(char **)0); }
@@ -3415,15 +4234,19 @@
 
 #undef _nc_setupterm
 int	_nc_setupterm(
-		char	*tname, 
+		const char *tname, 
 		int	Filedes, 
 		int	*errret, 
-		NCURSES_BOOL reuse)
+		int	reuse)
 		{ return(*(int *)0); }
 
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
 #undef setupterm
 int	setupterm(
-		char	*tname, 
+		const char *tname, 
 		int	Filedes, 
 		int	*errret)
 		{ return(*(int *)0); }
@@ -3435,36 +4258,61 @@
 #undef BC
 char	*BC;
 
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
 #undef tgetent
 int	tgetent(
 		char	*bufp, 
 		const char *name)
 		{ return(*(int *)0); }
 
-#if 0
-
-#include <capdefaults.c>
-
-#endif
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
 
 #undef tgetflag
 int	tgetflag(
-		char	*id)
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
 		{ return(*(int *)0); }
 
 #undef tgetnum
 int	tgetnum(
-		char	*id)
+		const char *id)
 		{ return(*(int *)0); }
 
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
 #undef tgetstr
 char	*tgetstr(
-		char	*id, 
+		const char *id, 
 		char	**area)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_termname.c */
 
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
 #undef termname
 char	*termname(void)
 		{ return(*(char **)0); }
@@ -3480,19 +4328,37 @@
 
 /* ./tinfo/lib_ti.c */
 
+#undef tigetflag_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
 #undef tigetflag
 int	tigetflag(
-		char	*str)
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
 		{ return(*(int *)0); }
 
 #undef tigetnum
 int	tigetnum(
-		char	*str)
+		const char *str)
 		{ return(*(int *)0); }
 
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
 #undef tigetstr
 char	*tigetstr(
-		char	*str)
+		const char *str)
 		{ return(*(char **)0); }
 
 /* ./tinfo/lib_tparm.c */
@@ -3504,12 +4370,18 @@
 int	_nc_tparm_analyze(
 		const char *string, 
 		char	*p_is_s[9], 
-		int	*popcount)
+		int	*_nc_popcount)
 		{ return(*(int *)0); }
 
 #undef tparm
 char	*tparm(
-		char	*string, 
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
 		...)
 		{ return(*(char **)0); }
 
@@ -3518,7 +4390,7 @@
 #undef PC
 char	PC;
 #undef ospeed
-NCURSES_OSPEED	ospeed;
+short	ospeed;
 #undef _nc_nulls_sent
 int	_nc_nulls_sent;
 
@@ -3527,25 +4399,86 @@
 		SCREEN	*sp)
 		{ /* void */ }
 
+#undef delay_output_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
 #undef delay_output
 int	delay_output(
 		int	ms)
 		{ return(*(int *)0); }
 
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
 #undef _nc_flush
 void	_nc_flush(void)
 		{ /* void */ }
 
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
 #undef _nc_outch
 int	_nc_outch(
 		int	ch)
 		{ return(*(int *)0); }
 
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
 #undef putp
 int	putp(
 		const char *string)
 		{ return(*(int *)0); }
 
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(int *)0); }
+
 #undef tputs
 int	tputs(
 		const char *string, 
@@ -3576,9 +4509,14 @@
 
 #undef _nc_retrace_bool
 NCURSES_BOOL _nc_retrace_bool(
-		NCURSES_BOOL code)
+		int	code)
 		{ return(*(NCURSES_BOOL *)0); }
 
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)0); }
+
 #undef _nc_retrace_int
 int	_nc_retrace_int(
 		int	code)
@@ -3600,9 +4538,9 @@
 		{ return(*(const char **)0); }
 
 #undef _nc_retrace_cvoid_ptr
-void	*_nc_retrace_cvoid_ptr(
-		void	*code)
-		{ return(*(void **)0); }
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const void **)0); }
 
 #undef _nc_retrace_void_ptr
 void	*_nc_retrace_void_ptr(
@@ -3632,6 +4570,11 @@
 		attr_t	newmode)
 		{ return(*(char **)0); }
 
+#undef _nc_retrace_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)0); }
+
 #undef _nc_retrace_attr_t
 attr_t	_nc_retrace_attr_t(
 		attr_t	code)
@@ -3674,7 +4617,7 @@
 
 typedef struct {
     unsigned int val;
-    const char *name;
+    const char name[8];
 } BITNAMES;
 
 #undef _nc_trace_ttymode
@@ -3701,36 +4644,78 @@
 
 /* ./tinfo/lib_ttyflags.c */
 
+#undef _nc_get_tty_mode_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
 #undef _nc_get_tty_mode
 int	_nc_get_tty_mode(
 		struct termios *buf)
 		{ return(*(int *)0); }
 
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef def_shell_mode
 int	def_shell_mode(void)
 		{ return(*(int *)0); }
 
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef def_prog_mode
 int	def_prog_mode(void)
 		{ return(*(int *)0); }
 
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef reset_prog_mode
 int	reset_prog_mode(void)
 		{ return(*(int *)0); }
 
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef reset_shell_mode
 int	reset_shell_mode(void)
 		{ return(*(int *)0); }
 
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef savetty
 int	savetty(void)
 		{ return(*(int *)0); }
 
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
 #undef resetty
 int	resetty(void)
 		{ return(*(int *)0); }
@@ -3762,21 +4747,39 @@
 /* ./names.c */
 
 #undef boolnames
-char	*const boolnames[] = {0};
+const char *const boolnames[] = {0};
 #undef boolfnames
-char	*const boolfnames[] = {0};
+const char *const boolfnames[] = {0};
 #undef numnames
-char	*const numnames[] = {0};
+const char *const numnames[] = {0};
 #undef numfnames
-char	*const numfnames[] = {0};
+const char *const numfnames[] = {0};
 #undef strnames
-char	*const strnames[] = {0};
+const char *const strnames[] = {0};
 #undef strfnames
-char	*const strfnames[] = {0};
+const char *const strfnames[] = {0};
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
 
 /* ./tinfo/read_entry.c */
 
-#include <hashed_db.h>
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
 
 #undef _nc_read_termtype
 int	_nc_read_termtype(
@@ -3800,20 +4803,8 @@
 
 /* ./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)
+#undef _nc_read_termcap
+void	_nc_read_termcap(void)
 		{ /* void */ }
 
 /* ./tinfo/strings.c */
@@ -3901,16 +4892,16 @@
 
 /* ./unctrl.c */
 
-#undef _nc_unctrl
-char	*_nc_unctrl(
+#undef unctrl_sp
+const char *unctrl_sp(
 		SCREEN	*sp, 
 		chtype	ch)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 #undef unctrl
-char	*unctrl(
+const char *unctrl(
 		chtype	ch)
-		{ return(*(char **)0); }
+		{ return(*(const char **)0); }
 
 /* ./trace/visbuf.c */
 
@@ -4011,25 +5002,6 @@
 		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
@@ -4039,21 +5011,6 @@
 		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
@@ -4095,6 +5052,8 @@
 
 #undef _nc_syntax
 int	_nc_syntax;
+#undef _nc_strict_bsd
+int	_nc_strict_bsd;
 #undef _nc_curr_file_pos
 long	_nc_curr_file_pos;
 #undef _nc_comment_start
@@ -4151,15 +5110,15 @@
 		{ return(*(int *)0); }
 
 typedef struct {
-    const char *from;
-    const char *to;
+    const char from[3];
+    const char to[6];
 } assoc;
 
 /* ./tinfo/write_entry.c */
 
 #undef _nc_set_writedir
 void	_nc_set_writedir(
-		char	*dir)
+		const char *dir)
 		{ /* void */ }
 
 #undef _nc_write_entry
@@ -4173,6 +5132,13 @@
 
 /* ./base/define_key.c */
 
+#undef define_key_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
 #undef define_key
 int	define_key(
 		const char *str, 
@@ -4187,6 +5153,12 @@
 
 /* ./base/key_defined.c */
 
+#undef key_defined_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
 #undef key_defined
 int	key_defined(
 		const char *str)
@@ -4194,6 +5166,13 @@
 
 /* ./base/keybound.c */
 
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
 #undef keybound
 char	*keybound(
 		int	code, 
@@ -4202,6 +5181,13 @@
 
 /* ./base/keyok.c */
 
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
 #undef keyok
 int	keyok(
 		int	c, 
diff --git a/ncurses/llib-ltic b/ncurses/llib-ltic
new file mode 100644
index 0000000..8230981
--- /dev/null
+++ b/ncurses/llib-ltic
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * Copyright (c) 2012,2015 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       2012-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/alloc_entry.c */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+#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 */
+
+#include <ctype.h>
+
+#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); }
+
+/* ./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_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_strict_bsd
+int	_nc_strict_bsd;
+#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[3];
+    const char to[6];
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		const 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); }
diff --git a/ncurses/llib-ltict b/ncurses/llib-ltict
new file mode 100644
index 0000000..e7d175c
--- /dev/null
+++ b/ncurses/llib-ltict
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * Copyright (c) 2013,2015 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       2013-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/alloc_entry.c */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+#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 */
+
+#include <ctype.h>
+
+#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); }
+
+/* ./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_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_strict_bsd
+int	_nc_strict_bsd;
+#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[3];
+    const char to[6];
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		const 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); }
diff --git a/ncurses/llib-ltictw b/ncurses/llib-ltictw
new file mode 100644
index 0000000..8230981
--- /dev/null
+++ b/ncurses/llib-ltictw
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * Copyright (c) 2012,2015 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       2012-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/alloc_entry.c */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+#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 */
+
+#include <ctype.h>
+
+#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); }
+
+/* ./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_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_strict_bsd
+int	_nc_strict_bsd;
+#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[3];
+    const char to[6];
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		const 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); }
diff --git a/ncurses/llib-lticw b/ncurses/llib-lticw
new file mode 100644
index 0000000..8230981
--- /dev/null
+++ b/ncurses/llib-lticw
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * Copyright (c) 2012,2015 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       2012-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/alloc_entry.c */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+#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 */
+
+#include <ctype.h>
+
+#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); }
+
+/* ./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_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_strict_bsd
+int	_nc_strict_bsd;
+#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[3];
+    const char to[6];
+} assoc;
+
+/* ./tinfo/write_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_set_writedir
+void	_nc_set_writedir(
+		const 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); }
diff --git a/ncurses/llib-ltinfo b/ncurses/llib-ltinfo
new file mode 100644
index 0000000..fd3036b
--- /dev/null
+++ b/ncurses/llib-ltinfo
@@ -0,0 +1,1531 @@
+/****************************************************************************
+ * Copyright (c) 2012-2013,2015 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       2012-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/access.c */
+
+#include <curses.priv.h>
+#include <ctype.h>
+#include <tic.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, 
+		const TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef boolcodes
+const char *const boolcodes[] = {0};
+#undef numcodes
+const char *const numcodes[] = {0};
+#undef strcodes
+const char *const strcodes[] = {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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)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/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./tinfo/db_iterator.c */
+
+#include <time.h>
+
+#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); }
+
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
+/* ./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_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+#include <termcap.h>
+
+struct speed {
+    short 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_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ 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_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)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;
+
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+/* ./tinfo/lib_has_cap.c */
+
+#undef has_ic_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef keyname_sp
+const char *keyname_sp(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(const char **)0); }
+
+#undef keyname
+const char *keyname(
+		int	c)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#include <sys/time.h>
+
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#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_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
+#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_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		int	flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ 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_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl
+void	use_tioctl(
+		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_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* 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(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret, 
+		int	reuse)
+		{ return(*(int *)0); }
+
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
+#undef setupterm
+int	setupterm(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#if 0
+
+#include <capdefaults.c>
+
+#endif
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetflag
+int	tgetflag(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#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_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetflag
+int	tigetflag(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		const 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	*_nc_popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+short	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_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ 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(
+		int	code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)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
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const 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_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)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[8];
+} 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_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ 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
+const char *const boolnames[] = {0};
+#undef boolfnames
+const char *const boolfnames[] = {0};
+#undef numnames
+const char *const numnames[] = {0};
+#undef numfnames
+const char *const numfnames[] = {0};
+#undef strnames
+const char *const strnames[] = {0};
+#undef strfnames
+const char *const strfnames[] = {0};
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+/* ./tinfo/read_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#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
+void	_nc_read_termcap(void)
+		{ /* 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 unctrl_sp
+const char *unctrl_sp(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef unctrl
+const char *unctrl(
+		chtype	ch)
+		{ return(*(const 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); }
+
+/* ./base/define_key.c */
+
+#undef define_key_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#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_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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-ltinfot b/ncurses/llib-ltinfot
new file mode 100644
index 0000000..11f0d95
--- /dev/null
+++ b/ncurses/llib-ltinfot
@@ -0,0 +1,1635 @@
+/****************************************************************************
+ * Copyright (c) 2013-2013,2015 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       2013-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/access.c */
+
+#include <curses.priv.h>
+#include <ctype.h>
+#include <tic.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, 
+		const TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef _nc_boolcodes
+const char *const *_nc_boolcodes(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numcodes
+const char *const *_nc_numcodes(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strcodes
+const char *const *_nc_strcodes(void)
+		{ return(*(const 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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)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/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./tinfo/db_iterator.c */
+
+#include <time.h>
+
+#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); }
+
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
+/* ./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_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+#include <termcap.h>
+
+struct speed {
+    short 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_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef baudrate
+int	baudrate(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_cur_term.c */
+
+#undef _nc_get_cur_term_sp
+TERMINAL *_nc_get_cur_term_sp(
+		SCREEN	*sp)
+		{ return(*(TERMINAL **)0); }
+
+#undef _nc_get_cur_term
+TERMINAL *_nc_get_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
+#undef _nc_cur_term
+TERMINAL *_nc_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)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_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+#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_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef keyname_sp
+const char *keyname_sp(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(const char **)0); }
+
+#undef keyname
+const char *keyname(
+		int	c)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#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_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
+#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_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		int	flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_LINES
+int	_nc_LINES(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Cols
+int	*_nc_ptr_Cols(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_COLS
+int	_nc_COLS(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Tabsize
+int	*_nc_ptr_Tabsize(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_TABSIZE
+int	_nc_TABSIZE(void)
+		{ return(*(int *)0); }
+
+#undef set_tabsize_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ 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_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl
+void	use_tioctl(
+		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_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* 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(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret, 
+		int	reuse)
+		{ return(*(int *)0); }
+
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
+#undef setupterm
+int	setupterm(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#if 0
+
+#include <capdefaults.c>
+
+#endif
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetflag
+int	tgetflag(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#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_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetflag
+int	tigetflag(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		const 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	*_nc_popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+short	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_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ 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(
+		int	code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)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
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const 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_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)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[8];
+} 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_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef resetty
+int	resetty(void)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_twait.c */
+
+#include <sys/time.h>
+
+#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
+const char *const *_nc_boolnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_boolfnames
+const char *const *_nc_boolfnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numnames
+const char *const *_nc_numnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numfnames
+const char *const *_nc_numfnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strnames
+const char *const *_nc_strnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strfnames
+const char *const *_nc_strfnames(void)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+/* ./tinfo/read_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#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
+void	_nc_read_termcap(void)
+		{ /* 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 unctrl_sp
+const char *unctrl_sp(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef unctrl
+const char *unctrl(
+		chtype	ch)
+		{ return(*(const 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); }
+
+/* ./base/define_key.c */
+
+#undef define_key_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#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_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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-ltinfotw b/ncurses/llib-ltinfotw
new file mode 100644
index 0000000..3e6ada3
--- /dev/null
+++ b/ncurses/llib-ltinfotw
@@ -0,0 +1,1668 @@
+/****************************************************************************
+ * Copyright (c) 2012-2013,2015 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       2012-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/access.c */
+
+#include <curses.priv.h>
+#include <ctype.h>
+#include <tic.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, 
+		const TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef _nc_boolcodes
+const char *const *_nc_boolcodes(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numcodes
+const char *const *_nc_numcodes(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strcodes
+const char *const *_nc_strcodes(void)
+		{ return(*(const 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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)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/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./tinfo/db_iterator.c */
+
+#include <time.h>
+
+#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); }
+
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
+/* ./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_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+#include <termcap.h>
+
+struct speed {
+    short 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_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef baudrate
+int	baudrate(void)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_cur_term.c */
+
+#undef _nc_get_cur_term_sp
+TERMINAL *_nc_get_cur_term_sp(
+		SCREEN	*sp)
+		{ return(*(TERMINAL **)0); }
+
+#undef _nc_get_cur_term
+TERMINAL *_nc_get_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
+#undef _nc_cur_term
+TERMINAL *_nc_cur_term(void)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)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_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+#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_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef keyname_sp
+const char *keyname_sp(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(const char **)0); }
+
+#undef keyname
+const char *keyname(
+		int	c)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#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_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
+#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_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		int	flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_LINES
+int	_nc_LINES(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Cols
+int	*_nc_ptr_Cols(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_COLS
+int	_nc_COLS(void)
+		{ return(*(int *)0); }
+
+#undef _nc_ptr_Tabsize
+int	*_nc_ptr_Tabsize(
+		SCREEN	*sp)
+		{ return(*(int **)0); }
+
+#undef _nc_TABSIZE
+int	_nc_TABSIZE(void)
+		{ return(*(int *)0); }
+
+#undef set_tabsize_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ 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_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl
+void	use_tioctl(
+		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_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* 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(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret, 
+		int	reuse)
+		{ return(*(int *)0); }
+
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
+#undef setupterm
+int	setupterm(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#if 0
+
+#include <capdefaults.c>
+
+#endif
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetflag
+int	tgetflag(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#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_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetflag
+int	tigetflag(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		const 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	*_nc_popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+short	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_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ 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(
+		int	code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)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
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const 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_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)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[8];
+} 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_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef resetty
+int	resetty(void)
+		{ return(*(int *)0); }
+
+/* ./tty/lib_twait.c */
+
+#include <sys/time.h>
+
+#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
+const char *const *_nc_boolnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_boolfnames
+const char *const *_nc_boolfnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numnames
+const char *const *_nc_numnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_numfnames
+const char *const *_nc_numfnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strnames
+const char *const *_nc_strnames(void)
+		{ return(*(const char **)0); }
+
+#undef _nc_strfnames
+const char *const *_nc_strfnames(void)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+/* ./tinfo/read_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#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
+void	_nc_read_termcap(void)
+		{ /* 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 unctrl_sp
+const char *unctrl_sp(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef unctrl
+const char *unctrl(
+		chtype	ch)
+		{ return(*(const 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); }
+
+/* ./base/define_key.c */
+
+#undef define_key_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#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_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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-ltinfow b/ncurses/llib-ltinfow
new file mode 100644
index 0000000..6df3296
--- /dev/null
+++ b/ncurses/llib-ltinfow
@@ -0,0 +1,1564 @@
+/****************************************************************************
+ * Copyright (c) 2012-2013,2015 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       2012-on                                  *
+ ****************************************************************************/
+/* LINTLIBRARY */
+
+/* ./tinfo/access.c */
+
+#include <curses.priv.h>
+#include <ctype.h>
+#include <tic.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, 
+		const TERMTYPE *src)
+		{ /* void */ }
+
+/* ./codes.c */
+
+#undef boolcodes
+const char *const boolcodes[] = {0};
+#undef numcodes
+const char *const numcodes[] = {0};
+#undef strcodes
+const char *const strcodes[] = {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 HashValue *_nc_get_hash_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashValue **)0); }
+
+#undef _nc_get_alias_table
+const struct alias *_nc_get_alias_table(
+		NCURSES_BOOL termcap)
+		{ return(*(const struct alias **)0); }
+
+#undef _nc_get_hash_info
+const HashData *_nc_get_hash_info(
+		NCURSES_BOOL termcap)
+		{ return(*(const HashData **)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/comp_hash.c */
+
+#undef _nc_find_entry
+struct name_table_entry const *_nc_find_entry(
+		const char *string, 
+		const HashValue *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, 
+		NCURSES_BOOL termcap)
+		{ return(*(struct name_table_entry const **)0); }
+
+/* ./tinfo/db_iterator.c */
+
+#include <time.h>
+
+#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); }
+
+#undef _nc_setenv_num
+void	_nc_setenv_num(
+		const char *name, 
+		int	value)
+		{ /* void */ }
+
+/* ./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_sp
+void	_nc_init_acs_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_init_acs
+void	_nc_init_acs(void)
+		{ /* void */ }
+
+/* ./tinfo/lib_baudrate.c */
+
+#include <termcap.h>
+
+struct speed {
+    short 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_sp
+int	baudrate_sp(
+		SCREEN	*sp)
+		{ 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_sp
+TERMINAL *set_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef set_curterm
+TERMINAL *set_curterm(
+		TERMINAL *termp)
+		{ return(*(TERMINAL **)0); }
+
+#undef del_curterm_sp
+int	del_curterm_sp(
+		SCREEN	*sp, 
+		TERMINAL *termp)
+		{ return(*(int *)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;
+
+#undef _nc_screen_of
+SCREEN	*_nc_screen_of(
+		WINDOW	*win)
+		{ return(*(SCREEN **)0); }
+
+/* ./tinfo/lib_has_cap.c */
+
+#undef has_ic_sp
+NCURSES_BOOL has_ic_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_ic
+NCURSES_BOOL has_ic(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il_sp
+NCURSES_BOOL has_il_sp(
+		SCREEN	*sp)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef has_il
+NCURSES_BOOL has_il(void)
+		{ return(*(NCURSES_BOOL *)0); }
+
+/* ./tinfo/lib_kernel.c */
+
+#undef erasechar_sp
+char	erasechar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef erasechar
+char	erasechar(void)
+		{ return(*(char *)0); }
+
+#undef killchar_sp
+char	killchar_sp(
+		SCREEN	*sp)
+		{ return(*(char *)0); }
+
+#undef killchar
+char	killchar(void)
+		{ return(*(char *)0); }
+
+#undef flushinp_sp
+int	flushinp_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef flushinp
+int	flushinp(void)
+		{ return(*(int *)0); }
+
+/* ./lib_keyname.c */
+
+struct kn { short offset; int code; };
+
+#undef keyname_sp
+const char *keyname_sp(
+		SCREEN	*sp, 
+		int	c)
+		{ return(*(const char **)0); }
+
+#undef keyname
+const char *keyname(
+		int	c)
+		{ return(*(const char **)0); }
+
+/* ./tinfo/lib_longname.c */
+
+#undef longname_sp
+char	*longname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#undef longname
+char	*longname(void)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_napms.c */
+
+#include <sys/time.h>
+
+#undef napms_sp
+int	napms_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#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_sp
+int	halfdelay_sp(
+		SCREEN	*sp, 
+		int	t)
+		{ return(*(int *)0); }
+
+#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_sp
+int	curs_set_sp(
+		SCREEN	*sp, 
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef curs_set
+int	curs_set(
+		int	vis)
+		{ return(*(int *)0); }
+
+#undef typeahead_sp
+int	typeahead_sp(
+		SCREEN	*sp, 
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef typeahead
+int	typeahead(
+		int	fd)
+		{ return(*(int *)0); }
+
+#undef has_key_sp
+int	has_key_sp(
+		SCREEN	*sp, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef has_key
+int	has_key(
+		int	keycode)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_flush_sp
+int	_nc_putp_flush_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *value)
+		{ return(*(int *)0); }
+
+#undef _nc_keypad
+int	_nc_keypad(
+		SCREEN	*sp, 
+		int	flag)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_raw.c */
+
+#undef raw_sp
+int	raw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef raw
+int	raw(void)
+		{ return(*(int *)0); }
+
+#undef cbreak_sp
+int	cbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef cbreak
+int	cbreak(void)
+		{ return(*(int *)0); }
+
+#undef qiflush_sp
+void	qiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef qiflush
+void	qiflush(void)
+		{ /* void */ }
+
+#undef noraw_sp
+int	noraw_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef noraw
+int	noraw(void)
+		{ return(*(int *)0); }
+
+#undef nocbreak_sp
+int	nocbreak_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef nocbreak
+int	nocbreak(void)
+		{ return(*(int *)0); }
+
+#undef noqiflush_sp
+void	noqiflush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef noqiflush
+void	noqiflush(void)
+		{ /* void */ }
+
+#undef intrflush_sp
+int	intrflush_sp(
+		SCREEN	*sp, 
+		WINDOW	*win, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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_sp
+int	set_tabsize_sp(
+		SCREEN	*sp, 
+		int	value)
+		{ 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_sp
+void	use_env_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl_sp
+void	use_tioctl_sp(
+		SCREEN	*sp, 
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_env
+void	use_env(
+		NCURSES_BOOL f)
+		{ /* void */ }
+
+#undef use_tioctl
+void	use_tioctl(
+		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_setup_tinfo
+int	_nc_setup_tinfo(
+		const char *const tn, 
+		TERMTYPE *const tp)
+		{ return(*(int *)0); }
+
+#undef _nc_tinfo_cmdch
+void	_nc_tinfo_cmdch(
+		TERMINAL *termp, 
+		int	proto)
+		{ /* 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(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret, 
+		int	reuse)
+		{ return(*(int *)0); }
+
+#undef new_prescr
+SCREEN	*new_prescr(void)
+		{ return(*(SCREEN **)0); }
+
+#undef setupterm
+int	setupterm(
+		const char *tname, 
+		int	Filedes, 
+		int	*errret)
+		{ return(*(int *)0); }
+
+/* ./tinfo/lib_termcap.c */
+
+#undef UP
+char	*UP;
+#undef BC
+char	*BC;
+
+#undef tgetent_sp
+int	tgetent_sp(
+		SCREEN	*sp, 
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#if 0
+
+#include <capdefaults.c>
+
+#endif
+
+#undef tgetent
+int	tgetent(
+		char	*bufp, 
+		const char *name)
+		{ return(*(int *)0); }
+
+#undef tgetflag_sp
+int	tgetflag_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetflag
+int	tgetflag(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum_sp
+int	tgetnum_sp(
+		SCREEN	*sp, 
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetnum
+int	tgetnum(
+		const char *id)
+		{ return(*(int *)0); }
+
+#undef tgetstr_sp
+char	*tgetstr_sp(
+		SCREEN	*sp, 
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+#undef tgetstr
+char	*tgetstr(
+		const char *id, 
+		char	**area)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_termname.c */
+
+#undef termname_sp
+char	*termname_sp(
+		SCREEN	*sp)
+		{ return(*(char **)0); }
+
+#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_sp
+int	tigetflag_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetflag
+int	tigetflag(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum_sp
+int	tigetnum_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetnum
+int	tigetnum(
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef tigetstr_sp
+char	*tigetstr_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(char **)0); }
+
+#undef tigetstr
+char	*tigetstr(
+		const 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	*_nc_popcount)
+		{ return(*(int *)0); }
+
+#undef tparm
+char	*tparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+#undef tiparm
+char	*tiparm(
+		const char *string, 
+		...)
+		{ return(*(char **)0); }
+
+/* ./tinfo/lib_tputs.c */
+
+#undef PC
+char	PC;
+#undef ospeed
+short	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_sp
+int	delay_output_sp(
+		SCREEN	*sp, 
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef delay_output
+int	delay_output(
+		int	ms)
+		{ return(*(int *)0); }
+
+#undef _nc_flush_sp
+void	_nc_flush_sp(
+		SCREEN	*sp)
+		{ /* void */ }
+
+#undef _nc_flush
+void	_nc_flush(void)
+		{ /* void */ }
+
+#undef _nc_outch_sp
+int	_nc_outch_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_outch
+int	_nc_outch(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar_sp
+int	_nc_putchar_sp(
+		SCREEN	*sp, 
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef _nc_putchar
+int	_nc_putchar(
+		int	ch)
+		{ return(*(int *)0); }
+
+#undef putp_sp
+int	putp_sp(
+		SCREEN	*sp, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef putp
+int	putp(
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp_sp
+int	_nc_putp_sp(
+		SCREEN	*sp, 
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef _nc_putp
+int	_nc_putp(
+		const char *name, 
+		const char *string)
+		{ return(*(int *)0); }
+
+#undef tputs_sp
+int	tputs_sp(
+		SCREEN	*sp, 
+		const char *string, 
+		int	affcnt, 
+		NCURSES_OUTC_sp outc)
+		{ return(*(int *)0); }
+
+#undef _nc_outc_wrapper
+int	_nc_outc_wrapper(
+		SCREEN	*sp, 
+		int	c)
+		{ 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(
+		int	code)
+		{ return(*(NCURSES_BOOL *)0); }
+
+#undef _nc_retrace_char
+char	_nc_retrace_char(
+		int	code)
+		{ return(*(char *)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
+const void *_nc_retrace_cvoid_ptr(
+		const void *code)
+		{ return(*(const 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_int_attr_t
+int	_nc_retrace_int_attr_t(
+		attr_t	code)
+		{ return(*(int *)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[8];
+} 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_sp
+int	_nc_get_tty_mode_sp(
+		SCREEN	*sp, 
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_get_tty_mode
+int	_nc_get_tty_mode(
+		struct termios *buf)
+		{ return(*(int *)0); }
+
+#undef _nc_set_tty_mode_sp
+int	_nc_set_tty_mode_sp(
+		SCREEN	*sp, 
+		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_sp
+int	def_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_shell_mode
+int	def_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode_sp
+int	def_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef def_prog_mode
+int	def_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode_sp
+int	reset_prog_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_prog_mode
+int	reset_prog_mode(void)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode_sp
+int	reset_shell_mode_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef reset_shell_mode
+int	reset_shell_mode(void)
+		{ return(*(int *)0); }
+
+#undef savetty_sp
+int	savetty_sp(
+		SCREEN	*sp)
+		{ return(*(int *)0); }
+
+#undef savetty
+int	savetty(void)
+		{ return(*(int *)0); }
+
+#undef resetty_sp
+int	resetty_sp(
+		SCREEN	*sp)
+		{ 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
+const char *const boolnames[] = {0};
+#undef boolfnames
+const char *const boolfnames[] = {0};
+#undef numnames
+const char *const numnames[] = {0};
+#undef numfnames
+const char *const numfnames[] = {0};
+#undef strnames
+const char *const strnames[] = {0};
+#undef strfnames
+const char *const strfnames[] = {0};
+
+/* ./tinfo/obsolete.c */
+
+#undef _nc_set_buffer_sp
+void	_nc_set_buffer_sp(
+		SCREEN	*sp, 
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+#undef _nc_set_buffer
+void	_nc_set_buffer(
+		FILE	*ofp, 
+		int	buffered)
+		{ /* void */ }
+
+/* ./tinfo/read_entry.c */
+
+#include <hashed_db.h>
+
+#undef _nc_init_termtype
+void	_nc_init_termtype(
+		TERMTYPE *const tp)
+		{ /* void */ }
+
+#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
+void	_nc_read_termcap(void)
+		{ /* 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 unctrl_sp
+const char *unctrl_sp(
+		SCREEN	*sp, 
+		chtype	ch)
+		{ return(*(const char **)0); }
+
+#undef unctrl
+const char *unctrl(
+		chtype	ch)
+		{ return(*(const 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); }
+
+/* ./base/define_key.c */
+
+#undef define_key_sp
+int	define_key_sp(
+		SCREEN	*sp, 
+		const char *str, 
+		int	keycode)
+		{ return(*(int *)0); }
+
+#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_sp
+int	key_defined_sp(
+		SCREEN	*sp, 
+		const char *str)
+		{ return(*(int *)0); }
+
+#undef key_defined
+int	key_defined(
+		const char *str)
+		{ return(*(int *)0); }
+
+/* ./base/keybound.c */
+
+#undef keybound_sp
+char	*keybound_sp(
+		SCREEN	*sp, 
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+#undef keybound
+char	*keybound(
+		int	code, 
+		int	count)
+		{ return(*(char **)0); }
+
+/* ./base/keyok.c */
+
+#undef keyok_sp
+int	keyok_sp(
+		SCREEN	*sp, 
+		int	c, 
+		NCURSES_BOOL flag)
+		{ return(*(int *)0); }
+
+#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/make_hash b/ncurses/make_hash
deleted file mode 100755
index 4d7f2b4..0000000
--- a/ncurses/make_hash
+++ /dev/null
Binary files differ
diff --git a/ncurses/make_keys b/ncurses/make_keys
deleted file mode 100755
index c611105..0000000
--- a/ncurses/make_keys
+++ /dev/null
Binary files differ
diff --git a/ncurses/modules b/ncurses/modules
index f28ef81..b3b9732 100644
--- a/ncurses/modules
+++ b/ncurses/modules
@@ -1,6 +1,6 @@
-# $Id: modules,v 1.112 2007/09/08 22:03:34 tom Exp $
+# $Id: modules,v 1.120 2013/01/26 22:17:55 tom Exp $
 ##############################################################################
-# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.                #
 #                                                                            #
 # Permission is hereby granted, free of charge, to any person obtaining a    #
 # copy of this software and associated documentation files (the "Software"), #
@@ -32,201 +32,213 @@
 
 @ 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)
+hardscroll	lib		$(serial)	$(HEADER_DEPS)
+hashmap		lib		$(serial)	$(HEADER_DEPS)
+lib_addch	lib		$(base)		$(HEADER_DEPS)
+lib_addstr	lib		$(base)		$(HEADER_DEPS)
+lib_beep	lib		$(base)		$(HEADER_DEPS)
+lib_bkgd	lib		$(base)		$(HEADER_DEPS)
+lib_box 	lib		$(base)		$(HEADER_DEPS)
+lib_chgat	lib		$(base)		$(HEADER_DEPS)
+lib_clear	lib		$(base)		$(HEADER_DEPS)
+lib_clearok	lib		$(base)		$(HEADER_DEPS)
+lib_clrbot	lib		$(base)		$(HEADER_DEPS)
+lib_clreol	lib		$(base)		$(HEADER_DEPS)
+lib_color	lib		$(base)		$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_colorset	lib		$(base)		$(HEADER_DEPS)
+lib_delch	lib		$(base)		$(HEADER_DEPS)
+lib_delwin	lib		$(base)		$(HEADER_DEPS)
+lib_echo	lib		$(base)		$(HEADER_DEPS)
+lib_endwin	lib		$(base)		$(HEADER_DEPS)
+lib_erase	lib		$(base)		$(HEADER_DEPS)
+lib_flash	lib		$(base)		$(HEADER_DEPS)
+lib_gen 	lib		.		$(HEADER_DEPS)
+lib_getch	lib		$(base)		$(HEADER_DEPS)	$(srcdir)/fifo_defs.h
+lib_getstr	lib		$(base)		$(HEADER_DEPS)
+lib_hline	lib		$(base)		$(HEADER_DEPS)
+lib_immedok	lib		$(base)		$(HEADER_DEPS)
+lib_inchstr	lib		$(base)		$(HEADER_DEPS)
+lib_initscr	lib		$(base)		$(HEADER_DEPS)
+lib_insch	lib		$(base)		$(HEADER_DEPS)
+lib_insdel	lib		$(base)		$(HEADER_DEPS)
+lib_insnstr	lib		$(base)		$(HEADER_DEPS)
+lib_instr	lib		$(base)		$(HEADER_DEPS)
+lib_isendwin	lib		$(base)		$(HEADER_DEPS)
+lib_leaveok	lib		$(base)		$(HEADER_DEPS)
+lib_mouse	lib		$(base)		$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_move	lib		$(base)		$(HEADER_DEPS)
+lib_mvcur	lib		$(serial)	$(HEADER_DEPS)	$(INCDIR)/tic.h $(srcdir)/../progs/dump_entry.h
+lib_mvwin	lib		$(base)		$(HEADER_DEPS)
+lib_newterm	lib		$(base)		$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_newwin	lib		$(base)		$(HEADER_DEPS)
+lib_nl		lib		$(base)		$(HEADER_DEPS)
+lib_overlay	lib		$(base)		$(HEADER_DEPS)
+lib_pad 	lib		$(base)		$(HEADER_DEPS)
+lib_printw	lib		$(base)		$(HEADER_DEPS)
+lib_redrawln	lib		$(base)		$(HEADER_DEPS)
+lib_refresh	lib		$(base)		$(HEADER_DEPS)
+lib_restart	lib		$(base)		$(HEADER_DEPS)
+lib_scanw	lib		$(base)		$(HEADER_DEPS)
+lib_screen	lib		$(base)		$(HEADER_DEPS)
+lib_scroll	lib		$(base)		$(HEADER_DEPS)
+lib_scrollok	lib		$(base)		$(HEADER_DEPS)
+lib_scrreg	lib		$(base)		$(HEADER_DEPS)
+lib_set_term	lib		$(base)		$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_slk 	lib		$(base)		$(HEADER_DEPS)
+lib_slkatr_set	lib		$(base)		$(HEADER_DEPS)
+lib_slkatrof 	lib		$(base)		$(HEADER_DEPS)
+lib_slkatron 	lib		$(base)		$(HEADER_DEPS)
+lib_slkatrset 	lib		$(base)		$(HEADER_DEPS)
+lib_slkattr 	lib		$(base)		$(HEADER_DEPS)
+lib_slkclear 	lib		$(base)		$(HEADER_DEPS)
+lib_slkcolor 	lib		$(base)		$(HEADER_DEPS)
+lib_slkinit 	lib		$(base)		$(HEADER_DEPS)
+lib_slklab	lib		$(base)		$(HEADER_DEPS)
+lib_slkrefr	lib		$(base)		$(HEADER_DEPS)
+lib_slkset	lib		$(base)		$(HEADER_DEPS)
+lib_slktouch	lib		$(base)		$(HEADER_DEPS)
+lib_touch	lib		$(base)		$(HEADER_DEPS)
+lib_tracedmp	lib		$(trace)	$(HEADER_DEPS)
+lib_tracemse	lib		$(trace)	$(HEADER_DEPS)
+lib_tstp	lib		$(serial)	$(HEADER_DEPS)	$(srcdir)/SigAction.h
+lib_ungetch	lib		$(base)		$(HEADER_DEPS)	$(srcdir)/fifo_defs.h
+lib_vidattr	lib		$(serial)	$(HEADER_DEPS)
+lib_vline	lib		$(base)		$(HEADER_DEPS)
+lib_wattroff	lib		$(base)		$(HEADER_DEPS)
+lib_wattron	lib		$(base)		$(HEADER_DEPS)
+lib_winch	lib		$(base)		$(HEADER_DEPS)
+lib_window	lib		$(base)		$(HEADER_DEPS)
+link_test 	lib		.		$(HEADER_DEPS)
+nc_panel	lib		$(base)		$(HEADER_DEPS)
+safe_sprintf	lib		$(base)		$(HEADER_DEPS)
+tty_update	lib		$(serial)	$(HEADER_DEPS)
+varargs		lib		$(trace)	$(HEADER_DEPS)
 
 # Modules for porting
-memmove		lib		$(base)
-vsscanf 	lib		$(base)
+vsscanf 	lib		$(base)		$(HEADER_DEPS)
 
 # actually an extension, but with its own configure option (--disable-leaks)
-lib_freeall	lib		$(base)
+lib_freeall	lib		$(base)		$(HEADER_DEPS)	$(INCDIR)/tic.h
 
 # 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)
+charable	lib		$(wide)		$(HEADER_DEPS)
+lib_add_wch	lib		$(wide)		$(HEADER_DEPS)
+lib_box_set	lib		$(wide)		$(HEADER_DEPS)
+lib_cchar	lib		$(wide)		$(HEADER_DEPS)
+lib_erasewchar	lib		$(wide)		$(HEADER_DEPS)
+lib_get_wch	lib		$(wide)		$(HEADER_DEPS)
+lib_get_wstr	lib		$(wide)		$(HEADER_DEPS)
+lib_hline_set	lib		$(wide)		$(HEADER_DEPS)
+lib_in_wch	lib		$(wide)		$(HEADER_DEPS)
+lib_in_wchnstr	lib		$(wide)		$(HEADER_DEPS)
+lib_ins_wch	lib		$(wide)		$(HEADER_DEPS)
+lib_inwstr	lib		$(wide)		$(HEADER_DEPS)
+lib_key_name	lib		$(wide)		$(HEADER_DEPS)
+lib_pecho_wchar	lib		$(wide)		$(HEADER_DEPS)
+lib_slk_wset	lib		$(wide)		$(HEADER_DEPS)
+lib_unget_wch	lib		$(wide)		$(HEADER_DEPS)
+lib_vid_attr	lib		$(wide)		$(HEADER_DEPS)
+lib_vline_set	lib		$(wide)		$(HEADER_DEPS)
+lib_wacs	lib		$(wide)		$(HEADER_DEPS)
+lib_wunctrl	lib		$(wide)		$(HEADER_DEPS)
 
 # 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
+expanded	lib		.		$(HEADER_DEPS)
+legacy_coding	lib		$(base)		$(HEADER_DEPS)
+lib_dft_fgbg	lib		$(base)		$(HEADER_DEPS)
+lib_print	lib		$(tinfo)	$(HEADER_DEPS)
+resizeterm	lib		$(base)		$(HEADER_DEPS)
+trace_xnames	lib		$(trace)	$(HEADER_DEPS)
+use_screen	lib		$(tinfo)	$(HEADER_DEPS)
+use_window	lib		$(base)		$(HEADER_DEPS)
+wresize		lib		$(base)		$(HEADER_DEPS)
 
 # 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
+access		lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+add_tries	lib		$(tinfo)	$(HEADER_DEPS)
+alloc_ttype	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+codes		lib		.		$(HEADER_DEPS)
+comp_captab	lib		.		$(HEADER_DEPS)	$(INCDIR)/tic.h ../include/hashsize.h
+comp_error	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+comp_hash	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h ../include/hashsize.h
+db_iterator	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+doalloc		lib		$(tinfo)	$(HEADER_DEPS)
+entries		lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+fallback	lib		.		$(HEADER_DEPS)
+free_ttype	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+getenv_num	lib		$(tinfo)	$(HEADER_DEPS)
+home_terminfo	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+init_keytry	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h init_keytry.h
+lib_acs 	lib		$(tinfo)	$(HEADER_DEPS)
+lib_baudrate	lib		$(tinfo)	$(HEADER_DEPS)	../include/termcap.h
+lib_cur_term	lib		$(tinfo)	$(HEADER_DEPS)	../include/termcap.h
+lib_data	lib		$(tinfo)	$(HEADER_DEPS)
+lib_has_cap	lib		$(tinfo)	$(HEADER_DEPS)
+lib_kernel	lib		$(tinfo)	$(HEADER_DEPS)
+lib_keyname	lib		.		$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_longname	lib		$(tinfo)	$(HEADER_DEPS)
+lib_napms	lib		$(tinfo)	$(HEADER_DEPS)
+lib_options	lib		$(tinfo)	$(HEADER_DEPS)
+lib_raw 	lib		$(tinfo)	$(HEADER_DEPS)
+lib_setup	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_termcap	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h ../include/termcap.h $(INCDIR)/capdefaults.c
+lib_termname	lib		$(tinfo)	$(HEADER_DEPS)
+lib_tgoto	lib		$(tinfo)	$(HEADER_DEPS)	../include/termcap.h
+lib_ti		lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_tparm	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_tputs	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h ../include/termcap.h
+lib_trace	lib		$(trace)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+lib_traceatr	lib		$(trace)	$(HEADER_DEPS)
+lib_tracebits	lib		$(trace)	$(HEADER_DEPS)
+lib_tracechr	lib		$(trace)	$(HEADER_DEPS)
+lib_ttyflags	lib		$(tinfo)	$(HEADER_DEPS)
+lib_twait	lib		$(serial)	$(HEADER_DEPS)
+name_match	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+names		lib		.		$(HEADER_DEPS)
+obsolete	lib		$(tinfo)	$(HEADER_DEPS)
+read_entry	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h $(INCDIR)/hashed_db.h
+read_termcap	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+strings		lib		$(tinfo)	$(HEADER_DEPS)
+trace_buf	lib		$(trace)	$(HEADER_DEPS)
+trace_tries	lib		$(trace)	$(HEADER_DEPS)
+tries		lib		$(base)		$(HEADER_DEPS)
+trim_sgr0	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+unctrl		lib		.		$(HEADER_DEPS)
+visbuf		lib		$(trace)	$(HEADER_DEPS)	$(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
+alloc_entry	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+captoinfo	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+comp_expand	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+comp_parse	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+comp_scan	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
+parse_entry	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h ../include/parametrized.h
+write_entry	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h $(INCDIR)/hashed_db.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)
+define_key	lib		$(base)		$(HEADER_DEPS)
+hashed_db	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h $(INCDIR)/hashed_db.h
+key_defined	lib		$(base)		$(HEADER_DEPS)
+keybound	lib		$(base)		$(HEADER_DEPS)
+keyok		lib		$(base)		$(HEADER_DEPS)
+version		lib		$(base)		$(HEADER_DEPS)
+
+# Porting
+@ port_drivers
+lib_driver      lib             $(base)		$(HEADER_DEPS)
+
+@ port_win32con
+gettimeofday	lib		$(win32con)	$(HEADER_DEPS)
+wcwidth		lib             $(win32con)	$(HEADER_DEPS)
+widechars	lib             $(wide)		$(HEADER_DEPS)
+win_driver	lib             $(win32con)	$(HEADER_DEPS)
+
+@ port_tinfo
+tinfo_driver	lib		$(tinfo)	$(HEADER_DEPS)	$(INCDIR)/tic.h
 
 # vile:makemode
diff --git a/ncurses/names.c b/ncurses/names.c
deleted file mode 100644
index 360e733..0000000
--- a/ncurses/names.c
+++ /dev/null
@@ -1,1365 +0,0 @@
-/* This file was generated by MKnames.awk */
-
-#include <curses.priv.h>
-
-#define IT NCURSES_CONST char * const
-
-
-#if BROKEN_LINKER || USE_REENTRANT
-
-#include <term.h>
-
-static const char _nc_name_blob[] = 
-"bw\0" "auto_left_margin\0" "am\0" "auto_right_margin\0" "xsb\0" "no_esc_ctlc\0" \
-"xhp\0" "ceol_standout_glitch\0" "xenl\0" "eat_newline_glitch\0" "eo\0" \
-"erase_overstrike\0" "gn\0" "generic_type\0" "hc\0" "hard_copy\0" "km\0" \
-"has_meta_key\0" "hs\0" "has_status_line\0" "in\0" "insert_null_glitch\0" \
-"da\0" "memory_above\0" "db\0" "memory_below\0" "mir\0" "move_insert_mode\0" \
-"msgr\0" "move_standout_mode\0" "os\0" "over_strike\0" "eslok\0" "status_line_esc_ok\0" \
-"xt\0" "dest_tabs_magic_smso\0" "hz\0" "tilde_glitch\0" "ul\0" "transparent_underline\0" \
-"xon\0" "xon_xoff\0" "nxon\0" "needs_xon_xoff\0" "mc5i\0" "prtr_silent\0" \
-"chts\0" "hard_cursor\0" "nrrmc\0" "non_rev_rmcup\0" "npc\0" "no_pad_char\0" \
-"ndscr\0" "non_dest_scroll_region\0" "ccc\0" "can_change\0" "bce\0" "back_color_erase\0" \
-"hls\0" "hue_lightness_saturation\0" "xhpa\0" "col_addr_glitch\0" "crxm\0" \
-"cr_cancels_micro_mode\0" "daisy\0" "has_print_wheel\0" "xvpa\0" "row_addr_glitch\0" \
-"sam\0" "semi_auto_right_margin\0" "cpix\0" "cpi_changes_res\0" "lpix\0" \
-"lpi_changes_res\0" "cols\0" "columns\0" "it\0" "init_tabs\0" "lines\0" \
-"lines\0" "lm\0" "lines_of_memory\0" "xmc\0" "magic_cookie_glitch\0" "pb\0" \
-"padding_baud_rate\0" "vt\0" "virtual_terminal\0" "wsl\0" "width_status_line\0" \
-"nlab\0" "num_labels\0" "lh\0" "label_height\0" "lw\0" "label_width\0" \
-"ma\0" "max_attributes\0" "wnum\0" "maximum_windows\0" "colors\0" "max_colors\0" \
-"pairs\0" "max_pairs\0" "ncv\0" "no_color_video\0" "bufsz\0" "buffer_capacity\0" \
-"spinv\0" "dot_vert_spacing\0" "spinh\0" "dot_horz_spacing\0" "maddr\0" \
-"max_micro_address\0" "mjump\0" "max_micro_jump\0" "mcs\0" "micro_col_size\0" \
-"mls\0" "micro_line_size\0" "npins\0" "number_of_pins\0" "orc\0" "output_res_char\0" \
-"orl\0" "output_res_line\0" "orhi\0" "output_res_horz_inch\0" "orvi\0" \
-"output_res_vert_inch\0" "cps\0" "print_rate\0" "widcs\0" "wide_char_size\0" \
-"btns\0" "buttons\0" "bitwin\0" "bit_image_entwining\0" "bitype\0" "bit_image_type\0" \
-"cbt\0" "back_tab\0" "bel\0" "bell\0" "cr\0" "carriage_return\0" "csr\0" \
-"change_scroll_region\0" "tbc\0" "clear_all_tabs\0" "clear\0" "clear_screen\0" \
-"el\0" "clr_eol\0" "ed\0" "clr_eos\0" "hpa\0" "column_address\0" "cmdch\0" \
-"command_character\0" "cup\0" "cursor_address\0" "cud1\0" "cursor_down\0" \
-"home\0" "cursor_home\0" "civis\0" "cursor_invisible\0" "cub1\0" "cursor_left\0" \
-"mrcup\0" "cursor_mem_address\0" "cnorm\0" "cursor_normal\0" "cuf1\0" "cursor_right\0" \
-"ll\0" "cursor_to_ll\0" "cuu1\0" "cursor_up\0" "cvvis\0" "cursor_visible\0" \
-"dch1\0" "delete_character\0" "dl1\0" "delete_line\0" "dsl\0" "dis_status_line\0" \
-"hd\0" "down_half_line\0" "smacs\0" "enter_alt_charset_mode\0" "blink\0" \
-"enter_blink_mode\0" "bold\0" "enter_bold_mode\0" "smcup\0" "enter_ca_mode\0" \
-"smdc\0" "enter_delete_mode\0" "dim\0" "enter_dim_mode\0" "smir\0" "enter_insert_mode\0" \
-"invis\0" "enter_secure_mode\0" "prot\0" "enter_protected_mode\0" "rev\0" \
-"enter_reverse_mode\0" "smso\0" "enter_standout_mode\0" "smul\0" "enter_underline_mode\0" \
-"ech\0" "erase_chars\0" "rmacs\0" "exit_alt_charset_mode\0" "sgr0\0" "exit_attribute_mode\0" \
-"rmcup\0" "exit_ca_mode\0" "rmdc\0" "exit_delete_mode\0" "rmir\0" "exit_insert_mode\0" \
-"rmso\0" "exit_standout_mode\0" "rmul\0" "exit_underline_mode\0" "flash\0" \
-"flash_screen\0" "ff\0" "form_feed\0" "fsl\0" "from_status_line\0" "is1\0" \
-"init_1string\0" "is2\0" "init_2string\0" "is3\0" "init_3string\0" "if\0" \
-"init_file\0" "ich1\0" "insert_character\0" "il1\0" "insert_line\0" "ip\0" \
-"insert_padding\0" "kbs\0" "key_backspace\0" "ktbc\0" "key_catab\0" "kclr\0" \
-"key_clear\0" "kctab\0" "key_ctab\0" "kdch1\0" "key_dc\0" "kdl1\0" "key_dl\0" \
-"kcud1\0" "key_down\0" "krmir\0" "key_eic\0" "kel\0" "key_eol\0" "ked\0" \
-"key_eos\0" "kf0\0" "key_f0\0" "kf1\0" "key_f1\0" "kf10\0" "key_f10\0" \
-"kf2\0" "key_f2\0" "kf3\0" "key_f3\0" "kf4\0" "key_f4\0" "kf5\0" "key_f5\0" \
-"kf6\0" "key_f6\0" "kf7\0" "key_f7\0" "kf8\0" "key_f8\0" "kf9\0" "key_f9\0" \
-"khome\0" "key_home\0" "kich1\0" "key_ic\0" "kil1\0" "key_il\0" "kcub1\0" \
-"key_left\0" "kll\0" "key_ll\0" "knp\0" "key_npage\0" "kpp\0" "key_ppage\0" \
-"kcuf1\0" "key_right\0" "kind\0" "key_sf\0" "kri\0" "key_sr\0" "khts\0" \
-"key_stab\0" "kcuu1\0" "key_up\0" "rmkx\0" "keypad_local\0" "smkx\0" "keypad_xmit\0" \
-"lf0\0" "lab_f0\0" "lf1\0" "lab_f1\0" "lf10\0" "lab_f10\0" "lf2\0" "lab_f2\0" \
-"lf3\0" "lab_f3\0" "lf4\0" "lab_f4\0" "lf5\0" "lab_f5\0" "lf6\0" "lab_f6\0" \
-"lf7\0" "lab_f7\0" "lf8\0" "lab_f8\0" "lf9\0" "lab_f9\0" "rmm\0" "meta_off\0" \
-"smm\0" "meta_on\0" "nel\0" "newline\0" "pad\0" "pad_char\0" "dch\0" "parm_dch\0" \
-"dl\0" "parm_delete_line\0" "cud\0" "parm_down_cursor\0" "ich\0" "parm_ich\0" \
-"indn\0" "parm_index\0" "il\0" "parm_insert_line\0" "cub\0" "parm_left_cursor\0" \
-"cuf\0" "parm_right_cursor\0" "rin\0" "parm_rindex\0" "cuu\0" "parm_up_cursor\0" \
-"pfkey\0" "pkey_key\0" "pfloc\0" "pkey_local\0" "pfx\0" "pkey_xmit\0" "mc0\0" \
-"print_screen\0" "mc4\0" "prtr_off\0" "mc5\0" "prtr_on\0" "rep\0" "repeat_char\0" \
-"rs1\0" "reset_1string\0" "rs2\0" "reset_2string\0" "rs3\0" "reset_3string\0" \
-"rf\0" "reset_file\0" "rc\0" "restore_cursor\0" "vpa\0" "row_address\0" \
-"sc\0" "save_cursor\0" "ind\0" "scroll_forward\0" "ri\0" "scroll_reverse\0" \
-"sgr\0" "set_attributes\0" "hts\0" "set_tab\0" "wind\0" "set_window\0" \
-"ht\0" "tab\0" "tsl\0" "to_status_line\0" "uc\0" "underline_char\0" "hu\0" \
-"up_half_line\0" "iprog\0" "init_prog\0" "ka1\0" "key_a1\0" "ka3\0" "key_a3\0" \
-"kb2\0" "key_b2\0" "kc1\0" "key_c1\0" "kc3\0" "key_c3\0" "mc5p\0" "prtr_non\0" \
-"rmp\0" "char_padding\0" "acsc\0" "acs_chars\0" "pln\0" "plab_norm\0" "kcbt\0" \
-"key_btab\0" "smxon\0" "enter_xon_mode\0" "rmxon\0" "exit_xon_mode\0" "smam\0" \
-"enter_am_mode\0" "rmam\0" "exit_am_mode\0" "xonc\0" "xon_character\0" \
-"xoffc\0" "xoff_character\0" "enacs\0" "ena_acs\0" "smln\0" "label_on\0" \
-"rmln\0" "label_off\0" "kbeg\0" "key_beg\0" "kcan\0" "key_cancel\0" "kclo\0" \
-"key_close\0" "kcmd\0" "key_command\0" "kcpy\0" "key_copy\0" "kcrt\0" "key_create\0" \
-"kend\0" "key_end\0" "kent\0" "key_enter\0" "kext\0" "key_exit\0" "kfnd\0" \
-"key_find\0" "khlp\0" "key_help\0" "kmrk\0" "key_mark\0" "kmsg\0" "key_message\0" \
-"kmov\0" "key_move\0" "knxt\0" "key_next\0" "kopn\0" "key_open\0" "kopt\0" \
-"key_options\0" "kprv\0" "key_previous\0" "kprt\0" "key_print\0" "krdo\0" \
-"key_redo\0" "kref\0" "key_reference\0" "krfr\0" "key_refresh\0" "krpl\0" \
-"key_replace\0" "krst\0" "key_restart\0" "kres\0" "key_resume\0" "ksav\0" \
-"key_save\0" "kspd\0" "key_suspend\0" "kund\0" "key_undo\0" "kBEG\0" "key_sbeg\0" \
-"kCAN\0" "key_scancel\0" "kCMD\0" "key_scommand\0" "kCPY\0" "key_scopy\0" \
-"kCRT\0" "key_screate\0" "kDC\0" "key_sdc\0" "kDL\0" "key_sdl\0" "kslt\0" \
-"key_select\0" "kEND\0" "key_send\0" "kEOL\0" "key_seol\0" "kEXT\0" "key_sexit\0" \
-"kFND\0" "key_sfind\0" "kHLP\0" "key_shelp\0" "kHOM\0" "key_shome\0" "kIC\0" \
-"key_sic\0" "kLFT\0" "key_sleft\0" "kMSG\0" "key_smessage\0" "kMOV\0" "key_smove\0" \
-"kNXT\0" "key_snext\0" "kOPT\0" "key_soptions\0" "kPRV\0" "key_sprevious\0" \
-"kPRT\0" "key_sprint\0" "kRDO\0" "key_sredo\0" "kRPL\0" "key_sreplace\0" \
-"kRIT\0" "key_sright\0" "kRES\0" "key_srsume\0" "kSAV\0" "key_ssave\0" \
-"kSPD\0" "key_ssuspend\0" "kUND\0" "key_sundo\0" "rfi\0" "req_for_input\0" \
-"kf11\0" "key_f11\0" "kf12\0" "key_f12\0" "kf13\0" "key_f13\0" "kf14\0" \
-"key_f14\0" "kf15\0" "key_f15\0" "kf16\0" "key_f16\0" "kf17\0" "key_f17\0" \
-"kf18\0" "key_f18\0" "kf19\0" "key_f19\0" "kf20\0" "key_f20\0" "kf21\0" \
-"key_f21\0" "kf22\0" "key_f22\0" "kf23\0" "key_f23\0" "kf24\0" "key_f24\0" \
-"kf25\0" "key_f25\0" "kf26\0" "key_f26\0" "kf27\0" "key_f27\0" "kf28\0" \
-"key_f28\0" "kf29\0" "key_f29\0" "kf30\0" "key_f30\0" "kf31\0" "key_f31\0" \
-"kf32\0" "key_f32\0" "kf33\0" "key_f33\0" "kf34\0" "key_f34\0" "kf35\0" \
-"key_f35\0" "kf36\0" "key_f36\0" "kf37\0" "key_f37\0" "kf38\0" "key_f38\0" \
-"kf39\0" "key_f39\0" "kf40\0" "key_f40\0" "kf41\0" "key_f41\0" "kf42\0" \
-"key_f42\0" "kf43\0" "key_f43\0" "kf44\0" "key_f44\0" "kf45\0" "key_f45\0" \
-"kf46\0" "key_f46\0" "kf47\0" "key_f47\0" "kf48\0" "key_f48\0" "kf49\0" \
-"key_f49\0" "kf50\0" "key_f50\0" "kf51\0" "key_f51\0" "kf52\0" "key_f52\0" \
-"kf53\0" "key_f53\0" "kf54\0" "key_f54\0" "kf55\0" "key_f55\0" "kf56\0" \
-"key_f56\0" "kf57\0" "key_f57\0" "kf58\0" "key_f58\0" "kf59\0" "key_f59\0" \
-"kf60\0" "key_f60\0" "kf61\0" "key_f61\0" "kf62\0" "key_f62\0" "kf63\0" \
-"key_f63\0" "el1\0" "clr_bol\0" "mgc\0" "clear_margins\0" "smgl\0" "set_left_margin\0" \
-"smgr\0" "set_right_margin\0" "fln\0" "label_format\0" "sclk\0" "set_clock\0" \
-"dclk\0" "display_clock\0" "rmclk\0" "remove_clock\0" "cwin\0" "create_window\0" \
-"wingo\0" "goto_window\0" "hup\0" "hangup\0" "dial\0" "dial_phone\0" "qdial\0" \
-"quick_dial\0" "tone\0" "tone\0" "pulse\0" "pulse\0" "hook\0" "flash_hook\0" \
-"pause\0" "fixed_pause\0" "wait\0" "wait_tone\0" "u0\0" "user0\0" "u1\0" \
-"user1\0" "u2\0" "user2\0" "u3\0" "user3\0" "u4\0" "user4\0" "u5\0" "user5\0" \
-"u6\0" "user6\0" "u7\0" "user7\0" "u8\0" "user8\0" "u9\0" "user9\0" "op\0" \
-"orig_pair\0" "oc\0" "orig_colors\0" "initc\0" "initialize_color\0" "initp\0" \
-"initialize_pair\0" "scp\0" "set_color_pair\0" "setf\0" "set_foreground\0" \
-"setb\0" "set_background\0" "cpi\0" "change_char_pitch\0" "lpi\0" "change_line_pitch\0" \
-"chr\0" "change_res_horz\0" "cvr\0" "change_res_vert\0" "defc\0" "define_char\0" \
-"swidm\0" "enter_doublewide_mode\0" "sdrfq\0" "enter_draft_quality\0" "sitm\0" \
-"enter_italics_mode\0" "slm\0" "enter_leftward_mode\0" "smicm\0" "enter_micro_mode\0" \
-"snlq\0" "enter_near_letter_quality\0" "snrmq\0" "enter_normal_quality\0" \
-"sshm\0" "enter_shadow_mode\0" "ssubm\0" "enter_subscript_mode\0" "ssupm\0" \
-"enter_superscript_mode\0" "sum\0" "enter_upward_mode\0" "rwidm\0" "exit_doublewide_mode\0" \
-"ritm\0" "exit_italics_mode\0" "rlm\0" "exit_leftward_mode\0" "rmicm\0" \
-"exit_micro_mode\0" "rshm\0" "exit_shadow_mode\0" "rsubm\0" "exit_subscript_mode\0" \
-"rsupm\0" "exit_superscript_mode\0" "rum\0" "exit_upward_mode\0" "mhpa\0" \
-"micro_column_address\0" "mcud1\0" "micro_down\0" "mcub1\0" "micro_left\0" \
-"mcuf1\0" "micro_right\0" "mvpa\0" "micro_row_address\0" "mcuu1\0" "micro_up\0" \
-"porder\0" "order_of_pins\0" "mcud\0" "parm_down_micro\0" "mcub\0" "parm_left_micro\0" \
-"mcuf\0" "parm_right_micro\0" "mcuu\0" "parm_up_micro\0" "scs\0" "select_char_set\0" \
-"smgb\0" "set_bottom_margin\0" "smgbp\0" "set_bottom_margin_parm\0" "smglp\0" \
-"set_left_margin_parm\0" "smgrp\0" "set_right_margin_parm\0" "smgt\0" "set_top_margin\0" \
-"smgtp\0" "set_top_margin_parm\0" "sbim\0" "start_bit_image\0" "scsd\0" \
-"start_char_set_def\0" "rbim\0" "stop_bit_image\0" "rcsd\0" "stop_char_set_def\0" \
-"subcs\0" "subscript_characters\0" "supcs\0" "superscript_characters\0" \
-"docr\0" "these_cause_cr\0" "zerom\0" "zero_motion\0" "csnm\0" "char_set_names\0" \
-"kmous\0" "key_mouse\0" "minfo\0" "mouse_info\0" "reqmp\0" "req_mouse_pos\0" \
-"getm\0" "get_mouse\0" "setaf\0" "set_a_foreground\0" "setab\0" "set_a_background\0" \
-"pfxl\0" "pkey_plab\0" "devt\0" "device_type\0" "csin\0" "code_set_init\0" \
-"s0ds\0" "set0_des_seq\0" "s1ds\0" "set1_des_seq\0" "s2ds\0" "set2_des_seq\0" \
-"s3ds\0" "set3_des_seq\0" "smglr\0" "set_lr_margin\0" "smgtb\0" "set_tb_margin\0" \
-"birep\0" "bit_image_repeat\0" "binel\0" "bit_image_newline\0" "bicr\0" \
-"bit_image_carriage_return\0" "colornm\0" "color_names\0" "defbi\0" "define_bit_image_region\0" \
-"endbi\0" "end_bit_image_region\0" "setcolor\0" "set_color_band\0" "slines\0" \
-"set_page_length\0" "dispc\0" "display_pc_char\0" "smpch\0" "enter_pc_charset_mode\0" \
-"rmpch\0" "exit_pc_charset_mode\0" "smsc\0" "enter_scancode_mode\0" "rmsc\0" \
-"exit_scancode_mode\0" "pctrm\0" "pc_term_options\0" "scesc\0" "scancode_escape\0" \
-"scesa\0" "alt_scancode_esc\0" "ehhlm\0" "enter_horizontal_hl_mode\0" "elhlm\0" \
-"enter_left_hl_mode\0" "elohlm\0" "enter_low_hl_mode\0" "erhlm\0" "enter_right_hl_mode\0" \
-"ethlm\0" "enter_top_hl_mode\0" "evhlm\0" "enter_vertical_hl_mode\0" "sgr1\0" \
-"set_a_attributes\0" "slength\0" "set_pglen_inch\0" "OTi2\0" "termcap_init2\0" \
-"OTrs\0" "termcap_reset\0" "OTug\0" "magic_cookie_glitch_ul\0" "OTbs\0" \
-"backspaces_with_bs\0" "OTns\0" "crt_no_scrolling\0" "OTnc\0" "no_correctly_working_cr\0" \
-"OTdC\0" "carriage_return_delay\0" "OTdN\0" "new_line_delay\0" "OTnl\0" \
-"linefeed_if_not_lf\0" "OTbc\0" "backspace_if_not_bs\0" "OTMT\0" "gnu_has_meta_key\0" \
-"OTNL\0" "linefeed_is_newline\0" "OTdB\0" "backspace_delay\0" "OTdT\0" \
-"horizontal_tab_delay\0" "OTkn\0" "number_of_function_keys\0" "OTko\0" \
-"other_non_function_keys\0" "OTma\0" "arrow_key_map\0" "OTpt\0" "has_hardware_tabs\0" \
-"OTxr\0" "return_does_clr_eol\0" "OTG2\0" "acs_ulcorner\0" "OTG3\0" "acs_llcorner\0" \
-"OTG1\0" "acs_urcorner\0" "OTG4\0" "acs_lrcorner\0" "OTGR\0" "acs_ltee\0" \
-"OTGL\0" "acs_rtee\0" "OTGU\0" "acs_btee\0" "OTGD\0" "acs_ttee\0" "OTGH\0" \
-"acs_hline\0" "OTGV\0" "acs_vline\0" "OTGC\0" "acs_plus\0" "meml\0" "memory_lock\0" \
-"memu\0" "memory_unlock\0" "box1\0" "box_chars_1\0" ;
-static const short _nc_offset_boolfnames[] = {
-3, 23, 45, 61, 87, 109, 129,
-145, 158, 174, 193, 215, 231,
-248, 270, 292, 310, 332, 356,
-372, 398, 412, 432, 449, 467,
-485, 503, 530, 545, 566, 596,
-617, 645, 666, 686, 714, 735,
-8193, 8217, 8239, 8364, 8386, 8535, 8558, };
-
-static NCURSES_CONST char ** ptr_boolfnames = 0;
-
-static const short _nc_offset_boolnames[] = {
-0, 20, 41, 57, 82, 106, 126, 142, 155, 171, 190, 212, 228, 244, 265, 289, 304, 329, 353, 369, 394, 407, 427, 444, 461, 481, 497, 526, 541, 562, 591, 612, 639, 661, 682, 709, 730, 8188, 8212, 8234, 8359, 8381, 8530, 8553, };
-
-static NCURSES_CONST char ** ptr_boolnames = 0;
-
-static const short _nc_offset_numfnames[] = {
-756, 767, 783, 792, 812, 835,
-856, 877, 900, 914, 930, 945,
-965, 988, 1005, 1019, 1040, 1062, 1085, 1108, 1132, 1151, 1170,
-1192, 1211, 1231, 1252, 1278, 1303, 1320, 1340, 1355, 1382, 8165,
-8268, 8295, 8411, 8432,
-8458, };
-
-static NCURSES_CONST char ** ptr_numfnames = 0;
-
-static const short _nc_offset_numnames[] = {
-751, 764, 777, 789, 808, 832, 853, 873, 895, 911, 927, 942, 960, 981, 999, 1015, 1034, 1056,
-1079, 1102, 1126, 1147, 1166, 1186, 1207, 1227, 1247, 1273, 1299,
-1314, 1335, 1348, 1375, 8160, 8263, 8290, 8406, 8427, 8453, };
-
-static NCURSES_CONST char ** ptr_numnames = 0;
-
-static const short _nc_offset_strfnames[] = {
-1401,
-1414, 1422, 1442, 1467, 1488, 1504, 1515, 1527, 1548, 1570, 1590,
-1607, 1625, 1647, 1665, 1690, 1709, 1725, 1743, 1759, 1779, 1800,
-1816, 1835, 1856, 1885, 1907, 1929, 1948, 1970, 1990, 2014, 2037,
-2062, 2086, 2111, 2136, 2154, 2181, 2207, 2225, 2247, 2269, 2293,
-2319, 2335, 2349, 2370, 2387, 2404, 2420, 2435, 2456, 2471, 2490,
-2509, 2524, 2540, 2555, 2567, 2580, 2595, 2607, 2619, 2631, 2642,
-2654, 2666, 2677, 2688, 2699, 2710, 2721, 2732, 2743, 2756, 2771,
-2783, 2796, 2809, 2820, 2834, 2850, 2865, 2876, 2888, 2903, 2915,
-2933, 2949, 2960, 2972, 2984, 2995, 3006, 3017, 3028, 3039, 3050,
-3061, 3072, 3085, 3097, 3109, 3122, 3134, 3155, 3176, 3190, 3204,
-3225, 3246, 3268, 3284, 3305, 3320, 3335, 3349, 3366, 3379, 3391,
-3407, 3425, 3443, 3460, 3474, 3493, 3508, 3524, 3542, 3561, 3580,
-3593, 3607, 3615, 3633, 3651, 3670, 3684, 3695, 3706, 3717, 3728,
-3740, 3753, 3771, 3785, 3800, 3815, 3836, 3855, 3874, 3892, 3912,
-3933, 3946, 3960, 3975, 3988, 4004, 4019, 4036, 4050, 4066, 4079,
-4094, 4108, 4122, 4136, 4150, 4167, 4181, 4195, 4209, 4226, 4244,
-4259, 4273, 4292, 4309, 4326, 4343, 4359, 4373, 4390, 4404, 4418,
-4435, 4453, 4468, 4484, 4496, 4509, 4525, 4539, 4553, 4568, 4583,
-4598, 4612, 4625, 4640, 4658, 4673, 4688, 4706, 4725, 4741, 4756,
-4774, 4790, 4806, 4821, 4839, 4853, 4872, 4885, 4898, 4911, 4924,
-4937, 4950, 4963, 4976, 4989, 5002, 5015, 5028, 5041, 5054, 5067,
-5080, 5093, 5106, 5119, 5132, 5145, 5158, 5171, 5184, 5197, 5210,
-5223, 5236, 5249, 5262, 5275, 5288, 5301, 5314, 5327, 5340, 5353,
-5366, 5379, 5392, 5405, 5418, 5431, 5444, 5457, 5470, 5483, 5496,
-5509, 5522, 5535, 5548, 5560, 5572, 5591, 5612, 5633, 5651, 5666,
-5686, 5704, 5724, 5740, 5752, 5769, 5785, 5796, 5807, 5824, 5841,
-5854, 5863, 5872, 5881, 5890, 5899, 5908, 5917, 5926, 5935, 5944,
-5957, 5975, 5998, 6018, 6038, 6058, 6077, 6099, 6121, 6141, 6162,
-6180, 6208, 6233, 6256, 6282, 6304, 6336, 6362, 6386, 6413, 6440,
-6464, 6490, 6512, 6537, 6558, 6581, 6607, 6633, 6655, 6682, 6699,
-6716, 6733, 6757, 6773, 6792, 6813, 6834, 6856, 6874, 6895, 6919,
-6948, 6975, 7002, 7023, 7048, 7069, 7093, 7113, 7137, 7164, 7192,
-7213, 7230, 7251, 7267, 7284, 7303, 7319, 7342, 7364, 7379, 7396,
-7415, 7433, 7451, 7469, 7488, 7508, 7528, 7551, 7574, 7608, 7626,
-7656, 7686, 7708, 7730, 7752, 7780, 7806, 7831, 7856, 7878, 7900,
-7923, 7954, 7980, 8004, 8030, 8054, 8082, 8107, 8127, 8146, 8315, 8339, 8487, 8516, 8583, 8601, 8619, 8637, 8655, 8669,
-8683, 8697, 8711, 8726, 8741, 8755, 8772, 8791, };
-
-static NCURSES_CONST char ** ptr_strfnames = 0;
-
-static const short _nc_offset_strnames[] = {
-1397, 1410, 1419, 1438, 1463, 1482, 1501,
-1512, 1523, 1542, 1566, 1585, 1602, 1619, 1642, 1659, 1684, 1704,
-1722, 1738, 1753, 1774, 1796, 1812, 1832, 1850, 1879, 1902, 1923,
-1943, 1966, 1985, 2008, 2032, 2058, 2081, 2106, 2132, 2148, 2176,
-2201, 2220, 2242, 2264, 2288, 2313, 2332, 2345, 2366, 2383, 2400,
-2417, 2430, 2452, 2468, 2486, 2504, 2519, 2534, 2549, 2562, 2574,
-2589, 2603, 2615, 2627, 2638, 2649, 2662, 2673, 2684, 2695, 2706,
-2717, 2728, 2739, 2750, 2765, 2778, 2790, 2805, 2816, 2830, 2844,
-2860, 2872, 2883, 2897, 2910, 2928, 2945, 2956, 2967, 2980, 2991,
-3002, 3013, 3024, 3035, 3046, 3057, 3068, 3081, 3093, 3105, 3118,
-3131, 3151, 3172, 3185, 3201, 3221, 3242, 3264, 3280, 3299, 3314,
-3331, 3345, 3362, 3375, 3387, 3403, 3421, 3439, 3457, 3471, 3489,
-3505, 3520, 3539, 3557, 3576, 3588, 3604, 3611, 3630, 3648, 3664,
-3680, 3691, 3702, 3713, 3724, 3735, 3749, 3766, 3781, 3795, 3809,
-3830, 3850, 3869, 3887, 3906, 3927, 3941, 3955, 3970, 3983, 3999,
-4014, 4031, 4045, 4061, 4074, 4089, 4103, 4117, 4131, 4145, 4162,
-4176, 4190, 4204, 4221, 4239, 4254, 4268, 4287, 4304, 4321, 4338,
-4354, 4368, 4385, 4399, 4413, 4430, 4448, 4463, 4480, 4492, 4504,
-4520, 4534, 4548, 4563, 4578, 4593, 4608, 4620, 4635, 4653, 4668,
-4683, 4701, 4720, 4736, 4751, 4769, 4785, 4801, 4816, 4834, 4849,
-4867, 4880, 4893, 4906, 4919, 4932, 4945, 4958, 4971, 4984, 4997,
-5010, 5023, 5036, 5049, 5062, 5075, 5088, 5101, 5114, 5127, 5140,
-5153, 5166, 5179, 5192, 5205, 5218, 5231, 5244, 5257, 5270, 5283,
-5296, 5309, 5322, 5335, 5348, 5361, 5374, 5387, 5400, 5413, 5426,
-5439, 5452, 5465, 5478, 5491, 5504, 5517, 5530, 5543, 5556, 5568,
-5586, 5607, 5629, 5646, 5661, 5680, 5699, 5718, 5736, 5747, 5763,
-5780, 5790, 5802, 5818, 5836, 5851, 5860, 5869, 5878, 5887, 5896,
-5905, 5914, 5923, 5932, 5941, 5954, 5969, 5992, 6014, 6033, 6053,
-6073, 6095, 6117, 6137, 6157, 6174, 6202, 6228, 6252, 6276, 6299,
-6330, 6357, 6380, 6407, 6436, 6458, 6485, 6508, 6531, 6553, 6575,
-6601, 6629, 6650, 6676, 6693, 6710, 6728, 6751, 6766, 6787, 6808,
-6829, 6851, 6870, 6890, 6913, 6942, 6969, 6997, 7017, 7043, 7064,
-7088, 7108, 7131, 7158, 7187, 7207, 7225, 7245, 7261, 7278, 7298,
-7313, 7336, 7359, 7374, 7391, 7410, 7428, 7446, 7464, 7482, 7502,
-7522, 7545, 7569, 7600, 7620, 7650, 7677, 7701, 7724, 7746, 7774,
-7801, 7826, 7850, 7872, 7894, 7917, 7948, 7973, 7998, 8024, 8048,
-8077, 8099, 8122, 8141, 8310,
-8334, 8482, 8511, 8578,
-8596, 8614, 8632, 8650, 8664, 8678, 8692, 8706, 8721, 8736, 8750,
-8767, 8786, };
-
-static NCURSES_CONST char ** ptr_strnames = 0;
-
-
-static IT *
-alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)
-{
-	if (*value == 0) {
-		if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {
-			unsigned n;
-			for (n = 0; n < size; ++n) {
-				(*value)[n] = (NCURSES_CONST char *) _nc_name_blob + offsets[n];
-			}
-		}
-	}
-	return *value;
-}
-
-#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }
-
-FIX(boolnames)
-FIX(boolfnames)
-FIX(numnames)
-FIX(numfnames)
-FIX(strnames)
-FIX(strfnames)
-
-
-#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }
-
-#if NO_LEAKS
-NCURSES_EXPORT(void)
-_nc_names_leaks(void)
-{
-FREE_FIX(boolnames)
-FREE_FIX(boolfnames)
-FREE_FIX(numnames)
-FREE_FIX(numfnames)
-FREE_FIX(strnames)
-FREE_FIX(strfnames)
-}
-#endif
-
-#else
-
-#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]
-
-DCL(boolnames) = {
-		"bw",
-		"am",
-		"xsb",
-		"xhp",
-		"xenl",
-		"eo",
-		"gn",
-		"hc",
-		"km",
-		"hs",
-		"in",
-		"da",
-		"db",
-		"mir",
-		"msgr",
-		"os",
-		"eslok",
-		"xt",
-		"hz",
-		"ul",
-		"xon",
-		"nxon",
-		"mc5i",
-		"chts",
-		"nrrmc",
-		"npc",
-		"ndscr",
-		"ccc",
-		"bce",
-		"hls",
-		"xhpa",
-		"crxm",
-		"daisy",
-		"xvpa",
-		"sam",
-		"cpix",
-		"lpix",
-		"OTbs",
-		"OTns",
-		"OTnc",
-		"OTMT",
-		"OTNL",
-		"OTpt",
-		"OTxr",
-
-		(NCURSES_CONST char *)0,
-};
-
-DCL(boolfnames) = {
-		"auto_left_margin",
-		"auto_right_margin",
-		"no_esc_ctlc",
-		"ceol_standout_glitch",
-		"eat_newline_glitch",
-		"erase_overstrike",
-		"generic_type",
-		"hard_copy",
-		"has_meta_key",
-		"has_status_line",
-		"insert_null_glitch",
-		"memory_above",
-		"memory_below",
-		"move_insert_mode",
-		"move_standout_mode",
-		"over_strike",
-		"status_line_esc_ok",
-		"dest_tabs_magic_smso",
-		"tilde_glitch",
-		"transparent_underline",
-		"xon_xoff",
-		"needs_xon_xoff",
-		"prtr_silent",
-		"hard_cursor",
-		"non_rev_rmcup",
-		"no_pad_char",
-		"non_dest_scroll_region",
-		"can_change",
-		"back_color_erase",
-		"hue_lightness_saturation",
-		"col_addr_glitch",
-		"cr_cancels_micro_mode",
-		"has_print_wheel",
-		"row_addr_glitch",
-		"semi_auto_right_margin",
-		"cpi_changes_res",
-		"lpi_changes_res",
-		"backspaces_with_bs",
-		"crt_no_scrolling",
-		"no_correctly_working_cr",
-		"gnu_has_meta_key",
-		"linefeed_is_newline",
-		"has_hardware_tabs",
-		"return_does_clr_eol",
-
-		(NCURSES_CONST char *)0,
-};
-
-DCL(numnames) = {
-		"cols",
-		"it",
-		"lines",
-		"lm",
-		"xmc",
-		"pb",
-		"vt",
-		"wsl",
-		"nlab",
-		"lh",
-		"lw",
-		"ma",
-		"wnum",
-		"colors",
-		"pairs",
-		"ncv",
-		"bufsz",
-		"spinv",
-		"spinh",
-		"maddr",
-		"mjump",
-		"mcs",
-		"mls",
-		"npins",
-		"orc",
-		"orl",
-		"orhi",
-		"orvi",
-		"cps",
-		"widcs",
-		"btns",
-		"bitwin",
-		"bitype",
-		"OTug",
-		"OTdC",
-		"OTdN",
-		"OTdB",
-		"OTdT",
-		"OTkn",
-
-		(NCURSES_CONST char *)0,
-};
-
-DCL(numfnames) = {
-		"columns",
-		"init_tabs",
-		"lines",
-		"lines_of_memory",
-		"magic_cookie_glitch",
-		"padding_baud_rate",
-		"virtual_terminal",
-		"width_status_line",
-		"num_labels",
-		"label_height",
-		"label_width",
-		"max_attributes",
-		"maximum_windows",
-		"max_colors",
-		"max_pairs",
-		"no_color_video",
-		"buffer_capacity",
-		"dot_vert_spacing",
-		"dot_horz_spacing",
-		"max_micro_address",
-		"max_micro_jump",
-		"micro_col_size",
-		"micro_line_size",
-		"number_of_pins",
-		"output_res_char",
-		"output_res_line",
-		"output_res_horz_inch",
-		"output_res_vert_inch",
-		"print_rate",
-		"wide_char_size",
-		"buttons",
-		"bit_image_entwining",
-		"bit_image_type",
-		"magic_cookie_glitch_ul",
-		"carriage_return_delay",
-		"new_line_delay",
-		"backspace_delay",
-		"horizontal_tab_delay",
-		"number_of_function_keys",
-
-		(NCURSES_CONST char *)0,
-};
-
-DCL(strnames) = {
-		"cbt",
-		"bel",
-		"cr",
-		"csr",
-		"tbc",
-		"clear",
-		"el",
-		"ed",
-		"hpa",
-		"cmdch",
-		"cup",
-		"cud1",
-		"home",
-		"civis",
-		"cub1",
-		"mrcup",
-		"cnorm",
-		"cuf1",
-		"ll",
-		"cuu1",
-		"cvvis",
-		"dch1",
-		"dl1",
-		"dsl",
-		"hd",
-		"smacs",
-		"blink",
-		"bold",
-		"smcup",
-		"smdc",
-		"dim",
-		"smir",
-		"invis",
-		"prot",
-		"rev",
-		"smso",
-		"smul",
-		"ech",
-		"rmacs",
-		"sgr0",
-		"rmcup",
-		"rmdc",
-		"rmir",
-		"rmso",
-		"rmul",
-		"flash",
-		"ff",
-		"fsl",
-		"is1",
-		"is2",
-		"is3",
-		"if",
-		"ich1",
-		"il1",
-		"ip",
-		"kbs",
-		"ktbc",
-		"kclr",
-		"kctab",
-		"kdch1",
-		"kdl1",
-		"kcud1",
-		"krmir",
-		"kel",
-		"ked",
-		"kf0",
-		"kf1",
-		"kf10",
-		"kf2",
-		"kf3",
-		"kf4",
-		"kf5",
-		"kf6",
-		"kf7",
-		"kf8",
-		"kf9",
-		"khome",
-		"kich1",
-		"kil1",
-		"kcub1",
-		"kll",
-		"knp",
-		"kpp",
-		"kcuf1",
-		"kind",
-		"kri",
-		"khts",
-		"kcuu1",
-		"rmkx",
-		"smkx",
-		"lf0",
-		"lf1",
-		"lf10",
-		"lf2",
-		"lf3",
-		"lf4",
-		"lf5",
-		"lf6",
-		"lf7",
-		"lf8",
-		"lf9",
-		"rmm",
-		"smm",
-		"nel",
-		"pad",
-		"dch",
-		"dl",
-		"cud",
-		"ich",
-		"indn",
-		"il",
-		"cub",
-		"cuf",
-		"rin",
-		"cuu",
-		"pfkey",
-		"pfloc",
-		"pfx",
-		"mc0",
-		"mc4",
-		"mc5",
-		"rep",
-		"rs1",
-		"rs2",
-		"rs3",
-		"rf",
-		"rc",
-		"vpa",
-		"sc",
-		"ind",
-		"ri",
-		"sgr",
-		"hts",
-		"wind",
-		"ht",
-		"tsl",
-		"uc",
-		"hu",
-		"iprog",
-		"ka1",
-		"ka3",
-		"kb2",
-		"kc1",
-		"kc3",
-		"mc5p",
-		"rmp",
-		"acsc",
-		"pln",
-		"kcbt",
-		"smxon",
-		"rmxon",
-		"smam",
-		"rmam",
-		"xonc",
-		"xoffc",
-		"enacs",
-		"smln",
-		"rmln",
-		"kbeg",
-		"kcan",
-		"kclo",
-		"kcmd",
-		"kcpy",
-		"kcrt",
-		"kend",
-		"kent",
-		"kext",
-		"kfnd",
-		"khlp",
-		"kmrk",
-		"kmsg",
-		"kmov",
-		"knxt",
-		"kopn",
-		"kopt",
-		"kprv",
-		"kprt",
-		"krdo",
-		"kref",
-		"krfr",
-		"krpl",
-		"krst",
-		"kres",
-		"ksav",
-		"kspd",
-		"kund",
-		"kBEG",
-		"kCAN",
-		"kCMD",
-		"kCPY",
-		"kCRT",
-		"kDC",
-		"kDL",
-		"kslt",
-		"kEND",
-		"kEOL",
-		"kEXT",
-		"kFND",
-		"kHLP",
-		"kHOM",
-		"kIC",
-		"kLFT",
-		"kMSG",
-		"kMOV",
-		"kNXT",
-		"kOPT",
-		"kPRV",
-		"kPRT",
-		"kRDO",
-		"kRPL",
-		"kRIT",
-		"kRES",
-		"kSAV",
-		"kSPD",
-		"kUND",
-		"rfi",
-		"kf11",
-		"kf12",
-		"kf13",
-		"kf14",
-		"kf15",
-		"kf16",
-		"kf17",
-		"kf18",
-		"kf19",
-		"kf20",
-		"kf21",
-		"kf22",
-		"kf23",
-		"kf24",
-		"kf25",
-		"kf26",
-		"kf27",
-		"kf28",
-		"kf29",
-		"kf30",
-		"kf31",
-		"kf32",
-		"kf33",
-		"kf34",
-		"kf35",
-		"kf36",
-		"kf37",
-		"kf38",
-		"kf39",
-		"kf40",
-		"kf41",
-		"kf42",
-		"kf43",
-		"kf44",
-		"kf45",
-		"kf46",
-		"kf47",
-		"kf48",
-		"kf49",
-		"kf50",
-		"kf51",
-		"kf52",
-		"kf53",
-		"kf54",
-		"kf55",
-		"kf56",
-		"kf57",
-		"kf58",
-		"kf59",
-		"kf60",
-		"kf61",
-		"kf62",
-		"kf63",
-		"el1",
-		"mgc",
-		"smgl",
-		"smgr",
-		"fln",
-		"sclk",
-		"dclk",
-		"rmclk",
-		"cwin",
-		"wingo",
-		"hup",
-		"dial",
-		"qdial",
-		"tone",
-		"pulse",
-		"hook",
-		"pause",
-		"wait",
-		"u0",
-		"u1",
-		"u2",
-		"u3",
-		"u4",
-		"u5",
-		"u6",
-		"u7",
-		"u8",
-		"u9",
-		"op",
-		"oc",
-		"initc",
-		"initp",
-		"scp",
-		"setf",
-		"setb",
-		"cpi",
-		"lpi",
-		"chr",
-		"cvr",
-		"defc",
-		"swidm",
-		"sdrfq",
-		"sitm",
-		"slm",
-		"smicm",
-		"snlq",
-		"snrmq",
-		"sshm",
-		"ssubm",
-		"ssupm",
-		"sum",
-		"rwidm",
-		"ritm",
-		"rlm",
-		"rmicm",
-		"rshm",
-		"rsubm",
-		"rsupm",
-		"rum",
-		"mhpa",
-		"mcud1",
-		"mcub1",
-		"mcuf1",
-		"mvpa",
-		"mcuu1",
-		"porder",
-		"mcud",
-		"mcub",
-		"mcuf",
-		"mcuu",
-		"scs",
-		"smgb",
-		"smgbp",
-		"smglp",
-		"smgrp",
-		"smgt",
-		"smgtp",
-		"sbim",
-		"scsd",
-		"rbim",
-		"rcsd",
-		"subcs",
-		"supcs",
-		"docr",
-		"zerom",
-		"csnm",
-		"kmous",
-		"minfo",
-		"reqmp",
-		"getm",
-		"setaf",
-		"setab",
-		"pfxl",
-		"devt",
-		"csin",
-		"s0ds",
-		"s1ds",
-		"s2ds",
-		"s3ds",
-		"smglr",
-		"smgtb",
-		"birep",
-		"binel",
-		"bicr",
-		"colornm",
-		"defbi",
-		"endbi",
-		"setcolor",
-		"slines",
-		"dispc",
-		"smpch",
-		"rmpch",
-		"smsc",
-		"rmsc",
-		"pctrm",
-		"scesc",
-		"scesa",
-		"ehhlm",
-		"elhlm",
-		"elohlm",
-		"erhlm",
-		"ethlm",
-		"evhlm",
-		"sgr1",
-		"slength",
-		"OTi2",
-		"OTrs",
-		"OTnl",
-		"OTbc",
-		"OTko",
-		"OTma",
-		"OTG2",
-		"OTG3",
-		"OTG1",
-		"OTG4",
-		"OTGR",
-		"OTGL",
-		"OTGU",
-		"OTGD",
-		"OTGH",
-		"OTGV",
-		"OTGC",
-		"meml",
-		"memu",
-		"box1",
-
-		(NCURSES_CONST char *)0,
-};
-
-DCL(strfnames) = {
-		"back_tab",
-		"bell",
-		"carriage_return",
-		"change_scroll_region",
-		"clear_all_tabs",
-		"clear_screen",
-		"clr_eol",
-		"clr_eos",
-		"column_address",
-		"command_character",
-		"cursor_address",
-		"cursor_down",
-		"cursor_home",
-		"cursor_invisible",
-		"cursor_left",
-		"cursor_mem_address",
-		"cursor_normal",
-		"cursor_right",
-		"cursor_to_ll",
-		"cursor_up",
-		"cursor_visible",
-		"delete_character",
-		"delete_line",
-		"dis_status_line",
-		"down_half_line",
-		"enter_alt_charset_mode",
-		"enter_blink_mode",
-		"enter_bold_mode",
-		"enter_ca_mode",
-		"enter_delete_mode",
-		"enter_dim_mode",
-		"enter_insert_mode",
-		"enter_secure_mode",
-		"enter_protected_mode",
-		"enter_reverse_mode",
-		"enter_standout_mode",
-		"enter_underline_mode",
-		"erase_chars",
-		"exit_alt_charset_mode",
-		"exit_attribute_mode",
-		"exit_ca_mode",
-		"exit_delete_mode",
-		"exit_insert_mode",
-		"exit_standout_mode",
-		"exit_underline_mode",
-		"flash_screen",
-		"form_feed",
-		"from_status_line",
-		"init_1string",
-		"init_2string",
-		"init_3string",
-		"init_file",
-		"insert_character",
-		"insert_line",
-		"insert_padding",
-		"key_backspace",
-		"key_catab",
-		"key_clear",
-		"key_ctab",
-		"key_dc",
-		"key_dl",
-		"key_down",
-		"key_eic",
-		"key_eol",
-		"key_eos",
-		"key_f0",
-		"key_f1",
-		"key_f10",
-		"key_f2",
-		"key_f3",
-		"key_f4",
-		"key_f5",
-		"key_f6",
-		"key_f7",
-		"key_f8",
-		"key_f9",
-		"key_home",
-		"key_ic",
-		"key_il",
-		"key_left",
-		"key_ll",
-		"key_npage",
-		"key_ppage",
-		"key_right",
-		"key_sf",
-		"key_sr",
-		"key_stab",
-		"key_up",
-		"keypad_local",
-		"keypad_xmit",
-		"lab_f0",
-		"lab_f1",
-		"lab_f10",
-		"lab_f2",
-		"lab_f3",
-		"lab_f4",
-		"lab_f5",
-		"lab_f6",
-		"lab_f7",
-		"lab_f8",
-		"lab_f9",
-		"meta_off",
-		"meta_on",
-		"newline",
-		"pad_char",
-		"parm_dch",
-		"parm_delete_line",
-		"parm_down_cursor",
-		"parm_ich",
-		"parm_index",
-		"parm_insert_line",
-		"parm_left_cursor",
-		"parm_right_cursor",
-		"parm_rindex",
-		"parm_up_cursor",
-		"pkey_key",
-		"pkey_local",
-		"pkey_xmit",
-		"print_screen",
-		"prtr_off",
-		"prtr_on",
-		"repeat_char",
-		"reset_1string",
-		"reset_2string",
-		"reset_3string",
-		"reset_file",
-		"restore_cursor",
-		"row_address",
-		"save_cursor",
-		"scroll_forward",
-		"scroll_reverse",
-		"set_attributes",
-		"set_tab",
-		"set_window",
-		"tab",
-		"to_status_line",
-		"underline_char",
-		"up_half_line",
-		"init_prog",
-		"key_a1",
-		"key_a3",
-		"key_b2",
-		"key_c1",
-		"key_c3",
-		"prtr_non",
-		"char_padding",
-		"acs_chars",
-		"plab_norm",
-		"key_btab",
-		"enter_xon_mode",
-		"exit_xon_mode",
-		"enter_am_mode",
-		"exit_am_mode",
-		"xon_character",
-		"xoff_character",
-		"ena_acs",
-		"label_on",
-		"label_off",
-		"key_beg",
-		"key_cancel",
-		"key_close",
-		"key_command",
-		"key_copy",
-		"key_create",
-		"key_end",
-		"key_enter",
-		"key_exit",
-		"key_find",
-		"key_help",
-		"key_mark",
-		"key_message",
-		"key_move",
-		"key_next",
-		"key_open",
-		"key_options",
-		"key_previous",
-		"key_print",
-		"key_redo",
-		"key_reference",
-		"key_refresh",
-		"key_replace",
-		"key_restart",
-		"key_resume",
-		"key_save",
-		"key_suspend",
-		"key_undo",
-		"key_sbeg",
-		"key_scancel",
-		"key_scommand",
-		"key_scopy",
-		"key_screate",
-		"key_sdc",
-		"key_sdl",
-		"key_select",
-		"key_send",
-		"key_seol",
-		"key_sexit",
-		"key_sfind",
-		"key_shelp",
-		"key_shome",
-		"key_sic",
-		"key_sleft",
-		"key_smessage",
-		"key_smove",
-		"key_snext",
-		"key_soptions",
-		"key_sprevious",
-		"key_sprint",
-		"key_sredo",
-		"key_sreplace",
-		"key_sright",
-		"key_srsume",
-		"key_ssave",
-		"key_ssuspend",
-		"key_sundo",
-		"req_for_input",
-		"key_f11",
-		"key_f12",
-		"key_f13",
-		"key_f14",
-		"key_f15",
-		"key_f16",
-		"key_f17",
-		"key_f18",
-		"key_f19",
-		"key_f20",
-		"key_f21",
-		"key_f22",
-		"key_f23",
-		"key_f24",
-		"key_f25",
-		"key_f26",
-		"key_f27",
-		"key_f28",
-		"key_f29",
-		"key_f30",
-		"key_f31",
-		"key_f32",
-		"key_f33",
-		"key_f34",
-		"key_f35",
-		"key_f36",
-		"key_f37",
-		"key_f38",
-		"key_f39",
-		"key_f40",
-		"key_f41",
-		"key_f42",
-		"key_f43",
-		"key_f44",
-		"key_f45",
-		"key_f46",
-		"key_f47",
-		"key_f48",
-		"key_f49",
-		"key_f50",
-		"key_f51",
-		"key_f52",
-		"key_f53",
-		"key_f54",
-		"key_f55",
-		"key_f56",
-		"key_f57",
-		"key_f58",
-		"key_f59",
-		"key_f60",
-		"key_f61",
-		"key_f62",
-		"key_f63",
-		"clr_bol",
-		"clear_margins",
-		"set_left_margin",
-		"set_right_margin",
-		"label_format",
-		"set_clock",
-		"display_clock",
-		"remove_clock",
-		"create_window",
-		"goto_window",
-		"hangup",
-		"dial_phone",
-		"quick_dial",
-		"tone",
-		"pulse",
-		"flash_hook",
-		"fixed_pause",
-		"wait_tone",
-		"user0",
-		"user1",
-		"user2",
-		"user3",
-		"user4",
-		"user5",
-		"user6",
-		"user7",
-		"user8",
-		"user9",
-		"orig_pair",
-		"orig_colors",
-		"initialize_color",
-		"initialize_pair",
-		"set_color_pair",
-		"set_foreground",
-		"set_background",
-		"change_char_pitch",
-		"change_line_pitch",
-		"change_res_horz",
-		"change_res_vert",
-		"define_char",
-		"enter_doublewide_mode",
-		"enter_draft_quality",
-		"enter_italics_mode",
-		"enter_leftward_mode",
-		"enter_micro_mode",
-		"enter_near_letter_quality",
-		"enter_normal_quality",
-		"enter_shadow_mode",
-		"enter_subscript_mode",
-		"enter_superscript_mode",
-		"enter_upward_mode",
-		"exit_doublewide_mode",
-		"exit_italics_mode",
-		"exit_leftward_mode",
-		"exit_micro_mode",
-		"exit_shadow_mode",
-		"exit_subscript_mode",
-		"exit_superscript_mode",
-		"exit_upward_mode",
-		"micro_column_address",
-		"micro_down",
-		"micro_left",
-		"micro_right",
-		"micro_row_address",
-		"micro_up",
-		"order_of_pins",
-		"parm_down_micro",
-		"parm_left_micro",
-		"parm_right_micro",
-		"parm_up_micro",
-		"select_char_set",
-		"set_bottom_margin",
-		"set_bottom_margin_parm",
-		"set_left_margin_parm",
-		"set_right_margin_parm",
-		"set_top_margin",
-		"set_top_margin_parm",
-		"start_bit_image",
-		"start_char_set_def",
-		"stop_bit_image",
-		"stop_char_set_def",
-		"subscript_characters",
-		"superscript_characters",
-		"these_cause_cr",
-		"zero_motion",
-		"char_set_names",
-		"key_mouse",
-		"mouse_info",
-		"req_mouse_pos",
-		"get_mouse",
-		"set_a_foreground",
-		"set_a_background",
-		"pkey_plab",
-		"device_type",
-		"code_set_init",
-		"set0_des_seq",
-		"set1_des_seq",
-		"set2_des_seq",
-		"set3_des_seq",
-		"set_lr_margin",
-		"set_tb_margin",
-		"bit_image_repeat",
-		"bit_image_newline",
-		"bit_image_carriage_return",
-		"color_names",
-		"define_bit_image_region",
-		"end_bit_image_region",
-		"set_color_band",
-		"set_page_length",
-		"display_pc_char",
-		"enter_pc_charset_mode",
-		"exit_pc_charset_mode",
-		"enter_scancode_mode",
-		"exit_scancode_mode",
-		"pc_term_options",
-		"scancode_escape",
-		"alt_scancode_esc",
-		"enter_horizontal_hl_mode",
-		"enter_left_hl_mode",
-		"enter_low_hl_mode",
-		"enter_right_hl_mode",
-		"enter_top_hl_mode",
-		"enter_vertical_hl_mode",
-		"set_a_attributes",
-		"set_pglen_inch",
-		"termcap_init2",
-		"termcap_reset",
-		"linefeed_if_not_lf",
-		"backspace_if_not_bs",
-		"other_non_function_keys",
-		"arrow_key_map",
-		"acs_ulcorner",
-		"acs_llcorner",
-		"acs_urcorner",
-		"acs_lrcorner",
-		"acs_ltee",
-		"acs_rtee",
-		"acs_btee",
-		"acs_ttee",
-		"acs_hline",
-		"acs_vline",
-		"acs_plus",
-		"memory_lock",
-		"memory_unlock",
-		"box_chars_1",
-
-		(NCURSES_CONST char *)0,
-};
-
-
-#endif /* BROKEN_LINKER */
diff --git a/ncurses/tinfo/MKcaptab.sh b/ncurses/tinfo/MKcaptab.sh
index 98c04e8..20c94a6 100755
--- a/ncurses/tinfo/MKcaptab.sh
+++ b/ncurses/tinfo/MKcaptab.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 ##############################################################################
-# Copyright (c) 2007 Free Software Foundation, Inc.                          #
+# Copyright (c) 2007-2010,2011 Free Software Foundation, Inc.                #
 #                                                                            #
 # Permission is hereby granted, free of charge, to any person obtaining a    #
 # copy of this software and associated documentation files (the "Software"), #
@@ -26,12 +26,19 @@
 # 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 $
+# $Id: MKcaptab.sh,v 1.14 2011/10/22 16:34:50 tom Exp $
 AWK=${1-awk}
 OPT1=${2-0}
 OPT2=${3-tinfo/MKcaptab.awk}
 DATA=${4-../include/Caps}
 
+cat <<EOF
+/*
+ * generated by $0
+ */
+
+EOF
+
 cat <<'EOF'
 /*
  *	comp_captab.c -- The names of the capabilities indexed via a hash
@@ -48,7 +55,7 @@
 ./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=capalias <$DATA
 
 $AWK -f $OPT2 bigstrings=$OPT1 tablename=infoalias <$DATA
 
@@ -58,7 +65,7 @@
 static void
 next_string(const char *strings, unsigned *offset)
 {
-	*offset += strlen(strings + *offset) + 1;
+    *offset += (unsigned) strlen(strings + *offset) + 1;
 }
 
 static const struct name_table_entry *
@@ -66,21 +73,21 @@
 		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);
-			}
-		}
+    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;
+    }
+    return *actual;
 }
 
 #define add_alias(field) \\
@@ -92,20 +99,20 @@
 _nc_build_alias(struct alias **actual,
 		const alias_table_data *source,
 		const char *strings,
-		unsigned tablesize)
+		size_t 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);
-			}
-		}
+    if (*actual == 0) {
+	*actual = typeCalloc(struct alias, tablesize + 1);
+	if (*actual != 0) {
+	    size_t n;
+	    for (n = 0; n < tablesize; ++n) {
+		add_alias(from);
+		add_alias(to);
+		add_alias(source);
+	    }
 	}
-	return *actual;
+    }
+    return *actual;
 }
 
 #define build_names(root) _nc_build_names(&_nc_##root##_table, \\
@@ -122,27 +129,82 @@
 
 NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool termcap)
 {
-	return termcap ? build_names(cap) : build_names(info) ;
+    return termcap ? build_names(cap) : build_names(info) ;
 }
 
-NCURSES_EXPORT(const short *) _nc_get_hash_table (bool termcap)
+/* entrypoint used by tack (do not alter) */
+NCURSES_EXPORT(const HashValue *) _nc_get_hash_table (bool termcap)
 {
-	return termcap ? _nc_cap_hash_table: _nc_info_hash_table ;
+    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) ;
+    return termcap ? build_alias(cap) : build_alias(info) ;
+}
+
+static HashValue
+info_hash(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 (HashValue) (sum % HASHTABSIZE);
+}
+
+#define TCAP_LEN 2		/* only 1- or 2-character names are used */
+
+static HashValue
+tcap_hash(const char *string)
+{
+    char temp[TCAP_LEN + 1];
+    int limit = 0;
+
+    while (*string) {
+	temp[limit++] = *string++;
+	if (limit >= TCAP_LEN)
+	    break;
+    }
+    temp[limit] = '\0';
+    return info_hash(temp);
+}
+
+static int
+compare_tcap_names(const char *a, const char *b)
+{
+    return !strncmp(a, b, (size_t) TCAP_LEN);
+}
+
+static int
+compare_info_names(const char *a, const char *b)
+{
+    return !strcmp(a, b);
+}
+
+static const HashData hash_data[2] = {
+    { HASHTABSIZE, _nc_info_hash_table, info_hash, compare_info_names },
+    { HASHTABSIZE, _nc_cap_hash_table, tcap_hash, compare_tcap_names }
+};
+
+NCURSES_EXPORT(const HashData *) _nc_get_hash_info (bool termcap)
+{
+    return &hash_data[(termcap != FALSE)];
 }
 
 #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);
+    FreeIfNeeded(_nc_cap_table);
+    FreeIfNeeded(_nc_info_table);
+    FreeIfNeeded(_nc_capalias_table);
+    FreeIfNeeded(_nc_infoalias_table);
 #endif
 }
 #endif /* NO_LEAKS */
diff --git a/ncurses/tinfo/MKcodes.awk b/ncurses/tinfo/MKcodes.awk
index b9ba636..97e5131 100644
--- a/ncurses/tinfo/MKcodes.awk
+++ b/ncurses/tinfo/MKcodes.awk
@@ -1,5 +1,5 @@
 ##############################################################################
-# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2009,2010 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"), #
@@ -25,7 +25,7 @@
 # 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 $
+# $Id: MKcodes.awk,v 1.9 2010/01/23 17:57:43 tom Exp $
 function large_item(value) {
 	result = sprintf("%d,", offset);
 	offset = offset + length(value) + 1;
@@ -101,8 +101,6 @@
 		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;
@@ -117,28 +115,39 @@
 			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  "				(*value)[n] = (NCURSES_CONST char *) _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)); }"
+			print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API NCURSES_PUBLIC_VAR(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  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API NCURSES_PUBLIC_VAR(it)(void) { return data##it; }"
 		}
 		print  ""
+		print  "/* remove public definition which conflicts with FIX() */"
+		print  "#undef boolcodes"
+		print  "#undef numcodes"
+		print  "#undef strcodes"
+		print  ""
+		print  "/* add local definition */"
 		print  "FIX(boolcodes)"
 		print  "FIX(numcodes)"
 		print  "FIX(strcodes)"
 		print  ""
+		print  "/* restore the public definition */"
+		print  ""
 		print  "#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }"
+		print  "#define boolcodes  NCURSES_PUBLIC_VAR(boolcodes())"
+		print  "#define numcodes   NCURSES_PUBLIC_VAR(numcodes())"
+		print  "#define strcodes   NCURSES_PUBLIC_VAR(strcodes())"
 		print  ""
 		print  "#if NO_LEAKS"
 		print  "NCURSES_EXPORT(void)"
diff --git a/ncurses/tinfo/MKfallback.sh b/ncurses/tinfo/MKfallback.sh
index 9feab35..11f1d2e 100755
--- a/ncurses/tinfo/MKfallback.sh
+++ b/ncurses/tinfo/MKfallback.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 ##############################################################################
-# Copyright (c) 1998-2001,2006 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2009,2010 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"), #
@@ -26,7 +26,7 @@
 # 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 $
+# $Id: MKfallback.sh,v 1.15 2010/08/07 20:32:34 tom Exp $
 #
 # MKfallback.sh -- create fallback table for entry reads
 #
@@ -42,6 +42,17 @@
 terminfo_src=$1
 shift
 
+tic_path=$1
+shift
+
+case $tic_path in #(vi
+/*)
+	tic_head=`echo "$tic_path" | sed -e 's,/[^/]*$,,'`
+	PATH=$tic_head:$PATH
+	export PATH
+	;;
+esac
+
 if test $# != 0 ; then
 	tmp_info=tmp_info
 	echo creating temporary terminfo directory... >&2
@@ -52,7 +63,7 @@
 	TERMINFO_DIRS=$TERMINFO:$terminfo_dir
 	export TERMINFO_DIRS
 
-	tic -x $terminfo_src >&2
+	$tic_path -x $terminfo_src >&2
 else
 	tmp_info=
 fi
@@ -63,7 +74,6 @@
  */
 
 #include <curses.priv.h>
-#include <term.h>
 
 EOF
 
diff --git a/ncurses/tinfo/MKnames.awk b/ncurses/tinfo/MKnames.awk
index 7e50744..7685d18 100644
--- a/ncurses/tinfo/MKnames.awk
+++ b/ncurses/tinfo/MKnames.awk
@@ -1,5 +1,5 @@
 ##############################################################################
-# Copyright (c) 2007,2008 Free Software Foundation, Inc.                     #
+# Copyright (c) 2007-2008,2009 Free Software Foundation, Inc.                #
 #                                                                            #
 # Permission is hereby granted, free of charge, to any person obtaining a    #
 # copy of this software and associated documentation files (the "Software"), #
@@ -25,7 +25,7 @@
 # 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 $
+# $Id: MKnames.awk,v 1.22 2009/03/21 21:03:39 tom Exp $
 function large_item(value) {
 	result = sprintf("%d,", offset);
 	offset = offset + length(value) + 1;
@@ -107,8 +107,6 @@
 		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;
@@ -133,7 +131,7 @@
 			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)); }"
+			print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API NCURSES_PUBLIC_VAR(it)(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }"
 		} else {
 			print  "#define DCL(it) static IT data##it[]"
 			print  ""
@@ -143,9 +141,18 @@
 			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  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API NCURSES_PUBLIC_VAR(it)(void) { return data##it; }"
 		}
 		print  ""
+		print  "/* remove public definition which conflicts with FIX() */"
+		print  "#undef boolnames"
+		print  "#undef boolfnames"
+		print  "#undef numnames"
+		print  "#undef numfnames"
+		print  "#undef strnames"
+		print  "#undef strfnames"
+		print  ""
+		print  "/* add local definition */"
 		print  "FIX(boolnames)"
 		print  "FIX(boolfnames)"
 		print  "FIX(numnames)"
@@ -153,6 +160,13 @@
 		print  "FIX(strnames)"
 		print  "FIX(strfnames)"
 		print  ""
+		print  "/* restore the public definition */"
+		print  "#define boolnames  NCURSES_PUBLIC_VAR(boolnames())"
+		print  "#define boolfnames NCURSES_PUBLIC_VAR(boolfnames())"
+		print  "#define numnames   NCURSES_PUBLIC_VAR(numnames())"
+		print  "#define numfnames  NCURSES_PUBLIC_VAR(numfnames())"
+		print  "#define strnames   NCURSES_PUBLIC_VAR(strnames())"
+		print  "#define strfnames  NCURSES_PUBLIC_VAR(strfnames())"
 		print  ""
 		print  "#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }"
 		print  ""
diff --git a/ncurses/tinfo/access.c b/ncurses/tinfo/access.c
index ce8ccda..d987687 100644
--- a/ncurses/tinfo/access.c
+++ b/ncurses/tinfo/access.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -33,12 +33,18 @@
 #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 $")
+MODULE_ID("$Id: access.c,v 1.23 2012/09/01 19:21:29 tom Exp $")
+
+#ifdef __TANDEM
+#define ROOT_UID 65535
+#endif
+
+#ifndef ROOT_UID
+#define ROOT_UID 0
+#endif
 
 #define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
 
@@ -54,7 +60,7 @@
     result = temp;
 #if !MIXEDCASE_FILENAMES
     for (s = result; *s != '\0'; ++s) {
-	*s = LOWERCASE(*s);
+	*s = (char) LOWERCASE(*s);
     }
 #endif
 #if defined(PROG_EXT)
@@ -97,7 +103,7 @@
 	test = path;
     else
 	test++;
-    return (test - path);
+    return (unsigned) (test - path);
 }
 
 NCURSES_EXPORT(char *)
@@ -109,24 +115,33 @@
 NCURSES_EXPORT(int)
 _nc_access(const char *path, int mode)
 {
-    if (access(path, mode) < 0) {
+    int result;
+
+    if (path == 0) {
+	result = -1;
+    } else 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));
+	    char *leaf;
 
+	    _nc_STRCPY(head, path, sizeof(head));
+	    leaf = _nc_basename(head);
 	    if (leaf == 0)
 		leaf = head;
 	    *leaf = '\0';
 	    if (head == leaf)
-		(void) strcpy(head, ".");
+		_nc_STRCPY(head, ".", sizeof(head));
 
-	    return access(head, R_OK | W_OK | X_OK);
+	    result = access(head, R_OK | W_OK | X_OK);
+	} else {
+	    result = -1;
 	}
-	return -1;
+    } else {
+	result = 0;
     }
-    return 0;
+    return result;
 }
 
 NCURSES_EXPORT(bool)
@@ -136,7 +151,7 @@
     struct stat sb;
 
     if (stat(path, &sb) == 0
-	&& (sb.st_mode & S_IFMT) == S_IFDIR) {
+	&& S_ISDIR(sb.st_mode)) {
 	result = TRUE;
     }
     return result;
@@ -149,7 +164,7 @@
     struct stat sb;
 
     if (stat(path, &sb) == 0
-	&& (sb.st_mode & S_IFMT) == S_IFREG) {
+	&& S_ISREG(sb.st_mode)) {
 	result = TRUE;
     }
     return result;
@@ -171,6 +186,7 @@
 	|| getgid() != getegid())
 	return FALSE;
 #endif
-    return getuid() != 0 && geteuid() != 0;	/* ...finally, disallow root */
+    /* ...finally, disallow root */
+    return (getuid() != ROOT_UID) && (geteuid() != ROOT_UID);
 }
 #endif
diff --git a/ncurses/tinfo/add_tries.c b/ncurses/tinfo/add_tries.c
index 455d142..29a1a60 100644
--- a/ncurses/tinfo/add_tries.c
+++ b/ncurses/tinfo/add_tries.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: add_tries.c,v 1.8 2006/12/30 23:15:26 tom Exp $")
+MODULE_ID("$Id: add_tries.c,v 1.10 2010/12/19 01:31:14 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))
@@ -50,7 +50,8 @@
     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));
+    T((T_CALLED("_nc_add_to_try(%p, %s, %u)"),
+       (void *) *tree, _nc_visbuf(str), code));
     if (txt == 0 || *txt == '\0' || code == 0)
 	returnCode(ERR);
 
@@ -66,7 +67,7 @@
 
 	    if (CMP_TRY(ptr->ch, cmp)) {
 		if (*(++txt) == '\0') {
-		    ptr->value = code;
+		    ptr->value = (unsigned short) code;
 		    returnCode(OK);
 		}
 		if (ptr->child != 0)
@@ -115,6 +116,6 @@
 	ptr->value = 0;
     }
 
-    ptr->value = code;
+    ptr->value = (unsigned short) code;
     returnCode(OK);
 }
diff --git a/ncurses/tinfo/alloc_entry.c b/ncurses/tinfo/alloc_entry.c
index 4638e99..14ea391 100644
--- a/ncurses/tinfo/alloc_entry.c
+++ b/ncurses/tinfo/alloc_entry.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -46,9 +46,8 @@
 #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 $")
+MODULE_ID("$Id: alloc_entry.c,v 1.58 2013/08/17 19:20:38 tom Exp $")
 
 #define ABSENT_OFFSET    -1
 #define CANCELLED_OFFSET -2
@@ -62,43 +61,21 @@
 _nc_init_entry(TERMTYPE *const tp)
 /* initialize a terminal type data block */
 {
-    unsigned i;
-
 #if NO_LEAKS
-    if (tp == 0 && stringbuf != 0) {
-	FreeAndNull(stringbuf);
+    if (tp == 0) {
+	if (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;
+	TYPE_MALLOC(char, (size_t) MAX_STRTAB, stringbuf);
 
     next_free = 0;
+
+    _nc_init_termtype(tp);
 }
 
 NCURSES_EXPORT(ENTRY *)
@@ -130,13 +107,13 @@
 	    result = (stringbuf + next_free - 1);
 	}
     } else if (next_free + len < MAX_STRTAB) {
-	strcpy(&stringbuf[next_free], string);
+	_nc_STRCPY(&stringbuf[next_free], string, MAX_STRTAB);
 	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");
+	_nc_warning("Too much data, some is lost: %s", string);
     }
     return result;
 }
@@ -181,7 +158,7 @@
 	    } else if (tp->Strings[i] == CANCELLED_STRING) {
 		offsets[i] = CANCELLED_OFFSET;
 	    } else {
-		offsets[i] = tp->Strings[i] - stringbuf;
+		offsets[i] = (int) (tp->Strings[i] - stringbuf);
 	    }
 	}
     }
@@ -190,11 +167,10 @@
 	if (ep->uses[i].name == 0)
 	    useoffsets[i] = ABSENT_OFFSET;
 	else
-	    useoffsets[i] = ep->uses[i].name - stringbuf;
+	    useoffsets[i] = (int) (ep->uses[i].name - stringbuf);
     }
 
-    if ((tp->str_table = typeMalloc(char, next_free)) == (char *) 0)
-	  _nc_err_abort(MSG_NO_MEMORY);
+    TYPE_MALLOC(char, next_free, tp->str_table);
     (void) memcpy(tp->str_table, stringbuf, next_free);
 
     tp->term_names = tp->str_table + n;
@@ -214,17 +190,19 @@
     if (!copy_strings) {
 	if ((n = (unsigned) NUM_EXT_NAMES(tp)) != 0) {
 	    if (n < SIZEOF(offsets)) {
-		unsigned length = 0;
+		size_t length = 0;
+		size_t offset;
 		for (i = 0; i < n; i++) {
 		    length += strlen(tp->ext_Names[i]) + 1;
-		    offsets[i] = tp->ext_Names[i] - stringbuf;
+		    offsets[i] = (int) (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;
+		TYPE_MALLOC(char, length, tp->ext_str_table);
+		for (i = 0, offset = 0; i < n; i++) {
+		    tp->ext_Names[i] = tp->ext_str_table + offset;
+		    _nc_STRCPY(tp->ext_Names[i],
+			       stringbuf + offsets[i],
+			       length - offset);
+		    offset += strlen(tp->ext_Names[i]) + 1;
 		}
 	    }
 	}
diff --git a/ncurses/tinfo/alloc_ttype.c b/ncurses/tinfo/alloc_ttype.c
index b2b06d1..35c92dd 100644
--- a/ncurses/tinfo/alloc_ttype.c
+++ b/ncurses/tinfo/alloc_ttype.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1999-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,9 +41,8 @@
 #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 $")
+MODULE_ID("$Id: alloc_ttype.c,v 1.27 2013/06/08 16:54:50 tom Exp $")
 
 #if NCURSES_XNAMES
 /*
@@ -91,6 +90,9 @@
     return FALSE;
 }
 
+#define EXTEND_NUM(num, ext) \
+	to->num = (unsigned short) (to->num + (ext - to->ext))
+
 static void
 realign_data(TERMTYPE *to, char **ext_Names,
 	     int ext_Booleans,
@@ -101,8 +103,8 @@
     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);
+	EXTEND_NUM(num_Booleans, ext_Booleans);
+	TYPE_REALLOC(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--) {
@@ -112,11 +114,12 @@
 		to->Booleans[base + m] = FALSE;
 	    }
 	}
-	to->ext_Booleans = ext_Booleans;
+	to->ext_Booleans = UShort(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);
+	EXTEND_NUM(num_Numbers, ext_Numbers);
+	TYPE_REALLOC(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--) {
@@ -126,11 +129,11 @@
 		to->Numbers[base + m] = ABSENT_NUMERIC;
 	    }
 	}
-	to->ext_Numbers = ext_Numbers;
+	to->ext_Numbers = UShort(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);
+	EXTEND_NUM(num_Strings, ext_Strings);
+	TYPE_REALLOC(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--) {
@@ -140,17 +143,17 @@
 		to->Strings[base + m] = ABSENT_STRING;
 	    }
 	}
-	to->ext_Strings = ext_Strings;
+	to->ext_Strings = UShort(ext_Strings);
     }
 }
 
 /*
  * Returns the first index in ext_Names[] for the given token-type
  */
-static int
+static unsigned
 _nc_first_ext_name(TERMTYPE *tp, int token_type)
 {
-    int first;
+    unsigned first;
 
     switch (token_type) {
     case BOOLEAN:
@@ -160,7 +163,7 @@
 	first = tp->ext_Booleans;
 	break;
     case STRING:
-	first = tp->ext_Booleans + tp->ext_Numbers;
+	first = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
 	break;
     default:
 	first = 0;
@@ -172,17 +175,17 @@
 /*
  * Returns the last index in ext_Names[] for the given token-type
  */
-static int
+static unsigned
 _nc_last_ext_name(TERMTYPE *tp, int token_type)
 {
-    int last;
+    unsigned last;
 
     switch (token_type) {
     case BOOLEAN:
 	last = tp->ext_Booleans;
 	break;
     case NUMBER:
-	last = tp->ext_Booleans + tp->ext_Numbers;
+	last = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
 	break;
     default:
     case STRING:
@@ -204,7 +207,7 @@
 
     for (j = first; j < last; j++) {
 	if (!strcmp(name, tp->ext_Names[j])) {
-	    return j;
+	    return (int) j;
 	}
     }
     return -1;
@@ -244,7 +247,7 @@
     int first, last;
 
     if ((first = _nc_find_ext_name(tp, name, token_type)) >= 0) {
-	last = NUM_EXT_NAMES(tp) - 1;
+	last = (int) NUM_EXT_NAMES(tp) - 1;
 	for (j = first; j < last; j++) {
 	    tp->ext_Names[j] = tp->ext_Names[j + 1];
 	}
@@ -254,22 +257,22 @@
 	    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;
+	    tp->ext_Booleans--;
+	    tp->num_Booleans--;
 	    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;
+	    tp->ext_Numbers--;
+	    tp->num_Numbers--;
 	    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;
+	    tp->ext_Strings--;
+	    tp->num_Strings--;
 	    break;
 	}
 	return TRUE;
@@ -299,36 +302,36 @@
 	}
     }
 
-    tp->ext_Names = typeRealloc(char *, total, tp->ext_Names);
+    TYPE_REALLOC(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);
+    j = (unsigned) _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->ext_Booleans++;
+	tp->num_Booleans++;
+	TYPE_REALLOC(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
+	for (k = (unsigned) (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->ext_Numbers++;
+	tp->num_Numbers++;
+	TYPE_REALLOC(short, tp->num_Numbers, tp->Numbers);
+	for (k = (unsigned) (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->ext_Strings++;
+	tp->num_Strings++;
+	TYPE_REALLOC(char *, tp->num_Strings, tp->Strings);
+	for (k = (unsigned) (tp->num_Strings - 1); k > j; k--)
 	    tp->Strings[k] = tp->Strings[k - 1];
 	break;
     }
-    return j;
+    return (int) j;
 }
 
 /*
@@ -345,10 +348,10 @@
 
     for (j = first; j < last;) {
 	char *name = to->ext_Names[j];
-	unsigned j_str = to->num_Strings - first - to->ext_Strings;
+	int 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_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);
@@ -356,8 +359,7 @@
 		} else {
 		    j++;
 		}
-	    } else if ((k = _nc_find_ext_name(from, to->ext_Names[j],
-					      NUMBER)) >= 0) {
+	    } else if (_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);
@@ -365,8 +367,7 @@
 		} else {
 		    j++;
 		}
-	    } else if ((k = _nc_find_ext_name(from, to->ext_Names[j],
-					      STRING)) >= 0) {
+	    } else if (_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);
@@ -386,8 +387,8 @@
 NCURSES_EXPORT(void)
 _nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
 {
-    int na = NUM_EXT_NAMES(to);
-    int nb = NUM_EXT_NAMES(from);
+    int na = (int) NUM_EXT_NAMES(to);
+    int nb = (int) NUM_EXT_NAMES(from);
     int n;
     bool same;
     char **ext_Names;
@@ -417,7 +418,7 @@
 	 * 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);
+	TYPE_MALLOC(char *, (size_t)(na + nb), ext_Names);
 
 	if (to->ext_Strings && (from->ext_Booleans + from->ext_Numbers))
 	    adjust_cancels(to, from);
@@ -461,8 +462,8 @@
 	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);
+	    TYPE_REALLOC(char *, (size_t) nb, from->ext_Names);
+	    memcpy(from->ext_Names, ext_Names, sizeof(char *) * (size_t) nb);
 	    DEBUG(2, ("realigned %d extended names for '%s' (from)",
 		      NUM_EXT_NAMES(from), from->term_names));
 	}
@@ -473,22 +474,27 @@
 #endif
 
 NCURSES_EXPORT(void)
-_nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src)
+_nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src)
 {
+#if NCURSES_XNAMES
     unsigned i;
+#endif
 
     *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];
+    TYPE_MALLOC(NCURSES_SBOOL, NUM_BOOLEANS(dst), dst->Booleans);
+    TYPE_MALLOC(short, NUM_NUMBERS(dst), dst->Numbers);
+    TYPE_MALLOC(char *, NUM_STRINGS(dst), dst->Strings);
+
+    memcpy(dst->Booleans,
+	   src->Booleans,
+	   NUM_BOOLEANS(dst) * sizeof(dst->Booleans[0]));
+    memcpy(dst->Numbers,
+	   src->Numbers,
+	   NUM_NUMBERS(dst) * sizeof(dst->Numbers[0]));
+    memcpy(dst->Strings,
+	   src->Strings,
+	   NUM_STRINGS(dst) * sizeof(dst->Strings[0]));
 
     /* FIXME: we probably should also copy str_table and ext_str_table,
      * but tic and infocmp are not written to exploit that (yet).
@@ -496,11 +502,10 @@
 
 #if NCURSES_XNAMES
     if ((i = NUM_EXT_NAMES(src)) != 0) {
-	dst->ext_Names = typeMalloc(char *, i);
+	TYPE_MALLOC(char *, i, dst->ext_Names);
 	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
index 93300c1..e02e622 100644
--- a/ncurses/tinfo/captoinfo.c
+++ b/ncurses/tinfo/captoinfo.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -93,7 +93,7 @@
 #include <ctype.h>
 #include <tic.h>
 
-MODULE_ID("$Id: captoinfo.c,v 1.52 2008/08/16 19:24:51 tom Exp $")
+MODULE_ID("$Id: captoinfo.c,v 1.77 2012/12/30 00:50:40 tom Exp $")
 
 #define MAX_PUSHED	16	/* max # args we can push onto the stack */
 
@@ -114,9 +114,7 @@
 /* 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);
+	TYPE_MALLOC(char, my_length = 256, my_string);
 
     *my_string = '\0';
     return my_string;
@@ -125,15 +123,15 @@
 static char *
 save_string(char *d, const char *const s)
 {
-    size_t have = (d - my_string);
+    size_t have = (size_t) (d - my_string);
     size_t need = have + strlen(s) + 2;
     if (need > my_length) {
-	my_string = (char *) realloc(my_string, my_length = (need + need));
+	my_string = (char *) _nc_doalloc(my_string, my_length = (need + need));
 	if (my_string == 0)
 	    _nc_err_abort(MSG_NO_MEMORY);
 	d = my_string + have;
     }
-    (void) strcpy(d, s);
+    _nc_STRCPY(d, s, my_length - have);
     return d + strlen(d);
 }
 
@@ -196,7 +194,7 @@
 	case '3':
 	    len = 1;
 	    while (isdigit(UChar(*sp))) {
-		c = 8 * c + (*sp++ - '0');
+		c = (unsigned char) (8 * c + (*sp++ - '0'));
 		len++;
 	    }
 	    break;
@@ -207,7 +205,7 @@
 	}
 	break;
     case '^':
-	c = (*++sp & 0x1f);
+	c = (unsigned char) (*++sp & 0x1f);
 	len = 2;
 	break;
     default:
@@ -240,6 +238,12 @@
 	else if (parm == 2)
 	    parm = 1;
     }
+
+    while (n--) {
+	dp = save_string(dp, "%p");
+	dp = save_char(dp, '0' + parm);
+    }
+
     if (onstack == parm) {
 	if (n > 1) {
 	    _nc_warning("string may not be optimal");
@@ -255,11 +259,6 @@
 
     onstack = parm;
 
-    while (n--) {
-	dp = save_string(dp, "%p");
-	dp = save_char(dp, '0' + parm);
-    }
-
     if (seenn && parm < 3) {
 	dp = save_string(dp, "%{96}%^");
     }
@@ -469,73 +468,9 @@
 		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
 	}
     }
 
@@ -578,7 +513,7 @@
 	{
 	    char buffer[80];
 	    int tst;
-	    sprintf(buffer, fmt, ch1, ch2);
+	    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) fmt, ch1, ch2);
 	    tst = strlen(buffer) - 1;
 	    assert(len == tst);
 	}
@@ -597,10 +532,13 @@
 	    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);
+	if (c1 == (c1 & 0x1f)) {	/* iscntrl() returns T on 255 */
+	    _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+			"%.20s", unctrl((chtype) c1));
+	} else {
+	    _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+			"\\%03o", c1);
+	}
 	bufptr = save_string(bufptr, temp);
     }
     return bufptr;
@@ -643,15 +581,18 @@
     int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0;
     const char *padding;
     const char *trimmed = 0;
+    int in0, in1, in2;
     char ch1 = 0, ch2 = 0;
     char *bufptr = init_string();
+    char octal[4];
     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;
+    if (padding > str && *padding == '>') {
+	if (*--padding == '/')
+	    --padding;
 	while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*')
 	    padding--;
 	if (padding > str && *padding == '<' && *--padding == '$')
@@ -662,12 +603,95 @@
 	    bufptr = save_char(bufptr, *padding++);
     }
 
-    for (; *str && str != trimmed; str++) {
+    for (; *str && ((trimmed == 0) || (str < trimmed)); str++) {
 	int c1, c2;
 	char *cp = 0;
 
-	if (str[0] == '\\' && (str[1] == '^' || str[1] == ',')) {
-	    bufptr = save_char(bufptr, *++str);
+	if (str[0] == '^') {
+	    if (str[1] == '\0' || (str + 1) == trimmed) {
+		bufptr = save_string(bufptr, "\\136");
+		++str;
+	    } else {
+		bufptr = save_char(bufptr, *str++);
+		bufptr = save_char(bufptr, *str);
+	    }
+	} else if (str[0] == '\\') {
+	    if (str[1] == '\0' || (str + 1) == trimmed) {
+		bufptr = save_string(bufptr, "\\134");
+		++str;
+	    } else if (str[1] == '^') {
+		bufptr = save_string(bufptr, "\\136");
+		++str;
+	    } else if (str[1] == ',') {
+		bufptr = save_char(bufptr, *++str);
+	    } else {
+		int xx1, xx2;
+
+		bufptr = save_char(bufptr, *str++);
+		xx1 = *str;
+		if (_nc_strict_bsd) {
+		    if (isdigit(UChar(xx1))) {
+			int pad = 0;
+
+			if (!isdigit(UChar(str[1])))
+			    pad = 2;
+			else if (str[1] && !isdigit(UChar(str[2])))
+			    pad = 1;
+
+			/*
+			 * Test for "\0", "\00" or "\000" and transform those
+			 * into "\200".
+			 */
+			if (xx1 == '0'
+			    && ((pad == 2) || (str[1] == '0'))
+			    && ((pad >= 1) || (str[2] == '0'))) {
+			    xx2 = '2';
+			} else {
+			    xx2 = '0';
+			    pad = 0;	/* FIXME - optionally pad to 3 digits */
+			}
+			while (pad-- > 0) {
+			    bufptr = save_char(bufptr, xx2);
+			    xx2 = '0';
+			}
+		    } else if (strchr("E\\nrtbf", xx1) == 0) {
+			switch (xx1) {
+			case 'e':
+			    xx1 = 'E';
+			    break;
+			case 'l':
+			    xx1 = 'n';
+			    break;
+			case 's':
+			    bufptr = save_char(bufptr, '0');
+			    bufptr = save_char(bufptr, '4');
+			    xx1 = '0';
+			    break;
+			case ':':
+			    /*
+			     * Note: termcap documentation claims that ":"
+			     * must be escaped as "\072", however the
+			     * documentation is incorrect - read the code.
+			     * The replacement does not work reliably,
+			     * so the advice is not helpful.
+			     */
+			    bufptr = save_char(bufptr, '0');
+			    bufptr = save_char(bufptr, '7');
+			    xx1 = '2';
+			    break;
+			default:
+			    /* should not happen, but handle this anyway */
+			    _nc_SPRINTF(octal, _nc_SLIMIT(sizeof(octal))
+					"%03o", UChar(xx1));
+			    bufptr = save_char(bufptr, octal[0]);
+			    bufptr = save_char(bufptr, octal[1]);
+			    xx1 = octal[2];
+			    break;
+			}
+		    }
+		}
+		bufptr = save_char(bufptr, xx1);
+	    }
 	} else if (str[0] == '$' && str[1] == '<') {	/* discard padding */
 	    str += 2;
 	    while (isdigit(UChar(*str))
@@ -677,6 +701,20 @@
 		   || *str == '>')
 		str++;
 	    --str;
+	} else if (sscanf(str,
+			  "[%%?%%p1%%{8}%%<%%t%d%%p1%%d%%e%%p1%%{16}%%<%%t%d%%p1%%{8}%%-%%d%%e%d;5;%%p1%%d%%;m",
+			  &in0, &in1, &in2) == 3
+		   && ((in0 == 4 && in1 == 10 && in2 == 48)
+		       || (in0 == 3 && in1 == 9 && in2 == 38))) {
+	    /* dumb-down an optimized case from xterm-256color for termcap */
+	    if ((str = strstr(str, ";m")) == 0)
+		break;		/* cannot happen */
+	    ++str;
+	    if (in2 == 48) {
+		bufptr = save_string(bufptr, "[48;5;%dm");
+	    } else {
+		bufptr = save_string(bufptr, "[38;5;%dm");
+	    }
 	} else if (str[0] == '%' && str[1] == '%') {	/* escaped '%' */
 	    bufptr = save_string(bufptr, "%%");
 	    ++str;
@@ -687,13 +725,13 @@
 	    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);
+	    bufptr = save_tc_inequality(bufptr, c1, ch2);
 	} else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1, &c2) == 2) {
 	    str = strchr(str, ';');
-	    bufptr = save_tc_inequality(bufptr, c1, c2);
+	    bufptr = save_tc_inequality(bufptr, ch1, c2);
 	} else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2) {
 	    str = strchr(str, ';');
-	    bufptr = save_tc_inequality(bufptr, c1, c2);
+	    bufptr = save_tc_inequality(bufptr, ch1, ch2);
 	} else if ((len = bcd_expression(str)) != 0) {
 	    str += len;
 	    bufptr = save_string(bufptr, "%B");
@@ -708,15 +746,15 @@
 	    bufptr = save_tc_char(bufptr, c1);
 	}
 	/* FIXME: this "works" for 'delta' */
-	else if (strncmp(str, "%{2}%*%-", 8) == 0) {
+	else if (strncmp(str, "%{2}%*%-", (size_t) 8) == 0) {
 	    str += 7;
 	    bufptr = save_string(bufptr, "%D");
-	} else if (strncmp(str, "%{96}%^", 7) == 0) {
+	} else if (strncmp(str, "%{96}%^", (size_t) 7) == 0) {
 	    str += 6;
 	    if (saw_m++ == 0) {
 		bufptr = save_string(bufptr, "%n");
 	    }
-	} else if (strncmp(str, "%{127}%^", 8) == 0) {
+	} else if (strncmp(str, "%{127}%^", (size_t) 8) == 0) {
 	    str += 7;
 	    if (saw_n++ == 0) {
 		bufptr = save_string(bufptr, "%m");
@@ -739,8 +777,25 @@
 	    case '8':
 	    case '9':
 		bufptr = save_char(bufptr, '%');
-		while (isdigit(UChar(*str)))
-		    bufptr = save_char(bufptr, *str++);
+		ch1 = 0;
+		ch2 = 0;
+		while (isdigit(UChar(*str))) {
+		    ch2 = ch1;
+		    ch1 = *str++;
+		    if (_nc_strict_bsd) {
+			if (ch1 > '3')
+			    return 0;
+		    } else {
+			bufptr = save_char(bufptr, ch1);
+		    }
+		}
+		if (_nc_strict_bsd) {
+		    if (ch2 != 0 && ch2 != '0')
+			return 0;
+		    if (ch1 < '2')
+			ch1 = 'd';
+		    bufptr = save_char(bufptr, ch1);
+		}
 		if (strchr("doxX.", *str)) {
 		    if (*str != 'd')	/* termcap doesn't have octal, hex */
 			return 0;
@@ -761,6 +816,8 @@
 		 * termcap notation.
 		 */
 	    case 's':
+		if (_nc_strict_bsd)
+		    return 0;
 		bufptr = save_string(bufptr, "%s");
 		break;
 
@@ -793,7 +850,7 @@
 	 * but that may not be the end of the string.
 	 */
 	assert(str != 0);
-	if (*str == '\0')
+	if (str == 0 || *str == '\0')
 	    break;
 
     }				/* endwhile (*str) */
diff --git a/ncurses/tinfo/comp_error.c b/ncurses/tinfo/comp_error.c
index 56c362a..ff0acc7 100644
--- a/ncurses/tinfo/comp_error.c
+++ b/ncurses/tinfo/comp_error.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,7 +41,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: comp_error.c,v 1.31 2007/04/21 23:38:32 tom Exp $")
+MODULE_ID("$Id: comp_error.c,v 1.36 2012/02/22 22:34:31 tom Exp $")
 
 NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
 NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
@@ -59,7 +59,8 @@
 NCURSES_EXPORT(void)
 _nc_set_source(const char *const name)
 {
-    SourceName = name;
+    FreeIfNeeded(SourceName);
+    SourceName = strdup(name);
 }
 
 NCURSES_EXPORT(void)
@@ -70,7 +71,7 @@
     if (TermType != 0) {
 	TermType[0] = '\0';
 	if (name)
-	    strncat(TermType, name, MAX_NAME_SIZE);
+	    strncat(TermType, name, (size_t) MAX_NAME_SIZE);
     }
 }
 
@@ -84,7 +85,7 @@
     }
 #endif
     if (name != 0)
-	strcpy(name, TermType != 0 ? TermType : "");
+	_nc_STRCPY(name, TermType != 0 ? TermType : "", MAX_NAME_SIZE);
 }
 
 static NCURSES_INLINE void
@@ -151,3 +152,12 @@
     exit(EXIT_FAILURE);
 #endif
 }
+
+#if NO_LEAKS
+NCURSES_EXPORT(void)
+_nc_comp_error_leaks(void)
+{
+    FreeAndNull(SourceName);
+    FreeAndNull(TermType);
+}
+#endif
diff --git a/ncurses/tinfo/comp_expand.c b/ncurses/tinfo/comp_expand.c
index 6e79a92..2ab06eb 100644
--- a/ncurses/tinfo/comp_expand.c
+++ b/ncurses/tinfo/comp_expand.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,7 +35,7 @@
 #include <ctype.h>
 #include <tic.h>
 
-MODULE_ID("$Id: comp_expand.c,v 1.20 2008/08/16 19:29:42 tom Exp $")
+MODULE_ID("$Id: comp_expand.c,v 1.25 2012/03/24 18:37:17 tom Exp $")
 
 static int
 trailing_spaces(const char *src)
@@ -49,6 +49,8 @@
 #define REALCTL(s) (UChar(*(s)) < 127 && iscntrl(UChar(*(s))))
 #define REALPRINT(s) (UChar(*(s)) < 127 && isprint(UChar(*(s))))
 
+#define P_LIMIT(p) (length - (size_t)(p))
+
 NCURSES_EXPORT(char *)
 _nc_tic_expand(const char *srcp, bool tic_format, int numbers)
 {
@@ -61,15 +63,15 @@
     size_t need = (2 + strlen(str)) * 4;
     int ch;
 
-#if NO_LEAKS
     if (srcp == 0) {
+#if NO_LEAKS
 	if (buffer != 0) {
 	    FreeAndNull(buffer);
 	    length = 0;
 	}
+#endif
 	return 0;
     }
-#endif
     if (buffer == 0 || need > length) {
 	if ((buffer = typeRealloc(char, length = need, buffer)) == 0)
 	      return 0;
@@ -90,8 +92,9 @@
 		    && str[1] != '\\'
 		    && REALPRINT(str + 1)
 		    && str[2] == S_QUOTE) {
-		    sprintf(buffer + bufp, "{%d}", str[1]);
-		    bufp += strlen(buffer + bufp);
+		    _nc_SPRINTF(buffer + bufp, _nc_SLIMIT(P_LIMIT(bufp))
+				"{%d}", str[1]);
+		    bufp += (int) strlen(buffer + bufp);
 		    str += 2;
 		} else {
 		    buffer[bufp++] = *str;
@@ -177,10 +180,12 @@
 #define UnCtl(c) ((c) + '@')
 	else if (REALCTL(str) && ch != '\\'
 		 && (!islong || isdigit(UChar(str[1])))) {
-	    (void) sprintf(&buffer[bufp], "^%c", UnCtl(ch));
+	    _nc_SPRINTF(&buffer[bufp], _nc_SLIMIT(P_LIMIT(bufp))
+			"^%c", UnCtl(ch));
 	    bufp += 2;
 	} else {
-	    (void) sprintf(&buffer[bufp], "\\%03o", ch);
+	    _nc_SPRINTF(&buffer[bufp], _nc_SLIMIT(P_LIMIT(bufp))
+			"\\%03o", ch);
 	    bufp += 4;
 	}
 
diff --git a/ncurses/tinfo/comp_hash.c b/ncurses/tinfo/comp_hash.c
index b7fbd06..959c6e1 100644
--- a/ncurses/tinfo/comp_hash.c
+++ b/ncurses/tinfo/comp_hash.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -44,110 +44,36 @@
 #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 *);
+MODULE_ID("$Id: comp_hash.c,v 1.48 2009/08/08 17:36:21 tom Exp $")
 
 /*
- *	_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[].
- *
+ * 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.
  */
-
-#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
+/* entrypoint used by tack (do not alter) */
 NCURSES_EXPORT(struct name_table_entry const *)
 _nc_find_entry(const char *string,
-	       const short *hash_table)
+	       const HashValue * hash_table)
 {
+    bool termcap = (hash_table != _nc_get_hash_table(FALSE));
+    const HashData *data = _nc_get_hash_info(termcap);
     int hashvalue;
     struct name_table_entry const *ptr = 0;
     struct name_table_entry const *real_table;
 
-    hashvalue = hash_function(string);
+    hashvalue = data->hash_of(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]);
+    if (data->table_data[hashvalue] >= 0) {
+
+	real_table = _nc_get_table(termcap);
+	ptr = real_table + data->table_data[hashvalue];
+	while (!data->compare_names(ptr->nte_name, string)) {
+	    if (ptr->nte_link < 0) {
+		ptr = 0;
+		break;
+	    }
+	    ptr = real_table + (ptr->nte_link
+				+ data->table_data[data->table_size]);
 	}
     }
 
@@ -155,216 +81,34 @@
 }
 
 /*
- *	struct name_table_entry *
- *	find_type_entry(string, type, table)
+ * Finds the entry for the given name with the given type in the given table if
+ * present (as distinct from _nc_find_entry, which finds the last entry
+ * regardless of type).
  *
- *	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.
+ * 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)
+		    bool termcap)
 {
-    struct name_table_entry const *ptr;
+    struct name_table_entry const *ptr = NULL;
+    const HashData *data = _nc_get_hash_info(termcap);
+    int hashvalue = data->hash_of(string);
 
-    for (ptr = table; ptr < table + CAPTABSIZE; ptr++) {
-	if (ptr->nte_type == type && strcmp(string, ptr->nte_name) == 0)
-	    return (ptr);
-    }
+    if (data->table_data[hashvalue] >= 0) {
+	const struct name_table_entry *const table = _nc_get_table(termcap);
 
-    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
+	ptr = table + data->table_data[hashvalue];
+	while (ptr->nte_type != type
+	       || !data->compare_names(ptr->nte_name, string)) {
+	    if (ptr->nte_link < 0) {
+		ptr = 0;
 		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;
+	    ptr = table + (ptr->nte_link + data->table_data[data->table_size]);
 	}
-	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;
+    return ptr;
 }
-#endif
diff --git a/ncurses/tinfo/comp_parse.c b/ncurses/tinfo/comp_parse.c
index 3325a0d..82a61a5 100644
--- a/ncurses/tinfo/comp_parse.c
+++ b/ncurses/tinfo/comp_parse.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,15 +35,10 @@
 /*
  *	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>
@@ -51,9 +46,8 @@
 #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 $")
+MODULE_ID("$Id: comp_parse.c,v 1.90 2013/08/31 15:22:31 tom Exp $")
 
 static void sanity_check2(TERMTYPE *, bool);
 NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype2) (TERMTYPE *, bool) = sanity_check2;
@@ -62,6 +56,8 @@
 static void sanity_check(TERMTYPE *);
 NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype) (TERMTYPE *) = sanity_check;
 
+static void fixup_acsc(TERMTYPE *, int);
+
 static void
 enqueue(ENTRY * ep)
 /* add an entry to the in-core list */
@@ -87,31 +83,125 @@
 	if (len > MAX_NAME_SIZE)
 	    len = MAX_NAME_SIZE;
 	(void) strncpy(dst, src, len);
-	(void) strcpy(dst + len, "|");
+	_nc_STRCPY(dst + len, "|", MAX_NAME_SIZE);
 	src = dst;
     }
     return src;
 }
+#define ForceBar(dst, src) ((strchr(src, '|') == 0) ? force_bar(dst, src) : src)
 
-NCURSES_EXPORT(bool)
-_nc_entry_match(char *n1, char *n2)
-/* do any of the aliases in a pair of terminal names match? */
+#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
+static char *
+skip_index(char *name)
+{
+    char *bar = strchr(name, '|');
+
+    if (bar != 0 && (bar - name) == 2)
+	name = bar + 1;
+
+    return name;
+}
+#endif
+
+static bool
+check_collisions(char *n1, char *n2, int counter)
 {
     char *pstart, *qstart, *pend, *qend;
-    char nc1[MAX_NAME_SIZE + 2], nc2[MAX_NAME_SIZE + 2];
+    char nc1[MAX_NAME_SIZE + 2];
+    char nc2[MAX_NAME_SIZE + 2];
 
-    n1 = force_bar(nc1, n1);
-    n2 = force_bar(nc2, n2);
+    n1 = ForceBar(nc1, n1);
+    n2 = ForceBar(nc2, n2);
 
-    for (pstart = n1; (pend = strchr(pstart, '|')); pstart = pend + 1)
-	for (qstart = n2; (qend = strchr(qstart, '|')); qstart = qend + 1)
+#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
+    if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
+	n1 = skip_index(n1);
+	n2 = skip_index(n2);
+    }
+#endif
+
+    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)
+		&& memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0) {
+		if (counter > 0)
+		    (void) fprintf(stderr, "Name collision '%.*s' between\n",
+				   (int) (pend - pstart), pstart);
 		return (TRUE);
+	    }
+	}
+    }
 
     return (FALSE);
 }
 
+static char *
+next_name(char *name)
+{
+    if (*name != '\0')
+	++name;
+    return name;
+}
+
+static char *
+name_ending(char *name)
+{
+    if (*name == '\0') {
+	name = 0;
+    } else {
+	while (*name != '\0' && *name != '|')
+	    ++name;
+    }
+    return name;
+}
+
+/*
+ * Essentially, find the conflict reported in check_collisions() and remove
+ * it from the second name, unless that happens to be the last alias.
+ */
+static bool
+remove_collision(char *n1, char *n2)
+{
+    char *p2 = n2;
+    char *pstart, *qstart, *pend, *qend;
+    bool removed = FALSE;
+
+#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
+    if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
+	n1 = skip_index(n1);
+	p2 = n2 = skip_index(n2);
+    }
+#endif
+
+    for (pstart = n1; (pend = name_ending(pstart)); pstart = next_name(pend)) {
+	for (qstart = n2; (qend = name_ending(qstart)); qstart = next_name(qend)) {
+	    if ((pend - pstart == qend - qstart)
+		&& memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0) {
+		if (qstart != p2 || *qend == '|') {
+		    if (*qend == '|')
+			++qend;
+		    while ((*qstart++ = *qend++) != '\0') ;
+		    fprintf(stderr, "...now\t%s\n", p2);
+		} else {
+		    fprintf(stderr, "Cannot remove alias '%.*s'\n",
+			    (int) (qend - qstart), qstart);
+		}
+		removed = TRUE;
+		break;
+	    }
+	}
+    }
+
+    return removed;
+}
+
+/* do any of the aliases in a pair of terminal names match? */
+NCURSES_EXPORT(bool)
+_nc_entry_match(char *n1, char *n2)
+{
+    return check_collisions(n1, n2, 0);
+}
+
 /****************************************************************************
  *
  * Entry compiler and resolution logic
@@ -197,19 +287,19 @@
 
 	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++;
+		&& check_collisions(qp->tterm.term_names,
+				    rp->tterm.term_names,
+				    matchcount + 1)) {
+		if (!matchcount++) {
+		    (void) fprintf(stderr, "\t%s\n", rp->tterm.term_names);
 		}
-		if (matchcount >= 1)
-		    (void) fprintf(stderr, " %s", _nc_first_name(rp->tterm.term_names));
+		(void) fprintf(stderr, "and\t%s\n", qp->tterm.term_names);
+		if (!remove_collision(rp->tterm.term_names,
+				      qp->tterm.term_names)) {
+		    ++multiples;
+		}
 	    }
 	}
-	if (matchcount >= 1)
-	    (void) putc('\n', stderr);
     }
     if (multiples > 0)
 	return (FALSE);
@@ -255,9 +345,7 @@
 		    DEBUG(2, ("%s: resolving use=%s (compiled)",
 			      child, lookfor));
 
-		    rp = typeMalloc(ENTRY, 1);
-		    if (rp == 0)
-			_nc_err_abort(MSG_NO_MEMORY);
+		    TYPE_MALLOC(ENTRY, 1, rp);
 		    rp->tterm = thisterm;
 		    rp->nuses = 0;
 		    rp->next = lastread;
@@ -273,7 +361,7 @@
 		unresolved++;
 		total_unresolved++;
 
-		_nc_curr_line = lookline;
+		_nc_curr_line = (int) lookline;
 		_nc_warning("resolution of use=%s failed", lookfor);
 		qp->uses[i].link = 0;
 	    }
@@ -375,9 +463,36 @@
 	if (_nc_check_termtype != 0) {
 	    _nc_curr_col = -1;
 	    for_entry_list(qp) {
-		_nc_curr_line = qp->startline;
+		_nc_curr_line = (int) qp->startline;
 		_nc_set_type(_nc_first_name(qp->tterm.term_names));
-		_nc_check_termtype2(&qp->tterm, literal);
+		/*
+		 * tic overrides this function pointer to provide more verbose
+		 * checking.
+		 */
+		if (_nc_check_termtype2 != sanity_check2) {
+		    SCREEN *save_SP = SP;
+		    SCREEN fake_sp;
+		    TERMINAL fake_tm;
+		    TERMINAL *save_tm = cur_term;
+
+		    /*
+		     * Setup so that tic can use ordinary terminfo interface
+		     * to obtain capability information.
+		     */
+		    memset(&fake_sp, 0, sizeof(fake_sp));
+		    memset(&fake_tm, 0, sizeof(fake_tm));
+		    fake_sp._term = &fake_tm;
+		    fake_tm.type = qp->tterm;
+		    _nc_set_screen(&fake_sp);
+		    set_curterm(&fake_tm);
+
+		    _nc_check_termtype2(&qp->tterm, literal);
+
+		    _nc_set_screen(save_SP);
+		    set_curterm(save_tm);
+		} else {
+		    fixup_acsc(&qp->tterm, literal);
+		}
 	    }
 	    DEBUG(2, ("SANITY CHECK FINISHED"));
 	}
@@ -402,6 +517,17 @@
 #define CUR tp->
 
 static void
+fixup_acsc(TERMTYPE *tp, int literal)
+{
+    if (!literal) {
+	if (acs_chars == 0
+	    && enter_alt_charset_mode != 0
+	    && exit_alt_charset_mode != 0)
+	    acs_chars = strdup(VT_ACSC);
+    }
+}
+
+static void
 sanity_check2(TERMTYPE *tp, bool literal)
 {
     if (!PRESENT(exit_attribute_mode)) {
@@ -421,16 +547,14 @@
 #endif /* __UNUSED__ */
 	PAIRED(enter_standout_mode, exit_standout_mode);
 	PAIRED(enter_underline_mode, exit_underline_mode);
+	PAIRED(enter_italics_mode, exit_italics_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);
+	fixup_acsc(tp, literal);
 	ANDMISSING(enter_alt_charset_mode, acs_chars);
 	ANDMISSING(exit_alt_charset_mode, acs_chars);
     }
@@ -473,7 +597,6 @@
 {
     _nc_alloc_entry_leaks();
     _nc_captoinfo_leaks();
-    _nc_comp_captab_leaks();
     _nc_comp_scan_leaks();
 #if BROKEN_LINKER || USE_REENTRANT
     _nc_names_leaks();
diff --git a/ncurses/tinfo/comp_scan.c b/ncurses/tinfo/comp_scan.c
index 5ad750f..fe6e8e7 100644
--- a/ncurses/tinfo/comp_scan.c
+++ b/ncurses/tinfo/comp_scan.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -48,10 +48,9 @@
 #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 $")
+MODULE_ID("$Id: comp_scan.c,v 1.102 2013/11/16 19:57:50 tom Exp $")
 
 /*
  * Maximum length of string capability we'll accept before raising an error.
@@ -61,19 +60,14 @@
 
 #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 (int) _nc_syntax = 0;         /* termcap or terminfo? */
+NCURSES_EXPORT_VAR (int) _nc_strict_bsd = 1;  /* ncurses extended termcap? */
+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 =
+NCURSES_EXPORT_VAR (struct token) _nc_curr_token =
 {
     0, 0, 0
 };
@@ -91,8 +85,7 @@
 static char *pushname;
 
 #if NCURSES_EXT_FUNCS
-NCURSES_EXPORT_VAR(bool)
-_nc_disable_period = FALSE;	/* used by tic -a option */
+NCURSES_EXPORT_VAR (bool) _nc_disable_period = FALSE; /* used by tic -a option */
 #endif
 
 /*****************************************************************************
@@ -135,14 +128,19 @@
  *	Returns the final nonblank character on the current input buffer
  */
 static int
-last_char(void)
+last_char(int from_end)
 {
     size_t len = strlen(bufptr);
+    int result = 0;
+
     while (len--) {
-	if (!isspace(UChar(bufptr[len])))
-	    return bufptr[len];
+	if (!isspace(UChar(bufptr[len]))) {
+	    if (from_end < (int) len)
+		result = bufptr[(int) len - from_end];
+	    break;
+	}
     }
-    return 0;
+    return result;
 }
 
 /*
@@ -203,7 +201,8 @@
 		    result = typeRealloc(char, allocated, result);
 		    if (result == 0)
 			return (EOF);
-		    bufstart = result;
+		    if (bufstart)
+			bufstart = result;
 		}
 		if (used == 0)
 		    _nc_curr_file_pos = ftell(yyin);
@@ -211,12 +210,16 @@
 		if (fgets(result + used, (int) (allocated - used), yyin) != 0) {
 		    bufstart = result;
 		    if (used == 0) {
+			if (_nc_curr_line == 0
+			    && IS_TIC_MAGIC(result)) {
+			    _nc_err_abort("This is a compiled terminal description, not a source");
+			}
 			_nc_curr_line++;
 			_nc_curr_col = 0;
 		    }
 		} else {
 		    if (used != 0)
-			strcat(result, "\n");
+			_nc_STRCAT(result, "\n", allocated);
 		}
 		if ((bufptr = bufstart) != 0) {
 		    used = strlen(bufptr);
@@ -260,12 +263,12 @@
 }
 
 static void
-push_back(char c)
+push_back(int c)
 /* push a character back onto the input stream */
 {
     if (bufptr == bufstart)
 	_nc_syserr_abort("Can't backspace off beginning of line");
-    *--bufptr = c;
+    *--bufptr = (char) c;
     _nc_curr_col--;
 }
 
@@ -303,6 +306,8 @@
 	*tok_ptr++ = (char) ch; \
 	*tok_ptr = '\0'
 
+static char *tok_buf;
+
 /*
  *	int
  *	get_token()
@@ -340,15 +345,14 @@
 _nc_get_token(bool silent)
 {
     static const char terminfo_punct[] = "@%&*!#";
-    static char *tok_buf;
 
-    char *after_list;
-    char *after_name;
+    char *after_name;		/* after primary name */
+    char *after_list;		/* after primary and alias list */
     char *numchk;
     char *tok_ptr;
     char *s;
     char numbuf[80];
-    int ch;
+    int ch, c0, c1;
     int dot_flag = FALSE;
     int type;
     long number;
@@ -376,11 +380,10 @@
 
     if (end_of_stream()) {
 	yyin = 0;
-	next_char();		/* frees its allocated memory */
+	(void) 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);
     }
@@ -394,6 +397,7 @@
     }
 
     ch = eat_escaped_newline(ch);
+    _nc_curr_token.tk_valstring = 0;
 
 #ifdef TRACE
     old_line = _nc_curr_line;
@@ -428,10 +432,10 @@
 #if NCURSES_EXT_FUNCS
 	    && !(ch == '.' && _nc_disable_period)
 #endif
-	    && !strchr(terminfo_punct, (char) ch)) {
+	    && ((strchr) (terminfo_punct, (char) ch) == 0)) {
 	    if (!silent)
 		_nc_warning("Illegal character (expected alphanumeric or %s) - '%s'",
-			    terminfo_punct, unctrl((chtype) ch));
+			    terminfo_punct, unctrl(UChar(ch)));
 	    _nc_panic_mode(separator);
 	    goto start_token;
 	}
@@ -461,7 +465,7 @@
 		    after_list = tok_ptr;
 		    if (after_name == 0)
 			after_name = tok_ptr;
-		} else if (ch == ':' && last_char() != ',') {
+		} else if (ch == ':' && last_char(0) != ',') {
 		    _nc_syntax = SYN_TERMCAP;
 		    separator = ':';
 		    break;
@@ -475,19 +479,70 @@
 		    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.
+		     * We saw a comma, but are not entirely sure this is
+		     * terminfo format, since we can still be parsing the
+		     * description field (for either syntax).
+		     *
+		     * A properly formatted termcap line ends with either a
+		     * colon, or a backslash after a colon.  It is possible
+		     * to have a backslash in the middle of a capability, but
+		     * then there would be no leading whitespace on the next
+		     * line - something we want to discourage.
 		     */
+		    c0 = last_char(0);
+		    c1 = last_char(1);
+		    if (c1 != ':' && c0 != '\\' && c0 != ':') {
+			bool capability = FALSE;
+
+			/*
+			 * Since it is not termcap, assume the line is terminfo
+			 * format.  However, the comma can be embedded in a
+			 * description field.  It also can be a separator
+			 * between a description field and a capability.
+			 *
+			 * Improve the guess by checking if the next word after
+			 * the comma does not look like a capability.  In that
+			 * case, extend the description past the comma.
+			 */
+			for (s = bufptr; isspace(UChar(*s)); ++s) {
+			    ;
+			}
+			if (islower(UChar(*s))) {
+			    char *name = s;
+			    while (isalnum(UChar(*s))) {
+				++s;
+			    }
+			    if (*s == '#' || *s == '=' || *s == '@') {
+				/*
+				 * Checking solely with syntax allows us to
+				 * support extended capabilities with string
+				 * values.
+				 */
+				capability = TRUE;
+			    } else if (*s == ',') {
+				c0 = *s;
+				*s = '\0';
+				/*
+				 * Otherwise, we can handle predefined boolean
+				 * capabilities, still aided by syntax.
+				 */
+				if (_nc_find_entry(name,
+						   _nc_get_hash_table(FALSE))) {
+				    capability = TRUE;
+				}
+				*s = (char) c0;
+			    }
+			}
+			if (capability) {
+			    break;
+			}
+		    }
 		} else
 		    ch = eat_escaped_newline(ch);
 
 		if (OkToAdd()) {
 		    AddCh(ch);
 		} else {
-		    ch = EOF;
 		    break;
 		}
 	    }
@@ -596,7 +651,7 @@
 	    case '@':
 		if ((ch = next_char()) != separator && !silent)
 		    _nc_warning("Missing separator after `%s', have %s",
-				tok_buf, unctrl((chtype) ch));
+				tok_buf, unctrl(UChar(ch)));
 		_nc_curr_token.tk_name = tok_buf;
 		type = CANCEL;
 		break;
@@ -617,7 +672,7 @@
 			_nc_warning("Missing separator");
 		}
 		_nc_curr_token.tk_name = tok_buf;
-		_nc_curr_token.tk_valnumber = number;
+		_nc_curr_token.tk_valnumber = (int) number;
 		type = NUMBER;
 		break;
 
@@ -637,7 +692,7 @@
 		/* just to get rid of the compiler warning */
 		type = UNDEF;
 		if (!silent)
-		    _nc_warning("Illegal character - '%s'", unctrl((chtype) ch));
+		    _nc_warning("Illegal character - '%s'", unctrl(UChar(ch)));
 	    }
 	}			/* end else (first_column == FALSE) */
     }				/* end else (ch != EOF) */
@@ -730,57 +785,62 @@
     int count = 0;
     int number = 0;
     int i, c;
-    chtype ch, last_ch = '\0';
+    int last_ch = '\0';
     bool ignored = FALSE;
     bool long_warning = FALSE;
 
-    while ((ch = c = next_char()) != (chtype) separator && c != EOF) {
+    while ((c = next_char()) != 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 == '^' && last_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 (!(is7bits(c) && isprint(c))) {
+		_nc_warning("Illegal ^ character - '%s'", unctrl(UChar(c)));
 	    }
-	    if (ch == '?') {
+	    if (c == '?' && (_nc_syntax != SYN_TERMCAP)) {
 		*(ptr++) = '\177';
 		if (_nc_tracing)
 		    _nc_warning("Allow ^? as synonym for \\177");
 	    } else {
-		if ((ch &= 037) == 0)
-		    ch = 128;
-		*(ptr++) = (char) (ch);
+		if ((c &= 037) == 0)
+		    c = 128;
+		*(ptr++) = (char) (c);
 	    }
-	} else if (ch == '\\') {
-	    ch = c = next_char();
+	} else if (c == '\\') {
+	    bool strict_bsd = ((_nc_syntax == SYN_TERMCAP) && _nc_strict_bsd);
+
+	    c = next_char();
 	    if (c == EOF)
 		_nc_err_abort(MSG_NO_INPUTS);
 
-	    if (ch >= '0' && ch <= '7') {
-		number = ch - '0';
+#define isoctal(c) ((c) >= '0' && (c) <= '7')
+
+	    if (isoctal(c) || (strict_bsd && isdigit(c))) {
+		number = c - '0';
 		for (i = 0; i < 2; i++) {
-		    ch = c = next_char();
+		    c = next_char();
 		    if (c == EOF)
 			_nc_err_abort(MSG_NO_INPUTS);
 
-		    if (c < '0' || c > '7') {
+		    if (!isoctal(c)) {
 			if (isdigit(c)) {
-			    _nc_warning("Non-octal digit `%c' in \\ sequence", c);
-			    /* allow the digit; it'll do less harm */
+			    if (!strict_bsd) {
+				_nc_warning("Non-octal digit `%c' in \\ sequence", c);
+				/* allow the digit; it'll do less harm */
+			    }
 			} else {
-			    push_back((char) c);
+			    push_back(c);
 			    break;
 			}
 		    }
@@ -788,21 +848,16 @@
 		    number = number * 8 + c - '0';
 		}
 
-		if (number == 0)
+		number = UChar(number);
+		if (number == 0 && !strict_bsd)
 		    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;
@@ -815,10 +870,6 @@
 		    *(ptr++) = '\010';
 		    break;
 
-		case 's':
-		    *(ptr++) = ' ';
-		    break;
-
 		case 'f':
 		    *(ptr++) = '\014';
 		    break;
@@ -839,40 +890,57 @@
 		    *(ptr++) = ',';
 		    break;
 
-		case ':':
-		    *(ptr++) = ':';
-		    break;
-
 		case '\n':
 		    continue;
 
 		default:
-		    _nc_warning("Illegal character '%s' in \\ sequence",
-				unctrl(ch));
+		    if ((_nc_syntax == SYN_TERMINFO) || !_nc_strict_bsd) {
+			switch (c) {
+			case 'a':
+			    c = '\007';
+			    break;
+			case 'e':
+			    c = '\033';
+			    break;
+			case 'l':
+			    c = '\n';
+			    break;
+			case 's':
+			    c = ' ';
+			    break;
+			case ':':
+			    c = ':';
+			    break;
+			default:
+			    _nc_warning("Illegal character '%s' in \\ sequence",
+					unctrl(UChar(c)));
+			    break;
+			}
+		    }
 		    /* FALLTHRU */
 		case '|':
-		    *(ptr++) = (char) ch;
-		}		/* endswitch (ch) */
-	    }			/* endelse (ch < '0' ||  ch > '7') */
+		    *(ptr++) = (char) c;
+		}		/* endswitch (c) */
+	    }			/* endelse (c < '0' ||  c > '7') */
 	}
-	/* end else if (ch == '\\') */
-	else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) {
+	/* end else if (c == '\\') */
+	else if (c == '\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;
+	    *(ptr++) = (char) c;
 	}
 
 	if (!ignored) {
 	    if (_nc_curr_col <= 1) {
-		push_back((char) ch);
-		ch = '\n';
+		push_back(c);
+		c = '\n';
 		break;
 	    }
-	    last_ch = ch;
+	    last_ch = c;
 	    count++;
 	}
 	ignored = FALSE;
@@ -885,7 +953,7 @@
 
     *ptr = '\0';
 
-    return (ch);
+    return (c);
 }
 
 /*
@@ -940,5 +1008,8 @@
     if (pushname != 0) {
 	FreeAndNull(pushname);
     }
+    if (tok_buf != 0) {
+	FreeAndNull(tok_buf);
+    }
 }
 #endif
diff --git a/ncurses/tinfo/db_iterator.c b/ncurses/tinfo/db_iterator.c
index fdc2bb0..94a4082 100644
--- a/ncurses/tinfo/db_iterator.c
+++ b/ncurses/tinfo/db_iterator.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2006,2007 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2006-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -36,13 +36,142 @@
 
 #include <curses.priv.h>
 
+#include <time.h>
 #include <tic.h>
 
-MODULE_ID("$Id: db_iterator.c,v 1.6 2007/04/22 00:00:26 tom Exp $")
+#if USE_HASHED_DB
+#include <hashed_db.h>
+#endif
+
+MODULE_ID("$Id: db_iterator.c,v 1.39 2014/11/01 14:47:00 tom Exp $")
 
 #define HaveTicDirectory _nc_globals.have_tic_directory
 #define KeepTicDirectory _nc_globals.keep_tic_directory
 #define TicDirectory     _nc_globals.tic_directory
+#define my_blob          _nc_globals.dbd_blob
+#define my_list          _nc_globals.dbd_list
+#define my_size          _nc_globals.dbd_size
+#define my_time          _nc_globals.dbd_time
+#define my_vars          _nc_globals.dbd_vars
+
+static void
+add_to_blob(const char *text, size_t limit)
+{
+    (void) limit;
+
+    if (*text != '\0') {
+	char *last = my_blob + strlen(my_blob);
+	if (last != my_blob)
+	    *last++ = NCURSES_PATHSEP;
+	_nc_STRCPY(last, text, limit);
+    }
+}
+
+static bool
+check_existence(const char *name, struct stat *sb)
+{
+    bool result = FALSE;
+
+    if (stat(name, sb) == 0
+	&& (S_ISDIR(sb->st_mode) || S_ISREG(sb->st_mode))) {
+	result = TRUE;
+    }
+#if USE_HASHED_DB
+    else if (strlen(name) < PATH_MAX - sizeof(DBM_SUFFIX)) {
+	char temp[PATH_MAX];
+	_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "%s%s", name, DBM_SUFFIX);
+	if (stat(temp, sb) == 0 && S_ISREG(sb->st_mode)) {
+	    result = TRUE;
+	}
+    }
+#endif
+    return result;
+}
+
+/*
+ * Store the latest value of an environment variable in my_vars[] so we can
+ * detect if one changes, invalidating the cached search-list.
+ */
+static bool
+update_getenv(const char *name, DBDIRS which)
+{
+    bool result = FALSE;
+
+    if (which < dbdLAST) {
+	char *value;
+
+	if ((value = getenv(name)) == 0 || (value = strdup(value)) == 0) {
+	    ;
+	} else if (my_vars[which].name == 0 || strcmp(my_vars[which].name, name)) {
+	    FreeIfNeeded(my_vars[which].value);
+	    my_vars[which].name = name;
+	    my_vars[which].value = value;
+	    result = TRUE;
+	} else if ((my_vars[which].value != 0) ^ (value != 0)) {
+	    FreeIfNeeded(my_vars[which].value);
+	    my_vars[which].value = value;
+	    result = TRUE;
+	} else if (value != 0 && strcmp(value, my_vars[which].value)) {
+	    FreeIfNeeded(my_vars[which].value);
+	    my_vars[which].value = value;
+	    result = TRUE;
+	} else {
+	    free(value);
+	}
+    }
+    return result;
+}
+
+static char *
+cache_getenv(const char *name, DBDIRS which)
+{
+    char *result = 0;
+
+    (void) update_getenv(name, which);
+    if (which < dbdLAST) {
+	result = my_vars[which].value;
+    }
+    return result;
+}
+
+/*
+ * The cache expires if at least a second has passed since the initial lookup,
+ * or if one of the environment variables changed.
+ *
+ * Only a few applications use multiple lookups of terminal entries, seems that
+ * aside from bulk I/O such as tic and toe, that leaves interactive programs
+ * which should not be modifying the terminal databases in a way that would
+ * invalidate the search-list.
+ *
+ * The "1-second" is to allow for user-directed changes outside the program.
+ */
+static bool
+cache_expired(void)
+{
+    bool result = FALSE;
+    time_t now = time((time_t *) 0);
+
+    if (now > my_time) {
+	result = TRUE;
+    } else {
+	DBDIRS n;
+	for (n = (DBDIRS) 0; n < dbdLAST; ++n) {
+	    if (my_vars[n].name != 0
+		&& update_getenv(my_vars[n].name, n)) {
+		result = TRUE;
+		break;
+	    }
+	}
+    }
+    return result;
+}
+
+static void
+free_cache(void)
+{
+    FreeAndNull(my_blob);
+    FreeAndNull(my_list);
+}
 
 /*
  * Record the "official" location of the terminfo directory, according to
@@ -51,17 +180,20 @@
 NCURSES_EXPORT(const char *)
 _nc_tic_dir(const char *path)
 {
+    T(("_nc_tic_dir %s", NonNull(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);
+	} else if (HaveTicDirectory == 0) {
+	    if (use_terminfo_vars()) {
+		const char *envp;
+		if ((envp = getenv("TERMINFO")) != 0)
+		    return _nc_tic_dir(envp);
+	    }
 	}
     }
-    return TicDirectory;
+    return TicDirectory ? TicDirectory : TERMINFO;
 }
 
 /*
@@ -77,62 +209,16 @@
 }
 
 /*
- * 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);
+    if (my_blob != 0 && cache_expired()) {
+	free_cache();
     }
-    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
@@ -142,84 +228,186 @@
 _nc_next_db(DBDIRS * state, int *offset)
 {
     const char *result;
-    char *envp;
 
-    while (*state < dbdLAST) {
-	DBDIRS next = (DBDIRS) ((int) (*state) + 1);
-
+    (void) offset;
+    if ((int) *state < my_size
+	&& my_list != 0
+	&& my_list[*state] != 0) {
+	result = my_list[*state];
+	(*state)++;
+    } else {
 	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;
+    if (result != 0) {
+	T(("_nc_next_db %d %s", *state, result));
+    }
+    return result;
 }
 
 NCURSES_EXPORT(void)
 _nc_first_db(DBDIRS * state, int *offset)
 {
+    bool cache_has_expired = FALSE;
     *state = dbdTIC;
     *offset = 0;
+
+    T(("_nc_first_db"));
+
+    /* build a blob containing all of the strings we will use for a lookup
+     * table.
+     */
+    if (my_blob == 0 || (cache_has_expired = cache_expired())) {
+	size_t blobsize = 0;
+	const char *values[dbdLAST];
+	struct stat *my_stat;
+	int j, k;
+
+	if (cache_has_expired)
+	    free_cache();
+
+	for (j = 0; j < dbdLAST; ++j)
+	    values[j] = 0;
+
+	/*
+	 * This is the first item in the list, and is used only when tic is
+	 * writing to the database, as a performance improvement.
+	 */
+	values[dbdTIC] = TicDirectory;
+
+#if NCURSES_USE_DATABASE
+#ifdef TERMINFO_DIRS
+	values[dbdCfgList] = TERMINFO_DIRS;
+#endif
+#ifdef TERMINFO
+	values[dbdCfgOnce] = TERMINFO;
+#endif
+#endif
+
+#if NCURSES_USE_TERMCAP
+	values[dbdCfgList2] = TERMPATH;
+#endif
+
+	if (use_terminfo_vars()) {
+#if NCURSES_USE_DATABASE
+	    values[dbdEnvOnce] = cache_getenv("TERMINFO", dbdEnvOnce);
+	    values[dbdHome] = _nc_home_terminfo();
+	    (void) cache_getenv("HOME", dbdHome);
+	    values[dbdEnvList] = cache_getenv("TERMINFO_DIRS", dbdEnvList);
+
+#endif
+#if NCURSES_USE_TERMCAP
+	    values[dbdEnvOnce2] = cache_getenv("TERMCAP", dbdEnvOnce2);
+	    /* only use $TERMCAP if it is an absolute path */
+	    if (values[dbdEnvOnce2] != 0
+		&& *values[dbdEnvOnce2] != '/') {
+		values[dbdEnvOnce2] = 0;
+	    }
+	    values[dbdEnvList2] = cache_getenv("TERMPATH", dbdEnvList2);
+#endif /* NCURSES_USE_TERMCAP */
+	}
+
+	for (j = 0; j < dbdLAST; ++j) {
+	    if (values[j] == 0)
+		values[j] = "";
+	    blobsize += 2 + strlen(values[j]);
+	}
+
+	my_blob = malloc(blobsize);
+	if (my_blob != 0) {
+	    *my_blob = '\0';
+	    for (j = 0; j < dbdLAST; ++j) {
+		add_to_blob(values[j], blobsize);
+	    }
+
+	    /* Now, build an array which will be pointers to the distinct
+	     * strings in the blob.
+	     */
+	    blobsize = 2;
+	    for (j = 0; my_blob[j] != '\0'; ++j) {
+		if (my_blob[j] == NCURSES_PATHSEP)
+		    ++blobsize;
+	    }
+	    my_list = typeCalloc(char *, blobsize);
+	    my_stat = typeCalloc(struct stat, blobsize);
+	    if (my_list != 0 && my_stat != 0) {
+		k = 0;
+		my_list[k++] = my_blob;
+		for (j = 0; my_blob[j] != '\0'; ++j) {
+		    if (my_blob[j] == NCURSES_PATHSEP) {
+			my_blob[j] = '\0';
+			my_list[k++] = &my_blob[j + 1];
+		    }
+		}
+
+		/*
+		 * Eliminate duplicates from the list.
+		 */
+		for (j = 0; my_list[j] != 0; ++j) {
+#ifdef TERMINFO
+		    if (*my_list[j] == '\0')
+			my_list[j] = strdup(TERMINFO);
+#endif
+		    for (k = 0; k < j; ++k) {
+			if (!strcmp(my_list[j], my_list[k])) {
+			    k = j - 1;
+			    while ((my_list[j] = my_list[j + 1]) != 0) {
+				++j;
+			    }
+			    j = k;
+			    break;
+			}
+		    }
+		}
+
+		/*
+		 * Eliminate non-existent databases, and those that happen to
+		 * be symlinked to another location.
+		 */
+		for (j = 0; my_list[j] != 0; ++j) {
+		    bool found = check_existence(my_list[j], &my_stat[j]);
+#if HAVE_LINK
+		    if (found) {
+			for (k = 0; k < j; ++k) {
+			    if (my_stat[j].st_dev == my_stat[k].st_dev
+				&& my_stat[j].st_ino == my_stat[k].st_ino) {
+				found = FALSE;
+				break;
+			    }
+			}
+		    }
+#endif
+		    if (!found) {
+			k = j;
+			while ((my_list[k] = my_list[k + 1]) != 0) {
+			    ++k;
+			}
+			--j;
+		    }
+		}
+		my_size = j;
+		my_time = time((time_t *) 0);
+	    } else {
+		FreeAndNull(my_blob);
+	    }
+	    free(my_stat);
+	}
+    }
 }
+
+#if NO_LEAKS
+void
+_nc_db_iterator_leaks(void)
+{
+    DBDIRS which;
+
+    if (my_blob != 0)
+	FreeAndNull(my_blob);
+    if (my_list != 0)
+	FreeAndNull(my_list);
+    for (which = 0; (int) which < dbdLAST; ++which) {
+	my_vars[which].name = 0;
+	FreeIfNeeded(my_vars[which].value);
+	my_vars[which].value = 0;
+    }
+}
+#endif
diff --git a/ncurses/tinfo/doalloc.c b/ncurses/tinfo/doalloc.c
index fe2a009..7c502b0 100644
--- a/ncurses/tinfo/doalloc.c
+++ b/ncurses/tinfo/doalloc.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2000,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: doalloc.c,v 1.8 2002/08/31 21:48:11 Philippe.Blain Exp $")
+MODULE_ID("$Id: doalloc.c,v 1.11 2012/11/03 19:27:41 tom Exp $")
 
 NCURSES_EXPORT(void *)
 _nc_doalloc(void *oldp, size_t amount)
@@ -56,20 +56,3 @@
     }
     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
index cf2a833..e84033d 100644
--- a/ncurses/tinfo/entries.c
+++ b/ncurses/tinfo/entries.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2006-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2006-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -28,6 +28,7 @@
 
 /****************************************************************************
  *  Author: Thomas E. Dickey                                                *
+ *     and: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
@@ -35,9 +36,8 @@
 #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 $")
+MODULE_ID("$Id: entries.c,v 1.21 2012/05/05 20:33:44 tom Exp $")
 
 /****************************************************************************
  *
@@ -96,6 +96,9 @@
 	    if (last != 0) {
 		last->next = ep->next;
 	    }
+	    if (ep->next != 0) {
+		ep->next->last = last;
+	    }
 	    if (ep == _nc_head) {
 		_nc_head = ep->next;
 	    }
@@ -119,18 +122,32 @@
 #if NO_LEAKS
     _nc_free_tparm();
     _nc_tgetent_leaks();
+
+    if (TerminalOf(CURRENT_SCREEN) != 0) {
+	del_curterm(TerminalOf(CURRENT_SCREEN));
+    }
+
+    _nc_comp_captab_leaks();
     _nc_free_entries(_nc_head);
     _nc_get_type(0);
     _nc_first_name(0);
+    _nc_db_iterator_leaks();
     _nc_keyname_leaks();
 #if BROKEN_LINKER || USE_REENTRANT
     _nc_names_leaks();
     _nc_codes_leaks();
     FreeIfNeeded(_nc_prescreen.real_acs_map);
 #endif
+    _nc_comp_error_leaks();
 
     if ((s = _nc_home_terminfo()) != 0)
 	free(s);
+
+#ifdef TRACE
+    trace(0);
+    _nc_trace_buf(-1, (size_t) 0);
+#endif
+
 #endif /* NO_LEAKS */
     returnVoid;
 }
diff --git a/ncurses/tinfo/free_ttype.c b/ncurses/tinfo/free_ttype.c
index fa0fff1..ad056ba 100644
--- a/ncurses/tinfo/free_ttype.c
+++ b/ncurses/tinfo/free_ttype.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1999-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,9 +41,8 @@
 #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 $")
+MODULE_ID("$Id: free_ttype.c,v 1.15 2011/02/06 01:08:31 tom Exp $")
 
 NCURSES_EXPORT(void)
 _nc_free_termtype(TERMTYPE *ptr)
@@ -70,6 +69,7 @@
 {
     int oldflag = _nc_user_definable;
 
+    START_TRACE();
     T((T_CALLED("use_extended_names(%d)"), flag));
     _nc_user_definable = flag;
     returnBool(oldflag);
diff --git a/ncurses/tinfo/getenv_num.c b/ncurses/tinfo/getenv_num.c
index a90cc08..d5e35cb 100644
--- a/ncurses/tinfo/getenv_num.c
+++ b/ncurses/tinfo/getenv_num.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -36,7 +36,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: getenv_num.c,v 1.3 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: getenv_num.c,v 1.6 2013/09/28 20:25:08 tom Exp $")
 
 NCURSES_EXPORT(int)
 _nc_getenv_num(const char *name)
@@ -54,3 +54,20 @@
 
     return (int) value;
 }
+
+NCURSES_EXPORT(void)
+_nc_setenv_num(const char *name, int value)
+{
+    if (name != 0 && value >= 0) {
+	char buffer[128];
+#if HAVE_SETENV
+	_nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "%d", value);
+	setenv(name, buffer, 1);
+#elif HAVE_PUTENV
+	char *s;
+	_nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "%s=%d", name, value);
+	if ((s = strdup(buffer)) != 0)
+	    putenv(s);
+#endif
+    }
+}
diff --git a/ncurses/tinfo/hashed_db.c b/ncurses/tinfo/hashed_db.c
index 3fc04ea..b594205 100644
--- a/ncurses/tinfo/hashed_db.c
+++ b/ncurses/tinfo/hashed_db.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2006 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2006-2011,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey                        2006                    *
+ *  Author: Thomas E. Dickey                        2006-on                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
@@ -36,12 +36,81 @@
 
 #if USE_HASHED_DB
 
-MODULE_ID("$Id: hashed_db.c,v 1.13 2006/08/19 19:48:38 tom Exp $")
+MODULE_ID("$Id: hashed_db.c,v 1.17 2013/12/15 00:33:01 tom Exp $")
 
 #if HASHED_DB_API >= 2
 static DBC *cursor;
 #endif
 
+typedef struct _myconn {
+    struct _myconn *next;
+    DB *db;
+    char *path;
+    bool modify;
+} MYCONN;
+
+static MYCONN *connections;
+
+static void
+cleanup(void)
+{
+    while (connections != 0) {
+	_nc_db_close(connections->db);
+    }
+}
+
+static DB *
+find_connection(const char *path, bool modify)
+{
+    DB *result = 0;
+    MYCONN *p;
+
+    for (p = connections; p != 0; p = p->next) {
+	if (!strcmp(p->path, path) && p->modify == modify) {
+	    result = p->db;
+	    break;
+	}
+    }
+
+    return result;
+}
+
+static void
+drop_connection(DB * db)
+{
+    MYCONN *p, *q;
+
+    for (p = connections, q = 0; p != 0; q = p, p = p->next) {
+	if (p->db == db) {
+	    if (q != 0)
+		q->next = p->next;
+	    else
+		connections = p->next;
+	    free(p->path);
+	    free(p);
+	    break;
+	}
+    }
+}
+
+static void
+make_connection(DB * db, const char *path, bool modify)
+{
+    MYCONN *p = typeCalloc(MYCONN, 1);
+
+    if (p != 0) {
+	p->db = db;
+	p->path = strdup(path);
+	p->modify = modify;
+	if (p->path != 0) {
+	    p->next = connections;
+	    connections = p;
+	} else {
+	    free(p);
+	}
+    }
+}
+
 /*
  * Open the database.
  */
@@ -49,49 +118,60 @@
 _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));
-    }
+    if (connections == 0)
+	atexit(cleanup);
+
+    if ((result = find_connection(path, modify)) == 0) {
+
+#if HASHED_DB_API >= 4
+	db_create(&result, NULL, 0);
+	if ((code = result->open(result,
+				 NULL,
+				 path,
+				 NULL,
+				 DB_HASH,
+				 modify ? DB_CREATE : DB_RDONLY,
+				 0644)) != 0) {
+	    result = 0;
+	}
+#elif HASHED_DB_API >= 3
+	db_create(&result, NULL, 0);
+	if ((code = result->open(result,
+				 path,
+				 NULL,
+				 DB_HASH,
+				 modify ? DB_CREATE : DB_RDONLY,
+				 0644)) != 0) {
+	    result = 0;
+	}
+#elif HASHED_DB_API >= 2
+	if ((code = db_open(path,
+			    DB_HASH,
+			    modify ? DB_CREATE : DB_RDONLY,
+			    0644,
+			    (DB_ENV *) 0,
+			    (DB_INFO *) 0,
+			    &result)) != 0) {
+	    result = 0;
+	}
 #else
-    result = dbopen(path,
-		    modify ? (O_CREAT | O_RDWR) : O_RDONLY,
-		    0644,
-		    DB_HASH,
-		    NULL);
-    if (result != 0) {
-	T(("opened %s", path));
-    }
+	if ((result = dbopen(path,
+			     modify ? (O_CREAT | O_RDWR) : O_RDONLY,
+			     0644,
+			     DB_HASH,
+			     NULL)) == 0) {
+	    code = errno;
+	}
 #endif
+	if (result != 0) {
+	    make_connection(result, path, modify);
+	    T(("opened %s", path));
+	} else {
+	    T(("cannot open %s: %s", path, strerror(code)));
+	}
+    }
     return result;
 }
 
@@ -103,6 +183,7 @@
 {
     int result;
 
+    drop_connection(db);
 #if HASHED_DB_API >= 2
     result = db->close(db, 0);
 #else
@@ -205,7 +286,7 @@
 _nc_db_have_index(DBT * key, DBT * data, char **buffer, int *size)
 {
     bool result = FALSE;
-    int used = data->size - 1;
+    int used = (int) data->size - 1;
     char *have = (char *) data->data;
 
     (void) key;
@@ -228,7 +309,7 @@
 _nc_db_have_data(DBT * key, DBT * data, char **buffer, int *size)
 {
     bool result = FALSE;
-    int used = data->size - 1;
+    int used = (int) data->size - 1;
     char *have = (char *) data->data;
 
     if (*have++ == 0) {
diff --git a/ncurses/tinfo/home_terminfo.c b/ncurses/tinfo/home_terminfo.c
index 4521c4a..e77f71c 100644
--- a/ncurses/tinfo/home_terminfo.c
+++ b/ncurses/tinfo/home_terminfo.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -37,7 +37,7 @@
 #include <curses.priv.h>
 #include <tic.h>
 
-MODULE_ID("$Id: home_terminfo.c,v 1.11 2008/08/03 23:43:11 tom Exp $")
+MODULE_ID("$Id: home_terminfo.c,v 1.15 2012/10/27 21:49:14 tom Exp $")
 
 /* ncurses extension...fall back on user's private directory */
 
@@ -53,11 +53,9 @@
     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);
+		size_t want = (strlen(home) + sizeof(PRIVATE_INFO));
+		TYPE_MALLOC(char, want, MyBuffer);
+		_nc_SPRINTF(MyBuffer, _nc_SLIMIT(want) PRIVATE_INFO, home);
 	    }
 	}
 	result = MyBuffer;
diff --git a/ncurses/tinfo/init_keytry.c b/ncurses/tinfo/init_keytry.c
index 2f6fe4f..ea47b38 100644
--- a/ncurses/tinfo/init_keytry.c
+++ b/ncurses/tinfo/init_keytry.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1999-2009,2010 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            *
@@ -27,16 +27,9 @@
  ****************************************************************************/
 
 #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 $")
+MODULE_ID("$Id: init_keytry.c,v 1.17 2010/04/24 22:29:56 tom Exp $")
 
 /*
 **      _nc_init_keytry()
@@ -50,7 +43,7 @@
  * than cur_term.
  */
 #undef CUR
-#define CUR (sp->_term)->type.
+#define CUR SP_TERMTYPE
 
 #if	BROKEN_LINKER
 #undef	_nc_tinfo_fkeys
@@ -73,7 +66,7 @@
 NCURSES_EXPORT(void)
 _nc_init_keytry(SCREEN *sp)
 {
-    size_t n;
+    unsigned n;
 
     /* The sp->_keytry value is initialized in newterm(), where the sp
      * structure is created, because we can not tell where keypad() or
@@ -97,12 +90,13 @@
 	{
 	    TERMTYPE *tp = &(sp->_term->type);
 	    for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
-		const char *name = ExtStrname(tp, n, strnames);
+		const char *name = ExtStrname(tp, (int) n, strnames);
 		char *value = tp->Strings[n];
 		if (name != 0
 		    && *name == 'k'
 		    && value != 0
-		    && key_defined(value) == 0) {
+		    && NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx
+						     value) == 0) {
 		    (void) _nc_add_to_try(&(sp->_keytry),
 					  value,
 					  n - STRCOUNT + KEY_MAX);
diff --git a/ncurses/tinfo/lib_acs.c b/ncurses/tinfo/lib_acs.c
index 919e472..69a1851 100644
--- a/ncurses/tinfo/lib_acs.c
+++ b/ncurses/tinfo/lib_acs.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,17 +30,21 @@
  *  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: Juergen Pfeifer                         2008                    *
  ****************************************************************************/
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_acs.c,v 1.45 2014/03/08 20:32:59 tom Exp $")
 
 #if BROKEN_LINKER || USE_REENTRANT
 #define MyBuffer _nc_prescreen.real_acs_map
-NCURSES_EXPORT_VAR(chtype *)
-_nc_acs_map(void)
+NCURSES_EXPORT(chtype *)
+NCURSES_PUBLIC_VAR(acs_map) (void)
 {
     if (MyBuffer == 0)
 	MyBuffer = typeCalloc(chtype, ACS_LEN);
@@ -48,17 +52,35 @@
 }
 #undef MyBuffer
 #else
-NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] =
+NCURSES_EXPORT_VAR (chtype) acs_map[ACS_LEN] =
 {
     0
 };
 #endif
 
+#ifdef USE_TERM_DRIVER
+NCURSES_EXPORT(chtype)
+NCURSES_SP_NAME(_nc_acs_char) (NCURSES_SP_DCLx int c)
+{
+    chtype *map;
+    if (c < 0 || c >= ACS_LEN)
+	return (chtype) 0;
+    map = (SP_PARM != 0) ? SP_PARM->_acs_map :
+#if BROKEN_LINKER || USE_REENTRANT
+	_nc_prescreen.real_acs_map
+#else
+	acs_map
+#endif
+	;
+    return map[c];
+}
+#endif /* USE_TERM_DRIVER */
+
 NCURSES_EXPORT(void)
-_nc_init_acs(void)
+NCURSES_SP_NAME(_nc_init_acs) (NCURSES_SP_DCL0)
 {
     chtype *fake_map = acs_map;
-    chtype *real_map = SP != 0 ? SP->_acs_map : fake_map;
+    chtype *real_map = SP_PARM != 0 ? SP_PARM->_acs_map : fake_map;
     int j;
 
     T(("initializing ACS map"));
@@ -71,9 +93,9 @@
     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;
+	    fake_map[j] = A_ALTCHARSET | (chtype) j;
+	    if (SP_PARM)
+		SP_PARM->_screen_acs_map[j] = FALSE;
 	}
     } else {
 	for (j = 1; j < ACS_LEN; ++j) {
@@ -118,10 +140,36 @@
     real_map['{'] = '*';	/* should be greek pi */
     real_map['|'] = '!';	/* should be not-equal */
     real_map['}'] = 'f';	/* should be pound-sterling symbol */
+    /* thick-line-drawing */
+    real_map['L'] = '+';	/* upper left corner */
+    real_map['M'] = '+';	/* lower left corner */
+    real_map['K'] = '+';	/* upper right corner */
+    real_map['J'] = '+';	/* lower right corner */
+    real_map['T'] = '+';	/* tee pointing left */
+    real_map['U'] = '+';	/* tee pointing right */
+    real_map['V'] = '+';	/* tee pointing up */
+    real_map['W'] = '+';	/* tee pointing down */
+    real_map['Q'] = '-';	/* horizontal line */
+    real_map['X'] = '|';	/* vertical line */
+    real_map['N'] = '+';	/* large plus or crossover */
+    /* double-line-drawing */
+    real_map['C'] = '+';	/* upper left corner */
+    real_map['D'] = '+';	/* lower left corner */
+    real_map['B'] = '+';	/* upper right corner */
+    real_map['A'] = '+';	/* lower right corner */
+    real_map['G'] = '+';	/* tee pointing left */
+    real_map['F'] = '+';	/* tee pointing right */
+    real_map['H'] = '+';	/* tee pointing up */
+    real_map['I'] = '+';	/* tee pointing down */
+    real_map['R'] = '-';	/* horizontal line */
+    real_map['Y'] = '|';	/* vertical line */
+    real_map['E'] = '+';	/* large plus or crossover */
 
+#ifdef USE_TERM_DRIVER
+    CallDriver_2(SP_PARM, td_initacs, real_map, fake_map);
+#else
     if (ena_acs != NULL) {
-	TPUTS_TRACE("ena_acs");
-	putp(ena_acs);
+	NCURSES_PUTP2("ena_acs", ena_acs);
     }
 #if NCURSES_EXT_FUNCS
     /*
@@ -140,7 +188,7 @@
 	size_t i;
 	for (i = 1; i < ACS_LEN; ++i) {
 	    if (real_map[i] == 0) {
-		real_map[i] = i;
+		real_map[i] = (chtype) i;
 		if (real_map != fake_map) {
 		    if (SP != 0)
 			SP->_screen_acs_map[i] = TRUE;
@@ -191,4 +239,13 @@
 	_nc_unlock_global(tracef);
     }
 #endif /* TRACE */
+#endif
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_init_acs(void)
+{
+    NCURSES_SP_NAME(_nc_init_acs) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/tinfo/lib_baudrate.c b/ncurses/tinfo/lib_baudrate.c
index b9cdfda..1cf5505 100644
--- a/ncurses/tinfo/lib_baudrate.c
+++ b/ncurses/tinfo/lib_baudrate.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 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            *
@@ -38,7 +38,6 @@
  */
 
 #include <curses.priv.h>
-#include <term.h>		/* cur_term, pad_char */
 #include <termcap.h>		/* ospeed */
 #if defined(__FreeBSD__)
 #include <sys/param.h>
@@ -50,7 +49,7 @@
  * 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__)
+#if NCURSES_OSPEED_COMPAT && ((defined(__FreeBSD__) && (__FreeBSD_version < 700000)) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__))
 #undef B0
 #undef B50
 #undef B75
@@ -80,7 +79,7 @@
 #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 $")
+MODULE_ID("$Id: lib_baudrate.c,v 1.37 2015/06/14 00:34:12 tom Exp $")
 
 /*
  *	int
@@ -91,54 +90,55 @@
  */
 
 struct speed {
-    int s;			/* value for 'ospeed' is an index */
+    NCURSES_OSPEED s;		/* values for 'ospeed' */
     int sp;			/* the actual speed */
 };
 
+#define DATA(number) { B##number, number }
+
 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},
+    DATA(0),
+    DATA(50),
+    DATA(75),
+    DATA(110),
+    DATA(134),
+    DATA(150),
+    DATA(200),
+    DATA(300),
+    DATA(600),
+    DATA(1200),
+    DATA(1800),
+    DATA(2400),
+    DATA(4800),
+    DATA(9600),
 #ifdef B19200
-    {B19200, 19200},
-#else
-#ifdef EXTA
+    DATA(19200),
+#elif defined(EXTA)
     {EXTA, 19200},
 #endif
-#endif
 #ifdef B38400
-    {B38400, 38400},
-#else
-#ifdef EXTB
+    DATA(38400),
+#elif defined(EXTB)
     {EXTB, 38400},
 #endif
-#endif
 #ifdef B57600
-    {B57600, 57600},
+    DATA(57600),
 #endif
+    /* ifdef to prevent overflow when OLD_TTY is not available */
+#if !(NCURSES_OSPEED_COMPAT && defined(__FreeBSD__) && (__FreeBSD_version > 700000))
 #ifdef B115200
-    {B115200, 115200},
+    DATA(115200),
 #endif
 #ifdef B230400
-    {B230400, 230400},
+    DATA(230400),
 #endif
 #ifdef B460800
-    {B460800, 460800},
+    DATA(460800),
 #endif
 #ifdef B921600
-    {B921600, 921600},
+    DATA(921600),
+#endif
 #endif
 };
 
@@ -161,14 +161,14 @@
     if (result == ERR) {
 	if (OSpeed >= 0) {
 	    for (i = 0; i < SIZEOF(speeds); i++) {
-		if (speeds[i].s == OSpeed) {
+		if ((int) speeds[i].s == OSpeed) {
 		    result = speeds[i].sp;
 		    break;
 		}
 	    }
 	}
 #if !USE_REENTRANT
-	if (OSpeed == last_OSpeed) {
+	if (OSpeed != last_OSpeed) {
 	    last_OSpeed = OSpeed;
 	    last_baudrate = result;
 	}
@@ -195,11 +195,11 @@
 }
 
 NCURSES_EXPORT(int)
-baudrate(void)
+NCURSES_SP_NAME(baudrate) (NCURSES_SP_DCL0)
 {
     int result;
 
-    T((T_CALLED("baudrate()")));
+    T((T_CALLED("baudrate(%p)"), (void *) SP_PARM));
 
     /*
      * In debugging, allow the environment symbol to override when we're
@@ -207,32 +207,41 @@
      * that take into account costs that depend on baudrate.
      */
 #ifdef TRACE
-    if (!isatty(fileno(SP ? SP->_ofp : stdout))
+    if (IsValidTIScreen(SP_PARM)
+	&& !NC_ISATTY(fileno(SP_PARM ? SP_PARM->_ofp : stdout))
 	&& getenv("BAUDRATE") != 0) {
 	int ret;
 	if ((ret = _nc_getenv_num("BAUDRATE")) <= 0)
 	    ret = 9600;
-	ospeed = _nc_ospeed(ret);
+	ospeed = (NCURSES_OSPEED) _nc_ospeed(ret);
 	returnCode(ret);
     }
 #endif
 
-    if (cur_term != 0) {
+    if (IsValidTIScreen(SP_PARM)) {
 #ifdef USE_OLD_TTY
-	result = cfgetospeed(&cur_term->Nttyb);
-	ospeed = _nc_ospeed(result);
+	result = (int) cfgetospeed(&(TerminalOf(SP_PARM)->Nttyb));
+	ospeed = (NCURSES_OSPEED) _nc_ospeed(result);
 #else /* !USE_OLD_TTY */
 #ifdef TERMIOS
-	ospeed = cfgetospeed(&cur_term->Nttyb);
+	ospeed = (NCURSES_OSPEED) cfgetospeed(&(TerminalOf(SP_PARM)->Nttyb));
 #else
-	ospeed = cur_term->Nttyb.sg_ospeed;
+	ospeed = (NCURSES_OSPEED) TerminalOf(SP_PARM)->Nttyb.sg_ospeed;
 #endif
 	result = _nc_baudrate(ospeed);
 #endif
-	cur_term->_baudrate = result;
+	TerminalOf(SP_PARM)->_baudrate = result;
     } else {
 	result = ERR;
     }
 
     returnCode(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+baudrate(void)
+{
+    return NCURSES_SP_NAME(baudrate) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/tinfo/lib_cur_term.c b/ncurses/tinfo/lib_cur_term.c
index 626578d..9941d13 100644
--- a/ncurses/tinfo/lib_cur_term.c
+++ b/ncurses/tinfo/lib_cur_term.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -37,69 +37,139 @@
  */
 
 #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 $")
+MODULE_ID("$Id: lib_cur_term.c,v 1.33 2014/03/08 20:32:59 tom Exp $")
 
 #undef CUR
 #define CUR termp->type.
 
-#if BROKEN_LINKER || USE_REENTRANT
+#if USE_REENTRANT
+
+NCURSES_EXPORT(TERMINAL *)
+NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_DCL0)
+{
+    return ((0 != TerminalOf(SP_PARM)) ? TerminalOf(SP_PARM) : CurTerm);
+}
+
+#if NCURSES_SP_FUNCS
+
+NCURSES_EXPORT(TERMINAL *)
+_nc_get_cur_term(void)
+{
+    return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
+}
+#endif
+
 NCURSES_EXPORT(TERMINAL *)
 NCURSES_PUBLIC_VAR(cur_term) (void)
 {
-    return (SP != 0 && SP->_term != 0) ? SP->_term : _nc_prescreen._cur_term;
+#if NCURSES_SP_FUNCS
+    return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
+#else
+    return NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG);
+#endif
 }
+
 #else
 NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0;
 #endif
 
 NCURSES_EXPORT(TERMINAL *)
-set_curterm(TERMINAL * termp)
+NCURSES_SP_NAME(set_curterm) (NCURSES_SP_DCLx TERMINAL * termp)
 {
     TERMINAL *oldterm;
 
-    T((T_CALLED("set_curterm(%p)"), termp));
+    T((T_CALLED("set_curterm(%p)"), (void *) termp));
 
     _nc_lock_global(curses);
     oldterm = cur_term;
-    if (SP)
-	SP->_term = termp;
-#if BROKEN_LINKER || USE_REENTRANT
-    _nc_prescreen._cur_term = termp;
+    if (SP_PARM)
+	SP_PARM->_term = termp;
+#if USE_REENTRANT
+    CurTerm = termp;
 #else
     cur_term = termp;
 #endif
     if (termp != 0) {
-	ospeed = _nc_ospeed(termp->_baudrate);
+#ifdef USE_TERM_DRIVER
+	TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
+	ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
+	if (TCB->drv->isTerminfo && termp->type.Strings) {
+	    PC = (char) ((pad_char != NULL) ? pad_char[0] : 0);
+	}
+	TCB->csp = SP_PARM;
+#else
+	ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
 	if (termp->type.Strings) {
 	    PC = (char) ((pad_char != NULL) ? pad_char[0] : 0);
 	}
+#endif
     }
     _nc_unlock_global(curses);
 
-    T((T_RETURN("%p"), oldterm));
+    T((T_RETURN("%p"), (void *) oldterm));
     return (oldterm);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(TERMINAL *)
+set_curterm(TERMINAL * termp)
+{
+    return NCURSES_SP_NAME(set_curterm) (CURRENT_SCREEN, termp);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL * termp)
+{
+    int rc = ERR;
+
+    T((T_CALLED("del_curterm(%p, %p)"), (void *) SP_PARM, (void *) termp));
+
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+	TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
+#endif
+	TERMINAL *cur = (
+#if USE_REENTRANT
+			    NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG)
+#else
+			    cur_term
+#endif
+	);
+
+	_nc_free_termtype(&(termp->type));
+	if (termp == cur)
+	    NCURSES_SP_NAME(set_curterm) (NCURSES_SP_ARGx 0);
+
+	FreeIfNeeded(termp->_termname);
+#if USE_HOME_TERMINFO
+	if (_nc_globals.home_terminfo != 0) {
+	    FreeAndNull(_nc_globals.home_terminfo);
+	}
+#endif
+#ifdef USE_TERM_DRIVER
+	if (TCB->drv)
+	    TCB->drv->td_release(TCB);
+#endif
+	free(termp);
+
+	rc = OK;
+    }
+    returnCode(rc);
+}
+
+#if NCURSES_SP_FUNCS
 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;
-    }
+    rc = NCURSES_SP_NAME(del_curterm) (CURRENT_SCREEN, termp);
     _nc_unlock_global(curses);
 
-    returnCode(rc);
+    return (rc);
 }
+#endif
diff --git a/ncurses/tinfo/lib_data.c b/ncurses/tinfo/lib_data.c
index e84209d..06b6f88 100644
--- a/ncurses/tinfo/lib_data.c
+++ b/ncurses/tinfo/lib_data.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 /*
@@ -41,7 +42,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_data.c,v 1.52 2008/08/23 22:16:15 tom Exp $")
+MODULE_ID("$Id: lib_data.c,v 1.66 2013/08/24 17:28:24 tom Exp $")
 
 /*
  * OS/2's native linker complains if we don't initialize public data when
@@ -51,17 +52,17 @@
 NCURSES_EXPORT(WINDOW *)
 NCURSES_PUBLIC_VAR(stdscr) (void)
 {
-    return SP ? SP->_stdscr : 0;
+    return CURRENT_SCREEN ? StdScreen(CURRENT_SCREEN) : 0;
 }
 NCURSES_EXPORT(WINDOW *)
 NCURSES_PUBLIC_VAR(curscr) (void)
 {
-    return SP ? SP->_curscr : 0;
+    return CURRENT_SCREEN ? CurScreen(CURRENT_SCREEN) : 0;
 }
 NCURSES_EXPORT(WINDOW *)
 NCURSES_PUBLIC_VAR(newscr) (void)
 {
-    return SP ? SP->_newscr : 0;
+    return CURRENT_SCREEN ? NewScreen(CURRENT_SCREEN) : 0;
 }
 #else
 NCURSES_EXPORT_VAR(WINDOW *) stdscr = 0;
@@ -93,7 +94,7 @@
 NCURSES_EXPORT(int)
 _nc_alloc_screen(void)
 {
-    return ((my_screen = typeCalloc(SCREEN, 1)) != 0);
+    return ((my_screen = _nc_alloc_screen_sp()) != 0);
 }
 
 NCURSES_EXPORT(void)
@@ -103,6 +104,7 @@
 }
 
 #else
+
 NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */
 #endif
 /* *INDENT-OFF* */
@@ -112,6 +114,7 @@
 #define TGETENT_0s { TGETENT_0, TGETENT_0, TGETENT_0, TGETENT_0 }
 
 NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = {
+    0,				/* have_sigtstp */
     0,				/* have_sigwinch */
     0,				/* cleanup_nested */
 
@@ -123,13 +126,14 @@
 
     FALSE,			/* have_tic_directory */
     FALSE,			/* keep_tic_directory */
-    TERMINFO,			/* tic_directory */
+    0,				/* tic_directory */
 
     NULL,			/* dbi_list */
     0,				/* dbi_size */
 
     NULL,			/* first_name */
     NULL,			/* keyname_table */
+    0,				/* init_keyname */
 
     0,				/* slk_format */
 
@@ -140,7 +144,15 @@
     0,				/* tgetent_index */
     0,				/* tgetent_sequence */
 
+    0,				/* dbd_blob */
+    0,				/* dbd_list */
+    0,				/* dbd_size */
+    0,				/* dbd_time */
+    { { 0, 0 } },		/* dbd_vars */
+
+#ifndef USE_SP_WINDOWLIST
     0,				/* _nc_windowlist */
+#endif
 
 #if USE_HOME_TERMINFO
     NULL,			/* home_terminfo */
@@ -151,6 +163,10 @@
     0,				/* safeprint_rows */
 #endif
 
+#ifdef USE_TERM_DRIVER
+    0,				/* term_driver */
+#endif
+
 #ifdef TRACE
     FALSE,			/* init_trace */
     CHARS_0s,			/* trace_fname */
@@ -174,7 +190,9 @@
     { CHARS_0s, CHARS_0s },	/* traceatr_color_buf */
     0,				/* traceatr_color_sel */
     -1,				/* traceatr_color_last */
-
+#if !defined(USE_PTHREADS) && USE_REENTRANT
+    0,				/* nested_tracef */
+#endif
 #endif /* TRACE */
 #ifdef USE_PTHREADS
     PTHREAD_MUTEX_INITIALIZER,	/* mutex_curses */
@@ -183,6 +201,9 @@
     0,				/* nested_tracef */
     0,				/* use_pthreads */
 #endif
+#if USE_PTHREADS_EINTR
+    0,				/* read_thread */
+#endif
 };
 
 #define STACK_FRAME_0	{ { 0 }, 0 }
@@ -196,8 +217,10 @@
     TRUE,			/* use_env */
     FALSE,			/* filter_mode */
     A_NORMAL,			/* previous_attr */
+#ifndef USE_SP_RIPOFF
     RIPOFF_0s,			/* ripoff */
     NULL,			/* rsp */
+#endif
     {				/* tparm_state */
 #ifdef TRACE
 	NULL,			/* tname */
@@ -221,19 +244,39 @@
 #if NCURSES_NO_PADDING
     FALSE,			/* flag to set if padding disabled  */
 #endif
+    0,				/* _outch */
 #if BROKEN_LINKER || USE_REENTRANT
     NULL,			/* real_acs_map */
     0,				/* LINES */
     0,				/* COLS */
+    8,				/* TABSIZE */
+    1000,			/* ESCDELAY */
     0,				/* cur_term */
 #ifdef TRACE
     0L,				/* _outchars */
     NULL,			/* _tputs_trace */
 #endif
 #endif
+    FALSE,			/* use_tioctl */
 };
 /* *INDENT-ON* */
 
+/*
+ * 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) {
+	sp = WINDOW_EXT(win, screen);
+    }
+    return (sp);
+}
+
 /******************************************************************************/
 #ifdef USE_PTHREADS
 static void
@@ -314,7 +357,9 @@
 	return 0;
     return pthread_mutex_unlock(obj);
 }
+#endif /* USE_PTHREADS */
 
+#if defined(USE_PTHREADS) || USE_PTHREADS_EINTR
 #if USE_WEAK_SYMBOLS
 /*
  * NB: sigprocmask(2) is global but pthread_sigmask(3p)
diff --git a/ncurses/tinfo/lib_has_cap.c b/ncurses/tinfo/lib_has_cap.c
index 0dc66bd..17e59d5 100644
--- a/ncurses/tinfo/lib_has_cap.c
+++ b/ncurses/tinfo/lib_has_cap.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
  *     and: Thomas E. Dickey                        1996-2003               *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -41,25 +42,53 @@
 
 #include <curses.priv.h>
 
-#include <term.h>
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-MODULE_ID("$Id: lib_has_cap.c,v 1.4 2003/10/25 19:43:55 tom Exp $")
+MODULE_ID("$Id: lib_has_cap.c,v 1.10 2013/11/16 19:57:22 tom Exp $")
 
 NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(has_ic) (NCURSES_SP_DCL0)
+{
+    bool code = FALSE;
+
+    T((T_CALLED("has_ic(%p)"), (void *) SP_PARM));
+
+    if (HasTInfoTerminal(SP_PARM)) {
+	code = ((insert_character || parm_ich
+		 || (enter_insert_mode && exit_insert_mode))
+		&& (delete_character || parm_dch)) ? TRUE : FALSE;
+    }
+
+    returnCode(code);
+}
+
+#if NCURSES_SP_FUNCS
+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));
+    return NCURSES_SP_NAME(has_ic) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(has_il) (NCURSES_SP_DCL0)
+{
+    bool code = FALSE;
+    T((T_CALLED("has_il(%p)"), (void *) SP_PARM));
+    if (HasTInfoTerminal(SP_PARM)) {
+	code = ((insert_line || parm_insert_line)
+		&& (delete_line || parm_delete_line)) ? TRUE : FALSE;
+    }
+
+    returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(bool)
 has_il(void)
 {
-    T((T_CALLED("has_il()")));
-    returnCode(cur_term
-	       && (insert_line || parm_insert_line)
-	       && (delete_line || parm_delete_line));
+    return NCURSES_SP_NAME(has_il) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/tinfo/lib_kernel.c b/ncurses/tinfo/lib_kernel.c
index 89dc1e8..37f7084 100644
--- a/ncurses/tinfo/lib_kernel.c
+++ b/ncurses/tinfo/lib_kernel.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 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            *
@@ -29,7 +29,8 @@
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
- *     and: Thomas E. Dickey 2002                                           *
+ *     and: Thomas E. Dickey                        2002                    *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -46,9 +47,8 @@
  */
 
 #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 $")
+MODULE_ID("$Id: lib_kernel.c,v 1.31 2010/12/19 01:21:19 tom Exp $")
 
 static int
 _nc_vdisable(void)
@@ -59,7 +59,7 @@
 #endif
 #if defined(_PC_VDISABLE)
     if (value == -1) {
-	value = fpathconf(0, _PC_VDISABLE);
+	value = (int) fpathconf(0, _PC_VDISABLE);
 	if (value == -1) {
 	    value = 0377;
 	}
@@ -79,23 +79,33 @@
  */
 
 NCURSES_EXPORT(char)
-erasechar(void)
+NCURSES_SP_NAME(erasechar) (NCURSES_SP_DCL0)
 {
     int result = ERR;
-    T((T_CALLED("erasechar()")));
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    if (cur_term != 0) {
+    T((T_CALLED("erasechar(%p)"), (void *) SP_PARM));
+
+    if (termp != 0) {
 #ifdef TERMIOS
-	result = cur_term->Ottyb.c_cc[VERASE];
+	result = termp->Ottyb.c_cc[VERASE];
 	if (result == _nc_vdisable())
 	    result = ERR;
 #else
-	result = cur_term->Ottyb.sg_erase;
+	result = termp->Ottyb.sg_erase;
 #endif
     }
-    returnCode(result);
+    returnChar((char) result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char)
+erasechar(void)
+{
+    return NCURSES_SP_NAME(erasechar) (CURRENT_SCREEN);
+}
+#endif
+
 /*
  *	killchar()
  *
@@ -104,23 +114,33 @@
  */
 
 NCURSES_EXPORT(char)
-killchar(void)
+NCURSES_SP_NAME(killchar) (NCURSES_SP_DCL0)
 {
     int result = ERR;
-    T((T_CALLED("killchar()")));
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    if (cur_term != 0) {
+    T((T_CALLED("killchar(%p)"), (void *) SP_PARM));
+
+    if (termp != 0) {
 #ifdef TERMIOS
-	result = cur_term->Ottyb.c_cc[VKILL];
+	result = termp->Ottyb.c_cc[VKILL];
 	if (result == _nc_vdisable())
 	    result = ERR;
 #else
-	result = cur_term->Ottyb.sg_kill;
+	result = termp->Ottyb.sg_kill;
 #endif
     }
-    returnCode(result);
+    returnChar((char) result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char)
+killchar(void)
+{
+    return NCURSES_SP_NAME(killchar) (CURRENT_SCREEN);
+}
+#endif
+
 /*
  *	flushinp()
  *
@@ -129,26 +149,36 @@
  */
 
 NCURSES_EXPORT(int)
-flushinp(void)
+NCURSES_SP_NAME(flushinp) (NCURSES_SP_DCL0)
 {
-    T((T_CALLED("flushinp()")));
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    if (cur_term != 0) {
+    T((T_CALLED("flushinp(%p)"), (void *) SP_PARM));
+
+    if (termp != 0) {
 #ifdef TERMIOS
-	tcflush(cur_term->Filedes, TCIFLUSH);
+	tcflush(termp->Filedes, TCIFLUSH);
 #else
 	errno = 0;
 	do {
-	    ioctl(cur_term->Filedes, TIOCFLUSH, 0);
+	    ioctl(termp->Filedes, TIOCFLUSH, 0);
 	} while
 	    (errno == EINTR);
 #endif
-	if (SP) {
-	    SP->_fifohead = -1;
-	    SP->_fifotail = 0;
-	    SP->_fifopeek = 0;
+	if (SP_PARM) {
+	    SP_PARM->_fifohead = -1;
+	    SP_PARM->_fifotail = 0;
+	    SP_PARM->_fifopeek = 0;
 	}
 	returnCode(OK);
     }
     returnCode(ERR);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+flushinp(void)
+{
+    return NCURSES_SP_NAME(flushinp) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/tinfo/lib_longname.c b/ncurses/tinfo/lib_longname.c
index 1301ee5..fa231b8 100644
--- a/ncurses/tinfo/lib_longname.c
+++ b/ncurses/tinfo/lib_longname.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2010,2015 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            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -40,7 +42,48 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_longname.c,v 1.9 2000/12/10 02:55:07 tom Exp $")
+MODULE_ID("$Id: lib_longname.c,v 1.13 2015/07/25 20:08:14 tom Exp $")
+
+#if USE_REENTRANT
+NCURSES_EXPORT(char *)
+NCURSES_SP_NAME(longname) (NCURSES_SP_DCL0)
+{
+    static char empty[] =
+    {'\0'};
+    char *ptr;
+
+    T((T_CALLED("longname(%p)"), (void *) SP_PARM));
+
+    if (SP_PARM) {
+	for (ptr = SP_PARM->_ttytype + strlen(SP_PARM->_ttytype);
+	     ptr > SP_PARM->_ttytype;
+	     ptr--)
+	    if (*ptr == '|')
+		returnPtr(ptr + 1);
+	returnPtr(SP_PARM->_ttytype);
+    }
+    return empty;
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char *)
+longname(void)
+{
+    return NCURSES_SP_NAME(longname) (CURRENT_SCREEN);
+}
+#endif
+
+#else
+
+/* a dummy entrypoint is simpler than generating a conditional in curses.h */
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char *)
+NCURSES_SP_NAME(longname) (NCURSES_SP_DCL0)
+{
+    (void) SP_PARM;
+    return longname();
+}
+#endif
 
 NCURSES_EXPORT(char *)
 longname(void)
@@ -49,9 +92,11 @@
 
     T((T_CALLED("longname()")));
 
-    for (ptr = ttytype + strlen(ttytype); ptr > ttytype; ptr--)
+    for (ptr = ttytype + strlen(ttytype);
+	 ptr > ttytype;
+	 ptr--)
 	if (*ptr == '|')
 	    returnPtr(ptr + 1);
-
     returnPtr(ttytype);
 }
+#endif
diff --git a/ncurses/tinfo/lib_napms.c b/ncurses/tinfo/lib_napms.c
index 417b3b4..df17363 100644
--- a/ncurses/tinfo/lib_napms.c
+++ b/ncurses/tinfo/lib_napms.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -49,13 +51,21 @@
 #endif
 #endif
 
-MODULE_ID("$Id: lib_napms.c,v 1.17 2008/05/03 21:34:13 tom Exp $")
+MODULE_ID("$Id: lib_napms.c,v 1.24 2014/03/08 20:32:59 tom Exp $")
 
 NCURSES_EXPORT(int)
-napms(int ms)
+NCURSES_SP_NAME(napms) (NCURSES_SP_DCLx int ms)
 {
     T((T_CALLED("napms(%d)"), ms));
 
+#ifdef USE_TERM_DRIVER
+    if (HasTerminal(SP_PARM)) {
+	CallDriver_1(SP_PARM, td_nap, ms);
+    }
+#else /* !USE_TERM_DRIVER */
+#if NCURSES_SP_FUNCS
+    (void) sp;
+#endif
 #if HAVE_NANOSLEEP
     {
 	struct timespec request, remaining;
@@ -69,6 +79,15 @@
 #else
     _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
 #endif
+#endif /* !USE_TERM_DRIVER */
 
     returnCode(OK);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+napms(int ms)
+{
+    return NCURSES_SP_NAME(napms) (CURRENT_SCREEN, ms);
+}
+#endif
diff --git a/ncurses/tinfo/lib_options.c b/ncurses/tinfo/lib_options.c
index f3b1485..b736d5f 100644
--- a/ncurses/tinfo/lib_options.c
+++ b/ncurses/tinfo/lib_options.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -41,53 +42,71 @@
 
 #include <curses.priv.h>
 
-#include <term.h>
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-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);
+MODULE_ID("$Id: lib_options.c,v 1.78 2014/09/27 21:55:24 tom Exp $")
 
 NCURSES_EXPORT(int)
 idlok(WINDOW *win, bool flag)
 {
-    T((T_CALLED("idlok(%p,%d)"), win, flag));
+    int res = ERR;
+    T((T_CALLED("idlok(%p,%d)"), (void *) win, flag));
 
     if (win) {
-	_nc_idlok = win->_idlok = (flag && (has_il() || change_scroll_region));
-	returnCode(OK);
-    } else
-	returnCode(ERR);
+	SCREEN *sp = _nc_screen_of(win);
+	if (sp != 0
+#ifdef USE_TERM_DRIVER
+	    && IsTermInfo(sp)
+#endif
+	    ) {
+	    sp->_nc_sp_idlok =
+		win->_idlok = (flag && (NCURSES_SP_NAME(has_il) (NCURSES_SP_ARG)
+					|| change_scroll_region));
+	    res = OK;
+	}
+    }
+    returnCode(res);
 }
 
 NCURSES_EXPORT(void)
 idcok(WINDOW *win, bool flag)
 {
-    T((T_CALLED("idcok(%p,%d)"), win, flag));
+    T((T_CALLED("idcok(%p,%d)"), (void *) win, flag));
 
-    if (win)
-	_nc_idcok = win->_idcok = (flag && has_ic());
-
+    if (win) {
+	SCREEN *sp = _nc_screen_of(win);
+	sp->_nc_sp_idcok = win->_idcok = (flag && NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG));
+    }
     returnVoid;
 }
 
 NCURSES_EXPORT(int)
-halfdelay(int t)
+NCURSES_SP_NAME(halfdelay) (NCURSES_SP_DCLx int t)
 {
-    T((T_CALLED("halfdelay(%d)"), t));
+    T((T_CALLED("halfdelay(%p,%d)"), (void *) SP_PARM, t));
 
-    if (t < 1 || t > 255 || SP == 0)
+    if (t < 1 || t > 255 || !IsValidTIScreen(SP_PARM))
 	returnCode(ERR);
 
-    cbreak();
-    SP->_cbreak = t + 1;
+    NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
+    SP_PARM->_cbreak = t + 1;
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+halfdelay(int t)
+{
+    return NCURSES_SP_NAME(halfdelay) (CURRENT_SCREEN, t);
+}
+#endif
+
 NCURSES_EXPORT(int)
 nodelay(WINDOW *win, bool flag)
 {
-    T((T_CALLED("nodelay(%p,%d)"), win, flag));
+    T((T_CALLED("nodelay(%p,%d)"), (void *) win, flag));
 
     if (win) {
 	if (flag == TRUE)
@@ -102,7 +121,7 @@
 NCURSES_EXPORT(int)
 notimeout(WINDOW *win, bool f)
 {
-    T((T_CALLED("notimeout(%p,%d)"), win, f));
+    T((T_CALLED("notimeout(%p,%d)"), (void *) win, f));
 
     if (win) {
 	win->_notimeout = f;
@@ -114,7 +133,7 @@
 NCURSES_EXPORT(void)
 wtimeout(WINDOW *win, int delay)
 {
-    T((T_CALLED("wtimeout(%p,%d)"), win, delay));
+    T((T_CALLED("wtimeout(%p,%d)"), (void *) win, delay));
 
     if (win) {
 	win->_delay = delay;
@@ -125,11 +144,11 @@
 NCURSES_EXPORT(int)
 keypad(WINDOW *win, bool flag)
 {
-    T((T_CALLED("keypad(%p,%d)"), win, flag));
+    T((T_CALLED("keypad(%p,%d)"), (void *) win, flag));
 
     if (win) {
 	win->_use_keypad = flag;
-	returnCode(_nc_keypad(SP, flag));
+	returnCode(_nc_keypad(_nc_screen_of(win), flag));
     } else
 	returnCode(ERR);
 }
@@ -137,38 +156,107 @@
 NCURSES_EXPORT(int)
 meta(WINDOW *win GCC_UNUSED, bool flag)
 {
-    int result;
+    int result = ERR;
+    SCREEN *sp = (win == 0) ? CURRENT_SCREEN : _nc_screen_of(win);
 
     /* 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);
+    T((T_CALLED("meta(%p,%d)"), (void *) win, flag));
+
+    /* Ok, we stay relaxed and don't signal an error if win is NULL */
+
+    if (sp != 0) {
+	sp->_use_meta = flag;
+#ifdef USE_TERM_DRIVER
+	if (IsTermInfo(sp)) {
+	    if (flag) {
+		NCURSES_PUTP2("meta_on", meta_on);
+	    } else {
+		NCURSES_PUTP2("meta_off", meta_off);
+	    }
+	}
+#else
+	if (flag) {
+	    NCURSES_PUTP2("meta_on", meta_on);
+	} else {
+	    NCURSES_PUTP2("meta_off", meta_off);
+	}
+#endif
+	result = OK;
+    }
     returnCode(result);
 }
 
 /* curs_set() moved here to narrow the kernel interface */
 
 NCURSES_EXPORT(int)
-curs_set(int vis)
+NCURSES_SP_NAME(curs_set) (NCURSES_SP_DCLx int vis)
 {
-    int result;
+    int code = ERR;
+    T((T_CALLED("curs_set(%p,%d)"), (void *) SP_PARM, vis));
 
-    T((T_CALLED("curs_set(%d)"), vis));
-    result = _nc_curs_set(SP, vis);
-    returnCode(result);
+    if (SP_PARM != 0 && vis >= 0 && vis <= 2) {
+	int cursor = SP_PARM->_cursor;
+	if (vis == cursor) {
+	    code = cursor;
+	} else {
+#ifdef USE_TERM_DRIVER
+	    code = CallDriver_1(SP_PARM, td_cursorSet, vis);
+#else
+	    if (IsTermInfo(SP_PARM)) {
+		switch (vis) {
+		case 2:
+		    code = NCURSES_PUTP2_FLUSH("cursor_visible",
+					       cursor_visible);
+		    break;
+		case 1:
+		    code = NCURSES_PUTP2_FLUSH("cursor_normal",
+					       cursor_normal);
+		    break;
+		case 0:
+		    code = NCURSES_PUTP2_FLUSH("cursor_invisible",
+					       cursor_invisible);
+		    break;
+		}
+	    } else {
+		code = ERR;
+	    }
+#endif
+	    if (code != ERR)
+		code = (cursor == -1 ? 1 : cursor);
+	    SP_PARM->_cursor = vis;
+	}
+    }
+    returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-typeahead(int fd)
+curs_set(int vis)
 {
-    T((T_CALLED("typeahead(%d)"), fd));
-    if (SP != 0) {
-	SP->_checkfd = fd;
+    return (NCURSES_SP_NAME(curs_set) (CURRENT_SCREEN, vis));
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(typeahead) (NCURSES_SP_DCLx int fd)
+{
+    T((T_CALLED("typeahead(%p, %d)"), (void *) SP_PARM, fd));
+    if (IsValidTIScreen(SP_PARM)) {
+	SP_PARM->_checkfd = fd;
 	returnCode(OK);
     } else {
 	returnCode(ERR);
     }
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+typeahead(int fd)
+{
+    return NCURSES_SP_NAME(typeahead) (CURRENT_SCREEN, fd);
+}
+#endif
+
 /*
 **      has_key()
 **
@@ -189,43 +277,50 @@
 		|| has_key_internal(keycode, tp->sibling));
 }
 
+#ifdef USE_TERM_DRIVER
+NCURSES_EXPORT(int)
+TINFO_HAS_KEY(SCREEN *sp, int keycode)
+{
+    return IsValidTIScreen(sp) ?
+	has_key_internal(keycode, sp->_keytry) : 0;
+}
+#else
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(has_key) (NCURSES_SP_DCLx int keycode)
+{
+    T((T_CALLED("has_key(%p,%d)"), (void *) SP_PARM, keycode));
+    returnCode(SP != 0 ? has_key_internal(keycode, SP_PARM->_keytry) : FALSE);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 has_key(int keycode)
 {
-    T((T_CALLED("has_key(%d)"), keycode));
-    returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE);
+    return NCURSES_SP_NAME(has_key) (CURRENT_SCREEN, keycode);
 }
+#endif
+#endif
 #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)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_putp_flush) (NCURSES_SP_DCLx
+				 const char *name, 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);
+    int rc = NCURSES_PUTP2(name, value);
     if (rc != ERR) {
 	_nc_flush();
     }
     return rc;
 }
 
+#if 0 && NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_putp_flush(const char *name, const char *value)
+{
+    return NCURSES_SP_NAME(_nc_putp_flush) (CURRENT_SCREEN, name, value);
+}
+#endif
+
 /* Turn the keypad on/off
  *
  * Note:  we flush the output because changing this mode causes some terminals
@@ -234,7 +329,7 @@
  * the terminal state _before_ switching modes.
  */
 NCURSES_EXPORT(int)
-_nc_keypad(SCREEN *sp, bool flag)
+_nc_keypad(SCREEN *sp, int flag)
 {
     int rc = ERR;
 
@@ -245,12 +340,12 @@
 	 * has wgetch() reading in more than one thread.  putp() and below
 	 * may use SP explicitly.
 	 */
-	if (_nc_use_pthreads && sp != SP) {
+	if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
 	    SCREEN *save_sp;
 
 	    /* cannot use use_screen(), since that is not in tinfo library */
 	    _nc_lock_global(curses);
-	    save_sp = SP;
+	    save_sp = CURRENT_SCREEN;
 	    _nc_set_screen(sp);
 	    rc = _nc_keypad(sp, flag);
 	    _nc_set_screen(save_sp);
@@ -258,10 +353,15 @@
 	} else
 #endif
 	{
+#ifdef USE_TERM_DRIVER
+	    rc = CallDriver_1(sp, td_kpad, flag);
+	    if (rc == OK)
+		sp->_keypad_on = flag;
+#else
 	    if (flag) {
-		(void) _nc_putp_flush("keypad_xmit", keypad_xmit);
+		(void) NCURSES_PUTP2_FLUSH("keypad_xmit", keypad_xmit);
 	    } else if (!flag && keypad_local) {
-		(void) _nc_putp_flush("keypad_local", keypad_local);
+		(void) NCURSES_PUTP2_FLUSH("keypad_local", keypad_local);
 	    }
 
 	    if (flag && !sp->_tried) {
@@ -270,58 +370,8 @@
 	    }
 	    sp->_keypad_on = flag;
 	    rc = OK;
+#endif
 	}
     }
     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
index 975b46d..0dab4d4 100644
--- a/ncurses/tinfo/lib_print.c
+++ b/ncurses/tinfo/lib_print.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,23 +29,31 @@
 /****************************************************************************
  *  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: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-#include <term.h>
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-MODULE_ID("$Id: lib_print.c,v 1.16 2006/11/26 00:26:34 tom Exp $")
+MODULE_ID("$Id: lib_print.c,v 1.23 2012/02/22 22:34:31 tom Exp $")
 
 NCURSES_EXPORT(int)
-mcprint(char *data, int len)
+NCURSES_SP_NAME(mcprint) (NCURSES_SP_DCLx char *data, int len)
 /* ship binary character data to the printer via mc4/mc5/mc5p */
 {
+    int result;
     char *mybuf, *switchon;
-    size_t onsize, offsize, res;
+    size_t onsize, offsize;
+    size_t need;
 
     errno = 0;
-    if (!cur_term || (!prtr_non && (!prtr_on || !prtr_off))) {
+    if (!HasTInfoTerminal(SP_PARM)
+	|| len <= 0
+	|| (!prtr_non && (!prtr_on || !prtr_off))) {
 	errno = ENODEV;
 	return (ERR);
     }
@@ -60,16 +68,18 @@
 	offsize = strlen(prtr_off);
     }
 
+    need = onsize + (size_t) len + offsize;
+
     if (switchon == 0
-	|| (mybuf = typeMalloc(char, onsize + len + offsize + 1)) == 0) {
+	|| (mybuf = typeMalloc(char, need + 1)) == 0) {
 	errno = ENOMEM;
 	return (ERR);
     }
 
-    (void) strcpy(mybuf, switchon);
-    memcpy(mybuf + onsize, data, (unsigned) len);
+    _nc_STRCPY(mybuf, switchon, need);
+    memcpy(mybuf + onsize, data, (size_t) len);
     if (offsize)
-	(void) strcpy(mybuf + onsize + len, prtr_off);
+	_nc_STRCPY(mybuf + onsize + len, prtr_off, need);
 
     /*
      * We're relying on the atomicity of UNIX writes here.  The
@@ -78,15 +88,24 @@
      * 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);
+    result = (int) write(TerminalOf(SP_PARM)->Filedes, mybuf, need);
 
     /*
      * 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.
      */
+#ifndef __MINGW32__
     (void) sleep(0);
-
+#endif
     free(mybuf);
-    return (res);
+    return (result);
 }
+
+#if NCURSES_SP_FUNCS && !defined(USE_TERM_DRIVER)
+NCURSES_EXPORT(int)
+mcprint(char *data, int len)
+{
+    return NCURSES_SP_NAME(mcprint) (CURRENT_SCREEN, data, len);
+}
+#endif
diff --git a/ncurses/tinfo/lib_raw.c b/ncurses/tinfo/lib_raw.c
index 58e7188..928692b 100644
--- a/ncurses/tinfo/lib_raw.c
+++ b/ncurses/tinfo/lib_raw.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2002,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,7 +29,8 @@
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
- *     and: Thomas E. Dickey 1998 on                                        *
+ *     and: Thomas E. Dickey                        1998-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -47,13 +48,8 @@
  */
 
 #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
+MODULE_ID("$Id: lib_raw.c,v 1.21 2012/01/21 19:21:29 KO.Myung-Hun Exp $")
 
 #if HAVE_SYS_TERMIO_H
 #include <sys/termio.h>		/* needed for ISC */
@@ -61,11 +57,16 @@
 
 #ifdef __EMX__
 #include <io.h>
-#define _nc_setmode(mode) setmode(SP->_ifd, mode)
+#define _nc_setmode(mode) setmode(SP_PARM->_ifd, mode)
 #else
 #define _nc_setmode(mode)	/* nothing */
 #endif
 
+#if USE_KLIBC_KBD
+#define INCL_KBD
+#include <os2.h>
+#endif
+
 #define COOKED_INPUT	(IXON|BRKINT|PARMRK)
 
 #ifdef TRACE
@@ -77,188 +78,257 @@
 #endif /* TRACE */
 
 NCURSES_EXPORT(int)
-raw(void)
+NCURSES_SP_NAME(raw) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("raw()")));
-
-    if (SP != 0 && cur_term != 0) {
+    T((T_CALLED("raw(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
 
 	BEFORE("raw");
 	_nc_setmode(O_BINARY);
 
-	buf = cur_term->Nttyb;
+	buf = termp->Nttyb;
 #ifdef TERMIOS
-	buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
-	buf.c_iflag &= ~(COOKED_INPUT);
+	buf.c_lflag &= (unsigned) ~(ICANON | ISIG | IEXTEN);
+	buf.c_iflag &= (unsigned) ~(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;
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+	if (result == OK) {
+#if USE_KLIBC_KBD
+	    KBDINFO kbdinfo;
+
+	    kbdinfo.cb = sizeof(kbdinfo);
+	    KbdGetStatus(&kbdinfo, 0);
+
+	    kbdinfo.cb = sizeof(kbdinfo);
+	    kbdinfo.fsMask &= ~KEYBOARD_ASCII_MODE;
+	    kbdinfo.fsMask |= KEYBOARD_BINARY_MODE;
+	    KbdSetStatus(&kbdinfo, 0);
+#endif
+	    SP_PARM->_raw = TRUE;
+	    SP_PARM->_cbreak = 1;
+	    termp->Nttyb = buf;
 	}
 	AFTER("raw");
     }
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-cbreak(void)
+raw(void)
+{
+    return NCURSES_SP_NAME(raw) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("cbreak()")));
-
-    if (SP != 0 && cur_term != 0) {
+    T((T_CALLED("cbreak(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
 
 	BEFORE("cbreak");
 	_nc_setmode(O_BINARY);
 
-	buf = cur_term->Nttyb;
+	buf = termp->Nttyb;
 #ifdef TERMIOS
-	buf.c_lflag &= ~ICANON;
-	buf.c_iflag &= ~ICRNL;
+	buf.c_lflag &= (unsigned) ~ICANON;
+	buf.c_iflag &= (unsigned) ~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;
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+	if (result == OK) {
+	    SP_PARM->_cbreak = 1;
+	    termp->Nttyb = buf;
 	}
 	AFTER("cbreak");
     }
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+cbreak(void)
+{
+    return NCURSES_SP_NAME(cbreak) (CURRENT_SCREEN);
+}
+#endif
+
 /*
  * Note:
  * this implementation may be wrong.  See the comment under intrflush().
  */
 NCURSES_EXPORT(void)
-qiflush(void)
+NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("qiflush()")));
-
-    if (cur_term != 0) {
+    T((T_CALLED("qiflush(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
 
 	BEFORE("qiflush");
-	buf = cur_term->Nttyb;
+	buf = termp->Nttyb;
 #ifdef TERMIOS
-	buf.c_lflag &= ~(NOFLSH);
-	result = _nc_set_tty_mode(&buf);
+	buf.c_lflag &= (unsigned) ~(NOFLSH);
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
 	/* FIXME */
 #endif
 	if (result == OK)
-	    cur_term->Nttyb = buf;
+	    termp->Nttyb = buf;
 	AFTER("qiflush");
     }
     returnVoid;
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+qiflush(void)
+{
+    NCURSES_SP_NAME(qiflush) (CURRENT_SCREEN);
+}
+#endif
+
 NCURSES_EXPORT(int)
-noraw(void)
+NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("noraw()")));
-
-    if (SP != 0 && cur_term != 0) {
+    T((T_CALLED("noraw(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
 
 	BEFORE("noraw");
 	_nc_setmode(O_TEXT);
 
-	buf = cur_term->Nttyb;
+	buf = termp->Nttyb;
 #ifdef TERMIOS
 	buf.c_lflag |= ISIG | ICANON |
-	    (cur_term->Ottyb.c_lflag & IEXTEN);
+	    (termp->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;
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+	if (result == OK) {
+#if USE_KLIBC_KBD
+	    KBDINFO kbdinfo;
+
+	    kbdinfo.cb = sizeof(kbdinfo);
+	    KbdGetStatus(&kbdinfo, 0);
+
+	    kbdinfo.cb = sizeof(kbdinfo);
+	    kbdinfo.fsMask &= ~KEYBOARD_BINARY_MODE;
+	    kbdinfo.fsMask |= KEYBOARD_ASCII_MODE;
+	    KbdSetStatus(&kbdinfo, 0);
+#endif
+	    SP_PARM->_raw = FALSE;
+	    SP_PARM->_cbreak = 0;
+	    termp->Nttyb = buf;
 	}
 	AFTER("noraw");
     }
     returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-nocbreak(void)
+noraw(void)
+{
+    return NCURSES_SP_NAME(noraw) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("nocbreak()")));
-
-    if (SP != 0 && cur_term != 0) {
+    T((T_CALLED("nocbreak(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
 
 	BEFORE("nocbreak");
 	_nc_setmode(O_TEXT);
 
-	buf = cur_term->Nttyb;
+	buf = termp->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;
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+	if (result == OK) {
+	    SP_PARM->_cbreak = 0;
+	    termp->Nttyb = buf;
 	}
 	AFTER("nocbreak");
     }
     returnCode(result);
 }
 
-/*
- * Note:
- * this implementation may be wrong.  See the comment under intrflush().
- */
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+nocbreak(void)
+{
+    return NCURSES_SP_NAME(nocbreak) (CURRENT_SCREEN);
+}
+#endif
+
 NCURSES_EXPORT(void)
-noqiflush(void)
+NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("noqiflush()")));
-
-    if (cur_term != 0) {
+    T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
 
 	BEFORE("noqiflush");
-	buf = cur_term->Nttyb;
+	buf = termp->Nttyb;
 #ifdef TERMIOS
 	buf.c_lflag |= NOFLSH;
-	result = _nc_set_tty_mode(&buf);
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
 	/* FIXME */
 #endif
-	if (result == OK) {
-	    cur_term->Nttyb = buf;
-	}
+	if (result == OK)
+	    termp->Nttyb = buf;
 	AFTER("noqiflush");
     }
     returnVoid;
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+noqiflush(void)
+{
+    NCURSES_SP_NAME(noqiflush) (CURRENT_SCREEN);
+}
+#endif
+
 /*
  * 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,
@@ -267,30 +337,41 @@
  * curs_inopts(3x) is too exact to be coincidence.
  */
 NCURSES_EXPORT(int)
-intrflush(WINDOW *win GCC_UNUSED, bool flag)
+NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("intrflush(%d)"), flag));
+    T((T_CALLED("intrflush(%p,%d)"), (void *) SP_PARM, flag));
+    if (SP_PARM == 0)
+	returnCode(ERR);
 
-    if (cur_term != 0) {
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
 	TTY buf;
 
 	BEFORE("intrflush");
-	buf = cur_term->Nttyb;
+	buf = termp->Nttyb;
 #ifdef TERMIOS
 	if (flag)
-	    buf.c_lflag &= ~(NOFLSH);
+	    buf.c_lflag &= (unsigned) ~(NOFLSH);
 	else
 	    buf.c_lflag |= (NOFLSH);
-	result = _nc_set_tty_mode(&buf);
+	result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
 	/* FIXME */
 #endif
 	if (result == OK) {
-	    cur_term->Nttyb = buf;
+	    termp->Nttyb = buf;
 	}
 	AFTER("intrflush");
     }
     returnCode(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+intrflush(WINDOW *win GCC_UNUSED, bool flag)
+{
+    return NCURSES_SP_NAME(intrflush) (CURRENT_SCREEN, win, flag);
+}
+#endif
diff --git a/ncurses/tinfo/lib_setup.c b/ncurses/tinfo/lib_setup.c
index 8cfaf12..0a0a1f5 100644
--- a/ncurses/tinfo/lib_setup.c
+++ b/ncurses/tinfo/lib_setup.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,30 +30,25 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
  * Terminal setup routines common to termcap and terminfo:
  *
  *		use_env(bool)
+ *		use_tioctl(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 $")
+MODULE_ID("$Id: lib_setup.c,v 1.164 2015/06/27 18:10:55 tom Exp $")
 
 /****************************************************************************
  *
@@ -109,61 +104,96 @@
  * 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;
+    char *result = empty;
+
+#if NCURSES_SP_FUNCS
+    if (CURRENT_SCREEN) {
+	TERMINAL *termp = TerminalOf(CURRENT_SCREEN);
+	if (termp != 0) {
+	    result = termp->type.term_names;
+	}
+    }
+#else
+    if (cur_term != 0) {
+	result = cur_term->type.term_names;
+    }
+#endif
+    return result;
 }
+
 NCURSES_EXPORT(int *)
-_nc_ptr_Lines(void)
+_nc_ptr_Lines(SCREEN *sp)
 {
-    return ptrLines();
+    return ptrLines(sp);
 }
+
 NCURSES_EXPORT(int)
 NCURSES_PUBLIC_VAR(LINES) (void)
 {
-    return *_nc_ptr_Lines();
+    return *_nc_ptr_Lines(CURRENT_SCREEN);
 }
+
 NCURSES_EXPORT(int *)
-_nc_ptr_Cols(void)
+_nc_ptr_Cols(SCREEN *sp)
 {
-    return ptrCols();
+    return ptrCols(sp);
 }
+
 NCURSES_EXPORT(int)
 NCURSES_PUBLIC_VAR(COLS) (void)
 {
-    return *_nc_ptr_Cols();
+    return *_nc_ptr_Cols(CURRENT_SCREEN);
 }
+
+NCURSES_EXPORT(int *)
+_nc_ptr_Tabsize(SCREEN *sp)
+{
+    return ptrTabsize(sp);
+}
+
 NCURSES_EXPORT(int)
 NCURSES_PUBLIC_VAR(TABSIZE) (void)
 {
-    return SP ? SP->_TABSIZE : 8;
+    return *_nc_ptr_Tabsize(CURRENT_SCREEN);
 }
 #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;
+NCURSES_EXPORT_VAR(int) TABSIZE = 8;
 #endif
 
 #if NCURSES_EXT_FUNCS
 NCURSES_EXPORT(int)
-set_tabsize(int value)
+NCURSES_SP_NAME(set_tabsize) (NCURSES_SP_DCLx int value)
 {
     int code = OK;
 #if USE_REENTRANT
-    if (SP) {
-	SP->_TABSIZE = value;
+    if (SP_PARM) {
+	SP_PARM->_TABSIZE = value;
     } else {
 	code = ERR;
     }
 #else
+    (void) SP_PARM;
     TABSIZE = value;
 #endif
     return code;
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+set_tabsize(int value)
+{
+    return NCURSES_SP_NAME(set_tabsize) (CURRENT_SCREEN, value);
+}
 #endif
+#endif /* NCURSES_EXT_FUNCS */
 
 #if USE_SIGWINCH
 /*
@@ -188,78 +218,157 @@
 #endif
 
 NCURSES_EXPORT(void)
+NCURSES_SP_NAME(use_env) (NCURSES_SP_DCLx bool f)
+{
+    T((T_CALLED("use_env(%p,%d)"), (void *) SP_PARM, (int) f));
+#if NCURSES_SP_FUNCS
+    START_TRACE();
+    if (IsPreScreen(SP_PARM)) {
+	SP_PARM->_use_env = f;
+    }
+#else
+    _nc_prescreen.use_env = f;
+#endif
+    returnVoid;
+}
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(use_tioctl) (NCURSES_SP_DCLx bool f)
+{
+    T((T_CALLED("use_tioctl(%p,%d)"), (void *) SP_PARM, (int) f));
+#if NCURSES_SP_FUNCS
+    START_TRACE();
+    if (IsPreScreen(SP_PARM)) {
+	SP_PARM->_use_tioctl = f;
+    }
+#else
+    _nc_prescreen.use_tioctl = f;
+#endif
+    returnVoid;
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
 use_env(bool f)
 {
-    T((T_CALLED("use_env()")));
+    T((T_CALLED("use_env(%d)"), (int) f));
+    START_TRACE();
     _nc_prescreen.use_env = f;
     returnVoid;
 }
 
 NCURSES_EXPORT(void)
-_nc_get_screensize(SCREEN *sp, int *linep, int *colp)
+use_tioctl(bool f)
+{
+    T((T_CALLED("use_tioctl(%d)"), (int) f));
+    START_TRACE();
+    _nc_prescreen.use_tioctl = f;
+    returnVoid;
+}
+#endif
+
+NCURSES_EXPORT(void)
+_nc_get_screensize(SCREEN *sp,
+#ifdef USE_TERM_DRIVER
+		   TERMINAL * termp,
+#endif
+		   int *linep, int *colp)
 /* Obtain lines/columns values from the environment and/or terminfo entry */
 {
+#ifdef USE_TERM_DRIVER
+    TERMINAL_CONTROL_BLOCK *TCB;
+    int my_tabsize;
+
+    assert(termp != 0 && linep != 0 && colp != 0);
+    TCB = (TERMINAL_CONTROL_BLOCK *) termp;
+
+    my_tabsize = TCB->info.tabsize;
+    TCB->drv->td_size(TCB, linep, colp);
+
+#if USE_REENTRANT
+    if (sp != 0) {
+	sp->_TABSIZE = my_tabsize;
+    }
+#else
+    (void) sp;
+    TABSIZE = my_tabsize;
+#endif
+    T(("TABSIZE = %d", my_tabsize));
+#else /* !USE_TERM_DRIVER */
     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 */
+    *linep = (int) lines;
+    *colp = (int) columns;
+
+    if (_nc_prescreen.use_env || _nc_prescreen.use_tioctl) {
 	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];
+	    *linep = ((sp != 0 && sp->_filtered)
+		      ? 1
+		      : 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;
+	/* try asking the OS */
+	if (NC_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)
+	    errno = 0;
+	    do {
+		if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) >= 0) {
+		    *linep = ((sp != 0 && sp->_filtered)
+			      ? 1
+			      : WINSIZE_ROWS(size));
 		    *colp = WINSIZE_COLS(size);
-	    }
-	    /* FALLTHRU */
-	  failure:;
+		    T(("SYS screen size: environment LINES = %d COLUMNS = %d",
+		       *linep, *colp));
+		    break;
+		}
+	    } while
+		(errno == EINTR);
 	}
 #endif /* HAVE_SIZECHANGE */
 
+	if (_nc_prescreen.use_env) {
+	    if (_nc_prescreen.use_tioctl) {
+		/*
+		 * If environment variables are used, update them.
+		 */
+		if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
+		    _nc_setenv_num("LINES", *linep);
+		}
+		if (_nc_getenv_num("COLUMNS") > 0) {
+		    _nc_setenv_num("COLUMNS", *colp);
+		}
+	    }
+
+	    /*
+	     * Finally, look for environment variables.
+	     *
+	     * Solaris lets users override either dimension with an environment
+	     * variable.
+	     */
+	    if ((value = _nc_getenv_num("LINES")) > 0) {
+		*linep = value;
+		T(("screen size: environment LINES = %d", *linep));
+	    }
+	    if ((value = _nc_getenv_num("COLUMNS")) > 0) {
+		*colp = value;
+		T(("screen size: environment COLUMNS = %d", *colp));
+	    }
+	}
+
 	/* if we can't get dynamic info about the size, use static */
 	if (*linep <= 0) {
 	    *linep = (int) lines;
@@ -298,29 +407,43 @@
     TABSIZE = my_tabsize;
 #endif
     T(("TABSIZE = %d", TABSIZE));
+#endif /* USE_TERM_DRIVER */
 }
 
 #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);
+#ifdef USE_TERM_DRIVER
+    int old_lines;
+    int old_cols;
+
+    assert(sp != 0);
+
+    CallDriver_2(sp, td_getsize, &old_lines, &old_cols);
+
+#else
+    TERMINAL *termp = cur_term;
+    int old_lines = lines;
+    int old_cols = columns;
+#endif
+
+    TINFO_GET_SIZE(sp, sp->_term, &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);
+    if (sp != 0 && sp->_resize != 0) {
+	if ((new_lines != old_lines) || (new_cols != old_cols)) {
+	    sp->_resize(NCURSES_SP_ARGx new_lines, new_cols);
+	} else if (sp->_sig_winch && (sp->_ungetch != 0)) {
+	    sp->_ungetch(SP_PARM, KEY_RESIZE);	/* so application can know this */
+	}
 	sp->_sig_winch = FALSE;
     }
 }
@@ -332,29 +455,13 @@
  *
  ****************************************************************************/
 
-#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
+#if NCURSES_USE_DATABASE || NCURSES_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)
+int
+_nc_setup_tinfo(const char *const tn, TERMTYPE *const tp)
 {
     char filename[PATH_MAX];
     int status = _nc_read_entry(tn, filename, tp);
@@ -381,28 +488,27 @@
 #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)
+void
+_nc_tinfo_cmdch(TERMINAL * termp, int proto)
 {
     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;
-		}
+    /*
+     * Only use the character if the string is a single character,
+     * since it is fairly common for developers to set the C compiler
+     * name as an environment variable - using the same symbol.
+     */
+    if ((tmp = getenv("CC")) != 0 && strlen(tmp) == 1) {
+	CC = *tmp;
+	for_each_string(i, &(termp->type)) {
+	    for (tmp = termp->type.Strings[i]; tmp && *tmp; tmp++) {
+		if (UChar(*tmp) == proto)
+		    *tmp = CC;
 	    }
 	}
     }
@@ -439,7 +545,9 @@
 _nc_unicode_locale(void)
 {
     int result = 0;
-#if HAVE_LANGINFO_CODESET
+#if defined(__MINGW32__) && USE_WIDEC_SUPPORT
+    result = 1;
+#elif HAVE_LANGINFO_CODESET
     char *env = nl_langinfo(CODESET);
     result = !strcmp(env, "UTF-8");
     T(("_nc_unicode_locale(%s) ->%d", env, result));
@@ -465,44 +573,74 @@
 NCURSES_EXPORT(int)
 _nc_locale_breaks_acs(TERMINAL * termp)
 {
-    char *env;
+    const char *env_name = "NCURSES_NO_UTF8_ACS";
+    const char *env;
+    int value;
+    int result = 0;
 
-    if ((env = getenv("NCURSES_NO_UTF8_ACS")) != 0) {
-	return atoi(env);
+    T((T_CALLED("_nc_locale_breaks_acs:%d"), result));
+    if (getenv(env_name) != 0) {
+	result = _nc_getenv_num(env_name);
+    } else if ((value = tigetnum("U8")) >= 0) {
+	result = value;		/* use extension feature */
     } 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 (strstr(env, "linux")) {
+	    result = 1;		/* always broken */
+	} else 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;
+		CONTROL_O(set_attributes)) {
+		result = 1;
+	    }
 	}
     }
-    return 0;
+    returnCode(result);
 }
 
-/*
- * 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)
+TINFO_SETUP_TERM(TERMINAL ** tp,
+		 NCURSES_CONST char *tname,
+		 int Filedes,
+		 int *errret,
+		 int reuse)
 {
-    TERMINAL *termp;
+#ifdef USE_TERM_DRIVER
+    TERMINAL_CONTROL_BLOCK *TCB = 0;
+#else
     int status;
+#endif
+    TERMINAL *termp;
+    SCREEN *sp = 0;
+    int code = ERR;
 
     START_TRACE();
-    T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
+
+#ifdef USE_TERM_DRIVER
+    T((T_CALLED("_nc_setupterm_ex(%p,%s,%d,%p)"),
+       (void *) tp, _nc_visbuf(tname), Filedes, (void *) errret));
+
+    if (tp == 0) {
+	ret_error0(TGETENT_ERR,
+		   "Invalid parameter, internal error.\n");
+    } else
+	termp = *tp;
+#else
+    termp = cur_term;
+    T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, (void *) errret));
+#endif
 
     if (tname == 0) {
 	tname = getenv("TERM");
 	if (tname == 0 || *tname == '\0') {
+#ifdef USE_TERM_DRIVER
+	    tname = "unknown";
+#else
 	    ret_error0(TGETENT_ERR, "TERM environment variable not set.\n");
+#endif
 	}
     }
 
@@ -518,7 +656,7 @@
      * 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))
+    if (Filedes == STDOUT_FILENO && !NC_ISATTY(Filedes))
 	Filedes = STDERR_FILENO;
 
     /*
@@ -538,22 +676,42 @@
      * properly with this feature).
      */
     if (reuse
-	&& (termp = cur_term) != 0
+	&& (termp != 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"));
+	code = OK;
+#ifdef USE_TERM_DRIVER
+	TCB = (TERMINAL_CONTROL_BLOCK *) termp;
+#endif
     } else {
-
+#ifdef USE_TERM_DRIVER
+	TERMINAL_CONTROL_BLOCK *my_tcb;
+	my_tcb = typeCalloc(TERMINAL_CONTROL_BLOCK, 1);
+	termp = &(my_tcb->term);
+#else
 	termp = typeCalloc(TERMINAL, 1);
-
+#endif
 	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);
+#ifdef USE_TERM_DRIVER
+	INIT_TERM_DRIVER();
+	TCB = (TERMINAL_CONTROL_BLOCK *) termp;
+	code = _nc_globals.term_driver(TCB, tname, errret);
+	if (code == OK) {
+	    termp->Filedes = (short) Filedes;
+	    termp->_termname = strdup(tname);
+	} else {
+	    ret_error0(errret ? *errret : TGETENT_ERR,
+		       "Could not find any driver to handle this terminal.\n");
+	}
+#else
+#if NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP
+	status = _nc_setup_tinfo(tname, &termp->type);
 #else
 	status = TGETENT_NO;
 #endif
@@ -563,7 +721,7 @@
 	    const TERMTYPE *fallback = _nc_fallback(tname);
 
 	    if (fallback) {
-		termp->type = *fallback;
+		_nc_copy_termtype(&(termp->type), fallback);
 		status = TGETENT_YES;
 	    }
 	}
@@ -573,21 +731,21 @@
 	    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);
+		ret_error1(status, "unknown terminal type.\n", tname);
 	    }
 	}
 #if !USE_REENTRANT
-	strncpy(ttytype, termp->type.term_names, NAMESIZE - 1);
+	strncpy(ttytype, termp->type.term_names, (size_t) (NAMESIZE - 1));
 	ttytype[NAMESIZE - 1] = '\0';
 #endif
 
-	termp->Filedes = Filedes;
+	termp->Filedes = (short) Filedes;
 	termp->_termname = strdup(tname);
 
 	set_curterm(termp);
 
-	if (command_character && getenv("CC"))
-	    do_prototype(termp);
+	if (command_character)
+	    _nc_tinfo_cmdch(termp, UChar(*command_character));
 
 	/*
 	 * If an application calls setupterm() rather than initscr() or
@@ -595,29 +753,109 @@
 	 * _nc_setupscreen().  Do it now anyway, so we can initialize the
 	 * baudrate.
 	 */
-	if (isatty(Filedes)) {
+	if (NC_ISATTY(Filedes)) {
 	    def_prog_mode();
 	    baudrate();
 	}
+	code = OK;
+#endif
     }
 
+#ifdef USE_TERM_DRIVER
+    *tp = termp;
+    NCURSES_SP_NAME(set_curterm) (sp, termp);
+    TCB->drv->td_init(TCB);
+#else
+    sp = SP;
+#endif
+
     /*
      * We should always check the screensize, just in case.
      */
-    _nc_get_screensize(SP, ptrLines(), ptrCols());
+    TINFO_GET_SIZE(sp, termp, ptrLines(sp), ptrCols(sp));
 
     if (errret)
 	*errret = TGETENT_YES;
 
+#ifndef USE_TERM_DRIVER
     if (generic_type) {
-	ret_error(TGETENT_NO, "'%s': I need something more specific.\n", tname);
+	/*
+	 * BSD 4.3's termcap contains mis-typed "gn" for wy99.  Do a sanity
+	 * check before giving up.
+	 */
+	if ((VALID_STRING(cursor_address)
+	     || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
+	    && VALID_STRING(clear_screen)) {
+	    ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname);
+	} else {
+	    del_curterm(termp);
+	    ret_error1(TGETENT_NO, "I need something more specific.\n", tname);
+	}
+    } else if (hard_copy) {
+	ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname);
     }
-    if (hard_copy) {
-	ret_error(TGETENT_YES, "'%s': I can't handle hardcopy terminals.\n", tname);
-    }
-    returnCode(OK);
+#endif
+    returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
+/*
+ * In case of handling multiple screens, we need to have a screen before
+ * initialization in setupscreen takes place.  This is to extend the substitute
+ * for some of the stuff in _nc_prescreen, especially for slk and ripoff
+ * handling which should be done per screen.
+ */
+NCURSES_EXPORT(SCREEN *)
+new_prescr(void)
+{
+    static SCREEN *sp;
+
+    START_TRACE();
+    T((T_CALLED("new_prescr()")));
+
+    if (sp == 0) {
+	sp = _nc_alloc_screen_sp();
+	if (sp != 0) {
+	    sp->rsp = sp->rippedoff;
+	    sp->_filtered = _nc_prescreen.filter_mode;
+	    sp->_use_env = _nc_prescreen.use_env;
+#if NCURSES_NO_PADDING
+	    sp->_no_padding = _nc_prescreen._no_padding;
+#endif
+	    sp->slk_format = 0;
+	    sp->_slk = 0;
+	    sp->_prescreen = TRUE;
+	    SP_PRE_INIT(sp);
+#if USE_REENTRANT
+	    sp->_TABSIZE = _nc_prescreen._TABSIZE;
+	    sp->_ESCDELAY = _nc_prescreen._ESCDELAY;
+#endif
+	}
+    }
+    returnSP(sp);
+}
+#endif
+
+#ifdef USE_TERM_DRIVER
+/*
+ * 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,
+	      int reuse)
+{
+    int res;
+    TERMINAL *termp = 0;
+    res = TINFO_SETUP_TERM(&termp, tname, Filedes, errret, reuse);
+    if (ERR != res)
+	NCURSES_SP_NAME(set_curterm) (CURRENT_SCREEN_PRE, termp);
+    return res;
+}
+#endif
+
 /*
  *	setupterm(termname, Filedes, errret)
  *
@@ -627,5 +865,6 @@
 NCURSES_EXPORT(int)
 setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
 {
+    START_TRACE();
     return _nc_setupterm(tname, Filedes, errret, FALSE);
 }
diff --git a/ncurses/tinfo/lib_termcap.c b/ncurses/tinfo/lib_termcap.c
index 2d245ff..fdfc494 100644
--- a/ncurses/tinfo/lib_termcap.c
+++ b/ncurses/tinfo/lib_termcap.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                                                 *
  *                                                                          *
  * some of the code in here was contributed by:                             *
  * Magnus Bengtsson, d6mbeng@dtek.chalmers.se (Nov'93)                      *
@@ -43,9 +44,11 @@
 #include <tic.h>
 #include <ctype.h>
 
-#include <term_entry.h>
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-MODULE_ID("$Id: lib_termcap.c,v 1.63 2008/08/16 19:22:55 tom Exp $")
+MODULE_ID("$Id: lib_termcap.c,v 1.80 2013/06/08 16:48:47 tom Exp $")
 
 NCURSES_EXPORT_VAR(char *) UP = 0;
 NCURSES_EXPORT_VAR(char *) BC = 0;
@@ -60,6 +63,15 @@
 #define LAST_USE MyCache[CacheInx].last_used
 #define LAST_SEQ MyCache[CacheInx].sequence
 
+/*
+ * Termcap names are matched only using the first two bytes.
+ * Ignore any extended names longer than two bytes, to avoid problems
+ * with legacy code which passes in parameters whose use is long forgotten.
+ */
+#define ValidCap(cap) (((cap)[0] != '\0') && ((cap)[1] != '\0'))
+#define SameCap(a,b)  (((a)[0] == (b)[0]) && ((a)[1] == (b)[1]))
+#define ValidExt(ext) (ValidCap(ext) && (ext)[2] == '\0')
+
 /***************************************************************************
  *
  * tgetent(bufp, term)
@@ -76,16 +88,26 @@
  ***************************************************************************/
 
 NCURSES_EXPORT(int)
-tgetent(char *bufp, const char *name)
+NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
 {
-    int errcode;
+    int rc = ERR;
     int n;
     bool found_cache = FALSE;
+#ifdef USE_TERM_DRIVER
+    TERMINAL *termp = 0;
+#endif
 
     START_TRACE();
     T((T_CALLED("tgetent()")));
 
-    _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE);
+    TINFO_SETUP_TERM(&termp, (NCURSES_CONST char *) name,
+		     STDOUT_FILENO, &rc, TRUE);
+
+#ifdef USE_TERM_DRIVER
+    if (termp == 0 ||
+	!((TERMINAL_CONTROL_BLOCK *) termp)->drv->isTerminfo)
+	returnCode(rc);
+#endif
 
     /*
      * In general we cannot tell if the fixed sgr0 is still used by the
@@ -109,9 +131,9 @@
 	    /*
 	     * Also free the terminfo data that we loaded (much bigger leak).
 	     */
-	    if (LAST_TRM != 0 && LAST_TRM != cur_term) {
+	    if (LAST_TRM != 0 && LAST_TRM != TerminalOf(SP_PARM)) {
 		TERMINAL *trm = LAST_TRM;
-		del_curterm(LAST_TRM);
+		NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx LAST_TRM);
 		for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx)
 		    if (LAST_TRM == trm)
 			LAST_TRM = 0;
@@ -131,7 +153,7 @@
 	}
 	CacheInx = best;
     }
-    LAST_TRM = cur_term;
+    LAST_TRM = TerminalOf(SP_PARM);
     LAST_SEQ = ++CacheSeq;
 
     PC = 0;
@@ -139,7 +161,7 @@
     BC = 0;
     FIX_SGR0 = 0;		/* don't free it - application may still use */
 
-    if (errcode == 1) {
+    if (rc == 1) {
 
 	if (cursor_left)
 	    if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0)
@@ -153,7 +175,7 @@
 	if (backspace_if_not_bs != NULL)
 	    BC = backspace_if_not_bs;
 
-	if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) {
+	if ((FIX_SGR0 = _nc_trim_sgr0(&(TerminalOf(SP_PARM)->type))) != 0) {
 	    if (!strcmp(FIX_SGR0, exit_attribute_mode)) {
 		if (FIX_SGR0 != exit_attribute_mode) {
 		    free(FIX_SGR0);
@@ -164,8 +186,8 @@
 	LAST_BUF = bufp;
 	LAST_USE = TRUE;
 
-	SetNoPadding(SP);
-	(void) baudrate();	/* sets ospeed as a side-effect */
+	SetNoPadding(SP_PARM);
+	(void) NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG);	/* sets ospeed as a side-effect */
 
 /* LINT_PREPRO
 #if 0*/
@@ -174,9 +196,30 @@
 #endif*/
 
     }
-    returnCode(errcode);
+    returnCode(rc);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+tgetent(char *bufp, const char *name)
+{
+    return NCURSES_SP_NAME(tgetent) (CURRENT_SCREEN, bufp, name);
+}
+#endif
+
+#if 0
+static bool
+same_tcname(const char *a, const char *b)
+{
+    bool code = SameCap(a, b);
+    fprintf(stderr, "compare(%s,%s) %s\n", a, b, code ? "same" : "diff");
+    return code;
+}
+
+#else
+#define same_tcname(a,b) SameCap(a,b)
+#endif
+
 /***************************************************************************
  *
  * tgetflag(str)
@@ -187,24 +230,48 @@
  ***************************************************************************/
 
 NCURSES_EXPORT(int)
-tgetflag(NCURSES_CONST char *id)
+NCURSES_SP_NAME(tgetflag) (NCURSES_SP_DCLx NCURSES_CONST char *id)
 {
-    unsigned i;
+    int result = 0;		/* Solaris returns zero for missing flag */
+    int j = -1;
 
-    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]);
+    T((T_CALLED("tgetflag(%p, %s)"), (void *) SP_PARM, id));
+    if (HasTInfoTerminal(SP_PARM) && ValidCap(id)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(id, BOOLEAN, TRUE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_boolean(i, tp) {
+		const char *capname = ExtBoolname(tp, i, boolcodes);
+		if (same_tcname(id, capname) && ValidExt(capname)) {
+		    j = i;
+		    break;
+		}
 	    }
 	}
+#endif
+	if (j >= 0) {
+	    /* note: setupterm forces invalid booleans to false */
+	    result = tp->Booleans[j];
+	}
     }
-    returnCode(0);		/* Solaris does this */
+    returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+tgetflag(NCURSES_CONST char *id)
+{
+    return NCURSES_SP_NAME(tgetflag) (CURRENT_SCREEN, id);
+}
+#endif
+
 /***************************************************************************
  *
  * tgetnum(str)
@@ -215,25 +282,48 @@
  ***************************************************************************/
 
 NCURSES_EXPORT(int)
-tgetnum(NCURSES_CONST char *id)
+NCURSES_SP_NAME(tgetnum) (NCURSES_SP_DCLx NCURSES_CONST char *id)
 {
-    unsigned i;
+    int result = ABSENT_NUMERIC;
+    int j = -1;
 
-    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]);
+    T((T_CALLED("tgetnum(%p, %s)"), (void *) SP_PARM, id));
+    if (HasTInfoTerminal(SP_PARM) && ValidCap(id)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(id, NUMBER, TRUE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_number(i, tp) {
+		const char *capname = ExtNumname(tp, i, numcodes);
+		if (same_tcname(id, capname) && ValidExt(capname)) {
+		    j = i;
+		    break;
+		}
 	    }
 	}
+#endif
+	if (j >= 0) {
+	    if (VALID_NUMERIC(tp->Numbers[j]))
+		result = tp->Numbers[j];
+	}
     }
-    returnCode(ABSENT_NUMERIC);
+    returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+tgetnum(NCURSES_CONST char *id)
+{
+    return NCURSES_SP_NAME(tgetnum) (CURRENT_SCREEN, id);
+}
+#endif
+
 /***************************************************************************
  *
  * tgetstr(str, area)
@@ -244,40 +334,62 @@
  ***************************************************************************/
 
 NCURSES_EXPORT(char *)
-tgetstr(NCURSES_CONST char *id, char **area)
+NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx NCURSES_CONST char *id, char **area)
 {
-    unsigned i;
     char *result = NULL;
+    int j = -1;
 
-    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;
-		    }
+    T((T_CALLED("tgetstr(%s,%p)"), id, (void *) area));
+    if (HasTInfoTerminal(SP_PARM) && ValidCap(id)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(id, STRING, TRUE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_string(i, tp) {
+		const char *capname = ExtStrname(tp, i, strcodes);
+		if (same_tcname(id, capname) && ValidExt(capname)) {
+		    j = i;
+		    break;
 		}
-		break;
+	    }
+	}
+#endif
+	if (j >= 0) {
+	    result = tp->Strings[j];
+	    TR(TRACE_DATABASE, ("found match %d: %s", j, _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) {
+		    _nc_STRCPY(*area, result, 1024);
+		    result = *area;
+		    *area += strlen(*area) + 1;
+		}
 	    }
 	}
     }
     returnPtr(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char *)
+tgetstr(NCURSES_CONST char *id, char **area)
+{
+    return NCURSES_SP_NAME(tgetstr) (CURRENT_SCREEN, id, area);
+}
+#endif
+
 #if NO_LEAKS
 NCURSES_EXPORT(void)
 _nc_tgetent_leaks(void)
diff --git a/ncurses/tinfo/lib_termname.c b/ncurses/tinfo/lib_termname.c
index 713d0be..e3f6827 100644
--- a/ncurses/tinfo/lib_termname.c
+++ b/ncurses/tinfo/lib_termname.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2003,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -28,17 +28,31 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_termname.c,v 1.8 2003/12/27 18:23:01 tom Exp $")
+MODULE_ID("$Id: lib_termname.c,v 1.12 2009/10/24 21:56:58 tom Exp $")
 
 NCURSES_EXPORT(char *)
-termname(void)
+NCURSES_SP_NAME(termname) (NCURSES_SP_DCL0)
 {
     char *name = 0;
 
-    T((T_CALLED("termname()")));
+    T((T_CALLED("termname(%p)"), (void *) SP_PARM));
 
+#if NCURSES_SP_FUNCS
+    if (TerminalOf(SP_PARM) != 0) {
+	name = TerminalOf(SP_PARM)->_termname;
+    }
+#else
     if (cur_term != 0)
 	name = cur_term->_termname;
+#endif
 
     returnPtr(name);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char *)
+termname(void)
+{
+    return NCURSES_SP_NAME(termname) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/tinfo/lib_tgoto.c b/ncurses/tinfo/lib_tgoto.c
index e07f464..31daf44 100644
--- a/ncurses/tinfo/lib_tgoto.c
+++ b/ncurses/tinfo/lib_tgoto.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2000-2006,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2000-2008,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,7 +35,7 @@
 #include <ctype.h>
 #include <termcap.h>
 
-MODULE_ID("$Id: lib_tgoto.c,v 1.13 2008/08/16 19:29:32 tom Exp $")
+MODULE_ID("$Id: lib_tgoto.c,v 1.16 2012/02/24 02:08:08 tom Exp $")
 
 #if !PURE_TERMINFO
 static bool
@@ -159,7 +159,8 @@
 		break;
 	    }
 	    if (fmt != 0) {
-		sprintf(result + used, fmt, *value++);
+		_nc_SPRINTF(result + used, _nc_SLIMIT(length - used)
+			    fmt, *value++);
 		used += strlen(result + used);
 		fmt = 0;
 	    }
@@ -174,7 +175,7 @@
     }
     if (result != 0) {
 	if (need_BC) {
-	    strcpy(result + used, BC);
+	    _nc_STRCPY(result + used, BC, length - used);
 	    used += strlen(BC);
 	}
 	result[used] = '\0';
diff --git a/ncurses/tinfo/lib_ti.c b/ncurses/tinfo/lib_ti.c
index df460f9..e9ae746 100644
--- a/ncurses/tinfo/lib_ti.c
+++ b/ncurses/tinfo/lib_ti.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,75 +29,159 @@
 /****************************************************************************
  *  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_entry.h>
 #include <tic.h>
 
-MODULE_ID("$Id: lib_ti.c,v 1.23 2003/05/24 21:10:28 tom Exp $")
+MODULE_ID("$Id: lib_ti.c,v 1.30 2013/06/08 16:55:05 tom Exp $")
 
+#if 0
+static bool
+same_name(const char *a, const char *b)
+{
+    fprintf(stderr, "compare(%s,%s)\n", a, b);
+    return !strcmp(a, b);
+}
+#else
+#define same_name(a,b) !strcmp(a,b)
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
+{
+    int result = ABSENT_BOOLEAN;
+    int j = -1;
+
+    T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
+
+    if (HasTInfoTerminal(SP_PARM)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_boolean(i, tp) {
+		const char *capname = ExtBoolname(tp, i, boolnames);
+		if (same_name(str, capname)) {
+		    j = i;
+		    break;
+		}
+	    }
+	}
+#endif
+	if (j >= 0) {
+	    /* note: setupterm forces invalid booleans to false */
+	    result = tp->Booleans[j];
+	}
+    }
+
+    returnCode(result);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 tigetflag(NCURSES_CONST char *str)
 {
-    unsigned i;
+    return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
+}
+#endif
 
-    T((T_CALLED("tigetflag(%s)"), str));
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
+{
+    int j = -1;
+    int result = CANCELLED_NUMERIC;	/* Solaris returns a -1 on error */
 
-    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]);
+    T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str));
+
+    if (HasTInfoTerminal(SP_PARM)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_number(i, tp) {
+		const char *capname = ExtNumname(tp, i, numnames);
+		if (same_name(str, capname)) {
+		    j = i;
+		    break;
+		}
 	    }
 	}
+#endif
+	if (j >= 0) {
+	    if (VALID_NUMERIC(tp->Numbers[j]))
+		result = tp->Numbers[j];
+	    else
+		result = ABSENT_NUMERIC;
+	}
     }
 
-    returnCode(ABSENT_BOOLEAN);
+    returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 tigetnum(NCURSES_CONST char *str)
 {
-    unsigned i;
+    return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
+}
+#endif
 
-    T((T_CALLED("tigetnum(%s)"), str));
+NCURSES_EXPORT(char *)
+NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
+{
+    char *result = CANCELLED_STRING;
+    int j = -1;
 
-    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]);
+    T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));
+
+    if (HasTInfoTerminal(SP_PARM)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_string(i, tp) {
+		const char *capname = ExtStrname(tp, i, strnames);
+		if (same_name(str, capname)) {
+		    j = i;
+		    break;
+		}
 	    }
 	}
+#endif
+	if (j >= 0) {
+	    /* note: setupterm forces cancelled strings to null */
+	    result = tp->Strings[j];
+	}
     }
 
-    returnCode(CANCELLED_NUMERIC);	/* Solaris returns a -1 instead */
+    returnPtr(result);
 }
 
+#if NCURSES_SP_FUNCS
 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);
+    return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
 }
+#endif
diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c
index ba2a840..4f18859 100644
--- a/ncurses/tinfo/lib_tparm.c
+++ b/ncurses/tinfo/lib_tparm.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,10 +40,9 @@
 #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 $")
+MODULE_ID("$Id: lib_tparm.c,v 1.94 2015/07/17 01:03:35 tom Exp $")
 
 /*
  *	char *
@@ -54,7 +53,7 @@
  *
  *	     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
+ *	capability, with escapes like %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
@@ -108,6 +107,7 @@
 NCURSES_EXPORT_VAR(int) _nc_tparm_err = 0;
 
 #define TPS(var) _nc_prescreen.tparm_state.var
+#define popcount _nc_popcount	/* workaround for NetBSD 6.0 defect */
 
 #if NO_LEAKS
 NCURSES_EXPORT(void)
@@ -129,9 +129,7 @@
     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);
+	TYPE_REALLOC(char, TPS(out_size), TPS(out_buff));
     }
 }
 
@@ -140,11 +138,13 @@
 {
     size_t s_len = strlen(s);
     if (len > (int) s_len)
-	s_len = len;
+	s_len = (size_t) len;
 
     get_space(s_len + 1);
 
-    (void) sprintf(TPS(out_buff) + TPS(out_used), fmt, s);
+    _nc_SPRINTF(TPS(out_buff) + TPS(out_used),
+		_nc_SLIMIT(TPS(out_size) - TPS(out_used))
+		fmt, s);
     TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used));
 }
 
@@ -154,9 +154,11 @@
     if (len < 30)
 	len = 30;		/* actually log10(MAX_INT)+1 */
 
-    get_space((unsigned) len + 1);
+    get_space((size_t) len + 1);
 
-    (void) sprintf(TPS(out_buff) + TPS(out_used), fmt, number);
+    _nc_SPRINTF(TPS(out_buff) + TPS(out_used),
+		_nc_SLIMIT(TPS(out_size) - TPS(out_used))
+		fmt, number);
     TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used));
 }
 
@@ -165,7 +167,7 @@
 {
     if (c == 0)
 	c = 0200;
-    get_space(1);
+    get_space((size_t) 1);
     TPS(out_buff)[TPS(out_used)++] = (char) c;
 }
 
@@ -251,6 +253,9 @@
 	    case 'x':		/* FALLTHRU */
 	    case 'X':		/* FALLTHRU */
 	    case 's':
+#ifdef EXP_XTERM_1005
+	    case 'u':
+#endif
 		*format++ = *s;
 		done = TRUE;
 		break;
@@ -370,6 +375,9 @@
 	    case 'x':		/* FALLTHRU */
 	    case 'X':		/* FALLTHRU */
 	    case 'c':		/* FALLTHRU */
+#ifdef EXP_XTERM_1005
+	    case 'u':
+#endif
 		if (lastpop <= 0)
 		    number++;
 		lastpop = -1;
@@ -451,18 +459,21 @@
 }
 
 static NCURSES_INLINE char *
-tparam_internal(const char *string, va_list ap)
+tparam_internal(int use_TPARM_ARG, const char *string, va_list ap)
 {
     char *p_is_s[NUM_PARM];
     TPARM_ARG param[NUM_PARM];
-    int popcount;
+    int popcount = 0;
     int number;
+    int num_args;
     int len;
     int level;
     int x, y;
     int i;
     const char *cp = string;
     size_t len2;
+    bool termcap_hack;
+    bool incremented_two;
 
     if (cp == NULL)
 	return NULL;
@@ -479,7 +490,15 @@
     if (TPS(fmt_buff) == 0)
 	return NULL;
 
-    for (i = 0; i < max(popcount, number); i++) {
+    incremented_two = FALSE;
+
+    if (number > NUM_PARM)
+	number = NUM_PARM;
+    if (popcount > NUM_PARM)
+	popcount = NUM_PARM;
+    num_args = max(popcount, number);
+
+    for (i = 0; i < num_args; i++) {
 	/*
 	 * A few caps (such as plab_norm) have string-valued parms.
 	 * We'll have to assume that the caller knows the difference, since
@@ -489,8 +508,11 @@
 	 */
 	if (p_is_s[i] != 0) {
 	    p_is_s[i] = va_arg(ap, char *);
-	} else {
+	    param[i] = 0;
+	} else if (use_TPARM_ARG) {
 	    param[i] = va_arg(ap, TPARM_ARG);
+	} else {
+	    param[i] = (TPARM_ARG) va_arg(ap, int);
 	}
     }
 
@@ -502,22 +524,24 @@
      * style, which means tparam() will expand termcap strings OK.
      */
     TPS(stack_ptr) = 0;
+    termcap_hack = FALSE;
     if (popcount == 0) {
+	termcap_hack = TRUE;
 	popcount = number;
 	for (i = number - 1; i >= 0; i--) {
 	    if (p_is_s[i])
 		spush(p_is_s[i]);
 	    else
-		npush(param[i]);
+		npush((int) param[i]);
 	}
     }
 #ifdef TRACE
     if (USE_TRACEF(TRACE_CALLS)) {
-	for (i = 0; i < popcount; i++) {
+	for (i = 0; i < num_args; i++) {
 	    if (p_is_s[i] != 0)
 		save_text(", %s", _nc_visbuf(p_is_s[i]), 0);
 	    else
-		save_number(", %d", param[i], 0);
+		save_number(", %d", (int) param[i], 0);
 	}
 	_tracef(T_CALLED("%s(%s%s)"), TPS(tname), _nc_visbuf(cp), TPS(out_buff));
 	TPS(out_used) = 0;
@@ -549,8 +573,22 @@
 		save_char(npop());
 		break;
 
+#ifdef EXP_XTERM_1005
+	    case 'u':
+		{
+		    unsigned char target[10];
+		    unsigned source = (unsigned) npop();
+		    int rc = _nc_conv_to_utf8(target, source, (unsigned)
+					      sizeof(target));
+		    int n;
+		    for (n = 0; n < rc; ++n) {
+			save_char(target[n]);
+		    }
+		}
+		break;
+#endif
 	    case 'l':
-		save_number("%d", (int) strlen(spop()), 0);
+		npush((int) strlen(spop()));
 		break;
 
 	    case 's':
@@ -561,10 +599,11 @@
 		cp++;
 		i = (UChar(*cp) - '1');
 		if (i >= 0 && i < NUM_PARM) {
-		    if (p_is_s[i])
+		    if (p_is_s[i]) {
 			spush(p_is_s[i]);
-		    else
-			npush(param[i]);
+		    } else {
+			npush((int) param[i]);
+		    }
 		}
 		break;
 
@@ -633,11 +672,15 @@
 		break;
 
 	    case 'A':
-		npush(npop() && npop());
+		y = npop();
+		x = npop();
+		npush(y && x);
 		break;
 
 	    case 'O':
-		npush(npop() || npop());
+		y = npop();
+		x = npop();
+		npush(y || x);
 		break;
 
 	    case '&':
@@ -679,10 +722,26 @@
 		break;
 
 	    case 'i':
-		if (p_is_s[0] == 0)
-		    param[0]++;
-		if (p_is_s[1] == 0)
-		    param[1]++;
+		/*
+		 * Increment the first two parameters -- if they are numbers
+		 * rather than strings.  As a side effect, assign into the
+		 * stack; if this is termcap, then the stack was populated
+		 * using the termcap hack above rather than via the terminfo
+		 * 'p' case.
+		 */
+		if (!incremented_two) {
+		    incremented_two = TRUE;
+		    if (p_is_s[0] == 0) {
+			param[0]++;
+			if (termcap_hack)
+			    TPS(stack)[0].data.num = (int) param[0];
+		    }
+		    if (p_is_s[1] == 0) {
+			param[1]++;
+			if (termcap_hack)
+			    TPS(stack)[1].data.num = (int) param[1];
+		    }
+		}
 		break;
 
 	    case '?':
@@ -748,7 +807,7 @@
 	cp++;
     }				/* endwhile (*cp) */
 
-    get_space(1);
+    get_space((size_t) 1);
     TPS(out_buff)[TPS(out_used)] = '\0';
 
     T((T_RETURN("%s"), _nc_visbuf(TPS(out_buff))));
@@ -772,7 +831,7 @@
 #ifdef TRACE
     TPS(tname) = "tparm";
 #endif /* TRACE */
-    result = tparam_internal(string, ap);
+    result = tparam_internal(TRUE, string, ap);
     va_end(ap);
     return result;
 }
@@ -793,3 +852,19 @@
     return tparm_varargs(string, a1, a2, a3, a4, a5, a6, a7, a8, a9);
 }
 #endif /* NCURSES_TPARM_VARARGS */
+
+NCURSES_EXPORT(char *)
+tiparm(const char *string,...)
+{
+    va_list ap;
+    char *result;
+
+    _nc_tparm_err = 0;
+    va_start(ap, string);
+#ifdef TRACE
+    TPS(tname) = "tiparm";
+#endif /* TRACE */
+    result = tparam_internal(FALSE, string, ap);
+    va_end(ap);
+    return result;
+}
diff --git a/ncurses/tinfo/lib_tputs.c b/ncurses/tinfo/lib_tputs.c
index a8b7276..09cbbc2 100644
--- a/ncurses/tinfo/lib_tputs.c
+++ b/ncurses/tinfo/lib_tputs.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -41,12 +42,16 @@
  */
 
 #include <curses.priv.h>
+
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
 #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 $")
+MODULE_ID("$Id: lib_tputs.c,v 1.96 2015/01/03 23:51:23 tom Exp $")
 
 NCURSES_EXPORT_VAR(char) PC = 0;              /* used by termcap library */
 NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0;        /* used by termcap library */
@@ -69,63 +74,195 @@
 }
 #endif
 
-static int (*my_outch) (int c) = _nc_outch;
+#if NCURSES_SP_FUNCS
+#define SetOutCh(func) if (SP_PARM) SP_PARM->_outch = func; else _nc_prescreen._outch = func
+#define GetOutCh()     (SP_PARM ? SP_PARM->_outch : _nc_prescreen._outch)
+#else
+#define SetOutCh(func) static_outch = func
+#define GetOutCh()     static_outch
+static NCURSES_SP_OUTC static_outch = NCURSES_SP_NAME(_nc_outch);
+#endif
 
 NCURSES_EXPORT(int)
-delay_output(int ms)
+NCURSES_SP_NAME(delay_output) (NCURSES_SP_DCLx int ms)
 {
-    T((T_CALLED("delay_output(%d)"), ms));
+    T((T_CALLED("delay_output(%p,%d)"), (void *) SP_PARM, ms));
+
+    if (!HasTInfoTerminal(SP_PARM))
+	returnCode(ERR);
 
     if (no_pad_char) {
-	_nc_flush();
+	NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
 	napms(ms);
     } else {
+	NCURSES_SP_OUTC my_outch = GetOutCh();
 	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();
+	    my_outch(NCURSES_SP_ARGx PC);
+	if (my_outch == NCURSES_SP_NAME(_nc_outch))
+	    NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
     }
 
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+delay_output(int ms)
+{
+    return NCURSES_SP_NAME(delay_output) (CURRENT_SCREEN, ms);
+}
+#endif
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_DCL0)
+{
+    if (SP_PARM != 0 && SP_PARM->_ofd >= 0) {
+	if (SP_PARM->out_inuse) {
+	    char *buf = SP_PARM->out_buffer;
+	    size_t amount = SP->out_inuse;
+	    ssize_t res;
+
+	    SP->out_inuse = 0;
+	    while (amount) {
+		res = write(SP_PARM->_ofd, buf, amount);
+
+		if (res > 0) {
+		    /* if the write was incomplete, try again */
+		    amount -= (size_t) res;
+		    buf += res;
+		} else if (errno == EAGAIN) {
+		    continue;
+		} else if (errno == EINTR) {
+		    continue;
+		} else {
+		    break;	/* an error we can not recover from */
+		}
+	    }
+	}
+    }
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(void)
 _nc_flush(void)
 {
-    (void) fflush(NC_OUTPUT);
+    NCURSES_SP_NAME(_nc_flush) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_outch) (NCURSES_SP_DCLx int ch)
+{
+    int rc = OK;
+
+    COUNT_OUTCHARS(1);
+
+    if (HasTInfoTerminal(SP_PARM)
+	&& SP_PARM != 0) {
+	if (SP_PARM->out_buffer != 0) {
+	    if (SP_PARM->out_inuse + 1 >= SP_PARM->out_limit)
+		NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
+	    SP_PARM->out_buffer[SP_PARM->out_inuse++] = (char) ch;
+	} else {
+	    char tmp = (char) ch;
+	    /*
+	     * POSIX says write() is safe in a signal handler, but the
+	     * buffered I/O is not.
+	     */
+	    if (write(fileno(NC_OUTPUT(SP_PARM)), &tmp, (size_t) 1) == -1)
+		rc = ERR;
+	}
+    } else {
+	char tmp = (char) ch;
+	if (write(fileno(stdout), &tmp, (size_t) 1) == -1)
+	    rc = ERR;
+    }
+    return rc;
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 _nc_outch(int ch)
 {
-    COUNT_OUTCHARS(1);
+    return NCURSES_SP_NAME(_nc_outch) (CURRENT_SCREEN, ch);
+}
+#endif
 
-    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;
+/*
+ * This is used for the putp special case.
+ */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_putchar) (NCURSES_SP_DCLx int ch)
+{
+    (void) SP_PARM;
+    return putchar(ch);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_putchar(int ch)
+{
+    return putchar(ch);
+}
+#endif
+
+/*
+ * putp is special - per documentation it calls tputs with putchar as the
+ * parameter for outputting characters.  This means that it uses stdio, which
+ * is not signal-safe.  Applications call this entrypoint; we do not call it
+ * from within the library.
+ */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(putp) (NCURSES_SP_DCLx const char *string)
+{
+    return NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				   string, 1, NCURSES_SP_NAME(_nc_putchar));
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 putp(const char *string)
 {
-    return tputs(string, 1, _nc_outch);
+    return NCURSES_SP_NAME(putp) (CURRENT_SCREEN, string);
+}
+#endif
+
+/*
+ * Use these entrypoints rather than "putp" within the library.
+ */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_putp) (NCURSES_SP_DCLx
+			   const char *name GCC_UNUSED,
+			   const char *string)
+{
+    int rc = ERR;
+
+    if (string != 0) {
+	TPUTS_TRACE(name);
+	rc = NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				     string, 1, NCURSES_SP_NAME(_nc_outch));
+    }
+    return rc;
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-tputs(const char *string, int affcnt, int (*outc) (int))
+_nc_putp(const char *name, const char *string)
 {
+    return NCURSES_SP_NAME(_nc_putp) (CURRENT_SCREEN, name, string);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(tputs) (NCURSES_SP_DCLx
+			const char *string,
+			int affcnt,
+			NCURSES_SP_OUTC outc)
+{
+    NCURSES_SP_OUTC my_outch = GetOutCh();
     bool always_delay;
     bool normal_delay;
     int number;
@@ -137,10 +274,10 @@
     char addrbuf[32];
 
     if (USE_TRACEF(TRACE_TPUTS)) {
-	if (outc == _nc_outch)
-	    (void) strcpy(addrbuf, "_nc_outch");
+	if (outc == NCURSES_SP_NAME(_nc_outch))
+	    _nc_STRCPY(addrbuf, "_nc_outch", sizeof(addrbuf));
 	else
-	    (void) sprintf(addrbuf, "%p", outc);
+	    _nc_SPRINTF(addrbuf, _nc_SLIMIT(sizeof(addrbuf)) "%p", outc);
 	if (_nc_tputs_trace) {
 	    _tracef("tputs(%s = %s, %d, %s) called", _nc_tputs_trace,
 		    _nc_visbuf(string), affcnt, addrbuf);
@@ -152,10 +289,19 @@
     }
 #endif /* TRACE */
 
+    if (SP_PARM != 0 && !HasTInfoTerminal(SP_PARM))
+	return ERR;
+
     if (!VALID_STRING(string))
 	return ERR;
 
-    if (cur_term == 0) {
+    if (
+#if NCURSES_SP_FUNCS
+	   (SP_PARM != 0 && SP_PARM->_term == 0)
+#else
+	   cur_term == 0
+#endif
+	) {
 	always_delay = FALSE;
 	normal_delay = TRUE;
     } else {
@@ -164,7 +310,7 @@
 	    !xon_xoff
 	    && padding_baud_rate
 #if NCURSES_NO_PADDING
-	    && !GetNoPadding(SP)
+	    && !GetNoPadding(SP_PARM)
 #endif
 	    && (_nc_baudrate(ospeed) >= padding_baud_rate);
     }
@@ -198,24 +344,24 @@
     }
 #endif /* BSD_TPUTS */
 
-    my_outch = outc;		/* redirect delay_output() */
+    SetOutCh(outc);		/* redirect delay_output() */
     while (*string) {
 	if (*string != '$')
-	    (*outc) (*string);
+	    (*outc) (NCURSES_SP_ARGx *string);
 	else {
 	    string++;
 	    if (*string != '<') {
-		(*outc) ('$');
+		(*outc) (NCURSES_SP_ARGx '$');
 		if (*string)
-		    (*outc) (*string);
+		    (*outc) (NCURSES_SP_ARGx *string);
 	    } else {
 		bool mandatory;
 
 		string++;
 		if ((!isdigit(UChar(*string)) && *string != '.')
 		    || !strchr(string, '>')) {
-		    (*outc) ('$');
-		    (*outc) ('<');
+		    (*outc) (NCURSES_SP_ARGx '$');
+		    (*outc) (NCURSES_SP_ARGx '<');
 		    continue;
 		}
 
@@ -250,7 +396,7 @@
 		    && (always_delay
 			|| normal_delay
 			|| mandatory))
-		    delay_output(number / 10);
+		    NCURSES_SP_NAME(delay_output) (NCURSES_SP_ARGx number / 10);
 
 	    }			/* endelse (*string == '<') */
 	}			/* endelse (*string == '$') */
@@ -270,6 +416,25 @@
 	delay_output(trailpad / 10);
 #endif /* BSD_TPUTS */
 
-    my_outch = _nc_outch;
+    SetOutCh(my_outch);
     return OK;
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_outc_wrapper(SCREEN *sp, int c)
+{
+    if (0 == sp) {
+	return (ERR);
+    } else {
+	return sp->jump(c);
+    }
+}
+
+NCURSES_EXPORT(int)
+tputs(const char *string, int affcnt, int (*outc) (int))
+{
+    SetSafeOutcWrapper(outc);
+    return NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx string, affcnt, _nc_outc_wrapper);
+}
+#endif
diff --git a/ncurses/tinfo/lib_ttyflags.c b/ncurses/tinfo/lib_ttyflags.c
index a2b38a3..43bed35 100644
--- a/ncurses/tinfo/lib_ttyflags.c
+++ b/ncurses/tinfo/lib_ttyflags.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -36,159 +36,248 @@
  */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_ttyflags.c,v 1.30 2014/04/26 18:47:20 juergen Exp $")
 
 NCURSES_EXPORT(int)
-_nc_get_tty_mode(TTY * buf)
+NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
 {
     int result = OK;
 
-    if (buf == 0) {
+    if (buf == 0 || SP_PARM == 0) {
 	result = ERR;
     } else {
-	if (cur_term == 0) {
+	TERMINAL *termp = TerminalOf(SP_PARM);
+
+	if (0 == termp) {
 	    result = ERR;
 	} else {
+#ifdef USE_TERM_DRIVER
+	    result = CallDriver_2(SP_PARM, td_sgmode, FALSE, buf);
+#else
 	    for (;;) {
-		if (GET_TTY(cur_term->Filedes, buf) != 0) {
+		if (GET_TTY(termp->Filedes, buf) != 0) {
 		    if (errno == EINTR)
 			continue;
 		    result = ERR;
 		}
 		break;
 	    }
+#endif
 	}
 
 	if (result == ERR)
 	    memset(buf, 0, sizeof(*buf));
 
 	TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
-			cur_term ? cur_term->Filedes : -1,
+			termp ? termp->Filedes : -1,
 			_nc_trace_ttymode(buf)));
     }
     return (result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-_nc_set_tty_mode(TTY * buf)
+_nc_get_tty_mode(TTY * buf)
+{
+    return NCURSES_SP_NAME(_nc_get_tty_mode) (CURRENT_SCREEN, buf);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_DCLx TTY * buf)
 {
     int result = OK;
 
-    if (buf == 0) {
+    if (buf == 0 || SP_PARM == 0) {
 	result = ERR;
     } else {
-	if (cur_term == 0) {
+	TERMINAL *termp = TerminalOf(SP_PARM);
+
+	if (0 == termp) {
 	    result = ERR;
 	} else {
+#ifdef USE_TERM_DRIVER
+	    result = CallDriver_2(SP_PARM, td_sgmode, TRUE, buf);
+#else
 	    for (;;) {
-		if (SET_TTY(cur_term->Filedes, buf) != 0) {
+		if ((SET_TTY(termp->Filedes, buf) != 0)
+#if USE_KLIBC_KBD
+		    && !NC_ISATTY(termp->Filedes)
+#endif
+		    ) {
 		    if (errno == EINTR)
 			continue;
-		    if ((errno == ENOTTY) && (SP != 0))
-			SP->_notty = TRUE;
+		    if ((errno == ENOTTY) && (SP_PARM != 0))
+			SP_PARM->_notty = TRUE;
 		    result = ERR;
 		}
 		break;
 	    }
+#endif
 	}
 	TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
-			cur_term ? cur_term->Filedes : -1,
+			termp ? termp->Filedes : -1,
 			_nc_trace_ttymode(buf)));
     }
     return (result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-def_shell_mode(void)
+_nc_set_tty_mode(TTY * buf)
+{
+    return NCURSES_SP_NAME(_nc_set_tty_mode) (CURRENT_SCREEN, buf);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0)
 {
     int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    T((T_CALLED("def_shell_mode()")));
+    T((T_CALLED("def_shell_mode(%p)"), (void *) SP_PARM));
 
-    if (cur_term != 0) {
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+	rc = CallDriver_2(SP_PARM, td_mode, FALSE, TRUE);
+#else
 	/*
 	 * If XTABS was on, remove the tab and backtab capabilities.
 	 */
-	if (_nc_get_tty_mode(&cur_term->Ottyb) == OK) {
+	if (_nc_get_tty_mode(&termp->Ottyb) == OK) {
 #ifdef TERMIOS
-	    if (cur_term->Ottyb.c_oflag & OFLAGS_TABS)
+	    if (termp->Ottyb.c_oflag & OFLAGS_TABS)
 		tab = back_tab = NULL;
 #else
-	    if (cur_term->Ottyb.sg_flags & XTABS)
+	    if (termp->Ottyb.sg_flags & XTABS)
 		tab = back_tab = NULL;
 #endif
 	    rc = OK;
 	}
+#endif
     }
     returnCode(rc);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-def_prog_mode(void)
+def_shell_mode(void)
+{
+    return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
 {
     int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    T((T_CALLED("def_prog_mode()")));
+    T((T_CALLED("def_prog_mode(%p)"), (void *) SP_PARM));
 
-    if (cur_term != 0) {
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+	rc = CallDriver_2(SP_PARM, td_mode, TRUE, TRUE);
+#else
 	/*
 	 * Turn off the XTABS bit in the tty structure if it was on.
 	 */
-	if (_nc_get_tty_mode(&cur_term->Nttyb) == OK) {
+	if (_nc_get_tty_mode(&termp->Nttyb) == OK) {
 #ifdef TERMIOS
-	    cur_term->Nttyb.c_oflag &= ~OFLAGS_TABS;
+	    termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
 #else
-	    cur_term->Nttyb.sg_flags &= ~XTABS;
+	    termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
 #endif
 	    rc = OK;
 	}
+#endif
     }
     returnCode(rc);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+def_prog_mode(void)
+{
+    return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
+{
+    int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
+
+    T((T_CALLED("reset_prog_mode(%p)"), (void *) SP_PARM));
+
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+	rc = CallDriver_2(SP_PARM, td_mode, TRUE, FALSE);
+#else
+	if (_nc_set_tty_mode(&termp->Nttyb) == OK) {
+	    if (SP_PARM) {
+		if (SP_PARM->_keypad_on)
+		    _nc_keypad(SP_PARM, TRUE);
+	    }
+	    rc = OK;
+	}
+#endif
+    }
+    returnCode(rc);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 reset_prog_mode(void)
 {
-    T((T_CALLED("reset_prog_mode()")));
+    return NCURSES_SP_NAME(reset_prog_mode) (CURRENT_SCREEN);
+}
+#endif
 
-    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);
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0)
+{
+    int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
+
+    T((T_CALLED("reset_shell_mode(%p)"), (void *) SP_PARM));
+
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+	rc = CallDriver_2(SP_PARM, td_mode, FALSE, FALSE);
+#else
+	if (SP_PARM) {
+	    _nc_keypad(SP_PARM, FALSE);
+	    _nc_flush();
 	}
+	rc = _nc_set_tty_mode(&termp->Ottyb);
+#endif
     }
-    returnCode(ERR);
+    returnCode(rc);
 }
 
+#if NCURSES_SP_FUNCS
 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);
+    return NCURSES_SP_NAME(reset_shell_mode) (CURRENT_SCREEN);
 }
+#endif
 
 static TTY *
-saved_tty(void)
+saved_tty(NCURSES_SP_DCL0)
 {
     TTY *result = 0;
 
-    if (SP != 0) {
-	result = &(SP->_saved_tty);
+    if (SP_PARM != 0) {
+	result = (TTY *) & (SP_PARM->_saved_tty);
     } else {
 	if (_nc_prescreen.saved_tty == 0) {
 	    _nc_prescreen.saved_tty = typeCalloc(TTY, 1);
@@ -204,17 +293,31 @@
 */
 
 NCURSES_EXPORT(int)
-savetty(void)
+NCURSES_SP_NAME(savetty) (NCURSES_SP_DCL0)
 {
-    T((T_CALLED("savetty()")));
-
-    returnCode(_nc_get_tty_mode(saved_tty()));
+    T((T_CALLED("savetty(%p)"), (void *) SP_PARM));
+    returnCode(NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+savetty(void)
+{
+    return NCURSES_SP_NAME(savetty) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(resetty) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("resetty(%p)"), (void *) SP_PARM));
+    returnCode(NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 resetty(void)
 {
-    T((T_CALLED("resetty()")));
-
-    returnCode(_nc_set_tty_mode(saved_tty()));
+    return NCURSES_SP_NAME(resetty) (CURRENT_SCREEN);
 }
+#endif
diff --git a/ncurses/tinfo/make_hash.c b/ncurses/tinfo/make_hash.c
new file mode 100644
index 0000000..37ac765
--- /dev/null
+++ b/ncurses/tinfo/make_hash.c
@@ -0,0 +1,330 @@
+/****************************************************************************
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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                 *
+ ****************************************************************************/
+
+/*
+ *	make_hash.c --- build-time program for constructing comp_captab.c
+ *
+ */
+
+#include <build.priv.h>
+
+#include <tic.h>
+#include <hashsize.h>
+
+#include <ctype.h>
+
+MODULE_ID("$Id: make_hash.c,v 1.13 2013/09/28 20:55:47 tom Exp $")
+
+/*
+ *	_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[].
+ *
+ */
+
+#undef MODULE_ID
+#define MODULE_ID(id)		/*nothing */
+#include <tinfo/doalloc.c>
+
+static void
+failed(const char *s)
+{
+    perror(s);
+    exit(EXIT_FAILURE);
+}
+
+static char *
+strmalloc(char *s)
+{
+    size_t need = strlen(s) + 1;
+    char *result = malloc(need);
+    if (result == 0)
+	failed("strmalloc");
+    _nc_STRCPY(result, s, need);
+    return result;
+}
+
+/*
+ *	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;
+
+    while (*string) {
+	sum += (long) (*string + (*(string + 1) << 8));
+	string++;
+    }
+
+    return (int) (sum % HASHTABSIZE);
+}
+
+static void
+_nc_make_hash_table(struct name_table_entry *table,
+		    HashValue * 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;
+    }
+
+    printf("/* %d collisions out of %d entries */\n", collisions, CAPTABSIZE);
+}
+
+/*
+ * 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 int
+count_columns(char **list)
+{
+    int result = 0;
+    if (list != 0) {
+	while (*list++) {
+	    ++result;
+	}
+    }
+    return result;
+}
+
+static char **
+parse_columns(char *buffer)
+{
+    static char **list;
+
+    int col = 0;
+
+    if (list == 0 && (list = typeCalloc(char *, (MAX_COLUMNS + 1))) == 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);
+    HashValue *hash_table = typeCalloc(HashValue, 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;
+	if (column > count_columns(list)) {
+	    fprintf(stderr, "expected %d columns, have %d:\n%s\n",
+		    column,
+		    count_columns(list),
+		    buffer);
+	    exit(EXIT_FAILURE);
+	}
+	name_table[n].nte_link = -1;	/* end-of-hash */
+	name_table[n].nte_name = strmalloc(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 const _nc_%s_table[] =\n",
+	       root_name);
+	printf("{\n");
+	for (n = 0; n < CAPTABSIZE; n++) {
+	    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(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 HashValue _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;
+}
diff --git a/ncurses/tinfo/make_keys.c b/ncurses/tinfo/make_keys.c
index c084f87..fa0c2f2 100644
--- a/ncurses/tinfo/make_keys.c
+++ b/ncurses/tinfo/make_keys.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2015 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            *
@@ -37,18 +37,33 @@
  */
 
 #define USE_TERMLIB 1
-#include <curses.priv.h>
+#include <build.priv.h>
 
-MODULE_ID("$Id: make_keys.c,v 1.14 2008/08/03 21:57:22 tom Exp $")
+MODULE_ID("$Id: make_keys.c,v 1.21 2015/07/16 01:10:03 tom Exp $")
 
 #include <names.c>
 
-#define UNKNOWN (SIZEOF(strnames) + SIZEOF(strfnames))
+static unsigned
+unknown(void)
+{
+    static unsigned result = 0;
 
-static size_t
+    if (result == 0) {
+	unsigned n;
+	for (n = 0; strnames[n] != 0; n++) {
+	    ++result;
+	}
+	for (n = 0; strfnames[n] != 0; n++) {
+	    ++result;
+	}
+    }
+    return result;
+}
+
+static unsigned
 lookup(const char *name)
 {
-    size_t n;
+    unsigned n;
     bool found = FALSE;
     for (n = 0; strnames[n] != 0; n++) {
 	if (!strcmp(name, strnames[n])) {
@@ -64,7 +79,7 @@
 	    }
 	}
     }
-    return found ? n : UNKNOWN;
+    return found ? n : unknown();
 }
 
 static void
@@ -73,10 +88,11 @@
     char buffer[BUFSIZ];
     char from[256];
     char to[256];
-    int maxlen = 16;
+    unsigned ignore = unknown();
+    unsigned maxlen = 16;
     int scanned;
 
-    while (fgets(buffer, sizeof(buffer), ifp) != 0) {
+    while (fgets(buffer, (int) sizeof(buffer), ifp) != 0) {
 	if (*buffer == '#')
 	    continue;
 
@@ -85,14 +101,14 @@
 
 	scanned = sscanf(buffer, "%255s %255s", to, from);
 	if (scanned == 2) {
-	    int code = lookup(from);
-	    if (code == UNKNOWN)
+	    unsigned code = lookup(from);
+	    if (code == ignore)
 		continue;
-	    if ((int) strlen(from) > maxlen)
-		maxlen = strlen(from);
-	    fprintf(ofp, "\t{ %4d, %-*.*s },\t/* %s */\n",
+	    if (strlen(from) > maxlen)
+		maxlen = (unsigned) strlen(from);
+	    fprintf(ofp, "\t{ %4u, %-*.*s },\t/* %s */\n",
 		    code,
-		    maxlen, maxlen,
+		    (int) maxlen, (int) maxlen,
 		    to,
 		    from);
 	}
diff --git a/ncurses/tinfo/name_match.c b/ncurses/tinfo/name_match.c
index d576901..c648535 100644
--- a/ncurses/tinfo/name_match.c
+++ b/ncurses/tinfo/name_match.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1999-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -31,28 +31,40 @@
  ****************************************************************************/
 
 #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 $")
+MODULE_ID("$Id: name_match.c,v 1.23 2013/05/25 20:20:08 tom Exp $")
 
-/*
- *	_nc_first_name(char *names)
- *
- *	Extract the primary name from a compiled entry.
- */
 #define FirstName _nc_globals.first_name
 
+#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
+static const char *
+skip_index(const char *name)
+{
+    if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
+	const char *bar = strchr(name, '|');
+	if (bar != 0 && (bar - name) == 2)
+	    name = bar + 1;
+    }
+    return name;
+}
+#endif
+
+/*
+ * Get the primary name from the given name list.  For terminfo, this is the
+ * first name.  For termcap, this may be the second name, if the first one
+ * happens to be two characters.
+ */
 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)
+	if (FirstName != 0) {
 	    FreeAndNull(FirstName);
+	}
     } else
 #endif
     {
@@ -60,8 +72,12 @@
 	    FirstName = typeMalloc(char, MAX_NAME_SIZE + 1);
 
 	if (FirstName != 0) {
+	    const char *src = sp;
+#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
+	    src = skip_index(sp);
+#endif
 	    for (n = 0; n < MAX_NAME_SIZE; n++) {
-		if ((FirstName[n] = sp[n]) == '\0'
+		if ((FirstName[n] = src[n]) == '\0'
 		    || (FirstName[n] == '|'))
 		    break;
 	    }
@@ -72,11 +88,8 @@
 }
 
 /*
- *	int _nc_name_match(namelist, name, delim)
- *
- *	Is the given name matched in namelist?
+ * 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)
 {
diff --git a/ncurses/tinfo/obsolete.c b/ncurses/tinfo/obsolete.c
new file mode 100644
index 0000000..63476dc
--- /dev/null
+++ b/ncurses/tinfo/obsolete.c
@@ -0,0 +1,239 @@
+/****************************************************************************
+ * Copyright (c) 2013,2014 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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                        2013-on                 *
+ ****************************************************************************/
+
+/*
+**	Support for obsolete/unusual features.
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: obsolete.c,v 1.3 2014/10/11 02:39:35 tom Exp $")
+
+/*
+ * Obsolete entrypoint retained for binary compatbility.
+ */
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_DCLx FILE *ofp, int buffered)
+{
+#if NCURSES_SP_FUNCS
+    (void) SP_PARM;
+#endif
+    (void) ofp;
+    (void) buffered;
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_set_buffer(FILE *ofp, int buffered)
+{
+    NCURSES_SP_NAME(_nc_set_buffer) (CURRENT_SCREEN, ofp, buffered);
+}
+#endif
+
+#if !HAVE_STRDUP
+NCURSES_EXPORT(char *)
+_nc_strdup(const char *s)
+{
+    char *result = 0;
+    if (s != 0) {
+	size_t need = strlen(s);
+	result = malloc(need + 1);
+	if (result != 0) {
+	    strcpy(result, s);
+	}
+    }
+    return result;
+}
+#endif
+
+#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;
+}
+#endif /* USE_MY_MEMMOVE */
+
+#ifdef EXP_XTERM_1005
+NCURSES_EXPORT(int)
+_nc_conv_to_utf8(unsigned char *target, unsigned source, unsigned limit)
+{
+#define CH(n) UChar((source) >> ((n) * 8))
+    int rc = 0;
+
+    if (source <= 0x0000007f)
+	rc = 1;
+    else if (source <= 0x000007ff)
+	rc = 2;
+    else if (source <= 0x0000ffff)
+	rc = 3;
+    else if (source <= 0x001fffff)
+	rc = 4;
+    else if (source <= 0x03ffffff)
+	rc = 5;
+    else			/* (source <= 0x7fffffff) */
+	rc = 6;
+
+    if ((unsigned) rc > limit) {	/* whatever it is, we cannot decode it */
+	rc = 0;
+    }
+
+    if (target != 0) {
+	switch (rc) {
+	case 1:
+	    target[0] = CH(0);
+	    break;
+
+	case 2:
+	    target[1] = UChar(0x80 | (CH(0) & 0x3f));
+	    target[0] = UChar(0xc0 | (CH(0) >> 6) | ((CH(1) & 0x07) << 2));
+	    break;
+
+	case 3:
+	    target[2] = UChar(0x80 | (CH(0) & 0x3f));
+	    target[1] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
+	    target[0] = UChar(0xe0 | ((int) (CH(1) & 0xf0) >> 4));
+	    break;
+
+	case 4:
+	    target[3] = UChar(0x80 | (CH(0) & 0x3f));
+	    target[2] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
+	    target[1] = UChar(0x80 |
+			      ((int) (CH(1) & 0xf0) >> 4) |
+			      ((int) (CH(2) & 0x03) << 4));
+	    target[0] = UChar(0xf0 | ((int) (CH(2) & 0x1f) >> 2));
+	    break;
+
+	case 5:
+	    target[4] = UChar(0x80 | (CH(0) & 0x3f));
+	    target[3] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
+	    target[2] = UChar(0x80 |
+			      ((int) (CH(1) & 0xf0) >> 4) |
+			      ((int) (CH(2) & 0x03) << 4));
+	    target[1] = UChar(0x80 | (CH(2) >> 2));
+	    target[0] = UChar(0xf8 | (CH(3) & 0x03));
+	    break;
+
+	case 6:
+	    target[5] = UChar(0x80 | (CH(0) & 0x3f));
+	    target[4] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
+	    target[3] = UChar(0x80 | (CH(1) >> 4) | ((CH(2) & 0x03) << 4));
+	    target[2] = UChar(0x80 | (CH(2) >> 2));
+	    target[1] = UChar(0x80 | (CH(3) & 0x3f));
+	    target[0] = UChar(0xfc | ((int) (CH(3) & 0x40) >> 6));
+	    break;
+	}
+    }
+
+    return rc;			/* number of bytes needed in target */
+#undef CH
+}
+
+NCURSES_EXPORT(int)
+_nc_conv_to_utf32(unsigned *target, const char *source, unsigned limit)
+{
+#define CH(n) UChar((*target) >> ((n) * 8))
+    int rc = 0;
+    int j;
+    unsigned mask = 0;
+
+    /*
+     * Find the number of bytes we will need from the source.
+     */
+    if ((*source & 0x80) == 0) {
+	rc = 1;
+	mask = (unsigned) *source;
+    } else if ((*source & 0xe0) == 0xc0) {
+	rc = 2;
+	mask = (unsigned) (*source & 0x1f);
+    } else if ((*source & 0xf0) == 0xe0) {
+	rc = 3;
+	mask = (unsigned) (*source & 0x0f);
+    } else if ((*source & 0xf8) == 0xf0) {
+	rc = 4;
+	mask = (unsigned) (*source & 0x07);
+    } else if ((*source & 0xfc) == 0xf8) {
+	rc = 5;
+	mask = (unsigned) (*source & 0x03);
+    } else if ((*source & 0xfe) == 0xfc) {
+	rc = 6;
+	mask = (unsigned) (*source & 0x01);
+    }
+
+    if ((unsigned) rc > limit) {	/* whatever it is, we cannot decode it */
+	rc = 0;
+    }
+
+    /*
+     * sanity-check.
+     */
+    if (rc > 1) {
+	for (j = 1; j < rc; j++) {
+	    if ((source[j] & 0xc0) != 0x80)
+		break;
+	}
+	if (j != rc) {
+	    rc = 0;
+	}
+    }
+
+    if (target != 0) {
+	int shift = 0;
+	*target = 0;
+	for (j = 1; j < rc; j++) {
+	    *target |= (unsigned) (source[rc - j] & 0x3f) << shift;
+	    shift += 6;
+	}
+	*target |= mask << shift;
+    }
+    return rc;
+#undef CH
+}
+#endif /* EXP_XTERM_1005 */
diff --git a/ncurses/tinfo/parse_entry.c b/ncurses/tinfo/parse_entry.c
index cf7a5f4..0dc1414 100644
--- a/ncurses/tinfo/parse_entry.c
+++ b/ncurses/tinfo/parse_entry.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -46,9 +46,8 @@
 
 #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 $")
+MODULE_ID("$Id: parse_entry.c,v 1.80 2015/04/04 14:18:38 tom Exp $")
 
 #ifdef LINT
 static short const parametrized[] =
@@ -84,13 +83,13 @@
     case NUMBER:
 	first = tp->ext_Booleans;
 	last = tp->ext_Numbers + first;
-	offset = tp->ext_Booleans + tp->ext_Numbers;
+	offset = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
 	tindex = tp->num_Numbers;
 	break;
     case STRING:
-	first = tp->ext_Booleans + tp->ext_Numbers;
+	first = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
 	last = tp->ext_Strings + first;
-	offset = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings;
+	offset = (unsigned) (tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings);
 	tindex = tp->num_Strings;
 	break;
     case CANCEL:
@@ -137,32 +136,36 @@
 	    break;
 	}
     }
+
+#define for_each_value(max) \
+	for (last = (unsigned) (max - 1); last > tindex; last--)
+
     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->ext_Booleans++;
+	    tp->num_Booleans++;
+	    TYPE_REALLOC(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
+	    for_each_value(tp->num_Booleans)
 		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->ext_Numbers++;
+	    tp->num_Numbers++;
+	    TYPE_REALLOC(short, tp->num_Numbers, tp->Numbers);
+	    for_each_value(tp->num_Numbers)
 		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->ext_Strings++;
+	    tp->num_Strings++;
+	    TYPE_REALLOC(char *, tp->num_Strings, tp->Strings);
+	    for_each_value(tp->num_Strings)
 		tp->Strings[last] = tp->Strings[last - 1];
 	    break;
 	}
 	actual = NUM_EXT_NAMES(tp);
-	tp->ext_Names = typeRealloc(char *, actual, tp->ext_Names);
+	TYPE_REALLOC(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);
@@ -170,7 +173,7 @@
 
     temp.nte_name = tp->ext_Names[offset];
     temp.nte_type = token_type;
-    temp.nte_index = tindex;
+    temp.nte_index = (short) tindex;
     temp.nte_link = -1;
 
     return &temp;
@@ -200,6 +203,8 @@
  	{ bad_tc_usage = TRUE; \
 	 _nc_warning("Legacy termcap allows only a trailing tc= clause"); }
 
+#define MAX_NUMBER 0x7fff	/* positive shorts only */
+
 NCURSES_EXPORT(int)
 _nc_parse_entry(struct entry *entryp, int literal, bool silent)
 {
@@ -379,16 +384,14 @@
 		    && !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));
+						    _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));
+						    _nc_syntax != 0);
 		    assert(entry_ptr != 0);
 
 		} else if (token_type == BOOLEAN
@@ -443,8 +446,12 @@
 		break;
 
 	    case NUMBER:
-		entryp->tterm.Numbers[entry_ptr->nte_index] =
-		    _nc_curr_token.tk_valnumber;
+		if (_nc_curr_token.tk_valnumber > MAX_NUMBER) {
+		    entryp->tterm.Numbers[entry_ptr->nte_index] = MAX_NUMBER;
+		} else {
+		    entryp->tterm.Numbers[entry_ptr->nte_index] =
+			(short) _nc_curr_token.tk_valnumber;
+		}
 		break;
 
 	    case STRING:
@@ -510,9 +517,9 @@
 _nc_capcmp(const char *s, const char *t)
 /* compare two string capabilities, stripping out padding */
 {
-    if (!s && !t)
+    if (!VALID_STRING(s) && !VALID_STRING(t))
 	return (0);
-    else if (!s || !t)
+    else if (!VALID_STRING(s) || !VALID_STRING(t))
 	return (1);
 
     for (;;) {
@@ -574,32 +581,32 @@
  * list.  For each capability, we may assume there is a keycap that sends the
  * string which is the value of that capability.
  */
+#define DATA(from, to) { { from }, { to } }
 typedef struct {
-    const char *from;
-    const char *to;
+    const char from[3];
+    const char to[6];
 } 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},
+    DATA("al", "kil1"),		/* insert line key  -> KEY_IL    */
+    DATA("bt", "kcbt"),		/* back tab         -> KEY_BTAB  */
+    DATA("cd", "ked"),		/* clear-to-eos key -> KEY_EOL   */
+    DATA("ce", "kel"),		/* clear-to-eol key -> KEY_EOS   */
+    DATA("cl", "kclr"),		/* clear key        -> KEY_CLEAR */
+    DATA("ct", "tbc"),		/* clear all tabs   -> KEY_CATAB */
+    DATA("dc", "kdch1"),	/* delete char      -> KEY_DC    */
+    DATA("dl", "kdl1"),		/* delete line      -> KEY_DL    */
+    DATA("do", "kcud1"),	/* down key         -> KEY_DOWN  */
+    DATA("ei", "krmir"),	/* exit insert key  -> KEY_EIC   */
+    DATA("ho", "khome"),	/* home key         -> KEY_HOME  */
+    DATA("ic", "kich1"),	/* insert char key  -> KEY_IC    */
+    DATA("im", "kIC"),		/* insert-mode key  -> KEY_SIC   */
+    DATA("le", "kcub1"),	/* le key           -> KEY_LEFT  */
+    DATA("nd", "kcuf1"),	/* nd key           -> KEY_RIGHT */
+    DATA("nl", "kent"),		/* new line key     -> KEY_ENTER */
+    DATA("st", "khts"),		/* set-tab key      -> KEY_STAB  */
+    DATA("ta", ""),
+    DATA("up", "kcuu1"),	/* up-arrow key     -> KEY_UP    */
 };
 
 /*
@@ -653,27 +660,30 @@
 
 	if (WANTED(carriage_return)) {
 	    if (carriage_return_delay > 0) {
-		sprintf(buf, "%s$<%d>", C_CR, carriage_return_delay);
+		_nc_SPRINTF(buf, _nc_SLIMIT(sizeof(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);
+		_nc_SPRINTF(buf, _nc_SLIMIT(sizeof(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 */
+	/* vi doesn't use "do", but it does seem 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);
+		    _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
+				"%s$<%d>", C_LF, new_line_delay);
 		    cursor_down = _nc_save_str(buf);
 		} else
 		    cursor_down = _nc_save_str(C_LF);
@@ -684,7 +694,8 @@
 		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);
+		    _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
+				"%s$<%d>", C_LF, new_line_delay);
 		    scroll_forward = _nc_save_str(buf);
 		} else
 		    scroll_forward = _nc_save_str(C_LF);
@@ -693,7 +704,8 @@
 	if (WANTED(newline)) {
 	    if (linefeed_is_newline == 1) {
 		if (new_line_delay > 0) {
-		    sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
+		    _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
+				"%s$<%d>", C_LF, new_line_delay);
 		    newline = _nc_save_str(buf);
 		} else
 		    newline = _nc_save_str(C_LF);
@@ -735,7 +747,8 @@
 	 */
 	if (WANTED(tab)) {
 	    if (horizontal_tab_delay > 0) {
-		sprintf(buf, "%s$<%d>", C_HT, horizontal_tab_delay);
+		_nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
+			    "%s$<%d>", C_HT, horizontal_tab_delay);
 		tab = _nc_save_str(buf);
 	    } else
 		tab = _nc_save_str(C_HT);
@@ -772,11 +785,10 @@
      * isn't from mytinfo...
      */
     if (PRESENT(other_non_function_keys)) {
-	char *base = other_non_function_keys;
+	char *base;
 	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;
 
@@ -788,18 +800,22 @@
 	for (base = other_non_function_keys;
 	     (cp = strchr(base, ',')) != 0;
 	     base = cp + 1) {
-	    size_t len = cp - base;
+	    size_t len = (unsigned) (cp - base);
+	    size_t n;
+	    assoc const *ap = 0;
 
-	    for (ap = ko_xlate; ap->from; ap++) {
-		if (len == strlen(ap->from)
-		    && strncmp(ap->from, base, len) == 0)
+	    for (n = 0; n < SIZEOF(ko_xlate); ++n) {
+		if (len == strlen(ko_xlate[n].from)
+		    && strncmp(ko_xlate[n].from, base, len) == 0) {
+		    ap = ko_xlate + n;
 		    break;
+		}
 	    }
-	    if (!(ap->from && ap->to)) {
+	    if (ap == 0) {
 		_nc_warning("unknown capability `%.*s' in ko string",
 			    (int) len, base);
 		continue;
-	    } else if (ap->to == CANCELLED_STRING)	/* ignore it */
+	    } else if (ap->to[0] == '\0')	/* ignore it */
 		continue;
 
 	    /* now we know we found a match in ko_table, so... */
@@ -840,7 +856,7 @@
 		} else
 		    *dp++ = *bp;
 	    }
-	    *dp++ = '\0';
+	    *dp = '\0';
 
 	    tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
 	}
diff --git a/ncurses/tinfo/read_entry.c b/ncurses/tinfo/read_entry.c
index b4ea61c..81fdc46 100644
--- a/ncurses/tinfo/read_entry.c
+++ b/ncurses/tinfo/read_entry.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,13 +40,14 @@
 #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 $")
+MODULE_ID("$Id: read_entry.c,v 1.129 2015/06/27 16:16:40 tom Exp $")
 
 #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
 
-#if USE_DATABASE
+#define MyNumber(n) (short) LOW_MSB(n)
+
+#if NCURSES_USE_DATABASE
 static void
 convert_shorts(char *buf, short *Numbers, int count)
 {
@@ -57,7 +58,7 @@
 	else if (IS_NEG2(buf + 2 * i))
 	    Numbers[i] = CANCELLED_NUMERIC;
 	else
-	    Numbers[i] = LOW_MSB(buf + 2 * i);
+	    Numbers[i] = MyNumber(buf + 2 * i);
 	TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i]));
     }
 }
@@ -73,10 +74,10 @@
 	    Strings[i] = ABSENT_STRING;
 	} else if (IS_NEG2(buf + 2 * i)) {
 	    Strings[i] = CANCELLED_STRING;
-	} else if ((int) LOW_MSB(buf + 2 * i) > size) {
+	} else if (MyNumber(buf + 2 * i) > size) {
 	    Strings[i] = ABSENT_STRING;
 	} else {
-	    Strings[i] = (LOW_MSB(buf + 2 * i) + table);
+	    Strings[i] = (MyNumber(buf + 2 * i) + table);
 	    TR(TRACE_DATABASE, ("Strings[%d] = %s", i, _nc_visbuf(Strings[i])));
 	}
 
@@ -99,31 +100,81 @@
 
     if (have > 0) {
 	if ((int) want > have)
-	    want = have;
-	memcpy(dst, src + *offset, want);
-	*offset += want;
+	    want = (unsigned) have;
+	memcpy(dst, src + *offset, (size_t) want);
+	*offset += (int) want;
     } else {
 	want = 0;
     }
     return (int) want;
 }
 
-#define Read(buf, count) fake_read(buffer, &offset, limit, buf, count)
+#define Read(buf, count) fake_read(buffer, &offset, limit, (char *) buf, (unsigned) count)
 
 #define read_shorts(buf, count) \
-	(Read(buf, (unsigned) (count)*2) == (int) (count)*2)
+	(Read(buf, (count)*2) == (int) (count)*2)
 
 #define even_boundary(value) \
     if ((value) % 2 != 0) Read(buf, 1)
+#endif
 
+NCURSES_EXPORT(void)
+_nc_init_termtype(TERMTYPE *const tp)
+{
+    unsigned i;
+
+#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)
+	TYPE_MALLOC(NCURSES_SBOOL, BOOLCOUNT, tp->Booleans);
+    if (tp->Numbers == 0)
+	TYPE_MALLOC(short, NUMCOUNT, tp->Numbers);
+    if (tp->Strings == 0)
+	TYPE_MALLOC(char *, STRCOUNT, tp->Strings);
+
+    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;
+}
+
+#if NCURSES_USE_DATABASE
+#if NCURSES_XNAMES
+static bool
+valid_shorts(char *buffer, int limit)
+{
+    bool result = FALSE;
+    int n;
+    for (n = 0; n < limit; ++n) {
+	if (MyNumber(buffer + (n * 2)) > 0) {
+	    result = TRUE;
+	    break;
+	}
+    }
+    return result;
+}
+#endif
+
+/*
+ * Return TGETENT_YES if read, TGETENT_NO if not found or garbled.
+ */
 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 buf[MAX_ENTRY_SIZE + 2];
     char *string_table;
     unsigned want, have;
 
@@ -137,11 +188,11 @@
 	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);
+    name_size = MyNumber(buf + 2);
+    bool_count = MyNumber(buf + 4);
+    num_count = MyNumber(buf + 6);
+    str_count = MyNumber(buf + 8);
+    str_size = MyNumber(buf + 10);
 
     TR(TRACE_DATABASE,
        ("TERMTYPE name_size=%d, bool=%d/%d, num=%d/%d str=%d/%d(%d)",
@@ -155,10 +206,10 @@
 	return (TGETENT_NO);
     }
 
-    want = str_size + name_size + 1;
+    want = (unsigned) (str_size + name_size + 1);
     if (str_size) {
 	/* try to allocate space for the string table */
-	if (str_count * 2 >= (int) sizeof(buf)
+	if (str_count * 2 >= MAX_ENTRY_SIZE
 	    || (string_table = typeMalloc(char, want)) == 0) {
 	    return (TGETENT_NO);
 	}
@@ -173,14 +224,14 @@
     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);
+    if ((have = (unsigned) Read(ptr->term_names, want)) != want) {
+	memset(ptr->term_names + have, 0, (size_t) (want - have));
     }
     ptr->term_names[want] = '\0';
     string_table += (want + 1);
 
     if (have > MAX_NAME_SIZE)
-	offset = (have - MAX_NAME_SIZE);
+	offset = (int) (have - MAX_NAME_SIZE);
 
     /* grab the booleans */
     if ((ptr->Booleans = TYPE_CALLOC(NCURSES_SBOOL,
@@ -204,8 +255,9 @@
     }
     convert_shorts(buf, ptr->Numbers, num_count);
 
-    if ((ptr->Strings = TYPE_CALLOC(char *, max(STRCOUNT, str_count))) == 0)
-	  return (TGETENT_NO);
+    if ((ptr->Strings = TYPE_CALLOC(char *, max(STRCOUNT, str_count))) == 0) {
+	return (TGETENT_NO);
+    }
 
     if (str_count) {
 	/* grab the string offsets */
@@ -213,8 +265,9 @@
 	    return (TGETENT_NO);
 	}
 	/* finally, grab the string table itself */
-	if (Read(string_table, (unsigned) str_size) != str_size)
+	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
@@ -228,32 +281,33 @@
      */
     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);
+    if (_nc_user_definable && read_shorts(buf, 5) && valid_shorts(buf, 5)) {
+	int ext_bool_count = MyNumber(buf + 0);
+	int ext_num_count = MyNumber(buf + 2);
+	int ext_str_count = MyNumber(buf + 4);
+	int ext_str_size = MyNumber(buf + 6);
+	int ext_str_limit = MyNumber(buf + 8);
+	unsigned need = (unsigned) (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)
+	if (need >= (MAX_ENTRY_SIZE / 2)
+	    || ext_str_size >= MAX_ENTRY_SIZE
+	    || ext_str_limit >= MAX_ENTRY_SIZE
 	    || ext_bool_count < 0
 	    || ext_num_count < 0
 	    || ext_str_count < 0
 	    || ext_str_size < 0
-	    || ext_str_limit < 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->num_Booleans = UShort(BOOLCOUNT + ext_bool_count);
+	ptr->num_Numbers = UShort(NUMCOUNT + ext_num_count);
+	ptr->num_Strings = UShort(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);
+	TYPE_REALLOC(NCURSES_SBOOL, ptr->num_Booleans, ptr->Booleans);
+	TYPE_REALLOC(short, ptr->num_Numbers, ptr->Numbers);
+	TYPE_REALLOC(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,
@@ -261,39 +315,48 @@
 
 	TR(TRACE_DATABASE, ("READ %d extended-booleans @%d",
 			    ext_bool_count, offset));
-	if ((ptr->ext_Booleans = ext_bool_count) != 0) {
+	if ((ptr->ext_Booleans = UShort(ext_bool_count)) != 0) {
 	    if (Read(ptr->Booleans + BOOLCOUNT, (unsigned)
-		     ext_bool_count) != ext_bool_count)
+		     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))
+	if ((ptr->ext_Numbers = UShort(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))
+	if ((unsigned) (ext_str_count + (int) need) >= (MAX_ENTRY_SIZE / 2)) {
 	    return (TGETENT_NO);
+	}
+	if ((ext_str_count || need)
+	    && !read_shorts(buf, ext_str_count + (int) 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)
+	    ptr->ext_str_table = typeMalloc(char, (size_t) ext_str_limit);
+	    if (ptr->ext_str_table == 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) {
+	if ((ptr->ext_Strings = UShort(ext_str_count)) != 0) {
 	    TR(TRACE_DATABASE,
 	       ("Before computing extended-string capabilities str_count=%d, ext_str_count=%d",
 		str_count, ext_str_count));
@@ -305,7 +368,7 @@
 				    _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);
+		    base += (int) (strlen(ptr->Strings[i + STRCOUNT]) + 1);
 		TR(TRACE_DATABASE, ("... to    [%d] %s",
 				    i + STRCOUNT,
 				    _nc_visbuf(ptr->Strings[i + STRCOUNT])));
@@ -313,10 +376,12 @@
 	}
 
 	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);
+	    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)));
@@ -326,17 +391,18 @@
 			    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,
+	   ("...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));
+	TR(TRACE_DATABASE, ("...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
@@ -364,30 +430,84 @@
 _nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
 /* return 1 if read, 0 if not found or garbled */
 {
-    int code, fd = -1;
+    FILE *fp = 0;
+    int code;
     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));
+	|| (fp = fopen(filename, "rb")) == 0) {
+	TR(TRACE_DATABASE, ("cannot open terminfo %s (errno=%d)", filename, errno));
 	code = TGETENT_NO;
     } else {
-	if ((limit = read(fd, buffer, sizeof(buffer))) > 0) {
+	if ((limit = (int) fread(buffer, sizeof(char), sizeof(buffer), fp))
+	    > 0) {
 
-	    T(("read terminfo %s", filename));
+	    TR(TRACE_DATABASE, ("read terminfo %s", filename));
 	    if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) {
 		_nc_free_termtype(ptr);
 	    }
 	} else {
 	    code = TGETENT_NO;
 	}
-	close(fd);
+	fclose(fp);
     }
 
     return (code);
 }
 
+#if USE_HASHED_DB
+/*
+ * Return if if we can build the filename of a ".db" file.
+ */
+static bool
+make_db_filename(char *filename, unsigned limit, const char *const path)
+{
+    static const char suffix[] = DBM_SUFFIX;
+
+    size_t lens = sizeof(suffix) - 1;
+    size_t size = strlen(path);
+    size_t test = lens + size;
+    bool result = FALSE;
+
+    if (test < limit) {
+	if (size >= lens
+	    && !strcmp(path + size - lens, suffix))
+	    _nc_STRCPY(filename, path, limit);
+	else
+	    _nc_SPRINTF(filename, _nc_SLIMIT(limit) "%s%s", path, suffix);
+	result = TRUE;
+    }
+    return result;
+}
+#endif
+
+/*
+ * Return true if we can build the name of a filesystem entry.
+ */
+static bool
+make_dir_filename(char *filename,
+		  unsigned limit,
+		  const char *const path,
+		  const char *name)
+{
+    bool result = FALSE;
+
+#if NCURSES_USE_TERMCAP
+    if (_nc_is_dir_path(path))
+#endif
+    {
+	unsigned need = (unsigned) (LEAF_LEN + 3 + strlen(path) + strlen(name));
+
+	if (need <= limit) {
+	    _nc_SPRINTF(filename, _nc_SLIMIT(limit)
+			"%s/" LEAF_FMT "/%s", path, *name, name);
+	    result = TRUE;
+	}
+    }
+    return result;
+}
+
 /*
  * Build a terminfo pathname and try to read the data.  Returns TGETENT_YES on
  * success, TGETENT_NO on failure.
@@ -399,107 +519,82 @@
 		   const char *name,
 		   TERMTYPE *const tp)
 {
-    int result = TGETENT_NO;
+    int code = 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;
+    DB *capdbp;
 
-	if (need <= limit) {
-	    if (size >= lens
-		&& !strcmp(path + size - lens, suffix))
-		(void) strcpy(filename, path);
-	    else
-		(void) sprintf(filename, "%s%s", path, suffix);
+    if (make_db_filename(filename, limit, path)
+	&& (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 = (int) data.size - 1;
+	    char *have = (char *) data.data;
+
+	    if (*have++ == 0) {
+		if (data.size > key.size
+		    && IS_TIC_MAGIC(have)) {
+		    code = _nc_read_termtype(tp, have, used);
+		    if (code == TGETENT_NO) {
+			_nc_free_termtype(tp);
+		    }
+		}
+		break;
+	    }
 
 	    /*
-	     * 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.
+	     * Just in case we have a corrupt database, do not waste time with
+	     * it.
 	     */
-	    if ((capdbp = _nc_db_open(filename, FALSE)) != 0) {
-		DBT key, data;
-		int reccnt = 0;
-		char *save = strdup(name);
+	    if (++reccnt >= 3)
+		break;
 
-		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);
-	    }
+	    /*
+	     * Prepare for the second level.
+	     */
+	    key.data = have;
+	    key.size = used;
 	}
+
+	free(save);
+    } else			/* may be either filesystem or flat file */
+#endif
+    if (make_dir_filename(filename, limit, path, name)) {
+	code = _nc_read_file_entry(filename, tp);
+    }
+#if NCURSES_USE_TERMCAP
+    else if (code != TGETENT_YES) {
+	code = _nc_read_termcap_entry(name, tp);
+	_nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
+		    "%.*s", PATH_MAX - 1, _nc_get_source());
     }
 #endif
-    return result;
+    return code;
 }
-#endif /* USE_DATABASE */
+#endif /* NCURSES_USE_DATABASE */
 
 /*
  *	_nc_read_entry(char *name, char *filename, TERMTYPE *tp)
@@ -515,30 +610,36 @@
 {
     int code = TGETENT_NO;
 
+    _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
+		"%.*s", PATH_MAX - 1, name);
+
     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));
+	TR(TRACE_DATABASE, ("illegal or missing entry name '%s'", name));
     } else {
-#if USE_DATABASE
-	DBDIRS state = dbdTIC;
-	int offset = 0;
+#if NCURSES_USE_DATABASE
+	DBDIRS state;
+	int offset;
 	const char *path;
 
+	_nc_first_db(&state, &offset);
+	code = TGETENT_ERR;
 	while ((path = _nc_next_db(&state, &offset)) != 0) {
+	    TR(TRACE_DATABASE, ("_nc_read_tic_entry path=%s, name=%s", path, name));
 	    code = _nc_read_tic_entry(filename, PATH_MAX, path, name, tp);
 	    if (code == TGETENT_YES) {
 		_nc_last_db();
 		break;
 	    }
 	}
-#endif
-#if USE_TERMCAP
+#elif NCURSES_USE_TERMCAP
 	if (code != TGETENT_YES) {
 	    code = _nc_read_termcap_entry(name, tp);
-	    sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source());
+	    _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
+			"%.*s", PATH_MAX - 1, _nc_get_source());
 	}
 #endif
     }
diff --git a/ncurses/tinfo/read_termcap.c b/ncurses/tinfo/read_termcap.c
index d94d1a4..6bfb23c 100644
--- a/ncurses/tinfo/read_termcap.c
+++ b/ncurses/tinfo/read_termcap.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -54,11 +54,9 @@
 
 #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 $")
+MODULE_ID("$Id: read_termcap.c,v 1.89 2013/12/15 00:32:43 tom Exp $")
 
 #if !PURE_TERMINFO
 
@@ -75,10 +73,19 @@
 
     if (!use_terminfo_vars() || (result = getenv("TERMPATH")) == 0)
 	result = TERMPATH;
-    T(("TERMPATH is %s", result));
+    TR(TRACE_DATABASE, ("TERMPATH is %s", result));
     return result;
 }
 
+/*
+ * Note:
+ * getcap(), cgetent(), etc., are BSD functions.  A copy of those was added to
+ * this file in November 1995, derived from the BSD4.4 Lite sources.
+ *
+ * The initial adaptation uses 518 lines from that source.
+ * The current source (in 2009) uses 183 lines of BSD4.4 Lite (441 ignoring
+ * whitespace).
+ */
 #if USE_GETCAP
 
 #if HAVE_BSD_CGETENT
@@ -107,11 +114,7 @@
  * 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
+ * 3. 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.
  *
@@ -158,7 +161,7 @@
 	return (-1);
     }
     gottoprec = 0;
-    (void) strcpy(toprec, ent);
+    _nc_STRCPY(toprec, ent, topreclen);
     return (0);
 }
 
@@ -291,7 +294,7 @@
 	    errno = ENOMEM;
 	    return (TC_SYS_ERR);
 	}
-	(void) strcpy(record, toprec);
+	_nc_STRCPY(record, toprec, topreclen + BFRAG);
 	rp = record + topreclen + 1;
 	r_end = rp + BFRAG;
 	current = in_array;
@@ -380,7 +383,14 @@
 			c = *bp++;
 			if (c == '\n') {
 			    lineno++;
-			    if (rp == record || *(rp - 1) != '\\')
+			    /*
+			     * Unlike BSD 4.3, this ignores a backslash at the
+			     * end of a comment-line.  That makes it consistent
+			     * with the rest of ncurses -TD
+			     */
+			    if (rp == record
+				|| *record == '#'
+				|| *(rp - 1) != '\\')
 				break;
 			}
 			*rp++ = c;
@@ -438,8 +448,10 @@
 		break;
 	}
 
-	if (!foundit)
+	if (!foundit) {
+	    free(record);
 	    return (TC_NOT_FOUND);
+	}
     }
 
     /*
@@ -451,7 +463,7 @@
 	register int newilen;
 	unsigned ilen;
 	int diff, iret, tclen, oline;
-	char *icap, *scan, *tc, *tcstart, *tcend;
+	char *icap = 0, *scan, *tc, *tcstart, *tcend;
 
 	/*
 	 * Loop invariants:
@@ -464,8 +476,9 @@
 	scan = record;
 	tc_not_resolved = FALSE;
 	for (;;) {
-	    if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0)
+	    if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0) {
 		break;
+	    }
 
 	    /*
 	     * Find end of tc=name and stomp on the trailing `:'
@@ -482,6 +495,7 @@
 	    tclen = s - tcstart;
 	    tcend = s;
 
+	    icap = 0;
 	    iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd,
 			      tc, depth + 1, 0);
 	    newicap = icap;	/* Put into a register. */
@@ -492,12 +506,13 @@
 		    if (myfd)
 			(void) close(fd);
 		    free(record);
+		    FreeIfNeeded(icap);
 		    return (iret);
 		}
-		if (iret == TC_UNRESOLVED)
+		if (iret == TC_UNRESOLVED) {
 		    tc_not_resolved = TRUE;
-		/* couldn't resolve tc */
-		if (iret == TC_NOT_FOUND) {
+		    /* couldn't resolve tc */
+		} else if (iret == TC_NOT_FOUND) {
 		    *(s - 1) = ':';
 		    scan = s - 1;
 		    tc_not_resolved = TRUE;
@@ -577,8 +592,9 @@
     }
 
     *cap = record;
-    if (tc_not_resolved)
+    if (tc_not_resolved) {
 	return (TC_UNRESOLVED);
+    }
     return (current);
 }
 
@@ -693,8 +709,6 @@
 #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 ':'.
@@ -756,7 +770,7 @@
 	    dst = 0;
 	    break;
 	}
-	*dst++ = ch;
+	*dst++ = (char) ch;
     }
     return dst;
 }
@@ -772,18 +786,16 @@
     register char *p;
     register char *cp;
     char *dummy = NULL;
-    char **fname;
+    CGETENT_CONST 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 */
+    CGETENT_CONST char *pathvec[PVECSIZ];	/* point to names in pathbuf */
     NCURSES_CONST char *termpath;
     string_desc desc;
 
+    *lineno = 1;
     fname = pathvec;
-    pvec = pathvec;
-    tbuf = bp;
     p = pathbuf;
     cp = use_terminfo_vars()? getenv("TERMCAP") : NULL;
 
@@ -808,10 +820,11 @@
 	    if ((home = getenv("HOME")) != 0 && *home != '\0'
 		&& strchr(home, ' ') == 0
 		&& strlen(home) < sizeof(temp) - 10) {	/* setup path */
-		sprintf(temp, "%s/", home);	/* $HOME first */
+		_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+			    "%s/", home);	/* $HOME first */
 	    }
 	    /* if no $HOME look in current directory */
-	    strcat(temp, ".termcap");
+	    _nc_STRCAT(temp, ".termcap", sizeof(temp));
 	    _nc_safe_strcat(&desc, temp);
 	    _nc_safe_strcat(&desc, " ");
 	    _nc_safe_strcat(&desc, get_termpath());
@@ -837,6 +850,9 @@
 	}
     }
     *fname = 0;			/* mark end of vector */
+#if !HAVE_BSD_CGETENT
+    (void) _nc_cgetset(0);
+#endif
     if (_nc_is_abs_path(cp)) {
 	if (_nc_cgetset(cp) < 0) {
 	    return (TC_SYS_ERR);
@@ -849,6 +865,7 @@
      * empty fields, and mistakenly use the last valid cap entry instead of
      * the first (breaks tc= includes)
      */
+    *bp = '\0';
     if (i >= 0) {
 	char *pd, *ps, *tok;
 	int endflag = FALSE;
@@ -870,7 +887,7 @@
 	    }
 	    if (ignore != TRUE) {
 		list[count++] = tok;
-		pd = copy_tc_token(pd, tok, TBUFSIZ - (2 + pd - bp));
+		pd = copy_tc_token(pd, tok, (size_t) (TBUFSIZ - (2 + pd - bp)));
 		if (pd == 0) {
 		    i = -1;
 		    break;
@@ -928,7 +945,7 @@
     if (count < MAXPATHS
 	&& _nc_access(path, R_OK) == 0) {
 	termpaths[count++] = path;
-	T(("Adding termpath %s", path));
+	TR(TRACE_DATABASE, ("Adding termpath %s", path));
     }
     termpaths[count] = 0;
     if (save != 0)
@@ -952,13 +969,13 @@
     static char *source;
     static int lineno;
 
-    T(("read termcap entry for %s", tn));
+    TR(TRACE_DATABASE, ("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));
+	TR(TRACE_DATABASE, ("illegal or missing entry name '%s'", tn));
 	return TGETENT_NO;
     }
 
@@ -976,7 +993,7 @@
 	_nc_curr_line = lineno;
 	_nc_set_source(source);
     }
-    _nc_read_entry_source((FILE *) 0, tc, FALSE, FALSE, NULLHOOK);
+    _nc_read_entry_source((FILE *) 0, tc, FALSE, TRUE, NULLHOOK);
 #else
     /*
      * Here is what the 4.4BSD termcap(3) page prescribes:
@@ -1023,7 +1040,9 @@
 	    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);
+	    _nc_SPRINTF(tc_buf,
+			_nc_SLIMIT(sizeof(tc_buf))
+			"%.*s\n", (int) sizeof(tc_buf) - 2, tc);
 	    normal = FALSE;
 	}
     }
@@ -1045,8 +1064,9 @@
 	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);
+	    _nc_STRCPY(envhome, h, sizeof(envhome));
+	    _nc_SPRINTF(pathbuf, _nc_SLIMIT(sizeof(pathbuf))
+			PRIVATE_CAP, envhome);
 	    ADD_TC(pathbuf, filecount);
 	}
     }
@@ -1059,7 +1079,7 @@
     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) {
+	    || !S_ISREG(test_stat[j].st_mode)) {
 	    omit = TRUE;
 	} else {
 	    for (k = 0; k < j; k++) {
@@ -1071,7 +1091,7 @@
 	    }
 	}
 	if (omit) {
-	    T(("Path %s is a duplicate", termpaths[j]));
+	    TR(TRACE_DATABASE, ("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];
@@ -1096,7 +1116,7 @@
 
 	for (i = 0; i < filecount; i++) {
 
-	    T(("Looking for %s in %s", tn, termpaths[i]));
+	    TR(TRACE_DATABASE, ("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]);
@@ -1134,8 +1154,7 @@
 		 * from the list.
 		 */
 		*tp = ep->tterm;
-		_nc_delink_entry(_nc_head, &(ep->tterm));
-		free(ep);
+		_nc_free_entry(_nc_head, &(ep->tterm));
 
 		/*
 		 * OK, now try to write the type to user's terminfo directory. 
diff --git a/ncurses/tinfo/setbuf.c b/ncurses/tinfo/setbuf.c
deleted file mode 100644
index ba910e8..0000000
--- a/ncurses/tinfo/setbuf.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/****************************************************************************
- * 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
index 78cd2ef..393d8e7 100644
--- a/ncurses/tinfo/strings.c
+++ b/ncurses/tinfo/strings.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2000-2003,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2000-2007,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -36,7 +36,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: strings.c,v 1.6 2007/08/11 17:12:17 tom Exp $")
+MODULE_ID("$Id: strings.c,v 1.8 2012/02/22 22:34:31 tom Exp $")
 
 /****************************************************************************
  * Useful string functions (especially for mvcur)
@@ -110,7 +110,7 @@
 
 	if (len < dst->s_size) {
 	    if (dst->s_tail != 0) {
-		strcpy(dst->s_tail, src);
+		_nc_STRCPY(dst->s_tail, src, dst->s_size);
 		dst->s_tail += len;
 	    }
 	    dst->s_size -= len;
@@ -131,7 +131,7 @@
 
 	if (len < dst->s_size) {
 	    if (dst->s_head != 0) {
-		strcpy(dst->s_head, src);
+		_nc_STRCPY(dst->s_head, src, dst->s_size);
 		dst->s_tail = dst->s_head + len;
 	    }
 	    dst->s_size = dst->s_init - len;
diff --git a/ncurses/tinfo/tinfo_driver.c b/ncurses/tinfo/tinfo_driver.c
new file mode 100644
index 0000000..c6a1c22
--- /dev/null
+++ b/ncurses/tinfo/tinfo_driver.c
@@ -0,0 +1,1384 @@
+/****************************************************************************
+ * Copyright (c) 2008-2014,2015 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                                                 *
+ *                                                                          *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#define CUR ((TERMINAL*)TCB)->type.
+#include <tic.h>
+
+#if HAVE_NANOSLEEP
+#include <time.h>
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>		/* needed for MacOS X DP3 */
+#endif
+#endif
+
+#if HAVE_SIZECHANGE
+# if !defined(sun) || !TERMIOS
+#  if HAVE_SYS_IOCTL_H
+#   include <sys/ioctl.h>
+#  endif
+# endif
+#endif
+
+MODULE_ID("$Id: tinfo_driver.c,v 1.40 2015/06/27 01:20:41 tom Exp $")
+
+/*
+ * 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
+
+/*
+ * 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 CURRENT_SCREEN ? CURRENT_SCREEN->_pair_count : -1;
+}
+NCURSES_EXPORT(int)
+NCURSES_PUBLIC_VAR(COLORS) (void)
+{
+    return CURRENT_SCREEN ? CURRENT_SCREEN->_color_count : -1;
+}
+#else
+NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
+NCURSES_EXPORT_VAR(int) COLORS = 0;
+#endif
+
+#define TCBMAGIC NCDRV_MAGIC(NCDRV_TINFO)
+#define AssertTCB() assert(TCB!=0 && TCB->magic==TCBMAGIC)
+#define SetSP() assert(TCB->csp!=0); sp = TCB->csp; (void) sp
+
+/*
+ * This routine needs to do all the work to make curscr look
+ * like newscr.
+ */
+static int
+drv_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    AssertTCB();
+    return TINFO_DOUPDATE(TCB->csp);
+}
+
+static const char *
+drv_Name(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    (void) TCB;
+    return "tinfo";
+}
+
+#undef SETUP_FAIL
+#define SETUP_FAIL FALSE
+
+static bool
+drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret)
+{
+    bool result = FALSE;
+    int status;
+    TERMINAL *termp;
+    SCREEN *sp;
+
+    START_TRACE();
+    T((T_CALLED("tinfo::drv_CanHandle(%p)"), TCB));
+
+    assert(TCB != 0 && tname != 0);
+    termp = (TERMINAL *) TCB;
+    sp = TCB->csp;
+    TCB->magic = TCBMAGIC;
+
+#if (NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP)
+    status = _nc_setup_tinfo(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) {
+	NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx termp);
+	if (status == TGETENT_ERR) {
+	    ret_error0(status, "terminals database is inaccessible\n");
+	} else if (status == TGETENT_NO) {
+	    ret_error1(status, "unknown terminal type.\n", tname);
+	}
+    }
+    result = TRUE;
+#if !USE_REENTRANT
+    strncpy(ttytype, termp->type.term_names, (size_t) NAMESIZE - 1);
+    ttytype[NAMESIZE - 1] = '\0';
+#endif
+
+    if (command_character)
+	_nc_tinfo_cmdch(termp, *command_character);
+
+    if (generic_type) {
+	/*
+	 * BSD 4.3's termcap contains mis-typed "gn" for wy99.  Do a sanity
+	 * check before giving up.
+	 */
+	if ((VALID_STRING(cursor_address)
+	     || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
+	    && VALID_STRING(clear_screen)) {
+	    ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname);
+	} else {
+	    ret_error1(TGETENT_NO, "I need something more specific.\n", tname);
+	}
+    }
+    if (hard_copy) {
+	ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname);
+    }
+
+    returnBool(result);
+}
+
+static int
+drv_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB, int beepFlag)
+{
+    SCREEN *sp;
+    int res = ERR;
+
+    AssertTCB();
+    SetSP();
+
+    /* FIXME: should make sure that we are not in altchar mode */
+    if (beepFlag) {
+	if (bell) {
+	    res = NCURSES_PUTP2("bell", bell);
+	    NCURSES_SP_NAME(_nc_flush) (sp);
+	} else if (flash_screen) {
+	    res = NCURSES_PUTP2("flash_screen", flash_screen);
+	    NCURSES_SP_NAME(_nc_flush) (sp);
+	}
+    } else {
+	if (flash_screen) {
+	    res = NCURSES_PUTP2("flash_screen", flash_screen);
+	    NCURSES_SP_NAME(_nc_flush) (sp);
+	} else if (bell) {
+	    res = NCURSES_PUTP2("bell", bell);
+	    NCURSES_SP_NAME(_nc_flush) (sp);
+	}
+    }
+    return res;
+}
+
+/*
+ * 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 int
+drv_print(TERMINAL_CONTROL_BLOCK * TCB, char *data, int len)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+#if NCURSES_EXT_FUNCS
+    return NCURSES_SP_NAME(mcprint) (TCB->csp, data, len);
+#else
+    return ERR;
+#endif
+}
+
+static int
+drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg)
+{
+    SCREEN *sp;
+    int code = ERR;
+
+    AssertTCB();
+    SetSP();
+
+    if (sp != 0 && orig_pair && orig_colors && (initialize_pair != 0)) {
+#if NCURSES_EXT_FUNCS
+	sp->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
+	sp->_has_sgr_39_49 = (NCURSES_SP_NAME(tigetflag) (NCURSES_SP_ARGx
+							  "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;
+	    NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx
+					0,
+					(short)fg,
+					(short)bg);
+	    sp->_default_color = save;
+	}
+#endif
+	code = OK;
+    }
+    return (code);
+}
+
+static void
+drv_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
+	     int fore,
+	     int color,
+	     NCURSES_SP_OUTC outc)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    if (fore) {
+	if (set_a_foreground) {
+	    TPUTS_TRACE("set_a_foreground");
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    TPARM_1(set_a_foreground, color), 1, outc);
+	} else {
+	    TPUTS_TRACE("set_foreground");
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    TPARM_1(set_foreground,
+					    toggled_colors(color)), 1, outc);
+	}
+    } else {
+	if (set_a_background) {
+	    TPUTS_TRACE("set_a_background");
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    TPARM_1(set_a_background, color), 1, outc);
+	} else {
+	    TPUTS_TRACE("set_background");
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    TPARM_1(set_background,
+					    toggled_colors(color)), 1, outc);
+	}
+    }
+}
+
+static bool
+drv_rescol(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    bool result = FALSE;
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    if (orig_pair != 0) {
+	NCURSES_PUTP2("orig_pair", orig_pair);
+	result = TRUE;
+    }
+    return result;
+}
+
+static bool
+drv_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    int result = FALSE;
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    if (orig_colors != 0) {
+	NCURSES_PUTP2("orig_colors", orig_colors);
+	result = TRUE;
+    }
+    return result;
+}
+
+static int
+drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp)
+{
+    SCREEN *sp;
+    bool useEnv = TRUE;
+    bool useTioctl = TRUE;
+
+    AssertTCB();
+    sp = TCB->csp;		/* can be null here */
+
+    if (sp) {
+	useEnv = sp->_use_env;
+	useTioctl = sp->_use_tioctl;
+    } else {
+	useEnv = _nc_prescreen.use_env;
+	useTioctl = _nc_prescreen.use_tioctl;
+    }
+
+    /* figure out the size of the screen */
+    T(("screen size: terminfo lines = %d columns = %d", lines, columns));
+
+    *linep = (int) lines;
+    *colp = (int) columns;
+
+    if (useEnv || useTioctl) {
+	int value;
+
+#ifdef __EMX__
+	{
+	    int screendata[2];
+	    _scrsize(screendata);
+	    *colp = screendata[0];
+	    *linep = ((sp != 0 && sp->_filtered)
+		      ? 1
+		      : screendata[1]);
+	    T(("EMX screen size: environment LINES = %d COLUMNS = %d",
+	       *linep, *colp));
+	}
+#endif
+#if HAVE_SIZECHANGE
+	/* try asking the OS */
+	{
+	    TERMINAL *termp = (TERMINAL *) TCB;
+	    if (NC_ISATTY(termp->Filedes)) {
+		STRUCT_WINSIZE size;
+
+		errno = 0;
+		do {
+		    if (ioctl(termp->Filedes, IOCTL_WINSIZE, &size) >= 0) {
+			*linep = ((sp != 0 && sp->_filtered)
+				  ? 1
+				  : WINSIZE_ROWS(size));
+			*colp = WINSIZE_COLS(size);
+			T(("SYS screen size: environment LINES = %d COLUMNS = %d",
+			   *linep, *colp));
+			break;
+		    }
+		} while
+		    (errno == EINTR);
+	    }
+	}
+#endif /* HAVE_SIZECHANGE */
+
+	if (useEnv) {
+	    if (useTioctl) {
+		/*
+		 * If environment variables are used, update them.
+		 */
+		if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
+		    _nc_setenv_num("LINES", *linep);
+		}
+		if (_nc_getenv_num("COLUMNS") > 0) {
+		    _nc_setenv_num("COLUMNS", *colp);
+		}
+	    }
+
+	    /*
+	     * Finally, look for environment variables.
+	     *
+	     * Solaris lets users override either dimension with an environment
+	     * variable.
+	     */
+	    if ((value = _nc_getenv_num("LINES")) > 0) {
+		*linep = value;
+		T(("screen size: environment LINES = %d", *linep));
+	    }
+	    if ((value = _nc_getenv_num("COLUMNS")) > 0) {
+		*colp = value;
+		T(("screen size: environment COLUMNS = %d", *colp));
+	    }
+	}
+
+	/* 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));
+    return OK;
+}
+
+static int
+drv_getsize(TERMINAL_CONTROL_BLOCK * TCB, int *l, int *c)
+{
+    AssertTCB();
+    assert(l != 0 && c != 0);
+    *l = lines;
+    *c = columns;
+    return OK;
+}
+
+static int
+drv_setsize(TERMINAL_CONTROL_BLOCK * TCB, int l, int c)
+{
+    AssertTCB();
+    lines = (short) l;
+    columns = (short) c;
+    return OK;
+}
+
+static int
+drv_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
+{
+    SCREEN *sp = TCB->csp;
+    TERMINAL *_term = (TERMINAL *) TCB;
+    int result = OK;
+
+    AssertTCB();
+    if (setFlag) {
+	for (;;) {
+	    if (SET_TTY(_term->Filedes, buf) != 0) {
+		if (errno == EINTR)
+		    continue;
+		if (errno == ENOTTY) {
+		    if (sp)
+			sp->_notty = TRUE;
+		}
+		result = ERR;
+	    }
+	    break;
+	}
+    } else {
+	for (;;) {
+	    if (GET_TTY(_term->Filedes, buf) != 0) {
+		if (errno == EINTR)
+		    continue;
+		result = ERR;
+	    }
+	    break;
+	}
+    }
+    return result;
+}
+
+static int
+drv_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
+{
+    SCREEN *sp;
+    TERMINAL *_term = (TERMINAL *) TCB;
+    int code = ERR;
+
+    AssertTCB();
+    sp = TCB->csp;
+
+    if (progFlag)		/* prog mode */
+    {
+	if (defFlag) {
+	    /* def_prog_mode */
+	    /*
+	     * Turn off the XTABS bit in the tty structure if it was on.
+	     */
+	    if ((drv_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
+#ifdef TERMIOS
+		_term->Nttyb.c_oflag &= (unsigned) ~OFLAGS_TABS;
+#else
+		_term->Nttyb.sg_flags &= (unsigned) ~XTABS;
+#endif
+		code = OK;
+	    }
+	} else {
+	    /* reset_prog_mode */
+	    if (drv_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
+		if (sp) {
+		    if (sp->_keypad_on)
+			_nc_keypad(sp, TRUE);
+		}
+		code = OK;
+	    }
+	}
+    } else {			/* shell mode */
+	if (defFlag) {
+	    /* def_shell_mode */
+	    /*
+	     * If XTABS was on, remove the tab and backtab capabilities.
+	     */
+	    if (drv_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
+#ifdef TERMIOS
+		if (_term->Ottyb.c_oflag & OFLAGS_TABS)
+		    tab = back_tab = NULL;
+#else
+		if (_term->Ottyb.sg_flags & XTABS)
+		    tab = back_tab = NULL;
+#endif
+		code = OK;
+	    }
+	} else {
+	    /* reset_shell_mode */
+	    if (sp) {
+		_nc_keypad(sp, FALSE);
+		NCURSES_SP_NAME(_nc_flush) (sp);
+	    }
+	    code = drv_sgmode(TCB, TRUE, &(_term->Ottyb));
+	}
+    }
+    return (code);
+}
+
+static void
+drv_wrap(SCREEN *sp)
+{
+    if (sp) {
+	sp->_mouse_wrap(sp);
+	NCURSES_SP_NAME(_nc_screen_wrap) (sp);
+	NCURSES_SP_NAME(_nc_mvcur_wrap) (sp);	/* wrap up cursor addressing */
+    }
+}
+
+static void
+drv_release(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
+{
+}
+
+#  define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
+
+static void
+drv_screen_init(SCREEN *sp)
+{
+    TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
+
+    AssertTCB();
+
+    /*
+     * 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.
+     */
+    sp->_use_rmso = SGR0_TEST(exit_standout_mode);
+    sp->_use_rmul = SGR0_TEST(exit_underline_mode);
+
+    /*
+     * 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)));
+
+    NCURSES_SP_NAME(baudrate) (sp);
+
+    NCURSES_SP_NAME(_nc_mvcur_init) (sp);
+    /* initialize terminal to a sane state */
+    NCURSES_SP_NAME(_nc_screen_init) (sp);
+}
+
+static void
+drv_init(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    TERMINAL *trm;
+
+    AssertTCB();
+
+    trm = (TERMINAL *) TCB;
+
+    TCB->info.initcolor = VALID_STRING(initialize_color);
+    TCB->info.canchange = can_change;
+    TCB->info.hascolor = ((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);
+
+    TCB->info.caninit = !(exit_ca_mode && non_rev_rmcup);
+
+    TCB->info.maxpairs = VALID_NUMERIC(max_pairs) ? max_pairs : 0;
+    TCB->info.maxcolors = VALID_NUMERIC(max_colors) ? max_colors : 0;
+    TCB->info.numlabels = VALID_NUMERIC(num_labels) ? num_labels : 0;
+    TCB->info.labelwidth = VALID_NUMERIC(label_width) ? label_width : 0;
+    TCB->info.labelheight = VALID_NUMERIC(label_height) ? label_height : 0;
+    TCB->info.nocolorvideo = VALID_NUMERIC(no_color_video) ? no_color_video
+	: 0;
+    TCB->info.tabsize = VALID_NUMERIC(init_tabs) ? (int) init_tabs : 8;
+
+    TCB->info.defaultPalette = hue_lightness_saturation ? _nc_hls_palette : _nc_cga_palette;
+
+    /*
+     * 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 (NC_ISATTY(trm->Filedes)) {
+	TCB->drv->td_mode(TCB, TRUE, TRUE);
+    }
+}
+
+#define MAX_PALETTE	8
+#define InPalette(n)	((n) >= 0 && (n) < MAX_PALETTE)
+
+static void
+drv_initpair(TERMINAL_CONTROL_BLOCK * TCB, int pair, int f, int b)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    if ((initialize_pair != NULL) && InPalette(f) && InPalette(b)) {
+	const color_t *tp = InfoOf(sp).defaultPalette;
+
+	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));
+
+	NCURSES_PUTP2("initialize_pair",
+		      TPARM_7(initialize_pair,
+			      pair,
+			      tp[f].red, tp[f].green, tp[f].blue,
+			      tp[b].red, tp[b].green, tp[b].blue));
+    }
+}
+
+static int
+default_fg(SCREEN *sp)
+{
+#if NCURSES_EXT_FUNCS
+    return (sp != 0) ? sp->_default_fg : COLOR_WHITE;
+#else
+    return COLOR_WHITE;
+#endif
+}
+
+static int
+default_bg(SCREEN *sp)
+{
+#if NCURSES_EXT_FUNCS
+    return sp != 0 ? sp->_default_bg : COLOR_BLACK;
+#else
+    return COLOR_BLACK;
+#endif
+}
+
+static void
+drv_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
+	      int color, int r, int g, int b)
+{
+    SCREEN *sp = TCB->csp;
+
+    AssertTCB();
+    if (initialize_color != NULL) {
+	NCURSES_PUTP2("initialize_color",
+		      TPARM_4(initialize_color, color, r, g, b));
+    }
+}
+
+static void
+drv_do_color(TERMINAL_CONTROL_BLOCK * TCB,
+	     int old_pair,
+	     int pair,
+	     int reverse,
+	     NCURSES_SP_OUTC outc)
+{
+    SCREEN *sp = TCB->csp;
+    NCURSES_COLOR_T fg = COLOR_DEFAULT;
+    NCURSES_COLOR_T bg = COLOR_DEFAULT;
+    NCURSES_COLOR_T old_fg, old_bg;
+
+    AssertTCB();
+    if (sp == 0)
+	return;
+
+    if (pair < 0 || pair >= COLOR_PAIRS) {
+	return;
+    } else if (pair != 0) {
+	if (set_color_pair) {
+	    TPUTS_TRACE("set_color_pair");
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    TPARM_1(set_color_pair, pair), 1, outc);
+	    return;
+	} else if (sp != 0) {
+	    NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
+					   (short) pair,
+					   &fg,
+					   &bg);
+	}
+    }
+
+    if (old_pair >= 0
+	&& sp != 0
+	&& NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
+					  (short) 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)) {
+		NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
+	    } else if (sp->_has_sgr_39_49
+		       && isDefaultColor(old_fg)
+		       && !isDefaultColor(old_bg)) {
+		NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
+	    } else
+#endif
+		drv_rescol(TCB);
+	}
+    } else {
+	drv_rescol(TCB);
+	if (old_pair < 0)
+	    return;
+    }
+
+#if NCURSES_EXT_FUNCS
+    if (isDefaultColor(fg))
+	fg = (NCURSES_COLOR_T) default_fg(sp);
+    if (isDefaultColor(bg))
+	bg = (NCURSES_COLOR_T) default_bg(sp);
+#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)) {
+	drv_setcolor(TCB, TRUE, fg, outc);
+    }
+    if (!isDefaultColor(bg)) {
+	drv_setcolor(TCB, FALSE, bg, outc);
+    }
+}
+
+#define xterm_kmous "\033[M"
+static void
+init_xterm_mouse(SCREEN *sp)
+{
+    sp->_mouse_type = M_XTERM;
+    sp->_mouse_xtermcap = NCURSES_SP_NAME(tigetstr) (NCURSES_SP_ARGx "XM");
+    if (!VALID_STRING(sp->_mouse_xtermcap))
+	sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
+}
+
+static void
+drv_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    /* we know how to recognize mouse events under "xterm" */
+    if (sp != 0) {
+	if (key_mouse != 0) {
+	    if (!strcmp(key_mouse, xterm_kmous)
+		|| strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
+		init_xterm_mouse(sp);
+	    }
+	} else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
+	    if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
+		init_xterm_mouse(sp);
+	}
+    }
+}
+
+static int
+drv_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
+	      int delay
+	      EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    int rc = 0;
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+#if USE_SYSMOUSE
+    if ((sp->_mouse_type == M_SYSMOUSE)
+	&& (sp->_sysmouse_head < sp->_sysmouse_tail)) {
+	rc = TW_MOUSE;
+    } else
+#endif
+    {
+	rc = TCBOf(sp)->drv->td_twait(TCBOf(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 |= TW_MOUSE;
+	}
+#endif
+    }
+    return rc;
+}
+
+static int
+drv_mvcur(TERMINAL_CONTROL_BLOCK * TCB, int yold, int xold, int ynew, int xnew)
+{
+    SCREEN *sp = TCB->csp;
+    AssertTCB();
+    return NCURSES_SP_NAME(_nc_mvcur) (sp, yold, xold, ynew, xnew);
+}
+
+static void
+drv_hwlabel(TERMINAL_CONTROL_BLOCK * TCB, int labnum, char *text)
+{
+    SCREEN *sp = TCB->csp;
+
+    AssertTCB();
+    if (labnum > 0 && labnum <= num_labels) {
+	NCURSES_PUTP2("plab_norm",
+		      TPARM_2(plab_norm, labnum, text));
+    }
+}
+
+static void
+drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB, int OnFlag)
+{
+    SCREEN *sp = TCB->csp;
+
+    AssertTCB();
+    if (OnFlag) {
+	NCURSES_PUTP2("label_on", label_on);
+    } else {
+	NCURSES_PUTP2("label_off", label_off);
+    }
+}
+
+static chtype
+drv_conattr(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    SCREEN *sp = TCB->csp;
+    chtype attrs = A_NORMAL;
+
+    AssertTCB();
+    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 && sp->_coloron)
+	attrs |= A_COLOR;
+
+#if USE_ITALIC
+    if (enter_italics_mode)
+	attrs |= A_ITALIC;
+#endif
+
+    return (attrs);
+}
+
+static void
+drv_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    AssertTCB();
+
+    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;
+}
+
+static void
+drv_initacs(TERMINAL_CONTROL_BLOCK * TCB, chtype *real_map, chtype *fake_map)
+{
+    SCREEN *sp = TCB->csp;
+
+    AssertTCB();
+    assert(sp != 0);
+    if (ena_acs != NULL) {
+	NCURSES_PUTP2("ena_acs", 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] = (chtype) 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 */
+}
+
+#define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
+
+NCURSES_EXPORT(void)
+_nc_cookie_init(SCREEN *sp)
+{
+    bool support_cookies = USE_XMC_SUPPORT;
+    TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) (sp->_term);
+
+    if (sp == 0 || !ENSURE_TINFO(sp))
+	return;
+
+#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 & XMC_CONFLICT;
+#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(sp->_term)) {
+	acs_chars = NULL;
+	ena_acs = NULL;
+	enter_alt_charset_mode = NULL;
+	exit_alt_charset_mode = NULL;
+	set_attributes = NULL;
+    }
+#endif
+}
+
+static int
+drv_twait(TERMINAL_CONTROL_BLOCK * TCB,
+	  int mode,
+	  int milliseconds,
+	  int *timeleft
+	  EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    return _nc_timed_wait(sp, mode, milliseconds, timeleft EVENTLIST_2nd(evl));
+}
+
+static int
+drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
+{
+    SCREEN *sp;
+    unsigned char c2 = 0;
+    int n;
+
+    AssertTCB();
+    assert(buf);
+    SetSP();
+
+# if USE_PTHREADS_EINTR
+    if ((pthread_self) && (pthread_kill) && (pthread_equal))
+	_nc_globals.read_thread = pthread_self();
+# endif
+    n = (int) read(sp->_ifd, &c2, (size_t) 1);
+#if USE_PTHREADS_EINTR
+    _nc_globals.read_thread = 0;
+#endif
+    *buf = (int) c2;
+    return n;
+}
+
+static int
+drv_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int 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
+    return OK;
+}
+
+static int
+__nc_putp(SCREEN *sp, const char *name GCC_UNUSED, const char *value)
+{
+    int rc = ERR;
+
+    if (value) {
+	rc = NCURSES_PUTP2(name, value);
+    }
+    return rc;
+}
+
+static int
+__nc_putp_flush(SCREEN *sp, const char *name, const char *value)
+{
+    int rc = __nc_putp(sp, name, value);
+    if (rc != ERR) {
+	NCURSES_SP_NAME(_nc_flush) (sp);
+    }
+    return rc;
+}
+
+static int
+drv_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag)
+{
+    int ret = ERR;
+    SCREEN *sp;
+
+    AssertTCB();
+
+    sp = TCB->csp;
+
+    if (sp) {
+	if (flag) {
+	    (void) __nc_putp_flush(sp, "keypad_xmit", keypad_xmit);
+	} else if (!flag && keypad_local) {
+	    (void) __nc_putp_flush(sp, "keypad_local", keypad_local);
+	}
+	if (flag && !sp->_tried) {
+	    _nc_init_keytry(sp);
+	    sp->_tried = TRUE;
+	}
+	ret = OK;
+    }
+
+    return ret;
+}
+
+static int
+drv_keyok(TERMINAL_CONTROL_BLOCK * TCB, int c, int flag)
+{
+    SCREEN *sp;
+    int code = ERR;
+    int count = 0;
+    char *s;
+
+    AssertTCB();
+    SetSP();
+
+    if (c >= 0) {
+	unsigned ch = (unsigned) c;
+	if (flag) {
+	    while ((s = _nc_expand_try(sp->_key_ok,
+				       ch, &count, (size_t) 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, (size_t) 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;
+	    }
+	}
+    }
+    return (code);
+}
+
+static int
+drv_cursorSet(TERMINAL_CONTROL_BLOCK * TCB, int vis)
+{
+    SCREEN *sp;
+    int code = ERR;
+
+    AssertTCB();
+    SetSP();
+
+    T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM, vis));
+
+    if (SP_PARM != 0 && IsTermInfo(SP_PARM)) {
+	switch (vis) {
+	case 2:
+	    code = NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible);
+	    break;
+	case 1:
+	    code = NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal);
+	    break;
+	case 0:
+	    code = NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible);
+	    break;
+	}
+    } else {
+	code = ERR;
+    }
+    returnCode(code);
+}
+
+static bool
+drv_kyExist(TERMINAL_CONTROL_BLOCK * TCB, int key)
+{
+    bool res = FALSE;
+
+    AssertTCB();
+    if (TCB->csp)
+	res = TINFO_HAS_KEY(TCB->csp, key) == 0 ? FALSE : TRUE;
+
+    return res;
+}
+
+NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_TINFO_DRIVER = {
+    TRUE,
+	drv_Name,		/* Name */
+	drv_CanHandle,		/* CanHandle */
+	drv_init,		/* init */
+	drv_release,		/* release */
+	drv_size,		/* size */
+	drv_sgmode,		/* sgmode */
+	drv_conattr,		/* conattr */
+	drv_mvcur,		/* hwcur */
+	drv_mode,		/* mode */
+	drv_rescol,		/* rescol */
+	drv_rescolors,		/* rescolors */
+	drv_setcolor,		/* color */
+	drv_dobeepflash,	/* doBeepOrFlash */
+	drv_initpair,		/* initpair */
+	drv_initcolor,		/* initcolor */
+	drv_do_color,		/* docolor */
+	drv_initmouse,		/* initmouse */
+	drv_testmouse,		/* testmouse */
+	drv_setfilter,		/* setfilter */
+	drv_hwlabel,		/* hwlabel */
+	drv_hwlabelOnOff,	/* hwlabelOnOff */
+	drv_doupdate,		/* update */
+	drv_defaultcolors,	/* defaultcolors */
+	drv_print,		/* print */
+	drv_getsize,		/* getsize */
+	drv_setsize,		/* setsize */
+	drv_initacs,		/* initacs */
+	drv_screen_init,	/* scinit */
+	drv_wrap,		/* scexit */
+	drv_twait,		/* twait  */
+	drv_read,		/* read */
+	drv_nap,		/* nap */
+	drv_kpad,		/* kpad */
+	drv_keyok,		/* kyOk */
+	drv_kyExist,		/* kyExist */
+	drv_cursorSet		/* cursorSet */
+};
diff --git a/ncurses/tinfo/trim_sgr0.c b/ncurses/tinfo/trim_sgr0.c
index 80c8f77..ec5e2b7 100644
--- a/ncurses/tinfo/trim_sgr0.c
+++ b/ncurses/tinfo/trim_sgr0.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2005-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2005-2010,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,9 +35,8 @@
 #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 $")
+MODULE_ID("$Id: trim_sgr0.c,v 1.15 2012/12/15 20:57:17 tom Exp $")
 
 #undef CUR
 #define CUR tp->
@@ -49,21 +48,28 @@
 static char *
 set_attribute_9(TERMTYPE *tp, int flag)
 {
-    const char *result;
+    const char *value;
+    char *result;
 
-    if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0)
-	result = "";
-    return strdup(result);
+    value = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag);
+    if (PRESENT(value))
+	result = strdup(value);
+    else
+	result = 0;
+    return 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;
+    int result = 0;
+    if (s != 0) {
+	if (UChar(s[0]) == CSI)
+	    result = 1;
+	else if (s[0] == ESC && s[1] == L_BRACK)
+	    result = 2;
+    }
+    return result;
 }
 
 static char *
@@ -98,10 +104,10 @@
 static bool
 rewrite_sgr(char *s, char *attr)
 {
-    if (PRESENT(s)) {
+    if (s != 0) {
 	if (PRESENT(attr)) {
-	    unsigned len_s = strlen(s);
-	    unsigned len_a = strlen(attr);
+	    size_t len_s = strlen(s);
+	    size_t len_a = strlen(attr);
 
 	    if (len_s > len_a && !strncmp(attr, s, len_a)) {
 		unsigned n;
@@ -109,7 +115,7 @@
 		for (n = 0; n < len_s - len_a; ++n) {
 		    s[n] = s[n + len_a];
 		}
-		strcpy(s + n, attr);
+		_nc_STRCPY(s + n, attr, strlen(s) + 1);
 		TR(TRACE_DATABASE, ("to:\n\t%s", s));
 	    }
 	}
@@ -122,33 +128,35 @@
 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;
+    if (a != 0 && b != 0) {
+	int csi_a = is_csi(a);
+	int csi_b = is_csi(b);
+	size_t len_a;
+	size_t 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);
+	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)));
     }
-    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;
 }
 
@@ -170,13 +178,13 @@
  * Returns the number of chars from 'full' that we matched.  If any mismatch
  * occurs, return zero.
  */
-static int
+static unsigned
 compare_part(const char *part, const char *full)
 {
     const char *next_part;
     const char *next_full;
-    int used_full = 0;
-    int used_delay = 0;
+    unsigned used_full = 0;
+    unsigned used_delay = 0;
 
     while (*part != 0) {
 	if (*part != *full) {
@@ -199,7 +207,7 @@
 	    next_part = skip_delay(part);
 	    next_full = skip_delay(full);
 	    if (next_part != part && next_full != full) {
-		used_delay += (next_full - full);
+		used_delay += (unsigned) (next_full - full);
 		full = next_full;
 		part = next_part;
 		continue;
@@ -261,10 +269,11 @@
 		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);
+			unsigned k2 = compare_part(exit_alt_charset_mode,
+						   off + i);
 			if (k2 != 0) {
 			    found = TRUE;
-			    chop_out(off, i, i + k2);
+			    chop_out(off, (unsigned) i, (unsigned) (i + k2));
 			    break;
 			}
 		    }
@@ -274,18 +283,18 @@
 	     * SGR 10 would reset to normal font.
 	     */
 	    if (!found) {
-		if ((i = is_csi(off)) != 0
+		if ((i = (size_t) 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;
+			i = (size_t) (tmp - off);
 			if (off[i - 1] == ';')
 			    i--;
-			j = skip_zero(tmp + 1) - off;
-			i = chop_out(off, i, j);
+			j = (size_t) (skip_zero(tmp + 1) - off);
+			(void) chop_out(off, (unsigned) i, (unsigned) j);
 			found = TRUE;
 		    }
 		}
@@ -293,10 +302,10 @@
 	    if (!found
 		&& (tmp = strstr(end, off)) != 0
 		&& strcmp(end, off) != 0) {
-		i = tmp - end;
+		i = (size_t) (tmp - end);
 		j = strlen(off);
 		tmp = strdup(end);
-		chop_out(tmp, i, j);
+		chop_out(tmp, (unsigned) i, (unsigned) j);
 		free(off);
 		result = tmp;
 	    }
diff --git a/ncurses/tinfo/use_screen.c b/ncurses/tinfo/use_screen.c
index 6c3b12f..6a0297c 100644
--- a/ncurses/tinfo/use_screen.c
+++ b/ncurses/tinfo/use_screen.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2007,2008 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2007-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -32,7 +32,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: use_screen.c,v 1.6 2008/06/07 19:16:56 tom Exp $")
+MODULE_ID("$Id: use_screen.c,v 1.8 2009/10/24 22:40:20 tom Exp $")
 
 NCURSES_EXPORT(int)
 use_screen(SCREEN *screen, NCURSES_SCREEN_CB func, void *data)
@@ -40,14 +40,14 @@
     SCREEN *save_SP;
     int code = OK;
 
-    T((T_CALLED("use_screen(%p,%p,%p)"), screen, func, data));
+    T((T_CALLED("use_screen(%p,%p,%p)"), (void *) screen, func, (void *) 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;
+    save_SP = CURRENT_SCREEN;
     set_term(screen);
 
     code = func(screen, data);
diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c
index b53bb21..b2edd5d 100644
--- a/ncurses/tinfo/write_entry.c
+++ b/ncurses/tinfo/write_entry.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,14 +39,7 @@
 #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)
@@ -54,7 +47,7 @@
 #define TRACE_OUT(p)		/*nothing */
 #endif
 
-MODULE_ID("$Id: write_entry.c,v 1.72 2008/08/03 19:24:00 tom Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.92 2014/11/01 14:47:00 tom Exp $")
 
 static int total_written;
 
@@ -77,7 +70,7 @@
     DEBUG(1, ("Created %s", filename));
 
     if (write_object(tp, buffer, &offset, limit) == ERR
-	|| fwrite(buffer, sizeof(char), offset, fp) != offset) {
+	|| fwrite(buffer, sizeof(char), (size_t) offset, fp) != offset) {
 	_nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename);
     }
 
@@ -100,13 +93,13 @@
     char dir[sizeof(LEAF_FMT)];
     char *s = 0;
 
-    if (code == 0 || (s = strchr(dirnames, code)) == 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);
+    _nc_SPRINTF(dir, _nc_SLIMIT(sizeof(dir)) LEAF_FMT, code);
     if (make_db_root(dir) < 0) {
 	_nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
     }
@@ -116,34 +109,35 @@
 #endif /* !USE_HASHED_DB */
 
 static int
-make_db_path(char *dst, const char *src, unsigned limit)
+make_db_path(char *dst, const char *src, size_t 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);
+	    _nc_STRCPY(dst, src, limit);
 	    rc = 0;
 	}
     } else {
 	if (strlen(top) + strlen(src) + 2 <= limit) {
-	    (void) sprintf(dst, "%s/%s", top, src);
+	    _nc_SPRINTF(dst, _nc_SLIMIT(limit) "%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;
+	static const char suffix[] = DBM_SUFFIX;
+	size_t have = strlen(dst);
+	size_t need = strlen(suffix);
+	if (have > need && strcmp(dst + (int) (have - need), suffix)) {
+	    if (have + need <= limit) {
+		_nc_STRCAT(dst, suffix, limit);
+	    } else {
+		rc = -1;
 	    }
+	} else if (_nc_is_dir_path(dst)) {
+	    rc = -1;
 	}
     }
 #endif
@@ -163,15 +157,20 @@
 #if USE_HASHED_DB
 	DB *capdbp;
 
-	if ((capdbp = _nc_db_open(fullpath, TRUE)) == NULL)
+	if ((capdbp = _nc_db_open(fullpath, TRUE)) == NULL) {
 	    rc = -1;
-	else if (_nc_db_close(capdbp) < 0)
+	} else if (_nc_db_close(capdbp) < 0) {
 	    rc = -1;
+	}
 #else
 	struct stat statbuf;
 
 	if ((rc = stat(path, &statbuf)) < 0) {
-	    rc = mkdir(path, 0777);
+	    rc = mkdir(path
+#if !defined(__MINGW32__)
+		       ,0777
+#endif
+		);
 	} else if (_nc_access(path, R_OK | W_OK | X_OK) < 0) {
 	    rc = -1;		/* permission denied */
 	} else if (!(S_ISDIR(statbuf.st_mode))) {
@@ -186,13 +185,16 @@
  * Set the write directory for compiled entries.
  */
 NCURSES_EXPORT(void)
-_nc_set_writedir(char *dir)
+_nc_set_writedir(const char *dir)
 {
     const char *destination;
     char actual[PATH_MAX];
 
     if (dir == 0
-	&& use_terminfo_vars())
+#ifndef USE_ROOT_ENVIRON
+	&& use_terminfo_vars()
+#endif
+	)
 	dir = getenv("TERMINFO");
 
     if (dir != 0)
@@ -274,16 +276,21 @@
     char name_list[MAX_TERMINFO_LENGTH];
     char *first_name, *other_names;
     char *ptr;
+    char *term_names = tp->term_names;
+    size_t name_size = strlen(term_names);
 
-    assert(strlen(tp->term_names) != 0);
-    assert(strlen(tp->term_names) < sizeof(name_list));
+    if (name_size == 0) {
+	_nc_syserr_abort("no terminal name found.");
+    } else if (name_size >= sizeof(name_list) - 1) {
+	_nc_syserr_abort("terminal name too long: %s", term_names);
+    }
 
-    (void) strcpy(name_list, tp->term_names);
+    _nc_STRCPY(name_list, term_names, sizeof(name_list));
     DEBUG(7, ("Name list = '%s'", name_list));
 
     first_name = name_list;
 
-    ptr = &name_list[strlen(name_list) - 1];
+    ptr = &name_list[name_size - 1];
     other_names = ptr + 1;
 
     while (ptr > name_list && *ptr != '|')
@@ -317,8 +324,8 @@
 	    buffer[0] = 0;
 
 	    memset(&key, 0, sizeof(key));
-	    key.data = tp->term_names;
-	    key.size = strlen(tp->term_names);
+	    key.data = term_names;
+	    key.size = name_size;
 
 	    memset(&data, 0, sizeof(data));
 	    data.data = buffer;
@@ -331,13 +338,16 @@
 	    key.data = name_list;
 	    key.size = strlen(name_list);
 
-	    strcpy(buffer + 1, tp->term_names);
-	    data.size = strlen(tp->term_names) + 1;
+	    _nc_STRCPY(buffer + 1,
+		       term_names,
+		       sizeof(buffer) - 1);
+	    data.size = name_size + 1;
 
 	    _nc_db_put(capdb, &key, &data);
 
 	    while (*other_names != '\0') {
 		ptr = other_names++;
+		assert(ptr < buffer + sizeof(buffer) - 1);
 		while (*other_names != '|' && *other_names != '\0')
 		    other_names++;
 
@@ -349,7 +359,6 @@
 
 		_nc_db_put(capdb, &key, &data);
 	    }
-	    _nc_db_close(capdb);
 	}
     }
 #else /* !USE_HASHED_DB */
@@ -357,10 +366,11 @@
 	start_time = 0;
     }
 
-    if (strlen(first_name) >= sizeof(filename) - 3)
+    if (strlen(first_name) >= sizeof(filename) - (2 + LEAF_LEN))
 	_nc_warning("terminal name too long.");
 
-    sprintf(filename, LEAF_FMT "/%s", first_name[0], first_name);
+    _nc_SPRINTF(filename, _nc_SLIMIT(sizeof(filename))
+		LEAF_FMT "/%s", first_name[0], first_name);
 
     /*
      * Has this primary name been written since the first call to
@@ -370,7 +380,22 @@
     if (start_time > 0 &&
 	stat(filename, &statbuf) >= 0
 	&& statbuf.st_mtime >= start_time) {
+#if HAVE_LINK && !USE_SYMLINKS
+	/*
+	 * If the file has more than one link, the reason for the previous
+	 * write could be that the current primary name used to be an alias for
+	 * the previous entry.  In that case, unlink the file so that we will
+	 * not modify the previous entry as we write this one.
+	 */
+	if (statbuf.st_nlink > 1) {
+	    _nc_warning("name redefined.");
+	    unlink(filename);
+	} else {
+	    _nc_warning("name multiply defined.");
+	}
+#else
 	_nc_warning("name multiply defined.");
+#endif
     }
 
     check_writeable(first_name[0]);
@@ -385,14 +410,13 @@
     }
     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) {
+	if (strlen(ptr) > sizeof(linkname) - (2 + LEAF_LEN)) {
 	    _nc_warning("terminal alias %s too long.", ptr);
 	    continue;
 	}
@@ -402,7 +426,8 @@
 	}
 
 	check_writeable(ptr[0]);
-	sprintf(linkname, LEAF_FMT "/%s", ptr[0], ptr);
+	_nc_SPRINTF(linkname, _nc_SLIMIT(sizeof(linkname))
+		    LEAF_FMT "/%s", ptr[0], ptr);
 
 	if (strcmp(filename, linkname) == 0) {
 	    _nc_warning("self-synonym ignored");
@@ -414,8 +439,12 @@
 	{
 	    int code;
 #if USE_SYMLINKS
-	    strcpy(symlinkname, "../");
-	    strncat(symlinkname, filename, sizeof(symlinkname) - 4);
+	    if (first_name[0] == linkname[0])
+		strncpy(symlinkname, first_name, sizeof(symlinkname) - 1);
+	    else {
+		_nc_STRCPY(symlinkname, "../", sizeof(suymlinkname));
+		strncat(symlinkname, filename, sizeof(symlinkname) - 4);
+	    }
 	    symlinkname[sizeof(symlinkname) - 1] = '\0';
 #endif /* USE_SYMLINKS */
 #if HAVE_REMOVE
@@ -460,42 +489,43 @@
 #endif /* USE_HASHED_DB */
 }
 
-static unsigned
+static size_t
 fake_write(char *dst,
 	   unsigned *offset,
-	   unsigned limit,
+	   size_t limit,
 	   char *src,
-	   unsigned want,
-	   unsigned size)
+	   size_t want,
+	   size_t size)
 {
-    int have = (limit - *offset);
+    size_t have = (limit - *offset);
 
     want *= size;
     if (have > 0) {
-	if ((int) want > have)
+	if (want > have)
 	    want = have;
 	memcpy(dst + *offset, src, want);
-	*offset += want;
+	*offset += (unsigned) want;
     } else {
 	want = 0;
     }
-    return (int) (want / size);
+    return (want / size);
 }
 
-#define Write(buf, size, count) fake_write(buffer, offset, limit, (char *) buf, count, size)
+#define Write(buf, size, count) fake_write(buffer, offset, (size_t) limit, (char *) buf, (size_t) count, (size_t) 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 LITTLE_ENDIAN(p, x)	(p)[0] = (unsigned char)LO(x),  \
+                                (p)[1] = (unsigned char)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)
+compute_offsets(char **Strings, size_t strmax, short *offsets)
 {
-    size_t nextfree = 0;
-    unsigned i;
+    int nextfree = 0;
+    size_t i;
 
     for (i = 0; i < strmax; i++) {
 	if (Strings[i] == ABSENT_STRING) {
@@ -503,8 +533,8 @@
 	} else if (Strings[i] == CANCELLED_STRING) {
 	    offsets[i] = -2;
 	} else {
-	    offsets[i] = nextfree;
-	    nextfree += strlen(Strings[i]) + 1;
+	    offsets[i] = (short) nextfree;
+	    nextfree += (int) strlen(Strings[i]) + 1;
 	    TRACE_OUT(("put Strings[%d]=%s(%d)", (int) i,
 		       _nc_visbuf(Strings[i]), (int) nextfree));
 	}
@@ -513,9 +543,9 @@
 }
 
 static void
-convert_shorts(unsigned char *buf, short *Numbers, unsigned count)
+convert_shorts(unsigned char *buf, short *Numbers, size_t count)
 {
-    unsigned i;
+    size_t 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;
@@ -524,7 +554,7 @@
 	    buf[2 * i + 1] = 0377;
 	} else {
 	    LITTLE_ENDIAN(buf + 2 * i, Numbers[i]);
-	    TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i]));
+	    TRACE_OUT(("put Numbers[%u]=%d", (unsigned) i, Numbers[i]));
 	}
     }
 }
@@ -536,8 +566,8 @@
 static unsigned
 extended_Booleans(TERMTYPE *tp)
 {
-    unsigned short result = 0;
-    unsigned short i;
+    unsigned result = 0;
+    unsigned i;
 
     for (i = 0; i < tp->ext_Booleans; ++i) {
 	if (tp->Booleans[BOOLCOUNT + i] == TRUE)
@@ -549,8 +579,8 @@
 static unsigned
 extended_Numbers(TERMTYPE *tp)
 {
-    unsigned short result = 0;
-    unsigned short i;
+    unsigned result = 0;
+    unsigned i;
 
     for (i = 0; i < tp->ext_Numbers; ++i) {
 	if (tp->Numbers[NUMCOUNT + i] != ABSENT_NUMERIC)
@@ -567,7 +597,7 @@
 
     for (i = 0; i < tp->ext_Strings; ++i) {
 	if (tp->Strings[STRCOUNT + i] != ABSENT_STRING)
-	    result = (i + 1);
+	    result = (unsigned short) (i + 1);
     }
     return result;
 }
@@ -597,7 +627,7 @@
     size_t namelen, boolmax, nummax, strmax;
     char zero = '\0';
     size_t i;
-    short nextfree;
+    int nextfree;
     short offsets[MAX_ENTRY_SIZE / 2];
     unsigned char buf[MAX_ENTRY_SIZE];
     unsigned last_bool = BOOLWRITE;
@@ -690,13 +720,13 @@
 
 #if NCURSES_XNAMES
     if (extended_object(tp)) {
-	unsigned extcnt = NUM_EXT_NAMES(tp);
+	unsigned extcnt = (unsigned) NUM_EXT_NAMES(tp);
 
 	if (even_boundary(nextfree))
 	    return (ERR);
 
 	nextfree = compute_offsets(tp->Strings + STRCOUNT,
-				   tp->ext_Strings,
+				   (size_t) tp->ext_Strings,
 				   offsets);
 	TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree));
 
@@ -704,7 +734,7 @@
 	    return (ERR);
 
 	nextfree += compute_offsets(tp->ext_Names,
-				    extcnt,
+				    (size_t) extcnt,
 				    offsets + tp->ext_Strings);
 	TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
 	strmax = tp->ext_Strings + extcnt;
@@ -732,7 +762,7 @@
 
 	TRACE_OUT(("WRITE %d numbers @%d", tp->ext_Numbers, *offset));
 	if (tp->ext_Numbers) {
-	    convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers);
+	    convert_shorts(buf, tp->Numbers + NUMCOUNT, (size_t) tp->ext_Numbers);
 	    if (Write(buf, 2, tp->ext_Numbers) != tp->ext_Numbers)
 		return (ERR);
 	}
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
index 743b1f6..cec01de 100644
--- a/ncurses/trace/lib_trace.c
+++ b/ncurses/trace/lib_trace.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 /*
@@ -46,7 +47,7 @@
 
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_trace.c,v 1.71 2008/08/23 18:04:29 tom Exp $")
+MODULE_ID("$Id: lib_trace.c,v 1.82 2013/07/06 19:42:09 tom Exp $")
 
 NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
 
@@ -56,26 +57,26 @@
 NCURSES_EXPORT(const char *)
 NCURSES_PUBLIC_VAR(_nc_tputs_trace) (void)
 {
-    return SP ? SP->_tputs_trace : _nc_prescreen._tputs_trace;
+    return CURRENT_SCREEN ? CURRENT_SCREEN->_tputs_trace : _nc_prescreen._tputs_trace;
 }
 NCURSES_EXPORT(long)
 NCURSES_PUBLIC_VAR(_nc_outchars) (void)
 {
-    return SP ? SP->_outchars : _nc_prescreen._outchars;
+    return CURRENT_SCREEN ? CURRENT_SCREEN->_outchars : _nc_prescreen._outchars;
 }
 NCURSES_EXPORT(void)
 _nc_set_tputs_trace(const char *s)
 {
-    if (SP)
-	SP->_tputs_trace = s;
+    if (CURRENT_SCREEN)
+	CURRENT_SCREEN->_tputs_trace = s;
     else
 	_nc_prescreen._tputs_trace = s;
 }
 NCURSES_EXPORT(void)
 _nc_count_outchars(long increment)
 {
-    if (SP)
-	SP->_outchars += increment;
+    if (CURRENT_SCREEN)
+	CURRENT_SCREEN->_outchars += increment;
     else
 	_nc_prescreen._outchars += increment;
 }
@@ -95,16 +96,16 @@
 	const char *mode = _nc_globals.init_trace ? "ab" : "wb";
 
 	if (TracePath[0] == '\0') {
-	    int size = sizeof(TracePath) - 12;
+	    size_t 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");
+	    _nc_STRCAT(TracePath, "/trace", sizeof(TracePath));
 	    if (_nc_is_dir_path(TracePath)) {
-		strcat(TracePath, ".log");
+		_nc_STRCAT(TracePath, ".log", sizeof(TracePath));
 	    }
 	}
 
@@ -120,8 +121,8 @@
 	 * 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) setvbuf(TraceFP, (char *) 0, _IOLBF, (size_t) 0);
+#elif HAVE_SETBUF /* POSIX */
 	(void) setbuffer(TraceFP, (char *) 0);
 #endif
 	_tracef("TRACING NCURSES version %s.%d (tracelevel=%#x)",
@@ -183,7 +184,11 @@
 # if USE_WEAK_SYMBOLS
 	if ((pthread_self))
 # endif
-	    fprintf(TraceFP, "%#lx:", (long) (void *) pthread_self());
+#ifdef __MINGW32__
+	    fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self().p);
+#else
+	    fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self());
+#endif
 #endif
 	if (before || after) {
 	    int n;
@@ -213,12 +218,20 @@
 
 /* Trace 'bool' return-values */
 NCURSES_EXPORT(NCURSES_BOOL)
-_nc_retrace_bool(NCURSES_BOOL code)
+_nc_retrace_bool(int code)
 {
     T((T_RETURN("%s"), code ? "TRUE" : "FALSE"));
     return code;
 }
 
+/* Trace 'char' return-values */
+NCURSES_EXPORT(char)
+_nc_retrace_char(int code)
+{
+    T((T_RETURN("%c"), code));
+    return (char) code;
+}
+
 /* Trace 'int' return-values */
 NCURSES_EXPORT(int)
 _nc_retrace_int(int code)
@@ -271,7 +284,7 @@
 NCURSES_EXPORT(SCREEN *)
 _nc_retrace_sp(SCREEN *code)
 {
-    T((T_RETURN("%p"), code));
+    T((T_RETURN("%p"), (void *) code));
     return code;
 }
 
@@ -279,7 +292,7 @@
 NCURSES_EXPORT(WINDOW *)
 _nc_retrace_win(WINDOW *code)
 {
-    T((T_RETURN("%p"), code));
+    T((T_RETURN("%p"), (void *) code));
     return code;
 }
 
@@ -326,8 +339,9 @@
     _nc_va_tracef(fmt, ap);
     va_end(ap);
 
-    if (--(_nc_globals.nested_tracef) == 0)
+    if (--(_nc_globals.nested_tracef) == 0) {
 	_nc_unlock_global(tracef);
+    }
 }
 #endif /* USE_REENTRANT */
 
diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c
index 45a03ce..24772d8 100644
--- a/ncurses/trace/lib_traceatr.c
+++ b/ncurses/trace/lib_traceatr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  Author: Thomas Dickey                           1996-on                 *
  *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Juergen Pfeifer                                                 *
  ****************************************************************************/
 
 /*
@@ -37,12 +38,18 @@
  */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_traceatr.c,v 1.83 2015/04/04 13:41:37 tom Exp $")
 
 #define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
 
+#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
+#define COLOR_BUF_SIZE(num) (sizeof(my_buffer[num]))
+
 #ifdef TRACE
 
 static const char l_brace[] = StringOf(L_BRACE);
@@ -61,9 +68,12 @@
 	my_cached = c;
 	my_select = !my_select;
 	if (c == COLOR_DEFAULT)
-	    strcpy(my_buffer[my_select], "default");
+	    _nc_STRCPY(my_buffer[my_select], "default",
+		       COLOR_BUF_SIZE(my_select));
 	else
-	    sprintf(my_buffer[my_select], "color%d", c);
+	    _nc_SPRINTF(my_buffer[my_select],
+			_nc_SLIMIT(COLOR_BUF_SIZE(my_select))
+			"color%d", c);
     }
     return my_buffer[my_select];
 }
@@ -75,78 +85,79 @@
 NCURSES_EXPORT(char *)
 _traceattr2(int bufnum, chtype newmode)
 {
+#define DATA(name) { name, { #name } }
     static const struct {
 	unsigned int val;
-	const char *name;
+	const char name[14];
     } 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* */
-
+	DATA(A_STANDOUT),
+	    DATA(A_UNDERLINE),
+	    DATA(A_REVERSE),
+	    DATA(A_BLINK),
+	    DATA(A_DIM),
+	    DATA(A_BOLD),
+	    DATA(A_ALTCHARSET),
+	    DATA(A_INVIS),
+	    DATA(A_PROTECT),
+	    DATA(A_CHARTEXT),
+	    DATA(A_NORMAL),
+	    DATA(A_COLOR),
+#if USE_ITALIC
+	    DATA(A_ITALIC),
+#endif
     }
 #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* */
-
+	DATA(COLOR_BLACK),
+	    DATA(COLOR_RED),
+	    DATA(COLOR_GREEN),
+	    DATA(COLOR_YELLOW),
+	    DATA(COLOR_BLUE),
+	    DATA(COLOR_MAGENTA),
+	    DATA(COLOR_CYAN),
+	    DATA(COLOR_WHITE),
     }
 #endif /* !USE_TERMLIB */
     ;
+#undef DATA
     size_t n;
     char temp[80];
-    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+    char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
 
     if (result != 0) {
 	unsigned save_nc_tracing = _nc_tracing;
 
 	_nc_tracing = 0;
 
-	strcpy(result, l_brace);
+	_nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
 
 	for (n = 0; n < SIZEOF(names); n++) {
 	    if ((newmode & names[n].val) != 0) {
 		if (result[1] != '\0')
-		    result = _nc_trace_bufcat(bufnum, "|");
+		    (void) _nc_trace_bufcat(bufnum, "|");
 		result = _nc_trace_bufcat(bufnum, names[n].name);
 
 		if (names[n].val == A_COLOR) {
-		    short pairnum = PAIR_NUMBER(newmode);
+		    short pairnum = (short) PairNumber(newmode);
 #ifdef USE_TERMLIB
 		    /* pair_content lives in libncurses */
-		    (void) sprintf(temp, "{%d}", pairnum);
+		    _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+				"{%d}", pairnum);
 #else
-		    short fg, bg;
+		    NCURSES_COLOR_T fg, bg;
 
 		    if (pair_content(pairnum, &fg, &bg) == OK) {
-			(void) sprintf(temp,
-				       "{%d = {%s, %s}}",
-				       pairnum,
-				       COLOR_OF(fg),
-				       COLOR_OF(bg));
+			_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+				    "{%d = {%s, %s}}",
+				    pairnum,
+				    COLOR_OF(fg),
+				    COLOR_OF(bg));
 		    } else {
-			(void) sprintf(temp, "{%d}", pairnum);
+			_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+				    "{%d}", pairnum);
 		    }
 #endif
 		    result = _nc_trace_bufcat(bufnum, temp);
@@ -172,6 +183,14 @@
 }
 
 /* Trace 'int' return-values */
+NCURSES_EXPORT(int)
+_nc_retrace_int_attr_t(attr_t code)
+{
+    T((T_RETURN("%s"), _traceattr(code)));
+    return (int) code;
+}
+
+/* Trace 'attr_t' return-values */
 NCURSES_EXPORT(attr_t)
 _nc_retrace_attr_t(attr_t code)
 {
@@ -182,68 +201,76 @@
 const char *
 _nc_altcharset_name(attr_t attr, chtype ch)
 {
+#define DATA(code, name) { code, { #name } }
     typedef struct {
 	unsigned int val;
-	const char *name;
+	const char name[13];
     } ALT_NAMES;
+#if NCURSES_SP_FUNCS
+    SCREEN *sp = CURRENT_SCREEN;
+#endif
     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}
+	DATA('l', ACS_ULCORNER),	/* upper left corner */
+	DATA('m', ACS_LLCORNER),	/* lower left corner */
+	DATA('k', ACS_URCORNER),	/* upper right corner */
+	DATA('j', ACS_LRCORNER),	/* lower right corner */
+	DATA('t', ACS_LTEE),	/* tee pointing right */
+	DATA('u', ACS_RTEE),	/* tee pointing left */
+	DATA('v', ACS_BTEE),	/* tee pointing up */
+	DATA('w', ACS_TTEE),	/* tee pointing down */
+	DATA('q', ACS_HLINE),	/* horizontal line */
+	DATA('x', ACS_VLINE),	/* vertical line */
+	DATA('n', ACS_PLUS),	/* large plus or crossover */
+	DATA('o', ACS_S1),	/* scan line 1 */
+	DATA('s', ACS_S9),	/* scan line 9 */
+	DATA('`', ACS_DIAMOND),	/* diamond */
+	DATA('a', ACS_CKBOARD),	/* checker board (stipple) */
+	DATA('f', ACS_DEGREE),	/* degree symbol */
+	DATA('g', ACS_PLMINUS),	/* plus/minus */
+	DATA('~', ACS_BULLET),	/* bullet */
+	DATA(',', ACS_LARROW),	/* arrow pointing left */
+	DATA('+', ACS_RARROW),	/* arrow pointing right */
+	DATA('.', ACS_DARROW),	/* arrow pointing down */
+	DATA('-', ACS_UARROW),	/* arrow pointing up */
+	DATA('h', ACS_BOARD),	/* board of squares */
+	DATA('i', ACS_LANTERN),	/* lantern symbol */
+	DATA('0', ACS_BLOCK),	/* solid square block */
+	DATA('p', ACS_S3),	/* scan line 3 */
+	DATA('r', ACS_S7),	/* scan line 7 */
+	DATA('y', ACS_LEQUAL),	/* less/equal */
+	DATA('z', ACS_GEQUAL),	/* greater/equal */
+	DATA('{', ACS_PI),	/* Pi */
+	DATA('|', ACS_NEQUAL),	/* not equal */
+	DATA('}', ACS_STERLING),	/* UK pound sign */
     };
+#undef DATA
 
     const char *result = 0;
 
-    if ((attr & A_ALTCHARSET) && (acs_chars != 0)) {
+#if NCURSES_SP_FUNCS
+    (void) sp;
+#endif
+    if (SP_PARM != 0 && (attr & A_ALTCHARSET) && (acs_chars != 0)) {
 	char *cp;
 	char *found = 0;
-	const ALT_NAMES *sp;
+	size_t n;
 
 	for (cp = acs_chars; cp[0] && cp[1]; cp += 2) {
-	    if (ChCharOf(cp[1]) == ChCharOf(ch)) {
+	    if (ChCharOf(UChar(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;
+	    ch = ChCharOf(UChar(*found));
+	    for (n = 0; n < SIZEOF(names); ++n) {
+		if (names[n].val == ch) {
+		    result = names[n].name;
 		    break;
 		}
+	    }
 	}
     }
     return result;
@@ -253,14 +280,16 @@
 _tracechtype2(int bufnum, chtype ch)
 {
     const char *found;
-    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+    char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
 
     if (result != 0) {
-	strcpy(result, l_brace);
+	_nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
 	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)));
+	    (void) _nc_trace_bufcat(bufnum,
+				    _nc_tracechar(CURRENT_SCREEN,
+						  (int) ChCharOf(ch)));
 
 	if (ChAttrOf(ch) != A_NORMAL) {
 	    (void) _nc_trace_bufcat(bufnum, " | ");
@@ -291,12 +320,12 @@
 NCURSES_EXPORT(char *)
 _tracecchar_t2(int bufnum, const cchar_t *ch)
 {
-    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+    char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
     attr_t attr;
     const char *found;
 
     if (result != 0) {
-	strcpy(result, l_brace);
+	_nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
 	if (ch != 0) {
 	    attr = AttrOfD(ch);
 	    if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) {
@@ -313,14 +342,17 @@
 		(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')
+		    if (PUTC_ch == L'\0') {
+			if (PUTC_i == 0)
+			    (void) _nc_trace_bufcat(bufnum, "\\000");
 			break;
-		    PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st);
+		    }
+		    PUTC_n = (int) 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,
+						    _nc_tracechar(CURRENT_SCREEN,
 								  UChar(ch->chars[PUTC_i])));
 			}
 			break;
@@ -329,7 +361,7 @@
 			if (n)
 			    (void) _nc_trace_bufcat(bufnum, ", ");
 			(void) _nc_trace_bufcat(bufnum,
-						_nc_tracechar(SP,
+						_nc_tracechar(CURRENT_SCREEN,
 							      UChar(PUTC_buf[n])));
 		    }
 		}
diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c
index cc441b3..f880b67 100644
--- a/ncurses/trace/lib_tracebits.c
+++ b/ncurses/trace/lib_tracebits.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2015 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            *
@@ -33,13 +33,8 @@
  ****************************************************************************/
 
 #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
+MODULE_ID("$Id: lib_tracebits.c,v 1.26 2015/04/19 14:58:39 tom Exp $")
 
 #if HAVE_SYS_TERMIO_H
 #include <sys/termio.h>		/* needed for ISC */
@@ -78,25 +73,27 @@
 
 typedef struct {
     unsigned int val;
-    const char *name;
+    const char name[8];
 } BITNAMES;
 
+#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
+
 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++)
+    _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0));
+    _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0));
+    for (sp = table; sp->name[0]; sp++)
 	if (sp->val != 0
 	    && (val & sp->val) == sp->val) {
-	    (void) strcat(buf, sp->name);
-	    (void) strcat(buf, ", ");
+	    _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0));
+	    _nc_STRCAT(buf, ", ", TRACE_BUF_SIZE(0));
 	}
     if (buf[strlen(buf) - 2] == ',')
 	buf[strlen(buf) - 2] = '\0';
-    (void) strcat(buf, "} ");
+    _nc_STRCAT(buf, "} ", TRACE_BUF_SIZE(0));
 }
 
 NCURSES_EXPORT(char *)
@@ -106,56 +103,59 @@
     char *buf;
 
 #ifdef TERMIOS
+#define DATA(name)        { name, { #name } }
+#define DATA2(name,name2) { name, { #name2 } }
+#define DATAX()           { 0,    { "" } }
     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}
+	DATA(BRKINT),
+	DATA(IGNBRK),
+	DATA(IGNPAR),
+	DATA(PARMRK),
+	DATA(INPCK),
+	DATA(ISTRIP),
+	DATA(INLCR),
+	DATA(IGNCR),
+	DATA(ICRNL),
+	DATA(IXON),
+	DATA(IXOFF),
+	DATAX()
 #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}
+	DATA(OPOST),
+	DATA2(OFLAGS_TABS, XTABS),
+	DATA(ONLCR),
+	DATA(OCRNL),
+	DATA(ONOCR),
+	DATA(ONLRET),
+	DATAX()
 #define ALLOUT	(OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
     }, cflags[] =
     {
-	{CLOCAL, "CLOCAL"},
-	{CREAD, "CREAD"},
-	{CSTOPB, "CSTOPB"},
+	DATA(CLOCAL),
+	DATA(CREAD),
+	DATA(CSTOPB),
 #if !defined(CS5) || !defined(CS8)
-	{CSIZE, "CSIZE"},
+	DATA(CSIZE),
 #endif
-	{HUPCL, "HUPCL"},
-	{PARENB, "PARENB"},
-	{PARODD | PARENB, "PARODD"},	/* concession to readability */
-	{0, NULL}
+	DATA(HUPCL),
+	DATA(PARENB),
+	DATA2(PARODD | PARENB, PARODD),
+	DATAX()
 #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}
+	DATA(ECHO),
+	DATA2(ECHOE | ECHO, ECHOE),
+	DATA2(ECHOK | ECHO, ECHOK),
+	DATA(ECHONL),
+	DATA(ICANON),
+	DATA(ISIG),
+	DATA(NOFLSH),
+	DATA(TOSTOP),
+	DATA(IEXTEN),
+	DATAX()
 #define ALLLOCAL	(ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
     };
 
@@ -178,11 +178,11 @@
 
 #if defined(CS5) && defined(CS8)
 	{
-	    static struct {
+	    static const struct {
 		int value;
-		const char *name;
+		const char name[5];
 	    } csizes[] = {
-#define CS_DATA(name) { name, #name " " }
+#define CS_DATA(name) { name, { #name " " } }
 		CS_DATA(CS5),
 #ifdef CS6
 		    CS_DATA(CS6),
@@ -193,7 +193,7 @@
 		    CS_DATA(CS8),
 	    };
 	    const char *result = "CSIZE? ";
-	    int value = (tty->c_cflag & CSIZE);
+	    int value = (int) (tty->c_cflag & CSIZE);
 	    unsigned n;
 
 	    if (value != 0) {
@@ -204,7 +204,7 @@
 		    }
 		}
 	    }
-	    strcat(buf, result);
+	    _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0));
 	}
 #endif
 
@@ -231,17 +231,17 @@
 
     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}
+	DATA(CBREAK),
+	DATA(CRMOD),
+	DATA(ECHO),
+	DATA(EVENP),
+	DATA(LCASE),
+	DATA(LLITOUT),
+	DATA(ODDP),
+	DATA(RAW),
+	DATA(TANDEM),
+	DATA(XTABS),
+	DATAX()
 #define ALLCTRL	(CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
     };
 
@@ -262,5 +262,5 @@
     return _nc_trace_ttymode(&(cur_term->Nttyb));
 }
 #else
-EMPTY_MODULE(_nc_tracebits)
+EMPTY_MODULE(_nc_empty_lib_tracebits)
 #endif /* TRACE */
diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c
index 79cf03b..8977f75 100644
--- a/ncurses/trace/lib_tracechr.c
+++ b/ncurses/trace/lib_tracechr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,10 +39,12 @@
 
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_tracechr.c,v 1.19 2008/08/03 15:39:29 tom Exp $")
+MODULE_ID("$Id: lib_tracechr.c,v 1.22 2012/02/22 22:40:24 tom Exp $")
 
 #ifdef TRACE
 
+#define MyBufSize sizeof(_nc_globals.tracechr_buf)
+
 NCURSES_EXPORT(char *)
 _nc_tracechar(SCREEN *sp, int ch)
 {
@@ -52,22 +54,25 @@
 		      : _nc_globals.tracechr_buf);
 
     if (ch > KEY_MIN || ch < 0) {
-	name = _nc_keyname(sp, ch);
+	name = safe_keyname(SP_PARM, ch);
 	if (name == 0 || *name == '\0')
 	    name = "NULL";
-	(void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+	_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+		    "'%.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);
+	_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+		    "%#03o", ch);
     } else {
-	name = _nc_unctrl(sp, (chtype) ch);
+	name = safe_unctrl(SP_PARM, (chtype) ch);
 	if (name == 0 || *name == 0)
 	    name = "null";	/* shouldn't happen */
-	(void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+	_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+		    "'%.30s' = %#03o", name, ch);
     }
     return (MyBuffer);
 }
@@ -75,7 +80,7 @@
 NCURSES_EXPORT(char *)
 _tracechar(int ch)
 {
-    return _nc_tracechar(SP, ch);
+    return _nc_tracechar(CURRENT_SCREEN, ch);
 }
 #else
 EMPTY_MODULE(_nc_lib_tracechr)
diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
index 58732a0..0fda15b 100644
--- a/ncurses/trace/lib_tracedmp.c
+++ b/ncurses/trace/lib_tracedmp.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_tracedmp.c,v 1.31 2008/08/16 19:30:56 tom Exp $")
+MODULE_ID("$Id: lib_tracedmp.c,v 1.34 2012/10/27 20:54:42 tom Exp $")
 
 #ifdef TRACE
 
@@ -68,8 +68,10 @@
     if (width < win->_maxx)
 	++width;
     if (++width + 1 > (int) my_length) {
-	my_length = 2 * (width + 1);
+	my_length = (unsigned) (2 * (width + 1));
 	my_buffer = typeRealloc(char, my_length, my_buffer);
+	if (my_buffer == 0)
+	    return;
     }
 
     for (n = 0; n <= win->_maxy; ++n) {
@@ -82,7 +84,7 @@
 	 * we map those to '.' and '?' respectively.
 	 */
 	for (j = 0; j < width; ++j) {
-	    chtype test = CharOf(win->_line[n].text[j]);
+	    chtype test = (chtype) CharOf(win->_line[n].text[j]);
 	    ep[j] = (char) ((UChar(test) == test
 #if USE_WIDEC_SUPPORT
 			     && (win->_line[n].text[j].chars[1] == 0)
@@ -153,7 +155,7 @@
 
 	for (i = 0; i < 4; ++i) {
 	    const char *hex = " 123456789ABCDEF";
-	    attr_t mask = (0xf << ((i + 4) * 4));
+	    attr_t mask = (attr_t) (0xf << ((i + 4) * 4));
 
 	    haveattrs = FALSE;
 	    for (j = 0; j < width; ++j)
diff --git a/ncurses/trace/lib_tracemse.c b/ncurses/trace/lib_tracemse.c
index 74cc177..c62b71a 100644
--- a/ncurses/trace/lib_tracemse.c
+++ b/ncurses/trace/lib_tracemse.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -38,23 +38,22 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_tracemse.c,v 1.15 2008/08/03 15:39:29 tom Exp $")
+MODULE_ID("$Id: lib_tracemse.c,v 1.22 2014/10/10 09:06:26 tom Exp $")
 
 #ifdef TRACE
 
 #define my_buffer sp->tracemse_buf
 
 NCURSES_EXPORT(char *)
-_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
+_nc_trace_mmask_t(SCREEN *sp, mmask_t code)
 {
-    (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), ", ")
+#define SHOW(m, s) \
+    if ((code & m) == m) { \
+	size_t n = strlen(my_buffer); \
+	if (n && (my_buffer[n-1] != '{')) \
+	_nc_STRCAT(my_buffer, ", ", sizeof(my_buffer)); \
+	_nc_STRCAT(my_buffer, s, sizeof(my_buffer)); \
+    }
 
     SHOW(BUTTON1_RELEASED, "release-1");
     SHOW(BUTTON1_PRESSED, "press-1");
@@ -110,14 +109,47 @@
 
     if (my_buffer[strlen(my_buffer) - 1] == ' ')
 	my_buffer[strlen(my_buffer) - 2] = '\0';
-    (void) strcat(my_buffer, "}");
+
     return (my_buffer);
 }
 
 NCURSES_EXPORT(char *)
+_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
+{
+    char *result = 0;
+
+    if (sp != 0) {
+	_nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
+		    TRACEMSE_FMT,
+		    ep->id,
+		    ep->x,
+		    ep->y,
+		    ep->z,
+		    (unsigned long) ep->bstate);
+
+	(void) _nc_trace_mmask_t(sp, ep->bstate);
+	_nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
+	result = (my_buffer);
+    }
+    return result;
+}
+
+NCURSES_EXPORT(mmask_t)
+_nc_retrace_mmask_t(SCREEN *sp, mmask_t code)
+{
+    if (sp != 0) {
+	*my_buffer = '\0';
+	T((T_RETURN("{%s}"), _nc_trace_mmask_t(sp, code)));
+    } else {
+	T((T_RETURN("{?}")));
+    }
+    return code;
+}
+
+NCURSES_EXPORT(char *)
 _tracemouse(MEVENT const *ep)
 {
-    return _nc_tracemouse(SP, ep);
+    return _nc_tracemouse(CURRENT_SCREEN, ep);
 }
 
 #else /* !TRACE */
diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c
index 6345acc..84a7a0c 100644
--- a/ncurses/trace/trace_buf.c
+++ b/ncurses/trace/trace_buf.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,7 +35,9 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: trace_buf.c,v 1.14 2008/08/03 15:13:56 tom Exp $")
+MODULE_ID("$Id: trace_buf.c,v 1.20 2012/02/22 22:34:31 tom Exp $")
+
+#ifdef TRACE
 
 #define MyList _nc_globals.tracebuf_ptr
 #define MySize _nc_globals.tracebuf_used
@@ -47,7 +49,7 @@
 
     if (bufnum >= 0) {
 	if ((size_t) (bufnum + 1) > MySize) {
-	    size_t need = (bufnum + 1) * 2;
+	    size_t need = (size_t) (bufnum + 1) * 2;
 	    if ((MyList = typeRealloc(TRACEBUF, need, MyList)) != 0) {
 		while (need > MySize)
 		    MyList[MySize++].text = 0;
@@ -101,14 +103,18 @@
 NCURSES_EXPORT(char *)
 _nc_trace_bufcat(int bufnum, const char *value)
 {
-    char *buffer = _nc_trace_alloc(bufnum, 0);
+    char *buffer = _nc_trace_alloc(bufnum, (size_t) 0);
     if (buffer != 0) {
 	size_t have = strlen(buffer);
+	size_t need = strlen(value) + have;
 
-	buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value));
+	buffer = _nc_trace_alloc(bufnum, 1 + need);
 	if (buffer != 0)
-	    (void) strcpy(buffer + have, value);
+	    _nc_STRCPY(buffer + have, value, need);
 
     }
     return buffer;
 }
+#else
+EMPTY_MODULE(_nc_empty_trace_buf)
+#endif /* TRACE */
diff --git a/ncurses/trace/trace_tries.c b/ncurses/trace/trace_tries.c
index f813aba..50ba016 100644
--- a/ncurses/trace/trace_tries.c
+++ b/ncurses/trace/trace_tries.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1999-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey <dickey@clark.net> 1999                        *
+ *  Author: Thomas E. Dickey 1999                                           *
  ****************************************************************************/
 /*
  *	trace_tries.c - Tracing/Debugging buffers (keycode tries-trees)
@@ -35,7 +35,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: trace_tries.c,v 1.13 2008/08/03 15:43:30 tom Exp $")
+MODULE_ID("$Id: trace_tries.c,v 1.17 2012/10/27 20:50:50 tom Exp $")
 
 #ifdef TRACE
 #define my_buffer _nc_globals.tracetry_buf
@@ -46,33 +46,36 @@
 {
     if (level > my_length) {
 	my_length = (level + 1) * 4;
-	my_buffer = (unsigned char *) realloc(my_buffer, my_length);
+	my_buffer = (unsigned char *) _nc_doalloc(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 (my_buffer != 0) {
+	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;
 	}
-	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);
+    if ((my_buffer = typeMalloc(unsigned char, my_length = 80)) != 0) {
+	_tracef("BEGIN tries %p", (void *) tree);
+	recur_tries(tree, 0);
+	_tracef(". . . tries %p", (void *) tree);
+	free(my_buffer);
+    }
 }
 
 #else
-EMPTY_MODULE(_nc_trace_tries)
+EMPTY_MODULE(_nc_empty_trace_tries)
 #endif
diff --git a/ncurses/trace/trace_xnames.c b/ncurses/trace/trace_xnames.c
index 9b0b592..38a4873 100644
--- a/ncurses/trace/trace_xnames.c
+++ b/ncurses/trace/trace_xnames.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1999-2000,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -34,12 +34,11 @@
  */
 
 #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 $")
+MODULE_ID("$Id: trace_xnames.c,v 1.6 2010/01/23 17:59:27 tom Exp $")
 
 NCURSES_EXPORT(void)
-_nc_trace_xnames(TERMTYPE * tp GCC_UNUSED)
+_nc_trace_xnames(TERMTYPE *tp GCC_UNUSED)
 {
 #ifdef TRACE
 #if NCURSES_XNAMES
diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c
index f4ee467..66252d8 100644
--- a/ncurses/trace/varargs.c
+++ b/ncurses/trace/varargs.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2001-2008,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -34,7 +34,7 @@
 
 #include <ctype.h>
 
-MODULE_ID("$Id: varargs.c,v 1.7 2008/08/03 15:42:49 tom Exp $")
+MODULE_ID("$Id: varargs.c,v 1.11 2012/10/27 21:03:28 tom Exp $")
 
 #ifdef TRACE
 
@@ -44,7 +44,7 @@
     atUnknown = 0, atInteger, atFloat, atPoint, atString
 } ARGTYPE;
 
-#define VA_INT(type) ival = va_arg(ap, type)
+#define VA_INT(type) ival = (int) 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)
@@ -149,25 +149,32 @@
 			param = buffer;
 			switch (used) {
 			case atInteger:
-			    sprintf(buffer, "%d", ival);
+			    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+					"%d", ival);
 			    break;
 			case atFloat:
-			    sprintf(buffer, "%f", fval);
+			    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+					"%f", fval);
 			    break;
 			case atPoint:
-			    sprintf(buffer, "%p", pval);
+			    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+					"%p", pval);
 			    break;
 			case atString:
 			    param = _nc_visbuf2(1, sval);
 			    break;
 			case atUnknown:
 			default:
-			    strcpy(buffer, "?");
+			    _nc_STRCPY(buffer, "?", sizeof(buffer));
 			    break;
 			}
 			MyLength += strlen(param) + 2;
 			MyBuffer = typeRealloc(char, MyLength, MyBuffer);
-			sprintf(MyBuffer + strlen(MyBuffer), ", %s", param);
+			if (MyBuffer != 0) {
+			    _nc_SPRINTF(MyBuffer + strlen(MyBuffer),
+					_nc_SLIMIT(MyLength - strlen(MyBuffer))
+					", %s", param);
+			}
 		    }
 		}
 		used = atUnknown;
@@ -177,7 +184,7 @@
 	}
     }
 
-    return (MyBuffer);
+    return (MyBuffer ? MyBuffer : dummy);
 }
 #else
 EMPTY_MODULE(_nc_varargs)
diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c
index bf9fb14..fec0643 100644
--- a/ncurses/trace/visbuf.c
+++ b/ncurses/trace/visbuf.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2001-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -42,10 +42,12 @@
 #include <tic.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: visbuf.c,v 1.32 2008/08/04 23:07:39 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.44 2014/09/25 08:51:13 tom Exp $")
+
+#define NUM_VISBUFS 4
 
 #define NormalLen(len) (size_t) (((size_t)(len) + 1) * 4)
-#define WideLen(len)   (size_t) (((size_t)(len) + 1) * 4 * MB_CUR_MAX)
+#define WideLen(len)   (size_t) (((size_t)(len) + 1) * 4 * (size_t) MB_CUR_MAX)
 
 #ifdef TRACE
 static const char d_quote[] = StringOf(D_QUOTE);
@@ -53,13 +55,21 @@
 static const char r_brace[] = StringOf(R_BRACE);
 #endif
 
+#if USE_STRING_HACKS && HAVE_SNPRINTF
+#define VisChar(tp, chr, limit) _nc_vischar(tp, chr, limit)
+#define LIMIT_ARG ,size_t limit
+#else
+#define VisChar(tp, chr, limit) _nc_vischar(tp, chr)
+#define LIMIT_ARG		/* nothing */
+#endif
+
 static char *
-_nc_vischar(char *tp, unsigned c)
+_nc_vischar(char *tp, unsigned c LIMIT_ARG)
 {
     if (c == '"' || c == '\\') {
 	*tp++ = '\\';
 	*tp++ = (char) c;
-    } else if (is7bits(c) && (isgraph(c) || c == ' ')) {
+    } else if (is7bits((int) c) && (isgraph((int) c) || c == ' ')) {
 	*tp++ = (char) c;
     } else if (c == '\n') {
 	*tp++ = '\\';
@@ -82,7 +92,8 @@
 	*tp++ = '^';
 	*tp++ = (char) ('@' + c);
     } else {
-	sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c));
+	_nc_SPRINTF(tp, _nc_SLIMIT(limit)
+		    "\\%03lo", (unsigned long) ChCharOf(c));
 	tp += strlen(tp);
     }
     *tp = 0;
@@ -92,9 +103,10 @@
 static const char *
 _nc_visbuf2n(int bufnum, const char *buf, int len)
 {
-    const char *vbuf;
+    const char *vbuf = 0;
     char *tp;
     int c;
+    int count;
 
     if (buf == 0)
 	return ("(null)");
@@ -104,22 +116,30 @@
     if (len < 0)
 	len = (int) strlen(buf);
 
+    count = len;
 #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];
+	static char *mybuf[NUM_VISBUFS];
+	if (bufnum < 0) {
+	    for (c = 0; c < NUM_VISBUFS; ++c) {
+		FreeAndNull(mybuf[c]);
+	    }
+	    tp = 0;
+	} else {
+	    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));
+	while ((--count >= 0) && (c = *buf++) != '\0') {
+	    tp = VisChar(tp, UChar(c), NormalLen(len));
 	}
 	*tp++ = D_QUOTE;
-	*tp++ = '\0';
+	*tp = '\0';
     } else {
 	vbuf = ("(_nc_visbuf2n failed)");
     }
@@ -166,6 +186,7 @@
     const char *vbuf;
     char *tp;
     wchar_t c;
+    int count;
 
     if (buf == 0)
 	return ("(null)");
@@ -173,30 +194,32 @@
     if (len < 0)
 	len = (int) wcslen(buf);
 
+    count = len;
 #ifdef TRACE
     vbuf = tp = _nc_trace_buf(bufnum, WideLen(len));
 #else
     {
-	static char *mybuf[2];
+	static char *mybuf[NUM_VISBUFS];
 	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') {
+	while ((--count >= 0) && (c = *buf++) != '\0') {
 	    char temp[CCHARW_MAX + 80];
 	    int j = wctomb(temp, c), k;
 	    if (j <= 0) {
-		sprintf(temp, "\\u%08X", (unsigned) c);
+		_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+			    "\\u%08X", (unsigned) c);
 		j = (int) strlen(temp);
 	    }
 	    for (k = 0; k < j; ++k) {
-		tp = _nc_vischar(tp, UChar(temp[k]));
+		tp = VisChar(tp, UChar(temp[k]), WideLen(len));
 	    }
 	}
 	*tp++ = D_QUOTE;
-	*tp++ = '\0';
+	*tp = '\0';
     } else {
 	vbuf = ("(_nc_viswbuf2n failed)");
     }
@@ -229,7 +252,9 @@
     static unsigned mylen;
     unsigned n;
 
-    for (n = 0; buf[n] != 0; ++n) ;
+    for (n = 0; buf[n] != 0; ++n) {
+	;			/* empty */
+    }
     if (mylen < ++n) {
 	mylen = n + 80;
 	if (mybuf != 0)
@@ -237,8 +262,12 @@
 	else
 	    mybuf = typeMalloc(wchar_t, mylen);
     }
-    for (n = 0; buf[n] != 0; ++n)
-	mybuf[n] = (wchar_t) buf[n];
+    if (mybuf != 0) {
+	for (n = 0; buf[n] != 0; ++n) {
+	    mybuf[n] = (wchar_t) buf[n];
+	}
+	mybuf[n] = L'\0';
+    }
 
     return _nc_viswbuf2(0, mybuf);
 }
@@ -248,7 +277,7 @@
 NCURSES_EXPORT(const char *)
 _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
 {
-    char *result = _nc_trace_buf(bufnum, BUFSIZ);
+    char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
     int first;
     const char *found;
 
@@ -274,12 +303,12 @@
 		}
 	    }
 
-	    result = _nc_trace_bufcat(bufnum, l_brace);
-	    result = _nc_trace_bufcat(bufnum, d_quote);
+	    (void) _nc_trace_bufcat(bufnum, l_brace);
+	    (void) _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);
+		    (void) _nc_trace_bufcat(bufnum, found);
 		    attr &= ~A_ALTCHARSET;
 		} else
 #if USE_WIDEC_SUPPORT
@@ -291,30 +320,34 @@
 			int k;
 
 			PUTC_ch = buf[j].chars[PUTC_i];
-			if (PUTC_ch == L'\0')
+			if (PUTC_ch == L'\0') {
+			    if (PUTC_i == 0)
+				(void) _nc_trace_bufcat(bufnum, "\\000");
 			    break;
-			PUTC_n = (int) wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st);
+			}
+			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);
+			    VisChar(temp, UChar(PUTC_buf[k]), sizeof(temp));
+			    (void) _nc_trace_bufcat(bufnum, temp);
 			}
 		    }
 		}
 #else
 		{
 		    char temp[80];
-		    _nc_vischar(temp, UChar(buf[j]));
-		    result = _nc_trace_bufcat(bufnum, temp);
+		    VisChar(temp, UChar(buf[j]), sizeof(temp));
+		    (void) _nc_trace_bufcat(bufnum, temp);
 		}
 #endif /* USE_WIDEC_SUPPORT */
 	    }
-	    result = _nc_trace_bufcat(bufnum, d_quote);
+	    (void) _nc_trace_bufcat(bufnum, d_quote);
 	    if (attr != A_NORMAL) {
-		result = _nc_trace_bufcat(bufnum, " | ");
-		result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
+		(void) _nc_trace_bufcat(bufnum, " | ");
+		(void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
 	    }
 	    result = _nc_trace_bufcat(bufnum, r_brace);
 	    first = last + 1;
diff --git a/ncurses/tty/MKexpanded.sh b/ncurses/tty/MKexpanded.sh
index bf9acf2..7a5f599 100755
--- a/ncurses/tty/MKexpanded.sh
+++ b/ncurses/tty/MKexpanded.sh
@@ -1,6 +1,6 @@
 #! /bin/sh
 ##############################################################################
-# Copyright (c) 1998-2000,2005 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2009,2010 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"), #
@@ -27,9 +27,9 @@
 # authorization.                                                             #
 ##############################################################################
 #
-# Author: Thomas E. Dickey <dickey@clark.net> 1997
+# Author: Thomas E. Dickey, 1997-on
 #
-# $Id: MKexpanded.sh,v 1.11 2005/01/02 01:06:40 tom Exp $
+# $Id: MKexpanded.sh,v 1.17 2010/01/23 17:57:43 tom Exp $
 #
 # Script to generate 'expanded.c', a dummy source that contains functions
 # corresponding to complex macros used in this library.  By making functions,
@@ -52,8 +52,13 @@
 
 cat <<EOF
 /* generated by MKexpanded.sh */
+#define NEED_NCURSES_CH_T 1
 #include <curses.priv.h>
-#include <term.h>
+
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
 #if NCURSES_EXPANDED
 EOF
 
@@ -68,29 +73,59 @@
 #undef FALSE
 /* this is a marker */
 IGNORE
-NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *S, attr_t at)
+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) 
+
+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)
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_DelCharCost) (NCURSES_SP_DCLx int count)
 {
-	return DelCharCost(count);
+	return DelCharCost(SP_PARM, count);
 }
-NCURSES_EXPORT(int) _nc_InsCharCost (int count)
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_InsCharCost) (NCURSES_SP_DCLx int count)
 {
-	return InsCharCost(count);
+	return InsCharCost(SP_PARM, count);
 }
-NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T c)
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_UpdateAttrs) (NCURSES_SP_DCLx CARG_CH_T c)
 {
-	UpdateAttrs(c);
+	UpdateAttrs(SP_PARM, CHDEREF(c));
 }
+
+@if_NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_DelCharCost (int count)
+{
+	return NCURSES_SP_NAME(_nc_DelCharCost) (CURRENT_SCREEN, count);
+}
+
+NCURSES_EXPORT(int)
+_nc_InsCharCost (int count)
+{
+	return NCURSES_SP_NAME(_nc_InsCharCost)(CURRENT_SCREEN, count);
+}
+
+NCURSES_EXPORT(void)
+_nc_UpdateAttrs (CARG_CH_T c)
+{
+	NCURSES_SP_NAME(_nc_UpdateAttrs)(CURRENT_SCREEN,c);
+}
+@endif
 EOF
 
-$preprocessor $TMP 2>/dev/null | sed -e '1,/^IGNORE$/d'
+$preprocessor $TMP 2>/dev/null | \
+	sed -e '1,/^IGNORE$/d' -e 's/^@/#/' -e 's/^#if_/#if /'
 
 cat <<EOF
 #else /* ! NCURSES_EXPANDED */
diff --git a/ncurses/tty/hardscroll.c b/ncurses/tty/hardscroll.c
index 2c40997..d6f28d6 100644
--- a/ncurses/tty/hardscroll.c
+++ b/ncurses/tty/hardscroll.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2015 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            *
@@ -147,90 +147,104 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: hardscroll.c,v 1.42 2008/08/03 23:49:30 tom Exp $")
+MODULE_ID("$Id: hardscroll.c,v 1.52 2015/07/25 20:13:07 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 screen_lines(sp) MAXLINES
+NCURSES_EXPORT_VAR (int)
+  oldnums[MAXLINES];
+# define OLDNUM(sp,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;
+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 */
+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 oldnums(sp)   (sp)->_oldnum_list
+#  define OLDNUM(sp,n)	oldnums(sp)[n]
+# else /* !USE_HASHMAP */
+#  define OLDNUM(sp,n)	NewScreen(sp)->_line[n].oldindex
+# endif	/* !USE_HASHMAP */
 
-#define OLDNUM_SIZE     SP->_oldnum_size
+#define OLDNUM_SIZE(sp) (sp)->_oldnum_size
 
 #endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */
 
 NCURSES_EXPORT(void)
-_nc_scroll_optimize(void)
+NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_DCL0)
 /* scroll optimization to transform curscr to newscr */
 {
     int i;
     int start, end, shift;
 
-    TR(TRACE_ICALLS, (T_CALLED("_nc_scroll_optimize")));
+    TR(TRACE_ICALLS, (T_CALLED("_nc_scroll_optimize(%p)"), (void *) SP_PARM));
 
 #if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
 #if USE_HASHMAP
     /* get enough storage */
-    if (OLDNUM_SIZE < screen_lines) {
-	int *new_oldnums = typeRealloc(int, screen_lines, oldnums);
+    assert(OLDNUM_SIZE(SP_PARM) >= 0);
+    assert(screen_lines(SP_PARM) > 0);
+    if ((oldnums(SP_PARM) == 0)
+	|| (OLDNUM_SIZE(SP_PARM) < screen_lines(SP_PARM))) {
+	int need_lines = ((OLDNUM_SIZE(SP_PARM) < screen_lines(SP_PARM))
+			  ? screen_lines(SP_PARM)
+			  : OLDNUM_SIZE(SP_PARM));
+	int *new_oldnums = typeRealloc(int,
+				       (size_t) need_lines,
+				       oldnums(SP_PARM));
 	if (!new_oldnums)
 	    return;
-	oldnums = new_oldnums;
-	OLDNUM_SIZE = screen_lines;
+	oldnums(SP_PARM) = new_oldnums;
+	OLDNUM_SIZE(SP_PARM) = need_lines;
     }
     /* calculate the indices */
-    _nc_hash_map();
+    NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_ARG);
 #endif
 #endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
 
 #ifdef TRACE
     if (USE_TRACEF(TRACE_UPDATE | TRACE_MOVE)) {
-	_nc_linedump();
+	NCURSES_SP_NAME(_nc_linedump) (NCURSES_SP_ARG);
 	_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))
+    for (i = 0; i < screen_lines(SP_PARM);) {
+	while (i < screen_lines(SP_PARM)
+	       && (OLDNUM(SP_PARM, i) == _NEWINDEX || OLDNUM(SP_PARM, i) <= i))
 	    i++;
-	if (i >= screen_lines)
+	if (i >= screen_lines(SP_PARM))
 	    break;
 
-	shift = OLDNUM(i) - i;	/* shift > 0 */
+	shift = OLDNUM(SP_PARM, i) - i;		/* shift > 0 */
 	start = i;
 
 	i++;
-	while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i
-	       == shift)
+	while (i < screen_lines(SP_PARM)
+	       && OLDNUM(SP_PARM, i) != _NEWINDEX
+	       && OLDNUM(SP_PARM, 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) {
+	if (NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_ARGx
+					  shift,
+					  start,
+					  end,
+					  screen_lines(SP_PARM) - 1) == ERR) {
 	    TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll"));
 	    continue;
 	}
@@ -238,23 +252,33 @@
     }
 
     /* pass 2 - from bottom to top scrolling down */
-    for (i = screen_lines - 1; i >= 0;) {
-	while (i >= 0 && (OLDNUM(i) == _NEWINDEX || OLDNUM(i) >= i))
+    for (i = screen_lines(SP_PARM) - 1; i >= 0;) {
+	while (i >= 0
+	       && (OLDNUM(SP_PARM, i) == _NEWINDEX
+		   || OLDNUM(SP_PARM, i) >= i)) {
 	    i--;
+	}
 	if (i < 0)
 	    break;
 
-	shift = OLDNUM(i) - i;	/* shift < 0 */
+	shift = OLDNUM(SP_PARM, i) - i;		/* shift < 0 */
 	end = i;
 
 	i--;
-	while (i >= 0 && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift)
+	while (i >= 0
+	       && OLDNUM(SP_PARM, i) != _NEWINDEX
+	       && OLDNUM(SP_PARM, 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) {
+	if (NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_ARGx
+					  shift,
+					  start,
+					  end,
+					  screen_lines(SP_PARM) - 1) == ERR) {
 	    TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll"));
 	    continue;
 	}
@@ -263,24 +287,44 @@
     TR(TRACE_ICALLS, (T_RETURN("")));
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_scroll_optimize(void)
+{
+    NCURSES_SP_NAME(_nc_scroll_optimize) (CURRENT_SCREEN);
+}
+#endif
+
 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
 NCURSES_EXPORT(void)
-_nc_linedump(void)
+NCURSES_SP_NAME(_nc_linedump) (NCURSES_SP_DCL0)
 /* dump the state of the real and virtual oldnum fields */
 {
     int n;
     char *buf = 0;
-    size_t want = (screen_lines + 1) * 4;
+    size_t want = ((size_t) screen_lines(SP_PARM) + 1) * 4;
+    (void) SP_PARM;
 
     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));
+	*buf = '\0';
+	for (n = 0; n < screen_lines(SP_PARM); n++)
+	    _nc_SPRINTF(buf + strlen(buf),
+			_nc_SLIMIT(want - strlen(buf))
+			" %02d", OLDNUM(SP_PARM, n));
+	TR(TRACE_UPDATE | TRACE_MOVE, ("virt %s", buf));
 	free(buf);
     }
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_linedump(void)
+{
+    NCURSES_SP_NAME(_nc_linedump) (CURRENT_SCREEN);
+}
+#endif
+
 #endif /* defined(TRACE) || defined(SCROLLDEBUG) */
 
 #ifdef SCROLLDEBUG
@@ -296,7 +340,7 @@
     for (;;) {
 	int n;
 
-	for (n = 0; n < screen_lines; n++)
+	for (n = 0; n < screen_lines(sp); n++)
 	    oldnums[n] = _NEWINDEX;
 
 	/* grab the test vector */
diff --git a/ncurses/tty/hashmap.c b/ncurses/tty/hashmap.c
index 9b60df6..8c0fdfd 100644
--- a/ncurses/tty/hashmap.c
+++ b/ncurses/tty/hashmap.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2014,2015 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            *
@@ -68,40 +68,47 @@
 *****************************************************************************/
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: hashmap.c,v 1.65 2015/07/25 20:13:56 tom Exp $")
 
 #ifdef HASHDEBUG
 
 # define _tracef	printf
 # undef TR
+# ifdef TRACE
 # define TR(n, a)	if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); }
+# else
+# define TR(n, a)	{ _tracef a ; putchar('\n'); }
+# endif
 # undef screen_lines
-# define screen_lines MAXLINES
-# define TEXTWIDTH	1
+# define screen_lines(sp) MAXLINES
+# define TEXTWIDTH(sp)	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
+static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH(sp)];
+static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH(sp)];
+# define OLDNUM(sp,n)	oldnums[n]
+# define OLDTEXT(sp,n)	oldtext[n]
+# define NEWTEXT(sp,m)	newtext[m]
+# define PENDING(sp,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)
+# define OLDNUM(sp,n)	(sp)->_oldnum_list[n]
+# define OLDTEXT(sp,n)	CurScreen(sp)->_line[n].text
+# define NEWTEXT(sp,m)	NewScreen(sp)->_line[m].text
+# define TEXTWIDTH(sp)	(CurScreen(sp)->_maxx + 1)
+# define PENDING(sp,n)  (NewScreen(sp)->_line[n].firstchar != _NOCHANGE)
 
 #endif /* !HASHDEBUG */
 
-#define oldhash		(SP->oldhash)
-#define newhash		(SP->newhash)
-#define hashtab		(SP->hashtab)
-#define lines_alloc	(SP->hashtab_len)
+#define oldhash(sp)	((sp)->oldhash)
+#define newhash(sp)	((sp)->newhash)
+#define hashtab(sp)	((sp)->hashtab)
+#define lines_alloc(sp)	((sp)->hashtab_len)
 
 #if USE_WIDEC_SUPPORT
 #define HASH_VAL(ch) (ch.chars[0])
@@ -112,26 +119,29 @@
 static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
 
 static NCURSES_INLINE unsigned long
-hash(NCURSES_CH_T * text)
+hash(SCREEN *sp, NCURSES_CH_T * text)
 {
     int i;
     NCURSES_CH_T ch;
     unsigned long result = 0;
-    for (i = TEXTWIDTH; i > 0; i--) {
+    (void) sp;
+
+    for (i = TEXTWIDTH(sp); i > 0; i--) {
 	ch = *text++;
-	result += (result << 5) + HASH_VAL(ch);
+	result += (result << 5) + (unsigned long) HASH_VAL(ch);
     }
     return result;
 }
 
 /* approximate update cost */
 static int
-update_cost(NCURSES_CH_T * from, NCURSES_CH_T * to)
+update_cost(SCREEN *sp, NCURSES_CH_T * from, NCURSES_CH_T * to)
 {
     int cost = 0;
     int i;
+    (void) sp;
 
-    for (i = TEXTWIDTH; i > 0; i--, from++, to++)
+    for (i = TEXTWIDTH(sp); i > 0; i--, from++, to++)
 	if (!(CharEq(*from, *to)))
 	    cost++;
 
@@ -139,16 +149,17 @@
 }
 
 static int
-update_cost_from_blank(NCURSES_CH_T * to)
+update_cost_from_blank(SCREEN *sp, NCURSES_CH_T * to)
 {
     int cost = 0;
     int i;
     NCURSES_CH_T blank = blankchar;
+    (void) sp;
 
     if (back_color_erase)
 	SetPair(blank, GetPair(stdscr->_nc_bkgd));
 
-    for (i = TEXTWIDTH; i > 0; i--, to++)
+    for (i = TEXTWIDTH(sp); i > 0; i--, to++)
 	if (!(CharEq(blank, *to)))
 	    cost++;
 
@@ -160,14 +171,14 @@
  * 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)
+cost_effective(SCREEN *sp, const int from, const int to, const int blank)
 {
     int new_from;
 
     if (from == to)
 	return FALSE;
 
-    new_from = OLDNUM(from);
+    new_from = OLDNUM(sp, from);
     if (new_from == _NEWINDEX)
 	new_from = from;
 
@@ -175,16 +186,17 @@
      * 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;
+    return (((blank ? update_cost_from_blank(sp, NEWTEXT(sp, to))
+	      : update_cost(sp, OLDTEXT(sp, to), NEWTEXT(sp, to)))
+	     + update_cost(sp, OLDTEXT(sp, new_from), NEWTEXT(sp, from)))
+	    >= ((new_from == from ? update_cost_from_blank(sp, NEWTEXT(sp, from))
+		 : update_cost(sp, OLDTEXT(sp, new_from), NEWTEXT(sp, from)))
+		+ update_cost(sp, OLDTEXT(sp, from), NEWTEXT(sp, to))))
+	? TRUE : FALSE;
 }
 
 static void
-grow_hunks(void)
+grow_hunks(SCREEN *sp)
 {
     int start, end, shift;
     int back_limit, forward_limit;	/* limits for cells to fill */
@@ -200,35 +212,36 @@
     back_ref_limit = 0;
 
     i = 0;
-    while (i < screen_lines && OLDNUM(i) == _NEWINDEX)
+    while (i < screen_lines(sp) && OLDNUM(sp, i) == _NEWINDEX)
 	i++;
-    for (; i < screen_lines; i = next_hunk) {
+    for (; i < screen_lines(sp); i = next_hunk) {
 	start = i;
-	shift = OLDNUM(i) - i;
+	shift = OLDNUM(sp, i) - i;
 
 	/* get forward limit */
 	i = start + 1;
-	while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i
-	       == shift)
+	while (i < screen_lines(sp)
+	       && OLDNUM(sp, i) != _NEWINDEX
+	       && OLDNUM(sp, i) - i == shift)
 	    i++;
 	end = i;
-	while (i < screen_lines && OLDNUM(i) == _NEWINDEX)
+	while (i < screen_lines(sp) && OLDNUM(sp, i) == _NEWINDEX)
 	    i++;
 	next_hunk = i;
 	forward_limit = i;
-	if (i >= screen_lines || OLDNUM(i) >= i)
+	if (i >= screen_lines(sp) || OLDNUM(sp, i) >= i)
 	    forward_ref_limit = i;
 	else
-	    forward_ref_limit = OLDNUM(i);
+	    forward_ref_limit = OLDNUM(sp, 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;
+	    if (newhash(sp)[i] == oldhash(sp)[i + shift]
+		|| cost_effective(sp, i + shift, i, shift < 0)) {
+		OLDNUM(sp, i) = i + shift;
 		TR(TRACE_UPDATE | TRACE_MOVE,
 		   ("connected new line %d to old line %d (backward continuation)",
 		    i, i + shift));
@@ -246,9 +259,9 @@
 	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;
+	    if (newhash(sp)[i] == oldhash(sp)[i + shift]
+		|| cost_effective(sp, i + shift, i, shift > 0)) {
+		OLDNUM(sp, i) = i + shift;
 		TR(TRACE_UPDATE | TRACE_MOVE,
 		   ("connected new line %d to old line %d (forward continuation)",
 		    i, i + shift));
@@ -268,51 +281,54 @@
 }
 
 NCURSES_EXPORT(void)
-_nc_hash_map(void)
+NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_DCL0)
 {
-    HASHMAP *sp;
+    HASHMAP *hsp;
     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);
+    if (screen_lines(SP_PARM) > lines_alloc(SP_PARM)) {
+	if (hashtab(SP_PARM))
+	    free(hashtab(SP_PARM));
+	hashtab(SP_PARM) = typeMalloc(HASHMAP,
+				      ((size_t) screen_lines(SP_PARM) + 1) * 2);
+	if (!hashtab(SP_PARM)) {
+	    if (oldhash(SP_PARM)) {
+		FreeAndNull(oldhash(SP_PARM));
 	    }
-	    lines_alloc = 0;
+	    lines_alloc(SP_PARM) = 0;
 	    return;
 	}
-	lines_alloc = screen_lines;
+	lines_alloc(SP_PARM) = screen_lines(SP_PARM);
     }
 
-    if (oldhash && newhash) {
+    if (oldhash(SP_PARM) && newhash(SP_PARM)) {
 	/* re-hash only changed lines */
-	for (i = 0; i < screen_lines; i++) {
-	    if (PENDING(i))
-		newhash[i] = hash(NEWTEXT(i));
+	for (i = 0; i < screen_lines(SP_PARM); i++) {
+	    if (PENDING(SP_PARM, i))
+		newhash(SP_PARM)[i] = hash(SP_PARM, NEWTEXT(SP_PARM, 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)
+	if (oldhash(SP_PARM) == 0)
+	    oldhash(SP_PARM) = typeCalloc(unsigned long,
+					    (size_t) screen_lines(SP_PARM));
+	if (newhash(SP_PARM) == 0)
+	    newhash(SP_PARM) = typeCalloc(unsigned long,
+					    (size_t) screen_lines(SP_PARM));
+	if (!oldhash(SP_PARM) || !newhash(SP_PARM))
 	    return;		/* malloc failure */
-	for (i = 0; i < screen_lines; i++) {
-	    newhash[i] = hash(NEWTEXT(i));
-	    oldhash[i] = hash(OLDTEXT(i));
+	for (i = 0; i < screen_lines(SP_PARM); i++) {
+	    newhash(SP_PARM)[i] = hash(SP_PARM, NEWTEXT(SP_PARM, i));
+	    oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
 	}
     }
 
 #ifdef HASH_VERIFY
-    for (i = 0; i < screen_lines; i++) {
-	if (newhash[i] != hash(NEWTEXT(i)))
+    for (i = 0; i < screen_lines(SP_PARM); i++) {
+	if (newhash(SP_PARM)[i] != hash(SP_PARM, NEWTEXT(SP_PARM, i)))
 	    fprintf(stderr, "error in newhash[%d]\n", i);
-	if (oldhash[i] != hash(OLDTEXT(i)))
+	if (oldhash(SP_PARM)[i] != hash(SP_PARM, OLDTEXT(SP_PARM, i)))
 	    fprintf(stderr, "error in oldhash[%d]\n", i);
     }
 #endif
@@ -320,28 +336,30 @@
     /*
      * 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];
+    memset(hashtab(SP_PARM), '\0',
+	   sizeof(*(hashtab(SP_PARM)))
+	   * ((size_t) screen_lines(SP_PARM) + 1) * 2);
+    for (i = 0; i < screen_lines(SP_PARM); i++) {
+	unsigned long hashval = oldhash(SP_PARM)[i];
 
-	for (sp = hashtab; sp->hashval; sp++)
-	    if (sp->hashval == hashval)
+	for (hsp = hashtab(SP_PARM); hsp->hashval; hsp++)
+	    if (hsp->hashval == hashval)
 		break;
-	sp->hashval = hashval;	/* in case this is a new entry */
-	sp->oldcount++;
-	sp->oldindex = i;
+	hsp->hashval = hashval;	/* in case this is a new entry */
+	hsp->oldcount++;
+	hsp->oldindex = i;
     }
-    for (i = 0; i < screen_lines; i++) {
-	unsigned long hashval = newhash[i];
+    for (i = 0; i < screen_lines(SP_PARM); i++) {
+	unsigned long hashval = newhash(SP_PARM)[i];
 
-	for (sp = hashtab; sp->hashval; sp++)
-	    if (sp->hashval == hashval)
+	for (hsp = hashtab(SP_PARM); hsp->hashval; hsp++)
+	    if (hsp->hashval == hashval)
 		break;
-	sp->hashval = hashval;	/* in case this is a new entry */
-	sp->newcount++;
-	sp->newindex = i;
+	hsp->hashval = hashval;	/* in case this is a new entry */
+	hsp->newcount++;
+	hsp->newindex = i;
 
-	OLDNUM(i) = _NEWINDEX;	/* initialize old indices array */
+	OLDNUM(SP_PARM, i) = _NEWINDEX;		/* initialize old indices array */
     }
 
     /*
@@ -351,16 +369,16 @@
      * 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) {
+    for (hsp = hashtab(SP_PARM); hsp->hashval; hsp++)
+	if (hsp->oldcount == 1 && hsp->newcount == 1
+	    && hsp->oldindex != hsp->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;
+		hsp->newindex, hsp->oldindex));
+	    OLDNUM(SP_PARM, hsp->newindex) = hsp->oldindex;
 	}
 
-    grow_hunks();
+    grow_hunks(SP_PARM);
 
     /*
      * Eliminate bad or impossible shifts -- this includes removing
@@ -368,58 +386,83 @@
      * 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)
+    for (i = 0; i < screen_lines(SP_PARM);) {
+	while (i < screen_lines(SP_PARM) && OLDNUM(SP_PARM, i) == _NEWINDEX)
 	    i++;
-	if (i >= screen_lines)
+	if (i >= screen_lines(SP_PARM))
 	    break;
 	start = i;
-	shift = OLDNUM(i) - i;
+	shift = OLDNUM(SP_PARM, i) - i;
 	i++;
-	while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i
-	       == shift)
+	while (i < screen_lines(SP_PARM)
+	       && OLDNUM(SP_PARM, i) != _NEWINDEX
+	       && OLDNUM(SP_PARM, i) - i == shift)
 	    i++;
 	size = i - start;
 	if (size < 3 || size + min(size / 8, 2) < abs(shift)) {
 	    while (start < i) {
-		OLDNUM(start) = _NEWINDEX;
+		OLDNUM(SP_PARM, start) = _NEWINDEX;
 		start++;
 	    }
 	}
     }
 
     /* After clearing invalid hunks, try grow the rest. */
-    grow_hunks();
+    grow_hunks(SP_PARM);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_hash_map(void)
+{
+    NCURSES_SP_NAME(_nc_hash_map) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_make_oldhash) (NCURSES_SP_DCLx int i)
+{
+    if (oldhash(SP_PARM))
+	oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(void)
 _nc_make_oldhash(int i)
 {
-    if (oldhash)
-	oldhash[i] = hash(OLDTEXT(i));
+    NCURSES_SP_NAME(_nc_make_oldhash) (CURRENT_SCREEN, i);
 }
+#endif
 
 NCURSES_EXPORT(void)
-_nc_scroll_oldhash(int n, int top, int bot)
+NCURSES_SP_NAME(_nc_scroll_oldhash) (NCURSES_SP_DCLx int n, int top, int bot)
 {
     size_t size;
     int i;
 
-    if (!oldhash)
+    if (!oldhash(SP_PARM))
 	return;
 
-    size = sizeof(*oldhash) * (bot - top + 1 - abs(n));
+    size = sizeof(*(oldhash(SP_PARM))) * (size_t) (bot - top + 1 - abs(n));
     if (n > 0) {
-	memmove(oldhash + top, oldhash + top + n, size);
+	memmove(oldhash(SP_PARM) + top, oldhash(SP_PARM) + top + n, size);
 	for (i = bot; i > bot - n; i--)
-	    oldhash[i] = hash(OLDTEXT(i));
+	    oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
     } else {
-	memmove(oldhash + top - n, oldhash + top, size);
+	memmove(oldhash(SP_PARM) + top - n, oldhash(SP_PARM) + top, size);
 	for (i = top; i < top - n; i++)
-	    oldhash[i] = hash(OLDTEXT(i));
+	    oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
     }
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_scroll_oldhash(int n, int top, int bot)
+{
+    NCURSES_SP_NAME(_nc_scroll_oldhash) (CURRENT_SCREEN, n, top, bot);
+}
+#endif
+
 #ifdef HASHDEBUG
 static void
 usage(void)
@@ -451,13 +494,13 @@
 	return EXIT_FAILURE;
     (void) _nc_alloc_screen();
 
-    for (n = 0; n < screen_lines; n++) {
+    for (n = 0; n < screen_lines(sp); n++) {
 	reallines[n] = n;
 	oldnums[n] = _NEWINDEX;
 	CharOf(oldtext[n][0]) = CharOf(newtext[n][0]) = '.';
     }
 
-    if (isatty(fileno(stdin)))
+    if (NC_ISATTY(fileno(stdin)))
 	usage();
 
 #ifdef TRACE
@@ -474,7 +517,7 @@
 	    break;
 
 	case 'l':		/* get initial line number vector */
-	    for (n = 0; n < screen_lines; n++) {
+	    for (n = 0; n < screen_lines(sp); n++) {
 		reallines[n] = n;
 		oldnums[n] = _NEWINDEX;
 	    }
@@ -487,9 +530,9 @@
 	    break;
 
 	case 'n':		/* use following letters as text of new lines */
-	    for (n = 0; n < screen_lines; n++)
+	    for (n = 0; n < screen_lines(sp); n++)
 		CharOf(newtext[n][0]) = '.';
-	    for (n = 0; n < screen_lines; n++)
+	    for (n = 0; n < screen_lines(sp); n++)
 		if (line[n + 1] == '\n')
 		    break;
 		else
@@ -497,9 +540,9 @@
 	    break;
 
 	case 'o':		/* use following letters as text of old lines */
-	    for (n = 0; n < screen_lines; n++)
+	    for (n = 0; n < screen_lines(sp); n++)
 		CharOf(oldtext[n][0]) = '.';
-	    for (n = 0; n < screen_lines; n++)
+	    for (n = 0; n < screen_lines(sp); n++)
 		if (line[n + 1] == '\n')
 		    break;
 		else
@@ -511,12 +554,12 @@
 	    _nc_linedump();
 #endif
 	    (void) fputs("Old lines: [", stdout);
-	    for (n = 0; n < screen_lines; n++)
+	    for (n = 0; n < screen_lines(sp); n++)
 		putchar(CharOf(oldtext[n][0]));
 	    putchar(']');
 	    putchar('\n');
 	    (void) fputs("New lines: [", stdout);
-	    for (n = 0; n < screen_lines; n++)
+	    for (n = 0; n < screen_lines(sp); n++)
 		putchar(CharOf(newtext[n][0]));
 	    putchar(']');
 	    putchar('\n');
diff --git a/ncurses/tty/lib_mvcur.c b/ncurses/tty/lib_mvcur.c
index 8e66fa3..0b3300b 100644
--- a/ncurses/tty/lib_mvcur.c
+++ b/ncurses/tty/lib_mvcur.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -109,8 +110,8 @@
  * 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) \
+#define NOT_LOCAL(sp, fy, fx, ty, tx)	((tx > LONG_DIST) \
+		 && (tx < screen_columns(sp) - 1 - LONG_DIST) \
 		 && (abs(ty-fy) + abs(tx-fx) > LONG_DIST))
 
 /****************************************************************************
@@ -152,13 +153,21 @@
  */
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-#define WANT_CHAR(y, x)	SP->_newscr->_line[y].text[x]	/* desired state */
-#define BAUDRATE	cur_term->_baudrate	/* bits per second */
+MODULE_ID("$Id: lib_mvcur.c,v 1.136 2015/07/25 20:14:57 tom Exp $")
+
+#define WANT_CHAR(sp, y, x) NewScreen(sp)->_line[y].text[x]	/* desired state */
+
+#if NCURSES_SP_FUNCS
+#define BAUDRATE(sp)	sp->_term->_baudrate	/* bits per second */
+#else
+#define BAUDRATE(sp)	cur_term->_baudrate	/* bits per second */
+#endif
 
 #if defined(MAIN) || defined(NCURSES_TEST)
 #include <sys/time.h>
@@ -167,9 +176,12 @@
 static float diff;
 #endif /* MAIN */
 
+#undef NCURSES_OUTC_FUNC
+#define NCURSES_OUTC_FUNC myOutCh
+
 #define OPT_SIZE 512
 
-static int normalized_cost(const char *const cap, int affcnt);
+static int normalized_cost(NCURSES_SP_DCLx const char *const cap, int affcnt);
 
 /****************************************************************************
  *
@@ -179,34 +191,34 @@
 
 #ifdef TRACE
 static int
-trace_cost_of(const char *capname, const char *cap, int affcnt)
+trace_cost_of(NCURSES_SP_DCLx const char *capname, const char *cap, int affcnt)
 {
-    int result = _nc_msec_cost(cap, affcnt);
+    int result = NCURSES_SP_NAME(_nc_msec_cost) (NCURSES_SP_ARGx 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);
+#define CostOf(cap,affcnt) trace_cost_of(NCURSES_SP_ARGx #cap, cap, affcnt)
 
 static int
-trace_normalized_cost(const char *capname, const char *cap, int affcnt)
+trace_normalized_cost(NCURSES_SP_DCLx const char *capname, const char *cap, int affcnt)
 {
-    int result = normalized_cost(cap, affcnt);
+    int result = normalized_cost(NCURSES_SP_ARGx 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);
+#define NormalizedCost(cap,affcnt) trace_normalized_cost(NCURSES_SP_ARGx #cap, cap, affcnt)
 
 #else
 
-#define CostOf(cap,affcnt) _nc_msec_cost(cap,affcnt);
-#define NormalizedCost(cap,affcnt) normalized_cost(cap,affcnt);
+#define CostOf(cap,affcnt) NCURSES_SP_NAME(_nc_msec_cost)(NCURSES_SP_ARGx cap, affcnt)
+#define NormalizedCost(cap,affcnt) normalized_cost(NCURSES_SP_ARGx cap, affcnt)
 
 #endif
 
 NCURSES_EXPORT(int)
-_nc_msec_cost(const char *const cap, int affcnt)
+NCURSES_SP_NAME(_nc_msec_cost) (NCURSES_SP_DCLx const char *const cap, int affcnt)
 /* compute the cost of a given operation */
 {
     if (cap == 0)
@@ -222,53 +234,65 @@
 
 		for (cp += 2; *cp != '>'; cp++) {
 		    if (isdigit(UChar(*cp)))
-			number = number * 10 + (*cp - '0');
+			number = number * 10 + (float) (*cp - '0');
 		    else if (*cp == '*')
-			number *= affcnt;
+			number *= (float) affcnt;
 		    else if (*cp == '.' && (*++cp != '>') && isdigit(UChar(*cp)))
-			number += (*cp - '0') / 10.0;
+			number += (float) ((*cp - '0') / 10.0);
 		}
 
 #if NCURSES_NO_PADDING
-		if (!GetNoPadding(SP))
+		if (!GetNoPadding(SP_PARM))
 #endif
 		    cum_cost += number * 10;
-	    } else
-		cum_cost += SP->_char_padding;
+	    } else if (SP_PARM) {
+		cum_cost += (float) SP_PARM->_char_padding;
+	    }
 	}
 
 	return ((int) cum_cost);
     }
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_msec_cost(const char *const cap, int affcnt)
+{
+    return NCURSES_SP_NAME(_nc_msec_cost) (CURRENT_SCREEN, cap, affcnt);
+}
+#endif
+
 static int
-normalized_cost(const char *const cap, int affcnt)
+normalized_cost(NCURSES_SP_DCLx const char *const cap, int affcnt)
 /* compute the effective character-count for an operation (round up) */
 {
-    int cost = _nc_msec_cost(cap, affcnt);
+    int cost = NCURSES_SP_NAME(_nc_msec_cost) (NCURSES_SP_ARGx cap, affcnt);
     if (cost != INFINITY)
-	cost = (cost + SP->_char_padding - 1) / SP->_char_padding;
+	cost = (cost + SP_PARM->_char_padding - 1) / SP_PARM->_char_padding;
     return cost;
 }
 
 static void
-reset_scroll_region(void)
+reset_scroll_region(NCURSES_SP_DCL0)
 /* 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_PUTP2("change_scroll_region",
+		      TPARM_2(change_scroll_region,
+			      0, screen_lines(SP_PARM) - 1));
     }
 }
 
 NCURSES_EXPORT(void)
-_nc_mvcur_resume(void)
+NCURSES_SP_NAME(_nc_mvcur_resume) (NCURSES_SP_DCL0)
 /* what to do at initialization time and after each shellout */
 {
+    if (!SP_PARM || !IsTermInfo(SP_PARM))
+	return;
+
     /* initialize screen for cursor access */
     if (enter_ca_mode) {
-	TPUTS_TRACE("enter_ca_mode");
-	putp(enter_ca_mode);
+	NCURSES_PUTP2("enter_ca_mode", enter_ca_mode);
     }
 
     /*
@@ -280,53 +304,64 @@
      * 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;
+    reset_scroll_region(NCURSES_SP_ARG);
+    SP_PARM->_cursrow = SP_PARM->_curscol = -1;
 
     /* restore cursor shape */
-    if (SP->_cursor != -1) {
-	int cursor = SP->_cursor;
-	SP->_cursor = -1;
-	curs_set(cursor);
+    if (SP_PARM->_cursor != -1) {
+	int cursor = SP_PARM->_cursor;
+	SP_PARM->_cursor = -1;
+	NCURSES_SP_NAME(curs_set) (NCURSES_SP_ARGx cursor);
     }
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(void)
-_nc_mvcur_init(void)
+_nc_mvcur_resume(void)
+{
+    NCURSES_SP_NAME(_nc_mvcur_resume) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_mvcur_init) (NCURSES_SP_DCL0)
 /* 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));
+    if (SP_PARM->_ofp && NC_ISATTY(fileno(SP_PARM->_ofp))) {
+	SP_PARM->_char_padding = ((BAUDBYTE * 1000 * 10)
+				  / (BAUDRATE(SP_PARM) > 0
+				     ? BAUDRATE(SP_PARM)
+				     : 9600));
+    } else {
+	SP_PARM->_char_padding = 1;	/* must be nonzero */
+    }
+    if (SP_PARM->_char_padding <= 0)
+	SP_PARM->_char_padding = 1;	/* must be nonzero */
+    TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP_PARM->_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);
+    SP_PARM->_cr_cost = CostOf(carriage_return, 0);
+    SP_PARM->_home_cost = CostOf(cursor_home, 0);
+    SP_PARM->_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);
+	SP_PARM->_ht_cost = CostOf(tab, 0);
+	SP_PARM->_cbt_cost = CostOf(back_tab, 0);
     } else {
-	SP->_ht_cost = INFINITY;
-	SP->_cbt_cost = INFINITY;
+	SP_PARM->_ht_cost = INFINITY;
+	SP_PARM->_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_PARM->_cub1_cost = CostOf(cursor_left, 0);
+    SP_PARM->_cuf1_cost = CostOf(cursor_right, 0);
+    SP_PARM->_cud1_cost = CostOf(cursor_down, 0);
+    SP_PARM->_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;
+    SP_PARM->_smir_cost = CostOf(enter_insert_mode, 0);
+    SP_PARM->_rmir_cost = CostOf(exit_insert_mode, 0);
+    SP_PARM->_ip_cost = 0;
     if (insert_padding) {
-	SP->_ip_cost = CostOf(insert_padding, 0);
+	SP_PARM->_ip_cost = CostOf(insert_padding, 0);
     }
 
     /*
@@ -335,7 +370,7 @@
      * 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;
+    SP_PARM->_address_cursor = cursor_address ? cursor_address : cursor_mem_address;
 
     /*
      * Parametrized local-motion strings.  This static cost computation
@@ -361,40 +396,43 @@
      * 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);
+    SP_PARM->_cup_cost = CostOf(TPARM_2(SP_PARM->_address_cursor, 23, 23), 1);
+    SP_PARM->_cub_cost = CostOf(TPARM_1(parm_left_cursor, 23), 1);
+    SP_PARM->_cuf_cost = CostOf(TPARM_1(parm_right_cursor, 23), 1);
+    SP_PARM->_cud_cost = CostOf(TPARM_1(parm_down_cursor, 23), 1);
+    SP_PARM->_cuu_cost = CostOf(TPARM_1(parm_up_cursor, 23), 1);
+    SP_PARM->_hpa_cost = CostOf(TPARM_1(column_address, 23), 1);
+    SP_PARM->_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);
+    SP_PARM->_ed_cost = NormalizedCost(clr_eos, 1);
+    SP_PARM->_el_cost = NormalizedCost(clr_eol, 1);
+    SP_PARM->_el1_cost = NormalizedCost(clr_bol, 1);
+    SP_PARM->_dch1_cost = NormalizedCost(delete_character, 1);
+    SP_PARM->_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;
+	SP_PARM->_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_PARM->_dch_cost = NormalizedCost(TPARM_1(parm_dch, 23), 1);
+    SP_PARM->_ich_cost = NormalizedCost(TPARM_1(parm_ich, 23), 1);
+    SP_PARM->_ech_cost = NormalizedCost(TPARM_1(erase_chars, 23), 1);
+    SP_PARM->_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));
+    SP_PARM->_cup_ch_cost = NormalizedCost(
+					      TPARM_2(SP_PARM->_address_cursor,
+						      23, 23),
+					      1);
+    SP_PARM->_hpa_ch_cost = NormalizedCost(TPARM_1(column_address, 23), 1);
+    SP_PARM->_cuf_ch_cost = NormalizedCost(TPARM_1(parm_right_cursor, 23), 1);
+    SP_PARM->_inline_cost = min(SP_PARM->_cup_ch_cost,
+				min(SP_PARM->_hpa_ch_cost,
+				    SP_PARM->_cuf_ch_cost));
 
     /*
      * If save_cursor is used within enter_ca_mode, we should not use it for
@@ -411,30 +449,40 @@
     }
 
     /*
-     * A different, possibly better way to arrange this would be to set
-     * SP->_endwin = TRUE at window initialization time and let this be
+     * A different, possibly better way to arrange this would be to set the
+     * SCREEN's _endwin to TRUE at window initialization time and let this be
      * called by doupdate's return-from-shellout code.
      */
-    _nc_mvcur_resume();
+    NCURSES_SP_NAME(_nc_mvcur_resume) (NCURSES_SP_ARG);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(void)
-_nc_mvcur_wrap(void)
+_nc_mvcur_init(void)
+{
+    NCURSES_SP_NAME(_nc_mvcur_init) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_mvcur_wrap) (NCURSES_SP_DCL0)
 /* wrap up cursor-addressing mode */
 {
     /* leave cursor at screen bottom */
-    mvcur(-1, -1, screen_lines - 1, 0);
+    TINFO_MVCUR(NCURSES_SP_ARGx -1, -1, screen_lines(SP_PARM) - 1, 0);
+
+    if (!SP_PARM || !IsTermInfo(SP_PARM))
+	return;
 
     /* set cursor to normal mode */
-    if (SP->_cursor != -1) {
-	int cursor = SP->_cursor;
-	curs_set(1);
-	SP->_cursor = cursor;
+    if (SP_PARM->_cursor != -1) {
+	int cursor = SP_PARM->_cursor;
+	NCURSES_SP_NAME(curs_set) (NCURSES_SP_ARGx 1);
+	SP_PARM->_cursor = cursor;
     }
 
     if (exit_ca_mode) {
-	TPUTS_TRACE("exit_ca_mode");
-	putp(exit_ca_mode);
+	NCURSES_PUTP2("exit_ca_mode", exit_ca_mode);
     }
     /*
      * Reset terminal's tab counter.  There's a long-time bug that
@@ -444,9 +492,17 @@
      * escape sequences that reset things as column positions.
      * Utter a \r to reset this invisibly.
      */
-    _nc_outch('\r');
+    NCURSES_SP_NAME(_nc_outch) (NCURSES_SP_ARGx '\r');
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_mvcur_wrap(void)
+{
+    NCURSES_SP_NAME(_nc_mvcur_wrap) (CURRENT_SCREEN);
+}
+#endif
+
 /****************************************************************************
  *
  * Optimized cursor movement
@@ -459,7 +515,7 @@
 static NCURSES_INLINE int
 repeated_append(string_desc * target, int total, int num, int repeat, const char *src)
 {
-    size_t need = repeat * strlen(src);
+    size_t need = (size_t) repeat * strlen(src);
 
     if (need < target->s_size) {
 	while (repeat-- > 0) {
@@ -486,8 +542,13 @@
 #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)
+relative_move(NCURSES_SP_DCLx
+	      string_desc * target,
+	      int from_y,
+	      int from_x,
+	      int to_y,
+	      int to_x,
+	      int ovw)
 /* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */
 {
     string_desc save;
@@ -500,38 +561,38 @@
 
 	if (row_address != 0
 	    && _nc_safe_strcat(target, TPARM_1(row_address, to_y))) {
-	    vcost = SP->_vpa_cost;
+	    vcost = SP_PARM->_vpa_cost;
 	}
 
 	if (to_y > from_y) {
 	    n = (to_y - from_y);
 
 	    if (parm_down_cursor
-		&& SP->_cud_cost < vcost
+		&& SP_PARM->_cud_cost < vcost
 		&& _nc_safe_strcat(_nc_str_copy(target, &save),
 				   TPARM_1(parm_down_cursor, n))) {
-		vcost = SP->_cud_cost;
+		vcost = SP_PARM->_cud_cost;
 	    }
 
 	    if (cursor_down
-		&& (*cursor_down != '\n' || SP->_nl)
-		&& (n * SP->_cud1_cost < vcost)) {
+		&& (*cursor_down != '\n' || SP_PARM->_nl)
+		&& (n * SP_PARM->_cud1_cost < vcost)) {
 		vcost = repeated_append(_nc_str_copy(target, &save), 0,
-					SP->_cud1_cost, n, cursor_down);
+					SP_PARM->_cud1_cost, n, cursor_down);
 	    }
 	} else {		/* (to_y < from_y) */
 	    n = (from_y - to_y);
 
 	    if (parm_up_cursor
-		&& SP->_cuu_cost < vcost
+		&& SP_PARM->_cuu_cost < vcost
 		&& _nc_safe_strcat(_nc_str_copy(target, &save),
 				   TPARM_1(parm_up_cursor, n))) {
-		vcost = SP->_cuu_cost;
+		vcost = SP_PARM->_cuu_cost;
 	    }
 
-	    if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
+	    if (cursor_up && (n * SP_PARM->_cuu1_cost < vcost)) {
 		vcost = repeated_append(_nc_str_copy(target, &save), 0,
-					SP->_cuu1_cost, n, cursor_up);
+					SP_PARM->_cuu1_cost, n, cursor_up);
 	    }
 	}
 
@@ -550,17 +611,17 @@
 	if (column_address
 	    && _nc_safe_strcat(_nc_str_copy(target, &save),
 			       TPARM_1(column_address, to_x))) {
-	    hcost = SP->_hpa_cost;
+	    hcost = SP_PARM->_hpa_cost;
 	}
 
 	if (to_x > from_x) {
 	    n = to_x - from_x;
 
 	    if (parm_right_cursor
-		&& SP->_cuf_cost < hcost
+		&& SP_PARM->_cuf_cost < hcost
 		&& _nc_safe_strcat(_nc_str_copy(target, &save),
 				   TPARM_1(parm_right_cursor, n))) {
-		hcost = SP->_cuf_cost;
+		hcost = SP_PARM->_cuf_cost;
 	    }
 
 	    if (cursor_right) {
@@ -575,7 +636,7 @@
 
 		    for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) {
 			lhcost = repeated_append(&check, lhcost,
-						 SP->_ht_cost, 1, tab);
+						 SP_PARM->_ht_cost, 1, tab);
 			if (lhcost == INFINITY)
 			    break;
 		    }
@@ -599,7 +660,7 @@
 		    && n < (int) check.s_size
 		    && vcost == 0
 		    && str[0] == '\0') {
-		    int wanted = CharOf(WANT_CHAR(to_y, from_x));
+		    int wanted = CharOf(WANT_CHAR(SP_PARM, to_y, from_x));
 		    if (is8bits(wanted) && isdigit(wanted))
 			ovw = FALSE;
 		}
@@ -616,8 +677,8 @@
 		    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))
+			NCURSES_CH_T ch = WANT_CHAR(SP_PARM, to_y, from_x + i);
+			if (!SameAttrOf(ch, SCREEN_ATTRS(SP_PARM))
 #if USE_WIDEC_SUPPORT
 			    || !Charable(ch)
 #endif
@@ -631,13 +692,13 @@
 		    int i;
 
 		    for (i = 0; i < n; i++)
-			*check.s_tail++ = (char) CharOf(WANT_CHAR(to_y,
+			*check.s_tail++ = (char) CharOf(WANT_CHAR(SP_PARM, to_y,
 								  from_x + i));
 		    *check.s_tail = '\0';
-		    check.s_size -= n;
-		    lhcost += n * SP->_char_padding;
+		    check.s_size -= (size_t) n;
+		    lhcost += n * SP_PARM->_char_padding;
 		} else {
-		    lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost,
+		    lhcost = repeated_append(&check, lhcost, SP_PARM->_cuf1_cost,
 					     n, cursor_right);
 		}
 
@@ -650,10 +711,10 @@
 	    n = from_x - to_x;
 
 	    if (parm_left_cursor
-		&& SP->_cub_cost < hcost
+		&& SP_PARM->_cub_cost < hcost
 		&& _nc_safe_strcat(_nc_str_copy(target, &save),
 				   TPARM_1(parm_left_cursor, n))) {
-		hcost = SP->_cub_cost;
+		hcost = SP_PARM->_cub_cost;
 	    }
 
 	    if (cursor_left) {
@@ -667,7 +728,8 @@
 
 		    for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) {
 			lhcost = repeated_append(&check, lhcost,
-						 SP->_cbt_cost, 1, back_tab);
+						 SP_PARM->_cbt_cost,
+						 1, back_tab);
 			if (lhcost == INFINITY)
 			    break;
 		    }
@@ -676,7 +738,9 @@
 		}
 #endif /* USE_HARD_TABS */
 
-		lhcost = repeated_append(&check, lhcost, SP->_cub1_cost, n, cursor_left);
+		lhcost = repeated_append(&check, lhcost,
+					 SP_PARM->_cub1_cost,
+					 n, cursor_left);
 
 		if (lhcost < hcost
 		    && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
@@ -705,7 +769,10 @@
  */
 
 static NCURSES_INLINE int
-onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
+onscreen_mvcur(NCURSES_SP_DCLx
+	       int yold, int xold,
+	       int ynew, int xnew, int ovw,
+	       NCURSES_SP_OUTC myOutCh)
 /* onscreen move from (yold, xold) to (ynew, xnew) */
 {
     string_desc result;
@@ -723,9 +790,9 @@
 #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))) {
+    if (_nc_safe_strcpy(InitResult, TPARM_2(SP_PARM->_address_cursor, ynew, xnew))) {
 	tactic = 0;
-	usecost = SP->_cup_cost;
+	usecost = SP_PARM->_cup_cost;
 
 #if defined(TRACE) || defined(NCURSES_TEST)
 	if (!(_nc_optimize_enable & OPTIMIZE_MVCUR))
@@ -740,7 +807,7 @@
 	 * (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 (yold == -1 || xold == -1 || NOT_LOCAL(SP_PARM, yold, xold, ynew, xnew)) {
 #if defined(MAIN) || defined(NCURSES_TEST)
 	    if (!profiling) {
 		(void) fputs("nonlocal\n", stderr);
@@ -754,8 +821,10 @@
 #ifndef NO_OPTIMIZE
     /* tactic #1: use local movement */
     if (yold != -1 && xold != -1
-	&& ((newcost = relative_move(NullResult, yold, xold, ynew, xnew,
-				     ovw)) != INFINITY)
+	&& ((newcost = relative_move(NCURSES_SP_ARGx
+				     NullResult,
+				     yold, xold,
+				     ynew, xnew, ovw)) != INFINITY)
 	&& newcost < usecost) {
 	tactic = 1;
 	usecost = newcost;
@@ -763,42 +832,51 @@
 
     /* 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) {
+	&& ((newcost = relative_move(NCURSES_SP_ARGx
+				     NullResult,
+				     yold, 0,
+				     ynew, xnew, ovw)) != INFINITY)
+	&& SP_PARM->_cr_cost + newcost < usecost) {
 	tactic = 2;
-	usecost = SP->_cr_cost + newcost;
+	usecost = SP_PARM->_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) {
+	&& ((newcost = relative_move(NCURSES_SP_ARGx
+				     NullResult,
+				     0, 0,
+				     ynew, xnew, ovw)) != INFINITY)
+	&& SP_PARM->_home_cost + newcost < usecost) {
 	tactic = 3;
-	usecost = SP->_home_cost + newcost;
+	usecost = SP_PARM->_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) {
+	&& ((newcost = relative_move(NCURSES_SP_ARGx
+				     NullResult,
+				     screen_lines(SP_PARM) - 1, 0,
+				     ynew, xnew, ovw)) != INFINITY)
+	&& SP_PARM->_ll_cost + newcost < usecost) {
 	tactic = 4;
-	usecost = SP->_ll_cost + newcost;
+	usecost = SP_PARM->_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);
+    t5_cr_cost = (xold > 0 ? SP_PARM->_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) {
+	&& ((newcost = relative_move(NCURSES_SP_ARGx
+				     NullResult,
+				     yold - 1, screen_columns(SP_PARM) - 1,
+				     ynew, xnew, ovw)) != INFINITY)
+	&& t5_cr_cost + SP_PARM->_cub1_cost + newcost < usecost) {
 	tactic = 5;
-	usecost = t5_cr_cost + SP->_cub1_cost + newcost;
+	usecost = t5_cr_cost + SP_PARM->_cub1_cost + newcost;
     }
 
     /*
@@ -808,26 +886,39 @@
 	InitResult;
     switch (tactic) {
     case 1:
-	(void) relative_move(&result, yold, xold, ynew, xnew, ovw);
+	(void) relative_move(NCURSES_SP_ARGx
+			     &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);
+	(void) relative_move(NCURSES_SP_ARGx
+			     &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);
+	(void) relative_move(NCURSES_SP_ARGx
+			     &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);
+	(void) relative_move(NCURSES_SP_ARGx
+			     &result,
+			     screen_lines(SP_PARM) - 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);
+	(void) relative_move(NCURSES_SP_ARGx
+			     &result,
+			     yold - 1, screen_columns(SP_PARM) - 1,
+			     ynew, xnew, ovw);
 	break;
     }
 #endif /* !NO_OPTIMIZE */
@@ -845,25 +936,32 @@
 
     if (usecost != INFINITY) {
 	TPUTS_TRACE("mvcur");
-	tputs(buffer, 1, _nc_outch);
-	SP->_cursrow = ynew;
-	SP->_curscol = xnew;
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				buffer, 1, myOutCh);
+	SP_PARM->_cursrow = ynew;
+	SP_PARM->_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) */
+/*
+ * optimized cursor move from (yold, xold) to (ynew, xnew)
+ */
+static int
+_nc_real_mvcur(NCURSES_SP_DCLx
+	       int yold, int xold,
+	       int ynew, int xnew,
+	       NCURSES_SP_OUTC myOutCh,
+	       int ovw)
 {
     NCURSES_CH_T oldattr;
     int code;
 
-    TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
-				  yold, xold, ynew, xnew));
+    TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("_nc_tinfo_mvcur(%p,%d,%d,%d,%d)"),
+				  (void *) SP_PARM, yold, xold, ynew, xnew));
 
-    if (SP == 0) {
+    if (SP_PARM == 0) {
 	code = ERR;
     } else if (yold == ynew && xold == xnew) {
 	code = OK;
@@ -874,9 +972,9 @@
 	 * 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;
+	if (xnew >= screen_columns(SP_PARM)) {
+	    ynew += xnew / screen_columns(SP_PARM);
+	    xnew %= screen_columns(SP_PARM);
 	}
 
 	/*
@@ -884,38 +982,38 @@
 	 * character set -- these have a strong tendency to screw up the CR &
 	 * LF used for local character motions!
 	 */
-	oldattr = SCREEN_ATTRS(SP);
+	oldattr = SCREEN_ATTRS(SP_PARM);
 	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);
+	    (void) VIDATTR(SP_PARM, A_NORMAL, 0);
 	}
 
-	if (xold >= screen_columns) {
+	if (xold >= screen_columns(SP_PARM)) {
 	    int l;
 
-	    if (SP->_nl) {
-		l = (xold + 1) / screen_columns;
+	    if (SP_PARM->_nl) {
+		l = (xold + 1) / screen_columns(SP_PARM);
 		yold += l;
-		if (yold >= screen_lines)
-		    l -= (yold - screen_lines - 1);
+		if (yold >= screen_lines(SP_PARM))
+		    l -= (yold - screen_lines(SP_PARM) - 1);
 
 		if (l > 0) {
 		    if (carriage_return) {
-			TPUTS_TRACE("carriage_return");
-			putp(carriage_return);
-		    } else
-			_nc_outch('\r');
+			NCURSES_PUTP2("carriage_return", carriage_return);
+		    } else {
+			myOutCh(NCURSES_SP_ARGx '\r');
+		    }
 		    xold = 0;
 
 		    while (l > 0) {
 			if (newline) {
-			    TPUTS_TRACE("newline");
-			    putp(newline);
-			} else
-			    _nc_outch('\n');
+			    NCURSES_PUTP2("newline", newline);
+			} else {
+			    myOutCh(NCURSES_SP_ARGx '\n');
+			}
 			l--;
 		    }
 		}
@@ -929,27 +1027,88 @@
 	    }
 	}
 
-	if (yold > screen_lines - 1)
-	    yold = screen_lines - 1;
-	if (ynew > screen_lines - 1)
-	    ynew = screen_lines - 1;
+	if (yold > screen_lines(SP_PARM) - 1)
+	    yold = screen_lines(SP_PARM) - 1;
+	if (ynew > screen_lines(SP_PARM) - 1)
+	    ynew = screen_lines(SP_PARM) - 1;
 
 	/* destination location is on screen now */
-	code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE);
+	code = onscreen_mvcur(NCURSES_SP_ARGx yold, xold, ynew, xnew, ovw, myOutCh);
 
 	/*
 	 * Restore attributes if we disabled them before moving.
 	 */
-	if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) {
+	if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP_PARM))) {
 	    TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move",
 			       (unsigned long) AttrOf(oldattr),
 			       _traceattr(AttrOf(oldattr))));
-	    (void) VIDATTR(AttrOf(oldattr), GetPair(oldattr));
+	    (void) VIDATTR(SP_PARM, AttrOf(oldattr), GetPair(oldattr));
 	}
     }
     returnCode(code);
 }
 
+/*
+ * These entrypoints are used within the library.
+ */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_mvcur) (NCURSES_SP_DCLx
+			    int yold, int xold,
+			    int ynew, int xnew)
+{
+    return _nc_real_mvcur(NCURSES_SP_ARGx yold, xold, ynew, xnew,
+			  NCURSES_SP_NAME(_nc_outch),
+			  TRUE);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_mvcur(int yold, int xold,
+	  int ynew, int xnew)
+{
+    return NCURSES_SP_NAME(_nc_mvcur) (CURRENT_SCREEN, yold, xold, ynew, xnew);
+}
+#endif
+
+#if defined(USE_TERM_DRIVER)
+/*
+ * The terminal driver does not support the external "mvcur()".
+ */
+NCURSES_EXPORT(int)
+TINFO_MVCUR(NCURSES_SP_DCLx int yold, int xold, int ynew, int xnew)
+{
+    return _nc_real_mvcur(NCURSES_SP_ARGx
+			  yold, xold,
+			  ynew, xnew,
+			  NCURSES_SP_NAME(_nc_outch),
+			  TRUE);
+}
+
+#else /* !USE_TERM_DRIVER */
+
+/*
+ * These entrypoints support users of the library.
+ */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(mvcur) (NCURSES_SP_DCLx int yold, int xold, int ynew,
+			int xnew)
+{
+    return _nc_real_mvcur(NCURSES_SP_ARGx
+			  yold, xold,
+			  ynew, xnew,
+			  NCURSES_SP_NAME(_nc_putchar),
+			  FALSE);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+mvcur(int yold, int xold, int ynew, int xnew)
+{
+    return NCURSES_SP_NAME(mvcur) (CURRENT_SCREEN, yold, xold, ynew, xnew);
+}
+#endif
+#endif /* USE_TERM_DRIVER */
+
 #if defined(TRACE) || defined(NCURSES_TEST)
 NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL;
 #endif
@@ -1028,7 +1187,6 @@
     baudrate();
 
     _nc_mvcur_init();
-    NC_BUFFERED(FALSE);
 
     (void) puts("The mvcur tester.  Type ? for help");
 
@@ -1120,7 +1278,7 @@
 		}
 	    }
 	} else if (buf[0] == 'i') {
-	    dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
+	    dump_init(NULL, F_TERMINFO, S_TERMINFO, 70, 0, 0, FALSE, FALSE);
 	    dump_entry(&cur_term->type, FALSE, TRUE, 0, 0);
 	    putchar('\n');
 	} else if (buf[0] == 'o') {
@@ -1212,25 +1370,25 @@
 			   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);
+	    (void) printf("char padding: %d\n", CURRENT_SCREEN->_char_padding);
+	    (void) printf("cr cost: %d\n", CURRENT_SCREEN->_cr_cost);
+	    (void) printf("cup cost: %d\n", CURRENT_SCREEN->_cup_cost);
+	    (void) printf("home cost: %d\n", CURRENT_SCREEN->_home_cost);
+	    (void) printf("ll cost: %d\n", CURRENT_SCREEN->_ll_cost);
 #if USE_HARD_TABS
-	    (void) printf("ht cost: %d\n", SP->_ht_cost);
-	    (void) printf("cbt cost: %d\n", SP->_cbt_cost);
+	    (void) printf("ht cost: %d\n", CURRENT_SCREEN->_ht_cost);
+	    (void) printf("cbt cost: %d\n", CURRENT_SCREEN->_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);
+	    (void) printf("cub1 cost: %d\n", CURRENT_SCREEN->_cub1_cost);
+	    (void) printf("cuf1 cost: %d\n", CURRENT_SCREEN->_cuf1_cost);
+	    (void) printf("cud1 cost: %d\n", CURRENT_SCREEN->_cud1_cost);
+	    (void) printf("cuu1 cost: %d\n", CURRENT_SCREEN->_cuu1_cost);
+	    (void) printf("cub cost: %d\n", CURRENT_SCREEN->_cub_cost);
+	    (void) printf("cuf cost: %d\n", CURRENT_SCREEN->_cuf_cost);
+	    (void) printf("cud cost: %d\n", CURRENT_SCREEN->_cud_cost);
+	    (void) printf("cuu cost: %d\n", CURRENT_SCREEN->_cuu_cost);
+	    (void) printf("hpa cost: %d\n", CURRENT_SCREEN->_hpa_cost);
+	    (void) printf("vpa cost: %d\n", CURRENT_SCREEN->_vpa_cost);
 	} else if (buf[0] == 'x' || buf[0] == 'q')
 	    break;
 	else
diff --git a/ncurses/tty/lib_tstp.c b/ncurses/tty/lib_tstp.c
index 06c8411..8624b76 100644
--- a/ncurses/tty/lib_tstp.c
+++ b/ncurses/tty/lib_tstp.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -42,11 +42,7 @@
 
 #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 $")
+MODULE_ID("$Id: lib_tstp.c,v 1.48 2014/04/26 18:47:35 juergen Exp $")
 
 #if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC)
 #define USE_SIGTSTP 1
@@ -59,16 +55,20 @@
 signal_name(int sig)
 {
     switch (sig) {
+#ifdef SIGALRM
     case SIGALRM:
 	return "SIGALRM";
+#endif
 #ifdef SIGCONT
     case SIGCONT:
 	return "SIGCONT";
 #endif
     case SIGINT:
 	return "SIGINT";
+#ifdef SIGQUIT
     case SIGQUIT:
 	return "SIGQUIT";
+#endif
     case SIGTERM:
 	return "SIGTERM";
 #ifdef SIGTSTP
@@ -134,8 +134,9 @@
 
 #if USE_SIGTSTP
 static void
-tstp(int dummy GCC_UNUSED)
+handle_SIGTSTP(int dummy GCC_UNUSED)
 {
+    SCREEN *sp = CURRENT_SCREEN;
     sigset_t mask, omask;
     sigaction_t act, oact;
 
@@ -143,7 +144,8 @@
     int sigttou_blocked;
 #endif
 
-    T(("tstp() called"));
+    _nc_globals.have_sigtstp = 1;
+    T(("handle_SIGTSTP() called"));
 
     /*
      * The user may have changed the prog_mode tty bits, so save them.
@@ -154,11 +156,11 @@
      * 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 (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();
+	    NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_ARG);
 
     /*
      * Block window change and timer signals.  The latter
@@ -166,7 +168,9 @@
      * to repaint the screen.
      */
     (void) sigemptyset(&mask);
+#ifdef SIGALRM
     (void) sigaddset(&mask, SIGALRM);
+#endif
 #if USE_SIGWINCH
     (void) sigaddset(&mask, SIGWINCH);
 #endif
@@ -185,7 +189,7 @@
      * End window mode, which also resets the terminal state to the
      * original (pre-curses) modes.
      */
-    endwin();
+    NCURSES_SP_NAME(endwin) (NCURSES_SP_ARG);
 
     /* Unblock SIGTSTP. */
     (void) sigemptyset(&mask);
@@ -212,19 +216,19 @@
 
     T(("SIGCONT received"));
     sigaction(SIGTSTP, &oact, NULL);
-    flushinp();
+    NCURSES_SP_NAME(flushinp) (NCURSES_SP_ARG);
 
     /*
      * 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();
+    NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_ARG);
 
     /*
      * This relies on the fact that doupdate() will restore the
      * program-mode tty state, and issue enter_ca_mode if need be.
      */
-    doupdate();
+    NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
 
     /* Reset the signals. */
     (void) sigprocmask(SIG_SETMASK, &omask, NULL);
@@ -232,16 +236,24 @@
 #endif /* USE_SIGTSTP */
 
 static void
-cleanup(int sig)
+handle_SIGINT(int sig)
 {
+    SCREEN *sp = CURRENT_SCREEN;
+
     /*
-     * 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.
+     * Much of this is unsafe from a signal handler.  But we'll _try_ to clean
+     * up the screen and terminal settings on the way out.
+     *
+     * There are at least the following problems:
+     * 1) Walking the SCREEN list is unsafe, since all list management
+     *    is done without any signal blocking.
+     * 2) On systems which have REENTRANT turned on, set_term() uses
+     *    _nc_lock_global() which could deadlock or misbehave in other ways.
+     * 3) endwin() calls all sorts of stuff, many of which use stdio or
+     *    other library functions which are clearly unsafe.
      */
     if (!_nc_globals.cleanup_nested++
-	&& (sig == SIGINT
-	    || sig == SIGQUIT)) {
+	&& (sig == SIGINT || sig == SIGTERM)) {
 #if HAVE_SIGACTION || HAVE_SIGVEC
 	sigaction_t act;
 	sigemptyset(&act.sa_mask);
@@ -255,25 +267,31 @@
 	    SCREEN *scan;
 	    for (each_screen(scan)) {
 		if (scan->_ofp != 0
-		    && isatty(fileno(scan->_ofp))) {
-		    scan->_cleanup = TRUE;
-		    scan->_outch = _nc_outch;
+		    && NC_ISATTY(fileno(scan->_ofp))) {
+		    scan->_outch = NCURSES_SP_NAME(_nc_outch);
 		}
 		set_term(scan);
-		endwin();
-		if (SP)
-		    SP->_endwin = FALSE;	/* in case we have an atexit! */
+		NCURSES_SP_NAME(endwin) (NCURSES_SP_ARG);
+		if (sp)
+		    sp->_endwin = FALSE;	/* in case of reuse */
 	    }
 	}
     }
-    exit(EXIT_FAILURE);
+    _exit(EXIT_FAILURE);
 }
 
 #if USE_SIGWINCH
 static void
-sigwinch(int sig GCC_UNUSED)
+handle_SIGWINCH(int sig GCC_UNUSED)
 {
     _nc_globals.have_sigwinch = 1;
+# if USE_PTHREADS_EINTR
+    if (_nc_globals.read_thread) {
+	if (!pthread_equal(pthread_self(), _nc_globals.read_thread))
+	    pthread_kill(_nc_globals.read_thread, SIGWINCH);
+	_nc_globals.read_thread = 0;
+    }
+# endif
 }
 #endif /* USE_SIGWINCH */
 
@@ -282,7 +300,7 @@
  * handler.
  */
 static int
-CatchIfDefault(int sig, RETSIGTYPE (*handler) (int))
+CatchIfDefault(int sig, void (*handler) (int))
 {
     int result;
 #if HAVE_SIGACTION || HAVE_SIGVEC
@@ -312,7 +330,7 @@
 	result = FALSE;
     }
 #else /* !HAVE_SIGACTION */
-    RETSIGTYPE (*ohandler) (int);
+    void (*ohandler) (int);
 
     ohandler = signal(sig, SIG_IGN);
     if (ohandler == SIG_DFL
@@ -345,7 +363,7 @@
  * the caller later changes its mind, but that doesn't seem correct.
  */
 NCURSES_EXPORT(void)
-_nc_signal_handler(bool enable)
+_nc_signal_handler(int enable)
 {
     T((T_CALLED("_nc_signal_handler(%d)"), enable));
 #if USE_SIGTSTP			/* Xenix 2.x doesn't have SIGTSTP, for example */
@@ -366,7 +384,7 @@
 #ifdef SA_RESTART
 		new_sigaction.sa_flags |= SA_RESTART;
 #endif /* SA_RESTART */
-		new_sigaction.sa_handler = tstp;
+		new_sigaction.sa_handler = handle_SIGTSTP;
 		(void) sigaction(SIGTSTP, &new_sigaction, NULL);
 	    } else {
 		ignore_tstp = TRUE;
@@ -377,10 +395,10 @@
 
     if (!_nc_globals.init_signals) {
 	if (enable) {
-	    CatchIfDefault(SIGINT, cleanup);
-	    CatchIfDefault(SIGTERM, cleanup);
+	    CatchIfDefault(SIGINT, handle_SIGINT);
+	    CatchIfDefault(SIGTERM, handle_SIGINT);
 #if USE_SIGWINCH
-	    CatchIfDefault(SIGWINCH, sigwinch);
+	    CatchIfDefault(SIGWINCH, handle_SIGWINCH);
 #endif
 	    _nc_globals.init_signals = TRUE;
 	}
diff --git a/ncurses/tty/lib_twait.c b/ncurses/tty/lib_twait.c
index 16d12ed..15d07c3 100644
--- a/ncurses/tty/lib_twait.c
+++ b/ncurses/tty/lib_twait.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2014,2015 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            *
@@ -53,6 +53,11 @@
 #include <OS.h>
 #endif
 
+#if USE_KLIBC_KBD
+#define INCL_KBD
+#include <os2.h>
+#endif
+
 #if USE_FUNC_POLL
 # if HAVE_SYS_TIME_H
 #  include <sys/time.h>
@@ -65,13 +70,15 @@
 #  include <sys/select.h>
 # endif
 #endif
-
+#ifdef __MINGW32__
+#  include <sys/time.h>
+#endif
 #undef CUR
 
-MODULE_ID("$Id: lib_twait.c,v 1.59 2008/08/30 20:08:19 tom Exp $")
+MODULE_ID("$Id: lib_twait.c,v 1.70 2015/07/04 21:01:02 tom Exp $")
 
 static long
-_nc_gettime(TimeType * t0, bool first)
+_nc_gettime(TimeType * t0, int first)
 {
     long res;
 
@@ -95,7 +102,7 @@
     if (first) {
 	*t0 = t1;
     }
-    res = (t1 - *t0) * 1000;
+    res = (long) ((t1 - *t0) * 1000);
 #endif
     TR(TRACE_IEVENT, ("%s time: %ld msec", first ? "get" : "elapsed", res));
     return res;
@@ -114,7 +121,7 @@
 	    _nc_event *ev = evl->events[n];
 
 	    if (ev->type == _NC_EVENT_TIMEOUT_MSEC) {
-		event_delay = ev->data.timeout_msec;
+		event_delay = (int) ev->data.timeout_msec;
 		if (event_delay < 0)
 		    event_delay = INT_MAX;	/* FIXME Is this defined? */
 	    }
@@ -124,15 +131,27 @@
 }
 #endif /* NCURSES_WGETCH_EVENTS */
 
+#if (USE_FUNC_POLL || HAVE_SELECT)
+#  define MAYBE_UNUSED
+#else
+#  define MAYBE_UNUSED GCC_UNUSED
+#endif
+
+#if (USE_FUNC_POLL || HAVE_SELECT)
+#  define MAYBE_UNUSED
+#else
+#  define MAYBE_UNUSED GCC_UNUSED
+#endif
+
 /*
  * 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.
- *
+ *	TW_NONE    0 - none (absolute time)
+ *	TW_INPUT   1 - ncurses' normal input-descriptor
+ *	TW_MOUSE   2 - mouse descriptor, if any
+ *	TW_ANY     3 - either input or mouse.
+ *      TW_EVENT   4 -
  * 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.
@@ -143,16 +162,18 @@
  * descriptors.
  */
 NCURSES_EXPORT(int)
-_nc_timed_wait(SCREEN *sp,
-	       int mode,
+_nc_timed_wait(SCREEN *sp MAYBE_UNUSED,
+	       int mode MAYBE_UNUSED,
 	       int milliseconds,
 	       int *timeleft
 	       EVENTLIST_2nd(_nc_eventlist * evl))
 {
-    int fd;
     int count;
-    int result = 0;
+    int result = TW_NONE;
     TimeType t0;
+#if (USE_FUNC_POLL || HAVE_SELECT)
+    int fd;
+#endif
 
 #ifdef NCURSES_WGETCH_EVENTS
     int timeout_is_event = 0;
@@ -168,13 +189,19 @@
     fd_set set;
 #endif
 
+#if USE_KLIBC_KBD
+    fd_set saved_set;
+    KBDKEYINFO ki;
+    struct timeval tv;
+#endif
+
     long starttime, returntime;
 
     TR(TRACE_IEVENT, ("start twait: %d milliseconds, mode: %d",
 		      milliseconds, mode));
 
 #ifdef NCURSES_WGETCH_EVENTS
-    if (mode & 4) {
+    if (mode & TW_EVENT) {
 	int event_delay = _nc_eventlist_timeout(evl);
 
 	if (event_delay >= 0
@@ -191,9 +218,10 @@
     starttime = _nc_gettime(&t0, TRUE);
 
     count = 0;
+    (void) count;
 
 #ifdef NCURSES_WGETCH_EVENTS
-    if ((mode & 4) && evl)
+    if ((mode & TW_EVENT) && evl)
 	evl->result_flags = 0;
 #endif
 
@@ -201,23 +229,27 @@
     memset(fd_list, 0, sizeof(fd_list));
 
 #ifdef NCURSES_WGETCH_EVENTS
-    if ((mode & 4) && evl)
-	fds = typeMalloc(struct pollfd, MIN_FDS + evl->count);
+    if ((mode & TW_EVENT) && evl) {
+	if (fds == fd_list)
+	    fds = typeMalloc(struct pollfd, MIN_FDS + evl->count);
+	if (fds == 0)
+	    return TW_NONE;
+    }
 #endif
 
-    if (mode & 1) {
+    if (mode & TW_INPUT) {
 	fds[count].fd = sp->_ifd;
 	fds[count].events = POLLIN;
 	count++;
     }
-    if ((mode & 2)
+    if ((mode & TW_MOUSE)
 	&& (fd = sp->_mouse_fd) >= 0) {
 	fds[count].fd = fd;
 	fds[count].events = POLLIN;
 	count++;
     }
 #ifdef NCURSES_WGETCH_EVENTS
-    if ((mode & 4) && evl) {
+    if ((mode & TW_EVENT) && evl) {
 	for (n = 0; n < evl->count; ++n) {
 	    _nc_event *ev = evl->events[n];
 
@@ -231,10 +263,10 @@
     }
 #endif
 
-    result = poll(fds, (unsigned) count, milliseconds);
+    result = poll(fds, (size_t) count, milliseconds);
 
 #ifdef NCURSES_WGETCH_EVENTS
-    if ((mode & 4) && evl) {
+    if ((mode & TW_EVENT) && evl) {
 	int c;
 
 	if (!result)
@@ -258,10 +290,6 @@
 	    }
 	}
     }
-
-    if (fds != fd_list)
-	free((char *) fds);
-
 #endif
 
 #elif defined(__BEOS__)
@@ -276,8 +304,8 @@
      *
      * FIXME: this assumes mode&1 if milliseconds < 0 (see lib_getch.c).
      */
-    result = 0;
-    if (mode & 1) {
+    result = TW_NONE;
+    if (mode & TW_INPUT) {
 	int step = (milliseconds < 0) ? 0 : 5000;
 	bigtime_t d;
 	bigtime_t useconds = milliseconds * 1000;
@@ -313,17 +341,19 @@
      */
     FD_ZERO(&set);
 
-    if (mode & 1) {
+#if !USE_KLIBC_KBD
+    if (mode & TW_INPUT) {
 	FD_SET(sp->_ifd, &set);
 	count = sp->_ifd + 1;
     }
-    if ((mode & 2)
+#endif
+    if ((mode & TW_MOUSE)
 	&& (fd = sp->_mouse_fd) >= 0) {
 	FD_SET(fd, &set);
 	count = max(fd, count) + 1;
     }
 #ifdef NCURSES_WGETCH_EVENTS
-    if ((mode & 4) && evl) {
+    if ((mode & TW_EVENT) && evl) {
 	for (n = 0; n < evl->count; ++n) {
 	    _nc_event *ev = evl->events[n];
 
@@ -336,6 +366,31 @@
     }
 #endif
 
+#if USE_KLIBC_KBD
+    for (saved_set = set;; set = saved_set) {
+	if ((mode & TW_INPUT)
+	    && (sp->_extended_key
+		|| (KbdPeek(&ki, 0) == 0
+		    && (ki.fbStatus & KBDTRF_FINAL_CHAR_IN)))) {
+	    FD_ZERO(&set);
+	    FD_SET(sp->_ifd, &set);
+	    result = 1;
+	    break;
+	}
+
+	tv.tv_sec = 0;
+	tv.tv_usec = (milliseconds == 0) ? 0 : (10 * 1000);
+
+	if ((result = select(count, &set, NULL, NULL, &tv)) != 0)
+	    break;
+
+	/* Time out ? */
+	if (milliseconds >= 0 && _nc_gettime(&t0, FALSE) >= milliseconds) {
+	    result = 0;
+	    break;
+	}
+    }
+#else
     if (milliseconds >= 0) {
 	struct timeval ntimeout;
 	ntimeout.tv_sec = milliseconds / 1000;
@@ -344,9 +399,10 @@
     } else {
 	result = select(count, &set, NULL, NULL, NULL);
     }
+#endif
 
 #ifdef NCURSES_WGETCH_EVENTS
-    if ((mode & 4) && evl) {
+    if ((mode & TW_EVENT) && evl) {
 	evl->result_flags = 0;
 	for (n = 0; n < evl->count; ++n) {
 	    _nc_event *ev = evl->events[n];
@@ -370,7 +426,7 @@
     returntime = _nc_gettime(&t0, FALSE);
 
     if (milliseconds >= 0)
-	milliseconds -= (returntime - starttime);
+	milliseconds -= (int) (returntime - starttime);
 
 #ifdef NCURSES_WGETCH_EVENTS
     if (evl) {
@@ -428,22 +484,29 @@
 		}
 	    }
 #elif defined(__BEOS__)
-	    result = 1;		/* redundant, but simple */
+	    result = TW_INPUT;	/* redundant, but simple */
 #elif HAVE_SELECT
-	    if ((mode & 2)
+	    if ((mode & TW_MOUSE)
 		&& (fd = sp->_mouse_fd) >= 0
 		&& FD_ISSET(fd, &set))
-		result |= 2;
-	    if ((mode & 1)
+		result |= TW_MOUSE;
+	    if ((mode & TW_INPUT)
 		&& FD_ISSET(sp->_ifd, &set))
-		result |= 1;
+		result |= TW_INPUT;
 #endif
 	} else
 	    result = 0;
     }
 #ifdef NCURSES_WGETCH_EVENTS
-    if ((mode & 4) && evl && evl->result_flags)
-	result |= 4;
+    if ((mode & TW_EVENT) && evl && evl->result_flags)
+	result |= TW_EVENT;
+#endif
+
+#if USE_FUNC_POLL
+#ifdef NCURSES_WGETCH_EVENTS
+    if (fds != fd_list)
+	free((char *) fds);
+#endif
 #endif
 
     return (result);
diff --git a/ncurses/tty/lib_vidattr.c b/ncurses/tty/lib_vidattr.c
index ac2a74f..184d9b9 100644
--- a/ncurses/tty/lib_vidattr.c
+++ b/ncurses/tty/lib_vidattr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,7 +29,8 @@
 /****************************************************************************
  *  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: Thomas E. Dickey                        1996-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
@@ -63,55 +64,69 @@
  */
 
 #include <curses.priv.h>
-#include <term.h>
 
-MODULE_ID("$Id: lib_vidattr.c,v 1.49 2007/06/30 21:58:04 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
+MODULE_ID("$Id: lib_vidattr.c,v 1.71 2014/09/04 22:01:27 tom Exp $")
 
-#define TurnOn(mask,mode) \
+#define doPut(mode) \
+	TPUTS_TRACE(#mode); \
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc)
+
+#define TurnOn(mask, mode) \
 	if ((turn_on & mask) && mode) { doPut(mode); }
 
-#define TurnOff(mask,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) \
+#define SetColorsIf(why, old_attr) \
 	if (can_color && (why)) { \
-		int old_pair = PAIR_NUMBER(old_attr); \
+		int old_pair = PairNumber(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); \
+		     NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx \
+				     (short) old_pair, \
+				     (short) pair, \
+				     reverse, outc); \
 		} \
 	}
 
 #define PreviousAttr _nc_prescreen.previous_attr
 
 NCURSES_EXPORT(int)
-vidputs(chtype newmode, int (*outc) (int))
+NCURSES_SP_NAME(vidputs) (NCURSES_SP_DCLx
+			  chtype newmode,
+			  NCURSES_SP_OUTC outc)
 {
     attr_t turn_on, turn_off;
     int pair;
     bool reverse = FALSE;
-    bool can_color = (SP == 0 || SP->_coloron);
+    bool can_color = (SP_PARM == 0 || SP_PARM->_coloron);
 #if NCURSES_EXT_FUNCS
-    bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color);
+    bool fix_pair0 = (SP_PARM != 0 && SP_PARM->_coloron && !SP_PARM->_default_color);
 #else
 #define fix_pair0 FALSE
 #endif
 
     newmode &= A_ATTRIBUTES;
-    T((T_CALLED("vidputs(%s)"), _traceattr(newmode)));
+
+    T((T_CALLED("vidputs(%p,%s)"), (void *) SP_PARM, _traceattr(newmode)));
+
+    if (!IsTermInfo(SP_PARM))
+	returnCode(ERR);
 
     /* this allows us to go on whether or not newterm() has been called */
-    if (SP)
-	PreviousAttr = AttrOf(SCREEN_ATTRS(SP));
+    if (SP_PARM)
+	PreviousAttr = AttrOf(SCREEN_ATTRS(SP_PARM));
 
     TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(PreviousAttr)));
 
-    if ((SP != 0)
+    if ((SP_PARM != 0)
 	&& (magic_cookie_glitch > 0)) {
 #if USE_XMC_SUPPORT
 	static const chtype table[] =
@@ -124,6 +139,9 @@
 	    A_BOLD,
 	    A_INVIS,
 	    A_PROTECT,
+#if USE_ITALIC
+	    A_ITALIC,
+#endif
 	};
 	unsigned n;
 	int used = 0;
@@ -135,7 +153,7 @@
 	 * the terminfo max_attributes value.
 	 */
 	for (n = 0; n < SIZEOF(table); ++n) {
-	    if ((table[n] & SP->_ok_attributes) == 0) {
+	    if ((table[n] & SP_PARM->_ok_attributes) == 0) {
 		newmode &= ~table[n];
 	    } else if ((table[n] & newmode) != 0) {
 		if (used++ >= limit) {
@@ -148,7 +166,7 @@
 	    }
 	}
 #else
-	newmode &= ~(SP->_xmc_suppress);
+	newmode &= ~(SP_PARM->_xmc_suppress);
 #endif
 	TR(TRACE_ATTRS, ("suppressed attribute is %s", _traceattr(newmode)));
     }
@@ -172,7 +190,7 @@
 	 * 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;
+	unsigned value = (unsigned) no_color_video;
 	attr_t mask = NCURSES_BITS((value & 63)
 				   | ((value & 192) << 1)
 				   | ((value & 256) >> 2), 8);
@@ -188,14 +206,14 @@
     if (newmode == PreviousAttr)
 	returnCode(OK);
 
-    pair = PAIR_NUMBER(newmode);
+    pair = PairNumber(newmode);
 
     if (reverse) {
 	newmode &= ~A_REVERSE;
     }
 
     turn_off = (~newmode & PreviousAttr) & ALL_BUT_COLOR;
-    turn_on = (newmode & ~PreviousAttr) & ALL_BUT_COLOR;
+    turn_on = (newmode & ~(PreviousAttr & TPARM_ATTR)) & ALL_BUT_COLOR;
 
     SetColorsIf(((pair == 0) && !fix_pair0), PreviousAttr);
 
@@ -208,12 +226,17 @@
 	    if (exit_attribute_mode) {
 		doPut(exit_attribute_mode);
 	    } else {
-		if (!SP || SP->_use_rmul) {
+		if (!SP_PARM || SP_PARM->_use_rmul) {
 		    TurnOff(A_UNDERLINE, exit_underline_mode);
 		}
-		if (!SP || SP->_use_rmso) {
+		if (!SP_PARM || SP_PARM->_use_rmso) {
 		    TurnOff(A_STANDOUT, exit_standout_mode);
 		}
+#if USE_ITALIC
+		if (!SP_PARM || SP_PARM->_use_ritm) {
+		    TurnOff(A_ITALIC, exit_italics_mode);
+		}
+#endif
 	    }
 	    PreviousAttr &= ALL_BUT_COLOR;
 	}
@@ -222,18 +245,29 @@
     } 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);
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    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;
 	}
+#if USE_ITALIC
+	if (!SP_PARM || SP_PARM->_use_ritm) {
+	    if (turn_on & A_ITALIC) {
+		TurnOn(A_ITALIC, enter_italics_mode);
+	    } else if (turn_off & A_ITALIC) {
+		TurnOff(A_ITALIC, exit_italics_mode);
+	    }
+	}
+#endif
 	SetColorsIf((pair != 0) || fix_pair0, PreviousAttr);
     } else {
 
@@ -241,14 +275,18 @@
 
 	TurnOff(A_ALTCHARSET, exit_alt_charset_mode);
 
-	if (!SP || SP->_use_rmul) {
+	if (!SP_PARM || SP_PARM->_use_rmul) {
 	    TurnOff(A_UNDERLINE, exit_underline_mode);
 	}
 
-	if (!SP || SP->_use_rmso) {
+	if (!SP_PARM || SP_PARM->_use_rmso) {
 	    TurnOff(A_STANDOUT, exit_standout_mode);
 	}
-
+#if USE_ITALIC
+	if (!SP_PARM || SP_PARM->_use_ritm) {
+	    TurnOff(A_ITALIC, exit_italics_mode);
+	}
+#endif
 	if (turn_off && exit_attribute_mode) {
 	    doPut(exit_attribute_mode);
 	    turn_on |= (newmode & ALL_BUT_COLOR);
@@ -267,6 +305,9 @@
 	TurnOn(A_PROTECT,	enter_protected_mode);
 	TurnOn(A_INVIS,		enter_secure_mode);
 	TurnOn(A_UNDERLINE,	enter_underline_mode);
+#if USE_ITALIC
+	TurnOn(A_ITALIC,	enter_italics_mode);
+#endif
 #if USE_WIDEC_SUPPORT
 	TurnOn(A_HORIZONTAL,	enter_horizontal_hl_mode);
 	TurnOn(A_LEFT,		enter_left_hl_mode);
@@ -282,57 +323,98 @@
     if (reverse)
 	newmode |= A_REVERSE;
 
-    if (SP)
-	SetAttr(SCREEN_ATTRS(SP), newmode);
+    if (SP_PARM)
+	SetAttr(SCREEN_ATTRS(SP_PARM), newmode);
     else
 	PreviousAttr = newmode;
 
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+vidputs(chtype newmode, NCURSES_OUTC outc)
+{
+    SetSafeOutcWrapper(outc);
+    return NCURSES_SP_NAME(vidputs) (CURRENT_SCREEN,
+				     newmode,
+				     _nc_outc_wrapper);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(vidattr) (NCURSES_SP_DCLx chtype newmode)
+{
+    T((T_CALLED("vidattr(%p,%s)"), (void *) SP_PARM, _traceattr(newmode)));
+    returnCode(NCURSES_SP_NAME(vidputs) (NCURSES_SP_ARGx
+					 newmode,
+					 NCURSES_SP_NAME(_nc_putchar)));
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 vidattr(chtype newmode)
 {
-    T((T_CALLED("vidattr(%s)"), _traceattr(newmode)));
-
-    returnCode(vidputs(newmode, _nc_outch));
+    return NCURSES_SP_NAME(vidattr) (CURRENT_SCREEN, newmode);
 }
+#endif
 
 NCURSES_EXPORT(chtype)
-termattrs(void)
+NCURSES_SP_NAME(termattrs) (NCURSES_SP_DCL0)
 {
     chtype attrs = A_NORMAL;
 
-    T((T_CALLED("termattrs()")));
-    if (enter_alt_charset_mode)
-	attrs |= A_ALTCHARSET;
+    T((T_CALLED("termattrs(%p)"), (void *) SP_PARM));
 
-    if (enter_blink_mode)
-	attrs |= A_BLINK;
+    if (HasTerminal(SP_PARM)) {
+#ifdef USE_TERM_DRIVER
+	attrs = CallDriver(SP_PARM, td_conattr);
+#else /* ! USE_TERM_DRIVER */
 
-    if (enter_bold_mode)
-	attrs |= A_BOLD;
+	if (enter_alt_charset_mode)
+	    attrs |= A_ALTCHARSET;
 
-    if (enter_dim_mode)
-	attrs |= A_DIM;
+	if (enter_blink_mode)
+	    attrs |= A_BLINK;
 
-    if (enter_reverse_mode)
-	attrs |= A_REVERSE;
+	if (enter_bold_mode)
+	    attrs |= A_BOLD;
 
-    if (enter_standout_mode)
-	attrs |= A_STANDOUT;
+	if (enter_dim_mode)
+	    attrs |= A_DIM;
 
-    if (enter_protected_mode)
-	attrs |= A_PROTECT;
+	if (enter_reverse_mode)
+	    attrs |= A_REVERSE;
 
-    if (enter_secure_mode)
-	attrs |= A_INVIS;
+	if (enter_standout_mode)
+	    attrs |= A_STANDOUT;
 
-    if (enter_underline_mode)
-	attrs |= A_UNDERLINE;
+	if (enter_protected_mode)
+	    attrs |= A_PROTECT;
 
-    if (SP->_coloron)
-	attrs |= A_COLOR;
+	if (enter_secure_mode)
+	    attrs |= A_INVIS;
 
-    returnChar(attrs);
+	if (enter_underline_mode)
+	    attrs |= A_UNDERLINE;
+
+	if (SP_PARM->_coloron)
+	    attrs |= A_COLOR;
+
+#if USE_ITALIC
+	if (enter_italics_mode)
+	    attrs |= A_ITALIC;
+#endif
+
+#endif /* USE_TERM_DRIVER */
+    }
+    returnChtype(attrs);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(chtype)
+termattrs(void)
+{
+    return NCURSES_SP_NAME(termattrs) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/tty/tty_display.h b/ncurses/tty/tty_display.h
deleted file mode 100644
index 4c45a08..0000000
--- a/ncurses/tty/tty_display.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/****************************************************************************
- * 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
deleted file mode 100644
index e520793..0000000
--- a/ncurses/tty/tty_input.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
- * 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
index 6a3a0c8..e66f716 100644
--- a/ncurses/tty/tty_update.c
+++ b/ncurses/tty/tty_update.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  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: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*-----------------------------------------------------------------
@@ -38,12 +39,16 @@
  *
  * 	The routine doupdate() and its dependents.
  * 	All physical output is concentrated here (except _nc_outch()
-  *	in lib_tputs.c).
+ *	in lib_tputs.c).
  *
  *-----------------------------------------------------------------*/
 
 #include <curses.priv.h>
 
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
 #if defined __HAIKU__ && defined __BEOS__
 #undef __BEOS__
 #endif
@@ -76,9 +81,8 @@
 #endif
 
 #include <ctype.h>
-#include <term.h>
 
-MODULE_ID("$Id: tty_update.c,v 1.246 2008/08/30 20:08:19 tom Exp $")
+MODULE_ID("$Id: tty_update.c,v 1.280 2014/08/23 19:25:18 tom Exp $")
 
 /*
  * This define controls the line-breakout optimization.  Every once in a
@@ -91,7 +95,7 @@
  */
 #define CHECK_INTERVAL	5
 
-#define FILL_BCE() (SP->_coloron && !SP->_default_color && !back_color_erase)
+#define FILL_BCE(sp) (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);
@@ -103,13 +107,23 @@
  */
 /* #define POSITION_DEBUG */
 
-static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win);
+static NCURSES_INLINE NCURSES_CH_T ClrBlank(NCURSES_SP_DCLx WINDOW *win);
+
+#if NCURSES_SP_FUNCS
+static int ClrBottom(SCREEN *, int total);
+static void ClearScreen(SCREEN *, NCURSES_CH_T blank);
+static void ClrUpdate(SCREEN *);
+static void DelChar(SCREEN *, int count);
+static void InsStr(SCREEN *, NCURSES_CH_T * line, int count);
+static void TransformLine(SCREEN *, int const lineno);
+#else
 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);
+#endif
 
 #ifdef POSITION_DEBUG
 /****************************************************************************
@@ -119,7 +133,7 @@
  ****************************************************************************/
 
 static void
-position_check(int expected_y, int expected_x, char *legend)
+position_check(NCURSES_SP_DCLx int expected_y, int expected_x, char *legend)
 /* check to see if the real cursor position matches the virtual */
 {
     char buf[20];
@@ -129,10 +143,9 @@
     if (!_nc_tracing || (expected_y < 0 && expected_x < 0))
 	return;
 
-    _nc_flush();
+    NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
     memset(buf, '\0', sizeof(buf));
-    putp("\033[6n");		/* only works on ANSI-compatibles */
-    _nc_flush();
+    NCURSES_PUTP2_FLUSH("cpr", "\033[6n");	/* only works on ANSI-compatibles */
     *(s = buf) = 0;
     do {
 	int ask = sizeof(buf) - 1 - (s - buf);
@@ -152,8 +165,12 @@
 	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);
+	    NCURSES_SP_NAME(beep) (NCURSES_SP_ARG);
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    tparm("\033[%d;%dH",
+					  expected_y + 1,
+					  expected_x + 1),
+				    1, NCURSES_SP_NAME(_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 {
@@ -172,29 +189,38 @@
  ****************************************************************************/
 
 static NCURSES_INLINE void
-GoTo(int const row, int const col)
+GoTo(NCURSES_SP_DCLx int const row, int const col)
 {
-    TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)",
-		    row, col, SP->_cursrow, SP->_curscol));
+    TR(TRACE_MOVE, ("GoTo(%p, %d, %d) from (%d, %d)",
+		    (void *) SP_PARM, row, col, SP_PARM->_cursrow, SP_PARM->_curscol));
 
-    position_check(SP->_cursrow, SP->_curscol, "GoTo");
+    position_check(NCURSES_SP_ARGx
+		   SP_PARM->_cursrow,
+		   SP_PARM->_curscol, "GoTo");
 
-    mvcur(SP->_cursrow, SP->_curscol, row, col);
-    position_check(SP->_cursrow, SP->_curscol, "GoTo2");
+    TINFO_MVCUR(NCURSES_SP_ARGx
+		SP_PARM->_cursrow,
+		SP_PARM->_curscol,
+		row, col);
+    position_check(NCURSES_SP_ARGx
+		   SP_PARM->_cursrow,
+		   SP_PARM->_curscol, "GoTo2");
 }
 
 static NCURSES_INLINE void
-PutAttrChar(CARG_CH_T ch)
+PutAttrChar(NCURSES_SP_DCLx CARG_CH_T ch)
 {
     int chlen = 1;
     NCURSES_CH_T my_ch;
+#if USE_WIDEC_SUPPORT
     PUTC_DATA;
+#endif
     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));
+		       SP_PARM->_cursrow, SP_PARM->_curscol));
 #if USE_WIDEC_SUPPORT
     /*
      * If this is not a valid character, there is nothing more to do.
@@ -224,12 +250,12 @@
 	 */
 	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)
+		|| (SP_PARM->_legacy_coding > 0 && CharOf(CHDEREF(ch)) >= 160)
+		|| (SP_PARM->_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)
+			 && SP_PARM->_acs_map != 0
+			 && SP_PARM->_acs_map[CharOfD(ch)] != 0)
 			|| (CharOfD(ch) >= 128))))) {
 	    ;
 	} else {
@@ -241,7 +267,7 @@
 #endif
 
     if ((AttrOf(attr) & A_ALTCHARSET)
-	&& SP->_acs_map != 0
+	&& SP_PARM->_acs_map != 0
 	&& CharOfD(ch) < ACS_LEN) {
 	my_ch = CHDEREF(ch);	/* work around const param */
 #if USE_WIDEC_SUPPORT
@@ -251,8 +277,13 @@
 	 * 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)]) {
+	if (SP_PARM->_screen_acs_fix
+	    && SP_PARM->_screen_acs_map[CharOf(my_ch)]) {
+	    RemAttr(attr, A_ALTCHARSET);
+	    my_ch = _nc_wacs[CharOf(my_ch)];
+	} else if (SP_PARM->_screen_unicode
+		   && !SP_PARM->_screen_acs_map[CharOf(my_ch)]
+		   && _nc_wacs[CharOf(my_ch)].chars[0]) {
 	    RemAttr(attr, A_ALTCHARSET);
 	    my_ch = _nc_wacs[CharOf(my_ch)];
 	}
@@ -265,15 +296,14 @@
 	 */
 	if (AttrOf(attr) & A_ALTCHARSET) {
 	    int j = CharOfD(ch);
-	    chtype temp = UChar(SP->_acs_map[j]);
+	    chtype temp = UChar(SP_PARM->_acs_map[j]);
 
-	    if (!(SP->_screen_acs_map[j])) {
-		RemAttr(attr, A_ALTCHARSET);
-		if (temp == 0)
-		    temp = ' ';
-	    }
-	    if (temp != 0)
+	    if (temp != 0) {
 		SetChar(my_ch, temp, AttrOf(attr));
+	    } else {
+		my_ch = CHDEREF(ch);
+		RemAttr(attr, A_ALTCHARSET);
+	    }
 	}
 	ch = CHREF(my_ch);
     }
@@ -282,28 +312,19 @@
 	ch = CHREF(tilde);
     }
 
-    UpdateAttrs(attr);
+    UpdateAttrs(SP_PARM, attr);
+    PUTC(CHDEREF(ch));
 #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
+    COUNT_OUTCHARS(1);
 #endif
-    {
-	PUTC(CHDEREF(ch), SP->_ofp);	/* macro's fastest... */
-	COUNT_OUTCHARS(1);
-    }
-    SP->_curscol += chlen;
+    SP_PARM->_curscol += chlen;
     if (char_padding) {
-	TPUTS_TRACE("char_padding");
-	putp(char_padding);
+	NCURSES_PUTP2("char_padding", char_padding);
     }
 }
 
 static bool
-check_pending(void)
+check_pending(NCURSES_SP_DCL0)
 /* check for pending input */
 {
     bool have_pending = FALSE;
@@ -313,15 +334,15 @@
      * have the refreshing slow down drastically (or stop) if there's an
      * unread character available.
      */
-    if (SP->_fifohold != 0)
+    if (SP_PARM->_fifohold != 0)
 	return FALSE;
 
-    if (SP->_checkfd >= 0) {
+    if (SP_PARM->_checkfd >= 0) {
 #if USE_FUNC_POLL
 	struct pollfd fds[1];
-	fds[0].fd = SP->_checkfd;
+	fds[0].fd = SP_PARM->_checkfd;
 	fds[0].events = POLLIN;
-	if (poll(fds, 1, 0) > 0) {
+	if (poll(fds, (size_t) 1, 0) > 0) {
 	    have_pending = TRUE;
 	}
 #elif defined(__BEOS__)
@@ -347,43 +368,50 @@
 	    ktimeout.tv_usec = 0;
 
 	FD_ZERO(&fdset);
-	FD_SET(SP->_checkfd, &fdset);
-	if (select(SP->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) {
+	FD_SET(SP_PARM->_checkfd, &fdset);
+	if (select(SP_PARM->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) {
 	    have_pending = TRUE;
 	}
 #endif
     }
     if (have_pending) {
-	SP->_fifohold = 5;
-	_nc_flush();
+	SP_PARM->_fifohold = 5;
+	NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
     }
     return FALSE;
 }
 
 /* put char at lower right corner */
 static void
-PutCharLR(const ARG_CH_T ch)
+PutCharLR(NCURSES_SP_DCLx const ARG_CH_T ch)
 {
     if (!auto_right_margin) {
 	/* we can put the char directly */
-	PutAttrChar(ch);
+	PutAttrChar(NCURSES_SP_ARGx ch);
     } else if (enter_am_mode && exit_am_mode) {
 	/* we can suppress automargin */
-	TPUTS_TRACE("exit_am_mode");
-	putp(exit_am_mode);
+	NCURSES_PUTP2("exit_am_mode", exit_am_mode);
 
-	PutAttrChar(ch);
-	SP->_curscol--;
-	position_check(SP->_cursrow, SP->_curscol, "exit_am_mode");
+	PutAttrChar(NCURSES_SP_ARGx ch);
+	SP_PARM->_curscol--;
+	position_check(NCURSES_SP_ARGx
+		       SP_PARM->_cursrow,
+		       SP_PARM->_curscol,
+		       "exit_am_mode");
 
-	TPUTS_TRACE("enter_am_mode");
-	putp(enter_am_mode);
+	NCURSES_PUTP2("enter_am_mode", 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);
+	GoTo(NCURSES_SP_ARGx
+	     screen_lines(SP_PARM) - 1,
+	     screen_columns(SP_PARM) - 2);
+	PutAttrChar(NCURSES_SP_ARGx ch);
+	GoTo(NCURSES_SP_ARGx
+	     screen_lines(SP_PARM) - 1,
+	     screen_columns(SP_PARM) - 2);
+	InsStr(NCURSES_SP_ARGx
+	       NewScreen(SP_PARM)->_line[screen_lines(SP_PARM) - 1].text +
+	       screen_columns(SP_PARM) - 2, 1);
     }
 }
 
@@ -391,7 +419,7 @@
  * Wrap the cursor position, i.e., advance to the beginning of the next line.
  */
 static void
-wrap_cursor(void)
+wrap_cursor(NCURSES_SP_DCL0)
 {
     if (eat_newline_glitch) {
 	/*
@@ -407,40 +435,47 @@
 	 * 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;
+	SP_PARM->_curscol = -1;
+	SP_PARM->_cursrow = -1;
     } else if (auto_right_margin) {
-	SP->_curscol = 0;
-	SP->_cursrow++;
+	SP_PARM->_curscol = 0;
+	SP_PARM->_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))) {
+	if (!move_standout_mode && AttrOf(SCREEN_ATTRS(SP_PARM))) {
 	    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);
+			       (unsigned long) AttrOf(SCREEN_ATTRS(SP_PARM)),
+			       _traceattr(AttrOf(SCREEN_ATTRS(SP_PARM)))));
+	    (void) VIDATTR(SP_PARM, A_NORMAL, 0);
 	}
     } else {
-	SP->_curscol--;
+	SP_PARM->_curscol--;
     }
-    position_check(SP->_cursrow, SP->_curscol, "wrap_cursor");
+    position_check(NCURSES_SP_ARGx
+		   SP_PARM->_cursrow,
+		   SP_PARM->_curscol,
+		   "wrap_cursor");
 }
 
 static NCURSES_INLINE void
-PutChar(const ARG_CH_T ch)
+PutChar(NCURSES_SP_DCLx 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_PARM->_cursrow == screen_lines(SP_PARM) - 1 &&
+	SP_PARM->_curscol == screen_columns(SP_PARM) - 1) {
+	PutCharLR(NCURSES_SP_ARGx ch);
+    } else {
+	PutAttrChar(NCURSES_SP_ARGx ch);
+    }
 
-    if (SP->_curscol >= screen_columns)
-	wrap_cursor();
+    if (SP_PARM->_curscol >= screen_columns(SP_PARM))
+	wrap_cursor(NCURSES_SP_ARG);
 
-    position_check(SP->_cursrow, SP->_curscol, "PutChar");
+    position_check(NCURSES_SP_ARGx
+		   SP_PARM->_cursrow,
+		   SP_PARM->_curscol, "PutChar");
 }
 
 /*
@@ -450,21 +485,24 @@
  * 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)
+can_clear_with(NCURSES_SP_DCLx ARG_CH_T ch)
 {
-    if (!back_color_erase && SP->_coloron) {
+    if (!back_color_erase && SP_PARM->_coloron) {
 #if NCURSES_EXT_FUNCS
 	int pair;
 
-	if (!SP->_default_color)
+	if (!SP_PARM->_default_color)
 	    return FALSE;
-	if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK)
+	if (SP_PARM->_default_fg != C_MASK || SP_PARM->_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)
+	    NCURSES_COLOR_T fg, bg;
+	    if (NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
+					       (short) pair,
+					       &fg, &bg) == ERR
+		|| (fg != C_MASK || bg != C_MASK)) {
 		return FALSE;
+	    }
 	}
 #else
 	if (AttrOfD(ch) & A_COLOR)
@@ -488,7 +526,7 @@
  * This code is optimized using ech and rep.
  */
 static int
-EmitRange(const NCURSES_CH_T * ntext, int num)
+EmitRange(NCURSES_SP_DCLx const NCURSES_CH_T * ntext, int num)
 {
     int i;
 
@@ -500,13 +538,13 @@
 	    NCURSES_CH_T ntext0;
 
 	    while (num > 1 && !CharEq(ntext[0], ntext[1])) {
-		PutChar(CHREF(ntext[0]));
+		PutChar(NCURSES_SP_ARGx CHREF(ntext[0]));
 		ntext++;
 		num--;
 	    }
 	    ntext0 = ntext[0];
 	    if (num == 1) {
-		PutChar(CHREF(ntext0));
+		PutChar(NCURSES_SP_ARGx CHREF(ntext0));
 		return 0;
 	    }
 	    runcount = 2;
@@ -523,10 +561,10 @@
 	     * 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));
+		&& runcount > SP_PARM->_ech_cost + SP_PARM->_cup_ch_cost
+		&& can_clear_with(NCURSES_SP_ARGx CHREF(ntext0))) {
+		UpdateAttrs(SP_PARM, ntext0);
+		NCURSES_PUTP2("erase_chars", TPARM_1(erase_chars, runcount));
 
 		/*
 		 * If this is the last part of the given interval,
@@ -534,27 +572,34 @@
 		 * last update on the line.
 		 */
 		if (runcount < num) {
-		    GoTo(SP->_cursrow, SP->_curscol + runcount);
+		    GoTo(NCURSES_SP_ARGx
+			 SP_PARM->_cursrow,
+			 SP_PARM->_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);
+	    } else if (repeat_char && runcount > SP_PARM->_rep_cost) {
+		bool wrap_possible = (SP_PARM->_curscol + runcount >=
+				      screen_columns(SP_PARM));
 		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;
+		UpdateAttrs(SP_PARM, ntext0);
+		NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+					TPARM_2(repeat_char,
+						CharOf(ntext0),
+						rep_count),
+					rep_count,
+					NCURSES_SP_NAME(_nc_outch));
+		SP_PARM->_curscol += rep_count;
 
 		if (wrap_possible)
-		    PutChar(CHREF(ntext0));
+		    PutChar(NCURSES_SP_ARGx CHREF(ntext0));
 	    } else {
 		for (i = 0; i < runcount; i++)
-		    PutChar(CHREF(ntext[i]));
+		    PutChar(NCURSES_SP_ARGx CHREF(ntext[i]));
 	    }
 	    ntext += runcount;
 	    num -= runcount;
@@ -563,7 +608,7 @@
     }
 
     for (i = 0; i < num; i++)
-	PutChar(CHREF(ntext[i]));
+	PutChar(NCURSES_SP_ARGx CHREF(ntext[i]));
     return 0;
 }
 
@@ -576,39 +621,46 @@
  * Returns: same as EmitRange
  */
 static int
-PutRange(const NCURSES_CH_T * otext,
+PutRange(NCURSES_SP_DCLx
+	 const NCURSES_CH_T * otext,
 	 const NCURSES_CH_T * ntext,
 	 int row,
 	 int first, int last)
 {
     int i, j, same;
+    int rc;
 
-    TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)",
-		       otext, ntext, row, first, last));
+    TR(TRACE_CHARPUT, ("PutRange(%p, %p, %p, %d, %d, %d)",
+		       (void *) SP_PARM,
+		       (const void *) otext,
+		       (const void *) ntext,
+		       row, first, last));
 
     if (otext != ntext
-	&& (last - first + 1) > SP->_inline_cost) {
+	&& (last - first + 1) > SP_PARM->_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);
+		if (same > SP_PARM->_inline_cost) {
+		    EmitRange(NCURSES_SP_ARGx ntext + first, j - same - first);
+		    GoTo(NCURSES_SP_ARGx row, first = j);
 		}
 		same = 0;
 	    }
 	}
-	i = EmitRange(ntext + first, j - same - first);
+	i = EmitRange(NCURSES_SP_ARGx 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);
+	rc = (same == 0 ? i : 1);
+    } else {
+	rc = EmitRange(NCURSES_SP_ARGx ntext + first, last - first + 1);
     }
-    return EmitRange(ntext + first, last - first + 1);
+    return rc;
 }
 
 /* leave unbracketed here so 'indent' works */
@@ -618,7 +670,7 @@
 		if_USE_SCROLL_HINTS(win->_line[row].oldindex = row)
 
 NCURSES_EXPORT(int)
-doupdate(void)
+TINFO_DOUPDATE(NCURSES_SP_DCL0)
 {
     int i;
     int nonempty;
@@ -626,30 +678,52 @@
     struct tms before, after;
 #endif /* USE_TRACE_TIMES */
 
-    T((T_CALLED("doupdate()")));
+    T((T_CALLED("_nc_tinfo:doupdate(%p)"), (void *) SP_PARM));
 
-    if (curscr == 0
-	|| newscr == 0)
+    if (SP_PARM == 0)
+	returnCode(ERR);
+
+#if !USE_REENTRANT
+    /*
+     * It is "legal" but unlikely that an application could assign a new
+     * value to one of the standard windows.  Check for that possibility
+     * and try to recover.
+     *
+     * We do not allow applications to assign new values in the reentrant
+     * model.
+     */
+#define SyncScreens(internal,exported) \
+	if (internal == 0) internal = exported; \
+	if (internal != exported) exported = internal
+
+    SyncScreens(CurScreen(SP_PARM), curscr);
+    SyncScreens(NewScreen(SP_PARM), newscr);
+    SyncScreens(StdScreen(SP_PARM), stdscr);
+#endif
+
+    if (CurScreen(SP_PARM) == 0
+	|| NewScreen(SP_PARM) == 0
+	|| StdScreen(SP_PARM) == 0)
 	returnCode(ERR);
 
 #ifdef TRACE
     if (USE_TRACEF(TRACE_UPDATE)) {
-	if (curscr->_clear)
+	if (CurScreen(SP_PARM)->_clear)
 	    _tracef("curscr is clear");
 	else
-	    _tracedump("curscr", curscr);
-	_tracedump("newscr", newscr);
+	    _tracedump("curscr", CurScreen(SP_PARM));
+	_tracedump("newscr", NewScreen(SP_PARM));
 	_nc_unlock_global(tracef);
     }
 #endif /* TRACE */
 
     _nc_signal_handler(FALSE);
 
-    if (SP->_fifohold)
-	SP->_fifohold--;
+    if (SP_PARM->_fifohold)
+	SP_PARM->_fifohold--;
 
 #if USE_SIZECHANGE
-    if (SP->_endwin || _nc_handle_sigwinch(SP)) {
+    if (SP_PARM->_endwin || _nc_handle_sigwinch(SP_PARM)) {
 	/*
 	 * This is a transparent extension:  XSI does not address it,
 	 * and applications need not know that ncurses can do it.
@@ -658,20 +732,20 @@
 	 * (this can happen in an xterm, for example), and resize the
 	 * ncurses data structures accordingly.
 	 */
-	_nc_update_screensize(SP);
+	_nc_update_screensize(SP_PARM);
     }
 #endif
 
-    if (SP->_endwin) {
+    if (SP_PARM->_endwin) {
 
 	T(("coming back from shell mode"));
-	reset_prog_mode();
+	NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
 
-	_nc_mvcur_resume();
-	_nc_screen_resume();
-	SP->_mouse_resume(SP);
+	NCURSES_SP_NAME(_nc_mvcur_resume) (NCURSES_SP_ARG);
+	NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
+	SP_PARM->_mouse_resume(SP_PARM);
 
-	SP->_endwin = FALSE;
+	SP_PARM->_endwin = FALSE;
     }
 #if USE_TRACE_TIMES
     /* zero the metering machinery */
@@ -695,11 +769,11 @@
 	int j, k;
 	attr_t rattr = A_NORMAL;
 
-	for (i = 0; i < screen_lines; i++) {
-	    for (j = 0; j < screen_columns; j++) {
+	for (i = 0; i < screen_lines(SP_PARM); i++) {
+	    for (j = 0; j < screen_columns(SP_PARM); j++) {
 		bool failed = FALSE;
-		NCURSES_CH_T *thisline = newscr->_line[i].text;
-		attr_t thisattr = AttrOf(thisline[j]) & SP->_xmc_triggers;
+		NCURSES_CH_T *thisline = NewScreen(SP_PARM)->_line[i].text;
+		attr_t thisattr = AttrOf(thisline[j]) & SP_PARM->_xmc_triggers;
 		attr_t turnon = thisattr & ~rattr;
 
 		/* is an attribute turned on here? */
@@ -717,8 +791,8 @@
 		 * 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)) {
+#define SAFE(scr,a)	(!((a) & (scr)->_xmc_triggers))
+		if (ISBLANK(thisline[j]) && SAFE(SP_PARM, turnon)) {
 		    RemAttr(thisline[j], turnon);
 		    continue;
 		}
@@ -727,14 +801,14 @@
 		for (k = 1; k <= magic_cookie_glitch; k++) {
 		    if (j - k < 0
 			|| !ISBLANK(thisline[j - k])
-			|| !SAFE(AttrOf(thisline[j - k]))) {
+			|| !SAFE(SP_PARM, 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]))
+					 (SAFE(SP_PARM, AttrOf(thisline[j - k]))
 					  ? ""
 					  : ":unsafe")));
 			break;
@@ -745,10 +819,11 @@
 		    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) {
+		    for (m = i; m < screen_lines(SP_PARM); m++) {
+			for (; n < screen_columns(SP_PARM); n++) {
+			    attr_t testattr =
+			    AttrOf(NewScreen(SP_PARM)->_line[m].text[n]);
+			    if ((testattr & SP_PARM->_xmc_triggers) == rattr) {
 				end_onscreen = TRUE;
 				TR(TRACE_ATTRS,
 				   ("Range attributed with %s ends at (%d, %d)",
@@ -764,7 +839,8 @@
 		  foundit:;
 
 		    if (end_onscreen) {
-			NCURSES_CH_T *lastline = newscr->_line[m].text;
+			NCURSES_CH_T *lastline =
+			NewScreen(SP_PARM)->_line[m].text;
 
 			/*
 			 * If there are safely-attributed blanks at the end of
@@ -773,15 +849,15 @@
 			 */
 			while (n >= 0
 			       && ISBLANK(lastline[n])
-			       && SAFE(AttrOf(lastline[n]))) {
+			       && SAFE(SP_PARM, 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
+			    if (n + k >= screen_columns(SP_PARM)
 				|| !ISBLANK(lastline[n + k])
-				|| !SAFE(AttrOf(lastline[n + k]))) {
+				|| !SAFE(SP_PARM, AttrOf(lastline[n + k]))) {
 				failed = TRUE;
 				TR(TRACE_ATTRS,
 				   ("No room at end in %d,%d%s%s",
@@ -789,7 +865,7 @@
 				    (ISBLANK(lastline[n + k])
 				     ? ""
 				     : ":nonblank"),
-				    (SAFE(AttrOf(lastline[n + k]))
+				    (SAFE(SP_PARM, AttrOf(lastline[n + k]))
 				     ? ""
 				     : ":unsafe")));
 				break;
@@ -806,12 +882,12 @@
 			_traceattr(turnon), i, j));
 
 		    /* turn off new attributes over span */
-		    for (p = i; p < screen_lines; p++) {
-			for (; q < screen_columns; q++) {
+		    for (p = i; p < screen_lines(SP_PARM); p++) {
+			for (; q < screen_columns(SP_PARM); q++) {
 			    attr_t testattr = AttrOf(newscr->_line[p].text[q]);
-			    if ((testattr & SP->_xmc_triggers) == rattr)
+			    if ((testattr & SP_PARM->_xmc_triggers) == rattr)
 				goto foundend;
-			    RemAttr(newscr->_line[p].text[q], turnon);
+			    RemAttr(NewScreen(SP_PARM)->_line[p].text[q], turnon);
 			}
 			q = 0;
 		    }
@@ -837,7 +913,7 @@
 	/* show altered highlights after magic-cookie check */
 	if (USE_TRACEF(TRACE_UPDATE)) {
 	    _tracef("After magic-cookie check...");
-	    _tracedump("newscr", newscr);
+	    _tracedump("newscr", NewScreen(SP_PARM));
 	    _nc_unlock_global(tracef);
 	}
 #endif /* TRACE */
@@ -845,23 +921,23 @@
 #endif /* USE_XMC_SUPPORT */
 
     nonempty = 0;
-    if (curscr->_clear || newscr->_clear) {	/* force refresh ? */
-	ClrUpdate();
-	curscr->_clear = FALSE;	/* reset flag */
-	newscr->_clear = FALSE;	/* reset flag */
+    if (CurScreen(SP_PARM)->_clear || NewScreen(SP_PARM)->_clear) {	/* force refresh ? */
+	ClrUpdate(NCURSES_SP_ARG);
+	CurScreen(SP_PARM)->_clear = FALSE;	/* reset flag */
+	NewScreen(SP_PARM)->_clear = FALSE;	/* reset flag */
     } else {
 	int changedlines = CHECK_INTERVAL;
 
-	if (check_pending())
+	if (check_pending(NCURSES_SP_ARG))
 	    goto cleanup;
 
-	nonempty = min(screen_lines, newscr->_maxy + 1);
+	nonempty = min(screen_lines(SP_PARM), NewScreen(SP_PARM)->_maxy + 1);
 
-	if (SP->_scrolling) {
-	    _nc_scroll_optimize();
+	if (SP_PARM->_scrolling) {
+	    NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_ARG);
 	}
 
-	nonempty = ClrBottom(nonempty);
+	nonempty = ClrBottom(NCURSES_SP_ARGx nonempty);
 
 	TR(TRACE_UPDATE, ("Transforming lines, nonempty %d", nonempty));
 	for (i = 0; i < nonempty; i++) {
@@ -869,7 +945,7 @@
 	     * Here is our line-breakout optimization.
 	     */
 	    if (changedlines == CHECK_INTERVAL) {
-		if (check_pending())
+		if (check_pending(NCURSES_SP_ARG))
 		    goto cleanup;
 		changedlines = 0;
 	    }
@@ -880,35 +956,35 @@
 	     * 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);
+	    if (NewScreen(SP_PARM)->_line[i].firstchar != _NOCHANGE
+		|| CurScreen(SP_PARM)->_line[i].firstchar != _NOCHANGE) {
+		TransformLine(NCURSES_SP_ARGx i);
 		changedlines++;
 	    }
 
 	    /* mark line changed successfully */
-	    if (i <= newscr->_maxy) {
-		MARK_NOCHANGE(newscr, i);
+	    if (i <= NewScreen(SP_PARM)->_maxy) {
+		MARK_NOCHANGE(NewScreen(SP_PARM), i);
 	    }
-	    if (i <= curscr->_maxy) {
-		MARK_NOCHANGE(curscr, i);
+	    if (i <= CurScreen(SP_PARM)->_maxy) {
+		MARK_NOCHANGE(CurScreen(SP_PARM), i);
 	    }
 	}
     }
 
     /* put everything back in sync */
-    for (i = nonempty; i <= newscr->_maxy; i++) {
-	MARK_NOCHANGE(newscr, i);
+    for (i = nonempty; i <= NewScreen(SP_PARM)->_maxy; i++) {
+	MARK_NOCHANGE(NewScreen(SP_PARM), i);
     }
-    for (i = nonempty; i <= curscr->_maxy; i++) {
-	MARK_NOCHANGE(curscr, i);
+    for (i = nonempty; i <= CurScreen(SP_PARM)->_maxy; i++) {
+	MARK_NOCHANGE(CurScreen(SP_PARM), i);
     }
 
-    if (!newscr->_leaveok) {
-	curscr->_curx = newscr->_curx;
-	curscr->_cury = newscr->_cury;
+    if (!NewScreen(SP_PARM)->_leaveok) {
+	CurScreen(SP_PARM)->_curx = NewScreen(SP_PARM)->_curx;
+	CurScreen(SP_PARM)->_cury = NewScreen(SP_PARM)->_cury;
 
-	GoTo(curscr->_cury, curscr->_curx);
+	GoTo(NCURSES_SP_ARGx CurScreen(SP_PARM)->_cury, CurScreen(SP_PARM)->_curx);
     }
 
   cleanup:
@@ -921,10 +997,10 @@
 #if USE_XMC_SUPPORT
     if (magic_cookie_glitch != 0)
 #endif
-	UpdateAttrs(normal);
+	UpdateAttrs(SP_PARM, normal);
 
-    _nc_flush();
-    WINDOW_ATTRS(curscr) = WINDOW_ATTRS(newscr);
+    NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
+    WINDOW_ATTRS(CurScreen(SP_PARM)) = WINDOW_ATTRS(NewScreen(SP_PARM));
 
 #if USE_TRACE_TIMES
     (void) times(&after);
@@ -940,6 +1016,14 @@
     returnCode(OK);
 }
 
+#if NCURSES_SP_FUNCS && !defined(USE_TERM_DRIVER)
+NCURSES_EXPORT(int)
+doupdate(void)
+{
+    return TINFO_DOUPDATE(CURRENT_SCREEN);
+}
+#endif
+
 /*
  *	ClrBlank(win)
  *
@@ -951,14 +1035,14 @@
  *	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)
+#define BCE_BKGD(sp,win) (((win) == CurScreen(sp) ? StdScreen(sp) : (win))->_nc_bkgd)
 
 static NCURSES_INLINE NCURSES_CH_T
-ClrBlank(WINDOW *win)
+ClrBlank(NCURSES_SP_DCLx WINDOW *win)
 {
     NCURSES_CH_T blank = blankchar;
     if (back_color_erase)
-	AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS));
+	AddAttr(blank, (AttrOf(BCE_BKGD(SP_PARM, win)) & BCE_ATTRS));
     return blank;
 }
 
@@ -970,23 +1054,24 @@
 */
 
 static void
-ClrUpdate(void)
+ClrUpdate(NCURSES_SP_DCL0)
 {
-    int i;
-    NCURSES_CH_T blank = ClrBlank(stdscr);
-    int nonempty = min(screen_lines, newscr->_maxy + 1);
-
     TR(TRACE_UPDATE, (T_CALLED("ClrUpdate")));
+    if (0 != SP_PARM) {
+	int i;
+	NCURSES_CH_T blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
+	int nonempty = min(screen_lines(SP_PARM),
+			   NewScreen(SP_PARM)->_maxy + 1);
 
-    ClearScreen(blank);
+	ClearScreen(NCURSES_SP_ARGx blank);
 
-    TR(TRACE_UPDATE, ("updating screen from scratch"));
+	TR(TRACE_UPDATE, ("updating screen from scratch"));
 
-    nonempty = ClrBottom(nonempty);
+	nonempty = ClrBottom(NCURSES_SP_ARGx nonempty);
 
-    for (i = 0; i < nonempty; i++)
-	TransformLine(i);
-
+	for (i = 0; i < nonempty; i++)
+	    TransformLine(NCURSES_SP_ARGx i);
+    }
     TR(TRACE_UPDATE, (T_RETURN("")));
 }
 
@@ -997,15 +1082,16 @@
 */
 
 static void
-ClrToEOL(NCURSES_CH_T blank, bool needclear)
+ClrToEOL(NCURSES_SP_DCLx NCURSES_CH_T blank, int needclear)
 {
     int j;
 
-    if (curscr != 0
-	&& SP->_cursrow >= 0) {
-	for (j = SP->_curscol; j < screen_columns; j++) {
+    if (CurScreen(SP_PARM) != 0
+	&& SP_PARM->_cursrow >= 0) {
+	for (j = SP_PARM->_curscol; j < screen_columns(SP_PARM); j++) {
 	    if (j >= 0) {
-		NCURSES_CH_T *cp = &(curscr->_line[SP->_cursrow].text[j]);
+		NCURSES_CH_T *cp =
+		&(CurScreen(SP_PARM)->_line[SP_PARM->_cursrow].text[j]);
 
 		if (!CharEq(*cp, blank)) {
 		    *cp = blank;
@@ -1013,19 +1099,16 @@
 		}
 	    }
 	}
-    } else {
-	needclear = TRUE;
     }
 
     if (needclear) {
-	UpdateAttrs(blank);
-	TPUTS_TRACE("clr_eol");
-	if (clr_eol && SP->_el_cost <= (screen_columns - SP->_curscol)) {
-	    putp(clr_eol);
+	UpdateAttrs(SP_PARM, blank);
+	if (clr_eol && SP_PARM->_el_cost <= (screen_columns(SP_PARM) - SP_PARM->_curscol)) {
+	    NCURSES_PUTP2("clr_eol", clr_eol);
 	} else {
-	    int count = (screen_columns - SP->_curscol);
+	    int count = (screen_columns(SP_PARM) - SP_PARM->_curscol);
 	    while (count-- > 0)
-		PutChar(CHREF(blank));
+		PutChar(NCURSES_SP_ARGx CHREF(blank));
 	}
     }
 }
@@ -1037,23 +1120,31 @@
 */
 
 static void
-ClrToEOS(NCURSES_CH_T blank)
+ClrToEOS(NCURSES_SP_DCLx NCURSES_CH_T blank)
 {
     int row, col;
 
-    row = SP->_cursrow;
-    col = SP->_curscol;
+    row = SP_PARM->_cursrow;
+    col = SP_PARM->_curscol;
 
-    UpdateAttrs(blank);
+    if (row < 0)
+	row = 0;
+    if (col < 0)
+	col = 0;
+
+    UpdateAttrs(SP_PARM, blank);
     TPUTS_TRACE("clr_eos");
-    tputs(clr_eos, screen_lines - row, _nc_outch);
+    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+			    clr_eos,
+			    screen_lines(SP_PARM) - row,
+			    NCURSES_SP_NAME(_nc_outch));
 
-    while (col < screen_columns)
-	curscr->_line[row].text[col++] = blank;
+    while (col < screen_columns(SP_PARM))
+	CurScreen(SP_PARM)->_line[row].text[col++] = blank;
 
-    for (row++; row < screen_lines; row++) {
-	for (col = 0; col < screen_columns; col++)
-	    curscr->_line[row].text[col] = blank;
+    for (row++; row < screen_lines(SP_PARM); row++) {
+	for (col = 0; col < screen_columns(SP_PARM); col++)
+	    CurScreen(SP_PARM)->_line[row].text[col] = blank;
     }
 }
 
@@ -1065,26 +1156,26 @@
  *	screen, checking if each is blank, and one or more are changed.
  */
 static int
-ClrBottom(int total)
+ClrBottom(NCURSES_SP_DCLx 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];
+    int last = min(screen_columns(SP_PARM), NewScreen(SP_PARM)->_maxx + 1);
+    NCURSES_CH_T blank = NewScreen(SP_PARM)->_line[total - 1].text[last - 1];
     bool ok;
 
-    if (clr_eos && can_clear_with(CHREF(blank))) {
+    if (clr_eos && can_clear_with(NCURSES_SP_ARGx 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));
+		ok = (CharEq(NewScreen(SP_PARM)->_line[row].text[col], blank));
 	    }
 	    if (!ok)
 		break;
 
 	    for (col = 0; ok && col < last; col++) {
-		ok = (CharEq(curscr->_line[row].text[col], blank));
+		ok = (CharEq(CurScreen(SP_PARM)->_line[row].text[col], blank));
 	    }
 	    if (!ok)
 		top = row;
@@ -1092,11 +1183,11 @@
 
 	/* 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];
+	    GoTo(NCURSES_SP_ARGx top, 0);
+	    ClrToEOS(NCURSES_SP_ARGx blank);
+	    if (SP_PARM->oldhash && SP_PARM->newhash) {
+		for (row = top; row < screen_lines(SP_PARM); row++)
+		    SP_PARM->oldhash[row] = SP_PARM->newhash[row];
 	    }
 	}
     }
@@ -1105,22 +1196,22 @@
 
 #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))
+#define check_xmc_transition(sp, a, b)					\
+    ((((a)->attr ^ (b)->attr) & ~((a)->attr) & (sp)->_xmc_triggers) != 0)
+#define xmc_turn_on(sp,a,b) check_xmc_transition(sp,&(a), &(b))
 #else
-#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0)
+#define xmc_turn_on(sp,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)
+#define xmc_new(sp,r,c) NewScreen(sp)->_line[r].text[c]
+#define xmc_turn_off(sp,a,b) xmc_turn_on(sp,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().
+**	Insert/Delete Character if idcok && has_ic().
 **
 **		firstChar = position of first different character in line
 **		oLastChar = position of last different character in old line
@@ -1135,19 +1226,19 @@
 */
 
 static void
-TransformLine(int const lineno)
+TransformLine(NCURSES_SP_DCLx int const lineno)
 {
     int firstChar, oLastChar, nLastChar;
-    NCURSES_CH_T *newLine = newscr->_line[lineno].text;
-    NCURSES_CH_T *oldLine = curscr->_line[lineno].text;
+    NCURSES_CH_T *newLine = NewScreen(SP_PARM)->_line[lineno].text;
+    NCURSES_CH_T *oldLine = CurScreen(SP_PARM)->_line[lineno].text;
     int n;
     bool attrchanged = FALSE;
 
-    TR(TRACE_UPDATE, (T_CALLED("TransformLine(%d)"), lineno));
+    TR(TRACE_UPDATE, (T_CALLED("TransformLine(%p, %d)"), (void *) SP_PARM, lineno));
 
     /* copy new hash value to old one */
-    if (SP->oldhash && SP->newhash)
-	SP->oldhash[lineno] = SP->newhash[lineno];
+    if (SP_PARM->oldhash && SP_PARM->newhash)
+	SP_PARM->oldhash[lineno] = SP_PARM->newhash[lineno];
 
     /*
      * If we have colors, there is the possibility of having two color pairs
@@ -1155,19 +1246,20 @@
      * for this case, and update the old line with the new line's colors when
      * they are equivalent.
      */
-    if (SP->_coloron) {
+    if (SP_PARM->_coloron) {
 	int oldPair;
 	int newPair;
 
-	for (n = 0; n < screen_columns; n++) {
+	for (n = 0; n < screen_columns(SP_PARM); 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]) {
+		    if (oldPair < SP_PARM->_pair_limit
+			&& newPair < SP_PARM->_pair_limit
+			&& (SP_PARM->_color_pairs[oldPair] ==
+			    SP_PARM->_color_pairs[newPair])) {
 			SetPair(oldLine[n], GetPair(newLine[n]));
 		    }
 		}
@@ -1177,7 +1269,7 @@
 
     if (ceol_standout_glitch && clr_eol) {
 	firstChar = 0;
-	while (firstChar < screen_columns) {
+	while (firstChar < screen_columns(SP_PARM)) {
 	    if (!SameAttrOf(newLine[firstChar], oldLine[firstChar])) {
 		attrchanged = TRUE;
 		break;
@@ -1189,9 +1281,13 @@
     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));
+	GoTo(NCURSES_SP_ARGx lineno, firstChar);
+	ClrToEOL(NCURSES_SP_ARGx
+		 ClrBlank(NCURSES_SP_ARGx
+			  CurScreen(SP_PARM)), FALSE);
+	PutRange(NCURSES_SP_ARGx
+		 oldLine, newLine, lineno, 0,
+		 screen_columns(SP_PARM) - 1);
 #if USE_XMC_SUPPORT
 
 	/*
@@ -1206,8 +1302,8 @@
 	 * following operation.
 	 */
     } else if (magic_cookie_glitch > 0) {
-	GoTo(lineno, firstChar);
-	for (n = 0; n < screen_columns; n++) {
+	GoTo(NCURSES_SP_ARGx lineno, firstChar);
+	for (n = 0; n < screen_columns(SP_PARM); n++) {
 	    int m = n + magic_cookie_glitch;
 
 	    /* check for turn-on:
@@ -1216,26 +1312,30 @@
 	     */
 	    if (ISBLANK(newLine[n])
 		&& ((n > 0
-		     && xmc_turn_on(newLine[n - 1], newLine[n]))
+		     && xmc_turn_on(SP_PARM, newLine[n - 1], newLine[n]))
 		    || (n == 0
 			&& lineno > 0
-			&& xmc_turn_on(xmc_new(lineno - 1, screen_columns - 1),
+			&& xmc_turn_on(SP_PARM,
+				       xmc_new(SP_PARM, lineno - 1,
+					       screen_columns(SP_PARM) - 1),
 				       newLine[n])))) {
 		n = m;
 	    }
 
-	    PutChar(CHREF(newLine[n]));
+	    PutChar(NCURSES_SP_ARGx 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 + 1 < screen_columns(SP_PARM)
+		     && xmc_turn_off(SP_PARM, newLine[n], newLine[n + 1]))
+		    || (n + 1 >= screen_columns(SP_PARM)
+			&& lineno + 1 < screen_lines(SP_PARM)
+			&& xmc_turn_off(SP_PARM,
+					newLine[n],
+					xmc_new(SP_PARM, lineno + 1, 0))))) {
 		n = m;
 	    }
 
@@ -1246,38 +1346,40 @@
 
 	/* it may be cheap to clear leading whitespace with clr_bol */
 	blank = newLine[0];
-	if (clr_bol && can_clear_with(CHREF(blank))) {
+	if (clr_bol && can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
 	    int oFirstChar, nFirstChar;
 
-	    for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++)
+	    for (oFirstChar = 0;
+		 oFirstChar < screen_columns(SP_PARM);
+		 oFirstChar++)
 		if (!CharEq(oldLine[oFirstChar], blank))
 		    break;
-	    for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++)
+	    for (nFirstChar = 0;
+		 nFirstChar < screen_columns(SP_PARM);
+		 nFirstChar++)
 		if (!CharEq(newLine[nFirstChar], blank))
 		    break;
 
 	    if (nFirstChar == oFirstChar) {
 		firstChar = nFirstChar;
 		/* find the first differing character */
-		while (firstChar < screen_columns
+		while (firstChar < screen_columns(SP_PARM)
 		       && 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);
+		if (SP_PARM->_el1_cost < nFirstChar - oFirstChar) {
+		    if (nFirstChar >= screen_columns(SP_PARM)
+			&& SP_PARM->_el_cost <= SP_PARM->_el1_cost) {
+			GoTo(NCURSES_SP_ARGx lineno, 0);
+			UpdateAttrs(SP_PARM, blank);
+			NCURSES_PUTP2("clr_eol", clr_eol);
 		    } else {
-			GoTo(lineno, nFirstChar - 1);
-			UpdateAttrs(blank);
-			TPUTS_TRACE("clr_bol");
-			putp(clr_bol);
+			GoTo(NCURSES_SP_ARGx lineno, nFirstChar - 1);
+			UpdateAttrs(SP_PARM, blank);
+			NCURSES_PUTP2("clr_bol", clr_bol);
 		    }
 
 		    while (firstChar < nFirstChar)
@@ -1286,64 +1388,81 @@
 	    }
 	} else {
 	    /* find the first differing character */
-	    while (firstChar < screen_columns
+	    while (firstChar < screen_columns(SP_PARM)
 		   && CharEq(newLine[firstChar], oldLine[firstChar]))
 		firstChar++;
 	}
 	/* if there wasn't one, we're done */
-	if (firstChar >= screen_columns) {
+	if (firstChar >= screen_columns(SP_PARM)) {
 	    TR(TRACE_UPDATE, (T_RETURN("")));
 	    return;
 	}
 
-	blank = newLine[screen_columns - 1];
+	blank = newLine[screen_columns(SP_PARM) - 1];
 
-	if (!can_clear_with(CHREF(blank))) {
+	if (!can_clear_with(NCURSES_SP_ARGx CHREF(blank))) {
 	    /* find the last differing character */
-	    nLastChar = screen_columns - 1;
+	    nLastChar = screen_columns(SP_PARM) - 1;
 
 	    while (nLastChar > firstChar
 		   && CharEq(newLine[nLastChar], oldLine[nLastChar]))
 		nLastChar--;
 
 	    if (nLastChar >= firstChar) {
-		GoTo(lineno, firstChar);
-		PutRange(oldLine, newLine, lineno, firstChar, nLastChar);
+		GoTo(NCURSES_SP_ARGx lineno, firstChar);
+		PutRange(NCURSES_SP_ARGx
+			 oldLine,
+			 newLine,
+			 lineno,
+			 firstChar,
+			 nLastChar);
 		memcpy(oldLine + firstChar,
 		       newLine + firstChar,
-		       (nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T));
+		       (unsigned) (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;
+	oLastChar = screen_columns(SP_PARM) - 1;
 	while (oLastChar > firstChar && CharEq(oldLine[oLastChar], blank))
 	    oLastChar--;
 
 	/* find last non-blank character on new line */
-	nLastChar = screen_columns - 1;
+	nLastChar = screen_columns(SP_PARM) - 1;
 	while (nLastChar > firstChar && CharEq(newLine[nLastChar], blank))
 	    nLastChar--;
 
 	if ((nLastChar == firstChar)
-	    && (SP->_el_cost < (oLastChar - nLastChar))) {
-	    GoTo(lineno, firstChar);
+	    && (SP_PARM->_el_cost < (oLastChar - nLastChar))) {
+	    GoTo(NCURSES_SP_ARGx lineno, firstChar);
 	    if (!CharEq(newLine[firstChar], blank))
-		PutChar(CHREF(newLine[firstChar]));
-	    ClrToEOL(blank, FALSE);
+		PutChar(NCURSES_SP_ARGx CHREF(newLine[firstChar]));
+	    ClrToEOL(NCURSES_SP_ARGx 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);
+		       || !(SP_PARM->_nc_sp_idcok
+			    && NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG)))) {
+	    GoTo(NCURSES_SP_ARGx lineno, firstChar);
+	    if ((oLastChar - nLastChar) > SP_PARM->_el_cost) {
+		if (PutRange(NCURSES_SP_ARGx
+			     oldLine,
+			     newLine,
+			     lineno,
+			     firstChar,
+			     nLastChar)) {
+		    GoTo(NCURSES_SP_ARGx lineno, nLastChar + 1);
+		}
+		ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
 	    } else {
 		n = max(nLastChar, oLastChar);
-		PutRange(oldLine, newLine, lineno, firstChar, n);
+		PutRange(NCURSES_SP_ARGx
+			 oldLine,
+			 newLine,
+			 lineno,
+			 firstChar,
+			 n);
 	    }
 	} else {
 	    int nLastNonblank = nLastChar;
@@ -1364,33 +1483,52 @@
 
 	    n = min(oLastChar, nLastChar);
 	    if (n >= firstChar) {
-		GoTo(lineno, firstChar);
-		PutRange(oldLine, newLine, lineno, firstChar, n);
+		GoTo(NCURSES_SP_ARGx lineno, firstChar);
+		PutRange(NCURSES_SP_ARGx
+			 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;
+		if (n) {
+		    while (isWidecExt(newLine[n + 1]) && n) {
+			--n;
+			--oLastChar;	/* increase cost */
+		    }
+		} else if (n >= firstChar &&
+			   isWidecBase(newLine[n])) {
+		    while (isWidecExt(newLine[n + 1])) {
+			++n;
+			++oLastChar;	/* decrease cost */
+		    }
 		}
 #endif
-		GoTo(lineno, n + 1);
+		GoTo(NCURSES_SP_ARGx lineno, n + 1);
 		if ((nLastChar < nLastNonblank)
-		    || InsCharCost(nLastChar - oLastChar) > (m - n)) {
-		    PutRange(oldLine, newLine, lineno, n + 1, m);
+		    || InsCharCost(SP_PARM, nLastChar - oLastChar) > (m - n)) {
+		    PutRange(NCURSES_SP_ARGx
+			     oldLine,
+			     newLine,
+			     lineno,
+			     n + 1,
+			     m);
 		} else {
-		    InsStr(&newLine[n + 1], nLastChar - oLastChar);
+		    InsStr(NCURSES_SP_ARGx &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);
+		GoTo(NCURSES_SP_ARGx lineno, n + 1);
+		if (DelCharCost(SP_PARM, oLastChar - nLastChar)
+		    > SP_PARM->_el_cost + nLastNonblank - (n + 1)) {
+		    if (PutRange(NCURSES_SP_ARGx oldLine, newLine, lineno,
+				 n + 1, nLastNonblank)) {
+			GoTo(NCURSES_SP_ARGx lineno, nLastNonblank + 1);
+		    }
+		    ClrToEOL(NCURSES_SP_ARGx blank, FALSE);
 		} else {
 		    /*
 		     * The delete-char sequence will
@@ -1400,18 +1538,18 @@
 		     * setting the video attributes from
 		     * the last character on the row.
 		     */
-		    UpdateAttrs(blank);
-		    DelChar(oLastChar - nLastChar);
+		    UpdateAttrs(SP_PARM, blank);
+		    DelChar(NCURSES_SP_ARGx oLastChar - nLastChar);
 		}
 	    }
 	}
     }
 
     /* update the code's internal representation */
-    if (screen_columns > firstChar)
+    if (screen_columns(SP_PARM) > firstChar)
 	memcpy(oldLine + firstChar,
 	       newLine + firstChar,
-	       (screen_columns - firstChar) * sizeof(NCURSES_CH_T));
+	       (unsigned) (screen_columns(SP_PARM) - firstChar) * sizeof(NCURSES_CH_T));
     TR(TRACE_UPDATE, (T_RETURN("")));
     return;
 }
@@ -1424,7 +1562,7 @@
 */
 
 static void
-ClearScreen(NCURSES_CH_T blank)
+ClearScreen(NCURSES_SP_DCLx NCURSES_CH_T blank)
 {
     int i, j;
     bool fast_clear = (clear_screen || clr_eos || clr_eol);
@@ -1432,9 +1570,13 @@
     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 (SP_PARM->_coloron
+	&& !SP_PARM->_default_color) {
+	NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx
+				       (short) GET_SCREEN_PAIR(SP_PARM),
+				       0,
+				       FALSE,
+				       NCURSES_SP_NAME(_nc_outch));
 	if (!back_color_erase) {
 	    fast_clear = FALSE;
 	}
@@ -1443,42 +1585,44 @@
 
     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");
+	    UpdateAttrs(SP_PARM, blank);
+	    NCURSES_PUTP2("clear_screen", clear_screen);
+	    SP_PARM->_cursrow = SP_PARM->_curscol = 0;
+	    position_check(NCURSES_SP_ARGx
+			   SP_PARM->_cursrow,
+			   SP_PARM->_curscol,
+			   "ClearScreen");
 	} else if (clr_eos) {
-	    SP->_cursrow = SP->_curscol = -1;
-	    GoTo(0, 0);
-
-	    UpdateAttrs(blank);
+	    SP_PARM->_cursrow = SP_PARM->_curscol = -1;
+	    GoTo(NCURSES_SP_ARGx 0, 0);
+	    UpdateAttrs(SP_PARM, blank);
 	    TPUTS_TRACE("clr_eos");
-	    tputs(clr_eos, screen_lines, _nc_outch);
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    clr_eos,
+				    screen_lines(SP_PARM),
+				    NCURSES_SP_NAME(_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);
+	    SP_PARM->_cursrow = SP_PARM->_curscol = -1;
+	    UpdateAttrs(SP_PARM, blank);
+	    for (i = 0; i < screen_lines(SP_PARM); i++) {
+		GoTo(NCURSES_SP_ARGx i, 0);
+		NCURSES_PUTP2("clr_eol", clr_eol);
 	    }
-	    GoTo(0, 0);
+	    GoTo(NCURSES_SP_ARGx 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));
+	UpdateAttrs(SP_PARM, blank);
+	for (i = 0; i < screen_lines(SP_PARM); i++) {
+	    GoTo(NCURSES_SP_ARGx i, 0);
+	    for (j = 0; j < screen_columns(SP_PARM); j++)
+		PutChar(NCURSES_SP_ARGx CHREF(blank));
 	}
-	GoTo(0, 0);
+	GoTo(NCURSES_SP_ARGx 0, 0);
     }
 
-    for (i = 0; i < screen_lines; i++) {
-	for (j = 0; j < screen_columns; j++)
-	    curscr->_line[i].text[j] = blank;
+    for (i = 0; i < screen_lines(SP_PARM); i++) {
+	for (j = 0; j < screen_columns(SP_PARM); j++)
+	    CurScreen(SP_PARM)->_line[i].text[j] = blank;
     }
 
     TR(TRACE_UPDATE, ("screen cleared"));
@@ -1492,49 +1636,51 @@
 */
 
 static void
-InsStr(NCURSES_CH_T * line, int count)
+InsStr(NCURSES_SP_DCLx NCURSES_CH_T * line, int count)
 {
-    TR(TRACE_UPDATE, ("InsStr(%p,%d) called", line, count));
+    TR(TRACE_UPDATE, ("InsStr(%p, %p,%d) called",
+		      (void *) SP_PARM,
+		      (void *) 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);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_1(parm_ich, count),
+				count,
+				NCURSES_SP_NAME(_nc_outch));
 	while (count) {
-	    PutAttrChar(CHREF(*line));
+	    PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
 	    line++;
 	    count--;
 	}
     } else if (enter_insert_mode && exit_insert_mode) {
-	TPUTS_TRACE("enter_insert_mode");
-	putp(enter_insert_mode);
+	NCURSES_PUTP2("enter_insert_mode", enter_insert_mode);
 	while (count) {
-	    PutAttrChar(CHREF(*line));
+	    PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
 	    if (insert_padding) {
-		TPUTS_TRACE("insert_padding");
-		putp(insert_padding);
+		NCURSES_PUTP2("insert_padding", insert_padding);
 	    }
 	    line++;
 	    count--;
 	}
-	TPUTS_TRACE("exit_insert_mode");
-	putp(exit_insert_mode);
+	NCURSES_PUTP2("exit_insert_mode", exit_insert_mode);
     } else {
 	while (count) {
-	    TPUTS_TRACE("insert_character");
-	    putp(insert_character);
-	    PutAttrChar(CHREF(*line));
+	    NCURSES_PUTP2("insert_character", insert_character);
+	    PutAttrChar(NCURSES_SP_ARGx CHREF(*line));
 	    if (insert_padding) {
-		TPUTS_TRACE("insert_padding");
-		putp(insert_padding);
+		NCURSES_PUTP2("insert_padding", insert_padding);
 	    }
 	    line++;
 	    count--;
 	}
     }
-    position_check(SP->_cursrow, SP->_curscol, "InsStr");
+    position_check(NCURSES_SP_ARGx
+		   SP_PARM->_cursrow,
+		   SP_PARM->_curscol, "InsStr");
 }
 
 /*
@@ -1545,22 +1691,24 @@
 */
 
 static void
-DelChar(int count)
+DelChar(NCURSES_SP_DCLx int count)
 {
     int n;
 
-    TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%ld,%ld)",
-		      count,
-		      (long) newscr->_cury,
-		      (long) newscr->_curx));
+    TR(TRACE_UPDATE, ("DelChar(%p, %d) called, position = (%ld,%ld)",
+		      (void *) SP_PARM, count,
+		      (long) NewScreen(SP_PARM)->_cury,
+		      (long) NewScreen(SP_PARM)->_curx));
 
     if (parm_dch) {
 	TPUTS_TRACE("parm_dch");
-	tputs(TPARM_1(parm_dch, count), count, _nc_outch);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_1(parm_dch, count),
+				count,
+				NCURSES_SP_NAME(_nc_outch));
     } else {
 	for (n = 0; n < count; n++) {
-	    TPUTS_TRACE("delete_character");
-	    putp(delete_character);
+	    NCURSES_PUTP2("delete_character", delete_character);
 	}
     }
 }
@@ -1599,54 +1747,62 @@
 
 /* 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)
+scroll_csr_forward(NCURSES_SP_DCLx
+		   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);
+	GoTo(NCURSES_SP_ARGx bot, 0);
+	UpdateAttrs(SP_PARM, blank);
+	NCURSES_PUTP2("scroll_forward", scroll_forward);
     } else if (n == 1 && delete_line && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
-	TPUTS_TRACE("delete_line");
-	putp(delete_line);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
+	NCURSES_PUTP2("delete_line", delete_line);
     } else if (parm_index && top == miny && bot == maxy) {
-	GoTo(bot, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx bot, 0);
+	UpdateAttrs(SP_PARM, blank);
 	TPUTS_TRACE("parm_index");
-	tputs(TPARM_2(parm_index, n, 0), n, _nc_outch);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_2(parm_index, n, 0),
+				n,
+				NCURSES_SP_NAME(_nc_outch));
     } else if (parm_delete_line && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
 	TPUTS_TRACE("parm_delete_line");
-	tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_2(parm_delete_line, n, 0),
+				n,
+				NCURSES_SP_NAME(_nc_outch));
     } else if (scroll_forward && top == miny && bot == maxy) {
-	GoTo(bot, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx bot, 0);
+	UpdateAttrs(SP_PARM, blank);
 	for (i = 0; i < n; i++) {
-	    TPUTS_TRACE("scroll_forward");
-	    putp(scroll_forward);
+	    NCURSES_PUTP2("scroll_forward", scroll_forward);
 	}
     } else if (delete_line && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
 	for (i = 0; i < n; i++) {
-	    TPUTS_TRACE("delete_line");
-	    putp(delete_line);
+	    NCURSES_PUTP2("delete_line", delete_line);
 	}
     } else
 	return ERR;
 
 #if NCURSES_EXT_FUNCS
-    if (FILL_BCE()) {
+    if (FILL_BCE(SP_PARM)) {
 	int j;
 	for (i = 0; i < n; i++) {
-	    GoTo(bot - i, 0);
-	    for (j = 0; j < screen_columns; j++)
-		PutChar(CHREF(blank));
+	    GoTo(NCURSES_SP_ARGx bot - i, 0);
+	    for (j = 0; j < screen_columns(SP_PARM); j++)
+		PutChar(NCURSES_SP_ARGx CHREF(blank));
 	}
     }
 #endif
@@ -1656,55 +1812,62 @@
 /* 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,
+scroll_csr_backward(NCURSES_SP_DCLx
+		    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);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
+	NCURSES_PUTP2("scroll_reverse", scroll_reverse);
     } else if (n == 1 && insert_line && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
-	TPUTS_TRACE("insert_line");
-	putp(insert_line);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
+	NCURSES_PUTP2("insert_line", insert_line);
     } else if (parm_rindex && top == miny && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
 	TPUTS_TRACE("parm_rindex");
-	tputs(TPARM_2(parm_rindex, n, 0), n, _nc_outch);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_2(parm_rindex, n, 0),
+				n,
+				NCURSES_SP_NAME(_nc_outch));
     } else if (parm_insert_line && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
 	TPUTS_TRACE("parm_insert_line");
-	tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_2(parm_insert_line, n, 0),
+				n,
+				NCURSES_SP_NAME(_nc_outch));
     } else if (scroll_reverse && top == miny && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
 	for (i = 0; i < n; i++) {
-	    TPUTS_TRACE("scroll_reverse");
-	    putp(scroll_reverse);
+	    NCURSES_PUTP2("scroll_reverse", scroll_reverse);
 	}
     } else if (insert_line && bot == maxy) {
-	GoTo(top, 0);
-	UpdateAttrs(blank);
+	GoTo(NCURSES_SP_ARGx top, 0);
+	UpdateAttrs(SP_PARM, blank);
 	for (i = 0; i < n; i++) {
-	    TPUTS_TRACE("insert_line");
-	    putp(insert_line);
+	    NCURSES_PUTP2("insert_line", insert_line);
 	}
     } else
 	return ERR;
 
 #if NCURSES_EXT_FUNCS
-    if (FILL_BCE()) {
+    if (FILL_BCE(SP_PARM)) {
 	int j;
 	for (i = 0; i < n; i++) {
-	    GoTo(top + i, 0);
-	    for (j = 0; j < screen_columns; j++)
-		PutChar(CHREF(blank));
+	    GoTo(NCURSES_SP_ARGx top + i, 0);
+	    for (j = 0; j < screen_columns(SP_PARM); j++)
+		PutChar(NCURSES_SP_ARGx CHREF(blank));
 	}
     }
 #endif
@@ -1714,40 +1877,42 @@
 /* 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)
+scroll_idl(NCURSES_SP_DCLx 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);
+    GoTo(NCURSES_SP_ARGx del, 0);
+    UpdateAttrs(SP_PARM, blank);
     if (n == 1 && delete_line) {
-	TPUTS_TRACE("delete_line");
-	putp(delete_line);
+	NCURSES_PUTP2("delete_line", delete_line);
     } else if (parm_delete_line) {
 	TPUTS_TRACE("parm_delete_line");
-	tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_2(parm_delete_line, n, 0),
+				n,
+				NCURSES_SP_NAME(_nc_outch));
     } else {			/* if (delete_line) */
 	for (i = 0; i < n; i++) {
-	    TPUTS_TRACE("delete_line");
-	    putp(delete_line);
+	    NCURSES_PUTP2("delete_line", delete_line);
 	}
     }
 
-    GoTo(ins, 0);
-    UpdateAttrs(blank);
+    GoTo(NCURSES_SP_ARGx ins, 0);
+    UpdateAttrs(SP_PARM, blank);
     if (n == 1 && insert_line) {
-	TPUTS_TRACE("insert_line");
-	putp(insert_line);
+	NCURSES_PUTP2("insert_line", insert_line);
     } else if (parm_insert_line) {
 	TPUTS_TRACE("parm_insert_line");
-	tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch);
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				TPARM_2(parm_insert_line, n, 0),
+				n,
+				NCURSES_SP_NAME(_nc_outch));
     } else {			/* if (insert_line) */
 	for (i = 0; i < n; i++) {
-	    TPUTS_TRACE("insert_line");
-	    putp(insert_line);
+	    NCURSES_PUTP2("insert_line", insert_line);
 	}
     }
 
@@ -1763,15 +1928,25 @@
  * save/restore cursor capabilities if the terminal has them.
  */
 NCURSES_EXPORT(int)
-_nc_scrolln(int n, int top, int bot, int maxy)
+NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_DCLx
+			      int n,
+			      int top,
+			      int bot,
+			      int maxy)
 /* scroll region from top to bot by n lines */
 {
-    NCURSES_CH_T blank = ClrBlank(stdscr);
+    NCURSES_CH_T blank;
     int i;
     bool cursor_saved = FALSE;
     int res;
 
-    TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy));
+    TR(TRACE_MOVE, ("_nc_scrolln(%p, %d, %d, %d, %d)",
+		    (void *) SP_PARM, n, top, bot, maxy));
+
+    if (!IsValidScreen(SP_PARM))
+	return (ERR);
+
+    blank = ClrBlank(NCURSES_SP_ARGx StdScreen(SP_PARM));
 
 #if USE_XMC_SUPPORT
     /*
@@ -1787,34 +1962,32 @@
 	 * 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);
+	res = scroll_csr_forward(NCURSES_SP_ARGx 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))
+		 && (SP_PARM->_cursrow == bot || SP_PARM->_cursrow == bot - 1))
 		&& save_cursor && restore_cursor) {
 		cursor_saved = TRUE;
-		TPUTS_TRACE("save_cursor");
-		putp(save_cursor);
+		NCURSES_PUTP2("save_cursor", save_cursor);
 	    }
-	    TPUTS_TRACE("change_scroll_region");
-	    putp(TPARM_2(change_scroll_region, top, bot));
+	    NCURSES_PUTP2("change_scroll_region",
+			  TPARM_2(change_scroll_region, top, bot));
 	    if (cursor_saved) {
-		TPUTS_TRACE("restore_cursor");
-		putp(restore_cursor);
+		NCURSES_PUTP2("restore_cursor", restore_cursor);
 	    } else {
-		SP->_cursrow = SP->_curscol = -1;
+		SP_PARM->_cursrow = SP_PARM->_curscol = -1;
 	    }
 
-	    res = scroll_csr_forward(n, top, bot, top, bot, blank);
+	    res = scroll_csr_forward(NCURSES_SP_ARGx n, top, bot, top, bot, blank);
 
-	    TPUTS_TRACE("change_scroll_region");
-	    putp(TPARM_2(change_scroll_region, 0, maxy));
-	    SP->_cursrow = SP->_curscol = -1;
+	    NCURSES_PUTP2("change_scroll_region",
+			  TPARM_2(change_scroll_region, 0, maxy));
+	    SP_PARM->_cursrow = SP_PARM->_curscol = -1;
 	}
 
-	if (res == ERR && _nc_idlok)
-	    res = scroll_idl(n, top, bot - n + 1, blank);
+	if (res == ERR && SP_PARM->_nc_sp_idlok)
+	    res = scroll_idl(NCURSES_SP_ARGx n, top, bot - n + 1, blank);
 
 	/*
 	 * Clear the newly shifted-in text.
@@ -1823,44 +1996,45 @@
 	    && (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);
+		GoTo(NCURSES_SP_ARGx bot - n + 1, 0);
+		ClrToEOS(NCURSES_SP_ARGx blank2);
 	    } else {
 		for (i = 0; i < n; i++) {
-		    GoTo(bot - i, 0);
-		    ClrToEOL(blank2, FALSE);
+		    GoTo(NCURSES_SP_ARGx bot - i, 0);
+		    ClrToEOL(NCURSES_SP_ARGx blank2, FALSE);
 		}
 	    }
 	}
 
     } else {			/* (n < 0) - scroll down (backward) */
-	res = scroll_csr_backward(-n, top, bot, 0, maxy, blank);
+	res = scroll_csr_backward(NCURSES_SP_ARGx -n, top, bot, 0, maxy, blank);
 
 	if (res == ERR && change_scroll_region) {
-	    if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top - 1)
+	    if (top != 0
+		&& (SP_PARM->_cursrow == top ||
+		    SP_PARM->_cursrow == top - 1)
 		&& save_cursor && restore_cursor) {
 		cursor_saved = TRUE;
-		TPUTS_TRACE("save_cursor");
-		putp(save_cursor);
+		NCURSES_PUTP2("save_cursor", save_cursor);
 	    }
-	    TPUTS_TRACE("change_scroll_region");
-	    putp(TPARM_2(change_scroll_region, top, bot));
+	    NCURSES_PUTP2("change_scroll_region",
+			  TPARM_2(change_scroll_region, top, bot));
 	    if (cursor_saved) {
-		TPUTS_TRACE("restore_cursor");
-		putp(restore_cursor);
+		NCURSES_PUTP2("restore_cursor", restore_cursor);
 	    } else {
-		SP->_cursrow = SP->_curscol = -1;
+		SP_PARM->_cursrow = SP_PARM->_curscol = -1;
 	    }
 
-	    res = scroll_csr_backward(-n, top, bot, top, bot, blank);
+	    res = scroll_csr_backward(NCURSES_SP_ARGx
+				      -n, top, bot, top, bot, blank);
 
-	    TPUTS_TRACE("change_scroll_region");
-	    putp(TPARM_2(change_scroll_region, 0, maxy));
-	    SP->_cursrow = SP->_curscol = -1;
+	    NCURSES_PUTP2("change_scroll_region",
+			  TPARM_2(change_scroll_region, 0, maxy));
+	    SP_PARM->_cursrow = SP_PARM->_curscol = -1;
 	}
 
-	if (res == ERR && _nc_idlok)
-	    res = scroll_idl(-n, bot + n + 1, top, blank);
+	if (res == ERR && SP_PARM->_nc_sp_idlok)
+	    res = scroll_idl(NCURSES_SP_ARGx -n, bot + n + 1, top, blank);
 
 	/*
 	 * Clear the newly shifted-in text.
@@ -1869,8 +2043,8 @@
 	    && (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);
+		GoTo(NCURSES_SP_ARGx i + top, 0);
+		ClrToEOL(NCURSES_SP_ARGx blank2, FALSE);
 	    }
 	}
     }
@@ -1878,99 +2052,165 @@
     if (res == ERR)
 	return (ERR);
 
-    _nc_scroll_window(curscr, n, top, bot, blank);
+    _nc_scroll_window(CurScreen(SP_PARM), n,
+		      (NCURSES_SIZE_T) top,
+		      (NCURSES_SIZE_T) bot,
+		      blank);
 
     /* shift hash values too - they can be reused */
-    _nc_scroll_oldhash(n, top, bot);
+    NCURSES_SP_NAME(_nc_scroll_oldhash) (NCURSES_SP_ARGx n, top, bot);
 
     return (OK);
 }
 
-NCURSES_EXPORT(void)
-_nc_screen_resume(void)
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_scrolln(int n, int top, int bot, int maxy)
 {
+    return NCURSES_SP_NAME(_nc_scrolln) (CURRENT_SCREEN, n, top, bot, maxy);
+}
+#endif
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_DCL0)
+{
+    assert(SP_PARM);
+
     /* make sure terminal is in a sane known state */
-    SetAttr(SCREEN_ATTRS(SP), A_NORMAL);
-    newscr->_clear = TRUE;
+    SetAttr(SCREEN_ATTRS(SP_PARM), A_NORMAL);
+    NewScreen(SP_PARM)->_clear = TRUE;
 
     /* reset color pairs and definitions */
-    if (SP->_coloron || SP->_color_defs)
-	_nc_reset_colors();
+    if (SP_PARM->_coloron || SP_PARM->_color_defs)
+	NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
 
     /* restore user-defined colors, if any */
-    if (SP->_color_defs < 0) {
+    if (SP_PARM->_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);
+	SP_PARM->_color_defs = -(SP_PARM->_color_defs);
+	for (n = 0; n < SP_PARM->_color_defs; ++n) {
+	    if (SP_PARM->_color_table[n].init) {
+		NCURSES_SP_NAME(init_color) (NCURSES_SP_ARGx
+					     (short) n,
+					     SP_PARM->_color_table[n].r,
+					     SP_PARM->_color_table[n].g,
+					     SP_PARM->_color_table[n].b);
 	    }
 	}
     }
 
     if (exit_attribute_mode)
-	putp(exit_attribute_mode);
+	NCURSES_PUTP2("exit_attribute_mode", exit_attribute_mode);
     else {
 	/* turn off attributes */
 	if (exit_alt_charset_mode)
-	    putp(exit_alt_charset_mode);
+	    NCURSES_PUTP2("exit_alt_charset_mode", exit_alt_charset_mode);
 	if (exit_standout_mode)
-	    putp(exit_standout_mode);
+	    NCURSES_PUTP2("exit_standout_mode", exit_standout_mode);
 	if (exit_underline_mode)
-	    putp(exit_underline_mode);
+	    NCURSES_PUTP2("exit_underline_mode", 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_PUTP2("exit_insert_mode", exit_insert_mode);
+    if (enter_am_mode && exit_am_mode) {
+	if (auto_right_margin) {
+	    NCURSES_PUTP2("enter_am_mode", enter_am_mode);
+	} else {
+	    NCURSES_PUTP2("exit_am_mode", exit_am_mode);
+	}
+    }
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_screen_resume(void)
+{
+    NCURSES_SP_NAME(_nc_screen_resume) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_screen_init) (NCURSES_SP_DCL0)
+{
+    NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(void)
 _nc_screen_init(void)
 {
-    _nc_screen_resume();
+    NCURSES_SP_NAME(_nc_screen_init) (CURRENT_SCREEN);
 }
+#endif
 
 /* wrap up screen handling */
 NCURSES_EXPORT(void)
-_nc_screen_wrap(void)
+NCURSES_SP_NAME(_nc_screen_wrap) (NCURSES_SP_DCL0)
 {
-    UpdateAttrs(normal);
+    if (SP_PARM != 0) {
+
+	UpdateAttrs(SP_PARM, 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;
+	if (SP_PARM->_coloron
+	    && !SP_PARM->_default_color) {
+	    static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+	    SP_PARM->_default_color = TRUE;
+	    NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx
+					   -1,
+					   0,
+					   FALSE,
+					   NCURSES_SP_NAME(_nc_outch));
+	    SP_PARM->_default_color = FALSE;
 
-	mvcur(SP->_cursrow, SP->_curscol, screen_lines - 1, 0);
+	    TINFO_MVCUR(NCURSES_SP_ARGx
+			SP_PARM->_cursrow,
+			SP_PARM->_curscol,
+			screen_lines(SP_PARM) - 1,
+			0);
 
-	ClrToEOL(blank, TRUE);
-    }
+	    ClrToEOL(NCURSES_SP_ARGx blank, TRUE);
+	}
 #endif
-    if (SP->_color_defs) {
-	_nc_reset_colors();
+	if (SP_PARM->_color_defs) {
+	    NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_ARG);
+	}
     }
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_screen_wrap(void)
+{
+    NCURSES_SP_NAME(_nc_screen_wrap) (CURRENT_SCREEN);
+}
+#endif
+
 #if USE_XMC_SUPPORT
 NCURSES_EXPORT(void)
-_nc_do_xmc_glitch(attr_t previous)
+NCURSES_SP_NAME(_nc_do_xmc_glitch) (NCURSES_SP_DCLx attr_t previous)
 {
-    attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP)));
+    if (SP_PARM != 0) {
+	attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP_PARM)));
 
-    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));
+	while (chg != 0) {
+	    if (chg & 1) {
+		SP_PARM->_curscol += magic_cookie_glitch;
+		if (SP_PARM->_curscol >= SP_PARM->_columns)
+		    wrap_cursor(NCURSES_SP_ARG);
+		TR(TRACE_UPDATE, ("bumped to %d,%d after cookie",
+				  SP_PARM->_cursrow, SP_PARM->_curscol));
+	    }
+	    chg >>= 1;
 	}
-	chg >>= 1;
     }
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_do_xmc_glitch(attr_t previous)
+{
+    NCURSES_SP_NAME(_nc_do_xmc_glitch) (CURRENT_SCREEN, previous);
+}
+#endif
+
 #endif /* USE_XMC_SUPPORT */
diff --git a/ncurses/unctrl.c b/ncurses/unctrl.c
deleted file mode 100644
index 563b176..0000000
--- a/ncurses/unctrl.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/* generated by MKunctrl.awk */
-
-#include <curses.priv.h>
-#include <ctype.h>
-
-#if USE_WIDEC_SUPPORT
-#if HAVE_WCTYPE_H
-#include <wctype.h>
-#endif
-#endif
-
-#undef unctrl
-
-NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *sp, chtype ch)
-{
-static const short unctrl_table[] = {
-       0,   3,   6,   9,  12,  15,  18,  21,
-      24,  27,  30,  33,  36,  39,  42,  45,
-      48,  51,  54,  57,  60,  63,  66,  69,
-      72,  75,  78,  81,  84,  87,  90,  93,
-      96,  98, 100, 102, 104, 106, 108, 110,
-     112, 114, 116, 118, 120, 122, 124, 126,
-     128, 130, 132, 134, 136, 138, 140, 142,
-     144, 146, 148, 150, 152, 154, 156, 158,
-     160, 162, 164, 166, 168, 170, 172, 174,
-     176, 178, 180, 182, 184, 186, 188, 190,
-     192, 194, 196, 198, 200, 202, 204, 206,
-     208, 210, 212, 214, 216, 218, 220, 222,
-     224, 226, 228, 230, 232, 234, 236, 238,
-     240, 242, 244, 246, 248, 250, 252, 254,
-     256, 258, 260, 262, 264, 266, 268, 270,
-     272, 274, 276, 278, 280, 282, 284, 286,
-     289, 292, 295, 298, 301, 304, 307, 310,
-     313, 316, 319, 322, 325, 328, 331, 334,
-     337, 340, 343, 346, 349, 352, 355, 358,
-     361, 364, 367, 370, 373, 376, 379, 382,
-     385, 389, 393, 397, 401, 405, 409, 413,
-     417, 421, 425, 429, 433, 437, 441, 445,
-     449, 453, 457, 461, 465, 469, 473, 477,
-     481, 485, 489, 493, 497, 501, 505, 509,
-     513, 517, 521, 525, 529, 533, 537, 541,
-     545, 549, 553, 557, 561, 565, 569, 573,
-     577, 581, 585, 589, 593, 597, 601, 605,
-     609, 613, 617, 621, 625, 629, 633, 637,
-     641, 645, 649, 653, 657, 661, 665, 669,
-     673, 677, 681, 685, 689, 693, 697, 701,
-     705, 709, 713, 717, 721, 725, 729, 733,
-     737, 741, 745, 749, 753, 757, 761, 765,};
-
-#if NCURSES_EXT_FUNCS
-static const short unctrl_c1[] = {
-     768, 770, 772, 774, 776, 778, 780, 782,
-     784, 786, 788, 790, 792, 794, 796, 798,
-     800, 802, 804, 806, 808, 810, 812, 814,
-     816, 818, 820, 822, 824, 826, 828, 830,
-     832, 834, 836, 838, 840, 842, 844, 846,
-     848, 850, 852, 854, 856, 858, 860, 862,
-     864, 866, 868, 870, 872, 874, 876, 878,
-     880, 882, 884, 886, 888, 890, 892, 894,
-     896, 898, 900, 902, 904, 906, 908, 910,
-     912, 914, 916, 918, 920, 922, 924, 926,
-     928, 930, 932, 934, 936, 938, 940, 942,
-     944, 946, 948, 950, 952, 954, 956, 958,
-     960, 962, 964, 966, 968, 970, 972, 974,
-     976, 978, 980, 982, 984, 986, 988, 990,
-     992, 994, 996, 998,1000,1002,1004,1006,
-    1008,1010,1012,1014,1016,1018,1020,1022,};
-#endif /* NCURSES_EXT_FUNCS */
-
-static const char unctrl_blob[] = 
-    "^\100\0^\101\0^\102\0^\103\0^\104\0^\105\0^\106\0^\107\0"
-    "^\110\0^\111\0^\112\0^\113\0^\114\0^\115\0^\116\0^\117\0"
-    "^\120\0^\121\0^\122\0^\123\0^\124\0^\125\0^\126\0^\127\0"
-    "^\130\0^\131\0^\132\0^\133\0^\134\0^\135\0^\136\0^\137\0"
-    "\040\0\041\0\042\0\043\0\044\0\045\0\046\0\047\0"
-    "\050\0\051\0\052\0\053\0\054\0\055\0\056\0\057\0"
-    "\060\0\061\0\062\0\063\0\064\0\065\0\066\0\067\0"
-    "\070\0\071\0\072\0\073\0\074\0\075\0\076\0\077\0"
-    "\100\0\101\0\102\0\103\0\104\0\105\0\106\0\107\0"
-    "\110\0\111\0\112\0\113\0\114\0\115\0\116\0\117\0"
-    "\120\0\121\0\122\0\123\0\124\0\125\0\126\0\127\0"
-    "\130\0\131\0\132\0\133\0\134\0\135\0\136\0\137\0"
-    "\140\0\141\0\142\0\143\0\144\0\145\0\146\0\147\0"
-    "\150\0\151\0\152\0\153\0\154\0\155\0\156\0\157\0"
-    "\160\0\161\0\162\0\163\0\164\0\165\0\166\0\167\0"
-    "\170\0\171\0\172\0\173\0\174\0\175\0\176\0^?\0"
-    "~\100\0~\101\0~\102\0~\103\0~\104\0~\105\0~\106\0~\107\0"
-    "~\110\0~\111\0~\112\0~\113\0~\114\0~\115\0~\116\0~\117\0"
-    "~\120\0~\121\0~\122\0~\123\0~\124\0~\125\0~\126\0~\127\0"
-    "~\130\0~\131\0~\132\0~\133\0~\134\0~\135\0~\136\0~\137\0"
-    "M-\040\0M-\041\0M-\042\0M-\043\0M-\044\0M-\045\0M-\046\0M-\047\0"
-    "M-\050\0M-\051\0M-\052\0M-\053\0M-\054\0M-\055\0M-\056\0M-\057\0"
-    "M-\060\0M-\061\0M-\062\0M-\063\0M-\064\0M-\065\0M-\066\0M-\067\0"
-    "M-\070\0M-\071\0M-\072\0M-\073\0M-\074\0M-\075\0M-\076\0M-\077\0"
-    "M-\100\0M-\101\0M-\102\0M-\103\0M-\104\0M-\105\0M-\106\0M-\107\0"
-    "M-\110\0M-\111\0M-\112\0M-\113\0M-\114\0M-\115\0M-\116\0M-\117\0"
-    "M-\120\0M-\121\0M-\122\0M-\123\0M-\124\0M-\125\0M-\126\0M-\127\0"
-    "M-\130\0M-\131\0M-\132\0M-\133\0M-\134\0M-\135\0M-\136\0M-\137\0"
-    "M-\140\0M-\141\0M-\142\0M-\143\0M-\144\0M-\145\0M-\146\0M-\147\0"
-    "M-\150\0M-\151\0M-\152\0M-\153\0M-\154\0M-\155\0M-\156\0M-\157\0"
-    "M-\160\0M-\161\0M-\162\0M-\163\0M-\164\0M-\165\0M-\166\0M-\167\0"
-    "M-\170\0M-\171\0M-\172\0M-\173\0M-\174\0M-\175\0M-\176\0~?\0"
-/* printable values in 128-255 range */
-    "\200\0\201\0\202\0\203\0\204\0\205\0\206\0\207\0"
-    "\210\0\211\0\212\0\213\0\214\0\215\0\216\0\217\0"
-    "\220\0\221\0\222\0\223\0\224\0\225\0\226\0\227\0"
-    "\230\0\231\0\232\0\233\0\234\0\235\0\236\0\237\0"
-    "\240\0\241\0\242\0\243\0\244\0\245\0\246\0\247\0"
-    "\250\0\251\0\252\0\253\0\254\0\255\0\256\0\257\0"
-    "\260\0\261\0\262\0\263\0\264\0\265\0\266\0\267\0"
-    "\270\0\271\0\272\0\273\0\274\0\275\0\276\0\277\0"
-    "\300\0\301\0\302\0\303\0\304\0\305\0\306\0\307\0"
-    "\310\0\311\0\312\0\313\0\314\0\315\0\316\0\317\0"
-    "\320\0\321\0\322\0\323\0\324\0\325\0\326\0\327\0"
-    "\330\0\331\0\332\0\333\0\334\0\335\0\336\0\337\0"
-    "\340\0\341\0\342\0\343\0\344\0\345\0\346\0\347\0"
-    "\350\0\351\0\352\0\353\0\354\0\355\0\356\0\357\0"
-    "\360\0\361\0\362\0\363\0\364\0\365\0\366\0\367\0"
-    "\370\0\371\0\372\0\373\0\374\0\375\0\376\0\377\0"
-;
-
-	int check = ChCharOf(ch);
-	const char *result;
-
-	if (check >= 0 && check < (int)SIZEOF(unctrl_table)) {
-#if NCURSES_EXT_FUNCS
-		if ((sp != 0)
-		 && (sp->_legacy_coding > 1)
-		 && (check >= 128)
-		 && (check < 160))
-			result = unctrl_blob + unctrl_c1[check - 128];
-		else
-#if USE_WIDEC_SUPPORT
-		if ((check >= 160)
-		 && (check < 256)
-		 && ((sp != 0)
-		  && ((sp->_legacy_coding > 0)
-		   || (sp->_legacy_coding == 0
-		       && (isprint(check) || iswprint(check))))))
-			result = unctrl_blob + unctrl_c1[check - 128];
-		else
-#else
-		if ((check >= 160)
-		 && (check < 256)
-		 && ((sp != 0)
-		  && ((sp->_legacy_coding > 0)
-		   || (sp->_legacy_coding == 0
-		       && isprint(check)))))
-			result = unctrl_blob + unctrl_c1[check - 128];
-		else
-#endif /* USE_WIDEC_SUPPORT */
-#endif /* NCURSES_EXT_FUNCS */
-			result = unctrl_blob + unctrl_table[check];
-	} else {
-		result = 0;
-	}
-	return (NCURSES_CONST char *)result;
-}
-
-NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)
-{
-	return _nc_unctrl(SP, ch);
-}
diff --git a/ncurses/wcwidth.h b/ncurses/wcwidth.h
new file mode 100644
index 0000000..e261170
--- /dev/null
+++ b/ncurses/wcwidth.h
@@ -0,0 +1,312 @@
+/*
+ * This is an implementation of wcwidth() and wcswidth() (defined in
+ * IEEE Std 1002.1-2001) for Unicode.
+ *
+ * http://www.opengroup.org/onlinepubs/007904975/functions/wcwidth.html
+ * http://www.opengroup.org/onlinepubs/007904975/functions/wcswidth.html
+ *
+ * In fixed-width output devices, Latin characters all occupy a single
+ * "cell" position of equal width, whereas ideographic CJK characters
+ * occupy two such cells. Interoperability between terminal-line
+ * applications and (teletype-style) character terminals using the
+ * UTF-8 encoding requires agreement on which character should advance
+ * the cursor by how many cell positions. No established formal
+ * standards exist at present on which Unicode character shall occupy
+ * how many cell positions on character terminals. These routines are
+ * a first attempt of defining such behavior based on simple rules
+ * applied to data provided by the Unicode Consortium.
+ *
+ * For some graphical characters, the Unicode standard explicitly
+ * defines a character-cell width via the definition of the East Asian
+ * FullWidth (F), Wide (W), Half-width (H), and Narrow (Na) classes.
+ * In all these cases, there is no ambiguity about which width a
+ * terminal shall use. For characters in the East Asian Ambiguous (A)
+ * class, the width choice depends purely on a preference of backward
+ * compatibility with either historic CJK or Western practice.
+ * Choosing single-width for these characters is easy to justify as
+ * the appropriate long-term solution, as the CJK practice of
+ * displaying these characters as double-width comes from historic
+ * implementation simplicity (8-bit encoded characters were displayed
+ * single-width and 16-bit ones double-width, even for Greek,
+ * Cyrillic, etc.) and not any typographic considerations.
+ *
+ * Much less clear is the choice of width for the Not East Asian
+ * (Neutral) class. Existing practice does not dictate a width for any
+ * of these characters. It would nevertheless make sense
+ * typographically to allocate two character cells to characters such
+ * as for instance EM SPACE or VOLUME INTEGRAL, which cannot be
+ * represented adequately with a single-width glyph. The following
+ * routines at present merely assign a single-cell width to all
+ * neutral characters, in the interest of simplicity. This is not
+ * entirely satisfactory and should be reconsidered before
+ * establishing a formal standard in this area. At the moment, the
+ * decision which Not East Asian (Neutral) characters should be
+ * represented by double-width glyphs cannot yet be answered by
+ * applying a simple rule from the Unicode database content. Setting
+ * up a proper standard for the behavior of UTF-8 character terminals
+ * will require a careful analysis not only of each Unicode character,
+ * but also of each presentation form, something the author of these
+ * routines has avoided to do so far.
+ *
+ * http://www.unicode.org/unicode/reports/tr11/
+ *
+ * Markus Kuhn -- 2007-05-26 (Unicode 5.0)
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * for any purpose and without fee is hereby granted. The author
+ * disclaims all warranties with regard to this software.
+ *
+ * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
+ */
+
+#include <wchar.h>
+
+struct interval {
+  int first;
+  int last;
+};
+
+/* auxiliary function for binary search in interval table */
+static int bisearch(wchar_t ucs, const struct interval *table, int max) {
+  int min = 0;
+  int mid;
+
+  if (ucs < table[0].first || ucs > table[max].last)
+    return 0;
+  while (max >= min) {
+    mid = (min + max) / 2;
+    if (ucs > table[mid].last)
+      min = mid + 1;
+    else if (ucs < table[mid].first)
+      max = mid - 1;
+    else
+      return 1;
+  }
+
+  return 0;
+}
+
+
+/* The following two functions define the column width of an ISO 10646
+ * character as follows:
+ *
+ *    - The null character (U+0000) has a column width of 0.
+ *
+ *    - Other C0/C1 control characters and DEL will lead to a return
+ *      value of -1.
+ *
+ *    - Non-spacing and enclosing combining characters (general
+ *      category code Mn or Me in the Unicode database) have a
+ *      column width of 0.
+ *
+ *    - SOFT HYPHEN (U+00AD) has a column width of 1.
+ *
+ *    - Other format characters (general category code Cf in the Unicode
+ *      database) and ZERO WIDTH SPACE (U+200B) have a column width of 0.
+ *
+ *    - Hangul Jamo medial vowels and final consonants (U+1160-U+11FF)
+ *      have a column width of 0.
+ *
+ *    - Spacing characters in the East Asian Wide (W) or East Asian
+ *      Full-width (F) category as defined in Unicode Technical
+ *      Report #11 have a column width of 2.
+ *
+ *    - All remaining characters (including all printable
+ *      ISO 8859-1 and WGL4 characters, Unicode control characters,
+ *      etc.) have a column width of 1.
+ *
+ * This implementation assumes that wchar_t characters are encoded
+ * in ISO 10646.
+ */
+
+int mk_wcwidth(wchar_t ucs)
+{
+  /* sorted list of non-overlapping intervals of non-spacing characters */
+  /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
+  static const struct interval combining[] = {
+    { 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 },
+    { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
+    { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 },
+    { 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 },
+    { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
+    { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
+    { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 },
+    { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D },
+    { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 },
+    { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD },
+    { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C },
+    { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D },
+    { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC },
+    { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD },
+    { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C },
+    { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D },
+    { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 },
+    { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 },
+    { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC },
+    { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
+    { 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D },
+    { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 },
+    { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E },
+    { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC },
+    { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 },
+    { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E },
+    { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 },
+    { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 },
+    { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 },
+    { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F },
+    { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 },
+    { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD },
+    { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD },
+    { 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 },
+    { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B },
+    { 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 },
+    { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 },
+    { 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF },
+    { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 },
+    { 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F },
+    { 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B },
+    { 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F },
+    { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB },
+    { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F },
+    { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 },
+    { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD },
+    { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F },
+    { 0xE0100, 0xE01EF }
+  };
+
+  /* test for 8-bit control characters */
+  if (ucs == 0)
+    return 0;
+  if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
+    return -1;
+
+  /* binary search in table of non-spacing characters */
+  if (bisearch(ucs, combining,
+	       sizeof(combining) / sizeof(struct interval) - 1))
+    return 0;
+
+  /* if we arrive here, ucs is not a combining or C0/C1 control character */
+
+  return 1 + 
+    (ucs >= 0x1100 &&
+     (ucs <= 0x115f ||                    /* Hangul Jamo init. consonants */
+      ucs == 0x2329 || ucs == 0x232a ||
+      (ucs >= 0x2e80 && ucs <= 0xa4cf &&
+       ucs != 0x303f)                     /* CJK ... Yi */
+      || (ucs >= 0xac00 && ucs <= 0xd7a3) /* Hangul Syllables */
+      || (ucs >= 0xf900 && ucs <= 0xfaff) /* CJK Compatibility Ideographs */
+      || (ucs >= 0xfe10 && ucs <= 0xfe19) /* Vertical forms */
+      || (ucs >= 0xfe30 && ucs <= 0xfe6f) /* CJK Compatibility Forms */
+      || (ucs >= 0xff00 && ucs <= 0xff60) /* Fullwidth Forms */
+      || (ucs >= 0xffe0 && ucs <= 0xffe6)
+#if !defined(SIZEOF_WCHAR_T) || (SIZEOF_WCHAR_T >= 4)
+      || (ucs >= 0x20000 && ucs <= 0x2fffd)
+      || (ucs >= 0x30000 && ucs <= 0x3fffd)
+#endif
+      ));
+}
+
+
+int mk_wcswidth(const wchar_t *pwcs, size_t n)
+{
+  int w, width = 0;
+
+  for (;*pwcs && n-- > 0; pwcs++)
+    if ((w = mk_wcwidth(*pwcs)) < 0)
+      return -1;
+    else
+      width += w;
+
+  return width;
+}
+
+
+/*
+ * The following functions are the same as mk_wcwidth() and
+ * mk_wcswidth(), except that spacing characters in the East Asian
+ * Ambiguous (A) category as defined in Unicode Technical Report #11
+ * have a column width of 2. This variant might be useful for users of
+ * CJK legacy encodings who want to migrate to UCS without changing
+ * the traditional terminal character-width behaviour. It is not
+ * otherwise recommended for general use.
+ */
+int mk_wcwidth_cjk(wchar_t ucs)
+{
+  /* sorted list of non-overlapping intervals of East Asian Ambiguous
+   * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */
+  static const struct interval ambiguous[] = {
+    { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 },
+    { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 },
+    { 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 },
+    { 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 },
+    { 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED },
+    { 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA },
+    { 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 },
+    { 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B },
+    { 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 },
+    { 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 },
+    { 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 },
+    { 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE },
+    { 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 },
+    { 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA },
+    { 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 },
+    { 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB },
+    { 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB },
+    { 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 },
+    { 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 },
+    { 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 },
+    { 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 },
+    { 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 },
+    { 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 },
+    { 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 },
+    { 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC },
+    { 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 },
+    { 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 },
+    { 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 },
+    { 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 },
+    { 0x2190, 0x2199 }, { 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 },
+    { 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 }, { 0x2200, 0x2200 },
+    { 0x2202, 0x2203 }, { 0x2207, 0x2208 }, { 0x220B, 0x220B },
+    { 0x220F, 0x220F }, { 0x2211, 0x2211 }, { 0x2215, 0x2215 },
+    { 0x221A, 0x221A }, { 0x221D, 0x2220 }, { 0x2223, 0x2223 },
+    { 0x2225, 0x2225 }, { 0x2227, 0x222C }, { 0x222E, 0x222E },
+    { 0x2234, 0x2237 }, { 0x223C, 0x223D }, { 0x2248, 0x2248 },
+    { 0x224C, 0x224C }, { 0x2252, 0x2252 }, { 0x2260, 0x2261 },
+    { 0x2264, 0x2267 }, { 0x226A, 0x226B }, { 0x226E, 0x226F },
+    { 0x2282, 0x2283 }, { 0x2286, 0x2287 }, { 0x2295, 0x2295 },
+    { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF },
+    { 0x2312, 0x2312 }, { 0x2460, 0x24E9 }, { 0x24EB, 0x254B },
+    { 0x2550, 0x2573 }, { 0x2580, 0x258F }, { 0x2592, 0x2595 },
+    { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 }, { 0x25B2, 0x25B3 },
+    { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD }, { 0x25C0, 0x25C1 },
+    { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB }, { 0x25CE, 0x25D1 },
+    { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF }, { 0x2605, 0x2606 },
+    { 0x2609, 0x2609 }, { 0x260E, 0x260F }, { 0x2614, 0x2615 },
+    { 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 },
+    { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 },
+    { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F },
+    { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xE000, 0xF8FF },
+    { 0xFFFD, 0xFFFD }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD }
+  };
+
+  /* binary search in table of non-spacing characters */
+  if (bisearch(ucs, ambiguous,
+	       sizeof(ambiguous) / sizeof(struct interval) - 1))
+    return 2;
+
+  return mk_wcwidth(ucs);
+}
+
+
+int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n)
+{
+  int w, width = 0;
+
+  for (;*pwcs && n-- > 0; pwcs++)
+    if ((w = mk_wcwidth_cjk(*pwcs)) < 0)
+      return -1;
+    else
+      width += w;
+
+  return width;
+}
diff --git a/ncurses/widechar/lib_add_wch.c b/ncurses/widechar/lib_add_wch.c
index 93b41bb..38d3130 100644
--- a/ncurses/widechar/lib_add_wch.c
+++ b/ncurses/widechar/lib_add_wch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2004,2006 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2004-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,39 +35,387 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_add_wch.c,v 1.6 2006/12/02 21:19:17 tom Exp $")
+#if HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
+
+MODULE_ID("$Id: lib_add_wch.c,v 1.12 2011/03/22 09:31:15 Petr.Pavlu Exp $")
+
+/* clone/adapt lib_addch.c */
+static const cchar_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
+ * wadd_wch().  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 cchar_t
+render_char(WINDOW *win, cchar_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);
+	}
+	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);
+}
+
+/* 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 = (NCURSES_SIZE_T) (*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);
+}
+
+static int wadd_wch_literal(WINDOW *, cchar_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)
+{
+    cchar_t blank = blankchar;
+    int save_x = win->_curx;
+    int save_y = win->_cury;
+
+    while (count-- > 0) {
+	if (wadd_wch_literal(win, blank) == ERR)
+	    break;
+    }
+    win->_curx = (NCURSES_SIZE_T) save_x;
+    win->_cury = (NCURSES_SIZE_T) save_y;
+}
+
+static int
+wadd_wch_literal(WINDOW *win, cchar_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);
+
+    /*
+     * Non-spacing characters are added to the current cell.
+     *
+     * Spacing characters that are wider than one column require some display
+     * adjustments.
+     */
+    {
+	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;
+		line = win->_line + y;
+	    }
+	    /*
+	     * 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) {
+		cchar_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.
+     */
+  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 = (NCURSES_SIZE_T) x;
+    return OK;
+}
+
+static NCURSES_INLINE int
+wadd_wch_nosync(WINDOW *win, cchar_t ch)
+/* the workhorse function -- add a character to the given window */
+{
+    NCURSES_SIZE_T x, y;
+    wchar_t *s;
+    int tabsize = 8;
+#if USE_REENTRANT
+    SCREEN *sp = _nc_screen_of(win);
+#endif
+
+    /*
+     * If we are using the alternate character set, forget about locale.
+     * Otherwise, if the locale claims the code is printable, treat it that
+     * way.
+     */
+    if ((AttrOf(ch) & A_ALTCHARSET)
+	|| iswprint((wint_t) CharOf(ch)))
+	return wadd_wch_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 (CharOf(ch)) {
+    case '\t':
+#if USE_REENTRANT
+	tabsize = *ptrTabsize(sp);
+#else
+	tabsize = TABSIZE;
+#endif
+	x = (NCURSES_SIZE_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)) {
+	    cchar_t blank = blankchar;
+	    AddAttr(blank, AttrOf(ch));
+	    while (win->_curx < x) {
+		if (wadd_wch_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:
+	if ((s = wunctrl(&ch)) != 0) {
+	    while (*s) {
+		cchar_t sch;
+		SetChar(sch, *s++, AttrOf(ch));
+		if_EXT_COLORS(SetPair(sch, GetPair(ch)));
+		if (wadd_wch_literal(win, sch) == ERR)
+		    return ERR;
+	    }
+	    return OK;
+	}
+	return ERR;
+    }
+
+    win->_curx = x;
+    win->_cury = y;
+
+    return OK;
+}
+
+/*
+ * 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)
 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)));
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"),
+				      (void *) win,
+				      _tracecchar_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;
-	}
+    if (win && (wadd_wch_nosync(win, *wch) != ERR)) {
+	_nc_synchook(win);
+	code = OK;
     }
 
     TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
@@ -77,37 +425,19 @@
 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)));
+    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"),
+				      (void *) win,
+				      _tracecchar_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);
+    if (win && (wadd_wch_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/widechar/lib_box_set.c b/ncurses/widechar/lib_box_set.c
index 35fce46..f9e701f 100644
--- a/ncurses/widechar/lib_box_set.c
+++ b/ncurses/widechar/lib_box_set.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2002-2009,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_box_set.c,v 1.4 2003/12/06 18:02:13 tom Exp $")
+MODULE_ID("$Id: lib_box_set.c,v 1.6 2011/06/25 19:02:07 Vassili.Courzakis Exp $")
 
 NCURSES_EXPORT(int)
 wborder_set(WINDOW *win,
@@ -52,8 +52,8 @@
     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,
+    T((T_CALLED("wborder_set(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
+       (void *) win,
        _tracech_t2(1, ls),
        _tracech_t2(2, rs),
        _tracech_t2(3, ts),
diff --git a/ncurses/widechar/lib_cchar.c b/ncurses/widechar/lib_cchar.c
index b4a0c37..654bebb 100644
--- a/ncurses/widechar/lib_cchar.c
+++ b/ncurses/widechar/lib_cchar.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2001-2005,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2001-2012,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,7 +35,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_cchar.c,v 1.12 2007/05/12 19:03:06 tom Exp $")
+MODULE_ID("$Id: lib_cchar.c,v 1.27 2014/02/01 22:10:42 tom Exp $")
 
 /* 
  * The SuSv2 description leaves some room for interpretation.  We'll assume wch
@@ -47,20 +47,20 @@
 setcchar(cchar_t *wcval,
 	 const wchar_t *wch,
 	 const attr_t attrs,
-	 short color_pair,
+	 NCURSES_PAIRS_T color_pair,
 	 const void *opts)
 {
-    int i;
-    int len;
+    unsigned i;
+    unsigned 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));
+		      (void *) wcval, _nc_viswbuf(wch),
+		      (unsigned long) attrs, (int) color_pair, opts));
 
-    len = wcslen(wch);
     if (opts != NULL
-	|| (len > 1 && wcwidth(wch[0]) < 0)) {
+	|| wch == NULL
+	|| ((len = (unsigned) wcslen(wch)) > 1 && wcwidth(wch[0]) < 0)) {
 	code = ERR;
     } else {
 	if (len > CCHARW_MAX)
@@ -80,7 +80,7 @@
 	memset(wcval, 0, sizeof(*wcval));
 
 	if (len != 0) {
-	    SetAttr(*wcval, attrs | COLOR_PAIR(color_pair));
+	    SetAttr(*wcval, attrs);
 	    SetPair(CHDEREF(wcval), color_pair);
 	    memcpy(&wcval->chars, wch, len * sizeof(wchar_t));
 	    TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
@@ -96,7 +96,7 @@
 getcchar(const cchar_t *wcval,
 	 wchar_t *wch,
 	 attr_t *attrs,
-	 short *color_pair,
+	 NCURSES_PAIRS_T *color_pair,
 	 void *opts)
 {
     wchar_t *wp;
@@ -104,21 +104,29 @@
     int code = ERR;
 
     TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
-		      wcval, wch, attrs, color_pair, opts));
+		      (const void *) wcval,
+		      (void *) wch,
+		      (void *) attrs,
+		      (void *) color_pair,
+		      opts));
 
-    if (opts == NULL) {
-	len = (wp = wmemchr(wcval->chars, L'\0', CCHARW_MAX))
-	    ? wp - wcval->chars
-	    : CCHARW_MAX;
+    if (opts == NULL && wcval != NULL) {
+	len = ((wp = wmemchr(wcval->chars, L'\0', (size_t) CCHARW_MAX))
+	       ? (int) (wp - wcval->chars)
+	       : CCHARW_MAX);
 
 	if (wch == NULL) {
-	    code = len;
+	    /*
+	     * If the value is a null, set the length to 1.
+	     * If the value is not a null, return the length plus 1 for null.
+	     */
+	    code = (len < CCHARW_MAX) ? (len + 1) : CCHARW_MAX;
 	} else if (attrs == 0 || color_pair == 0) {
 	    code = ERR;
 	} else if (len >= 0) {
 	    *attrs = AttrOf(*wcval) & A_ATTRIBUTES;
-	    *color_pair = GetPair(*wcval);
-	    wmemcpy(wch, wcval->chars, (unsigned) len);
+	    *color_pair = (NCURSES_PAIRS_T) GetPair(*wcval);
+	    wmemcpy(wch, wcval->chars, (size_t) len);
 	    wch[len] = L'\0';
 	    code = OK;
 	}
diff --git a/ncurses/widechar/lib_erasewchar.c b/ncurses/widechar/lib_erasewchar.c
index 7d64553..ddce27a 100644
--- a/ncurses/widechar/lib_erasewchar.c
+++ b/ncurses/widechar/lib_erasewchar.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2002-2010,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -32,7 +32,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_erasewchar.c,v 1.1 2002/05/11 20:38:06 tom Exp $")
+MODULE_ID("$Id: lib_erasewchar.c,v 1.3 2014/02/23 01:21:08 tom Exp $")
 
 /*
  *	erasewchar()
@@ -42,14 +42,14 @@
  */
 
 NCURSES_EXPORT(int)
-erasewchar(wchar_t * wch)
+erasewchar(wchar_t *wch)
 {
     int value;
     int result = ERR;
 
     T((T_CALLED("erasewchar()")));
     if ((value = erasechar()) != ERR) {
-	*wch = value;
+	*wch = (wchar_t) value;
 	result = OK;
     }
     returnCode(result);
@@ -63,14 +63,14 @@
  */
 
 NCURSES_EXPORT(int)
-killwchar(wchar_t * wch)
+killwchar(wchar_t *wch)
 {
     int value;
     int result = ERR;
 
     T((T_CALLED("killwchar()")));
     if ((value = killchar()) != ERR) {
-	*wch = value;
+	*wch = (wchar_t) value;
 	result = OK;
     }
     returnCode(result);
diff --git a/ncurses/widechar/lib_get_wch.c b/ncurses/widechar/lib_get_wch.c
index 6cf3129..71d5603 100644
--- a/ncurses/widechar/lib_get_wch.c
+++ b/ncurses/widechar/lib_get_wch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2002-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,22 +40,7 @@
 #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
+MODULE_ID("$Id: lib_get_wch.c,v 1.23 2011/05/28 23:00:29 tom Exp $")
 
 NCURSES_EXPORT(int)
 wget_wch(WINDOW *win, wint_t *result)
@@ -65,13 +50,13 @@
     char buffer[(MB_LEN_MAX * 9) + 1];	/* allow some redundant shifts */
     int status;
     size_t count = 0;
-    unsigned long value;
+    int value = 0;
     wchar_t wch;
 #ifndef state_unused
     mbstate_t state;
 #endif
 
-    T((T_CALLED("wget_wch(%p)"), win));
+    T((T_CALLED("wget_wch(%p)"), (void *) win));
 
     /*
      * We can get a stream of single-byte characters and KEY_xxx codes from
@@ -95,12 +80,12 @@
 		 * whether the improvement would be worth the effort.
 		 */
 		if (count != 0) {
-		    _nc_ungetch(sp, (int) value);
+		    safe_ungetch(SP_PARM, value);
 		    code = ERR;
 		}
 		break;
 	    } else if (count + 1 >= sizeof(buffer)) {
-		_nc_ungetch(sp, (int) value);
+		safe_ungetch(SP_PARM, value);
 		code = ERR;
 		break;
 	    } else {
@@ -111,7 +96,7 @@
 		    reset_mbytes(state);
 		    if (check_mbytes(wch, buffer, count, state) != status) {
 			code = ERR;	/* the two calls should match */
-			_nc_ungetch(sp, (int) value);
+			safe_ungetch(SP_PARM, value);
 		    }
 		    value = wch;
 		    break;
@@ -121,8 +106,11 @@
     } else {
 	code = ERR;
     }
-    *result = value;
+
+    if (result != 0)
+	*result = (wint_t) value;
+
     _nc_unlock_global(curses);
-    T(("result %#lo", value));
+    T(("result %#o", value));
     returnCode(code);
 }
diff --git a/ncurses/widechar/lib_get_wstr.c b/ncurses/widechar/lib_get_wstr.c
index baa70a5..27cdae0 100644
--- a/ncurses/widechar/lib_get_wstr.c
+++ b/ncurses/widechar/lib_get_wstr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002-2004,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2002-2009,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -38,9 +38,8 @@
 */
 
 #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 $")
+MODULE_ID("$Id: lib_get_wstr.c,v 1.13 2011/10/22 16:31:35 tom Exp $")
 
 static int
 wadd_wint(WINDOW *win, wint_t *src)
@@ -50,7 +49,7 @@
 
     wch[0] = (wchar_t) (*src);
     wch[1] = 0;
-    setcchar(&tmp, wch, A_NORMAL, 0, NULL);
+    setcchar(&tmp, wch, A_NORMAL, (short) 0, NULL);
     return wadd_wch(win, &tmp);
 }
 
@@ -59,7 +58,7 @@
  * 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)
+WipeOut(WINDOW *win, int y, int x, wint_t *first, wint_t *last, int echoed)
 {
     if (last > first) {
 	*--last = '\0';
@@ -96,7 +95,7 @@
     wint_t ch;
     int y, x, code;
 
-    T((T_CALLED("wgetn_wstr(%p,%p, %d)"), win, str, maxlen));
+    T((T_CALLED("wgetn_wstr(%p,%p, %d)"), (void *) win, (void *) str, maxlen));
 
     if (!win)
 	returnCode(ERR);
diff --git a/ncurses/widechar/lib_hline_set.c b/ncurses/widechar/lib_hline_set.c
index 43175de..da92b83 100644
--- a/ncurses/widechar/lib_hline_set.c
+++ b/ncurses/widechar/lib_hline_set.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2002-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,16 +39,16 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_hline_set.c,v 1.2 2002/03/23 21:35:34 tom Exp $")
+MODULE_ID("$Id: lib_hline_set.c,v 1.4 2010/12/19 01:45:03 tom Exp $")
 
 NCURSES_EXPORT(int)
-whline_set(WINDOW *win, const cchar_t * ch, int n)
+whline_set(WINDOW *win, const cchar_t *ch, int n)
 {
     int code = ERR;
-    NCURSES_SIZE_T start;
-    NCURSES_SIZE_T end;
+    int start;
+    int end;
 
-    T((T_CALLED("whline_set(%p,%s,%d)"), win, _tracecchar_t(ch), n));
+    T((T_CALLED("whline_set(%p,%s,%d)"), (void *) win, _tracecchar_t(ch), n));
 
     if (win) {
 	struct ldat *line = &(win->_line[win->_cury]);
diff --git a/ncurses/widechar/lib_in_wch.c b/ncurses/widechar/lib_in_wch.c
index 5cd92e3..b239650 100644
--- a/ncurses/widechar/lib_in_wch.c
+++ b/ncurses/widechar/lib_in_wch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002-2004,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 2002-2006,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_in_wch.c,v 1.4 2006/09/03 15:41:22 tom Exp $")
+MODULE_ID("$Id: lib_in_wch.c,v 1.5 2009/10/24 22:37:55 tom Exp $")
 
 NCURSES_EXPORT(int)
 win_wch(WINDOW *win, cchar_t *wcval)
@@ -47,7 +47,7 @@
     int row, col;
     int code = OK;
 
-    TR(TRACE_CCALLS, (T_CALLED("win_wch(%p,%p)"), win, wcval));
+    TR(TRACE_CCALLS, (T_CALLED("win_wch(%p,%p)"), (void *) win, (void *) wcval));
     if (win != 0
 	&& wcval != 0) {
 	getyx(win, row, col);
diff --git a/ncurses/widechar/lib_in_wchnstr.c b/ncurses/widechar/lib_in_wchnstr.c
index e9f0646..57cc2ca 100644
--- a/ncurses/widechar/lib_in_wchnstr.c
+++ b/ncurses/widechar/lib_in_wchnstr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002-2004-2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2002-2007,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,14 +39,14 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_in_wchnstr.c,v 1.7 2007/02/11 01:00:00 tom Exp $")
+MODULE_ID("$Id: lib_in_wchnstr.c,v 1.8 2009/10/24 22:37:48 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));
+    T((T_CALLED("win_wchnstr(%p,%p,%d)"), (void *) win, (void *) wchstr, n));
     if (win != 0
 	&& wchstr != 0) {
 	NCURSES_CH_T *src;
diff --git a/ncurses/widechar/lib_ins_wch.c b/ncurses/widechar/lib_ins_wch.c
index c3d0420..2aa71a5 100644
--- a/ncurses/widechar/lib_ins_wch.c
+++ b/ncurses/widechar/lib_ins_wch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002-2003,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 2002-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,39 +39,44 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_ins_wch.c,v 1.8 2005/12/03 20:24:19 tom Exp $")
+MODULE_ID("$Id: lib_ins_wch.c,v 1.17 2011/10/22 16:34:50 tom Exp $")
 
 /*
  * Insert the given character, updating the current location to simplify
  * inserting a string.
  */
-static int
+NCURSES_EXPORT(int)
 _nc_insert_wch(WINDOW *win, const cchar_t *wch)
 {
     int cells = wcwidth(CharOf(CHDEREF(wch)));
     int cell;
+    int code = OK;
 
-    if (cells <= 0)
-	cells = 1;
+    if (cells < 0) {
+	code = winsch(win, (chtype) CharOf(CHDEREF(wch)));
+    } else {
+	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;
+	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--;
+	    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);
+	    *temp1 = _nc_render(win, *wch);
+	    for (cell = 1; cell < cells; ++cell) {
+		SetWidecExt(temp1[cell], cell);
+	    }
+
+	    win->_curx++;
 	}
-
-	win->_curx++;
     }
-    return OK;
+    return code;
 }
 
 NCURSES_EXPORT(int)
@@ -81,7 +86,7 @@
     NCURSES_SIZE_T ox;
     int code = ERR;
 
-    T((T_CALLED("wins_wch(%p, %s)"), win, _tracecchar_t(wch)));
+    T((T_CALLED("wins_wch(%p, %s)"), (void *) win, _tracecchar_t(wch)));
 
     if (win != 0) {
 	oy = win->_cury;
@@ -104,32 +109,35 @@
     NCURSES_SIZE_T ox;
     const wchar_t *cp;
 
-    T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbufn(wstr, n), n));
+    T((T_CALLED("wins_nwstr(%p,%s,%d)"),
+       (void *) win, _nc_viswbufn(wstr, n), n));
 
     if (win != 0
 	&& wstr != 0) {
 	if (n < 1)
-	    n = wcslen(wstr);
+	    n = (int) wcslen(wstr);
 	code = OK;
 	if (n > 0) {
+	    SCREEN *sp = _nc_screen_of(win);
+
 	    oy = win->_cury;
 	    ox = win->_curx;
 	    for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
 		int len = wcwidth(*cp);
 
-		if (len != 1 || !is8bits(*cp)) {
+		if ((len >= 0 && len != 1) || !is7bits(*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,
+				    (short) 0,
 				    (void *) 0);
 		    code = _nc_insert_wch(win, &tmp_cchar);
 		} else {
 		    /* tabs, other ASCII stuff */
-		    code = _nc_insert_ch(win, (chtype) (*cp));
+		    code = _nc_insert_ch(sp, win, (chtype) (*cp));
 		}
 		if (code != OK)
 		    break;
diff --git a/ncurses/widechar/lib_inwstr.c b/ncurses/widechar/lib_inwstr.c
index 2207a5f..a4f5b8e 100644
--- a/ncurses/widechar/lib_inwstr.c
+++ b/ncurses/widechar/lib_inwstr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002,2004 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2002-2009,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_inwstr.c,v 1.4 2004/10/23 20:41:28 tom Exp $")
+MODULE_ID("$Id: lib_inwstr.c,v 1.6 2011/05/28 22:49:49 tom Exp $")
 
 NCURSES_EXPORT(int)
 winnwstr(WINDOW *win, wchar_t *wstr, int n)
@@ -50,7 +50,7 @@
     cchar_t *text;
     wchar_t wch;
 
-    T((T_CALLED("winnwstr(%p,%p,%d)"), win, wstr, n));
+    T((T_CALLED("winnwstr(%p,%p,%d)"), (void *) win, (void *) wstr, n));
     if (wstr != 0) {
 	if (win) {
 	    getyx(win, row, col);
@@ -93,8 +93,13 @@
 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)
+
+    T((T_CALLED("winwstr(%p,%p)"), (void *) win, (void *) wstr));
+    if (win == 0) {
 	result = ERR;
+    } else if (winnwstr(win, wstr,
+			CCHARW_MAX * (win->_maxx - win->_curx + 1)) == ERR) {
+	result = ERR;
+    }
     returnCode(result);
 }
diff --git a/ncurses/widechar/lib_pecho_wchar.c b/ncurses/widechar/lib_pecho_wchar.c
index e612775..b6da7a8 100644
--- a/ncurses/widechar/lib_pecho_wchar.c
+++ b/ncurses/widechar/lib_pecho_wchar.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2004 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2004,2009 Free Software Foundation, Inc.                   *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -32,12 +32,12 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_pecho_wchar.c,v 1.1 2004/01/03 21:42:01 tom Exp $")
+MODULE_ID("$Id: lib_pecho_wchar.c,v 1.2 2009/10/24 22:43:32 tom Exp $")
 
 NCURSES_EXPORT(int)
-pecho_wchar(WINDOW *pad, const cchar_t * wch)
+pecho_wchar(WINDOW *pad, const cchar_t *wch)
 {
-    T((T_CALLED("pecho_wchar(%p, %s)"), pad, _tracech_t(wch)));
+    T((T_CALLED("pecho_wchar(%p, %s)"), (void *) pad, _tracech_t(wch)));
 
     if (pad == 0)
 	returnCode(ERR);
diff --git a/ncurses/widechar/lib_slk_wset.c b/ncurses/widechar/lib_slk_wset.c
index 646b5d9..8927556 100644
--- a/ncurses/widechar/lib_slk_wset.c
+++ b/ncurses/widechar/lib_slk_wset.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2003-2004,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 2003-2002,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,7 +40,7 @@
 #include <wctype.h>
 #endif
 
-MODULE_ID("$Id: lib_slk_wset.c,v 1.11 2005/01/16 01:03:53 tom Exp $")
+MODULE_ID("$Id: lib_slk_wset.c,v 1.13 2011/10/22 15:52:20 tom Exp $")
 
 NCURSES_EXPORT(int)
 slk_wset(int i, const wchar_t *astr, int format)
@@ -53,19 +53,21 @@
 
     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);
+    if (astr != 0) {
+	init_mb(state);
+	str = astr;
+	if ((arglen = wcsrtombs(NULL, &str, (size_t) 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);
 	    }
-	    free(mystr);
 	}
     }
     returnCode(result);
diff --git a/ncurses/widechar/lib_unget_wch.c b/ncurses/widechar/lib_unget_wch.c
index bb2c4a0..d5ae608 100644
--- a/ncurses/widechar/lib_unget_wch.c
+++ b/ncurses/widechar/lib_unget_wch.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2002-2010,2011 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +39,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_unget_wch.c,v 1.10 2008/06/07 14:50:37 tom Exp $")
+MODULE_ID("$Id: lib_unget_wch.c,v 1.15 2011/10/22 16:34:50 tom Exp $")
 
 /*
  * Wrapper for wcrtomb() which obtains the length needed for the given
@@ -55,24 +55,24 @@
 	const wchar_t *tempp = temp;
 	temp[0] = source;
 	temp[1] = 0;
-	result = wcsrtombs(NULL, &tempp, 0, state);
+	result = (int) wcsrtombs(NULL, &tempp, (size_t) 0, state);
     } else {
-	result = wcrtomb(target, source, state);
+	result = (int) wcrtomb(target, source, state);
     }
     if (!isEILSEQ(result) && (result == 0))
 	result = 1;
-    return result;
+    return (size_t) result;
 }
 
 NCURSES_EXPORT(int)
-unget_wch(const wchar_t wch)
+NCURSES_SP_NAME(unget_wch) (NCURSES_SP_DCLx const wchar_t wch)
 {
     int result = OK;
     mbstate_t state;
     size_t length;
     int n;
 
-    T((T_CALLED("unget_wch(%#lx)"), (unsigned long) wch));
+    T((T_CALLED("unget_wch(%p, %#lx)"), (void *) SP_PARM, (unsigned long) wch));
 
     init_mb(state);
     length = _nc_wcrtomb(0, wch, &state);
@@ -83,10 +83,12 @@
 
 	if ((string = (char *) malloc(length)) != 0) {
 	    init_mb(state);
-	    wcrtomb(string, wch, &state);
+	    /* ignore the result, since we already validated the character */
+	    IGNORE_RC((int) wcrtomb(string, wch, &state));
 
 	    for (n = (int) (length - 1); n >= 0; --n) {
-		if (_nc_ungetch(SP, string[n]) != OK) {
+		if (NCURSES_SP_NAME(ungetch) (NCURSES_SP_ARGx
+					      UChar(string[n])) !=OK) {
 		    result = ERR;
 		    break;
 		}
@@ -101,3 +103,11 @@
 
     returnCode(result);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+unget_wch(const wchar_t wch)
+{
+    return NCURSES_SP_NAME(unget_wch) (CURRENT_SCREEN, wch);
+}
+#endif
diff --git a/ncurses/widechar/lib_vid_attr.c b/ncurses/widechar/lib_vid_attr.c
index 1dc679e..80c1ea4 100644
--- a/ncurses/widechar/lib_vid_attr.c
+++ b/ncurses/widechar/lib_vid_attr.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2002-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -31,16 +31,21 @@
  ****************************************************************************/
 
 #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 $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
+MODULE_ID("$Id: lib_vid_attr.c,v 1.23 2014/06/07 22:13:46 tom Exp $")
 
-#define TurnOn(mask,mode) \
+#define doPut(mode) \
+	TPUTS_TRACE(#mode); \
+	NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx mode, 1, outc)
+
+#define TurnOn(mask, mode) \
 	if ((turn_on & mask) && mode) { doPut(mode); }
 
-#define TurnOff(mask,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 */
@@ -50,14 +55,22 @@
 		if ((pair != old_pair) \
 		 || (fix_pair0 && (pair == 0)) \
 		 || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \
-			_nc_do_color(old_pair, pair, reverse, outc); \
+		    NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_ARGx \
+						   old_pair, pair, \
+						   reverse, outc); \
 		} \
 	}
 
-#define set_color(mode, pair) mode &= ALL_BUT_COLOR; mode |= COLOR_PAIR(pair)
+#define set_color(mode, pair) \
+	mode &= ALL_BUT_COLOR; \
+	mode |= (attr_t) ColorPair(pair)
 
 NCURSES_EXPORT(int)
-vid_puts(attr_t newmode, short pair, void *opts GCC_UNUSED, int (*outc) (int))
+NCURSES_SP_NAME(vid_puts) (NCURSES_SP_DCLx
+			   attr_t newmode,
+			   NCURSES_PAIRS_T pair,
+			   void *opts GCC_UNUSED,
+			   NCURSES_SP_OUTC outc)
 {
 #if NCURSES_EXT_COLORS
     static attr_t previous_attr = A_NORMAL;
@@ -65,9 +78,9 @@
 
     attr_t turn_on, turn_off;
     bool reverse = FALSE;
-    bool can_color = (SP == 0 || SP->_coloron);
+    bool can_color = (SP_PARM == 0 || SP_PARM->_coloron);
 #if NCURSES_EXT_FUNCS
-    bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color);
+    bool fix_pair0 = (SP_PARM != 0 && SP_PARM->_coloron && !SP_PARM->_default_color);
 #else
 #define fix_pair0 FALSE
 #endif
@@ -76,18 +89,18 @@
     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));
+    if (SP_PARM) {
+	previous_attr = AttrOf(SCREEN_ATTRS(SP_PARM));
+	previous_pair = GetPair(SCREEN_ATTRS(SP_PARM));
     }
 
     TR(TRACE_ATTRS, ("previous attribute was %s, %d",
 		     _traceattr(previous_attr), previous_pair));
 
 #if !USE_XMC_SUPPORT
-    if ((SP != 0)
+    if ((SP_PARM != 0)
 	&& (magic_cookie_glitch > 0))
-	newmode &= ~(SP->_xmc_suppress);
+	newmode &= ~(SP_PARM->_xmc_suppress);
 #endif
 
     /*
@@ -109,7 +122,7 @@
 	 * 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;
+	unsigned value = (unsigned) no_color_video;
 	attr_t mask = NCURSES_BITS((value & 63)
 				   | ((value & 192) << 1)
 				   | ((value & 256) >> 2), 8);
@@ -131,7 +144,7 @@
     }
 
     turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR;
-    turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR;
+    turn_on = (newmode & ~(previous_attr & TPARM_ATTR)) & ALL_BUT_COLOR;
 
     SetColorsIf(((pair == 0) && !fix_pair0), previous_attr, previous_pair);
 
@@ -144,12 +157,17 @@
 	    if (exit_attribute_mode) {
 		doPut(exit_attribute_mode);
 	    } else {
-		if (!SP || SP->_use_rmul) {
+		if (!SP_PARM || SP_PARM->_use_rmul) {
 		    TurnOff(A_UNDERLINE, exit_underline_mode);
 		}
-		if (!SP || SP->_use_rmso) {
+		if (!SP_PARM || SP_PARM->_use_rmso) {
 		    TurnOff(A_STANDOUT, exit_standout_mode);
 		}
+#if USE_ITALIC
+		if (!SP_PARM || SP_PARM->_use_ritm) {
+		    TurnOff(A_ITALIC, exit_italics_mode);
+		}
+#endif
 	    }
 	    previous_attr &= ALL_BUT_COLOR;
 	    previous_pair = 0;
@@ -159,19 +177,30 @@
     } 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);
+	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
+				    TPARM_9(set_attributes,
+					    (newmode & A_STANDOUT) != 0,
+					    (newmode & A_UNDERLINE) != 0,
+					    (newmode & A_REVERSE) != 0,
+					    (newmode & A_BLINK) != 0,
+					    (newmode & A_DIM) != 0,
+					    (newmode & A_BOLD) != 0,
+					    (newmode & A_INVIS) != 0,
+					    (newmode & A_PROTECT) != 0,
+					    (newmode & A_ALTCHARSET) != 0),
+				    1, outc);
 	    previous_attr &= ALL_BUT_COLOR;
 	    previous_pair = 0;
 	}
+#if USE_ITALIC
+	if (!SP_PARM || SP_PARM->_use_ritm) {
+	    if (turn_on & A_ITALIC) {
+		TurnOn(A_ITALIC, enter_italics_mode);
+	    } else if (turn_off & A_ITALIC) {
+		TurnOff(A_ITALIC, exit_italics_mode);
+	    }
+	}
+#endif
 	SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
     } else {
 
@@ -179,14 +208,18 @@
 
 	TurnOff(A_ALTCHARSET, exit_alt_charset_mode);
 
-	if (!SP || SP->_use_rmul) {
+	if (!SP_PARM || SP_PARM->_use_rmul) {
 	    TurnOff(A_UNDERLINE, exit_underline_mode);
 	}
 
-	if (!SP || SP->_use_rmso) {
+	if (!SP_PARM || SP_PARM->_use_rmso) {
 	    TurnOff(A_STANDOUT, exit_standout_mode);
 	}
-
+#if USE_ITALIC
+	if (!SP_PARM || SP_PARM->_use_ritm) {
+	    TurnOff(A_ITALIC, exit_italics_mode);
+	}
+#endif
 	if (turn_off && exit_attribute_mode) {
 	    doPut(exit_attribute_mode);
 	    turn_on |= (newmode & ALL_BUT_COLOR);
@@ -206,6 +239,9 @@
 	TurnOn(A_PROTECT,	enter_protected_mode);
 	TurnOn(A_INVIS,		enter_secure_mode);
 	TurnOn(A_UNDERLINE,	enter_underline_mode);
+#if USE_ITALIC
+	TurnOn(A_ITALIC,	enter_italics_mode);
+#endif
 #if USE_WIDEC_SUPPORT
 	TurnOn(A_HORIZONTAL,	enter_horizontal_hl_mode);
 	TurnOn(A_LEFT,		enter_left_hl_mode);
@@ -221,9 +257,9 @@
     if (reverse)
 	newmode |= A_REVERSE;
 
-    if (SP) {
-	SetAttr(SCREEN_ATTRS(SP), newmode);
-	SetPair(SCREEN_ATTRS(SP), pair);
+    if (SP_PARM) {
+	SetAttr(SCREEN_ATTRS(SP_PARM), newmode);
+	SetPair(SCREEN_ATTRS(SP_PARM), pair);
     } else {
 	previous_attr = newmode;
 	previous_pair = pair;
@@ -231,45 +267,86 @@
 
     returnCode(OK);
 #else
-    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair));
+    T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), (int) pair));
     set_color(newmode, pair);
-    returnCode(vidputs(newmode, outc));
+    returnCode(NCURSES_SP_NAME(vidputs) (NCURSES_SP_ARGx newmode, outc));
 #endif
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+vid_puts(attr_t newmode,
+	 NCURSES_PAIRS_T pair,
+	 void *opts GCC_UNUSED,
+	 NCURSES_OUTC outc)
+{
+    SetSafeOutcWrapper(outc);
+    return NCURSES_SP_NAME(vid_puts) (CURRENT_SCREEN,
+				      newmode,
+				      pair,
+				      opts,
+				      _nc_outc_wrapper);
+}
+#endif
+
 #undef vid_attr
 NCURSES_EXPORT(int)
-vid_attr(attr_t newmode, short pair, void *opts)
+NCURSES_SP_NAME(vid_attr) (NCURSES_SP_DCLx
+			   attr_t newmode,
+			   NCURSES_PAIRS_T pair,
+			   void *opts)
 {
-    T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), pair));
-    returnCode(vid_puts(newmode, pair, opts, _nc_outch));
+    T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), (int) pair));
+    returnCode(NCURSES_SP_NAME(vid_puts) (NCURSES_SP_ARGx
+					  newmode,
+					  pair,
+					  opts,
+					  NCURSES_SP_NAME(_nc_putchar)));
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+vid_attr(attr_t newmode, NCURSES_PAIRS_T pair, void *opts)
+{
+    return NCURSES_SP_NAME(vid_attr) (CURRENT_SCREEN, newmode, pair, opts);
+}
+#endif
+
 /*
  * 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)
+NCURSES_SP_NAME(term_attrs) (NCURSES_SP_DCL0)
 {
-    attr_t attrs;
+    attr_t attrs = 0;
 
     T((T_CALLED("term_attrs()")));
-    attrs = termattrs();
+    if (SP_PARM) {
+	attrs = NCURSES_SP_NAME(termattrs) (NCURSES_SP_ARG);
 
-    /* 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;
+	/* 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);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(attr_t)
+term_attrs(void)
+{
+    return NCURSES_SP_NAME(term_attrs) (CURRENT_SCREEN);
+}
+#endif
diff --git a/ncurses/widechar/lib_vline_set.c b/ncurses/widechar/lib_vline_set.c
index af42df1..917caac 100644
--- a/ncurses/widechar/lib_vline_set.c
+++ b/ncurses/widechar/lib_vline_set.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2002-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,16 +39,16 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_vline_set.c,v 1.2 2002/03/23 21:36:01 tom Exp $")
+MODULE_ID("$Id: lib_vline_set.c,v 1.4 2010/12/19 01:50:50 tom Exp $")
 
 NCURSES_EXPORT(int)
-wvline_set(WINDOW *win, const cchar_t * ch, int n)
+wvline_set(WINDOW *win, const cchar_t *ch, int n)
 {
     int code = ERR;
-    NCURSES_SIZE_T row, col;
-    NCURSES_SIZE_T end;
+    int row, col;
+    int end;
 
-    T((T_CALLED("wvline(%p,%s,%d)"), win, _tracecchar_t(ch), n));
+    T((T_CALLED("wvline(%p,%s,%d)"), (void *) win, _tracecchar_t(ch), n));
 
     if (win) {
 	NCURSES_CH_T wch;
diff --git a/ncurses/widechar/lib_wacs.c b/ncurses/widechar/lib_wacs.c
index fe893b4..dc3af21 100644
--- a/ncurses/widechar/lib_wacs.c
+++ b/ncurses/widechar/lib_wacs.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2002,2006 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2002-2013,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -31,9 +31,8 @@
  ****************************************************************************/
 
 #include <curses.priv.h>
-#include <term.h>
 
-MODULE_ID("$Id: lib_wacs.c,v 1.7 2006/12/17 15:16:17 tom Exp $")
+MODULE_ID("$Id: lib_wacs.c,v 1.14 2014/02/23 01:21:08 tom Exp $")
 
 NCURSES_EXPORT_VAR(cchar_t) * _nc_wacs = 0;
 
@@ -42,7 +41,7 @@
 {
     /* *INDENT-OFF* */
     static const struct {
-	int	map;
+	unsigned map;
 	int	value[2];
     } table[] = {
 	/* VT100 symbols */
@@ -80,6 +79,30 @@
 	{ '{',	{ '*',	0x03c0 }},	/* greek pi */
 	{ '|',	{ '!',	0x2260 }},	/* not-equal */
 	{ '}',	{ 'f',	0x00a3 }},	/* pound-sterling symbol */
+	/* thick-line-drawing */
+	{ 'L',	{ '+',	0x250f }},	/* upper left corner */
+	{ 'M',	{ '+',	0x2517 }},	/* lower left corner */
+	{ 'K',	{ '+',	0x2513 }},	/* upper right corner */
+	{ 'J',	{ '+',	0x251b }},	/* lower right corner */
+	{ 'T',	{ '+',	0x2523 }},	/* tee pointing left */
+	{ 'U',	{ '+',	0x252b }},	/* tee pointing right */
+	{ 'V',	{ '+',	0x253b }},	/* tee pointing up */
+	{ 'W',	{ '+',	0x2533 }},	/* tee pointing down */
+	{ 'Q',	{ '-',	0x2501 }},	/* horizontal line */
+	{ 'X',	{ '|',	0x2503 }},	/* vertical line */
+	{ 'N',	{ '+',	0x254b }},	/* large plus or crossover */
+	/* double-line-drawing */
+	{ 'C',	{ '+',	0x2554 }},	/* upper left corner */
+	{ 'D',	{ '+',	0x255a }},	/* lower left corner */
+	{ 'B',	{ '+',	0x2557 }},	/* upper right corner */
+	{ 'A',	{ '+',	0x255d }},	/* lower right corner */
+	{ 'G',	{ '+',	0x2563 }},	/* tee pointing left */
+	{ 'F',	{ '+',	0x2560 }},	/* tee pointing right */
+	{ 'H',	{ '+',	0x2569 }},	/* tee pointing up */
+	{ 'I',	{ '+',	0x2566 }},	/* tee pointing down */
+	{ 'R',	{ '-',	0x2550 }},	/* horizontal line */
+	{ 'Y',	{ '|',	0x2551 }},	/* vertical line */
+	{ 'E',	{ '+',	0x256c }},	/* large plus or crossover */
     };
     /* *INDENT-ON* */
 
@@ -96,22 +119,24 @@
     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]);
+    if ((_nc_wacs = typeCalloc(cchar_t, ACS_LEN)) != 0) {
 
-	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);
+	for (n = 0; n < SIZEOF(table); ++n) {
+	    int wide = wcwidth((wchar_t) table[n].value[active]);
+
+	    m = table[n].map;
+	    if (active && (wide == 1)) {
+		SetChar(_nc_wacs[m], table[n].value[1], 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])));
 	}
-
-	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
index be2259a..45d4952 100644
--- a/ncurses/widechar/lib_wunctrl.c
+++ b/ncurses/widechar/lib_wunctrl.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2001-2005,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2001-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -35,21 +35,36 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_wunctrl.c,v 1.12 2007/06/12 20:22:32 tom Exp $")
+MODULE_ID("$Id: lib_wunctrl.c,v 1.16 2012/12/15 20:53:42 tom Exp $")
 
 NCURSES_EXPORT(wchar_t *)
+NCURSES_SP_NAME(wunctrl) (NCURSES_SP_DCLx cchar_t *wc)
+{
+    static wchar_t str[CCHARW_MAX + 1], *wsp;
+    wchar_t *result;
+
+    if (wc == 0) {
+	result = 0;
+    } else if (SP_PARM != 0 && Charable(*wc)) {
+	const char *p =
+	NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx
+				 (unsigned) _nc_to_char((wint_t)CharOf(*wc)));
+
+	for (wsp = str; *p; ++p) {
+	    *wsp++ = (wchar_t) _nc_to_widechar(*p);
+	}
+	*wsp = 0;
+	result = str;
+    } else {
+	result = wc->chars;
+    }
+    return result;
+}
+
+#if NCURSES_SP_FUNCS
+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;
+    return NCURSES_SP_NAME(wunctrl) (CURRENT_SCREEN, wc);
 }
+#endif
diff --git a/ncurses/widechar/widechars.c b/ncurses/widechar/widechars.c
new file mode 100644
index 0000000..6951e28
--- /dev/null
+++ b/ncurses/widechar/widechars.c
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * Copyright (c) 2012,2013 Free Software Foundation, Inc.                   *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "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>
+
+#if USE_WIDEC_SUPPORT
+
+MODULE_ID("$Id: widechars.c,v 1.5 2013/03/02 18:55:51 tom Exp $")
+
+#if defined(__MINGW32__)
+/*
+ * MinGW has wide-character functions, but they do not work correctly.
+ */
+
+int
+_nc_mbtowc(wchar_t *pwc, const char *s, size_t n)
+{
+    int result;
+    int count;
+    int try;
+
+    if (s != 0 && n != 0) {
+	/*
+	 * MultiByteToWideChar() can decide to return more than one
+	 * wide-character.  We want only one.  Ignore any trailing null, both
+	 * in the initial count and in the conversion.
+	 */
+	count = 0;
+	for (try = 1; try <= (int) n; ++try) {
+	    count = MultiByteToWideChar(CP_UTF8,
+					MB_ERR_INVALID_CHARS,
+					s,
+					try,
+					pwc,
+					0);
+	    TR(TRACE_BITS, ("...try %d:%d", try, count));
+	    if (count > 0) {
+		break;
+	    }
+	}
+	if (count < 1 || count > 2) {
+	    result = -1;
+	} else {
+	    wchar_t actual[2];
+	    memset(&actual, 0, sizeof(actual));
+	    count = MultiByteToWideChar(CP_UTF8,
+					MB_ERR_INVALID_CHARS,
+					s,
+					try,
+					actual,
+					2);
+	    TR(TRACE_BITS, ("\twin32 ->%#x, %#x", actual[0], actual[1]));
+	    *pwc = actual[0];
+	    if (actual[1] != 0)
+		result = -1;
+	    else
+		result = try;
+	}
+    } else {
+	result = 0;
+    }
+
+    return result;
+}
+
+int
+_nc_mblen(const char *s, size_t n)
+{
+    int result = -1;
+    int count;
+    wchar_t temp;
+
+    if (s != 0 && n != 0) {
+	count = _nc_mbtowc(&temp, s, n);
+	if (count == 1) {
+	    int check = WideCharToMultiByte(CP_UTF8,
+					    0,
+					    &temp,
+					    1,
+					    NULL,
+					    0,	/* compute length only */
+					    NULL,
+					    NULL);
+	    TR(TRACE_BITS, ("\tcheck ->%d\n", check));
+	    if (check > 0 && (size_t) check <= n) {
+		result = check;
+	    }
+	}
+    } else {
+	result = 0;
+    }
+
+    return result;
+}
+
+int __MINGW_NOTHROW
+_nc_wctomb(char *s, wchar_t wc)
+{
+    int result;
+    int check;
+
+    check = WideCharToMultiByte(CP_UTF8,
+				0,
+				&wc,
+				1,
+				NULL,
+				0,	/* compute length only */
+				NULL,
+				NULL);
+    if (check > 0) {
+	result = WideCharToMultiByte(CP_UTF8,
+				     0,
+				     &wc,
+				     1,
+				     s,
+				     check + 1,
+				     NULL,
+				     NULL);
+    } else {
+	result = -1;
+    }
+    return result;
+}
+
+#endif /* __MINGW32__ */
+
+#endif /* USE_WIDEC_SUPPORT */
diff --git a/ncurses/base/memmove.c b/ncurses/win32con/gettimeofday.c
similarity index 65%
rename from ncurses/base/memmove.c
rename to ncurses/win32con/gettimeofday.c
index 093ad72..867041f 100644
--- a/ncurses/base/memmove.c
+++ b/ncurses/win32con/gettimeofday.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2008-2010,2014 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -26,44 +26,29 @@
  * authorization.                                                           *
  ****************************************************************************/
 
+#ifdef WINVER
+#  undef WINVER
+#endif
+#define WINVER 0x0501
+
 #include <curses.priv.h>
 
-MODULE_ID("$Id: memmove.c,v 1.5 2007/08/11 17:12:43 tom Exp $")
+#include <windows.h>
 
-/****************************************************************************
- *  Author: Thomas E. Dickey <dickey@clark.net> 1998                        *
- ****************************************************************************/
+MODULE_ID("$Id: gettimeofday.c,v 1.3 2014/04/26 19:41:34 juergen Exp $")
 
-#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)
+#define JAN1970 116444736000000000LL	/* the value for 01/01/1970 00:00 */
+
+int
+gettimeofday(struct timeval *tv, void *tz GCC_UNUSED)
 {
-    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;
+    union {
+	FILETIME ft;
+	long long since1601;	/* time since 1 Jan 1601 in 100ns units */
+    } data;
+
+    GetSystemTimeAsFileTime(&data.ft);
+    tv->tv_usec = (long) ((data.since1601 / 10LL) % 1000000LL);
+    tv->tv_sec = (long) ((data.since1601 - JAN1970) / 10000000LL);
+    return (0);
 }
-#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/memmove.c b/ncurses/win32con/wcwidth.c
similarity index 65%
copy from ncurses/base/memmove.c
copy to ncurses/win32con/wcwidth.c
index 093ad72..cdef64a 100644
--- a/ncurses/base/memmove.c
+++ b/ncurses/win32con/wcwidth.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 2010 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            *
@@ -25,45 +25,26 @@
  * 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 $")
+MODULE_ID("$Id: wcwidth.c,v 1.2 2010/08/07 20:52:43 tom Exp $")
 
-/****************************************************************************
- *  Author: Thomas E. Dickey <dickey@clark.net> 1998                        *
- ****************************************************************************/
+#if USE_WIDEC_SUPPORT
+#define mk_wcwidth(ucs)          _nc_wcwidth(ucs)
+#define mk_wcswidth(pwcs, n)     _nc_wcswidth(pwcs, n)
+#define mk_wcwidth_cjk(ucs)      _nc_wcwidth_cjk(ucs)
+#define mk_wcswidth_cjk(pwcs, n) _nc_wcswidth_cjk(pwcs, n)
 
-#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;
-}
+extern int mk_wcwidth(wchar_t);
+extern int mk_wcswidth(const wchar_t *, size_t);
+extern int mk_wcwidth_cjk(wchar_t);
+extern int mk_wcswidth_cjk(const wchar_t *, size_t);
+
+#include <wcwidth.h>
 #else
-extern
-NCURSES_EXPORT(void)
-_nc_memmove(void);		/* quiet's gcc warning */
-NCURSES_EXPORT(void)
-_nc_memmove(void)
+void _nc_empty_wcwidth(void);
+void
+_nc_empty_wcwidth(void)
 {
-}				/* nonempty for strict ANSI compilers */
-#endif /* USE_MY_MEMMOVE */
+}
+#endif
diff --git a/ncurses/win32con/win_driver.c b/ncurses/win32con/win_driver.c
new file mode 100644
index 0000000..78ccfed
--- /dev/null
+++ b/ncurses/win32con/win_driver.c
@@ -0,0 +1,2264 @@
+/****************************************************************************
+ * Copyright (c) 1998-2014,2015 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                                                *
+ ****************************************************************************/
+
+/*
+ * TODO - GetMousePos(POINT * result) from ntconio.c
+ * TODO - implement nodelay
+ * TODO - improve screen-repainting performance, using implied wraparound to reduce write's
+ * TODO - make it optional whether screen is restored or not when non-buffered
+ */
+
+#include <curses.priv.h>
+
+#ifdef __MINGW32__
+#include <tchar.h>
+#else
+#include <windows.h>
+#include <wchar.h>
+#endif
+
+#include <io.h>
+
+#define PSAPI_VERSION 2
+#include <psapi.h>
+
+#define CUR my_term.type.
+
+MODULE_ID("$Id: win_driver.c,v 1.55 2015/02/28 21:30:23 tom Exp $")
+
+#ifndef __GNUC__
+#  error We need GCC to compile for MinGW
+#endif
+
+#define WINMAGIC NCDRV_MAGIC(NCDRV_WINCONSOLE)
+
+#define EXP_OPTIMIZE 0
+
+#define array_length(a) (sizeof(a)/sizeof(a[0]))
+
+static bool InitConsole(void);
+static bool okConsoleHandle(TERMINAL_CONTROL_BLOCK *);
+
+#define AssertTCB() assert(TCB != 0 && (TCB->magic == WINMAGIC))
+#define SetSP()     assert(TCB->csp != 0); sp = TCB->csp; (void) sp
+
+#define GenMap(vKey,key) MAKELONG(key, vKey)
+
+#define AdjustY() (CON.buffered ? 0 : (int) CON.SBI.srWindow.Top)
+
+#if USE_WIDEC_SUPPORT
+#define write_screen WriteConsoleOutputW
+#define read_screen  ReadConsoleOutputW
+#else
+#define write_screen WriteConsoleOutput
+#define read_screen  ReadConsoleOutput
+#endif
+
+static const LONG keylist[] =
+{
+    GenMap(VK_PRIOR, KEY_PPAGE),
+    GenMap(VK_NEXT, KEY_NPAGE),
+    GenMap(VK_END, KEY_END),
+    GenMap(VK_HOME, KEY_HOME),
+    GenMap(VK_LEFT, KEY_LEFT),
+    GenMap(VK_UP, KEY_UP),
+    GenMap(VK_RIGHT, KEY_RIGHT),
+    GenMap(VK_DOWN, KEY_DOWN),
+    GenMap(VK_DELETE, KEY_DC),
+    GenMap(VK_INSERT, KEY_IC)
+};
+static const LONG ansi_keys[] =
+{
+    GenMap(VK_PRIOR, 'I'),
+    GenMap(VK_NEXT, 'Q'),
+    GenMap(VK_END, 'O'),
+    GenMap(VK_HOME, 'H'),
+    GenMap(VK_LEFT, 'K'),
+    GenMap(VK_UP, 'H'),
+    GenMap(VK_RIGHT, 'M'),
+    GenMap(VK_DOWN, 'P'),
+    GenMap(VK_DELETE, 'S'),
+    GenMap(VK_INSERT, 'R')
+};
+#define N_INI ((int)array_length(keylist))
+#define FKEYS 24
+#define MAPSIZE (FKEYS + N_INI)
+#define NUMPAIRS 64
+
+/*   A process can only have a single console, so it's safe
+     to maintain all the information about it in a single
+     static structure.
+ */
+static struct {
+    BOOL initialized;
+    BOOL buffered;
+    BOOL window_only;
+    BOOL progMode;
+    BOOL isMinTTY;
+    BOOL isTermInfoConsole;
+    HANDLE out;
+    HANDLE inp;
+    HANDLE hdl;
+    HANDLE lastOut;
+    int numButtons;
+    DWORD ansi_map[MAPSIZE];
+    DWORD map[MAPSIZE];
+    DWORD rmap[MAPSIZE];
+    WORD pairs[NUMPAIRS];
+    COORD origin;
+    CHAR_INFO *save_screen;
+    COORD save_size;
+    SMALL_RECT save_region;
+    CONSOLE_SCREEN_BUFFER_INFO SBI;
+    CONSOLE_SCREEN_BUFFER_INFO save_SBI;
+    CONSOLE_CURSOR_INFO save_CI;
+} CON;
+
+static BOOL console_initialized = FALSE;
+
+static WORD
+MapColor(bool fore, int color)
+{
+    static const int _cmap[] =
+    {0, 4, 2, 6, 1, 5, 3, 7};
+    int a;
+    if (color < 0 || color > 7)
+	a = fore ? 7 : 0;
+    else
+	a = _cmap[color];
+    if (!fore)
+	a = a << 4;
+    return (WORD) a;
+}
+
+#define RevAttr(attr) \
+	       (WORD) (((attr) & 0xff00) | \
+		      ((((attr) & 0x07) << 4) | \
+		       (((attr) & 0x70) >> 4)))
+
+static WORD
+MapAttr(WORD res, attr_t ch)
+{
+    if (ch & A_COLOR) {
+	int p;
+
+	p = PairNumber(ch);
+	if (p > 0 && p < NUMPAIRS) {
+	    WORD a;
+	    a = CON.pairs[p];
+	    res = (WORD) ((res & 0xff00) | a);
+	}
+    }
+
+    if (ch & A_REVERSE) {
+	res = RevAttr(res);
+    }
+
+    if (ch & A_STANDOUT) {
+	res = RevAttr(res) | BACKGROUND_INTENSITY;
+    }
+
+    if (ch & A_BOLD)
+	res |= FOREGROUND_INTENSITY;
+
+    if (ch & A_DIM)
+	res |= BACKGROUND_INTENSITY;
+
+    return res;
+}
+
+#if 0				/* def TRACE */
+static void
+dump_screen(const char *fn, int ln)
+{
+    int max_cells = (CON.SBI.dwSize.Y * (1 + CON.SBI.dwSize.X)) + 1;
+    char output[max_cells];
+    CHAR_INFO save_screen[max_cells];
+    COORD save_size;
+    SMALL_RECT save_region;
+    COORD bufferCoord;
+
+    T(("dump_screen %s@%d", fn, ln));
+
+    save_region.Top = CON.SBI.srWindow.Top;
+    save_region.Left = CON.SBI.srWindow.Left;
+    save_region.Bottom = CON.SBI.srWindow.Bottom;
+    save_region.Right = CON.SBI.srWindow.Right;
+
+    save_size.X = (SHORT) (save_region.Right - save_region.Left + 1);
+    save_size.Y = (SHORT) (save_region.Bottom - save_region.Top + 1);
+
+    bufferCoord.X = bufferCoord.Y = 0;
+
+    if (read_screen(CON.hdl,
+		    save_screen,
+		    save_size,
+		    bufferCoord,
+		    &save_region)) {
+	int i, j;
+	int ij = 0;
+	int k = 0;
+
+	for (i = save_region.Top; i <= save_region.Bottom; ++i) {
+	    for (j = save_region.Left; j <= save_region.Right; ++j) {
+		output[k++] = save_screen[ij++].Char.AsciiChar;
+	    }
+	    output[k++] = '\n';
+	}
+	output[k] = 0;
+
+	T(("DUMP: %d,%d - %d,%d",
+	   save_region.Top,
+	   save_region.Left,
+	   save_region.Bottom,
+	   save_region.Right));
+	T(("%s", output));
+    }
+}
+
+#else
+#define dump_screen(fn,ln)	/* nothing */
+#endif
+
+#if USE_WIDEC_SUPPORT
+/*
+ * TODO: support surrogate pairs
+ * TODO: support combining characters
+ * TODO: support acsc
+ * TODO: _nc_wacs should be part of sp.
+ */
+static BOOL
+con_write16(TERMINAL_CONTROL_BLOCK * TCB, int y, int x, cchar_t *str, int limit)
+{
+    int actual = 0;
+    CHAR_INFO ci[limit];
+    COORD loc, siz;
+    SMALL_RECT rec;
+    int i;
+    cchar_t ch;
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    for (i = actual = 0; i < limit; i++) {
+	ch = str[i];
+	if (isWidecExt(ch))
+	    continue;
+	ci[actual].Char.UnicodeChar = CharOf(ch);
+	ci[actual].Attributes = MapAttr(CON.SBI.wAttributes,
+					AttrOf(ch));
+	if (AttrOf(ch) & A_ALTCHARSET) {
+	    if (_nc_wacs) {
+		int which = CharOf(ch);
+		if (which > 0
+		    && which < ACS_LEN
+		    && CharOf(_nc_wacs[which]) != 0) {
+		    ci[actual].Char.UnicodeChar = CharOf(_nc_wacs[which]);
+		} else {
+		    ci[actual].Char.UnicodeChar = ' ';
+		}
+	    }
+	}
+	++actual;
+    }
+
+    loc.X = (SHORT) 0;
+    loc.Y = (SHORT) 0;
+    siz.X = (SHORT) actual;
+    siz.Y = 1;
+
+    rec.Left = (SHORT) x;
+    rec.Top = (SHORT) (y + AdjustY());
+    rec.Right = (SHORT) (x + limit - 1);
+    rec.Bottom = rec.Top;
+
+    return write_screen(CON.hdl, ci, siz, loc, &rec);
+}
+#define con_write(tcb, y, x, str, n) con_write16(tcb, y, x, str, n)
+#else
+static BOOL
+con_write8(TERMINAL_CONTROL_BLOCK * TCB, int y, int x, chtype *str, int n)
+{
+    CHAR_INFO ci[n];
+    COORD loc, siz;
+    SMALL_RECT rec;
+    int i;
+    chtype ch;
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    for (i = 0; i < n; i++) {
+	ch = str[i];
+	ci[i].Char.AsciiChar = ChCharOf(ch);
+	ci[i].Attributes = MapAttr(CON.SBI.wAttributes,
+				   ChAttrOf(ch));
+	if (ChAttrOf(ch) & A_ALTCHARSET) {
+	    if (sp->_acs_map)
+		ci[i].Char.AsciiChar =
+		ChCharOf(NCURSES_SP_NAME(_nc_acs_char) (sp, ChCharOf(ch)));
+	}
+    }
+
+    loc.X = (short) 0;
+    loc.Y = (short) 0;
+    siz.X = (short) n;
+    siz.Y = 1;
+
+    rec.Left = (short) x;
+    rec.Top = (short) y;
+    rec.Right = (short) (x + n - 1);
+    rec.Bottom = rec.Top;
+
+    return write_screen(CON.hdl, ci, siz, loc, &rec);
+}
+#define con_write(tcb, y, x, str, n) con_write8(tcb, y, x, str, n)
+#endif
+
+#if EXP_OPTIMIZE
+/*
+ * Comparing new/current screens, determine the last column-index for a change
+ * beginning on the given row,col position.  Unlike a serial terminal, there is
+ * no cost for "moving" the "cursor" on the line as we update it.
+ */
+static int
+find_end_of_change(SCREEN *sp, int row, int col)
+{
+    int result = col;
+    struct ldat *curdat = CurScreen(sp)->_line + row;
+    struct ldat *newdat = NewScreen(sp)->_line + row;
+
+    while (col <= newdat->lastchar) {
+#if USE_WIDEC_SUPPORT
+	if (isWidecExt(curdat->text[col]) || isWidecExt(newdat->text[col])) {
+	    result = col;
+	} else if (memcmp(&curdat->text[col],
+			  &newdat->text[col],
+			  sizeof(curdat->text[0]))) {
+	    result = col;
+	} else {
+	    break;
+	}
+#else
+	if (curdat->text[col] != newdat->text[col]) {
+	    result = col;
+	} else {
+	    break;
+	}
+#endif
+	++col;
+    }
+    return result;
+}
+
+/*
+ * Given a row,col position at the end of a change-chunk, look for the
+ * beginning of the next change-chunk.
+ */
+static int
+find_next_change(SCREEN *sp, int row, int col)
+{
+    struct ldat *curdat = CurScreen(sp)->_line + row;
+    struct ldat *newdat = NewScreen(sp)->_line + row;
+    int result = newdat->lastchar + 1;
+
+    while (++col <= newdat->lastchar) {
+#if USE_WIDEC_SUPPORT
+	if (isWidecExt(curdat->text[col]) != isWidecExt(newdat->text[col])) {
+	    result = col;
+	    break;
+	} else if (memcmp(&curdat->text[col],
+			  &newdat->text[col],
+			  sizeof(curdat->text[0]))) {
+	    result = col;
+	    break;
+	}
+#else
+	if (curdat->text[col] != newdat->text[col]) {
+	    result = col;
+	    break;
+	}
+#endif
+    }
+    return result;
+}
+
+#define EndChange(first) \
+	find_end_of_change(sp, y, first)
+#define NextChange(last) \
+	find_next_change(sp, y, last)
+
+#endif /* EXP_OPTIMIZE */
+
+#define MARK_NOCHANGE(win,row) \
+		win->_line[row].firstchar = _NOCHANGE; \
+		win->_line[row].lastchar  = _NOCHANGE
+
+static void
+selectActiveHandle(void)
+{
+    if (CON.lastOut != CON.hdl) {
+	CON.lastOut = CON.hdl;
+	SetConsoleActiveScreenBuffer(CON.lastOut);
+    }
+}
+
+static bool
+restore_original_screen(void)
+{
+    COORD bufferCoord;
+    bool result = FALSE;
+    SMALL_RECT save_region = CON.save_region;
+
+    T(("... restoring %s", CON.window_only ? "window" : "entire buffer"));
+
+    bufferCoord.X = (SHORT) (CON.window_only ? CON.SBI.srWindow.Left : 0);
+    bufferCoord.Y = (SHORT) (CON.window_only ? CON.SBI.srWindow.Top : 0);
+
+    if (write_screen(CON.hdl,
+		     CON.save_screen,
+		     CON.save_size,
+		     bufferCoord,
+		     &save_region)) {
+	result = TRUE;
+	mvcur(-1, -1, LINES - 2, 0);
+	T(("... restore original screen contents ok %dx%d (%d,%d - %d,%d)",
+	   CON.save_size.Y,
+	   CON.save_size.X,
+	   save_region.Top,
+	   save_region.Left,
+	   save_region.Bottom,
+	   save_region.Right));
+    } else {
+	T(("... restore original screen contents err"));
+    }
+    return result;
+}
+
+static const char *
+wcon_name(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    (void) TCB;
+    return "win32console";
+}
+
+static int
+wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    int result = ERR;
+    int y, nonempty, n, x0, x1, Width, Height;
+    SCREEN *sp;
+
+    T((T_CALLED("win32con::wcon_doupdate(%p)"), TCB));
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	Width = screen_columns(sp);
+	Height = screen_lines(sp);
+	nonempty = min(Height, NewScreen(sp)->_maxy + 1);
+
+	T(("... %dx%d clear cur:%d new:%d",
+	   Height, Width,
+	   CurScreen(sp)->_clear,
+	   NewScreen(sp)->_clear));
+
+	if (SP_PARM->_endwin) {
+
+	    T(("coming back from shell mode"));
+	    NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
+
+	    NCURSES_SP_NAME(_nc_mvcur_resume) (NCURSES_SP_ARG);
+	    NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
+	    SP_PARM->_mouse_resume(SP_PARM);
+
+	    SP_PARM->_endwin = FALSE;
+	}
+
+	if ((CurScreen(sp)->_clear || NewScreen(sp)->_clear)) {
+	    int x;
+#if USE_WIDEC_SUPPORT
+	    cchar_t empty[Width];
+	    wchar_t blank[2] =
+	    {
+		L' ', L'\0'
+	    };
+
+	    for (x = 0; x < Width; x++)
+		setcchar(&empty[x], blank, 0, 0, 0);
+#else
+	    chtype empty[Width];
+
+	    for (x = 0; x < Width; x++)
+		empty[x] = ' ';
+#endif
+
+	    for (y = 0; y < nonempty; y++) {
+		con_write(TCB, y, 0, empty, Width);
+		memcpy(empty,
+		       CurScreen(sp)->_line[y].text,
+		       (size_t) Width * sizeof(empty[0]));
+	    }
+	    CurScreen(sp)->_clear = FALSE;
+	    NewScreen(sp)->_clear = FALSE;
+	    touchwin(NewScreen(sp));
+	    T(("... cleared %dx%d lines @%d of screen", nonempty, Width,
+	       AdjustY()));
+	}
+
+	for (y = 0; y < nonempty; y++) {
+	    x0 = NewScreen(sp)->_line[y].firstchar;
+	    if (x0 != _NOCHANGE) {
+#if EXP_OPTIMIZE
+		int x2;
+		int limit = NewScreen(sp)->_line[y].lastchar;
+		while ((x1 = EndChange(x0)) <= limit) {
+		    while ((x2 = NextChange(x1)) <= limit && x2 <= (x1 + 2)) {
+			x1 = x2;
+		    }
+		    n = x1 - x0 + 1;
+		    memcpy(&CurScreen(sp)->_line[y].text[x0],
+			   &NewScreen(sp)->_line[y].text[x0],
+			   n * sizeof(CurScreen(sp)->_line[y].text[x0]));
+		    con_write(TCB,
+			      y,
+			      x0,
+			      &CurScreen(sp)->_line[y].text[x0], n);
+		    x0 = NextChange(x1);
+		}
+
+		/* mark line changed successfully */
+		if (y <= NewScreen(sp)->_maxy) {
+		    MARK_NOCHANGE(NewScreen(sp), y);
+		}
+		if (y <= CurScreen(sp)->_maxy) {
+		    MARK_NOCHANGE(CurScreen(sp), y);
+		}
+#else
+		x1 = NewScreen(sp)->_line[y].lastchar;
+		n = x1 - x0 + 1;
+		if (n > 0) {
+		    memcpy(&CurScreen(sp)->_line[y].text[x0],
+			   &NewScreen(sp)->_line[y].text[x0],
+			   (size_t) n * sizeof(CurScreen(sp)->_line[y].text[x0]));
+		    con_write(TCB,
+			      y,
+			      x0,
+			      &CurScreen(sp)->_line[y].text[x0], n);
+
+		    /* mark line changed successfully */
+		    if (y <= NewScreen(sp)->_maxy) {
+			MARK_NOCHANGE(NewScreen(sp), y);
+		    }
+		    if (y <= CurScreen(sp)->_maxy) {
+			MARK_NOCHANGE(CurScreen(sp), y);
+		    }
+		}
+#endif
+	    }
+	}
+
+	/* put everything back in sync */
+	for (y = nonempty; y <= NewScreen(sp)->_maxy; y++) {
+	    MARK_NOCHANGE(NewScreen(sp), y);
+	}
+	for (y = nonempty; y <= CurScreen(sp)->_maxy; y++) {
+	    MARK_NOCHANGE(CurScreen(sp), y);
+	}
+
+	if (!NewScreen(sp)->_leaveok) {
+	    CurScreen(sp)->_curx = NewScreen(sp)->_curx;
+	    CurScreen(sp)->_cury = NewScreen(sp)->_cury;
+
+	    TCB->drv->td_hwcur(TCB,
+			       0, 0,
+			       CurScreen(sp)->_cury, CurScreen(sp)->_curx);
+	}
+	selectActiveHandle();
+	result = OK;
+    }
+    returnCode(result);
+}
+
+static bool
+wcon_CanHandle(TERMINAL_CONTROL_BLOCK * TCB,
+	       const char *tname,
+	       int *errret GCC_UNUSED)
+{
+    bool code = FALSE;
+
+    T((T_CALLED("win32con::wcon_CanHandle(%p)"), TCB));
+
+    assert((TCB != 0) && (tname != 0));
+
+    TCB->magic = WINMAGIC;
+
+    if (tname == 0 || *tname == 0)
+	code = TRUE;
+    else if (tname != 0 && *tname == '#') {
+	/*
+	 * Use "#" (a character which cannot begin a terminal's name) to
+	 * select specific driver from the table.
+	 *
+	 * In principle, we could have more than one non-terminfo driver,
+	 * e.g., "win32gui".
+	 */
+	size_t n = strlen(tname + 1);
+	if (n != 0
+	    && ((strncmp(tname + 1, "win32console", n) == 0)
+		|| (strncmp(tname + 1, "win32con", n) == 0))) {
+	    code = TRUE;
+	}
+    } else if (tname != 0 && stricmp(tname, "unknown") == 0) {
+	code = TRUE;
+    }
+
+    /*
+     * This is intentional, to avoid unnecessary breakage of applications
+     * using <term.h> symbols.
+     */
+    if (code && (TCB->term.type.Booleans == 0)) {
+	_nc_init_termtype(&(TCB->term.type));
+    }
+
+    if (!code) {
+	if (_nc_mingw_isconsole(0))
+	    CON.isTermInfoConsole = TRUE;
+    }
+    returnBool(code);
+}
+
+static int
+wcon_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB,
+		 int beepFlag)
+{
+    SCREEN *sp;
+    int res = ERR;
+
+    int high = (CON.SBI.srWindow.Bottom - CON.SBI.srWindow.Top + 1);
+    int wide = (CON.SBI.srWindow.Right - CON.SBI.srWindow.Left + 1);
+    int max_cells = (high * wide);
+    int i;
+
+    CHAR_INFO this_screen[max_cells];
+    CHAR_INFO that_screen[max_cells];
+    COORD this_size;
+    SMALL_RECT this_region;
+    COORD bufferCoord;
+
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+	this_region.Top = CON.SBI.srWindow.Top;
+	this_region.Left = CON.SBI.srWindow.Left;
+	this_region.Bottom = CON.SBI.srWindow.Bottom;
+	this_region.Right = CON.SBI.srWindow.Right;
+
+	this_size.X = (SHORT) wide;
+	this_size.Y = (SHORT) high;
+
+	bufferCoord.X = this_region.Left;
+	bufferCoord.Y = this_region.Top;
+
+	if (!beepFlag &&
+	    read_screen(CON.hdl,
+			this_screen,
+			this_size,
+			bufferCoord,
+			&this_region)) {
+
+	    memcpy(that_screen, this_screen, sizeof(that_screen));
+
+	    for (i = 0; i < max_cells; i++) {
+		that_screen[i].Attributes = RevAttr(that_screen[i].Attributes);
+	    }
+
+	    write_screen(CON.hdl, that_screen, this_size, bufferCoord, &this_region);
+	    Sleep(200);
+	    write_screen(CON.hdl, this_screen, this_size, bufferCoord, &this_region);
+
+	} else {
+	    MessageBeep(MB_ICONWARNING);	/* MB_OK might be better */
+	}
+	res = OK;
+    }
+    return res;
+}
+
+static int
+wcon_print(TERMINAL_CONTROL_BLOCK * TCB,
+	   char *data GCC_UNUSED,
+	   int len GCC_UNUSED)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    return ERR;
+}
+
+static int
+wcon_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB,
+		   int fg GCC_UNUSED,
+		   int bg GCC_UNUSED)
+{
+    SCREEN *sp;
+    int code = ERR;
+
+    AssertTCB();
+    SetSP();
+
+    return (code);
+}
+
+static bool
+get_SBI(void)
+{
+    bool rc = FALSE;
+    if (GetConsoleScreenBufferInfo(CON.hdl, &(CON.SBI))) {
+	T(("GetConsoleScreenBufferInfo"));
+	T(("... buffer(X:%d Y:%d)",
+	   CON.SBI.dwSize.X,
+	   CON.SBI.dwSize.Y));
+	T(("... window(X:%d Y:%d)",
+	   CON.SBI.dwMaximumWindowSize.X,
+	   CON.SBI.dwMaximumWindowSize.Y));
+	T(("... cursor(X:%d Y:%d)",
+	   CON.SBI.dwCursorPosition.X,
+	   CON.SBI.dwCursorPosition.Y));
+	T(("... display(Top:%d Bottom:%d Left:%d Right:%d)",
+	   CON.SBI.srWindow.Top,
+	   CON.SBI.srWindow.Bottom,
+	   CON.SBI.srWindow.Left,
+	   CON.SBI.srWindow.Right));
+	if (CON.buffered) {
+	    CON.origin.X = 0;
+	    CON.origin.Y = 0;
+	} else {
+	    CON.origin.X = CON.SBI.srWindow.Left;
+	    CON.origin.Y = CON.SBI.srWindow.Top;
+	}
+	rc = TRUE;
+    } else {
+	T(("GetConsoleScreenBufferInfo ERR"));
+    }
+    return rc;
+}
+
+static void
+wcon_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
+	      int fore,
+	      int color,
+	      int (*outc) (SCREEN *, int) GCC_UNUSED)
+{
+    if (okConsoleHandle(TCB)) {
+	WORD a = MapColor(fore, color);
+	a |= (WORD) ((CON.SBI.wAttributes) & (fore ? 0xfff8 : 0xff8f));
+	SetConsoleTextAttribute(CON.hdl, a);
+	get_SBI();
+    }
+}
+
+static bool
+wcon_rescol(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    bool res = FALSE;
+
+    if (okConsoleHandle(TCB)) {
+	WORD a = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN;
+	SetConsoleTextAttribute(CON.hdl, a);
+	get_SBI();
+	res = TRUE;
+    }
+    return res;
+}
+
+static bool
+wcon_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    int result = FALSE;
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+
+    return result;
+}
+
+static int
+wcon_size(TERMINAL_CONTROL_BLOCK * TCB, int *Lines, int *Cols)
+{
+    int result = ERR;
+
+    T((T_CALLED("win32con::wcon_size(%p)"), TCB));
+
+    if (okConsoleHandle(TCB) &&
+	Lines != NULL &&
+	Cols != NULL) {
+	if (CON.buffered) {
+	    *Lines = (int) (CON.SBI.dwSize.Y);
+	    *Cols = (int) (CON.SBI.dwSize.X);
+	} else {
+	    *Lines = (int) (CON.SBI.srWindow.Bottom + 1 -
+			    CON.SBI.srWindow.Top);
+	    *Cols = (int) (CON.SBI.srWindow.Right + 1 -
+			   CON.SBI.srWindow.Left);
+	}
+	result = OK;
+    }
+    returnCode(result);
+}
+
+static int
+wcon_setsize(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED,
+	     int l GCC_UNUSED,
+	     int c GCC_UNUSED)
+{
+    AssertTCB();
+    return ERR;
+}
+
+static int
+wcon_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
+{
+    DWORD dwFlag = 0;
+    tcflag_t iflag;
+    tcflag_t lflag;
+    int result = ERR;
+
+    if (buf != NULL && okConsoleHandle(TCB)) {
+
+	if (setFlag) {
+	    iflag = buf->c_iflag;
+	    lflag = buf->c_lflag;
+
+	    GetConsoleMode(CON.inp, &dwFlag);
+
+	    if (lflag & ICANON)
+		dwFlag |= ENABLE_LINE_INPUT;
+	    else
+		dwFlag &= (DWORD) (~ENABLE_LINE_INPUT);
+
+	    if (lflag & ECHO)
+		dwFlag |= ENABLE_ECHO_INPUT;
+	    else
+		dwFlag &= (DWORD) (~ENABLE_ECHO_INPUT);
+
+	    if (iflag & BRKINT)
+		dwFlag |= ENABLE_PROCESSED_INPUT;
+	    else
+		dwFlag &= (DWORD) (~ENABLE_PROCESSED_INPUT);
+
+	    dwFlag |= ENABLE_MOUSE_INPUT;
+
+	    buf->c_iflag = iflag;
+	    buf->c_lflag = lflag;
+	    SetConsoleMode(CON.inp, dwFlag);
+	    TCB->term.Nttyb = *buf;
+	} else {
+	    iflag = TCB->term.Nttyb.c_iflag;
+	    lflag = TCB->term.Nttyb.c_lflag;
+	    GetConsoleMode(CON.inp, &dwFlag);
+
+	    if (dwFlag & ENABLE_LINE_INPUT)
+		lflag |= ICANON;
+	    else
+		lflag &= (tcflag_t) (~ICANON);
+
+	    if (dwFlag & ENABLE_ECHO_INPUT)
+		lflag |= ECHO;
+	    else
+		lflag &= (tcflag_t) (~ECHO);
+
+	    if (dwFlag & ENABLE_PROCESSED_INPUT)
+		iflag |= BRKINT;
+	    else
+		iflag &= (tcflag_t) (~BRKINT);
+
+	    TCB->term.Nttyb.c_iflag = iflag;
+	    TCB->term.Nttyb.c_lflag = lflag;
+
+	    *buf = TCB->term.Nttyb;
+	}
+	result = OK;
+    }
+    return result;
+}
+
+#define MIN_WIDE 80
+#define MIN_HIGH 24
+
+/*
+ * In "normal" mode, reset the buffer- and window-sizes back to their original values.
+ */
+static void
+set_scrollback(bool normal, CONSOLE_SCREEN_BUFFER_INFO * info)
+{
+    SMALL_RECT rect;
+    COORD coord;
+    bool changed = FALSE;
+
+    T((T_CALLED("win32con::set_scrollback(%s)"),
+       (normal
+	? "normal"
+	: "application")));
+
+    T(("... SBI.srWindow %d,%d .. %d,%d",
+       info->srWindow.Top,
+       info->srWindow.Left,
+       info->srWindow.Bottom,
+       info->srWindow.Right));
+    T(("... SBI.dwSize %dx%d",
+       info->dwSize.Y,
+       info->dwSize.X));
+
+    if (normal) {
+	rect = info->srWindow;
+	coord = info->dwSize;
+	if (memcmp(info, &CON.SBI, sizeof(*info)) != 0) {
+	    changed = TRUE;
+	    CON.SBI = *info;
+	}
+    } else {
+	int high = info->srWindow.Bottom - info->srWindow.Top + 1;
+	int wide = info->srWindow.Right - info->srWindow.Left + 1;
+
+	if (high < MIN_HIGH) {
+	    T(("... height %d < %d", high, MIN_HIGH));
+	    high = MIN_HIGH;
+	    changed = TRUE;
+	}
+	if (wide < MIN_WIDE) {
+	    T(("... width %d < %d", wide, MIN_WIDE));
+	    wide = MIN_WIDE;
+	    changed = TRUE;
+	}
+
+	rect.Left =
+	    rect.Top = 0;
+	rect.Right = (SHORT) (wide - 1);
+	rect.Bottom = (SHORT) (high - 1);
+
+	coord.X = (SHORT) wide;
+	coord.Y = (SHORT) high;
+
+	if (info->dwSize.Y != high ||
+	    info->dwSize.X != wide ||
+	    info->srWindow.Top != 0 ||
+	    info->srWindow.Left != 0) {
+	    changed = TRUE;
+	}
+
+    }
+
+    if (changed) {
+	T(("... coord %d,%d", coord.Y, coord.X));
+	T(("... rect %d,%d - %d,%d",
+	   rect.Top, rect.Left,
+	   rect.Bottom, rect.Right));
+	SetConsoleScreenBufferSize(CON.hdl, coord);	/* dwSize */
+	SetConsoleWindowInfo(CON.hdl, TRUE, &rect);	/* srWindow */
+	get_SBI();
+    }
+    returnVoid;
+}
+
+static int
+wcon_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
+{
+    SCREEN *sp;
+    TERMINAL *_term = (TERMINAL *) TCB;
+    int code = ERR;
+
+    if (okConsoleHandle(TCB)) {
+	sp = TCB->csp;
+
+	T((T_CALLED("win32con::wcon_mode(%p, prog=%d, def=%d)"),
+	   TCB, progFlag, defFlag));
+
+	CON.progMode = progFlag;
+	CON.lastOut = progFlag ? CON.hdl : CON.out;
+	SetConsoleActiveScreenBuffer(CON.lastOut);
+
+	if (progFlag) /* prog mode */  {
+	    if (defFlag) {
+		if ((wcon_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
+		    _term->Nttyb.c_oflag &= (tcflag_t) (~OFLAGS_TABS);
+		    code = OK;
+		}
+	    } else {
+		/* reset_prog_mode */
+		if (wcon_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
+		    if (sp) {
+			if (sp->_keypad_on)
+			    _nc_keypad(sp, TRUE);
+		    }
+		    if (!CON.buffered) {
+			set_scrollback(FALSE, &CON.SBI);
+		    }
+		    code = OK;
+		}
+	    }
+	    T(("... buffered:%d, clear:%d", CON.buffered, CurScreen(sp)->_clear));
+	} else {		/* shell mode */
+	    if (defFlag) {
+		/* def_shell_mode */
+		if (wcon_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
+		    code = OK;
+		}
+	    } else {
+		/* reset_shell_mode */
+		if (sp) {
+		    _nc_keypad(sp, FALSE);
+		    NCURSES_SP_NAME(_nc_flush) (sp);
+		}
+		code = wcon_sgmode(TCB, TRUE, &(_term->Ottyb));
+		if (!CON.buffered) {
+		    set_scrollback(TRUE, &CON.save_SBI);
+		    if (!restore_original_screen())
+			code = ERR;
+		}
+		SetConsoleCursorInfo(CON.hdl, &CON.save_CI);
+	    }
+	}
+
+    }
+    returnCode(code);
+}
+
+static void
+wcon_screen_init(SCREEN *sp GCC_UNUSED)
+{
+}
+
+static void
+wcon_wrap(SCREEN *sp GCC_UNUSED)
+{
+}
+
+static int
+rkeycompare(const void *el1, const void *el2)
+{
+    WORD key1 = (LOWORD((*((const LONG *) el1)))) & 0x7fff;
+    WORD key2 = (LOWORD((*((const LONG *) el2)))) & 0x7fff;
+
+    return ((key1 < key2) ? -1 : ((key1 == key2) ? 0 : 1));
+}
+
+static int
+keycompare(const void *el1, const void *el2)
+{
+    WORD key1 = HIWORD((*((const LONG *) el1)));
+    WORD key2 = HIWORD((*((const LONG *) el2)));
+
+    return ((key1 < key2) ? -1 : ((key1 == key2) ? 0 : 1));
+}
+
+static int
+MapKey(WORD vKey)
+{
+    WORD nKey = 0;
+    void *res;
+    LONG key = GenMap(vKey, 0);
+    int code = -1;
+
+    res = bsearch(&key,
+		  CON.map,
+		  (size_t) (N_INI + FKEYS),
+		  sizeof(keylist[0]),
+		  keycompare);
+    if (res) {
+	key = *((LONG *) res);
+	nKey = LOWORD(key);
+	code = (int) (nKey & 0x7fff);
+	if (nKey & 0x8000)
+	    code = -code;
+    }
+    return code;
+}
+
+static int
+AnsiKey(WORD vKey)
+{
+    WORD nKey = 0;
+    void *res;
+    LONG key = GenMap(vKey, 0);
+    int code = -1;
+
+    res = bsearch(&key,
+		  CON.ansi_map,
+		  (size_t) (N_INI + FKEYS),
+		  sizeof(keylist[0]),
+		  keycompare);
+    if (res) {
+	key = *((LONG *) res);
+	nKey = LOWORD(key);
+	code = (int) (nKey & 0x7fff);
+	if (nKey & 0x8000)
+	    code = -code;
+    }
+    return code;
+}
+
+static void
+wcon_release(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    T((T_CALLED("win32con::wcon_release(%p)"), TCB));
+
+    AssertTCB();
+    if (TCB->prop)
+	free(TCB->prop);
+
+    returnVoid;
+}
+
+static bool
+read_screen_data(void)
+{
+    bool result = FALSE;
+    COORD bufferCoord;
+    size_t want;
+
+    CON.save_size.X = (SHORT) (CON.save_region.Right
+			       - CON.save_region.Left + 1);
+    CON.save_size.Y = (SHORT) (CON.save_region.Bottom
+			       - CON.save_region.Top + 1);
+
+    want = (size_t) (CON.save_size.X * CON.save_size.Y);
+
+    if ((CON.save_screen = malloc(want * sizeof(CHAR_INFO))) != 0) {
+	bufferCoord.X = (SHORT) (CON.window_only ? CON.SBI.srWindow.Left : 0);
+	bufferCoord.Y = (SHORT) (CON.window_only ? CON.SBI.srWindow.Top : 0);
+
+	T(("... reading console %s %dx%d into %d,%d - %d,%d at %d,%d",
+	   CON.window_only ? "window" : "buffer",
+	   CON.save_size.Y, CON.save_size.X,
+	   CON.save_region.Top,
+	   CON.save_region.Left,
+	   CON.save_region.Bottom,
+	   CON.save_region.Right,
+	   bufferCoord.Y,
+	   bufferCoord.X));
+
+	if (read_screen(CON.hdl,
+			CON.save_screen,
+			CON.save_size,
+			bufferCoord,
+			&CON.save_region)) {
+	    result = TRUE;
+	} else {
+	    T((" error %#lx", (unsigned long) GetLastError()));
+	    FreeAndNull(CON.save_screen);
+	}
+    }
+
+    return result;
+}
+
+/*
+ * Attempt to save the screen contents.  PDCurses does this if
+ * PDC_RESTORE_SCREEN is set, giving the same visual appearance on
+ * restoration as if the library had allocated a console buffer.  MSDN
+ * says that the data which can be read is limited to 64Kb (and may be
+ * less).
+ */
+static bool
+save_original_screen(void)
+{
+    bool result = FALSE;
+
+    CON.save_region.Top = 0;
+    CON.save_region.Left = 0;
+    CON.save_region.Bottom = (SHORT) (CON.SBI.dwSize.Y - 1);
+    CON.save_region.Right = (SHORT) (CON.SBI.dwSize.X - 1);
+
+    if (read_screen_data()) {
+	result = TRUE;
+    } else {
+
+	CON.save_region.Top = CON.SBI.srWindow.Top;
+	CON.save_region.Left = CON.SBI.srWindow.Left;
+	CON.save_region.Bottom = CON.SBI.srWindow.Bottom;
+	CON.save_region.Right = CON.SBI.srWindow.Right;
+
+	CON.window_only = TRUE;
+
+	if (read_screen_data()) {
+	    result = TRUE;
+	}
+    }
+
+    T(("... save original screen contents %s", result ? "ok" : "err"));
+    return result;
+}
+
+static void
+wcon_init(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    T((T_CALLED("win32con::wcon_init(%p)"), TCB));
+
+    AssertTCB();
+
+    if (TCB) {
+	if (!InitConsole()) {
+	    returnVoid;
+	}
+
+	TCB->info.initcolor = TRUE;
+	TCB->info.canchange = FALSE;
+	TCB->info.hascolor = TRUE;
+	TCB->info.caninit = TRUE;
+
+	TCB->info.maxpairs = NUMPAIRS;
+	TCB->info.maxcolors = 8;
+	TCB->info.numlabels = 0;
+	TCB->info.labelwidth = 0;
+	TCB->info.labelheight = 0;
+	TCB->info.nocolorvideo = 1;
+	TCB->info.tabsize = 8;
+
+	TCB->info.numbuttons = CON.numButtons;
+	TCB->info.defaultPalette = _nc_cga_palette;
+
+    }
+    returnVoid;
+}
+
+static void
+wcon_initpair(TERMINAL_CONTROL_BLOCK * TCB,
+	      int pair,
+	      int f,
+	      int b)
+{
+    SCREEN *sp;
+
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	if ((pair > 0) && (pair < NUMPAIRS) && (f >= 0) && (f < 8)
+	    && (b >= 0) && (b < 8)) {
+	    CON.pairs[pair] = MapColor(true, f) | MapColor(false, b);
+	}
+    }
+}
+
+static void
+wcon_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
+	       int color GCC_UNUSED,
+	       int r GCC_UNUSED,
+	       int g GCC_UNUSED,
+	       int b GCC_UNUSED)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+}
+
+static void
+wcon_do_color(TERMINAL_CONTROL_BLOCK * TCB,
+	      int old_pair GCC_UNUSED,
+	      int pair GCC_UNUSED,
+	      int reverse GCC_UNUSED,
+	      int (*outc) (SCREEN *, int) GCC_UNUSED
+)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+}
+
+static void
+wcon_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    SCREEN *sp;
+
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	sp->_mouse_type = M_TERM_DRIVER;
+    }
+}
+
+static int
+wcon_testmouse(TERMINAL_CONTROL_BLOCK * TCB, int delay)
+{
+    int rc = 0;
+    SCREEN *sp;
+
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	if (sp->_drv_mouse_head < sp->_drv_mouse_tail) {
+	    rc = TW_MOUSE;
+	} else {
+	    rc = TCBOf(sp)->drv->td_twait(TCBOf(sp),
+					  TWAIT_MASK,
+					  delay,
+					  (int *) 0
+					  EVENTLIST_2nd(evl));
+	}
+    }
+
+    return rc;
+}
+
+static int
+wcon_mvcur(TERMINAL_CONTROL_BLOCK * TCB,
+	   int yold GCC_UNUSED, int xold GCC_UNUSED,
+	   int y, int x)
+{
+    int ret = ERR;
+    if (okConsoleHandle(TCB)) {
+	COORD loc;
+	loc.X = (short) x;
+	loc.Y = (short) (y + AdjustY());
+	SetConsoleCursorPosition(CON.hdl, loc);
+	ret = OK;
+    }
+    return ret;
+}
+
+static void
+wcon_hwlabel(TERMINAL_CONTROL_BLOCK * TCB,
+	     int labnum GCC_UNUSED,
+	     char *text GCC_UNUSED)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+}
+
+static void
+wcon_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB,
+		  int OnFlag GCC_UNUSED)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+}
+
+static chtype
+wcon_conattr(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
+{
+    chtype res = A_NORMAL;
+    res |= (A_BOLD | A_DIM | A_REVERSE | A_STANDOUT | A_COLOR);
+    return res;
+}
+
+static void
+wcon_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    SCREEN *sp;
+
+    AssertTCB();
+    SetSP();
+}
+
+static void
+wcon_initacs(TERMINAL_CONTROL_BLOCK * TCB,
+	     chtype *real_map GCC_UNUSED,
+	     chtype *fake_map GCC_UNUSED)
+{
+#define DATA(a,b) { a, b }
+    static struct {
+	int acs_code;
+	int use_code;
+    } table[] = {
+	DATA('a', 0xb1),	/* ACS_CKBOARD  */
+	    DATA('f', 0xf8),	/* ACS_DEGREE   */
+	    DATA('g', 0xf1),	/* ACS_PLMINUS  */
+	    DATA('j', 0xd9),	/* ACS_LRCORNER */
+	    DATA('l', 0xda),	/* ACS_ULCORNER */
+	    DATA('k', 0xbf),	/* ACS_URCORNER */
+	    DATA('m', 0xc0),	/* ACS_LLCORNER */
+	    DATA('n', 0xc5),	/* ACS_PLUS     */
+	    DATA('q', 0xc4),	/* ACS_HLINE    */
+	    DATA('t', 0xc3),	/* ACS_LTEE     */
+	    DATA('u', 0xb4),	/* ACS_RTEE     */
+	    DATA('v', 0xc1),	/* ACS_BTEE     */
+	    DATA('w', 0xc2),	/* ACS_TTEE     */
+	    DATA('x', 0xb3),	/* ACS_VLINE    */
+	    DATA('y', 0xf3),	/* ACS_LEQUAL   */
+	    DATA('z', 0xf2),	/* ACS_GEQUAL   */
+	    DATA('0', 0xdb),	/* ACS_BLOCK    */
+	    DATA('{', 0xe3),	/* ACS_PI       */
+	    DATA('}', 0x9c),	/* ACS_STERLING */
+	    DATA(',', 0xae),	/* ACS_LARROW   */
+	    DATA('+', 0xaf),	/* ACS_RARROW   */
+	    DATA('~', 0xf9),	/* ACS_BULLET   */
+    };
+#undef DATA
+    unsigned n;
+
+    SCREEN *sp;
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	for (n = 0; n < SIZEOF(table); ++n) {
+	    real_map[table[n].acs_code] = (chtype) table[n].use_code | A_ALTCHARSET;
+	    if (sp != 0)
+		sp->_screen_acs_map[table[n].acs_code] = TRUE;
+	}
+    }
+}
+
+static ULONGLONG
+tdiff(FILETIME fstart, FILETIME fend)
+{
+    ULARGE_INTEGER ustart;
+    ULARGE_INTEGER uend;
+    ULONGLONG diff;
+
+    ustart.LowPart = fstart.dwLowDateTime;
+    ustart.HighPart = fstart.dwHighDateTime;
+    uend.LowPart = fend.dwLowDateTime;
+    uend.HighPart = fend.dwHighDateTime;
+
+    diff = (uend.QuadPart - ustart.QuadPart) / 10000;
+    return diff;
+}
+
+static int
+Adjust(int milliseconds, int diff)
+{
+    if (milliseconds != INFINITY) {
+	milliseconds -= diff;
+	if (milliseconds < 0)
+	    milliseconds = 0;
+    }
+    return milliseconds;
+}
+
+#define BUTTON_MASK (FROM_LEFT_1ST_BUTTON_PRESSED | \
+		     FROM_LEFT_2ND_BUTTON_PRESSED | \
+		     FROM_LEFT_3RD_BUTTON_PRESSED | \
+		     FROM_LEFT_4TH_BUTTON_PRESSED | \
+		     RIGHTMOST_BUTTON_PRESSED)
+
+static int
+decode_mouse(SCREEN *sp, int mask)
+{
+    int result = 0;
+
+    (void) sp;
+    assert(sp && console_initialized);
+
+    if (mask & FROM_LEFT_1ST_BUTTON_PRESSED)
+	result |= BUTTON1_PRESSED;
+    if (mask & FROM_LEFT_2ND_BUTTON_PRESSED)
+	result |= BUTTON2_PRESSED;
+    if (mask & FROM_LEFT_3RD_BUTTON_PRESSED)
+	result |= BUTTON3_PRESSED;
+    if (mask & FROM_LEFT_4TH_BUTTON_PRESSED)
+	result |= BUTTON4_PRESSED;
+
+    if (mask & RIGHTMOST_BUTTON_PRESSED) {
+	switch (CON.numButtons) {
+	case 1:
+	    result |= BUTTON1_PRESSED;
+	    break;
+	case 2:
+	    result |= BUTTON2_PRESSED;
+	    break;
+	case 3:
+	    result |= BUTTON3_PRESSED;
+	    break;
+	case 4:
+	    result |= BUTTON4_PRESSED;
+	    break;
+	}
+    }
+
+    return result;
+}
+
+static int
+console_twait(
+		 SCREEN *sp,
+		 HANDLE fd,
+		 int mode,
+		 int milliseconds,
+		 int *timeleft
+		 EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    INPUT_RECORD inp_rec;
+    BOOL b;
+    DWORD nRead = 0, rc = (DWORD) (-1);
+    int code = 0;
+    FILETIME fstart;
+    FILETIME fend;
+    int diff;
+    bool isImmed = (milliseconds == 0);
+
+#define CONSUME() ReadConsoleInput(fd,&inp_rec,1,&nRead)
+
+    assert(sp);
+
+    TR(TRACE_IEVENT, ("start twait: %d milliseconds, mode: %d",
+		      milliseconds, mode));
+
+    if (milliseconds < 0)
+	milliseconds = INFINITY;
+
+    memset(&inp_rec, 0, sizeof(inp_rec));
+
+    while (true) {
+	GetSystemTimeAsFileTime(&fstart);
+	rc = WaitForSingleObject(fd, (DWORD) milliseconds);
+	GetSystemTimeAsFileTime(&fend);
+	diff = (int) tdiff(fstart, fend);
+	milliseconds = Adjust(milliseconds, diff);
+
+	if (!isImmed && milliseconds <= 0)
+	    break;
+
+	if (rc == WAIT_OBJECT_0) {
+	    if (mode) {
+		b = GetNumberOfConsoleInputEvents(fd, &nRead);
+		if (b && nRead > 0) {
+		    b = PeekConsoleInput(fd, &inp_rec, 1, &nRead);
+		    if (b && nRead > 0) {
+			switch (inp_rec.EventType) {
+			case KEY_EVENT:
+			    if (mode & TW_INPUT) {
+				WORD vk = inp_rec.Event.KeyEvent.wVirtualKeyCode;
+				char ch = inp_rec.Event.KeyEvent.uChar.AsciiChar;
+
+				if (inp_rec.Event.KeyEvent.bKeyDown) {
+				    if (0 == ch) {
+					int nKey = MapKey(vk);
+					if (nKey < 0) {
+					    CONSUME();
+					    continue;
+					}
+				    }
+				    code = TW_INPUT;
+				    goto end;
+				} else {
+				    CONSUME();
+				}
+			    }
+			    continue;
+			case MOUSE_EVENT:
+			    if (decode_mouse(sp,
+					     (inp_rec.Event.MouseEvent.dwButtonState
+					      & BUTTON_MASK)) == 0) {
+				CONSUME();
+			    } else if (mode & TW_MOUSE) {
+				code = TW_MOUSE;
+				goto end;
+			    }
+			    continue;
+			    /* e.g., FOCUS_EVENT */
+			default:
+			    CONSUME();
+			    selectActiveHandle();
+			    continue;
+			}
+		    }
+		}
+	    }
+	    continue;
+	} else {
+	    if (rc != WAIT_TIMEOUT) {
+		code = -1;
+		break;
+	    } else {
+		code = 0;
+		break;
+	    }
+	}
+    }
+  end:
+
+    TR(TRACE_IEVENT, ("end twait: returned %d (%d), remaining time %d msec",
+		      code, errno, milliseconds));
+
+    if (timeleft)
+	*timeleft = milliseconds;
+
+    return code;
+}
+
+static int
+wcon_twait(TERMINAL_CONTROL_BLOCK * TCB,
+	   int mode,
+	   int milliseconds,
+	   int *timeleft
+	   EVENTLIST_2nd(_nc_eventlist * evl))
+{
+    SCREEN *sp;
+    int code = 0;
+
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	code = console_twait(sp,
+			     CON.inp,
+			     mode,
+			     milliseconds,
+			     timeleft EVENTLIST_2nd(_nc_eventlist * evl));
+    }
+    return code;
+}
+
+static bool
+handle_mouse(SCREEN *sp, MOUSE_EVENT_RECORD mer)
+{
+    MEVENT work;
+    bool result = FALSE;
+
+    assert(sp);
+
+    sp->_drv_mouse_old_buttons = sp->_drv_mouse_new_buttons;
+    sp->_drv_mouse_new_buttons = mer.dwButtonState & BUTTON_MASK;
+
+    /*
+     * We're only interested if the button is pressed or released.
+     * FIXME: implement continuous event-tracking.
+     */
+    if (sp->_drv_mouse_new_buttons != sp->_drv_mouse_old_buttons) {
+
+	memset(&work, 0, sizeof(work));
+
+	if (sp->_drv_mouse_new_buttons) {
+
+	    work.bstate |= (mmask_t) decode_mouse(sp, sp->_drv_mouse_new_buttons);
+
+	} else {
+
+	    /* cf: BUTTON_PRESSED, BUTTON_RELEASED */
+	    work.bstate |= (mmask_t) (decode_mouse(sp,
+						   sp->_drv_mouse_old_buttons)
+				      >> 1);
+
+	    result = TRUE;
+	}
+
+	work.x = mer.dwMousePosition.X;
+	work.y = mer.dwMousePosition.Y - AdjustY();
+
+	sp->_drv_mouse_fifo[sp->_drv_mouse_tail] = work;
+	sp->_drv_mouse_tail += 1;
+    }
+
+    return result;
+}
+
+static int
+wcon_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
+{
+    SCREEN *sp;
+    int n = -1;
+
+    T((T_CALLED("win32con::wcon_read(%p)"), TCB));
+
+    assert(buf);
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	n = _nc_mingw_console_read(sp, CON.inp, buf);
+    }
+    returnCode(n);
+}
+
+static int
+wcon_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int ms)
+{
+    T((T_CALLED("win32con::wcon_nap(%p, %d)"), TCB, ms));
+    Sleep((DWORD) ms);
+    returnCode(OK);
+}
+
+static int
+wcon_cursorSet(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int mode)
+{
+    int res = -1;
+
+    T((T_CALLED("win32con:wcon_cursorSet(%d)"), mode));
+    if (okConsoleHandle(TCB)) {
+	CONSOLE_CURSOR_INFO this_CI = CON.save_CI;
+	switch (mode) {
+	case 0:
+	    this_CI.bVisible = FALSE;
+	    break;
+	case 1:
+	    break;
+	case 2:
+	    this_CI.dwSize = 100;
+	    break;
+	}
+	SetConsoleCursorInfo(CON.hdl, &this_CI);
+    }
+    returnCode(res);
+}
+
+static bool
+wcon_kyExist(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int keycode)
+{
+    WORD nKey;
+    void *res;
+    bool found = FALSE;
+    LONG key = GenMap(0, (WORD) keycode);
+
+    T((T_CALLED("win32con::wcon_kyExist(%d)"), keycode));
+    res = bsearch(&key,
+		  CON.rmap,
+		  (size_t) (N_INI + FKEYS),
+		  sizeof(keylist[0]),
+		  rkeycompare);
+    if (res) {
+	key = *((LONG *) res);
+	nKey = LOWORD(key);
+	if (!(nKey & 0x8000))
+	    found = TRUE;
+    }
+    returnCode(found);
+}
+
+static int
+wcon_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag GCC_UNUSED)
+{
+    SCREEN *sp;
+    int code = ERR;
+
+    T((T_CALLED("win32con::wcon_kpad(%p, %d)"), TCB, flag));
+
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	if (sp) {
+	    code = OK;
+	}
+    }
+    returnCode(code);
+}
+
+static int
+wcon_keyok(TERMINAL_CONTROL_BLOCK * TCB,
+	   int keycode,
+	   int flag)
+{
+    int code = ERR;
+    SCREEN *sp;
+    WORD nKey;
+    WORD vKey;
+    void *res;
+    LONG key = GenMap(0, (WORD) keycode);
+
+    T((T_CALLED("win32con::wcon_keyok(%p, %d, %d)"), TCB, keycode, flag));
+
+    if (okConsoleHandle(TCB)) {
+	SetSP();
+
+	if (sp) {
+	    res = bsearch(&key,
+			  CON.rmap,
+			  (size_t) (N_INI + FKEYS),
+			  sizeof(keylist[0]),
+			  rkeycompare);
+	    if (res) {
+		key = *((LONG *) res);
+		vKey = HIWORD(key);
+		nKey = (LOWORD(key)) & 0x7fff;
+		if (!flag)
+		    nKey |= 0x8000;
+		*(LONG *) res = GenMap(vKey, nKey);
+	    }
+	}
+    }
+    returnCode(code);
+}
+
+NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_WIN_DRIVER = {
+    FALSE,
+	wcon_name,		/* Name */
+	wcon_CanHandle,		/* CanHandle */
+	wcon_init,		/* init */
+	wcon_release,		/* release */
+	wcon_size,		/* size */
+	wcon_sgmode,		/* sgmode */
+	wcon_conattr,		/* conattr */
+	wcon_mvcur,		/* hwcur */
+	wcon_mode,		/* mode */
+	wcon_rescol,		/* rescol */
+	wcon_rescolors,		/* rescolors */
+	wcon_setcolor,		/* color */
+	wcon_dobeepflash,	/* DoBeepFlash */
+	wcon_initpair,		/* initpair */
+	wcon_initcolor,		/* initcolor */
+	wcon_do_color,		/* docolor */
+	wcon_initmouse,		/* initmouse */
+	wcon_testmouse,		/* testmouse */
+	wcon_setfilter,		/* setfilter */
+	wcon_hwlabel,		/* hwlabel */
+	wcon_hwlabelOnOff,	/* hwlabelOnOff */
+	wcon_doupdate,		/* update */
+	wcon_defaultcolors,	/* defaultcolors */
+	wcon_print,		/* print */
+	wcon_size,		/* getsize */
+	wcon_setsize,		/* setsize */
+	wcon_initacs,		/* initacs */
+	wcon_screen_init,	/* scinit */
+	wcon_wrap,		/* scexit */
+	wcon_twait,		/* twait */
+	wcon_read,		/* read */
+	wcon_nap,		/* nap */
+	wcon_kpad,		/* kpad */
+	wcon_keyok,		/* kyOk */
+	wcon_kyExist,		/* kyExist */
+	wcon_cursorSet		/* cursorSet */
+};
+
+/* --------------------------------------------------------- */
+
+static HANDLE
+get_handle(int fd)
+{
+    intptr_t value = _get_osfhandle(fd);
+    return (HANDLE) value;
+}
+
+#if WINVER >= 0x0600
+/*   This function tests, whether or not the ncurses application
+     is running as a descendant of MSYS2/cygwin mintty terminal
+     application. mintty doesn't use Windows Console for it's screen
+     I/O, so the native Windows _isatty doesn't recognize it as
+     character device. But we can discover we are at the end of an
+     Pipe and can query to server side of the pipe, looking whether
+     or not this is mintty.
+ */
+static int
+_ismintty(int fd, LPHANDLE pMinTTY)
+{
+    HANDLE handle = get_handle(fd);
+    DWORD dw;
+    int code = 0;
+
+    T((T_CALLED("win32con::_ismintty(%d, %p)"), fd, pMinTTY));
+
+    if (handle != INVALID_HANDLE_VALUE) {
+	dw = GetFileType(handle);
+	if (dw == FILE_TYPE_PIPE) {
+	    if (GetNamedPipeInfo(handle, 0, 0, 0, 0)) {
+		ULONG pPid;
+		/* Requires NT6 */
+		if (GetNamedPipeServerProcessId(handle, &pPid)) {
+		    TCHAR buf[MAX_PATH];
+		    DWORD len = 0;
+		    /* These security attributes may allow us to
+		       create a remote thread in mintty to manipulate
+		       the terminal state remotely */
+		    HANDLE pHandle = OpenProcess(
+						    PROCESS_CREATE_THREAD
+						    | PROCESS_QUERY_INFORMATION
+						    | PROCESS_VM_OPERATION
+						    | PROCESS_VM_WRITE
+						    | PROCESS_VM_READ,
+						    FALSE,
+						    pPid);
+		    if (pMinTTY)
+			*pMinTTY = INVALID_HANDLE_VALUE;
+		    if (pHandle != INVALID_HANDLE_VALUE) {
+			if ((len = GetProcessImageFileName(
+							      pHandle,
+							      buf,
+							      (DWORD)
+							      array_length(buf)))) {
+			    TCHAR *pos = _tcsrchr(buf, _T('\\'));
+			    if (pos) {
+				pos++;
+				if (_tcsnicmp(pos, _TEXT("mintty.exe"), 10)
+				    == 0) {
+				    if (pMinTTY)
+					*pMinTTY = pHandle;
+				    code = 1;
+				}
+			    }
+			}
+		    }
+		}
+	    }
+	}
+    }
+    returnCode(code);
+}
+#endif
+
+/*   Borrowed from ansicon project.
+     Check whether or not an I/O handle is associated with
+     a Windows console.
+*/
+static BOOL
+IsConsoleHandle(HANDLE hdl)
+{
+    DWORD dwFlag = 0;
+    BOOL result;
+
+    if (!GetConsoleMode(hdl, &dwFlag)) {
+	result = (int) WriteConsoleA(hdl, NULL, 0, &dwFlag, NULL);
+    } else {
+	result = (int) (dwFlag & ENABLE_PROCESSED_OUTPUT);
+    }
+    return result;
+}
+
+/*   Our replacement for the systems _isatty to include also
+     a test for mintty. This is called from the NC_ISATTY macro
+     defined in curses.priv.h
+ */
+int
+_nc_mingw_isatty(int fd)
+{
+    int result = 0;
+
+#ifdef __MING32__
+#define SysISATTY(fd) _isatty(fd)
+#else
+#define SysISATTY(fd) isatty(fd)
+#endif
+    if (SysISATTY(fd)) {
+	result = 1;
+    } else {
+#if WINVER >= 0x0600
+	result = _ismintty(fd, NULL);
+#endif
+    }
+    return result;
+}
+
+/*   This is used when running in terminfo mode to discover,
+     whether or not the "terminal" is actually a Windows
+     Console. It's the responsibilty of the console to deal
+     with the terminal escape sequences that are sent by
+     terminfo.
+ */
+int
+_nc_mingw_isconsole(int fd)
+{
+    HANDLE hdl = get_handle(fd);
+    int code = 0;
+
+    T((T_CALLED("win32con::_nc_mingw_isconsole(%d)"), fd));
+
+    code = (int) IsConsoleHandle(hdl);
+
+    returnCode(code);
+}
+
+#define TC_PROLOGUE(fd) \
+    SCREEN *sp;                                               \
+    TERMINAL *term = 0;                                       \
+    int code = ERR;                                           \
+    if (_nc_screen_chain == 0)                                \
+        return 0;                                             \
+    for (each_screen(sp)) {                                   \
+        if (sp->_term && (sp->_term->Filedes == fd)) {        \
+            term = sp->_term;                                 \
+            break;                                            \
+        }                                                     \
+    }                                                         \
+    assert(term != 0)
+
+int
+_nc_mingw_tcsetattr(
+		       int fd,
+		       int optional_action GCC_UNUSED,
+		       const struct termios *arg)
+{
+    TC_PROLOGUE(fd);
+
+    if (_nc_mingw_isconsole(fd)) {
+	DWORD dwFlag = 0;
+	HANDLE ofd = get_handle(fd);
+	if (ofd != INVALID_HANDLE_VALUE) {
+	    if (arg) {
+		if (arg->c_lflag & ICANON)
+		    dwFlag |= ENABLE_LINE_INPUT;
+		else
+		    dwFlag = dwFlag & (DWORD) (~ENABLE_LINE_INPUT);
+
+		if (arg->c_lflag & ECHO)
+		    dwFlag = dwFlag | ENABLE_ECHO_INPUT;
+		else
+		    dwFlag = dwFlag & (DWORD) (~ENABLE_ECHO_INPUT);
+
+		if (arg->c_iflag & BRKINT)
+		    dwFlag |= ENABLE_PROCESSED_INPUT;
+		else
+		    dwFlag = dwFlag & (DWORD) (~ENABLE_PROCESSED_INPUT);
+	    }
+	    dwFlag |= ENABLE_MOUSE_INPUT;
+	    SetConsoleMode(ofd, dwFlag);
+	    code = OK;
+	}
+    }
+    if (arg)
+	term->Nttyb = *arg;
+
+    return code;
+}
+
+int
+_nc_mingw_tcgetattr(int fd, struct termios *arg)
+{
+    TC_PROLOGUE(fd);
+
+    if (_nc_mingw_isconsole(fd)) {
+	if (arg)
+	    *arg = term->Nttyb;
+    }
+    return code;
+}
+
+int
+_nc_mingw_tcflush(int fd, int queue)
+{
+    TC_PROLOGUE(fd);
+    (void) term;
+
+    if (_nc_mingw_isconsole(fd)) {
+	if (queue == TCIFLUSH) {
+	    BOOL b = FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
+	    if (!b)
+		return (int) GetLastError();
+	}
+    }
+    return code;
+}
+
+int
+_nc_mingw_testmouse(
+		       SCREEN *sp,
+		       HANDLE fd,
+		       int delay)
+{
+    int rc = 0;
+
+    assert(sp);
+
+    if (sp->_drv_mouse_head < sp->_drv_mouse_tail) {
+	rc = TW_MOUSE;
+    } else {
+	rc = console_twait(sp,
+			   fd,
+			   TWAIT_MASK,
+			   delay,
+			   (int *) 0
+			   EVENTLIST_2nd(evl));
+    }
+    return rc;
+}
+
+int
+_nc_mingw_console_read(
+			  SCREEN *sp,
+			  HANDLE fd,
+			  int *buf)
+{
+    int rc = -1;
+    INPUT_RECORD inp_rec;
+    BOOL b;
+    DWORD nRead;
+    WORD vk;
+
+    assert(sp);
+    assert(buf);
+
+    memset(&inp_rec, 0, sizeof(inp_rec));
+
+    T((T_CALLED("_nc_mingw_console_read(%p)"), sp));
+
+    while ((b = ReadConsoleInput(fd, &inp_rec, 1, &nRead))) {
+	if (b && nRead > 0) {
+	    if (rc < 0)
+		rc = 0;
+	    rc += nRead;
+	    if (inp_rec.EventType == KEY_EVENT) {
+		if (!inp_rec.Event.KeyEvent.bKeyDown)
+		    continue;
+		*buf = (int) inp_rec.Event.KeyEvent.uChar.AsciiChar;
+		vk = inp_rec.Event.KeyEvent.wVirtualKeyCode;
+		/*
+		 * There are 24 virtual function-keys, and typically
+		 * 12 function-keys on a keyboard.  Use the shift-modifier
+		 * to provide the remaining 12 keys.
+		 */
+		if (vk >= VK_F1 && vk <= VK_F12) {
+		    if (inp_rec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) {
+			vk = (WORD) (vk + 12);
+		    }
+		}
+		if (*buf == 0) {
+		    int key = MapKey(vk);
+		    if (key < 0)
+			continue;
+		    if (sp->_keypad_on) {
+			*buf = key;
+		    } else {
+			ungetch('\0');
+			*buf = AnsiKey(vk);
+		    }
+		}
+		break;
+	    } else if (inp_rec.EventType == MOUSE_EVENT) {
+		if (handle_mouse(sp,
+				 inp_rec.Event.MouseEvent)) {
+		    *buf = KEY_MOUSE;
+		    break;
+		}
+	    }
+	    continue;
+	}
+    }
+    returnCode(rc);
+}
+
+static bool
+InitConsole(void)
+{
+    /* initalize once, or not at all */
+    if (!console_initialized) {
+	int i;
+	DWORD num_buttons;
+	WORD a;
+	BOOL buffered = TRUE;
+	BOOL b;
+
+	START_TRACE();
+	if (_nc_mingw_isatty(0)) {
+	    CON.isMinTTY = TRUE;
+	}
+
+	for (i = 0; i < (N_INI + FKEYS); i++) {
+	    if (i < N_INI) {
+		CON.rmap[i] = CON.map[i] =
+		    (DWORD) keylist[i];
+		CON.ansi_map[i] = (DWORD) ansi_keys[i];
+	    } else {
+		CON.rmap[i] = CON.map[i] =
+		    (DWORD) GenMap((VK_F1 + (i - N_INI)),
+				   (KEY_F(1) + (i - N_INI)));
+		CON.ansi_map[i] =
+		    (DWORD) GenMap((VK_F1 + (i - N_INI)),
+				   (';' + (i - N_INI)));
+	    }
+	}
+	qsort(CON.ansi_map,
+	      (size_t) (MAPSIZE),
+	      sizeof(keylist[0]),
+	      keycompare);
+	qsort(CON.map,
+	      (size_t) (MAPSIZE),
+	      sizeof(keylist[0]),
+	      keycompare);
+	qsort(CON.rmap,
+	      (size_t) (MAPSIZE),
+	      sizeof(keylist[0]),
+	      rkeycompare);
+
+	if (GetNumberOfConsoleMouseButtons(&num_buttons)) {
+	    CON.numButtons = (int) num_buttons;
+	} else {
+	    CON.numButtons = 1;
+	}
+
+	a = MapColor(true, COLOR_WHITE) | MapColor(false, COLOR_BLACK);
+	for (i = 0; i < NUMPAIRS; i++)
+	    CON.pairs[i] = a;
+
+	CON.inp = GetStdHandle(STD_INPUT_HANDLE);
+	CON.out = GetStdHandle(STD_OUTPUT_HANDLE);
+
+	b = AllocConsole();
+
+	if (!b)
+	    b = AttachConsole(ATTACH_PARENT_PROCESS);
+
+	if (getenv("NCGDB") || getenv("NCURSES_CONSOLE2")) {
+	    T(("... will not buffer console"));
+	    buffered = FALSE;
+	    CON.hdl = CON.out;
+	} else {
+	    T(("... creating console buffer"));
+	    CON.hdl = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
+						0,
+						NULL,
+						CONSOLE_TEXTMODE_BUFFER,
+						NULL);
+	}
+
+	if (CON.hdl != INVALID_HANDLE_VALUE) {
+	    CON.buffered = buffered;
+	    get_SBI();
+	    CON.save_SBI = CON.SBI;
+	    if (!buffered) {
+		save_original_screen();
+		set_scrollback(FALSE, &CON.SBI);
+	    }
+	    GetConsoleCursorInfo(CON.hdl, &CON.save_CI);
+	    T(("... initial cursor is %svisible, %d%%",
+	       (CON.save_CI.bVisible ? "" : "not-"),
+	       (int) CON.save_CI.dwSize));
+	}
+
+	console_initialized = TRUE;
+    }
+    return (CON.hdl != INVALID_HANDLE_VALUE);
+}
+
+static bool
+okConsoleHandle(TERMINAL_CONTROL_BLOCK * TCB)
+{
+    return ((TCB != 0) &&
+	    (TCB->magic == WINMAGIC) &&
+	    InitConsole());
+}
+
+/*
+ * While a constructor would ensure that this module is initialized, that will
+ * interfere with applications that may combine this with GUI interfaces.
+ */
+#if 0
+static
+__attribute__((constructor))
+     void _enter_console(void)
+{
+    (void) InitConsole();
+}
+#endif